1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.AppLaunchContext; 26 27 private import gio.AppInfo; 28 private import gio.AppInfoIF; 29 private import gio.FileIF; 30 private import glib.ConstructionException; 31 private import glib.ListG; 32 private import glib.Str; 33 private import glib.Variant; 34 private import gobject.ObjectG; 35 private import gobject.Signals; 36 public import gtkc.gdktypes; 37 private import gtkc.gio; 38 public import gtkc.giotypes; 39 40 41 /** 42 * Integrating the launch with the launching application. This is used to 43 * handle for instance startup notification and launching the new application 44 * on the same screen as the launching window. 45 */ 46 public class AppLaunchContext : ObjectG 47 { 48 /** the main Gtk struct */ 49 protected GAppLaunchContext* gAppLaunchContext; 50 51 /** Get the main Gtk struct */ 52 public GAppLaunchContext* getAppLaunchContextStruct() 53 { 54 return gAppLaunchContext; 55 } 56 57 /** the main Gtk struct as a void* */ 58 protected override void* getStruct() 59 { 60 return cast(void*)gAppLaunchContext; 61 } 62 63 protected override void setStruct(GObject* obj) 64 { 65 gAppLaunchContext = cast(GAppLaunchContext*)obj; 66 super.setStruct(obj); 67 } 68 69 /** 70 * Sets our main struct and passes it to the parent class. 71 */ 72 public this (GAppLaunchContext* gAppLaunchContext, bool ownedRef = false) 73 { 74 this.gAppLaunchContext = gAppLaunchContext; 75 super(cast(GObject*)gAppLaunchContext, ownedRef); 76 } 77 78 /** 79 */ 80 81 public static GType getType() 82 { 83 return g_app_launch_context_get_type(); 84 } 85 86 /** 87 * Creates a new application launch context. This is not normally used, 88 * instead you instantiate a subclass of this, such as #GdkAppLaunchContext. 89 * 90 * Return: a #GAppLaunchContext. 91 * 92 * Throws: ConstructionException GTK+ fails to create the object. 93 */ 94 public this() 95 { 96 auto p = g_app_launch_context_new(); 97 98 if(p is null) 99 { 100 throw new ConstructionException("null returned by new"); 101 } 102 103 this(cast(GAppLaunchContext*) p, true); 104 } 105 106 /** 107 * Gets the display string for the @context. This is used to ensure new 108 * applications are started on the same display as the launching 109 * application, by setting the `DISPLAY` environment variable. 110 * 111 * Params: 112 * info = a #GAppInfo 113 * files = a #GList of #GFile objects 114 * 115 * Return: a display string for the display. 116 */ 117 public string getDisplay(AppInfoIF info, ListG files) 118 { 119 return Str.toString(g_app_launch_context_get_display(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct())); 120 } 121 122 /** 123 * Gets the complete environment variable list to be passed to 124 * the child process when @context is used to launch an application. 125 * This is a %NULL-terminated array of strings, where each string has 126 * the form `KEY=VALUE`. 127 * 128 * Return: the 129 * child's environment 130 * 131 * Since: 2.32 132 */ 133 public string[] getEnvironment() 134 { 135 return Str.toStringArray(g_app_launch_context_get_environment(gAppLaunchContext)); 136 } 137 138 /** 139 * Initiates startup notification for the application and returns the 140 * `DESKTOP_STARTUP_ID` for the launched operation, if supported. 141 * 142 * Startup notification IDs are defined in the 143 * [FreeDesktop.Org Startup Notifications standard](http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"). 144 * 145 * Params: 146 * info = a #GAppInfo 147 * files = a #GList of of #GFile objects 148 * 149 * Return: a startup notification ID for the application, or %NULL if 150 * not supported. 151 */ 152 public string getStartupNotifyId(AppInfoIF info, ListG files) 153 { 154 return Str.toString(g_app_launch_context_get_startup_notify_id(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct())); 155 } 156 157 /** 158 * Called when an application has failed to launch, so that it can cancel 159 * the application startup notification started in g_app_launch_context_get_startup_notify_id(). 160 * 161 * Params: 162 * startupNotifyId = the startup notification id that was returned by g_app_launch_context_get_startup_notify_id(). 163 */ 164 public void launchFailed(string startupNotifyId) 165 { 166 g_app_launch_context_launch_failed(gAppLaunchContext, Str.toStringz(startupNotifyId)); 167 } 168 169 /** 170 * Arranges for @variable to be set to @value in the child's 171 * environment when @context is used to launch an application. 172 * 173 * Params: 174 * variable = the environment variable to set 175 * value = the value for to set the variable to. 176 * 177 * Since: 2.32 178 */ 179 public void setenv(string variable, string value) 180 { 181 g_app_launch_context_setenv(gAppLaunchContext, Str.toStringz(variable), Str.toStringz(value)); 182 } 183 184 /** 185 * Arranges for @variable to be unset in the child's environment 186 * when @context is used to launch an application. 187 * 188 * Params: 189 * variable = the environment variable to remove 190 * 191 * Since: 2.32 192 */ 193 public void unsetenv(string variable) 194 { 195 g_app_launch_context_unsetenv(gAppLaunchContext, Str.toStringz(variable)); 196 } 197 198 int[string] connectedSignals; 199 200 void delegate(string, AppLaunchContext)[] onLaunchFailedListeners; 201 /** 202 * The ::launch-failed signal is emitted when a #GAppInfo launch 203 * fails. The startup notification id is provided, so that the launcher 204 * can cancel the startup notification. 205 * 206 * Params: 207 * startupNotifyId = the startup notification id for the failed launch 208 * 209 * Since: 2.36 210 */ 211 void addOnLaunchFailed(void delegate(string, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 212 { 213 if ( "launch-failed" !in connectedSignals ) 214 { 215 Signals.connectData( 216 this, 217 "launch-failed", 218 cast(GCallback)&callBackLaunchFailed, 219 cast(void*)this, 220 null, 221 connectFlags); 222 connectedSignals["launch-failed"] = 1; 223 } 224 onLaunchFailedListeners ~= dlg; 225 } 226 extern(C) static void callBackLaunchFailed(GAppLaunchContext* applaunchcontextStruct, char* startupNotifyId, AppLaunchContext _applaunchcontext) 227 { 228 foreach ( void delegate(string, AppLaunchContext) dlg; _applaunchcontext.onLaunchFailedListeners ) 229 { 230 dlg(Str.toString(startupNotifyId), _applaunchcontext); 231 } 232 } 233 234 void delegate(AppInfoIF, Variant, AppLaunchContext)[] onLaunchedListeners; 235 /** 236 * The ::launched signal is emitted when a #GAppInfo is successfully 237 * launched. The @platform_data is an GVariant dictionary mapping 238 * strings to variants (ie a{sv}), which contains additional, 239 * platform-specific data about this launch. On UNIX, at least the 240 * "pid" and "startup-notification-id" keys will be present. 241 * 242 * Params: 243 * info = the #GAppInfo that was just launched 244 * platformData = additional platform-specific data for this launch 245 * 246 * Since: 2.36 247 */ 248 void addOnLaunched(void delegate(AppInfoIF, Variant, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 249 { 250 if ( "launched" !in connectedSignals ) 251 { 252 Signals.connectData( 253 this, 254 "launched", 255 cast(GCallback)&callBackLaunched, 256 cast(void*)this, 257 null, 258 connectFlags); 259 connectedSignals["launched"] = 1; 260 } 261 onLaunchedListeners ~= dlg; 262 } 263 extern(C) static void callBackLaunched(GAppLaunchContext* applaunchcontextStruct, GAppInfo* info, GVariant* platformData, AppLaunchContext _applaunchcontext) 264 { 265 foreach ( void delegate(AppInfoIF, Variant, AppLaunchContext) dlg; _applaunchcontext.onLaunchedListeners ) 266 { 267 dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(info), new Variant(platformData), _applaunchcontext); 268 } 269 } 270 }