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