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