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 		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 	 * Return: 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 	 * Return: 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 	int[string] connectedSignals;
207 
208 	void delegate(string, AppLaunchContext)[] onLaunchFailedListeners;
209 	/**
210 	 * The ::launch-failed signal is emitted when a #GAppInfo launch
211 	 * fails. The startup notification id is provided, so that the launcher
212 	 * can cancel the startup notification.
213 	 *
214 	 * Params:
215 	 *     startupNotifyId = the startup notification id for the failed launch
216 	 *
217 	 * Since: 2.36
218 	 */
219 	void addOnLaunchFailed(void delegate(string, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
220 	{
221 		if ( "launch-failed" !in connectedSignals )
222 		{
223 			Signals.connectData(
224 				this,
225 				"launch-failed",
226 				cast(GCallback)&callBackLaunchFailed,
227 				cast(void*)this,
228 				null,
229 				connectFlags);
230 			connectedSignals["launch-failed"] = 1;
231 		}
232 		onLaunchFailedListeners ~= dlg;
233 	}
234 	extern(C) static void callBackLaunchFailed(GAppLaunchContext* applaunchcontextStruct, char* startupNotifyId, AppLaunchContext _applaunchcontext)
235 	{
236 		foreach ( void delegate(string, AppLaunchContext) dlg; _applaunchcontext.onLaunchFailedListeners )
237 		{
238 			dlg(Str.toString(startupNotifyId), _applaunchcontext);
239 		}
240 	}
241 
242 	void delegate(AppInfoIF, Variant, AppLaunchContext)[] onLaunchedListeners;
243 	/**
244 	 * The ::launched signal is emitted when a #GAppInfo is successfully
245 	 * launched. The @platform_data is an GVariant dictionary mapping
246 	 * strings to variants (ie a{sv}), which contains additional,
247 	 * platform-specific data about this launch. On UNIX, at least the
248 	 * "pid" and "startup-notification-id" keys will be present.
249 	 *
250 	 * Params:
251 	 *     info = the #GAppInfo that was just launched
252 	 *     platformData = additional platform-specific data for this launch
253 	 *
254 	 * Since: 2.36
255 	 */
256 	void addOnLaunched(void delegate(AppInfoIF, Variant, AppLaunchContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
257 	{
258 		if ( "launched" !in connectedSignals )
259 		{
260 			Signals.connectData(
261 				this,
262 				"launched",
263 				cast(GCallback)&callBackLaunched,
264 				cast(void*)this,
265 				null,
266 				connectFlags);
267 			connectedSignals["launched"] = 1;
268 		}
269 		onLaunchedListeners ~= dlg;
270 	}
271 	extern(C) static void callBackLaunched(GAppLaunchContext* applaunchcontextStruct, GAppInfo* info, GVariant* platformData, AppLaunchContext _applaunchcontext)
272 	{
273 		foreach ( void delegate(AppInfoIF, Variant, AppLaunchContext) dlg; _applaunchcontext.onLaunchedListeners )
274 		{
275 			dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(info), new Variant(platformData), _applaunchcontext);
276 		}
277 	}
278 }