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.FileIF; 35 private import gio.Notification; 36 private import gio.c.functions; 37 public import gio.c.types; 38 private import glib.ConstructionException; 39 private import glib.ErrorG; 40 private import glib.GException; 41 private import glib.OptionGroup; 42 private import glib.Str; 43 private import glib.VariantDict; 44 private import gobject.ObjectG; 45 private import gobject.Signals; 46 public import gtkc.giotypes; 47 private import std.algorithm; 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 * [D-Bus 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(bool transferOwnership = false) 174 { 175 if (transferOwnership) 176 ownedRef = false; 177 return gApplication; 178 } 179 180 /** the main Gtk struct as a void* */ 181 protected override void* getStruct() 182 { 183 return cast(void*)gApplication; 184 } 185 186 protected override void setStruct(GObject* obj) 187 { 188 gApplication = cast(GApplication*)obj; 189 super.setStruct(obj); 190 } 191 192 /** 193 * Sets our main struct and passes it to the parent class. 194 */ 195 public this (GApplication* gApplication, bool ownedRef = false) 196 { 197 this.gApplication = gApplication; 198 super(cast(GObject*)gApplication, ownedRef); 199 } 200 201 // add the ActionGroup capabilities 202 mixin ActionGroupT!(GApplication); 203 204 // add the ActionMap capabilities 205 mixin ActionMapT!(GApplication); 206 207 protected class ScopedOnCommandLineDelegateWrapper 208 { 209 int delegate(Scoped!ApplicationCommandLine, Application) dlg; 210 gulong handlerId; 211 212 this(int delegate(Scoped!ApplicationCommandLine, Application) dlg) 213 { 214 this.dlg = dlg; 215 scopedOnCommandLineListeners ~= this; 216 } 217 218 void remove(ScopedOnCommandLineDelegateWrapper source) 219 { 220 foreach(index, wrapper; scopedOnCommandLineListeners) 221 { 222 if (wrapper.handlerId == source.handlerId) 223 { 224 scopedOnCommandLineListeners[index] = null; 225 scopedOnCommandLineListeners = std.algorithm.remove(scopedOnCommandLineListeners, index); 226 break; 227 } 228 } 229 } 230 } 231 ScopedOnCommandLineDelegateWrapper[] scopedOnCommandLineListeners; 232 233 /** 234 * The ::command-line signal is emitted on the primary instance when 235 * a commandline is not handled locally. See g_application_run() and 236 * the #GApplicationCommandLine documentation for more information. 237 * 238 * Params: 239 * commandLine = a #GApplicationCommandLine representing the 240 * passed commandline 241 * 242 * Return: An integer that is set as the exit status for the calling 243 * process. See g_application_command_line_set_exit_status(). 244 */ 245 gulong addOnCommandLine(int delegate(Scoped!ApplicationCommandLine, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 246 { 247 auto wrapper = new ScopedOnCommandLineDelegateWrapper(dlg); 248 wrapper.handlerId = Signals.connectData( 249 this, 250 "command-line", 251 cast(GCallback)&callBackScopedCommandLine, 252 cast(void*)wrapper, 253 cast(GClosureNotify)&callBackScopedCommandLineDestroy, 254 connectFlags); 255 return wrapper.handlerId; 256 } 257 258 extern(C) static int callBackScopedCommandLine(GApplication* applicationStruct, GApplicationCommandLine* commandLine, ScopedOnCommandLineDelegateWrapper wrapper) 259 { 260 return wrapper.dlg(getScopedGobject!ApplicationCommandLine(commandLine), wrapper.outer); 261 } 262 263 extern(C) static void callBackScopedCommandLineDestroy(ScopedOnCommandLineDelegateWrapper wrapper, GClosure* closure) 264 { 265 wrapper.remove(wrapper); 266 } 267 268 /** 269 */ 270 271 /** */ 272 public static GType getType() 273 { 274 return g_application_get_type(); 275 } 276 277 /** 278 * Creates a new #GApplication instance. 279 * 280 * If non-%NULL, the application id must be valid. See 281 * g_application_id_is_valid(). 282 * 283 * If no application ID is given then some features of #GApplication 284 * (most notably application uniqueness) will be disabled. 285 * 286 * Params: 287 * applicationId = the application id 288 * flags = the application flags 289 * 290 * Returns: a new #GApplication instance 291 * 292 * Throws: ConstructionException GTK+ fails to create the object. 293 */ 294 public this(string applicationId, GApplicationFlags flags) 295 { 296 auto p = g_application_new(Str.toStringz(applicationId), flags); 297 298 if(p is null) 299 { 300 throw new ConstructionException("null returned by new"); 301 } 302 303 this(cast(GApplication*) p, true); 304 } 305 306 /** 307 * Returns the default #GApplication instance for this process. 308 * 309 * Normally there is only one #GApplication per process and it becomes 310 * the default when it is created. You can exercise more control over 311 * this by using g_application_set_default(). 312 * 313 * If there is no default application then %NULL is returned. 314 * 315 * Returns: the default application for this process, or %NULL 316 * 317 * Since: 2.32 318 */ 319 public static Application getDefault() 320 { 321 auto p = g_application_get_default(); 322 323 if(p is null) 324 { 325 return null; 326 } 327 328 return ObjectG.getDObject!(Application)(cast(GApplication*) p); 329 } 330 331 /** 332 * Checks if @application_id is a valid application identifier. 333 * 334 * A valid ID is required for calls to g_application_new() and 335 * g_application_set_application_id(). 336 * 337 * For convenience, the restrictions on application identifiers are 338 * reproduced here: 339 * 340 * - Application identifiers must contain only the ASCII characters 341 * "[A-Z][a-z][0-9]_-." and must not begin with a digit. 342 * 343 * - Application identifiers must contain at least one '.' (period) 344 * character (and thus at least two elements). 345 * 346 * - Application identifiers must not begin or end with a '.' (period) 347 * character. 348 * 349 * - Application identifiers must not contain consecutive '.' (period) 350 * characters. 351 * 352 * - Application identifiers must not exceed 255 characters. 353 * 354 * Params: 355 * applicationId = a potential application identifier 356 * 357 * Returns: %TRUE if @application_id is valid 358 */ 359 public static bool idIsValid(string applicationId) 360 { 361 return g_application_id_is_valid(Str.toStringz(applicationId)) != 0; 362 } 363 364 /** 365 * Activates the application. 366 * 367 * In essence, this results in the #GApplication::activate signal being 368 * emitted in the primary instance. 369 * 370 * The application must be registered before calling this function. 371 * 372 * Since: 2.28 373 */ 374 public void activate() 375 { 376 g_application_activate(gApplication); 377 } 378 379 /** 380 * Add an option to be handled by @application. 381 * 382 * Calling this function is the equivalent of calling 383 * g_application_add_main_option_entries() with a single #GOptionEntry 384 * that has its arg_data member set to %NULL. 385 * 386 * The parsed arguments will be packed into a #GVariantDict which 387 * is passed to #GApplication::handle-local-options. If 388 * %G_APPLICATION_HANDLES_COMMAND_LINE is set, then it will also 389 * be sent to the primary instance. See 390 * g_application_add_main_option_entries() for more details. 391 * 392 * See #GOptionEntry for more documentation of the arguments. 393 * 394 * Params: 395 * longName = the long name of an option used to specify it in a commandline 396 * shortName = the short name of an option 397 * flags = flags from #GOptionFlags 398 * arg = the type of the option, as a #GOptionArg 399 * description = the description for the option in `--help` output 400 * argDescription = the placeholder to use for the extra argument 401 * parsed by the option in `--help` output 402 * 403 * Since: 2.42 404 */ 405 public void addMainOption(string longName, char shortName, GOptionFlags flags, GOptionArg arg, string description, string argDescription) 406 { 407 g_application_add_main_option(gApplication, Str.toStringz(longName), shortName, flags, arg, Str.toStringz(description), Str.toStringz(argDescription)); 408 } 409 410 /** 411 * Adds main option entries to be handled by @application. 412 * 413 * This function is comparable to g_option_context_add_main_entries(). 414 * 415 * After the commandline arguments are parsed, the 416 * #GApplication::handle-local-options signal will be emitted. At this 417 * point, the application can inspect the values pointed to by @arg_data 418 * in the given #GOptionEntrys. 419 * 420 * Unlike #GOptionContext, #GApplication supports giving a %NULL 421 * @arg_data for a non-callback #GOptionEntry. This results in the 422 * argument in question being packed into a #GVariantDict which is also 423 * passed to #GApplication::handle-local-options, where it can be 424 * inspected and modified. If %G_APPLICATION_HANDLES_COMMAND_LINE is 425 * set, then the resulting dictionary is sent to the primary instance, 426 * where g_application_command_line_get_options_dict() will return it. 427 * This "packing" is done according to the type of the argument -- 428 * booleans for normal flags, strings for strings, bytestrings for 429 * filenames, etc. The packing only occurs if the flag is given (ie: we 430 * do not pack a "false" #GVariant in the case that a flag is missing). 431 * 432 * In general, it is recommended that all commandline arguments are 433 * parsed locally. The options dictionary should then be used to 434 * transmit the result of the parsing to the primary instance, where 435 * g_variant_dict_lookup() can be used. For local options, it is 436 * possible to either use @arg_data in the usual way, or to consult (and 437 * potentially remove) the option from the options dictionary. 438 * 439 * This function is new in GLib 2.40. Before then, the only real choice 440 * was to send all of the commandline arguments (options and all) to the 441 * primary instance for handling. #GApplication ignored them completely 442 * on the local side. Calling this function "opts in" to the new 443 * behaviour, and in particular, means that unrecognised options will be 444 * treated as errors. Unrecognised options have never been ignored when 445 * %G_APPLICATION_HANDLES_COMMAND_LINE is unset. 446 * 447 * If #GApplication::handle-local-options needs to see the list of 448 * filenames, then the use of %G_OPTION_REMAINING is recommended. If 449 * @arg_data is %NULL then %G_OPTION_REMAINING can be used as a key into 450 * the options dictionary. If you do use %G_OPTION_REMAINING then you 451 * need to handle these arguments for yourself because once they are 452 * consumed, they will no longer be visible to the default handling 453 * (which treats them as filenames to be opened). 454 * 455 * It is important to use the proper GVariant format when retrieving 456 * the options with g_variant_dict_lookup(): 457 * - for %G_OPTION_ARG_NONE, use b 458 * - for %G_OPTION_ARG_STRING, use &s 459 * - for %G_OPTION_ARG_INT, use i 460 * - for %G_OPTION_ARG_INT64, use x 461 * - for %G_OPTION_ARG_DOUBLE, use d 462 * - for %G_OPTION_ARG_FILENAME, use ^ay 463 * - for %G_OPTION_ARG_STRING_ARRAY, use &as 464 * - for %G_OPTION_ARG_FILENAME_ARRAY, use ^aay 465 * 466 * Params: 467 * entries = a 468 * %NULL-terminated list of #GOptionEntrys 469 * 470 * Since: 2.40 471 */ 472 public void addMainOptionEntries(GOptionEntry[] entries) 473 { 474 g_application_add_main_option_entries(gApplication, entries.ptr); 475 } 476 477 /** 478 * Adds a #GOptionGroup to the commandline handling of @application. 479 * 480 * This function is comparable to g_option_context_add_group(). 481 * 482 * Unlike g_application_add_main_option_entries(), this function does 483 * not deal with %NULL @arg_data and never transmits options to the 484 * primary instance. 485 * 486 * The reason for that is because, by the time the options arrive at the 487 * primary instance, it is typically too late to do anything with them. 488 * Taking the GTK option group as an example: GTK will already have been 489 * initialised by the time the #GApplication::command-line handler runs. 490 * In the case that this is not the first-running instance of the 491 * application, the existing instance may already have been running for 492 * a very long time. 493 * 494 * This means that the options from #GOptionGroup are only really usable 495 * in the case that the instance of the application being run is the 496 * first instance. Passing options like `--display=` or `--gdk-debug=` 497 * on future runs will have no effect on the existing primary instance. 498 * 499 * Calling this function will cause the options in the supplied option 500 * group to be parsed, but it does not cause you to be "opted in" to the 501 * new functionality whereby unrecognised options are rejected even if 502 * %G_APPLICATION_HANDLES_COMMAND_LINE was given. 503 * 504 * Params: 505 * group = a #GOptionGroup 506 * 507 * Since: 2.40 508 */ 509 public void addOptionGroup(OptionGroup group) 510 { 511 g_application_add_option_group(gApplication, (group is null) ? null : group.getOptionGroupStruct(true)); 512 } 513 514 /** 515 * Marks @application as busy (see g_application_mark_busy()) while 516 * @property on @object is %TRUE. 517 * 518 * The binding holds a reference to @application while it is active, but 519 * not to @object. Instead, the binding is destroyed when @object is 520 * finalized. 521 * 522 * Params: 523 * object = a #GObject 524 * property = the name of a boolean property of @object 525 * 526 * Since: 2.44 527 */ 528 public void bindBusyProperty(ObjectG object, string property) 529 { 530 g_application_bind_busy_property(gApplication, (object is null) ? null : object.getObjectGStruct(), Str.toStringz(property)); 531 } 532 533 /** 534 * Gets the unique identifier for @application. 535 * 536 * Returns: the identifier for @application, owned by @application 537 * 538 * Since: 2.28 539 */ 540 public string getApplicationId() 541 { 542 return Str.toString(g_application_get_application_id(gApplication)); 543 } 544 545 /** 546 * Gets the #GDBusConnection being used by the application, or %NULL. 547 * 548 * If #GApplication is using its D-Bus backend then this function will 549 * return the #GDBusConnection being used for uniqueness and 550 * communication with the desktop environment and other instances of the 551 * application. 552 * 553 * If #GApplication is not using D-Bus then this function will return 554 * %NULL. This includes the situation where the D-Bus backend would 555 * normally be in use but we were unable to connect to the bus. 556 * 557 * This function must not be called before the application has been 558 * registered. See g_application_get_is_registered(). 559 * 560 * Returns: a #GDBusConnection, or %NULL 561 * 562 * Since: 2.34 563 */ 564 public DBusConnection getDbusConnection() 565 { 566 auto p = g_application_get_dbus_connection(gApplication); 567 568 if(p is null) 569 { 570 return null; 571 } 572 573 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p); 574 } 575 576 /** 577 * Gets the D-Bus object path being used by the application, or %NULL. 578 * 579 * If #GApplication is using its D-Bus backend then this function will 580 * return the D-Bus object path that #GApplication is using. If the 581 * application is the primary instance then there is an object published 582 * at this path. If the application is not the primary instance then 583 * the result of this function is undefined. 584 * 585 * If #GApplication is not using D-Bus then this function will return 586 * %NULL. This includes the situation where the D-Bus backend would 587 * normally be in use but we were unable to connect to the bus. 588 * 589 * This function must not be called before the application has been 590 * registered. See g_application_get_is_registered(). 591 * 592 * Returns: the object path, or %NULL 593 * 594 * Since: 2.34 595 */ 596 public string getDbusObjectPath() 597 { 598 return Str.toString(g_application_get_dbus_object_path(gApplication)); 599 } 600 601 /** 602 * Gets the flags for @application. 603 * 604 * See #GApplicationFlags. 605 * 606 * Returns: the flags for @application 607 * 608 * Since: 2.28 609 */ 610 public GApplicationFlags getFlags() 611 { 612 return g_application_get_flags(gApplication); 613 } 614 615 /** 616 * Gets the current inactivity timeout for the application. 617 * 618 * This is the amount of time (in milliseconds) after the last call to 619 * g_application_release() before the application stops running. 620 * 621 * Returns: the timeout, in milliseconds 622 * 623 * Since: 2.28 624 */ 625 public uint getInactivityTimeout() 626 { 627 return g_application_get_inactivity_timeout(gApplication); 628 } 629 630 /** 631 * Gets the application's current busy state, as set through 632 * g_application_mark_busy() or g_application_bind_busy_property(). 633 * 634 * Returns: %TRUE if @application is currenty marked as busy 635 * 636 * Since: 2.44 637 */ 638 public bool getIsBusy() 639 { 640 return g_application_get_is_busy(gApplication) != 0; 641 } 642 643 /** 644 * Checks if @application is registered. 645 * 646 * An application is registered if g_application_register() has been 647 * successfully called. 648 * 649 * Returns: %TRUE if @application is registered 650 * 651 * Since: 2.28 652 */ 653 public bool getIsRegistered() 654 { 655 return g_application_get_is_registered(gApplication) != 0; 656 } 657 658 /** 659 * Checks if @application is remote. 660 * 661 * If @application is remote then it means that another instance of 662 * application already exists (the 'primary' instance). Calls to 663 * perform actions on @application will result in the actions being 664 * performed by the primary instance. 665 * 666 * The value of this property cannot be accessed before 667 * g_application_register() has been called. See 668 * g_application_get_is_registered(). 669 * 670 * Returns: %TRUE if @application is remote 671 * 672 * Since: 2.28 673 */ 674 public bool getIsRemote() 675 { 676 return g_application_get_is_remote(gApplication) != 0; 677 } 678 679 /** 680 * Gets the resource base path of @application. 681 * 682 * See g_application_set_resource_base_path() for more information. 683 * 684 * Returns: the base resource path, if one is set 685 * 686 * Since: 2.42 687 */ 688 public string getResourceBasePath() 689 { 690 return Str.toString(g_application_get_resource_base_path(gApplication)); 691 } 692 693 /** 694 * Increases the use count of @application. 695 * 696 * Use this function to indicate that the application has a reason to 697 * continue to run. For example, g_application_hold() is called by GTK+ 698 * when a toplevel window is on the screen. 699 * 700 * To cancel the hold, call g_application_release(). 701 */ 702 public void hold() 703 { 704 g_application_hold(gApplication); 705 } 706 707 /** 708 * Increases the busy count of @application. 709 * 710 * Use this function to indicate that the application is busy, for instance 711 * while a long running operation is pending. 712 * 713 * The busy state will be exposed to other processes, so a session shell will 714 * use that information to indicate the state to the user (e.g. with a 715 * spinner). 716 * 717 * To cancel the busy indication, use g_application_unmark_busy(). 718 * 719 * Since: 2.38 720 */ 721 public void markBusy() 722 { 723 g_application_mark_busy(gApplication); 724 } 725 726 /** 727 * Opens the given files. 728 * 729 * In essence, this results in the #GApplication::open signal being emitted 730 * in the primary instance. 731 * 732 * @n_files must be greater than zero. 733 * 734 * @hint is simply passed through to the ::open signal. It is 735 * intended to be used by applications that have multiple modes for 736 * opening files (eg: "view" vs "edit", etc). Unless you have a need 737 * for this functionality, you should use "". 738 * 739 * The application must be registered before calling this function 740 * and it must have the %G_APPLICATION_HANDLES_OPEN flag set. 741 * 742 * Params: 743 * files = an array of #GFiles to open 744 * hint = a hint (or ""), but never %NULL 745 * 746 * Since: 2.28 747 */ 748 public void open(FileIF[] files, string hint) 749 { 750 GFile*[] filesArray = new GFile*[files.length]; 751 for ( int i = 0; i < files.length; i++ ) 752 { 753 filesArray[i] = files[i].getFileStruct(); 754 } 755 756 g_application_open(gApplication, filesArray.ptr, cast(int)files.length, Str.toStringz(hint)); 757 } 758 759 /** 760 * Immediately quits the application. 761 * 762 * Upon return to the mainloop, g_application_run() will return, 763 * calling only the 'shutdown' function before doing so. 764 * 765 * The hold count is ignored. 766 * 767 * The result of calling g_application_run() again after it returns is 768 * unspecified. 769 * 770 * Since: 2.32 771 */ 772 public void quit() 773 { 774 g_application_quit(gApplication); 775 } 776 777 /** 778 * Attempts registration of the application. 779 * 780 * This is the point at which the application discovers if it is the 781 * primary instance or merely acting as a remote for an already-existing 782 * primary instance. This is implemented by attempting to acquire the 783 * application identifier as a unique bus name on the session bus using 784 * GDBus. 785 * 786 * If there is no application ID or if %G_APPLICATION_NON_UNIQUE was 787 * given, then this process will always become the primary instance. 788 * 789 * Due to the internal architecture of GDBus, method calls can be 790 * dispatched at any time (even if a main loop is not running). For 791 * this reason, you must ensure that any object paths that you wish to 792 * register are registered before calling this function. 793 * 794 * If the application has already been registered then %TRUE is 795 * returned with no work performed. 796 * 797 * The #GApplication::startup signal is emitted if registration succeeds 798 * and @application is the primary instance (including the non-unique 799 * case). 800 * 801 * In the event of an error (such as @cancellable being cancelled, or a 802 * failure to connect to the session bus), %FALSE is returned and @error 803 * is set appropriately. 804 * 805 * Note: the return value of this function is not an indicator that this 806 * instance is or is not the primary instance of the application. See 807 * g_application_get_is_remote() for that. 808 * 809 * Params: 810 * cancellable = a #GCancellable, or %NULL 811 * 812 * Returns: %TRUE if registration succeeded 813 * 814 * Since: 2.28 815 * 816 * Throws: GException on failure. 817 */ 818 public bool register(Cancellable cancellable) 819 { 820 GError* err = null; 821 822 auto p = g_application_register(gApplication, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 823 824 if (err !is null) 825 { 826 throw new GException( new ErrorG(err) ); 827 } 828 829 return p; 830 } 831 832 /** 833 * Decrease the use count of @application. 834 * 835 * When the use count reaches zero, the application will stop running. 836 * 837 * Never call this function except to cancel the effect of a previous 838 * call to g_application_hold(). 839 */ 840 public void release() 841 { 842 g_application_release(gApplication); 843 } 844 845 /** 846 * Runs the application. 847 * 848 * This function is intended to be run from main() and its return value 849 * is intended to be returned by main(). Although you are expected to pass 850 * the @argc, @argv parameters from main() to this function, it is possible 851 * to pass %NULL if @argv is not available or commandline handling is not 852 * required. Note that on Windows, @argc and @argv are ignored, and 853 * g_win32_get_command_line() is called internally (for proper support 854 * of Unicode commandline arguments). 855 * 856 * #GApplication will attempt to parse the commandline arguments. You 857 * can add commandline flags to the list of recognised options by way of 858 * g_application_add_main_option_entries(). After this, the 859 * #GApplication::handle-local-options signal is emitted, from which the 860 * application can inspect the values of its #GOptionEntrys. 861 * 862 * #GApplication::handle-local-options is a good place to handle options 863 * such as `--version`, where an immediate reply from the local process is 864 * desired (instead of communicating with an already-running instance). 865 * A #GApplication::handle-local-options handler can stop further processing 866 * by returning a non-negative value, which then becomes the exit status of 867 * the process. 868 * 869 * What happens next depends on the flags: if 870 * %G_APPLICATION_HANDLES_COMMAND_LINE was specified then the remaining 871 * commandline arguments are sent to the primary instance, where a 872 * #GApplication::command-line signal is emitted. Otherwise, the 873 * remaining commandline arguments are assumed to be a list of files. 874 * If there are no files listed, the application is activated via the 875 * #GApplication::activate signal. If there are one or more files, and 876 * %G_APPLICATION_HANDLES_OPEN was specified then the files are opened 877 * via the #GApplication::open signal. 878 * 879 * If you are interested in doing more complicated local handling of the 880 * commandline then you should implement your own #GApplication subclass 881 * and override local_command_line(). In this case, you most likely want 882 * to return %TRUE from your local_command_line() implementation to 883 * suppress the default handling. See 884 * [gapplication-example-cmdline2.c][gapplication-example-cmdline2] 885 * for an example. 886 * 887 * If, after the above is done, the use count of the application is zero 888 * then the exit status is returned immediately. If the use count is 889 * non-zero then the default main context is iterated until the use count 890 * falls to zero, at which point 0 is returned. 891 * 892 * If the %G_APPLICATION_IS_SERVICE flag is set, then the service will 893 * run for as much as 10 seconds with a use count of zero while waiting 894 * for the message that caused the activation to arrive. After that, 895 * if the use count falls to zero the application will exit immediately, 896 * except in the case that g_application_set_inactivity_timeout() is in 897 * use. 898 * 899 * This function sets the prgname (g_set_prgname()), if not already set, 900 * to the basename of argv[0]. 901 * 902 * Much like g_main_loop_run(), this function will acquire the main context 903 * for the duration that the application is running. 904 * 905 * Since 2.40, applications that are not explicitly flagged as services 906 * or launchers (ie: neither %G_APPLICATION_IS_SERVICE or 907 * %G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the 908 * default handler for local_command_line) if "--gapplication-service" 909 * was given in the command line. If this flag is present then normal 910 * commandline processing is interrupted and the 911 * %G_APPLICATION_IS_SERVICE flag is set. This provides a "compromise" 912 * solution whereby running an application directly from the commandline 913 * will invoke it in the normal way (which can be useful for debugging) 914 * while still allowing applications to be D-Bus activated in service 915 * mode. The D-Bus service file should invoke the executable with 916 * "--gapplication-service" as the sole commandline argument. This 917 * approach is suitable for use by most graphical applications but 918 * should not be used from applications like editors that need precise 919 * control over when processes invoked via the commandline will exit and 920 * what their exit status will be. 921 * 922 * Params: 923 * argv = the argv from main(), or %NULL 924 * 925 * Returns: the exit status 926 * 927 * Since: 2.28 928 */ 929 public int run(string[] argv) 930 { 931 return g_application_run(gApplication, cast(int)argv.length, Str.toStringzArray(argv)); 932 } 933 934 /** 935 * Sends a notification on behalf of @application to the desktop shell. 936 * There is no guarantee that the notification is displayed immediately, 937 * or even at all. 938 * 939 * Notifications may persist after the application exits. It will be 940 * D-Bus-activated when the notification or one of its actions is 941 * activated. 942 * 943 * Modifying @notification after this call has no effect. However, the 944 * object can be reused for a later call to this function. 945 * 946 * @id may be any string that uniquely identifies the event for the 947 * application. It does not need to be in any special format. For 948 * example, "new-message" might be appropriate for a notification about 949 * new messages. 950 * 951 * If a previous notification was sent with the same @id, it will be 952 * replaced with @notification and shown again as if it was a new 953 * notification. This works even for notifications sent from a previous 954 * execution of the application, as long as @id is the same string. 955 * 956 * @id may be %NULL, but it is impossible to replace or withdraw 957 * notifications without an id. 958 * 959 * If @notification is no longer relevant, it can be withdrawn with 960 * g_application_withdraw_notification(). 961 * 962 * Params: 963 * id = id of the notification, or %NULL 964 * notification = the #GNotification to send 965 * 966 * Since: 2.40 967 */ 968 public void sendNotification(string id, Notification notification) 969 { 970 g_application_send_notification(gApplication, Str.toStringz(id), (notification is null) ? null : notification.getNotificationStruct()); 971 } 972 973 /** 974 * This used to be how actions were associated with a #GApplication. 975 * Now there is #GActionMap for that. 976 * 977 * Deprecated: Use the #GActionMap interface instead. Never ever 978 * mix use of this API with use of #GActionMap on the same @application 979 * or things will go very badly wrong. This function is known to 980 * introduce buggy behaviour (ie: signals not emitted on changes to the 981 * action group), so you should really use #GActionMap instead. 982 * 983 * Params: 984 * actionGroup = a #GActionGroup, or %NULL 985 * 986 * Since: 2.28 987 */ 988 public void setActionGroup(ActionGroupIF actionGroup) 989 { 990 g_application_set_action_group(gApplication, (actionGroup is null) ? null : actionGroup.getActionGroupStruct()); 991 } 992 993 /** 994 * Sets the unique identifier for @application. 995 * 996 * The application id can only be modified if @application has not yet 997 * been registered. 998 * 999 * If non-%NULL, the application id must be valid. See 1000 * g_application_id_is_valid(). 1001 * 1002 * Params: 1003 * applicationId = the identifier for @application 1004 * 1005 * Since: 2.28 1006 */ 1007 public void setApplicationId(string applicationId) 1008 { 1009 g_application_set_application_id(gApplication, Str.toStringz(applicationId)); 1010 } 1011 1012 /** 1013 * Sets or unsets the default application for the process, as returned 1014 * by g_application_get_default(). 1015 * 1016 * This function does not take its own reference on @application. If 1017 * @application is destroyed then the default application will revert 1018 * back to %NULL. 1019 * 1020 * Since: 2.32 1021 */ 1022 public void setDefault() 1023 { 1024 g_application_set_default(gApplication); 1025 } 1026 1027 /** 1028 * Sets the flags for @application. 1029 * 1030 * The flags can only be modified if @application has not yet been 1031 * registered. 1032 * 1033 * See #GApplicationFlags. 1034 * 1035 * Params: 1036 * flags = the flags for @application 1037 * 1038 * Since: 2.28 1039 */ 1040 public void setFlags(GApplicationFlags flags) 1041 { 1042 g_application_set_flags(gApplication, flags); 1043 } 1044 1045 /** 1046 * Sets the current inactivity timeout for the application. 1047 * 1048 * This is the amount of time (in milliseconds) after the last call to 1049 * g_application_release() before the application stops running. 1050 * 1051 * This call has no side effects of its own. The value set here is only 1052 * used for next time g_application_release() drops the use count to 1053 * zero. Any timeouts currently in progress are not impacted. 1054 * 1055 * Params: 1056 * inactivityTimeout = the timeout, in milliseconds 1057 * 1058 * Since: 2.28 1059 */ 1060 public void setInactivityTimeout(uint inactivityTimeout) 1061 { 1062 g_application_set_inactivity_timeout(gApplication, inactivityTimeout); 1063 } 1064 1065 /** 1066 * Sets (or unsets) the base resource path of @application. 1067 * 1068 * The path is used to automatically load various [application 1069 * resources][gresource] such as menu layouts and action descriptions. 1070 * The various types of resources will be found at fixed names relative 1071 * to the given base path. 1072 * 1073 * By default, the resource base path is determined from the application 1074 * ID by prefixing '/' and replacing each '.' with '/'. This is done at 1075 * the time that the #GApplication object is constructed. Changes to 1076 * the application ID after that point will not have an impact on the 1077 * resource base path. 1078 * 1079 * As an example, if the application has an ID of "org.example.app" then 1080 * the default resource base path will be "/org/example/app". If this 1081 * is a #GtkApplication (and you have not manually changed the path) 1082 * then Gtk will then search for the menus of the application at 1083 * "/org/example/app/gtk/menus.ui". 1084 * 1085 * See #GResource for more information about adding resources to your 1086 * application. 1087 * 1088 * You can disable automatic resource loading functionality by setting 1089 * the path to %NULL. 1090 * 1091 * Changing the resource base path once the application is running is 1092 * not recommended. The point at which the resource path is consulted 1093 * for forming paths for various purposes is unspecified. When writing 1094 * a sub-class of #GApplication you should either set the 1095 * #GApplication:resource-base-path property at construction time, or call 1096 * this function during the instance initialization. Alternatively, you 1097 * can call this function in the #GApplicationClass.startup virtual function, 1098 * before chaining up to the parent implementation. 1099 * 1100 * Params: 1101 * resourcePath = the resource path to use 1102 * 1103 * Since: 2.42 1104 */ 1105 public void setResourceBasePath(string resourcePath) 1106 { 1107 g_application_set_resource_base_path(gApplication, Str.toStringz(resourcePath)); 1108 } 1109 1110 /** 1111 * Destroys a binding between @property and the busy state of 1112 * @application that was previously created with 1113 * g_application_bind_busy_property(). 1114 * 1115 * Params: 1116 * object = a #GObject 1117 * property = the name of a boolean property of @object 1118 * 1119 * Since: 2.44 1120 */ 1121 public void unbindBusyProperty(ObjectG object, string property) 1122 { 1123 g_application_unbind_busy_property(gApplication, (object is null) ? null : object.getObjectGStruct(), Str.toStringz(property)); 1124 } 1125 1126 /** 1127 * Decreases the busy count of @application. 1128 * 1129 * When the busy count reaches zero, the new state will be propagated 1130 * to other processes. 1131 * 1132 * This function must only be called to cancel the effect of a previous 1133 * call to g_application_mark_busy(). 1134 * 1135 * Since: 2.38 1136 */ 1137 public void unmarkBusy() 1138 { 1139 g_application_unmark_busy(gApplication); 1140 } 1141 1142 /** 1143 * Withdraws a notification that was sent with 1144 * g_application_send_notification(). 1145 * 1146 * This call does nothing if a notification with @id doesn't exist or 1147 * the notification was never sent. 1148 * 1149 * This function works even for notifications sent in previous 1150 * executions of this application, as long @id is the same as it was for 1151 * the sent notification. 1152 * 1153 * Note that notifications are dismissed when the user clicks on one 1154 * of the buttons in a notification or triggers its default action, so 1155 * there is no need to explicitly withdraw the notification in that case. 1156 * 1157 * Params: 1158 * id = id of a previously sent notification 1159 * 1160 * Since: 2.40 1161 */ 1162 public void withdrawNotification(string id) 1163 { 1164 g_application_withdraw_notification(gApplication, Str.toStringz(id)); 1165 } 1166 1167 protected class OnActivateDelegateWrapper 1168 { 1169 void delegate(Application) dlg; 1170 gulong handlerId; 1171 1172 this(void delegate(Application) dlg) 1173 { 1174 this.dlg = dlg; 1175 onActivateListeners ~= this; 1176 } 1177 1178 void remove(OnActivateDelegateWrapper source) 1179 { 1180 foreach(index, wrapper; onActivateListeners) 1181 { 1182 if (wrapper.handlerId == source.handlerId) 1183 { 1184 onActivateListeners[index] = null; 1185 onActivateListeners = std.algorithm.remove(onActivateListeners, index); 1186 break; 1187 } 1188 } 1189 } 1190 } 1191 OnActivateDelegateWrapper[] onActivateListeners; 1192 1193 /** 1194 * The ::activate signal is emitted on the primary instance when an 1195 * activation occurs. See g_application_activate(). 1196 */ 1197 gulong addOnActivate(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1198 { 1199 auto wrapper = new OnActivateDelegateWrapper(dlg); 1200 wrapper.handlerId = Signals.connectData( 1201 this, 1202 "activate", 1203 cast(GCallback)&callBackActivate, 1204 cast(void*)wrapper, 1205 cast(GClosureNotify)&callBackActivateDestroy, 1206 connectFlags); 1207 return wrapper.handlerId; 1208 } 1209 1210 extern(C) static void callBackActivate(GApplication* applicationStruct, OnActivateDelegateWrapper wrapper) 1211 { 1212 wrapper.dlg(wrapper.outer); 1213 } 1214 1215 extern(C) static void callBackActivateDestroy(OnActivateDelegateWrapper wrapper, GClosure* closure) 1216 { 1217 wrapper.remove(wrapper); 1218 } 1219 1220 protected class OnCommandLineDelegateWrapper 1221 { 1222 int delegate(ApplicationCommandLine, Application) dlg; 1223 gulong handlerId; 1224 1225 this(int delegate(ApplicationCommandLine, Application) dlg) 1226 { 1227 this.dlg = dlg; 1228 onCommandLineListeners ~= this; 1229 } 1230 1231 void remove(OnCommandLineDelegateWrapper source) 1232 { 1233 foreach(index, wrapper; onCommandLineListeners) 1234 { 1235 if (wrapper.handlerId == source.handlerId) 1236 { 1237 onCommandLineListeners[index] = null; 1238 onCommandLineListeners = std.algorithm.remove(onCommandLineListeners, index); 1239 break; 1240 } 1241 } 1242 } 1243 } 1244 OnCommandLineDelegateWrapper[] onCommandLineListeners; 1245 1246 /** 1247 * The ::command-line signal is emitted on the primary instance when 1248 * a commandline is not handled locally. See g_application_run() and 1249 * the #GApplicationCommandLine documentation for more information. 1250 * 1251 * Params: 1252 * commandLine = a #GApplicationCommandLine representing the 1253 * passed commandline 1254 * 1255 * Returns: An integer that is set as the exit status for the calling 1256 * process. See g_application_command_line_set_exit_status(). 1257 */ 1258 gulong addOnCommandLine(int delegate(ApplicationCommandLine, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1259 { 1260 auto wrapper = new OnCommandLineDelegateWrapper(dlg); 1261 wrapper.handlerId = Signals.connectData( 1262 this, 1263 "command-line", 1264 cast(GCallback)&callBackCommandLine, 1265 cast(void*)wrapper, 1266 cast(GClosureNotify)&callBackCommandLineDestroy, 1267 connectFlags); 1268 return wrapper.handlerId; 1269 } 1270 1271 extern(C) static int callBackCommandLine(GApplication* applicationStruct, GApplicationCommandLine* commandLine, OnCommandLineDelegateWrapper wrapper) 1272 { 1273 return wrapper.dlg(ObjectG.getDObject!(ApplicationCommandLine)(commandLine), wrapper.outer); 1274 } 1275 1276 extern(C) static void callBackCommandLineDestroy(OnCommandLineDelegateWrapper wrapper, GClosure* closure) 1277 { 1278 wrapper.remove(wrapper); 1279 } 1280 1281 protected class OnHandleLocalOptionsDelegateWrapper 1282 { 1283 int delegate(VariantDict, Application) dlg; 1284 gulong handlerId; 1285 1286 this(int delegate(VariantDict, Application) dlg) 1287 { 1288 this.dlg = dlg; 1289 onHandleLocalOptionsListeners ~= this; 1290 } 1291 1292 void remove(OnHandleLocalOptionsDelegateWrapper source) 1293 { 1294 foreach(index, wrapper; onHandleLocalOptionsListeners) 1295 { 1296 if (wrapper.handlerId == source.handlerId) 1297 { 1298 onHandleLocalOptionsListeners[index] = null; 1299 onHandleLocalOptionsListeners = std.algorithm.remove(onHandleLocalOptionsListeners, index); 1300 break; 1301 } 1302 } 1303 } 1304 } 1305 OnHandleLocalOptionsDelegateWrapper[] onHandleLocalOptionsListeners; 1306 1307 /** 1308 * The ::handle-local-options signal is emitted on the local instance 1309 * after the parsing of the commandline options has occurred. 1310 * 1311 * You can add options to be recognised during commandline option 1312 * parsing using g_application_add_main_option_entries() and 1313 * g_application_add_option_group(). 1314 * 1315 * Signal handlers can inspect @options (along with values pointed to 1316 * from the @arg_data of an installed #GOptionEntrys) in order to 1317 * decide to perform certain actions, including direct local handling 1318 * (which may be useful for options like --version). 1319 * 1320 * In the event that the application is marked 1321 * %G_APPLICATION_HANDLES_COMMAND_LINE the "normal processing" will 1322 * send the @options dictionary to the primary instance where it can be 1323 * read with g_application_command_line_get_options_dict(). The signal 1324 * handler can modify the dictionary before returning, and the 1325 * modified dictionary will be sent. 1326 * 1327 * In the event that %G_APPLICATION_HANDLES_COMMAND_LINE is not set, 1328 * "normal processing" will treat the remaining uncollected command 1329 * line arguments as filenames or URIs. If there are no arguments, 1330 * the application is activated by g_application_activate(). One or 1331 * more arguments results in a call to g_application_open(). 1332 * 1333 * If you want to handle the local commandline arguments for yourself 1334 * by converting them to calls to g_application_open() or 1335 * g_action_group_activate_action() then you must be sure to register 1336 * the application first. You should probably not call 1337 * g_application_activate() for yourself, however: just return -1 and 1338 * allow the default handler to do it for you. This will ensure that 1339 * the `--gapplication-service` switch works properly (i.e. no activation 1340 * in that case). 1341 * 1342 * Note that this signal is emitted from the default implementation of 1343 * local_command_line(). If you override that function and don't 1344 * chain up then this signal will never be emitted. 1345 * 1346 * You can override local_command_line() if you need more powerful 1347 * capabilities than what is provided here, but this should not 1348 * normally be required. 1349 * 1350 * Params: 1351 * options = the options dictionary 1352 * 1353 * Returns: an exit code. If you have handled your options and want 1354 * to exit the process, return a non-negative option, 0 for success, 1355 * and a positive value for failure. To continue, return -1 to let 1356 * the default option processing continue. 1357 * 1358 * Since: 2.40 1359 */ 1360 gulong addOnHandleLocalOptions(int delegate(VariantDict, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1361 { 1362 auto wrapper = new OnHandleLocalOptionsDelegateWrapper(dlg); 1363 wrapper.handlerId = Signals.connectData( 1364 this, 1365 "handle-local-options", 1366 cast(GCallback)&callBackHandleLocalOptions, 1367 cast(void*)wrapper, 1368 cast(GClosureNotify)&callBackHandleLocalOptionsDestroy, 1369 connectFlags); 1370 return wrapper.handlerId; 1371 } 1372 1373 extern(C) static int callBackHandleLocalOptions(GApplication* applicationStruct, GVariantDict* options, OnHandleLocalOptionsDelegateWrapper wrapper) 1374 { 1375 return wrapper.dlg(new VariantDict(options), wrapper.outer); 1376 } 1377 1378 extern(C) static void callBackHandleLocalOptionsDestroy(OnHandleLocalOptionsDelegateWrapper wrapper, GClosure* closure) 1379 { 1380 wrapper.remove(wrapper); 1381 } 1382 1383 protected class OnOpenDelegateWrapper 1384 { 1385 void delegate(void*, int, string, Application) dlg; 1386 gulong handlerId; 1387 1388 this(void delegate(void*, int, string, Application) dlg) 1389 { 1390 this.dlg = dlg; 1391 onOpenListeners ~= this; 1392 } 1393 1394 void remove(OnOpenDelegateWrapper source) 1395 { 1396 foreach(index, wrapper; onOpenListeners) 1397 { 1398 if (wrapper.handlerId == source.handlerId) 1399 { 1400 onOpenListeners[index] = null; 1401 onOpenListeners = std.algorithm.remove(onOpenListeners, index); 1402 break; 1403 } 1404 } 1405 } 1406 } 1407 OnOpenDelegateWrapper[] onOpenListeners; 1408 1409 /** 1410 * The ::open signal is emitted on the primary instance when there are 1411 * files to open. See g_application_open() for more information. 1412 * 1413 * Params: 1414 * files = an array of #GFiles 1415 * nFiles = the length of @files 1416 * hint = a hint provided by the calling instance 1417 */ 1418 gulong addOnOpen(void delegate(void*, int, string, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1419 { 1420 auto wrapper = new OnOpenDelegateWrapper(dlg); 1421 wrapper.handlerId = Signals.connectData( 1422 this, 1423 "open", 1424 cast(GCallback)&callBackOpen, 1425 cast(void*)wrapper, 1426 cast(GClosureNotify)&callBackOpenDestroy, 1427 connectFlags); 1428 return wrapper.handlerId; 1429 } 1430 1431 extern(C) static void callBackOpen(GApplication* applicationStruct, void* files, int nFiles, char* hint, OnOpenDelegateWrapper wrapper) 1432 { 1433 wrapper.dlg(files, nFiles, Str.toString(hint), wrapper.outer); 1434 } 1435 1436 extern(C) static void callBackOpenDestroy(OnOpenDelegateWrapper wrapper, GClosure* closure) 1437 { 1438 wrapper.remove(wrapper); 1439 } 1440 1441 protected class OnShutdownDelegateWrapper 1442 { 1443 void delegate(Application) dlg; 1444 gulong handlerId; 1445 1446 this(void delegate(Application) dlg) 1447 { 1448 this.dlg = dlg; 1449 onShutdownListeners ~= this; 1450 } 1451 1452 void remove(OnShutdownDelegateWrapper source) 1453 { 1454 foreach(index, wrapper; onShutdownListeners) 1455 { 1456 if (wrapper.handlerId == source.handlerId) 1457 { 1458 onShutdownListeners[index] = null; 1459 onShutdownListeners = std.algorithm.remove(onShutdownListeners, index); 1460 break; 1461 } 1462 } 1463 } 1464 } 1465 OnShutdownDelegateWrapper[] onShutdownListeners; 1466 1467 /** 1468 * The ::shutdown signal is emitted only on the registered primary instance 1469 * immediately after the main loop terminates. 1470 */ 1471 gulong addOnShutdown(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1472 { 1473 auto wrapper = new OnShutdownDelegateWrapper(dlg); 1474 wrapper.handlerId = Signals.connectData( 1475 this, 1476 "shutdown", 1477 cast(GCallback)&callBackShutdown, 1478 cast(void*)wrapper, 1479 cast(GClosureNotify)&callBackShutdownDestroy, 1480 connectFlags); 1481 return wrapper.handlerId; 1482 } 1483 1484 extern(C) static void callBackShutdown(GApplication* applicationStruct, OnShutdownDelegateWrapper wrapper) 1485 { 1486 wrapper.dlg(wrapper.outer); 1487 } 1488 1489 extern(C) static void callBackShutdownDestroy(OnShutdownDelegateWrapper wrapper, GClosure* closure) 1490 { 1491 wrapper.remove(wrapper); 1492 } 1493 1494 protected class OnStartupDelegateWrapper 1495 { 1496 void delegate(Application) dlg; 1497 gulong handlerId; 1498 1499 this(void delegate(Application) dlg) 1500 { 1501 this.dlg = dlg; 1502 onStartupListeners ~= this; 1503 } 1504 1505 void remove(OnStartupDelegateWrapper source) 1506 { 1507 foreach(index, wrapper; onStartupListeners) 1508 { 1509 if (wrapper.handlerId == source.handlerId) 1510 { 1511 onStartupListeners[index] = null; 1512 onStartupListeners = std.algorithm.remove(onStartupListeners, index); 1513 break; 1514 } 1515 } 1516 } 1517 } 1518 OnStartupDelegateWrapper[] onStartupListeners; 1519 1520 /** 1521 * The ::startup signal is emitted on the primary instance immediately 1522 * after registration. See g_application_register(). 1523 */ 1524 gulong addOnStartup(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1525 { 1526 auto wrapper = new OnStartupDelegateWrapper(dlg); 1527 wrapper.handlerId = Signals.connectData( 1528 this, 1529 "startup", 1530 cast(GCallback)&callBackStartup, 1531 cast(void*)wrapper, 1532 cast(GClosureNotify)&callBackStartupDestroy, 1533 connectFlags); 1534 return wrapper.handlerId; 1535 } 1536 1537 extern(C) static void callBackStartup(GApplication* applicationStruct, OnStartupDelegateWrapper wrapper) 1538 { 1539 wrapper.dlg(wrapper.outer); 1540 } 1541 1542 extern(C) static void callBackStartupDestroy(OnStartupDelegateWrapper wrapper, GClosure* closure) 1543 { 1544 wrapper.remove(wrapper); 1545 } 1546 }