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.Application; 26 27 private import gio.ActionGroupIF; 28 private import gio.ActionGroupT; 29 private import gio.ActionMapIF; 30 private import gio.ActionMapT; 31 private import gio.ApplicationCommandLine; 32 private import gio.Cancellable; 33 private import gio.DBusConnection; 34 private import gio.File; 35 private import gio.FileIF; 36 private import gio.Notification; 37 private import glib.ConstructionException; 38 private import glib.ErrorG; 39 private import glib.GException; 40 private import glib.OptionGroup; 41 private import glib.Str; 42 private import glib.VariantDict; 43 private import gobject.ObjectG; 44 private import gobject.Signals; 45 public import gtkc.gdktypes; 46 private import gtkc.gio; 47 public import gtkc.giotypes; 48 49 50 /** 51 * A #GApplication is the foundation of an application. It wraps some 52 * low-level platform-specific services and is intended to act as the 53 * foundation for higher-level application classes such as 54 * #GtkApplication or #MxApplication. In general, you should not use 55 * this class outside of a higher level framework. 56 * 57 * GApplication provides convenient life cycle management by maintaining 58 * a "use count" for the primary application instance. The use count can 59 * be changed using g_application_hold() and g_application_release(). If 60 * it drops to zero, the application exits. Higher-level classes such as 61 * #GtkApplication employ the use count to ensure that the application 62 * stays alive as long as it has any opened windows. 63 * 64 * Another feature that GApplication (optionally) provides is process 65 * uniqueness. Applications can make use of this functionality by 66 * providing a unique application ID. If given, only one application 67 * with this ID can be running at a time per session. The session 68 * concept is platform-dependent, but corresponds roughly to a graphical 69 * desktop login. When your application is launched again, its 70 * arguments are passed through platform communication to the already 71 * running program. The already running instance of the program is 72 * called the "primary instance"; for non-unique applications this is 73 * the always the current instance. On Linux, the D-Bus session bus 74 * is used for communication. 75 * 76 * The use of #GApplication differs from some other commonly-used 77 * uniqueness libraries (such as libunique) in important ways. The 78 * application is not expected to manually register itself and check 79 * if it is the primary instance. Instead, the main() function of a 80 * #GApplication should do very little more than instantiating the 81 * application instance, possibly connecting signal handlers, then 82 * calling g_application_run(). All checks for uniqueness are done 83 * internally. If the application is the primary instance then the 84 * startup signal is emitted and the mainloop runs. If the application 85 * is not the primary instance then a signal is sent to the primary 86 * instance and g_application_run() promptly returns. See the code 87 * examples below. 88 * 89 * If used, the expected form of an application identifier is very close 90 * to that of of a 91 * [DBus bus name](http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface). 92 * Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator". 93 * For details on valid application identifiers, see g_application_id_is_valid(). 94 * 95 * On Linux, the application identifier is claimed as a well-known bus name 96 * on the user's session bus. This means that the uniqueness of your 97 * application is scoped to the current session. It also means that your 98 * application may provide additional services (through registration of other 99 * object paths) at that bus name. The registration of these object paths 100 * should be done with the shared GDBus session bus. Note that due to the 101 * internal architecture of GDBus, method calls can be dispatched at any time 102 * (even if a main loop is not running). For this reason, you must ensure that 103 * any object paths that you wish to register are registered before #GApplication 104 * attempts to acquire the bus name of your application (which happens in 105 * g_application_register()). Unfortunately, this means that you cannot use 106 * g_application_get_is_remote() to decide if you want to register object paths. 107 * 108 * GApplication also implements the #GActionGroup and #GActionMap 109 * interfaces and lets you easily export actions by adding them with 110 * g_action_map_add_action(). When invoking an action by calling 111 * g_action_group_activate_action() on the application, it is always 112 * invoked in the primary instance. The actions are also exported on 113 * the session bus, and GIO provides the #GDBusActionGroup wrapper to 114 * conveniently access them remotely. GIO provides a #GDBusMenuModel wrapper 115 * for remote access to exported #GMenuModels. 116 * 117 * There is a number of different entry points into a GApplication: 118 * 119 * - via 'Activate' (i.e. just starting the application) 120 * 121 * - via 'Open' (i.e. opening some files) 122 * 123 * - by handling a command-line 124 * 125 * - via activating an action 126 * 127 * The #GApplication::startup signal lets you handle the application 128 * initialization for all of these in a single place. 129 * 130 * Regardless of which of these entry points is used to start the 131 * application, GApplication passes some "platform data from the 132 * launching instance to the primary instance, in the form of a 133 * #GVariant dictionary mapping strings to variants. To use platform 134 * data, override the @before_emit or @after_emit virtual functions 135 * in your #GApplication subclass. When dealing with 136 * #GApplicationCommandLine objects, the platform data is 137 * directly available via g_application_command_line_get_cwd(), 138 * g_application_command_line_get_environ() and 139 * g_application_command_line_get_platform_data(). 140 * 141 * As the name indicates, the platform data may vary depending on the 142 * operating system, but it always includes the current directory (key 143 * "cwd"), and optionally the environment (ie the set of environment 144 * variables and their values) of the calling process (key "environ"). 145 * The environment is only added to the platform data if the 146 * %G_APPLICATION_SEND_ENVIRONMENT flag is set. #GApplication subclasses 147 * can add their own platform data by overriding the @add_platform_data 148 * virtual function. For instance, #GtkApplication adds startup notification 149 * data in this way. 150 * 151 * To parse commandline arguments you may handle the 152 * #GApplication::command-line signal or override the local_command_line() 153 * vfunc, to parse them in either the primary instance or the local instance, 154 * respectively. 155 * 156 * For an example of opening files with a GApplication, see 157 * [gapplication-example-open.c](https://git.gnome.org/browse/glib/tree/gio/tests/gapplication-example-open.c). 158 * 159 * For an example of using actions with GApplication, see 160 * [gapplication-example-actions.c](https://git.gnome.org/browse/glib/tree/gio/tests/gapplication-example-actions.c). 161 * 162 * For an example of using extra D-Bus hooks with GApplication, see 163 * [gapplication-example-dbushooks.c](https://git.gnome.org/browse/glib/tree/gio/tests/gapplication-example-dbushooks.c). 164 * 165 * Since: 2.28 166 */ 167 public class Application : ObjectG, ActionGroupIF, ActionMapIF 168 { 169 /** the main Gtk struct */ 170 protected GApplication* gApplication; 171 172 /** Get the main Gtk struct */ 173 public GApplication* getApplicationStruct() 174 { 175 return gApplication; 176 } 177 178 /** the main Gtk struct as a void* */ 179 protected override void* getStruct() 180 { 181 return cast(void*)gApplication; 182 } 183 184 protected override void setStruct(GObject* obj) 185 { 186 gApplication = cast(GApplication*)obj; 187 super.setStruct(obj); 188 } 189 190 /** 191 * Sets our main struct and passes it to the parent class. 192 */ 193 public this (GApplication* gApplication, bool ownedRef = false) 194 { 195 this.gApplication = gApplication; 196 super(cast(GObject*)gApplication, ownedRef); 197 } 198 199 // add the ActionGroup capabilities 200 mixin ActionGroupT!(GApplication); 201 202 // add the ActionMap capabilities 203 mixin ActionMapT!(GApplication); 204 205 /** 206 */ 207 208 public static GType getType() 209 { 210 return g_application_get_type(); 211 } 212 213 /** 214 * Creates a new #GApplication instance. 215 * 216 * If non-%NULL, the application id must be valid. See 217 * g_application_id_is_valid(). 218 * 219 * If no application ID is given then some features of #GApplication 220 * (most notably application uniqueness) will be disabled. 221 * 222 * Params: 223 * applicationId = the application id 224 * flags = the application flags 225 * 226 * Return: a new #GApplication instance 227 * 228 * Throws: ConstructionException GTK+ fails to create the object. 229 */ 230 public this(string applicationId, GApplicationFlags flags) 231 { 232 auto p = g_application_new(Str.toStringz(applicationId), flags); 233 234 if(p is null) 235 { 236 throw new ConstructionException("null returned by new"); 237 } 238 239 this(cast(GApplication*) p, true); 240 } 241 242 /** 243 * Returns the default #GApplication instance for this process. 244 * 245 * Normally there is only one #GApplication per process and it becomes 246 * the default when it is created. You can exercise more control over 247 * this by using g_application_set_default(). 248 * 249 * If there is no default application then %NULL is returned. 250 * 251 * Return: the default application for this process, or %NULL 252 * 253 * Since: 2.32 254 */ 255 public static Application getDefault() 256 { 257 auto p = g_application_get_default(); 258 259 if(p is null) 260 { 261 return null; 262 } 263 264 return ObjectG.getDObject!(Application)(cast(GApplication*) p); 265 } 266 267 /** 268 * Checks if @application_id is a valid application identifier. 269 * 270 * A valid ID is required for calls to g_application_new() and 271 * g_application_set_application_id(). 272 * 273 * For convenience, the restrictions on application identifiers are 274 * reproduced here: 275 * 276 * - Application identifiers must contain only the ASCII characters 277 * "[A-Z][a-z][0-9]_-." and must not begin with a digit. 278 * 279 * - Application identifiers must contain at least one '.' (period) 280 * character (and thus at least three elements). 281 * 282 * - Application identifiers must not begin or end with a '.' (period) 283 * character. 284 * 285 * - Application identifiers must not contain consecutive '.' (period) 286 * characters. 287 * 288 * - Application identifiers must not exceed 255 characters. 289 * 290 * Params: 291 * applicationId = a potential application identifier 292 * 293 * Return: %TRUE if @application_id is valid 294 */ 295 public static bool idIsValid(string applicationId) 296 { 297 return g_application_id_is_valid(Str.toStringz(applicationId)) != 0; 298 } 299 300 /** 301 * Activates the application. 302 * 303 * In essence, this results in the #GApplication::activate signal being 304 * emitted in the primary instance. 305 * 306 * The application must be registered before calling this function. 307 * 308 * Since: 2.28 309 */ 310 public void activate() 311 { 312 g_application_activate(gApplication); 313 } 314 315 /** 316 * Add an option to be handled by @application. 317 * 318 * Calling this function is the equivalent of calling 319 * g_application_add_main_option_entries() with a single #GOptionEntry 320 * that has its arg_data member set to %NULL. 321 * 322 * The parsed arguments will be packed into a #GVariantDict which 323 * is passed to #GApplication::handle-local-options. If 324 * %G_APPLICATION_HANDLES_COMMAND_LINE is set, then it will also 325 * be sent to the primary instance. See 326 * g_application_add_main_option_entries() for more details. 327 * 328 * See #GOptionEntry for more documentation of the arguments. 329 * 330 * Params: 331 * longName = the long name of an option used to specify it in a commandline 332 * shortName = the short name of an option 333 * flags = flags from #GOptionFlags 334 * arg = the type of the option, as a #GOptionArg 335 * description = the description for the option in `--help` output 336 * argDescription = the placeholder to use for the extra argument 337 * parsed by the option in `--help` output 338 * 339 * Since: 2.42 340 */ 341 public void addMainOption(string longName, char shortName, GOptionFlags flags, GOptionArg arg, string description, string argDescription) 342 { 343 g_application_add_main_option(gApplication, Str.toStringz(longName), shortName, flags, arg, Str.toStringz(description), Str.toStringz(argDescription)); 344 } 345 346 /** 347 * Adds main option entries to be handled by @application. 348 * 349 * This function is comparable to g_option_context_add_main_entries(). 350 * 351 * After the commandline arguments are parsed, the 352 * #GApplication::handle-local-options signal will be emitted. At this 353 * point, the application can inspect the values pointed to by @arg_data 354 * in the given #GOptionEntrys. 355 * 356 * Unlike #GOptionContext, #GApplication supports giving a %NULL 357 * @arg_data for a non-callback #GOptionEntry. This results in the 358 * argument in question being packed into a #GVariantDict which is also 359 * passed to #GApplication::handle-local-options, where it can be 360 * inspected and modified. If %G_APPLICATION_HANDLES_COMMAND_LINE is 361 * set, then the resulting dictionary is sent to the primary instance, 362 * where g_application_command_line_get_options_dict() will return it. 363 * This "packing" is done according to the type of the argument -- 364 * booleans for normal flags, strings for strings, bytestrings for 365 * filenames, etc. The packing only occurs if the flag is given (ie: we 366 * do not pack a "false" #GVariant in the case that a flag is missing). 367 * 368 * In general, it is recommended that all commandline arguments are 369 * parsed locally. The options dictionary should then be used to 370 * transmit the result of the parsing to the primary instance, where 371 * g_variant_dict_lookup() can be used. For local options, it is 372 * possible to either use @arg_data in the usual way, or to consult (and 373 * potentially remove) the option from the options dictionary. 374 * 375 * This function is new in GLib 2.40. Before then, the only real choice 376 * was to send all of the commandline arguments (options and all) to the 377 * primary instance for handling. #GApplication ignored them completely 378 * on the local side. Calling this function "opts in" to the new 379 * behaviour, and in particular, means that unrecognised options will be 380 * treated as errors. Unrecognised options have never been ignored when 381 * %G_APPLICATION_HANDLES_COMMAND_LINE is unset. 382 * 383 * If #GApplication::handle-local-options needs to see the list of 384 * filenames, then the use of %G_OPTION_REMAINING is recommended. If 385 * @arg_data is %NULL then %G_OPTION_REMAINING can be used as a key into 386 * the options dictionary. If you do use %G_OPTION_REMAINING then you 387 * need to handle these arguments for yourself because once they are 388 * consumed, they will no longer be visible to the default handling 389 * (which treats them as filenames to be opened). 390 * 391 * Params: 392 * entries = a 393 * %NULL-terminated list of #GOptionEntrys 394 * 395 * Since: 2.40 396 */ 397 public void addMainOptionEntries(GOptionEntry[] entries) 398 { 399 g_application_add_main_option_entries(gApplication, entries.ptr); 400 } 401 402 /** 403 * Adds a #GOptionGroup to the commandline handling of @application. 404 * 405 * This function is comparable to g_option_context_add_group(). 406 * 407 * Unlike g_application_add_main_option_entries(), this function does 408 * not deal with %NULL @arg_data and never transmits options to the 409 * primary instance. 410 * 411 * The reason for that is because, by the time the options arrive at the 412 * primary instance, it is typically too late to do anything with them. 413 * Taking the GTK option group as an example: GTK will already have been 414 * initialised by the time the #GApplication::command-line handler runs. 415 * In the case that this is not the first-running instance of the 416 * application, the existing instance may already have been running for 417 * a very long time. 418 * 419 * This means that the options from #GOptionGroup are only really usable 420 * in the case that the instance of the application being run is the 421 * first instance. Passing options like `--display=` or `--gdk-debug=` 422 * on future runs will have no effect on the existing primary instance. 423 * 424 * Calling this function will cause the options in the supplied option 425 * group to be parsed, but it does not cause you to be "opted in" to the 426 * new functionality whereby unrecognised options are rejected even if 427 * %G_APPLICATION_HANDLES_COMMAND_LINE was given. 428 * 429 * Params: 430 * group = a #GOptionGroup 431 * 432 * Since: 2.40 433 */ 434 public void addOptionGroup(OptionGroup group) 435 { 436 g_application_add_option_group(gApplication, (group is null) ? null : group.getOptionGroupStruct()); 437 } 438 439 /** 440 * Gets the unique identifier for @application. 441 * 442 * Return: the identifier for @application, owned by @application 443 * 444 * Since: 2.28 445 */ 446 public string getApplicationId() 447 { 448 return Str.toString(g_application_get_application_id(gApplication)); 449 } 450 451 /** 452 * Gets the #GDBusConnection being used by the application, or %NULL. 453 * 454 * If #GApplication is using its D-Bus backend then this function will 455 * return the #GDBusConnection being used for uniqueness and 456 * communication with the desktop environment and other instances of the 457 * application. 458 * 459 * If #GApplication is not using D-Bus then this function will return 460 * %NULL. This includes the situation where the D-Bus backend would 461 * normally be in use but we were unable to connect to the bus. 462 * 463 * This function must not be called before the application has been 464 * registered. See g_application_get_is_registered(). 465 * 466 * Return: a #GDBusConnection, or %NULL 467 * 468 * Since: 2.34 469 */ 470 public DBusConnection getDbusConnection() 471 { 472 auto p = g_application_get_dbus_connection(gApplication); 473 474 if(p is null) 475 { 476 return null; 477 } 478 479 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p); 480 } 481 482 /** 483 * Gets the D-Bus object path being used by the application, or %NULL. 484 * 485 * If #GApplication is using its D-Bus backend then this function will 486 * return the D-Bus object path that #GApplication is using. If the 487 * application is the primary instance then there is an object published 488 * at this path. If the application is not the primary instance then 489 * the result of this function is undefined. 490 * 491 * If #GApplication is not using D-Bus then this function will return 492 * %NULL. This includes the situation where the D-Bus backend would 493 * normally be in use but we were unable to connect to the bus. 494 * 495 * This function must not be called before the application has been 496 * registered. See g_application_get_is_registered(). 497 * 498 * Return: the object path, or %NULL 499 * 500 * Since: 2.34 501 */ 502 public string getDbusObjectPath() 503 { 504 return Str.toString(g_application_get_dbus_object_path(gApplication)); 505 } 506 507 /** 508 * Gets the flags for @application. 509 * 510 * See #GApplicationFlags. 511 * 512 * Return: the flags for @application 513 * 514 * Since: 2.28 515 */ 516 public GApplicationFlags getFlags() 517 { 518 return g_application_get_flags(gApplication); 519 } 520 521 /** 522 * Gets the current inactivity timeout for the application. 523 * 524 * This is the amount of time (in milliseconds) after the last call to 525 * g_application_release() before the application stops running. 526 * 527 * Return: the timeout, in milliseconds 528 * 529 * Since: 2.28 530 */ 531 public uint getInactivityTimeout() 532 { 533 return g_application_get_inactivity_timeout(gApplication); 534 } 535 536 /** 537 * Checks if @application is registered. 538 * 539 * An application is registered if g_application_register() has been 540 * successfully called. 541 * 542 * Return: %TRUE if @application is registered 543 * 544 * Since: 2.28 545 */ 546 public bool getIsRegistered() 547 { 548 return g_application_get_is_registered(gApplication) != 0; 549 } 550 551 /** 552 * Checks if @application is remote. 553 * 554 * If @application is remote then it means that another instance of 555 * application already exists (the 'primary' instance). Calls to 556 * perform actions on @application will result in the actions being 557 * performed by the primary instance. 558 * 559 * The value of this property cannot be accessed before 560 * g_application_register() has been called. See 561 * g_application_get_is_registered(). 562 * 563 * Return: %TRUE if @application is remote 564 * 565 * Since: 2.28 566 */ 567 public bool getIsRemote() 568 { 569 return g_application_get_is_remote(gApplication) != 0; 570 } 571 572 /** 573 * Gets the resource base path of @application. 574 * 575 * See g_application_set_resource_base_path() for more information. 576 * 577 * Return: the base resource path, if one is set 578 * 579 * Since: 2.42 580 */ 581 public string getResourceBasePath() 582 { 583 return Str.toString(g_application_get_resource_base_path(gApplication)); 584 } 585 586 /** 587 * Increases the use count of @application. 588 * 589 * Use this function to indicate that the application has a reason to 590 * continue to run. For example, g_application_hold() is called by GTK+ 591 * when a toplevel window is on the screen. 592 * 593 * To cancel the hold, call g_application_release(). 594 */ 595 public void hold() 596 { 597 g_application_hold(gApplication); 598 } 599 600 /** 601 * Increases the busy count of @application. 602 * 603 * Use this function to indicate that the application is busy, for instance 604 * while a long running operation is pending. 605 * 606 * The busy state will be exposed to other processes, so a session shell will 607 * use that information to indicate the state to the user (e.g. with a 608 * spinner). 609 * 610 * To cancel the busy indication, use g_application_unmark_busy(). 611 * 612 * Since: 2.38 613 */ 614 public void markBusy() 615 { 616 g_application_mark_busy(gApplication); 617 } 618 619 /** 620 * Opens the given files. 621 * 622 * In essence, this results in the #GApplication::open signal being emitted 623 * in the primary instance. 624 * 625 * @n_files must be greater than zero. 626 * 627 * @hint is simply passed through to the ::open signal. It is 628 * intended to be used by applications that have multiple modes for 629 * opening files (eg: "view" vs "edit", etc). Unless you have a need 630 * for this functionality, you should use "". 631 * 632 * The application must be registered before calling this function 633 * and it must have the %G_APPLICATION_HANDLES_OPEN flag set. 634 * 635 * Params: 636 * files = an array of #GFiles to open 637 * nFiles = the length of the @files array 638 * hint = a hint (or ""), but never %NULL 639 * 640 * Since: 2.28 641 */ 642 public void open(FileIF[] files, string hint) 643 { 644 GFile*[] filesArray = new GFile*[files.length]; 645 for ( int i = 0; i < files.length; i++ ) 646 { 647 filesArray[i] = files[i].getFileStruct(); 648 } 649 650 g_application_open(gApplication, filesArray.ptr, cast(int)files.length, Str.toStringz(hint)); 651 } 652 653 /** 654 * Immediately quits the application. 655 * 656 * Upon return to the mainloop, g_application_run() will return, 657 * calling only the 'shutdown' function before doing so. 658 * 659 * The hold count is ignored. 660 * 661 * The result of calling g_application_run() again after it returns is 662 * unspecified. 663 * 664 * Since: 2.32 665 */ 666 public void quit() 667 { 668 g_application_quit(gApplication); 669 } 670 671 /** 672 * Attempts registration of the application. 673 * 674 * This is the point at which the application discovers if it is the 675 * primary instance or merely acting as a remote for an already-existing 676 * primary instance. This is implemented by attempting to acquire the 677 * application identifier as a unique bus name on the session bus using 678 * GDBus. 679 * 680 * If there is no application ID or if %G_APPLICATION_NON_UNIQUE was 681 * given, then this process will always become the primary instance. 682 * 683 * Due to the internal architecture of GDBus, method calls can be 684 * dispatched at any time (even if a main loop is not running). For 685 * this reason, you must ensure that any object paths that you wish to 686 * register are registered before calling this function. 687 * 688 * If the application has already been registered then %TRUE is 689 * returned with no work performed. 690 * 691 * The #GApplication::startup signal is emitted if registration succeeds 692 * and @application is the primary instance (including the non-unique 693 * case). 694 * 695 * In the event of an error (such as @cancellable being cancelled, or a 696 * failure to connect to the session bus), %FALSE is returned and @error 697 * is set appropriately. 698 * 699 * Note: the return value of this function is not an indicator that this 700 * instance is or is not the primary instance of the application. See 701 * g_application_get_is_remote() for that. 702 * 703 * Params: 704 * cancellable = a #GCancellable, or %NULL 705 * 706 * Return: %TRUE if registration succeeded 707 * 708 * Since: 2.28 709 * 710 * Throws: GException on failure. 711 */ 712 public bool register(Cancellable cancellable) 713 { 714 GError* err = null; 715 716 auto p = g_application_register(gApplication, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 717 718 if (err !is null) 719 { 720 throw new GException( new ErrorG(err) ); 721 } 722 723 return p; 724 } 725 726 /** 727 * Decrease the use count of @application. 728 * 729 * When the use count reaches zero, the application will stop running. 730 * 731 * Never call this function except to cancel the effect of a previous 732 * call to g_application_hold(). 733 */ 734 public void release() 735 { 736 g_application_release(gApplication); 737 } 738 739 /** 740 * Runs the application. 741 * 742 * This function is intended to be run from main() and its return value 743 * is intended to be returned by main(). Although you are expected to pass 744 * the @argc, @argv parameters from main() to this function, it is possible 745 * to pass %NULL if @argv is not available or commandline handling is not 746 * required. Note that on Windows, @argc and @argv are ignored, and 747 * g_win32_get_command_line() is called internally (for proper support 748 * of Unicode commandline arguments). 749 * 750 * #GApplication will attempt to parse the commandline arguments. You 751 * can add commandline flags to the list of recognised options by way of 752 * g_application_add_main_option_entries(). After this, the 753 * #GApplication::handle-local-options signal is emitted, from which the 754 * application can inspect the values of its #GOptionEntrys. 755 * 756 * #GApplication::handle-local-options is a good place to handle options 757 * such as `--version`, where an immediate reply from the local process is 758 * desired (instead of communicating with an already-running instance). 759 * A #GApplication::handle-local-options handler can stop further processing 760 * by returning a non-negative value, which then becomes the exit status of 761 * the process. 762 * 763 * What happens next depends on the flags: if 764 * %G_APPLICATION_HANDLES_COMMAND_LINE was specified then the remaining 765 * commandline arguments are sent to the primary instance, where a 766 * #GApplication::command-line signal is emitted. Otherwise, the 767 * remaining commandline arguments are assumed to be a list of files. 768 * If there are no files listed, the application is activated via the 769 * #GApplication::activate signal. If there are one or more files, and 770 * %G_APPLICATION_HANDLES_OPEN was specified then the files are opened 771 * via the #GApplication::open signal. 772 * 773 * If you are interested in doing more complicated local handling of the 774 * commandline then you should implement your own #GApplication subclass 775 * and override local_command_line(). In this case, you most likely want 776 * to return %TRUE from your local_command_line() implementation to 777 * suppress the default handling. See 778 * [gapplication-example-cmdline2.c][gapplication-example-cmdline2] 779 * for an example. 780 * 781 * If, after the above is done, the use count of the application is zero 782 * then the exit status is returned immediately. If the use count is 783 * non-zero then the default main context is iterated until the use count 784 * falls to zero, at which point 0 is returned. 785 * 786 * If the %G_APPLICATION_IS_SERVICE flag is set, then the service will 787 * run for as much as 10 seconds with a use count of zero while waiting 788 * for the message that caused the activation to arrive. After that, 789 * if the use count falls to zero the application will exit immediately, 790 * except in the case that g_application_set_inactivity_timeout() is in 791 * use. 792 * 793 * This function sets the prgname (g_set_prgname()), if not already set, 794 * to the basename of argv[0]. Since 2.38, if %G_APPLICATION_IS_SERVICE 795 * is specified, the prgname is set to the application ID. The main 796 * impact of this is is that the wmclass of windows created by Gtk+ will 797 * be set accordingly, which helps the window manager determine which 798 * application is showing the window. 799 * 800 * Since 2.40, applications that are not explicitly flagged as services 801 * or launchers (ie: neither %G_APPLICATION_IS_SERVICE or 802 * %G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the 803 * default handler for local_command_line) if "--gapplication-service" 804 * was given in the command line. If this flag is present then normal 805 * commandline processing is interrupted and the 806 * %G_APPLICATION_IS_SERVICE flag is set. This provides a "compromise" 807 * solution whereby running an application directly from the commandline 808 * will invoke it in the normal way (which can be useful for debugging) 809 * while still allowing applications to be D-Bus activated in service 810 * mode. The D-Bus service file should invoke the executable with 811 * "--gapplication-service" as the sole commandline argument. This 812 * approach is suitable for use by most graphical applications but 813 * should not be used from applications like editors that need precise 814 * control over when processes invoked via the commandline will exit and 815 * what their exit status will be. 816 * 817 * Params: 818 * argc = the argc from main() (or 0 if @argv is %NULL) 819 * argv = the argv from main(), or %NULL 820 * 821 * Return: the exit status 822 * 823 * Since: 2.28 824 */ 825 public int run(string[] argv) 826 { 827 return g_application_run(gApplication, cast(int)argv.length, Str.toStringzArray(argv)); 828 } 829 830 /** 831 * Sends a notification on behalf of @application to the desktop shell. 832 * There is no guarantee that the notification is displayed immediately, 833 * or even at all. 834 * 835 * Notifications may persist after the application exits. It will be 836 * D-Bus-activated when the notification or one of its actions is 837 * activated. 838 * 839 * Modifying @notification after this call has no effect. However, the 840 * object can be reused for a later call to this function. 841 * 842 * @id may be any string that uniquely identifies the event for the 843 * application. It does not need to be in any special format. For 844 * example, "new-message" might be appropriate for a notification about 845 * new messages. 846 * 847 * If a previous notification was sent with the same @id, it will be 848 * replaced with @notification and shown again as if it was a new 849 * notification. This works even for notifications sent from a previous 850 * execution of the application, as long as @id is the same string. 851 * 852 * @id may be %NULL, but it is impossible to replace or withdraw 853 * notifications without an id. 854 * 855 * If @notification is no longer relevant, it can be withdrawn with 856 * g_application_withdraw_notification(). 857 * 858 * Params: 859 * id = id of the notification, or %NULL 860 * notification = the #GNotification to send 861 * 862 * Since: 2.40 863 */ 864 public void sendNotification(string id, Notification notification) 865 { 866 g_application_send_notification(gApplication, Str.toStringz(id), (notification is null) ? null : notification.getNotificationStruct()); 867 } 868 869 /** 870 * This used to be how actions were associated with a #GApplication. 871 * Now there is #GActionMap for that. 872 * 873 * Deprecated: Use the #GActionMap interface instead. Never ever 874 * mix use of this API with use of #GActionMap on the same @application 875 * or things will go very badly wrong. This function is known to 876 * introduce buggy behaviour (ie: signals not emitted on changes to the 877 * action group), so you should really use #GActionMap instead. 878 * 879 * Params: 880 * actionGroup = a #GActionGroup, or %NULL 881 * 882 * Since: 2.28 883 */ 884 public void setActionGroup(ActionGroupIF actionGroup) 885 { 886 g_application_set_action_group(gApplication, (actionGroup is null) ? null : actionGroup.getActionGroupStruct()); 887 } 888 889 /** 890 * Sets the unique identifier for @application. 891 * 892 * The application id can only be modified if @application has not yet 893 * been registered. 894 * 895 * If non-%NULL, the application id must be valid. See 896 * g_application_id_is_valid(). 897 * 898 * Params: 899 * applicationId = the identifier for @application 900 * 901 * Since: 2.28 902 */ 903 public void setApplicationId(string applicationId) 904 { 905 g_application_set_application_id(gApplication, Str.toStringz(applicationId)); 906 } 907 908 /** 909 * Sets or unsets the default application for the process, as returned 910 * by g_application_get_default(). 911 * 912 * This function does not take its own reference on @application. If 913 * @application is destroyed then the default application will revert 914 * back to %NULL. 915 * 916 * Since: 2.32 917 */ 918 public void setDefault() 919 { 920 g_application_set_default(gApplication); 921 } 922 923 /** 924 * Sets the flags for @application. 925 * 926 * The flags can only be modified if @application has not yet been 927 * registered. 928 * 929 * See #GApplicationFlags. 930 * 931 * Params: 932 * flags = the flags for @application 933 * 934 * Since: 2.28 935 */ 936 public void setFlags(GApplicationFlags flags) 937 { 938 g_application_set_flags(gApplication, flags); 939 } 940 941 /** 942 * Sets the current inactivity timeout for the application. 943 * 944 * This is the amount of time (in milliseconds) after the last call to 945 * g_application_release() before the application stops running. 946 * 947 * This call has no side effects of its own. The value set here is only 948 * used for next time g_application_release() drops the use count to 949 * zero. Any timeouts currently in progress are not impacted. 950 * 951 * Params: 952 * inactivityTimeout = the timeout, in milliseconds 953 * 954 * Since: 2.28 955 */ 956 public void setInactivityTimeout(uint inactivityTimeout) 957 { 958 g_application_set_inactivity_timeout(gApplication, inactivityTimeout); 959 } 960 961 /** 962 * Sets (or unsets) the base resource path of @application. 963 * 964 * The path is used to automatically load various [application 965 * resources][gresource] such as menu layouts and action descriptions. 966 * The various types of resources will be found at fixed names relative 967 * to the given base path. 968 * 969 * By default, the resource base path is determined from the application 970 * ID by prefixing '/' and replacing each '.' with '/'. This is done at 971 * the time that the #GApplication object is constructed. Changes to 972 * the application ID after that point will not have an impact on the 973 * resource base path. 974 * 975 * As an example, if the application has an ID of "org.example.app" then 976 * the default resource base path will be "/org/example/app". If this 977 * is a #GtkApplication (and you have not manually changed the path) 978 * then Gtk will then search for the menus of the application at 979 * "/org/example/app/gtk/menus.ui". 980 * 981 * See #GResource for more information about adding resources to your 982 * application. 983 * 984 * You can disable automatic resource loading functionality by setting 985 * the path to %NULL. 986 * 987 * Changing the resource base path once the application is running is 988 * not recommended. The point at which the resource path is consulted 989 * for forming paths for various purposes is unspecified. 990 * 991 * Params: 992 * resourcePath = the resource path to use 993 * 994 * Since: 2.42 995 */ 996 public void setResourceBasePath(string resourcePath) 997 { 998 g_application_set_resource_base_path(gApplication, Str.toStringz(resourcePath)); 999 } 1000 1001 /** 1002 * Decreases the busy count of @application. 1003 * 1004 * When the busy count reaches zero, the new state will be propagated 1005 * to other processes. 1006 * 1007 * This function must only be called to cancel the effect of a previous 1008 * call to g_application_mark_busy(). 1009 * 1010 * Since: 2.38 1011 */ 1012 public void unmarkBusy() 1013 { 1014 g_application_unmark_busy(gApplication); 1015 } 1016 1017 /** 1018 * Withdraws a notification that was sent with 1019 * g_application_send_notification(). 1020 * 1021 * This call does nothing if a notification with @id doesn't exist or 1022 * the notification was never sent. 1023 * 1024 * This function works even for notifications sent in previous 1025 * executions of this application, as long @id is the same as it was for 1026 * the sent notification. 1027 * 1028 * Note that notifications are dismissed when the user clicks on one 1029 * of the buttons in a notification or triggers its default action, so 1030 * there is no need to explicitly withdraw the notification in that case. 1031 * 1032 * Params: 1033 * id = id of a previously sent notification 1034 * 1035 * Since: 2.40 1036 */ 1037 public void withdrawNotification(string id) 1038 { 1039 g_application_withdraw_notification(gApplication, Str.toStringz(id)); 1040 } 1041 1042 int[string] connectedSignals; 1043 1044 void delegate(Application)[] onActivateListeners; 1045 /** 1046 * The ::activate signal is emitted on the primary instance when an 1047 * activation occurs. See g_application_activate(). 1048 */ 1049 void addOnActivate(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1050 { 1051 if ( "activate" !in connectedSignals ) 1052 { 1053 Signals.connectData( 1054 this, 1055 "activate", 1056 cast(GCallback)&callBackActivate, 1057 cast(void*)this, 1058 null, 1059 connectFlags); 1060 connectedSignals["activate"] = 1; 1061 } 1062 onActivateListeners ~= dlg; 1063 } 1064 extern(C) static void callBackActivate(GApplication* applicationStruct, Application _application) 1065 { 1066 foreach ( void delegate(Application) dlg; _application.onActivateListeners ) 1067 { 1068 dlg(_application); 1069 } 1070 } 1071 1072 int delegate(ApplicationCommandLine, Application)[] onCommandLineListeners; 1073 /** 1074 * The ::command-line signal is emitted on the primary instance when 1075 * a commandline is not handled locally. See g_application_run() and 1076 * the #GApplicationCommandLine documentation for more information. 1077 * 1078 * Params: 1079 * commandLine = a #GApplicationCommandLine representing the 1080 * passed commandline 1081 * 1082 * Return: An integer that is set as the exit status for the calling 1083 * process. See g_application_command_line_set_exit_status(). 1084 */ 1085 void addOnCommandLine(int delegate(ApplicationCommandLine, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1086 { 1087 if ( "command-line" !in connectedSignals ) 1088 { 1089 Signals.connectData( 1090 this, 1091 "command-line", 1092 cast(GCallback)&callBackCommandLine, 1093 cast(void*)this, 1094 null, 1095 connectFlags); 1096 connectedSignals["command-line"] = 1; 1097 } 1098 onCommandLineListeners ~= dlg; 1099 } 1100 extern(C) static int callBackCommandLine(GApplication* applicationStruct, GApplicationCommandLine* commandLine, Application _application) 1101 { 1102 return _application.onCommandLineListeners[0](ObjectG.getDObject!(ApplicationCommandLine)(commandLine), _application); 1103 } 1104 1105 int delegate(VariantDict, Application)[] onHandleLocalOptionsListeners; 1106 /** 1107 * The ::handle-local-options signal is emitted on the local instance 1108 * after the parsing of the commandline options has occurred. 1109 * 1110 * You can add options to be recognised during commandline option 1111 * parsing using g_application_add_main_option_entries() and 1112 * g_application_add_option_group(). 1113 * 1114 * Signal handlers can inspect @options (along with values pointed to 1115 * from the @arg_data of an installed #GOptionEntrys) in order to 1116 * decide to perform certain actions, including direct local handling 1117 * (which may be useful for options like --version). 1118 * 1119 * In the event that the application is marked 1120 * %G_APPLICATION_HANDLES_COMMAND_LINE the "normal processing" will 1121 * send the @option dictionary to the primary instance where it can be 1122 * read with g_application_command_line_get_options(). The signal 1123 * handler can modify the dictionary before returning, and the 1124 * modified dictionary will be sent. 1125 * 1126 * In the event that %G_APPLICATION_HANDLES_COMMAND_LINE is not set, 1127 * "normal processing" will treat the remaining uncollected command 1128 * line arguments as filenames or URIs. If there are no arguments, 1129 * the application is activated by g_application_activate(). One or 1130 * more arguments results in a call to g_application_open(). 1131 * 1132 * If you want to handle the local commandline arguments for yourself 1133 * by converting them to calls to g_application_open() or 1134 * g_action_group_activate_action() then you must be sure to register 1135 * the application first. You should probably not call 1136 * g_application_activate() for yourself, however: just return -1 and 1137 * allow the default handler to do it for you. This will ensure that 1138 * the `--gapplication-service` switch works properly (i.e. no activation 1139 * in that case). 1140 * 1141 * Note that this signal is emitted from the default implementation of 1142 * local_command_line(). If you override that function and don't 1143 * chain up then this signal will never be emitted. 1144 * 1145 * You can override local_command_line() if you need more powerful 1146 * capabilities than what is provided here, but this should not 1147 * normally be required. 1148 * 1149 * Params: 1150 * options = the options dictionary 1151 * 1152 * Return: an exit code. If you have handled your options and want 1153 * to exit the process, return a non-negative option, 0 for success, 1154 * and a positive value for failure. To continue, return -1 to let 1155 * the default option processing continue. 1156 * 1157 * Since: 2.40 1158 */ 1159 void addOnHandleLocalOptions(int delegate(VariantDict, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1160 { 1161 if ( "handle-local-options" !in connectedSignals ) 1162 { 1163 Signals.connectData( 1164 this, 1165 "handle-local-options", 1166 cast(GCallback)&callBackHandleLocalOptions, 1167 cast(void*)this, 1168 null, 1169 connectFlags); 1170 connectedSignals["handle-local-options"] = 1; 1171 } 1172 onHandleLocalOptionsListeners ~= dlg; 1173 } 1174 extern(C) static int callBackHandleLocalOptions(GApplication* applicationStruct, GVariantDict* options, Application _application) 1175 { 1176 return _application.onHandleLocalOptionsListeners[0](new VariantDict(options), _application); 1177 } 1178 1179 void delegate(void*, int, string, Application)[] onOpenListeners; 1180 /** 1181 * The ::open signal is emitted on the primary instance when there are 1182 * files to open. See g_application_open() for more information. 1183 * 1184 * Params: 1185 * files = an array of #GFiles 1186 * nFiles = the length of @files 1187 * hint = a hint provided by the calling instance 1188 */ 1189 void addOnOpen(void delegate(void*, int, string, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1190 { 1191 if ( "open" !in connectedSignals ) 1192 { 1193 Signals.connectData( 1194 this, 1195 "open", 1196 cast(GCallback)&callBackOpen, 1197 cast(void*)this, 1198 null, 1199 connectFlags); 1200 connectedSignals["open"] = 1; 1201 } 1202 onOpenListeners ~= dlg; 1203 } 1204 extern(C) static void callBackOpen(GApplication* applicationStruct, void* files, int nFiles, char* hint, Application _application) 1205 { 1206 foreach ( void delegate(void*, int, string, Application) dlg; _application.onOpenListeners ) 1207 { 1208 dlg(files, nFiles, Str.toString(hint), _application); 1209 } 1210 } 1211 1212 void delegate(Application)[] onShutdownListeners; 1213 /** 1214 * The ::shutdown signal is emitted only on the registered primary instance 1215 * immediately after the main loop terminates. 1216 */ 1217 void addOnShutdown(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1218 { 1219 if ( "shutdown" !in connectedSignals ) 1220 { 1221 Signals.connectData( 1222 this, 1223 "shutdown", 1224 cast(GCallback)&callBackShutdown, 1225 cast(void*)this, 1226 null, 1227 connectFlags); 1228 connectedSignals["shutdown"] = 1; 1229 } 1230 onShutdownListeners ~= dlg; 1231 } 1232 extern(C) static void callBackShutdown(GApplication* applicationStruct, Application _application) 1233 { 1234 foreach ( void delegate(Application) dlg; _application.onShutdownListeners ) 1235 { 1236 dlg(_application); 1237 } 1238 } 1239 1240 void delegate(Application)[] onStartupListeners; 1241 /** 1242 * The ::startup signal is emitted on the primary instance immediately 1243 * after registration. See g_application_register(). 1244 */ 1245 void addOnStartup(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1246 { 1247 if ( "startup" !in connectedSignals ) 1248 { 1249 Signals.connectData( 1250 this, 1251 "startup", 1252 cast(GCallback)&callBackStartup, 1253 cast(void*)this, 1254 null, 1255 connectFlags); 1256 connectedSignals["startup"] = 1; 1257 } 1258 onStartupListeners ~= dlg; 1259 } 1260 extern(C) static void callBackStartup(GApplication* applicationStruct, Application _application) 1261 { 1262 foreach ( void delegate(Application) dlg; _application.onStartupListeners ) 1263 { 1264 dlg(_application); 1265 } 1266 } 1267 }