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