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 * Conversion parameters: 26 * inFile = GApplication.html 27 * outPack = gio 28 * outFile = Application 29 * strct = GApplication 30 * realStrct= 31 * ctorStrct= 32 * clss = Application 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - ActionGroupIF 40 * - ActionMapIF 41 * prefixes: 42 * - g_application_ 43 * omit structs: 44 * omit prefixes: 45 * omit code: 46 * omit signals: 47 * imports: 48 * - glib.Str 49 * - glib.ErrorG 50 * - glib.GException 51 * - gio.Cancellable 52 * - gio.DBusConnection 53 * - gio.File 54 * - gio.ActionGroupIF 55 * - gio.ActionGroupT 56 * - gio.ActionMapIF 57 * - gio.ActionMapT 58 * structWrap: 59 * - GApplication* -> Application 60 * - GCancellable* -> Cancellable 61 * - GDBusConnection* -> DBusConnection 62 * - GFile* -> File 63 * module aliases: 64 * local aliases: 65 * overrides: 66 */ 67 68 module gio.Application; 69 70 public import gtkc.giotypes; 71 72 private import gtkc.gio; 73 private import glib.ConstructionException; 74 private import gobject.ObjectG; 75 76 private import gobject.Signals; 77 public import gtkc.gdktypes; 78 private import glib.Str; 79 private import glib.ErrorG; 80 private import glib.GException; 81 private import gio.Cancellable; 82 private import gio.DBusConnection; 83 private import gio.File; 84 private import gio.ActionGroupIF; 85 private import gio.ActionGroupT; 86 private import gio.ActionMapIF; 87 private import gio.ActionMapT; 88 89 90 private import gobject.ObjectG; 91 92 /** 93 * A GApplication is the foundation of an application. It wraps some 94 * low-level platform-specific services and is intended to act as the 95 * foundation for higher-level application classes such as 96 * GtkApplication or MxApplication. In general, you should not use 97 * this class outside of a higher level framework. 98 * 99 * GApplication provides convenient life cycle management by maintaining 100 * a use count for the primary application instance. 101 * The use count can be changed using g_application_hold() and 102 * g_application_release(). If it drops to zero, the application exits. 103 * Higher-level classes such as GtkApplication employ the use count to 104 * ensure that the application stays alive as long as it has any opened 105 * windows. 106 * 107 * Another feature that GApplication (optionally) provides is process 108 * uniqueness. Applications can make use of this functionality by 109 * providing a unique application ID. If given, only one application 110 * with this ID can be running at a time per session. The session 111 * concept is platform-dependent, but corresponds roughly to a graphical 112 * desktop login. When your application is launched again, its 113 * arguments are passed through platform communication to the already 114 * running program. The already running instance of the program is 115 * called the primary instance; for non-unique 116 * applications this is the always the current instance. 117 * On Linux, the D-Bus session bus is used for communication. 118 * 119 * The use of GApplication differs from some other commonly-used 120 * uniqueness libraries (such as libunique) in important ways. The 121 * application is not expected to manually register itself and check if 122 * it is the primary instance. Instead, the main() 123 * function of a GApplication should do very little more than 124 * instantiating the application instance, possibly connecting signal 125 * handlers, then calling g_application_run(). All checks for 126 * uniqueness are done internally. If the application is the primary 127 * instance then the startup signal is emitted and the mainloop runs. 128 * If the application is not the primary instance then a signal is sent 129 * to the primary instance and g_application_run() promptly returns. 130 * See the code examples below. 131 * 132 * If used, the expected form of an application identifier is very close 133 * to that of of a 134 * DBus bus name. 135 * Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator". 136 * For details on valid application identifiers, see g_application_id_is_valid(). 137 * 138 * On Linux, the application identifier is claimed as a well-known bus name 139 * on the user's session bus. This means that the uniqueness of your 140 * application is scoped to the current session. It also means that your 141 * application may provide additional services (through registration of other 142 * object paths) at that bus name. The registration of these object paths 143 * should be done with the shared GDBus session bus. Note that due to the 144 * internal architecture of GDBus, method calls can be dispatched at any time 145 * (even if a main loop is not running). For this reason, you must ensure that 146 * any object paths that you wish to register are registered before GApplication 147 * attempts to acquire the bus name of your application (which happens in 148 * g_application_register()). Unfortunately, this means that you cannot use 149 * g_application_get_is_remote() to decide if you want to register object paths. 150 * 151 * GApplication also implements the GActionGroup and GActionMap 152 * interfaces and lets you easily export actions by adding them with 153 * g_action_map_add_action(). When invoking an action by calling 154 * g_action_group_activate_action() on the application, it is always 155 * invoked in the primary instance. The actions are also exported on 156 * the session bus, and GIO provides the GDBusActionGroup wrapper to 157 * conveniently access them remotely. GIO provides a GDBusMenuModel wrapper 158 * for remote access to exported GMenuModels. 159 * 160 * There is a number of different entry points into a GApplication: 161 * 162 * via 'Activate' (i.e. just starting the application) 163 * via 'Open' (i.e. opening some files) 164 * by handling a command-line 165 * via activating an action 166 * 167 * The "startup" signal lets you handle the application 168 * initialization for all of these in a single place. 169 * 170 * Regardless of which of these entry points is used to start the application, 171 * GApplication passes some platform 172 * data from the launching instance to the primary instance, 173 * in the form of a GVariant dictionary mapping strings to variants. 174 * To use platform data, override the before_emit or after_emit virtual 175 * functions in your GApplication subclass. When dealing with 176 * GApplicationCommandLine objects, the platform data is directly 177 * available via g_application_command_line_get_cwd(), 178 * g_application_command_line_get_environ() and 179 * g_application_command_line_get_platform_data(). 180 * 181 * As the name indicates, the platform data may vary depending on the 182 * operating system, but it always includes the current directory (key 183 * "cwd"), and optionally the environment (ie the set of environment 184 * variables and their values) of the calling process (key "environ"). 185 * The environment is only added to the platform data if the 186 * G_APPLICATION_SEND_ENVIRONMENT flag is set. GApplication subclasses 187 * can add their own platform data by overriding the add_platform_data 188 * virtual function. For instance, GtkApplication adds startup notification 189 * data in this way. 190 * 191 * To parse commandline arguments you may handle the 192 * "command-line" signal or override the local_command_line() 193 * vfunc, to parse them in either the primary instance or the local instance, 194 * respectively. 195 * 196 * $(DDOC_COMMENT example) 197 * 198 * $(DDOC_COMMENT example) 199 * 200 * $(DDOC_COMMENT example) 201 * 202 * $(DDOC_COMMENT example) 203 */ 204 public class Application : ObjectG, ActionGroupIF, ActionMapIF 205 { 206 207 /** the main Gtk struct */ 208 protected GApplication* gApplication; 209 210 211 /** Get the main Gtk struct */ 212 public GApplication* getApplicationStruct() 213 { 214 return gApplication; 215 } 216 217 218 /** the main Gtk struct as a void* */ 219 protected override void* getStruct() 220 { 221 return cast(void*)gApplication; 222 } 223 224 /** 225 * Sets our main struct and passes it to the parent class 226 */ 227 public this (GApplication* gApplication) 228 { 229 super(cast(GObject*)gApplication); 230 this.gApplication = gApplication; 231 } 232 233 protected override void setStruct(GObject* obj) 234 { 235 super.setStruct(obj); 236 gApplication = cast(GApplication*)obj; 237 } 238 239 // add the ActionGroup capabilities 240 mixin ActionGroupT!(GApplication); 241 242 // add the ActionMap capabilities 243 mixin ActionMapT!(GApplication); 244 245 /** 246 */ 247 int[string] connectedSignals; 248 249 void delegate(Application)[] onActivateListeners; 250 /** 251 * The ::activate signal is emitted on the primary instance when an 252 * activation occurs. See g_application_activate(). 253 */ 254 void addOnActivate(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 255 { 256 if ( !("activate" in connectedSignals) ) 257 { 258 Signals.connectData( 259 getStruct(), 260 "activate", 261 cast(GCallback)&callBackActivate, 262 cast(void*)this, 263 null, 264 connectFlags); 265 connectedSignals["activate"] = 1; 266 } 267 onActivateListeners ~= dlg; 268 } 269 extern(C) static void callBackActivate(GApplication* applicationStruct, Application _application) 270 { 271 foreach ( void delegate(Application) dlg ; _application.onActivateListeners ) 272 { 273 dlg(_application); 274 } 275 } 276 277 gint delegate(GApplicationCommandLine*, Application)[] onCommandLineListeners; 278 /** 279 * The ::command-line signal is emitted on the primary instance when 280 * a commandline is not handled locally. See g_application_run() and 281 * the GApplicationCommandLine documentation for more information. 282 */ 283 void addOnCommandLine(gint delegate(GApplicationCommandLine*, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 284 { 285 if ( !("command-line" in connectedSignals) ) 286 { 287 Signals.connectData( 288 getStruct(), 289 "command-line", 290 cast(GCallback)&callBackCommandLine, 291 cast(void*)this, 292 null, 293 connectFlags); 294 connectedSignals["command-line"] = 1; 295 } 296 onCommandLineListeners ~= dlg; 297 } 298 extern(C) static void callBackCommandLine(GApplication* applicationStruct, GApplicationCommandLine* commandLine, Application _application) 299 { 300 foreach ( gint delegate(GApplicationCommandLine*, Application) dlg ; _application.onCommandLineListeners ) 301 { 302 dlg(commandLine, _application); 303 } 304 } 305 306 void delegate(void*, gint, string, Application)[] onOpenListeners; 307 /** 308 * The ::open signal is emitted on the primary instance when there are 309 * files to open. See g_application_open() for more information. 310 */ 311 void addOnOpen(void delegate(void*, gint, string, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 312 { 313 if ( !("open" in connectedSignals) ) 314 { 315 Signals.connectData( 316 getStruct(), 317 "open", 318 cast(GCallback)&callBackOpen, 319 cast(void*)this, 320 null, 321 connectFlags); 322 connectedSignals["open"] = 1; 323 } 324 onOpenListeners ~= dlg; 325 } 326 extern(C) static void callBackOpen(GApplication* applicationStruct, void* files, gint nFiles, gchar* hint, Application _application) 327 { 328 foreach ( void delegate(void*, gint, string, Application) dlg ; _application.onOpenListeners ) 329 { 330 dlg(files, nFiles, Str.toString(hint), _application); 331 } 332 } 333 334 void delegate(Application)[] onShutdownListeners; 335 /** 336 * The ::shutdown signal is emitted only on the registered primary instance 337 * immediately after the main loop terminates. 338 */ 339 void addOnShutdown(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 340 { 341 if ( !("shutdown" in connectedSignals) ) 342 { 343 Signals.connectData( 344 getStruct(), 345 "shutdown", 346 cast(GCallback)&callBackShutdown, 347 cast(void*)this, 348 null, 349 connectFlags); 350 connectedSignals["shutdown"] = 1; 351 } 352 onShutdownListeners ~= dlg; 353 } 354 extern(C) static void callBackShutdown(GApplication* applicationStruct, Application _application) 355 { 356 foreach ( void delegate(Application) dlg ; _application.onShutdownListeners ) 357 { 358 dlg(_application); 359 } 360 } 361 362 void delegate(Application)[] onStartupListeners; 363 /** 364 * The ::startup signal is emitted on the primary instance immediately 365 * after registration. See g_application_register(). 366 */ 367 void addOnStartup(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 368 { 369 if ( !("startup" in connectedSignals) ) 370 { 371 Signals.connectData( 372 getStruct(), 373 "startup", 374 cast(GCallback)&callBackStartup, 375 cast(void*)this, 376 null, 377 connectFlags); 378 connectedSignals["startup"] = 1; 379 } 380 onStartupListeners ~= dlg; 381 } 382 extern(C) static void callBackStartup(GApplication* applicationStruct, Application _application) 383 { 384 foreach ( void delegate(Application) dlg ; _application.onStartupListeners ) 385 { 386 dlg(_application); 387 } 388 } 389 390 391 /** 392 * Checks if application_id is a valid application identifier. 393 * A valid ID is required for calls to g_application_new() and 394 * g_application_set_application_id(). 395 * For convenience, the restrictions on application identifiers are 396 * Params: 397 * applicationId = a potential application identifier 398 * Returns: TRUE if application_id is valid 399 */ 400 public static int idIsValid(string applicationId) 401 { 402 // gboolean g_application_id_is_valid (const gchar *application_id); 403 return g_application_id_is_valid(Str.toStringz(applicationId)); 404 } 405 406 /** 407 * Creates a new GApplication instance. 408 * If non-NULL, the application id must be valid. See 409 * g_application_id_is_valid(). 410 * If no application ID is given then some features of GApplication 411 * (most notably application uniqueness) will be disabled. 412 * Params: 413 * applicationId = the application id. [allow-none] 414 * flags = the application flags 415 * Throws: ConstructionException GTK+ fails to create the object. 416 */ 417 public this (string applicationId, GApplicationFlags flags) 418 { 419 // GApplication * g_application_new (const gchar *application_id, GApplicationFlags flags); 420 auto p = g_application_new(Str.toStringz(applicationId), flags); 421 if(p is null) 422 { 423 throw new ConstructionException("null returned by g_application_new(Str.toStringz(applicationId), flags)"); 424 } 425 this(cast(GApplication*) p); 426 } 427 428 /** 429 * Gets the unique identifier for application. 430 * Since 2.28 431 * Returns: the identifier for application, owned by application 432 */ 433 public string getApplicationId() 434 { 435 // const gchar * g_application_get_application_id (GApplication *application); 436 return Str.toString(g_application_get_application_id(gApplication)); 437 } 438 439 /** 440 * Sets the unique identifier for application. 441 * The application id can only be modified if application has not yet 442 * been registered. 443 * If non-NULL, the application id must be valid. See 444 * g_application_id_is_valid(). 445 * Since 2.28 446 * Params: 447 * application = a GApplication 448 * applicationId = the identifier for application. [allow-none] 449 */ 450 public void setApplicationId(string applicationId) 451 { 452 // void g_application_set_application_id (GApplication *application, const gchar *application_id); 453 g_application_set_application_id(gApplication, Str.toStringz(applicationId)); 454 } 455 456 /** 457 * Gets the current inactivity timeout for the application. 458 * This is the amount of time (in milliseconds) after the last call to 459 * g_application_release() before the application stops running. 460 * Since 2.28 461 * Returns: the timeout, in milliseconds 462 */ 463 public uint getInactivityTimeout() 464 { 465 // guint g_application_get_inactivity_timeout (GApplication *application); 466 return g_application_get_inactivity_timeout(gApplication); 467 } 468 469 /** 470 * Sets the current inactivity timeout for the application. 471 * This is the amount of time (in milliseconds) after the last call to 472 * g_application_release() before the application stops running. 473 * This call has no side effects of its own. The value set here is only 474 * used for next time g_application_release() drops the use count to 475 * zero. Any timeouts currently in progress are not impacted. 476 * Since 2.28 477 * Params: 478 * inactivityTimeout = the timeout, in milliseconds 479 */ 480 public void setInactivityTimeout(uint inactivityTimeout) 481 { 482 // void g_application_set_inactivity_timeout (GApplication *application, guint inactivity_timeout); 483 g_application_set_inactivity_timeout(gApplication, inactivityTimeout); 484 } 485 486 /** 487 * Gets the flags for application. 488 * See GApplicationFlags. 489 * Since 2.28 490 * Returns: the flags for application 491 */ 492 public GApplicationFlags getFlags() 493 { 494 // GApplicationFlags g_application_get_flags (GApplication *application); 495 return g_application_get_flags(gApplication); 496 } 497 498 /** 499 * Sets the flags for application. 500 * The flags can only be modified if application has not yet been 501 * registered. 502 * See GApplicationFlags. 503 * Since 2.28 504 * Params: 505 * flags = the flags for application 506 */ 507 public void setFlags(GApplicationFlags flags) 508 { 509 // void g_application_set_flags (GApplication *application, GApplicationFlags flags); 510 g_application_set_flags(gApplication, flags); 511 } 512 513 /** 514 * Gets the GDBusConnection being used by the application, or NULL. 515 * If GApplication is using its D-Bus backend then this function will 516 * return the GDBusConnection being used for uniqueness and 517 * communication with the desktop environment and other instances of the 518 * application. 519 * If GApplication is not using D-Bus then this function will return 520 * NULL. This includes the situation where the D-Bus backend would 521 * normally be in use but we were unable to connect to the bus. 522 * This function must not be called before the application has been 523 * registered. See g_application_get_is_registered(). 524 * Since 2.34 525 * Returns: a GDBusConnection, or NULL. [transfer none] 526 */ 527 public DBusConnection getDbusConnection() 528 { 529 // GDBusConnection * g_application_get_dbus_connection (GApplication *application); 530 auto p = g_application_get_dbus_connection(gApplication); 531 532 if(p is null) 533 { 534 return null; 535 } 536 537 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p); 538 } 539 540 /** 541 * Gets the D-Bus object path being used by the application, or NULL. 542 * If GApplication is using its D-Bus backend then this function will 543 * return the D-Bus object path that GApplication is using. If the 544 * application is the primary instance then there is an object published 545 * at this path. If the application is not the primary instance then 546 * the result of this function is undefined. 547 * If GApplication is not using D-Bus then this function will return 548 * NULL. This includes the situation where the D-Bus backend would 549 * normally be in use but we were unable to connect to the bus. 550 * This function must not be called before the application has been 551 * registered. See g_application_get_is_registered(). 552 * Since 2.34 553 * Returns: the object path, or NULL 554 */ 555 public string getDbusObjectPath() 556 { 557 // const gchar * g_application_get_dbus_object_path (GApplication *application); 558 return Str.toString(g_application_get_dbus_object_path(gApplication)); 559 } 560 561 /** 562 * Warning 563 * g_application_set_action_group has been deprecated since version 2.32 and should not be used in newly-written code. Use the GActionMap interface instead. Never ever 564 * mix use of this API with use of GActionMap on the same application 565 * or things will go very badly wrong. This function is known to 566 * introduce buggy behaviour (ie: signals not emitted on changes to the 567 * action group), so you should really use GActionMap instead. 568 * This used to be how actions were associated with a GApplication. 569 * Now there is GActionMap for that. 570 * Since 2.28 571 * Params: 572 * actionGroup = a GActionGroup, or NULL. [allow-none] 573 */ 574 public void setActionGroup(GActionGroup* actionGroup) 575 { 576 // void g_application_set_action_group (GApplication *application, GActionGroup *action_group); 577 g_application_set_action_group(gApplication, actionGroup); 578 } 579 580 /** 581 * Checks if application is registered. 582 * An application is registered if g_application_register() has been 583 * successfully called. 584 * Since 2.28 585 * Returns: TRUE if application is registered 586 */ 587 public int getIsRegistered() 588 { 589 // gboolean g_application_get_is_registered (GApplication *application); 590 return g_application_get_is_registered(gApplication); 591 } 592 593 /** 594 * Checks if application is remote. 595 * If application is remote then it means that another instance of 596 * application already exists (the 'primary' instance). Calls to 597 * perform actions on application will result in the actions being 598 * performed by the primary instance. 599 * The value of this property cannot be accessed before 600 * g_application_register() has been called. See 601 * g_application_get_is_registered(). 602 * Since 2.28 603 * Returns: TRUE if application is remote 604 */ 605 public int getIsRemote() 606 { 607 // gboolean g_application_get_is_remote (GApplication *application); 608 return g_application_get_is_remote(gApplication); 609 } 610 611 /** 612 * Attempts registration of the application. 613 * This is the point at which the application discovers if it is the 614 * primary instance or merely acting as a remote for an already-existing 615 * primary instance. This is implemented by attempting to acquire the 616 * application identifier as a unique bus name on the session bus using 617 * GDBus. 618 * If there is no application ID or if G_APPLICATION_NON_UNIQUE was 619 * given, then this process will always become the primary instance. 620 * Due to the internal architecture of GDBus, method calls can be 621 * dispatched at any time (even if a main loop is not running). For 622 * this reason, you must ensure that any object paths that you wish to 623 * register are registered before calling this function. 624 * If the application has already been registered then TRUE is 625 * returned with no work performed. 626 * The "startup" signal is emitted if registration succeeds 627 * and application is the primary instance (including the non-unique 628 * case). 629 * In the event of an error (such as cancellable being cancelled, or a 630 * failure to connect to the session bus), FALSE is returned and error 631 * is set appropriately. 632 * Note: the return value of this function is not an indicator that this 633 * instance is or is not the primary instance of the application. See 634 * g_application_get_is_remote() for that. 635 * Since 2.28 636 * Params: 637 * cancellable = a GCancellable, or NULL. [allow-none] 638 * Returns: TRUE if registration succeeded 639 * Throws: GException on failure. 640 */ 641 public int register(Cancellable cancellable) 642 { 643 // gboolean g_application_register (GApplication *application, GCancellable *cancellable, GError **error); 644 GError* err = null; 645 646 auto p = g_application_register(gApplication, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 647 648 if (err !is null) 649 { 650 throw new GException( new ErrorG(err) ); 651 } 652 653 return p; 654 } 655 656 /** 657 * Increases the use count of application. 658 * Use this function to indicate that the application has a reason to 659 * continue to run. For example, g_application_hold() is called by GTK+ 660 * when a toplevel window is on the screen. 661 * To cancel the hold, call g_application_release(). 662 */ 663 public void hold() 664 { 665 // void g_application_hold (GApplication *application); 666 g_application_hold(gApplication); 667 } 668 669 /** 670 * Decrease the use count of application. 671 * When the use count reaches zero, the application will stop running. 672 * Never call this function except to cancel the effect of a previous 673 * call to g_application_hold(). 674 */ 675 public void release() 676 { 677 // void g_application_release (GApplication *application); 678 g_application_release(gApplication); 679 } 680 681 /** 682 * Immediately quits the application. 683 * Upon return to the mainloop, g_application_run() will return, 684 * calling only the 'shutdown' function before doing so. 685 * The hold count is ignored. 686 * The result of calling g_application_run() again after it returns is 687 * unspecified. 688 * Since 2.32 689 */ 690 public void quit() 691 { 692 // void g_application_quit (GApplication *application); 693 g_application_quit(gApplication); 694 } 695 696 /** 697 * Activates the application. 698 * In essence, this results in the "activate" signal being 699 * emitted in the primary instance. 700 * The application must be registered before calling this function. 701 * Since 2.28 702 */ 703 public void activate() 704 { 705 // void g_application_activate (GApplication *application); 706 g_application_activate(gApplication); 707 } 708 709 /** 710 * Opens the given files. 711 * In essence, this results in the "open" signal being emitted 712 * in the primary instance. 713 * n_files must be greater than zero. 714 * hint is simply passed through to the ::open signal. It is 715 * intended to be used by applications that have multiple modes for 716 * opening files (eg: "view" vs "edit", etc). Unless you have a need 717 * for this functionality, you should use "". 718 * The application must be registered before calling this function 719 * and it must have the G_APPLICATION_HANDLES_OPEN flag set. 720 * Since 2.28 721 * Params: 722 * files = an array of GFiles to open. [array length=n_files] 723 * hint = a hint (or ""), but never NULL 724 */ 725 public void open(File[] files, string hint) 726 { 727 // void g_application_open (GApplication *application, GFile **files, gint n_files, const gchar *hint); 728 729 GFile*[] filesArray = new GFile*[files.length]; 730 for ( int i = 0; i < files.length ; i++ ) 731 { 732 filesArray[i] = files[i].getFileStruct(); 733 } 734 735 g_application_open(gApplication, filesArray.ptr, cast(int) files.length, Str.toStringz(hint)); 736 } 737 738 /** 739 * Runs the application. 740 * This function is intended to be run from main() and its return value 741 * is intended to be returned by main(). Although you are expected to pass 742 * the argc, argv parameters from main() to this function, it is possible 743 * to pass NULL if argv is not available or commandline handling is not 744 * required. 745 * First, the local_command_line() virtual function is invoked. 746 * This function always runs on the local instance. It gets passed a pointer 747 * to a NULL-terminated copy of argv and is expected to remove the arguments 748 * that it handled (shifting up remaining arguments). See 749 * Example 23, “Split commandline handling” for an example of 750 * parsing argv manually. Alternatively, you may use the GOptionContext API, 751 * after setting argc = g_strv_length (argv);. 752 * The last argument to local_command_line() is a pointer to the status 753 * variable which can used to set the exit status that is returned from 754 * g_application_run(). 755 * If local_command_line() returns TRUE, the command line is expected 756 * to be completely handled, including possibly registering as the primary 757 * instance, calling g_application_activate() or g_application_open(), etc. 758 * If local_command_line() returns FALSE then the application is registered 759 * and the "command-line" signal is emitted in the primary 760 * instance (which may or may not be this instance). The signal handler 761 * gets passed a GApplicationCommandLine object that (among other things) 762 * contains the remaining commandline arguments that have not been handled 763 * by local_command_line(). 764 * If the application has the G_APPLICATION_HANDLES_COMMAND_LINE 765 * flag set then the default implementation of local_command_line() 766 * always returns FALSE immediately, resulting in the commandline 767 * always being handled in the primary instance. 768 * Otherwise, the default implementation of local_command_line() tries 769 * to do a couple of things that are probably reasonable for most 770 * applications. First, g_application_register() is called to attempt 771 * to register the application. If that works, then the command line 772 * arguments are inspected. If no commandline arguments are given, then 773 * g_application_activate() is called. If commandline arguments are 774 * given and the G_APPLICATION_HANDLES_OPEN flag is set then they 775 * are assumed to be filenames and g_application_open() is called. 776 * If you need to handle commandline arguments that are not filenames, 777 * and you don't mind commandline handling to happen in the primary 778 * instance, you should set G_APPLICATION_HANDLES_COMMAND_LINE and 779 * process the commandline arguments in your "command-line" 780 * signal handler, either manually or using the GOptionContext API. 781 * If you are interested in doing more complicated local handling of the 782 * commandline then you should implement your own GApplication subclass 783 * and override local_command_line(). In this case, you most likely want 784 * to return TRUE from your local_command_line() implementation to 785 * suppress the default handling. See 786 * Example 23, “Split commandline handling” for an example. 787 * If, after the above is done, the use count of the application is zero 788 * then the exit status is returned immediately. If the use count is 789 * non-zero then the default main context is iterated until the use count 790 * falls to zero, at which point 0 is returned. 791 * If the G_APPLICATION_IS_SERVICE flag is set, then the service will 792 * run for as much as 10 seconds with a use count of zero while waiting 793 * for the message that caused the activation to arrive. After that, 794 * if the use count falls to zero the application will exit immediately, 795 * except in the case that g_application_set_inactivity_timeout() is in 796 * use. 797 * This function sets the prgname (g_set_prgname()), if not already set, 798 * to the basename of argv[0]. Since 2.38, if G_APPLICATION_IS_SERVICE 799 * is specified, the prgname is set to the application ID. The main 800 * impact of this is is that the wmclass of windows created by Gtk+ will 801 * be set accordingly, which helps the window manager determine which 802 * application is showing the window. 803 * Since 2.28 804 * Params: 805 * argv = the argv from main(), or NULL. [array length=argc][allow-none] 806 * Returns: the exit status 807 */ 808 public int run(string[] argv) 809 { 810 // int g_application_run (GApplication *application, int argc, char **argv); 811 return g_application_run(gApplication, cast(int) argv.length, Str.toStringzArray(argv)); 812 } 813 814 /** 815 * Sets or unsets the default application for the process, as returned 816 * by g_application_get_default(). 817 * This function does not take its own reference on application. If 818 * application is destroyed then the default application will revert 819 * back to NULL. 820 * Since 2.32 821 */ 822 public void setDefault() 823 { 824 // void g_application_set_default (GApplication *application); 825 g_application_set_default(gApplication); 826 } 827 828 /** 829 * Returns the default GApplication instance for this process. 830 * Normally there is only one GApplication per process and it becomes 831 * the default when it is created. You can exercise more control over 832 * this by using g_application_set_default(). 833 * If there is no default application then NULL is returned. 834 * Since 2.32 835 * Returns: the default application for this process, or NULL. [transfer none] 836 */ 837 public static Application getDefault() 838 { 839 // GApplication * g_application_get_default (void); 840 auto p = g_application_get_default(); 841 842 if(p is null) 843 { 844 return null; 845 } 846 847 return ObjectG.getDObject!(Application)(cast(GApplication*) p); 848 } 849 850 /** 851 * Increases the busy count of application. 852 * Use this function to indicate that the application is busy, for instance 853 * while a long running operation is pending. 854 * The busy state will be exposed to other processes, so a session shell will 855 * use that information to indicate the state to the user (e.g. with a 856 * spinner). 857 * To cancel the busy indication, use g_application_unmark_busy(). 858 * Since 2.38 859 */ 860 public void markBusy() 861 { 862 // void g_application_mark_busy (GApplication *application); 863 g_application_mark_busy(gApplication); 864 } 865 866 /** 867 * Decreases the busy count of application. 868 * When the busy count reaches zero, the new state will be propagated 869 * to other processes. 870 * This function must only be called to cancel the effect of a previous 871 * call to g_application_mark_busy(). 872 * Since 2.38 873 */ 874 public void unmarkBusy() 875 { 876 // void g_application_unmark_busy (GApplication *application); 877 g_application_unmark_busy(gApplication); 878 } 879 }