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