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 	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 	 * Return: 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 	 * Return: a display string for the display.
115 	 */
116 	public string getDisplay(AppInfoIF info, ListG files)
117 	{
118 		return Str.toString(g_app_launch_context_get_display(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct()));
119 	}
120 
121 	/**
122 	 * Gets the complete environment variable list to be passed to
123 	 * the child process when @context is used to launch an application.
124 	 * This is a %NULL-terminated array of strings, where each string has
125 	 * the form `KEY=VALUE`.
126 	 *
127 	 * Return: the
128 	 *     child's environment
129 	 *
130 	 * Since: 2.32
131 	 */
132 	public string[] getEnvironment()
133 	{
134 		return Str.toStringArray(g_app_launch_context_get_environment(gAppLaunchContext));
135 	}
136 
137 	/**
138 	 * Initiates startup notification for the application and returns the
139 	 * `DESKTOP_STARTUP_ID` for the launched operation, if supported.
140 	 *
141 	 * Startup notification IDs are defined in the
142 	 * [FreeDesktop.Org Startup Notifications standard](http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt").
143 	 *
144 	 * Params:
145 	 *     info = a #GAppInfo
146 	 *     files = a #GList of of #GFile objects
147 	 *
148 	 * Return: a startup notification ID for the application, or %NULL if
149 	 *     not supported.
150 	 */
151 	public string getStartupNotifyId(AppInfoIF info, ListG files)
152 	{
153 		return Str.toString(g_app_launch_context_get_startup_notify_id(gAppLaunchContext, (info is null) ? null : info.getAppInfoStruct(), (files is null) ? null : files.getListGStruct()));
154 	}
155 
156 	/**
157 	 * Called when an application has failed to launch, so that it can cancel
158 	 * the application startup notification started in g_app_launch_context_get_startup_notify_id().
159 	 *
160 	 * Params:
161 	 *     startupNotifyId = the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
162 	 */
163 	public void launchFailed(string startupNotifyId)
164 	{
165 		g_app_launch_context_launch_failed(gAppLaunchContext, Str.toStringz(startupNotifyId));
166 	}
167 
168 	/**
169 	 * Arranges for @variable to be set to @value in the child's
170 	 * environment when @context is used to launch an application.
171 	 *
172 	 * Params:
173 	 *     variable = the environment variable to set
174 	 *     value = the value for to set the variable to.
175 	 *
176 	 * Since: 2.32
177 	 */
178 	public void setenv(string variable, string value)
179 	{
180 		g_app_launch_context_setenv(gAppLaunchContext, Str.toStringz(variable), Str.toStringz(value));
181 	}
182 
183 	/**
184 	 * Arranges for @variable to be unset in the child's environment
185 	 * when @context is used to launch an application.
186 	 *
187 	 * Params:
188 	 *     variable = the environment variable to remove
189 	 *
190 	 * Since: 2.32
191 	 */
192 	public void unsetenv(string variable)
193 	{
194 		g_app_launch_context_unsetenv(gAppLaunchContext, Str.toStringz(variable));
195 	}
196 
197 	int[string] connectedSignals;
198 
199 	void delegate(string, AppLaunchContext)[] onLaunchFailedListeners;
200 	/**
201 	 * The ::launch-failed signal is emitted when a #GAppInfo launch
202 	 * fails. The startup notification id is provided, so that the launcher
203 	 * can cancel the startup notification.
204 	 *
205 	 * Params:
206 	 *     startupNotifyId = the startup notification id for the failed launch
207 	 *
208 	 * Since: 2.36
209 	 */
210 	void addOnLaunchFailed(void delegate(string, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
211 	{
212 		if ( "launch-failed" !in connectedSignals )
213 		{
214 			Signals.connectData(
215 				this,
216 				"launch-failed",
217 				cast(GCallback)&callBackLaunchFailed,
218 				cast(void*)this,
219 				null,
220 				connectFlags);
221 			connectedSignals["launch-failed"] = 1;
222 		}
223 		onLaunchFailedListeners ~= dlg;
224 	}
225 	extern(C) static void callBackLaunchFailed(GAppLaunchContext* applaunchcontextStruct, char* startupNotifyId, AppLaunchContext _applaunchcontext)
226 	{
227 		foreach ( void delegate(string, AppLaunchContext) dlg; _applaunchcontext.onLaunchFailedListeners )
228 		{
229 			dlg(Str.toString(startupNotifyId), _applaunchcontext);
230 		}
231 	}
232 
233 	void delegate(AppInfoIF, Variant, AppLaunchContext)[] onLaunchedListeners;
234 	/**
235 	 * The ::launched signal is emitted when a #GAppInfo is successfully
236 	 * launched. The @platform_data is an GVariant dictionary mapping
237 	 * strings to variants (ie a{sv}), which contains additional,
238 	 * platform-specific data about this launch. On UNIX, at least the
239 	 * "pid" and "startup-notification-id" keys will be present.
240 	 *
241 	 * Params:
242 	 *     info = the #GAppInfo that was just launched
243 	 *     platformData = additional platform-specific data for this launch
244 	 *
245 	 * Since: 2.36
246 	 */
247 	void addOnLaunched(void delegate(AppInfoIF, Variant, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
248 	{
249 		if ( "launched" !in connectedSignals )
250 		{
251 			Signals.connectData(
252 				this,
253 				"launched",
254 				cast(GCallback)&callBackLaunched,
255 				cast(void*)this,
256 				null,
257 				connectFlags);
258 			connectedSignals["launched"] = 1;
259 		}
260 		onLaunchedListeners ~= dlg;
261 	}
262 	extern(C) static void callBackLaunched(GAppLaunchContext* applaunchcontextStruct, GAppInfo* info, GVariant* platformData, AppLaunchContext _applaunchcontext)
263 	{
264 		foreach ( void delegate(AppInfoIF, Variant, AppLaunchContext) dlg; _applaunchcontext.onLaunchedListeners )
265 		{
266 			dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(info), new Variant(platformData), _applaunchcontext);
267 		}
268 	}
269 }