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.AsyncResultIF; 31 public import gio.Cancellable; 32 public import gio.FileIF; 33 public import gio.Icon; 34 public import gio.IconIF; 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.gio; 41 public import gtkc.giotypes; 42 43 44 /** 45 * #GAppInfo and #GAppLaunchContext are used for describing and launching 46 * applications installed on the system. 47 * 48 * As of GLib 2.20, URIs will always be converted to POSIX paths 49 * (using g_file_get_path()) when using g_app_info_launch() even if 50 * the application requested an URI and not a POSIX path. For example 51 * for an desktop-file based application with Exec key `totem 52 * %U` and a single URI, `sftp://foo/file.avi`, then 53 * `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will 54 * only work if a set of suitable GIO extensions (such as gvfs 2.26 55 * compiled with FUSE support), is available and operational; if this 56 * is not the case, the URI will be passed unmodified to the application. 57 * Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX 58 * path (in gvfs there's no FUSE mount for it); such URIs will be 59 * passed unmodified to the application. 60 * 61 * Specifically for gvfs 2.26 and later, the POSIX URI will be mapped 62 * back to the GIO URI in the #GFile constructors (since gvfs 63 * implements the #GVfs extension point). As such, if the application 64 * needs to examine the URI, it needs to use g_file_get_uri() or 65 * similar on #GFile. In other words, an application cannot assume 66 * that the URI passed to e.g. g_file_new_for_commandline_arg() is 67 * equal to the result of g_file_get_uri(). The following snippet 68 * illustrates this: 69 * 70 * |[ 71 * GFile *f; 72 * char *uri; 73 * 74 * file = g_file_new_for_commandline_arg (uri_from_commandline); 75 * 76 * uri = g_file_get_uri (file); 77 * strcmp (uri, uri_from_commandline) == 0; 78 * g_free (uri); 79 * 80 * if (g_file_has_uri_scheme (file, "cdda")) 81 * { 82 * // do something special with uri 83 * } 84 * g_object_unref (file); 85 * ]| 86 * 87 * This code will work when both `cdda://sr0/Track 1.wav` and 88 * `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the 89 * application. It should be noted that it's generally not safe 90 * for applications to rely on the format of a particular URIs. 91 * Different launcher applications (e.g. file managers) may have 92 * different ideas of what a given URI means. 93 */ 94 public template AppInfoT(TStruct) 95 { 96 /** Get the main Gtk struct */ 97 public GAppInfo* getAppInfoStruct() 98 { 99 return cast(GAppInfo*)getStruct(); 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, true); 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, true); 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, true); 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, true); 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, true); 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, true); 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, true); 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 * Async version of g_app_info_launch_default_for_uri(). 317 * 318 * This version is useful if you are interested in receiving 319 * error information in the case where the application is 320 * sandboxed and the portal may present an application chooser 321 * dialog to the user. 322 * 323 * Params: 324 * uri = the uri to show 325 * callback = a #GASyncReadyCallback to call when the request is done 326 * userData = data to pass to @callback 327 * 328 * Since: 2.50 329 */ 330 public static void launchDefaultForUriAsync(string uri, AppLaunchContext launchContext, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 331 { 332 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); 333 } 334 335 /** 336 * Finishes an asynchronous launch-default-for-uri operation. 337 * 338 * Params: 339 * result = a #GAsyncResult 340 * 341 * Return: %TRUE if the launch was successful, %FALSE if @error is set 342 * 343 * Since: 2.50 344 * 345 * Throws: GException on failure. 346 */ 347 public static bool launchDefaultForUriFinish(AsyncResultIF result) 348 { 349 GError* err = null; 350 351 auto p = g_app_info_launch_default_for_uri_finish((result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 352 353 if (err !is null) 354 { 355 throw new GException( new ErrorG(err) ); 356 } 357 358 return p; 359 } 360 361 /** 362 * Removes all changes to the type associations done by 363 * g_app_info_set_as_default_for_type(), 364 * g_app_info_set_as_default_for_extension(), 365 * g_app_info_add_supports_type() or 366 * g_app_info_remove_supports_type(). 367 * 368 * Params: 369 * contentType = a content type 370 * 371 * Since: 2.20 372 */ 373 public static void resetTypeAssociations(string contentType) 374 { 375 g_app_info_reset_type_associations(Str.toStringz(contentType)); 376 } 377 378 /** 379 * Adds a content type to the application information to indicate the 380 * application is capable of opening files with the given content type. 381 * 382 * Params: 383 * contentType = a string. 384 * 385 * Return: %TRUE on success, %FALSE on error. 386 * 387 * Throws: GException on failure. 388 */ 389 public bool addSupportsType(string contentType) 390 { 391 GError* err = null; 392 393 auto p = g_app_info_add_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 394 395 if (err !is null) 396 { 397 throw new GException( new ErrorG(err) ); 398 } 399 400 return p; 401 } 402 403 /** 404 * Obtains the information whether the #GAppInfo can be deleted. 405 * See g_app_info_delete(). 406 * 407 * Return: %TRUE if @appinfo can be deleted 408 * 409 * Since: 2.20 410 */ 411 public bool canDelete() 412 { 413 return g_app_info_can_delete(getAppInfoStruct()) != 0; 414 } 415 416 /** 417 * Checks if a supported content type can be removed from an application. 418 * 419 * Return: %TRUE if it is possible to remove supported 420 * content types from a given @appinfo, %FALSE if not. 421 */ 422 public bool canRemoveSupportsType() 423 { 424 return g_app_info_can_remove_supports_type(getAppInfoStruct()) != 0; 425 } 426 427 /** 428 * Tries to delete a #GAppInfo. 429 * 430 * On some platforms, there may be a difference between user-defined 431 * #GAppInfos which can be deleted, and system-wide ones which cannot. 432 * See g_app_info_can_delete(). 433 * 434 * Return: %TRUE if @appinfo has been deleted 435 * 436 * Since: 2.20 437 */ 438 public bool delet() 439 { 440 return g_app_info_delete(getAppInfoStruct()) != 0; 441 } 442 443 /** 444 * Creates a duplicate of a #GAppInfo. 445 * 446 * Return: a duplicate of @appinfo. 447 */ 448 public AppInfoIF dup() 449 { 450 auto p = g_app_info_dup(getAppInfoStruct()); 451 452 if(p is null) 453 { 454 return null; 455 } 456 457 return ObjectG.getDObject!(AppInfo, AppInfoIF)(cast(GAppInfo*) p, true); 458 } 459 460 /** 461 * Checks if two #GAppInfos are equal. 462 * 463 * Params: 464 * appinfo2 = the second #GAppInfo. 465 * 466 * Return: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise. 467 */ 468 public bool equal(AppInfoIF appinfo2) 469 { 470 return g_app_info_equal(getAppInfoStruct(), (appinfo2 is null) ? null : appinfo2.getAppInfoStruct()) != 0; 471 } 472 473 /** 474 * Gets the commandline with which the application will be 475 * started. 476 * 477 * Return: a string containing the @appinfo's commandline, 478 * or %NULL if this information is not available 479 * 480 * Since: 2.20 481 */ 482 public string getCommandline() 483 { 484 return Str.toString(g_app_info_get_commandline(getAppInfoStruct())); 485 } 486 487 /** 488 * Gets a human-readable description of an installed application. 489 * 490 * Return: a string containing a description of the 491 * application @appinfo, or %NULL if none. 492 */ 493 public string getDescription() 494 { 495 return Str.toString(g_app_info_get_description(getAppInfoStruct())); 496 } 497 498 /** 499 * Gets the display name of the application. The display name is often more 500 * descriptive to the user than the name itself. 501 * 502 * Return: the display name of the application for @appinfo, or the name if 503 * no display name is available. 504 * 505 * Since: 2.24 506 */ 507 public string getDisplayName() 508 { 509 return Str.toString(g_app_info_get_display_name(getAppInfoStruct())); 510 } 511 512 /** 513 * Gets the executable's name for the installed application. 514 * 515 * Return: a string containing the @appinfo's application 516 * binaries name 517 */ 518 public string getExecutable() 519 { 520 return Str.toString(g_app_info_get_executable(getAppInfoStruct())); 521 } 522 523 /** 524 * Gets the icon for the application. 525 * 526 * Return: the default #GIcon for @appinfo or %NULL 527 * if there is no default icon. 528 */ 529 public IconIF getIcon() 530 { 531 auto p = g_app_info_get_icon(getAppInfoStruct()); 532 533 if(p is null) 534 { 535 return null; 536 } 537 538 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p); 539 } 540 541 /** 542 * Gets the ID of an application. An id is a string that 543 * identifies the application. The exact format of the id is 544 * platform dependent. For instance, on Unix this is the 545 * desktop file id from the xdg menu specification. 546 * 547 * Note that the returned ID may be %NULL, depending on how 548 * the @appinfo has been constructed. 549 * 550 * Return: a string containing the application's ID. 551 */ 552 public string getId() 553 { 554 return Str.toString(g_app_info_get_id(getAppInfoStruct())); 555 } 556 557 /** 558 * Gets the installed name of the application. 559 * 560 * Return: the name of the application for @appinfo. 561 */ 562 public string getName() 563 { 564 return Str.toString(g_app_info_get_name(getAppInfoStruct())); 565 } 566 567 /** 568 * Retrieves the list of content types that @app_info claims to support. 569 * If this information is not provided by the environment, this function 570 * will return %NULL. 571 * This function does not take in consideration associations added with 572 * g_app_info_add_supports_type(), but only those exported directly by 573 * the application. 574 * 575 * Return: a list of content types. 576 * 577 * Since: 2.34 578 */ 579 public string[] getSupportedTypes() 580 { 581 return Str.toStringArray(g_app_info_get_supported_types(getAppInfoStruct())); 582 } 583 584 /** 585 * Launches the application. Passes @files to the launched application 586 * as arguments, using the optional @launch_context to get information 587 * about the details of the launcher (like what screen it is on). 588 * On error, @error will be set accordingly. 589 * 590 * To launch the application without arguments pass a %NULL @files list. 591 * 592 * Note that even if the launch is successful the application launched 593 * can fail to start if it runs into problems during startup. There is 594 * no way to detect this. 595 * 596 * Some URIs can be changed when passed through a GFile (for instance 597 * unsupported URIs with strange formats like mailto:), so if you have 598 * a textual URI you want to pass in as argument, consider using 599 * g_app_info_launch_uris() instead. 600 * 601 * The launched application inherits the environment of the launching 602 * process, but it can be modified with g_app_launch_context_setenv() 603 * and g_app_launch_context_unsetenv(). 604 * 605 * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE` 606 * environment variable with the path of the launched desktop file and 607 * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched 608 * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`, 609 * should it be inherited by further processes. The `DISPLAY` and 610 * `DESKTOP_STARTUP_ID` environment variables are also set, based 611 * on information provided in @launch_context. 612 * 613 * Params: 614 * files = a #GList of #GFile objects 615 * launchContext = a #GAppLaunchContext or %NULL 616 * 617 * Return: %TRUE on successful launch, %FALSE otherwise. 618 * 619 * Throws: GException on failure. 620 */ 621 public bool launch(ListG files, AppLaunchContext launchContext) 622 { 623 GError* err = null; 624 625 auto p = g_app_info_launch(getAppInfoStruct(), (files is null) ? null : files.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), &err) != 0; 626 627 if (err !is null) 628 { 629 throw new GException( new ErrorG(err) ); 630 } 631 632 return p; 633 } 634 635 /** 636 * Launches the application. This passes the @uris to the launched application 637 * as arguments, using the optional @launch_context to get information 638 * about the details of the launcher (like what screen it is on). 639 * On error, @error will be set accordingly. 640 * 641 * To launch the application without arguments pass a %NULL @uris list. 642 * 643 * Note that even if the launch is successful the application launched 644 * can fail to start if it runs into problems during startup. There is 645 * no way to detect this. 646 * 647 * Params: 648 * uris = a #GList containing URIs to launch. 649 * launchContext = a #GAppLaunchContext or %NULL 650 * 651 * Return: %TRUE on successful launch, %FALSE otherwise. 652 * 653 * Throws: GException on failure. 654 */ 655 public bool launchUris(ListG uris, AppLaunchContext launchContext) 656 { 657 GError* err = null; 658 659 auto p = g_app_info_launch_uris(getAppInfoStruct(), (uris is null) ? null : uris.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), &err) != 0; 660 661 if (err !is null) 662 { 663 throw new GException( new ErrorG(err) ); 664 } 665 666 return p; 667 } 668 669 /** 670 * Removes a supported type from an application, if possible. 671 * 672 * Params: 673 * contentType = a string. 674 * 675 * Return: %TRUE on success, %FALSE on error. 676 * 677 * Throws: GException on failure. 678 */ 679 public bool removeSupportsType(string contentType) 680 { 681 GError* err = null; 682 683 auto p = g_app_info_remove_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 684 685 if (err !is null) 686 { 687 throw new GException( new ErrorG(err) ); 688 } 689 690 return p; 691 } 692 693 /** 694 * Sets the application as the default handler for the given file extension. 695 * 696 * Params: 697 * extension = a string containing the file extension 698 * (without the dot). 699 * 700 * Return: %TRUE on success, %FALSE on error. 701 * 702 * Throws: GException on failure. 703 */ 704 public bool setAsDefaultForExtension(string extension) 705 { 706 GError* err = null; 707 708 auto p = g_app_info_set_as_default_for_extension(getAppInfoStruct(), Str.toStringz(extension), &err) != 0; 709 710 if (err !is null) 711 { 712 throw new GException( new ErrorG(err) ); 713 } 714 715 return p; 716 } 717 718 /** 719 * Sets the application as the default handler for a given type. 720 * 721 * Params: 722 * contentType = the content type. 723 * 724 * Return: %TRUE on success, %FALSE on error. 725 * 726 * Throws: GException on failure. 727 */ 728 public bool setAsDefaultForType(string contentType) 729 { 730 GError* err = null; 731 732 auto p = g_app_info_set_as_default_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 733 734 if (err !is null) 735 { 736 throw new GException( new ErrorG(err) ); 737 } 738 739 return p; 740 } 741 742 /** 743 * Sets the application as the last used application for a given type. 744 * This will make the application appear as first in the list returned 745 * by g_app_info_get_recommended_for_type(), regardless of the default 746 * application for that content type. 747 * 748 * Params: 749 * contentType = the content type. 750 * 751 * Return: %TRUE on success, %FALSE on error. 752 * 753 * Throws: GException on failure. 754 */ 755 public bool setAsLastUsedForType(string contentType) 756 { 757 GError* err = null; 758 759 auto p = g_app_info_set_as_last_used_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 760 761 if (err !is null) 762 { 763 throw new GException( new ErrorG(err) ); 764 } 765 766 return p; 767 } 768 769 /** 770 * Checks if the application info should be shown in menus that 771 * list available applications. 772 * 773 * Return: %TRUE if the @appinfo should be shown, %FALSE otherwise. 774 */ 775 public bool shouldShow() 776 { 777 return g_app_info_should_show(getAppInfoStruct()) != 0; 778 } 779 780 /** 781 * Checks if the application accepts files as arguments. 782 * 783 * Return: %TRUE if the @appinfo supports files. 784 */ 785 public bool supportsFiles() 786 { 787 return g_app_info_supports_files(getAppInfoStruct()) != 0; 788 } 789 790 /** 791 * Checks if the application supports reading files and directories from URIs. 792 * 793 * Return: %TRUE if the @appinfo supports URIs. 794 */ 795 public bool supportsUris() 796 { 797 return g_app_info_supports_uris(getAppInfoStruct()) != 0; 798 } 799 }