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  * Conversion parameters:
26  * inFile  = gio-Desktop-file-based-GAppInfo.html
27  * outPack = gio
28  * outFile = DesktopAppInfo
29  * strct   = GDesktopAppInfo
30  * realStrct=
31  * ctorStrct=
32  * clss    = DesktopAppInfo
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- AppInfoIF
40  * prefixes:
41  * 	- g_desktop_app_info_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- g_desktop_app_info_new_from_filename
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * 	- glib.ErrorG
50  * 	- glib.GException
51  * 	- glib.ListG
52  * 	- glib.KeyFile
53  * 	- gio.AppInfo
54  * 	- gio.AppInfoIF
55  * 	- gio.AppLaunchContext
56  * 	- gio.AppInfoT
57  * 	- gio.AppInfoIF
58  * structWrap:
59  * 	- GAppInfo* -> AppInfoIF
60  * 	- GAppLaunchContext* -> AppLaunchContext
61  * 	- GKeyFile* -> KeyFile
62  * 	- GList* -> ListG
63  * module aliases:
64  * local aliases:
65  * overrides:
66  */
67 
68 module gio.DesktopAppInfo;
69 
70 public  import gtkc.giotypes;
71 
72 private import gtkc.gio;
73 private import glib.ConstructionException;
74 private import gobject.ObjectG;
75 
76 private import glib.Str;
77 private import glib.ErrorG;
78 private import glib.GException;
79 private import glib.ListG;
80 private import glib.KeyFile;
81 private import gio.AppInfo;
82 private import gio.AppInfoIF;
83 private import gio.AppLaunchContext;
84 private import gio.AppInfoT;
85 private import gio.AppInfoIF;
86 
87 
88 private import gobject.ObjectG;
89 
90 /**
91  * GDesktopAppInfo is an implementation of GAppInfo based on
92  * desktop files.
93  *
94  * Note that <gio/gdesktopappinfo.h> belongs to
95  * the UNIX-specific GIO interfaces, thus you have to use the
96  * gio-unix-2.0.pc pkg-config file when using it.
97  */
98 public class DesktopAppInfo : ObjectG, AppInfoIF
99 {
100 	
101 	/** the main Gtk struct */
102 	protected GDesktopAppInfo* gDesktopAppInfo;
103 	
104 	
105 	/** Get the main Gtk struct */
106 	public GDesktopAppInfo* getDesktopAppInfoStruct()
107 	{
108 		return gDesktopAppInfo;
109 	}
110 	
111 	
112 	/** the main Gtk struct as a void* */
113 	protected override void* getStruct()
114 	{
115 		return cast(void*)gDesktopAppInfo;
116 	}
117 	
118 	/**
119 	 * Sets our main struct and passes it to the parent class
120 	 */
121 	public this (GDesktopAppInfo* gDesktopAppInfo)
122 	{
123 		super(cast(GObject*)gDesktopAppInfo);
124 		this.gDesktopAppInfo = gDesktopAppInfo;
125 	}
126 	
127 	protected override void setStruct(GObject* obj)
128 	{
129 		super.setStruct(obj);
130 		gDesktopAppInfo = cast(GDesktopAppInfo*)obj;
131 	}
132 	
133 	// add the AppInfo capabilities
134 	mixin AppInfoT!(GDesktopAppInfo);
135 	
136 	public static DesktopAppInfo createFromFilename(string filename)
137 	{
138 		auto p = g_desktop_app_info_new_from_filename(Str.toStringz(filename));
139 		
140 		if(p is null)
141 		{
142 			throw new ConstructionException("null returned by g_desktop_app_info_new_from_filename");
143 		}
144 		
145 		return new DesktopAppInfo(p);
146 	}
147 	
148 	/**
149 	 */
150 	
151 	/**
152 	 * Creates a new GDesktopAppInfo.
153 	 * Since 2.18
154 	 * Params:
155 	 * keyFile = an opened GKeyFile
156 	 * Throws: ConstructionException GTK+ fails to create the object.
157 	 */
158 	public this (KeyFile keyFile)
159 	{
160 		// GDesktopAppInfo * g_desktop_app_info_new_from_keyfile (GKeyFile *key_file);
161 		auto p = g_desktop_app_info_new_from_keyfile((keyFile is null) ? null : keyFile.getKeyFileStruct());
162 		if(p is null)
163 		{
164 			throw new ConstructionException("null returned by g_desktop_app_info_new_from_keyfile((keyFile is null) ? null : keyFile.getKeyFileStruct())");
165 		}
166 		this(cast(GDesktopAppInfo*) p);
167 	}
168 	
169 	/**
170 	 * Creates a new GDesktopAppInfo based on a desktop file id.
171 	 * A desktop file id is the basename of the desktop file, including the
172 	 * .desktop extension. GIO is looking for a desktop file with this name
173 	 * in the applications subdirectories of the XDG data
174 	 * directories (i.e. the directories specified in the
175 	 * XDG_DATA_HOME and XDG_DATA_DIRS environment
176 	 * variables). GIO also supports the prefix-to-subdirectory mapping that is
177 	 * described in the Menu Spec
178 	 * (i.e. a desktop id of kde-foo.desktop will match
179 	 * /usr/share/applications/kde/foo.desktop).
180 	 * Params:
181 	 * desktopId = the desktop file id
182 	 * Throws: ConstructionException GTK+ fails to create the object.
183 	 */
184 	public this (string desktopId)
185 	{
186 		// GDesktopAppInfo * g_desktop_app_info_new (const char *desktop_id);
187 		auto p = g_desktop_app_info_new(Str.toStringz(desktopId));
188 		if(p is null)
189 		{
190 			throw new ConstructionException("null returned by g_desktop_app_info_new(Str.toStringz(desktopId))");
191 		}
192 		this(cast(GDesktopAppInfo*) p);
193 	}
194 	
195 	/**
196 	 * When info was created from a known filename, return it. In some
197 	 * situations such as the GDesktopAppInfo returned from
198 	 * g_desktop_app_info_new_from_keyfile(), this function will return NULL.
199 	 * Since 2.24
200 	 * Returns: The full path to the file for info, or NULL if not known.
201 	 */
202 	public string getFilename()
203 	{
204 		// const char * g_desktop_app_info_get_filename (GDesktopAppInfo *info);
205 		return Str.toString(g_desktop_app_info_get_filename(gDesktopAppInfo));
206 	}
207 	
208 	/**
209 	 * A desktop file is hidden if the Hidden key in it is
210 	 * set to True.
211 	 * Returns: TRUE if hidden, FALSE otherwise.
212 	 */
213 	public int getIsHidden()
214 	{
215 		// gboolean g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info);
216 		return g_desktop_app_info_get_is_hidden(gDesktopAppInfo);
217 	}
218 	
219 	/**
220 	 * Gets the value of the NoDisplay key, which helps determine if the
221 	 * application info should be shown in menus. See
222 	 * G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY and g_app_info_should_show().
223 	 * Since 2.30
224 	 * Returns: The value of the NoDisplay key
225 	 */
226 	public int getNodisplay()
227 	{
228 		// gboolean g_desktop_app_info_get_nodisplay (GDesktopAppInfo *info);
229 		return g_desktop_app_info_get_nodisplay(gDesktopAppInfo);
230 	}
231 	
232 	/**
233 	 * Checks if the application info should be shown in menus that list available
234 	 * applications for a specific name of the desktop, based on the
235 	 * OnlyShowIn and NotShowIn keys.
236 	 * If desktop_env is NULL, then the name of the desktop set with
237 	 * g_desktop_app_info_set_desktop_env() is used.
238 	 * Note that g_app_info_should_show() for info will include this check (with
239 	 * NULL for desktop_env) as well as additional checks.
240 	 * Since 2.30
241 	 * Params:
242 	 * desktopEnv = a string specifying a desktop name
243 	 * Returns: TRUE if the info should be shown in desktop_env according to the OnlyShowIn and NotShowIn keys, FALSE otherwise.
244 	 */
245 	public int getShowIn(string desktopEnv)
246 	{
247 		// gboolean g_desktop_app_info_get_show_in (GDesktopAppInfo *info,  const gchar *desktop_env);
248 		return g_desktop_app_info_get_show_in(gDesktopAppInfo, Str.toStringz(desktopEnv));
249 	}
250 	
251 	/**
252 	 * Gets the generic name from the destkop file.
253 	 * Returns: The value of the GenericName key
254 	 */
255 	public string getGenericName()
256 	{
257 		// const char * g_desktop_app_info_get_generic_name (GDesktopAppInfo *info);
258 		return Str.toString(g_desktop_app_info_get_generic_name(gDesktopAppInfo));
259 	}
260 	
261 	/**
262 	 * Gets the categories from the desktop file.
263 	 * Returns: The unparsed Categories key from the desktop file; i.e. no attempt is made to split it by ';' or validate it.
264 	 */
265 	public string getCategories()
266 	{
267 		// const char * g_desktop_app_info_get_categories (GDesktopAppInfo *info);
268 		return Str.toString(g_desktop_app_info_get_categories(gDesktopAppInfo));
269 	}
270 	
271 	/**
272 	 * Gets the keywords from the desktop file.
273 	 * Since 2.32
274 	 * Returns: The value of the Keywords key. [transfer none]
275 	 */
276 	public string[] getKeywords()
277 	{
278 		// const char * const * g_desktop_app_info_get_keywords (GDesktopAppInfo *info);
279 		return Str.toStringArray(g_desktop_app_info_get_keywords(gDesktopAppInfo));
280 	}
281 	
282 	/**
283 	 * Retrieves the StartupWMClass field from info. This represents the
284 	 * WM_CLASS property of the main window of the application, if launched
285 	 * through info.
286 	 * Since 2.34
287 	 * Returns: the startup WM class, or NULL if none is set in the desktop file. [transfer none]
288 	 */
289 	public string getStartupWmClass()
290 	{
291 		// const char * g_desktop_app_info_get_startup_wm_class  (GDesktopAppInfo *info);
292 		return Str.toString(g_desktop_app_info_get_startup_wm_class(gDesktopAppInfo));
293 	}
294 	
295 	/**
296 	 * Sets the name of the desktop that the application is running in.
297 	 * This is used by g_app_info_should_show() and
298 	 * g_desktop_app_info_get_show_in() to evaluate the
299 	 * OnlyShowIn and NotShowIn
300 	 * desktop entry fields.
301 	 * The Desktop
302 	 * Params:
303 	 * desktopEnv = a string specifying what desktop this is
304 	 */
305 	public static void setDesktopEnv(string desktopEnv)
306 	{
307 		// void g_desktop_app_info_set_desktop_env (const char *desktop_env);
308 		g_desktop_app_info_set_desktop_env(Str.toStringz(desktopEnv));
309 	}
310 	
311 	/**
312 	 * Looks up a string value in the keyfile backing info.
313 	 * The key is looked up in the "Desktop Entry" group.
314 	 * Since 2.36
315 	 * Params:
316 	 * key = the key to look up
317 	 * Returns: a newly allocated string, or NULL if the key is not found
318 	 */
319 	public string getString(string key)
320 	{
321 		// char * g_desktop_app_info_get_string (GDesktopAppInfo *info,  const char *key);
322 		return Str.toString(g_desktop_app_info_get_string(gDesktopAppInfo, Str.toStringz(key)));
323 	}
324 	
325 	/**
326 	 * Looks up a boolean value in the keyfile backing info.
327 	 * The key is looked up in the "Desktop Entry" group.
328 	 * Since 2.36
329 	 * Params:
330 	 * key = the key to look up
331 	 * Returns: the boolean value, or FALSE if the key is not found
332 	 */
333 	public int getBoolean(string key)
334 	{
335 		// gboolean g_desktop_app_info_get_boolean (GDesktopAppInfo *info,  const char *key);
336 		return g_desktop_app_info_get_boolean(gDesktopAppInfo, Str.toStringz(key));
337 	}
338 	
339 	/**
340 	 * Returns whether key exists in the "Desktop Entry" group
341 	 * of the keyfile backing info.
342 	 * Since 2.26
343 	 * Params:
344 	 * key = the key to look up
345 	 * Returns: TRUE if the key exists
346 	 */
347 	public int hasKey(string key)
348 	{
349 		// gboolean g_desktop_app_info_has_key (GDesktopAppInfo *info,  const char *key);
350 		return g_desktop_app_info_has_key(gDesktopAppInfo, Str.toStringz(key));
351 	}
352 	
353 	/**
354 	 * This function performs the equivalent of g_app_info_launch_uris(),
355 	 * but is intended primarily for operating system components that
356 	 * launch applications. Ordinary applications should use
357 	 * g_app_info_launch_uris().
358 	 * If the application is launched via traditional UNIX fork()/exec()
359 	 * then spawn_flags, user_setup and user_setup_data are used for the
360 	 * call to g_spawn_async(). Additionally, pid_callback (with
361 	 * pid_callback_data) will be called to inform about the PID of the
362 	 * created process.
363 	 * If application launching occurs via some other mechanism (eg: D-Bus
364 	 * activation) then spawn_flags, user_setup, user_setup_data,
365 	 * pid_callback and pid_callback_data are ignored.
366 	 * Params:
367 	 * uris = List of URIs. [element-type utf8]
368 	 * launchContext = a GAppLaunchContext
369 	 * spawnFlags = GSpawnFlags, used for each process
370 	 * userSetup = a GSpawnChildSetupFunc, used once for
371 	 * each process. [scope call]
372 	 * userSetupData = User data for user_setup. [closure user_setup]
373 	 * pidCallback = Callback for child processes. [scope call]
374 	 * pidCallbackData = User data for callback. [closure pid_callback]
375 	 * Returns: TRUE on successful launch, FALSE otherwise.
376 	 * Throws: GException on failure.
377 	 */
378 	public int launchUrisAsManager(ListG uris, AppLaunchContext launchContext, GSpawnFlags spawnFlags, GSpawnChildSetupFunc userSetup, void* userSetupData, GDesktopAppLaunchCallback pidCallback, void* pidCallbackData)
379 	{
380 		// gboolean g_desktop_app_info_launch_uris_as_manager  (GDesktopAppInfo *appinfo,  GList *uris,  GAppLaunchContext *launch_context,  GSpawnFlags spawn_flags,  GSpawnChildSetupFunc user_setup,  gpointer user_setup_data,  GDesktopAppLaunchCallback pid_callback,  gpointer pid_callback_data,  GError **error);
381 		GError* err = null;
382 		
383 		auto p = g_desktop_app_info_launch_uris_as_manager(gDesktopAppInfo, (uris is null) ? null : uris.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), spawnFlags, userSetup, userSetupData, pidCallback, pidCallbackData, &err);
384 		
385 		if (err !is null)
386 		{
387 			throw new GException( new ErrorG(err) );
388 		}
389 		
390 		return p;
391 	}
392 	
393 	/**
394 	 * Returns the list of "additional application actions" supported on the
395 	 * desktop file, as per the desktop file specification.
396 	 * As per the specification, this is the list of actions that are
397 	 * explicitly listed in the "Actions" key of the [Desktop Entry] group.
398 	 * Since 2.38
399 	 * Returns: a list of strings, always non-NULL. [array zero-terminated=1][element-type utf8][transfer none]
400 	 */
401 	public string[] listActions()
402 	{
403 		// const gchar * const * g_desktop_app_info_list_actions (GDesktopAppInfo *info);
404 		return Str.toStringArray(g_desktop_app_info_list_actions(gDesktopAppInfo));
405 	}
406 	
407 	/**
408 	 * Gets the user-visible display name of the "additional application
409 	 * action" specified by action_name.
410 	 * This corresponds to the "Name" key within the keyfile group for the
411 	 * action.
412 	 * Since 2.38
413 	 * Params:
414 	 * actionName = the name of the action as from
415 	 * g_desktop_app_info_list_actions()
416 	 * Returns: the locale-specific action name. [transfer full]
417 	 */
418 	public string getActionName(string actionName)
419 	{
420 		// gchar * g_desktop_app_info_get_action_name (GDesktopAppInfo *info,  const gchar *action_name);
421 		return Str.toString(g_desktop_app_info_get_action_name(gDesktopAppInfo, Str.toStringz(actionName)));
422 	}
423 	
424 	/**
425 	 * Activates the named application action.
426 	 * You may only call this function on action names that were
427 	 * returned from g_desktop_app_info_list_actions().
428 	 * Note that if the main entry of the desktop file indicates that the
429 	 * application supports startup notification, and launch_context is
430 	 * non-NULL, then startup notification will be used when activating the
431 	 * action (and as such, invocation of the action on the receiving side
432 	 * must signal the end of startup notification when it is completed).
433 	 * This is the expected behaviour of applications declaring additional
434 	 * actions, as per the desktop file specification.
435 	 * As with g_app_info_launch() there is no way to detect failures that
436 	 * occur while using this function.
437 	 * Since 2.38
438 	 * Params:
439 	 * actionName = the name of the action as from
440 	 * g_desktop_app_info_list_actions()
441 	 * launchContext = a GAppLaunchContext. [allow-none]
442 	 */
443 	public void launchAction(string actionName, AppLaunchContext launchContext)
444 	{
445 		// void g_desktop_app_info_launch_action (GDesktopAppInfo *info,  const gchar *action_name,  GAppLaunchContext *launch_context);
446 		g_desktop_app_info_launch_action(gDesktopAppInfo, Str.toStringz(actionName), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct());
447 	}
448 }