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 private import gtkc.gio; 37 public import gtkc.giotypes; 38 private import std.algorithm; 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 public static GType getType() 81 { 82 return g_app_launch_context_get_type(); 83 } 84 85 /** 86 * Creates a new application launch context. This is not normally used, 87 * instead you instantiate a subclass of this, such as #GdkAppLaunchContext. 88 * 89 * Returns: a #GAppLaunchContext. 90 * 91 * Throws: ConstructionException GTK+ fails to create the object. 92 */ 93 public this() 94 { 95 auto p = g_app_launch_context_new(); 96 97 if(p is null) 98 { 99 throw new ConstructionException("null returned by new"); 100 } 101 102 this(cast(GAppLaunchContext*) p, true); 103 } 104 105 /** 106 * Gets the display string for the @context. This is used to ensure new 107 * applications are started on the same display as the launching 108 * application, by setting the `DISPLAY` environment variable. 109 * 110 * Params: 111 * info = a #GAppInfo 112 * files = a #GList of #GFile objects 113 * 114 * Returns: a display string for the display. 115 */ 116 public string getDisplay(AppInfoIF info, ListG files) 117 { 118 auto retStr = g_app_launch_context_get_display(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct()); 119 120 scope(exit) Str.freeString(retStr); 121 return Str.toString(retStr); 122 } 123 124 /** 125 * Gets the complete environment variable list to be passed to 126 * the child process when @context is used to launch an application. 127 * This is a %NULL-terminated array of strings, where each string has 128 * the form `KEY=VALUE`. 129 * 130 * Returns: the 131 * child's environment 132 * 133 * Since: 2.32 134 */ 135 public string[] getEnvironment() 136 { 137 auto retStr = g_app_launch_context_get_environment(gAppLaunchContext); 138 139 scope(exit) Str.freeStringArray(retStr); 140 return Str.toStringArray(retStr); 141 } 142 143 /** 144 * Initiates startup notification for the application and returns the 145 * `DESKTOP_STARTUP_ID` for the launched operation, if supported. 146 * 147 * Startup notification IDs are defined in the 148 * [FreeDesktop.Org Startup Notifications standard](http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"). 149 * 150 * Params: 151 * info = a #GAppInfo 152 * files = a #GList of of #GFile objects 153 * 154 * Returns: a startup notification ID for the application, or %NULL if 155 * not supported. 156 */ 157 public string getStartupNotifyId(AppInfoIF info, ListG files) 158 { 159 auto retStr = g_app_launch_context_get_startup_notify_id(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct()); 160 161 scope(exit) Str.freeString(retStr); 162 return Str.toString(retStr); 163 } 164 165 /** 166 * Called when an application has failed to launch, so that it can cancel 167 * the application startup notification started in g_app_launch_context_get_startup_notify_id(). 168 * 169 * Params: 170 * startupNotifyId = the startup notification id that was returned by g_app_launch_context_get_startup_notify_id(). 171 */ 172 public void launchFailed(string startupNotifyId) 173 { 174 g_app_launch_context_launch_failed(gAppLaunchContext, Str.toStringz(startupNotifyId)); 175 } 176 177 /** 178 * Arranges for @variable to be set to @value in the child's 179 * environment when @context is used to launch an application. 180 * 181 * Params: 182 * variable = the environment variable to set 183 * value = the value for to set the variable to. 184 * 185 * Since: 2.32 186 */ 187 public void setenv(string variable, string value) 188 { 189 g_app_launch_context_setenv(gAppLaunchContext, Str.toStringz(variable), Str.toStringz(value)); 190 } 191 192 /** 193 * Arranges for @variable to be unset in the child's environment 194 * when @context is used to launch an application. 195 * 196 * Params: 197 * variable = the environment variable to remove 198 * 199 * Since: 2.32 200 */ 201 public void unsetenv(string variable) 202 { 203 g_app_launch_context_unsetenv(gAppLaunchContext, Str.toStringz(variable)); 204 } 205 206 protected class OnLaunchFailedDelegateWrapper 207 { 208 static OnLaunchFailedDelegateWrapper[] listeners; 209 void delegate(string, AppLaunchContext) dlg; 210 gulong handlerId; 211 212 this(void delegate(string, AppLaunchContext) dlg) 213 { 214 this.dlg = dlg; 215 this.listeners ~= this; 216 } 217 218 void remove(OnLaunchFailedDelegateWrapper source) 219 { 220 foreach(index, wrapper; listeners) 221 { 222 if (wrapper.handlerId == source.handlerId) 223 { 224 listeners[index] = null; 225 listeners = std.algorithm.remove(listeners, index); 226 break; 227 } 228 } 229 } 230 } 231 232 /** 233 * The ::launch-failed signal is emitted when a #GAppInfo launch 234 * fails. The startup notification id is provided, so that the launcher 235 * can cancel the startup notification. 236 * 237 * Params: 238 * startupNotifyId = the startup notification id for the failed launch 239 * 240 * Since: 2.36 241 */ 242 gulong addOnLaunchFailed(void delegate(string, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 243 { 244 auto wrapper = new OnLaunchFailedDelegateWrapper(dlg); 245 wrapper.handlerId = Signals.connectData( 246 this, 247 "launch-failed", 248 cast(GCallback)&callBackLaunchFailed, 249 cast(void*)wrapper, 250 cast(GClosureNotify)&callBackLaunchFailedDestroy, 251 connectFlags); 252 return wrapper.handlerId; 253 } 254 255 extern(C) static void callBackLaunchFailed(GAppLaunchContext* applaunchcontextStruct, char* startupNotifyId, OnLaunchFailedDelegateWrapper wrapper) 256 { 257 wrapper.dlg(Str.toString(startupNotifyId), wrapper.outer); 258 } 259 260 extern(C) static void callBackLaunchFailedDestroy(OnLaunchFailedDelegateWrapper wrapper, GClosure* closure) 261 { 262 wrapper.remove(wrapper); 263 } 264 265 protected class OnLaunchedDelegateWrapper 266 { 267 static OnLaunchedDelegateWrapper[] listeners; 268 void delegate(AppInfoIF, Variant, AppLaunchContext) dlg; 269 gulong handlerId; 270 271 this(void delegate(AppInfoIF, Variant, AppLaunchContext) dlg) 272 { 273 this.dlg = dlg; 274 this.listeners ~= this; 275 } 276 277 void remove(OnLaunchedDelegateWrapper source) 278 { 279 foreach(index, wrapper; listeners) 280 { 281 if (wrapper.handlerId == source.handlerId) 282 { 283 listeners[index] = null; 284 listeners = std.algorithm.remove(listeners, index); 285 break; 286 } 287 } 288 } 289 } 290 291 /** 292 * The ::launched signal is emitted when a #GAppInfo is successfully 293 * launched. The @platform_data is an GVariant dictionary mapping 294 * strings to variants (ie a{sv}), which contains additional, 295 * platform-specific data about this launch. On UNIX, at least the 296 * "pid" and "startup-notification-id" keys will be present. 297 * 298 * Params: 299 * info = the #GAppInfo that was just launched 300 * platformData = additional platform-specific data for this launch 301 * 302 * Since: 2.36 303 */ 304 gulong addOnLaunched(void delegate(AppInfoIF, Variant, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 305 { 306 auto wrapper = new OnLaunchedDelegateWrapper(dlg); 307 wrapper.handlerId = Signals.connectData( 308 this, 309 "launched", 310 cast(GCallback)&callBackLaunched, 311 cast(void*)wrapper, 312 cast(GClosureNotify)&callBackLaunchedDestroy, 313 connectFlags); 314 return wrapper.handlerId; 315 } 316 317 extern(C) static void callBackLaunched(GAppLaunchContext* applaunchcontextStruct, GAppInfo* info, GVariant* platformData, OnLaunchedDelegateWrapper wrapper) 318 { 319 wrapper.dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(info), new Variant(platformData), wrapper.outer); 320 } 321 322 extern(C) static void callBackLaunchedDestroy(OnLaunchedDelegateWrapper wrapper, GClosure* closure) 323 { 324 wrapper.remove(wrapper); 325 } 326 }