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.AppInfoT; 26 27 public import gio.AppInfo; 28 public import gio.AppInfoIF; 29 public import gio.AppLaunchContext; 30 public import gio.FileIF; 31 public import gio.Icon; 32 public import gio.IconIF; 33 public import glib.ErrorG; 34 public import glib.GException; 35 public import glib.ListG; 36 public import glib.Str; 37 public import gobject.ObjectG; 38 public import gtkc.gio; 39 public import gtkc.giotypes; 40 41 42 /** 43 * #GAppInfo and #GAppLaunchContext are used for describing and launching 44 * applications installed on the system. 45 * 46 * As of GLib 2.20, URIs will always be converted to POSIX paths 47 * (using g_file_get_path()) when using g_app_info_launch() even if 48 * the application requested an URI and not a POSIX path. For example 49 * for an desktop-file based application with Exec key `totem 50 * %U` and a single URI, `sftp://foo/file.avi`, then 51 * `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will 52 * only work if a set of suitable GIO extensions (such as gvfs 2.26 53 * compiled with FUSE support), is available and operational; if this 54 * is not the case, the URI will be passed unmodified to the application. 55 * Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX 56 * path (in gvfs there's no FUSE mount for it); such URIs will be 57 * passed unmodified to the application. 58 * 59 * Specifically for gvfs 2.26 and later, the POSIX URI will be mapped 60 * back to the GIO URI in the #GFile constructors (since gvfs 61 * implements the #GVfs extension point). As such, if the application 62 * needs to examine the URI, it needs to use g_file_get_uri() or 63 * similar on #GFile. In other words, an application cannot assume 64 * that the URI passed to e.g. g_file_new_for_commandline_arg() is 65 * equal to the result of g_file_get_uri(). The following snippet 66 * illustrates this: 67 * 68 * |[ 69 * GFile *f; 70 * char *uri; 71 * 72 * file = g_file_new_for_commandline_arg (uri_from_commandline); 73 * 74 * uri = g_file_get_uri (file); 75 * strcmp (uri, uri_from_commandline) == 0; 76 * g_free (uri); 77 * 78 * if (g_file_has_uri_scheme (file, "cdda")) 79 * { 80 * // do something special with uri 81 * } 82 * g_object_unref (file); 83 * ]| 84 * 85 * This code will work when both `cdda://sr0/Track 1.wav` and 86 * `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the 87 * application. It should be noted that it's generally not safe 88 * for applications to rely on the format of a particular URIs. 89 * Different launcher applications (e.g. file managers) may have 90 * different ideas of what a given URI means. 91 */ 92 public template AppInfoT(TStruct) 93 { 94 /** Get the main Gtk struct */ 95 public GAppInfo* getAppInfoStruct() 96 { 97 return cast(GAppInfo*)getStruct(); 98 } 99 100 /** 101 */ 102 103 /** 104 * Creates a new #GAppInfo from the given information. 105 * 106 * Note that for @commandline, the quoting rules of the Exec key of the 107 * [freedesktop.org Desktop Entry Specification](http://freedesktop.org/Standards/desktop-entry-spec) 108 * are applied. For example, if the @commandline contains 109 * percent-encoded URIs, the percent-character must be doubled in order to prevent it from 110 * being swallowed by Exec key unquoting. See the specification for exact quoting rules. 111 * 112 * Params: 113 * commandline = the commandline to use 114 * applicationName = the application name, or %NULL to use @commandline 115 * flags = flags that can specify details of the created #GAppInfo 116 * 117 * Return: new #GAppInfo for given command. 118 * 119 * Throws: GException on failure. 120 */ 121 public static AppInfoIF createFromCommandline(string commandline, string applicationName, GAppInfoCreateFlags flags) 122 { 123 GError* err = null; 124 125 auto p = g_app_info_create_from_commandline(Str.toStringz(commandline), Str.toStringz(applicationName), flags, &err); 126 127 if (err !is null) 128 { 129 throw new GException( new ErrorG(err) ); 130 } 131 132 if(p is null) 133 { 134 return null; 135 } 136 137 return ObjectG.getDObject!(AppInfo, AppInfoIF)(cast(GAppInfo*) p); 138 } 139 140 /** 141 * Gets a list of all of the applications currently registered 142 * on this system. 143 * 144 * For desktop files, this includes applications that have 145 * `NoDisplay=true` set or are excluded from display by means 146 * of `OnlyShowIn` or `NotShowIn`. See g_app_info_should_show(). 147 * The returned list does not include applications which have 148 * the `Hidden` key set. 149 * 150 * Return: a newly allocated #GList of references to #GAppInfos. 151 */ 152 public static ListG getAll() 153 { 154 auto p = g_app_info_get_all(); 155 156 if(p is null) 157 { 158 return null; 159 } 160 161 return new ListG(cast(GList*) p); 162 } 163 164 /** 165 * Gets a list of all #GAppInfos for a given content type, 166 * including the recommended and fallback #GAppInfos. See 167 * g_app_info_get_recommended_for_type() and 168 * g_app_info_get_fallback_for_type(). 169 * 170 * Params: 171 * contentType = the content type to find a #GAppInfo for 172 * 173 * Return: #GList of #GAppInfos 174 * for given @content_type or %NULL on error. 175 */ 176 public static ListG getAllForType(string contentType) 177 { 178 auto p = g_app_info_get_all_for_type(Str.toStringz(contentType)); 179 180 if(p is null) 181 { 182 return null; 183 } 184 185 return new ListG(cast(GList*) p); 186 } 187 188 /** 189 * Gets the default #GAppInfo for a given content type. 190 * 191 * Params: 192 * contentType = the content type to find a #GAppInfo for 193 * mustSupportUris = if %TRUE, the #GAppInfo is expected to 194 * support URIs 195 * 196 * Return: #GAppInfo for given @content_type or 197 * %NULL on error. 198 */ 199 public static AppInfoIF getDefaultForType(string contentType, bool mustSupportUris) 200 { 201 auto p = g_app_info_get_default_for_type(Str.toStringz(contentType), mustSupportUris); 202 203 if(p is null) 204 { 205 return null; 206 } 207 208 return ObjectG.getDObject!(AppInfo, AppInfoIF)(cast(GAppInfo*) p); 209 } 210 211 /** 212 * Gets the default application for handling URIs with 213 * the given URI scheme. A URI scheme is the initial part 214 * of the URI, up to but not including the ':', e.g. "http", 215 * "ftp" or "sip". 216 * 217 * Params: 218 * uriScheme = a string containing a URI scheme. 219 * 220 * Return: #GAppInfo for given @uri_scheme or %NULL on error. 221 */ 222 public static AppInfoIF getDefaultForUriScheme(string uriScheme) 223 { 224 auto p = g_app_info_get_default_for_uri_scheme(Str.toStringz(uriScheme)); 225 226 if(p is null) 227 { 228 return null; 229 } 230 231 return ObjectG.getDObject!(AppInfo, AppInfoIF)(cast(GAppInfo*) p); 232 } 233 234 /** 235 * Gets a list of fallback #GAppInfos for a given content type, i.e. 236 * those applications which claim to support the given content type 237 * by MIME type subclassing and not directly. 238 * 239 * Params: 240 * contentType = the content type to find a #GAppInfo for 241 * 242 * Return: #GList of #GAppInfos 243 * for given @content_type or %NULL on error. 244 * 245 * Since: 2.28 246 */ 247 public static ListG getFallbackForType(string contentType) 248 { 249 auto p = g_app_info_get_fallback_for_type(Str.toStringz(contentType)); 250 251 if(p is null) 252 { 253 return null; 254 } 255 256 return new ListG(cast(GList*) p); 257 } 258 259 /** 260 * Gets a list of recommended #GAppInfos for a given content type, i.e. 261 * those applications which claim to support the given content type exactly, 262 * and not by MIME type subclassing. 263 * Note that the first application of the list is the last used one, i.e. 264 * the last one for which g_app_info_set_as_last_used_for_type() has been 265 * called. 266 * 267 * Params: 268 * contentType = the content type to find a #GAppInfo for 269 * 270 * Return: #GList of #GAppInfos 271 * for given @content_type or %NULL on error. 272 * 273 * Since: 2.28 274 */ 275 public static ListG getRecommendedForType(string contentType) 276 { 277 auto p = g_app_info_get_recommended_for_type(Str.toStringz(contentType)); 278 279 if(p is null) 280 { 281 return null; 282 } 283 284 return new ListG(cast(GList*) p); 285 } 286 287 /** 288 * Utility function that launches the default application 289 * registered to handle the specified uri. Synchronous I/O 290 * is done on the uri to detect the type of the file if 291 * required. 292 * 293 * Params: 294 * uri = the uri to show 295 * launchContext = an optional #GAppLaunchContext. 296 * 297 * Return: %TRUE on success, %FALSE on error. 298 * 299 * Throws: GException on failure. 300 */ 301 public static bool launchDefaultForUri(string uri, AppLaunchContext launchContext) 302 { 303 GError* err = null; 304 305 auto p = g_app_info_launch_default_for_uri(Str.toStringz(uri), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), &err) != 0; 306 307 if (err !is null) 308 { 309 throw new GException( new ErrorG(err) ); 310 } 311 312 return p; 313 } 314 315 /** 316 * Removes all changes to the type associations done by 317 * g_app_info_set_as_default_for_type(), 318 * g_app_info_set_as_default_for_extension(), 319 * g_app_info_add_supports_type() or 320 * g_app_info_remove_supports_type(). 321 * 322 * Params: 323 * contentType = a content type 324 * 325 * Since: 2.20 326 */ 327 public static void resetTypeAssociations(string contentType) 328 { 329 g_app_info_reset_type_associations(Str.toStringz(contentType)); 330 } 331 332 /** 333 * Adds a content type to the application information to indicate the 334 * application is capable of opening files with the given content type. 335 * 336 * Params: 337 * contentType = a string. 338 * 339 * Return: %TRUE on success, %FALSE on error. 340 * 341 * Throws: GException on failure. 342 */ 343 public bool addSupportsType(string contentType) 344 { 345 GError* err = null; 346 347 auto p = g_app_info_add_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 348 349 if (err !is null) 350 { 351 throw new GException( new ErrorG(err) ); 352 } 353 354 return p; 355 } 356 357 /** 358 * Obtains the information whether the #GAppInfo can be deleted. 359 * See g_app_info_delete(). 360 * 361 * Return: %TRUE if @appinfo can be deleted 362 * 363 * Since: 2.20 364 */ 365 public bool canDelete() 366 { 367 return g_app_info_can_delete(getAppInfoStruct()) != 0; 368 } 369 370 /** 371 * Checks if a supported content type can be removed from an application. 372 * 373 * Return: %TRUE if it is possible to remove supported 374 * content types from a given @appinfo, %FALSE if not. 375 */ 376 public bool canRemoveSupportsType() 377 { 378 return g_app_info_can_remove_supports_type(getAppInfoStruct()) != 0; 379 } 380 381 /** 382 * Tries to delete a #GAppInfo. 383 * 384 * On some platforms, there may be a difference between user-defined 385 * #GAppInfos which can be deleted, and system-wide ones which cannot. 386 * See g_app_info_can_delete(). 387 * 388 * Return: %TRUE if @appinfo has been deleted 389 * 390 * Since: 2.20 391 */ 392 public bool delet() 393 { 394 return g_app_info_delete(getAppInfoStruct()) != 0; 395 } 396 397 /** 398 * Creates a duplicate of a #GAppInfo. 399 * 400 * Return: a duplicate of @appinfo. 401 */ 402 public AppInfoIF dup() 403 { 404 auto p = g_app_info_dup(getAppInfoStruct()); 405 406 if(p is null) 407 { 408 return null; 409 } 410 411 return ObjectG.getDObject!(AppInfo, AppInfoIF)(cast(GAppInfo*) p); 412 } 413 414 /** 415 * Checks if two #GAppInfos are equal. 416 * 417 * Params: 418 * appinfo2 = the second #GAppInfo. 419 * 420 * Return: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise. 421 */ 422 public bool equal(AppInfoIF appinfo2) 423 { 424 return g_app_info_equal(getAppInfoStruct(), (appinfo2 is null) ? null : appinfo2.getAppInfoStruct()) != 0; 425 } 426 427 /** 428 * Gets the commandline with which the application will be 429 * started. 430 * 431 * Return: a string containing the @appinfo's commandline, 432 * or %NULL if this information is not available 433 * 434 * Since: 2.20 435 */ 436 public string getCommandline() 437 { 438 return Str.toString(g_app_info_get_commandline(getAppInfoStruct())); 439 } 440 441 /** 442 * Gets a human-readable description of an installed application. 443 * 444 * Return: a string containing a description of the 445 * application @appinfo, or %NULL if none. 446 */ 447 public string getDescription() 448 { 449 return Str.toString(g_app_info_get_description(getAppInfoStruct())); 450 } 451 452 /** 453 * Gets the display name of the application. The display name is often more 454 * descriptive to the user than the name itself. 455 * 456 * Return: the display name of the application for @appinfo, or the name if 457 * no display name is available. 458 * 459 * Since: 2.24 460 */ 461 public string getDisplayName() 462 { 463 return Str.toString(g_app_info_get_display_name(getAppInfoStruct())); 464 } 465 466 /** 467 * Gets the executable's name for the installed application. 468 * 469 * Return: a string containing the @appinfo's application 470 * binaries name 471 */ 472 public string getExecutable() 473 { 474 return Str.toString(g_app_info_get_executable(getAppInfoStruct())); 475 } 476 477 /** 478 * Gets the icon for the application. 479 * 480 * Return: the default #GIcon for @appinfo or %NULL 481 * if there is no default icon. 482 */ 483 public IconIF getIcon() 484 { 485 auto p = g_app_info_get_icon(getAppInfoStruct()); 486 487 if(p is null) 488 { 489 return null; 490 } 491 492 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p); 493 } 494 495 /** 496 * Gets the ID of an application. An id is a string that 497 * identifies the application. The exact format of the id is 498 * platform dependent. For instance, on Unix this is the 499 * desktop file id from the xdg menu specification. 500 * 501 * Note that the returned ID may be %NULL, depending on how 502 * the @appinfo has been constructed. 503 * 504 * Return: a string containing the application's ID. 505 */ 506 public string getId() 507 { 508 return Str.toString(g_app_info_get_id(getAppInfoStruct())); 509 } 510 511 /** 512 * Gets the installed name of the application. 513 * 514 * Return: the name of the application for @appinfo. 515 */ 516 public string getName() 517 { 518 return Str.toString(g_app_info_get_name(getAppInfoStruct())); 519 } 520 521 /** 522 * Retrieves the list of content types that @app_info claims to support. 523 * If this information is not provided by the environment, this function 524 * will return %NULL. 525 * This function does not take in consideration associations added with 526 * g_app_info_add_supports_type(), but only those exported directly by 527 * the application. 528 * 529 * Return: a list of content types. 530 * 531 * Since: 2.34 532 */ 533 public string[] getSupportedTypes() 534 { 535 return Str.toStringArray(g_app_info_get_supported_types(getAppInfoStruct())); 536 } 537 538 /** 539 * Launches the application. Passes @files to the launched application 540 * as arguments, using the optional @launch_context to get information 541 * about the details of the launcher (like what screen it is on). 542 * On error, @error will be set accordingly. 543 * 544 * To launch the application without arguments pass a %NULL @files list. 545 * 546 * Note that even if the launch is successful the application launched 547 * can fail to start if it runs into problems during startup. There is 548 * no way to detect this. 549 * 550 * Some URIs can be changed when passed through a GFile (for instance 551 * unsupported URIs with strange formats like mailto:), so if you have 552 * a textual URI you want to pass in as argument, consider using 553 * g_app_info_launch_uris() instead. 554 * 555 * The launched application inherits the environment of the launching 556 * process, but it can be modified with g_app_launch_context_setenv() 557 * and g_app_launch_context_unsetenv(). 558 * 559 * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE` 560 * environment variable with the path of the launched desktop file and 561 * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched 562 * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`, 563 * should it be inherited by further processes. The `DISPLAY` and 564 * `DESKTOP_STARTUP_ID` environment variables are also set, based 565 * on information provided in @launch_context. 566 * 567 * Params: 568 * files = a #GList of #GFile objects 569 * launchContext = a #GAppLaunchContext or %NULL 570 * 571 * Return: %TRUE on successful launch, %FALSE otherwise. 572 * 573 * Throws: GException on failure. 574 */ 575 public bool launch(ListG files, AppLaunchContext launchContext) 576 { 577 GError* err = null; 578 579 auto p = g_app_info_launch(getAppInfoStruct(), (files is null) ? null : files.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), &err) != 0; 580 581 if (err !is null) 582 { 583 throw new GException( new ErrorG(err) ); 584 } 585 586 return p; 587 } 588 589 /** 590 * Launches the application. This passes the @uris to the launched application 591 * as arguments, using the optional @launch_context to get information 592 * about the details of the launcher (like what screen it is on). 593 * On error, @error will be set accordingly. 594 * 595 * To launch the application without arguments pass a %NULL @uris list. 596 * 597 * Note that even if the launch is successful the application launched 598 * can fail to start if it runs into problems during startup. There is 599 * no way to detect this. 600 * 601 * Params: 602 * uris = a #GList containing URIs to launch. 603 * launchContext = a #GAppLaunchContext or %NULL 604 * 605 * Return: %TRUE on successful launch, %FALSE otherwise. 606 * 607 * Throws: GException on failure. 608 */ 609 public bool launchUris(ListG uris, AppLaunchContext launchContext) 610 { 611 GError* err = null; 612 613 auto p = g_app_info_launch_uris(getAppInfoStruct(), (uris is null) ? null : uris.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), &err) != 0; 614 615 if (err !is null) 616 { 617 throw new GException( new ErrorG(err) ); 618 } 619 620 return p; 621 } 622 623 /** 624 * Removes a supported type from an application, if possible. 625 * 626 * Params: 627 * contentType = a string. 628 * 629 * Return: %TRUE on success, %FALSE on error. 630 * 631 * Throws: GException on failure. 632 */ 633 public bool removeSupportsType(string contentType) 634 { 635 GError* err = null; 636 637 auto p = g_app_info_remove_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 638 639 if (err !is null) 640 { 641 throw new GException( new ErrorG(err) ); 642 } 643 644 return p; 645 } 646 647 /** 648 * Sets the application as the default handler for the given file extension. 649 * 650 * Params: 651 * extension = a string containing the file extension (without the dot). 652 * 653 * Return: %TRUE on success, %FALSE on error. 654 * 655 * Throws: GException on failure. 656 */ 657 public bool setAsDefaultForExtension(string extension) 658 { 659 GError* err = null; 660 661 auto p = g_app_info_set_as_default_for_extension(getAppInfoStruct(), Str.toStringz(extension), &err) != 0; 662 663 if (err !is null) 664 { 665 throw new GException( new ErrorG(err) ); 666 } 667 668 return p; 669 } 670 671 /** 672 * Sets the application as the default handler for a given type. 673 * 674 * Params: 675 * contentType = the content type. 676 * 677 * Return: %TRUE on success, %FALSE on error. 678 * 679 * Throws: GException on failure. 680 */ 681 public bool setAsDefaultForType(string contentType) 682 { 683 GError* err = null; 684 685 auto p = g_app_info_set_as_default_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 686 687 if (err !is null) 688 { 689 throw new GException( new ErrorG(err) ); 690 } 691 692 return p; 693 } 694 695 /** 696 * Sets the application as the last used application for a given type. 697 * This will make the application appear as first in the list returned 698 * by g_app_info_get_recommended_for_type(), regardless of the default 699 * application for that content type. 700 * 701 * Params: 702 * contentType = the content type. 703 * 704 * Return: %TRUE on success, %FALSE on error. 705 * 706 * Throws: GException on failure. 707 */ 708 public bool setAsLastUsedForType(string contentType) 709 { 710 GError* err = null; 711 712 auto p = g_app_info_set_as_last_used_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 713 714 if (err !is null) 715 { 716 throw new GException( new ErrorG(err) ); 717 } 718 719 return p; 720 } 721 722 /** 723 * Checks if the application info should be shown in menus that 724 * list available applications. 725 * 726 * Return: %TRUE if the @appinfo should be shown, %FALSE otherwise. 727 */ 728 public bool shouldShow() 729 { 730 return g_app_info_should_show(getAppInfoStruct()) != 0; 731 } 732 733 /** 734 * Checks if the application accepts files as arguments. 735 * 736 * Return: %TRUE if the @appinfo supports files. 737 */ 738 public bool supportsFiles() 739 { 740 return g_app_info_supports_files(getAppInfoStruct()) != 0; 741 } 742 743 /** 744 * Checks if the application supports reading files and directories from URIs. 745 * 746 * Return: %TRUE if the @appinfo supports URIs. 747 */ 748 public bool supportsUris() 749 { 750 return g_app_info_supports_uris(getAppInfoStruct()) != 0; 751 } 752 }