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 private import std.algorithm; 40 41 42 /** 43 * Integrating the launch with the launching application. This is used to 44 * handle for instance startup notification and launching the new application 45 * on the same screen as the launching window. 46 */ 47 public class AppLaunchContext : ObjectG 48 { 49 /** the main Gtk struct */ 50 protected GAppLaunchContext* gAppLaunchContext; 51 52 /** Get the main Gtk struct */ 53 public GAppLaunchContext* getAppLaunchContextStruct() 54 { 55 return gAppLaunchContext; 56 } 57 58 /** the main Gtk struct as a void* */ 59 protected override void* getStruct() 60 { 61 return cast(void*)gAppLaunchContext; 62 } 63 64 protected override void setStruct(GObject* obj) 65 { 66 gAppLaunchContext = cast(GAppLaunchContext*)obj; 67 super.setStruct(obj); 68 } 69 70 /** 71 * Sets our main struct and passes it to the parent class. 72 */ 73 public this (GAppLaunchContext* gAppLaunchContext, bool ownedRef = false) 74 { 75 this.gAppLaunchContext = gAppLaunchContext; 76 super(cast(GObject*)gAppLaunchContext, ownedRef); 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 auto retStr = g_app_launch_context_get_display(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct()); 120 121 scope(exit) Str.freeString(retStr); 122 return Str.toString(retStr); 123 } 124 125 /** 126 * Gets the complete environment variable list to be passed to 127 * the child process when @context is used to launch an application. 128 * This is a %NULL-terminated array of strings, where each string has 129 * the form `KEY=VALUE`. 130 * 131 * Return: the 132 * child's environment 133 * 134 * Since: 2.32 135 */ 136 public string[] getEnvironment() 137 { 138 auto retStr = g_app_launch_context_get_environment(gAppLaunchContext); 139 140 scope(exit) Str.freeStringArray(retStr); 141 return Str.toStringArray(retStr); 142 } 143 144 /** 145 * Initiates startup notification for the application and returns the 146 * `DESKTOP_STARTUP_ID` for the launched operation, if supported. 147 * 148 * Startup notification IDs are defined in the 149 * [FreeDesktop.Org Startup Notifications standard](http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"). 150 * 151 * Params: 152 * info = a #GAppInfo 153 * files = a #GList of of #GFile objects 154 * 155 * Return: a startup notification ID for the application, or %NULL if 156 * not supported. 157 */ 158 public string getStartupNotifyId(AppInfoIF info, ListG files) 159 { 160 auto retStr = g_app_launch_context_get_startup_notify_id(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct()); 161 162 scope(exit) Str.freeString(retStr); 163 return Str.toString(retStr); 164 } 165 166 /** 167 * Called when an application has failed to launch, so that it can cancel 168 * the application startup notification started in g_app_launch_context_get_startup_notify_id(). 169 * 170 * Params: 171 * startupNotifyId = the startup notification id that was returned by g_app_launch_context_get_startup_notify_id(). 172 */ 173 public void launchFailed(string startupNotifyId) 174 { 175 g_app_launch_context_launch_failed(gAppLaunchContext, Str.toStringz(startupNotifyId)); 176 } 177 178 /** 179 * Arranges for @variable to be set to @value in the child's 180 * environment when @context is used to launch an application. 181 * 182 * Params: 183 * variable = the environment variable to set 184 * value = the value for to set the variable to. 185 * 186 * Since: 2.32 187 */ 188 public void setenv(string variable, string value) 189 { 190 g_app_launch_context_setenv(gAppLaunchContext, Str.toStringz(variable), Str.toStringz(value)); 191 } 192 193 /** 194 * Arranges for @variable to be unset in the child's environment 195 * when @context is used to launch an application. 196 * 197 * Params: 198 * variable = the environment variable to remove 199 * 200 * Since: 2.32 201 */ 202 public void unsetenv(string variable) 203 { 204 g_app_launch_context_unsetenv(gAppLaunchContext, Str.toStringz(variable)); 205 } 206 207 protected class OnLaunchFailedDelegateWrapper 208 { 209 void delegate(string, AppLaunchContext) dlg; 210 gulong handlerId; 211 ConnectFlags flags; 212 this(void delegate(string, AppLaunchContext) dlg, gulong handlerId, ConnectFlags flags) 213 { 214 this.dlg = dlg; 215 this.handlerId = handlerId; 216 this.flags = flags; 217 } 218 } 219 protected OnLaunchFailedDelegateWrapper[] onLaunchFailedListeners; 220 221 /** 222 * The ::launch-failed signal is emitted when a #GAppInfo launch 223 * fails. The startup notification id is provided, so that the launcher 224 * can cancel the startup notification. 225 * 226 * Params: 227 * startupNotifyId = the startup notification id for the failed launch 228 * 229 * Since: 2.36 230 */ 231 gulong addOnLaunchFailed(void delegate(string, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 232 { 233 onLaunchFailedListeners ~= new OnLaunchFailedDelegateWrapper(dlg, 0, connectFlags); 234 onLaunchFailedListeners[onLaunchFailedListeners.length - 1].handlerId = Signals.connectData( 235 this, 236 "launch-failed", 237 cast(GCallback)&callBackLaunchFailed, 238 cast(void*)onLaunchFailedListeners[onLaunchFailedListeners.length - 1], 239 cast(GClosureNotify)&callBackLaunchFailedDestroy, 240 connectFlags); 241 return onLaunchFailedListeners[onLaunchFailedListeners.length - 1].handlerId; 242 } 243 244 extern(C) static void callBackLaunchFailed(GAppLaunchContext* applaunchcontextStruct, char* startupNotifyId,OnLaunchFailedDelegateWrapper wrapper) 245 { 246 wrapper.dlg(Str.toString(startupNotifyId), wrapper.outer); 247 } 248 249 extern(C) static void callBackLaunchFailedDestroy(OnLaunchFailedDelegateWrapper wrapper, GClosure* closure) 250 { 251 wrapper.outer.internalRemoveOnLaunchFailed(wrapper); 252 } 253 254 protected void internalRemoveOnLaunchFailed(OnLaunchFailedDelegateWrapper source) 255 { 256 foreach(index, wrapper; onLaunchFailedListeners) 257 { 258 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 259 { 260 onLaunchFailedListeners[index] = null; 261 onLaunchFailedListeners = std.algorithm.remove(onLaunchFailedListeners, index); 262 break; 263 } 264 } 265 } 266 267 268 protected class OnLaunchedDelegateWrapper 269 { 270 void delegate(AppInfoIF, Variant, AppLaunchContext) dlg; 271 gulong handlerId; 272 ConnectFlags flags; 273 this(void delegate(AppInfoIF, Variant, AppLaunchContext) dlg, gulong handlerId, ConnectFlags flags) 274 { 275 this.dlg = dlg; 276 this.handlerId = handlerId; 277 this.flags = flags; 278 } 279 } 280 protected OnLaunchedDelegateWrapper[] onLaunchedListeners; 281 282 /** 283 * The ::launched signal is emitted when a #GAppInfo is successfully 284 * launched. The @platform_data is an GVariant dictionary mapping 285 * strings to variants (ie a{sv}), which contains additional, 286 * platform-specific data about this launch. On UNIX, at least the 287 * "pid" and "startup-notification-id" keys will be present. 288 * 289 * Params: 290 * info = the #GAppInfo that was just launched 291 * platformData = additional platform-specific data for this launch 292 * 293 * Since: 2.36 294 */ 295 gulong addOnLaunched(void delegate(AppInfoIF, Variant, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 296 { 297 onLaunchedListeners ~= new OnLaunchedDelegateWrapper(dlg, 0, connectFlags); 298 onLaunchedListeners[onLaunchedListeners.length - 1].handlerId = Signals.connectData( 299 this, 300 "launched", 301 cast(GCallback)&callBackLaunched, 302 cast(void*)onLaunchedListeners[onLaunchedListeners.length - 1], 303 cast(GClosureNotify)&callBackLaunchedDestroy, 304 connectFlags); 305 return onLaunchedListeners[onLaunchedListeners.length - 1].handlerId; 306 } 307 308 extern(C) static void callBackLaunched(GAppLaunchContext* applaunchcontextStruct, GAppInfo* info, GVariant* platformData,OnLaunchedDelegateWrapper wrapper) 309 { 310 wrapper.dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(info), new Variant(platformData), wrapper.outer); 311 } 312 313 extern(C) static void callBackLaunchedDestroy(OnLaunchedDelegateWrapper wrapper, GClosure* closure) 314 { 315 wrapper.outer.internalRemoveOnLaunched(wrapper); 316 } 317 318 protected void internalRemoveOnLaunched(OnLaunchedDelegateWrapper source) 319 { 320 foreach(index, wrapper; onLaunchedListeners) 321 { 322 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 323 { 324 onLaunchedListeners[index] = null; 325 onLaunchedListeners = std.algorithm.remove(onLaunchedListeners, index); 326 break; 327 } 328 } 329 } 330 331 }