1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  A Glib.Application.Gapplication is the foundation of an application. It 
  26. --  wraps some low-level platform-specific services and is intended to act as 
  27. --  the foundation for higher-level application classes such as 
  28. --  Gtk.Application.Gtk_Application or Mx_Application. In general, you should 
  29. --  not use this class outside of a higher level framework. 
  30. -- 
  31. --  GApplication provides convenient life cycle management by maintaining a 
  32. --  'use count' for the primary application instance. The use count can be 
  33. --  changed using Glib.Application.Hold and Glib.Application.Release. If it 
  34. --  drops to zero, the application exits. Higher-level classes such as 
  35. --  Gtk.Application.Gtk_Application employ the use count to ensure that the 
  36. --  application stays alive as long as it has any opened windows. 
  37. -- 
  38. --  Another feature that GApplication (optionally) provides is process 
  39. --  uniqueness. Applications can make use of this functionality by providing a 
  40. --  unique application ID. If given, only one application with this ID can be 
  41. --  running at a time per session. The session concept is platform-dependent, 
  42. --  but corresponds roughly to a graphical desktop login. When your application 
  43. --  is launched again, its arguments are passed through platform communication 
  44. --  to the already running program. The already running instance of the program 
  45. --  is called the 'primary instance'; for non-unique applications this is the 
  46. --  always the current instance. On Linux, the D-Bus session bus is used for 
  47. --  communication. 
  48. -- 
  49. --  The use of Glib.Application.Gapplication differs from some other 
  50. --  commonly-used uniqueness libraries (such as libunique) in important ways. 
  51. --  The application is not expected to manually register itself and check if it 
  52. --  is the primary instance. Instead, the <code>main</code> function of a 
  53. --  Glib.Application.Gapplication should do very little more than instantiating 
  54. --  the application instance, possibly connecting signal handlers, then calling 
  55. --  Glib.Application.Run. All checks for uniqueness are done internally. If the 
  56. --  application is the primary instance then the startup signal is emitted and 
  57. --  the mainloop runs. If the application is not the primary instance then a 
  58. --  signal is sent to the primary instance and Glib.Application.Run promptly 
  59. --  returns. See the code examples below. 
  60. -- 
  61. --  If used, the expected form of an application identifier is very close to 
  62. --  that of of a <ulink 
  63. --  url="http://dbus.freedesktop.org/doc/dbus-specification.htmlmessage-protocol-names-interface">DBus 
  64. --  bus name</ulink>. Examples include: "com.example.MyApp", 
  65. --  "org.example.internal-apps.Calculator". For details on valid application 
  66. --  identifiers, see Glib.Application.Id_Is_Valid. 
  67. -- 
  68. --  On Linux, the application identifier is claimed as a well-known bus name 
  69. --  on the user's session bus. This means that the uniqueness of your 
  70. --  application is scoped to the current session. It also means that your 
  71. --  application may provide additional services (through registration of other 
  72. --  object paths) at that bus name. The registration of these object paths 
  73. --  should be done with the shared GDBus session bus. Note that due to the 
  74. --  internal architecture of GDBus, method calls can be dispatched at any time 
  75. --  (even if a main loop is not running). For this reason, you must ensure that 
  76. --  any object paths that you wish to register are registered before 
  77. --  Glib.Application.Gapplication attempts to acquire the bus name of your 
  78. --  application (which happens in Glib.Application.Register). Unfortunately, 
  79. --  this means that you cannot use Glib.Application.Get_Is_Remote to decide if 
  80. --  you want to register object paths. 
  81. -- 
  82. --  GApplication also implements the Glib.Action_Group.Gaction_Group and 
  83. --  Glib.Action_Map.Gaction_Map interfaces and lets you easily export actions 
  84. --  by adding them with Glib.Action_Map.Add_Action. When invoking an action by 
  85. --  calling Glib.Action_Group.Activate_Action on the application, it is always 
  86. --  invoked in the primary instance. The actions are also exported on the 
  87. --  session bus, and GIO provides the Gdbus.Action_Group.Gdbus_Action_Group 
  88. --  wrapper to conveniently access them remotely. GIO provides a 
  89. --  Gdbus.Menu_Model.Gdbus_Menu_Model wrapper for remote access to exported 
  90. --  GMenu_Models. 
  91. -- 
  92. --  There is a number of different entry points into a GApplication: 
  93. -- 
  94. --     * via 'Activate' (i.e. just starting the application) 
  95. -- 
  96. --     * via 'Open' (i.e. opening some files) 
  97. -- 
  98. --     * by handling a command-line 
  99. -- 
  100. --     * via activating an action 
  101. -- 
  102. --  The Glib.Application.Gapplication::startup signal lets you handle the 
  103. --  application initialization for all of these in a single place. 
  104. -- 
  105. --  Regardless of which of these entry points is used to start the 
  106. --  application, GApplication passes some <firstterm 
  107. --  id="platform-data">platform data' from the launching instance to the 
  108. --  primary instance, in the form of a Glib.Variant.Gvariant dictionary mapping 
  109. --  strings to variants. To use platform data, override the Before_Emit or 
  110. --  After_Emit virtual functions in your Glib.Application.Gapplication 
  111. --  subclass. When dealing with Glib.Application.Gapplication_Command_Line 
  112. --  objects, the platform data is directly available via 
  113. --  Glib.Application.Get_Cwd, Glib.Application.Get_Environ and 
  114. --  Glib.Application.Get_Platform_Data. 
  115. -- 
  116. --  As the name indicates, the platform data may vary depending on the 
  117. --  operating system, but it always includes the current directory (key "cwd"), 
  118. --  and optionally the environment (ie the set of environment variables and 
  119. --  their values) of the calling process (key "environ"). The environment is 
  120. --  only added to the platform data if the 
  121. --  Glib.Application.G_Application_Send_Environment flag is set. 
  122. --  Glib.Application.Gapplication subclasses can add their own platform data by 
  123. --  overriding the Add_Platform_Data virtual function. For instance, 
  124. --  Gtk.Application.Gtk_Application adds startup notification data in this way. 
  125. -- 
  126. --  To parse commandline arguments you may handle the 
  127. --  Glib.Application.Gapplication::command-line signal or override the 
  128. --  local_command_line vfunc, to parse them in either the primary instance or 
  129. --  the local instance, respectively. 
  130. -- 
  131. --  <example id="gapplication-example-open"> 
  132. --  == Opening files with a GApplication == 
  133. -- 
  134. --    <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-open.c"> 
  135. --    <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback> 
  136. --    </xi:include> 
  137. --  <example id="gapplication-example-actions"> 
  138. --  == A GApplication with actions == 
  139. -- 
  140. --    <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-actions.c"> 
  141. --    <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback> 
  142. --    </xi:include> 
  143. --  <example id="gapplication-example-menu"> 
  144. --  == A GApplication with menus == 
  145. -- 
  146. --    <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-menu.c"> 
  147. --    <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback> 
  148. --    </xi:include> 
  149. --  <example id="gapplication-example-dbushooks"> 
  150. --  == Using extra D-Bus hooks with a GApplication == 
  151. -- 
  152. --    <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-dbushooks.c"> 
  153. --    <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback> 
  154. --    </xi:include> 
  155. --  </description> 
  156. pragma Ada_2005; 
  157.  
  158. pragma Warnings (Off, "*is already use-visible*"); 
  159. with GNAT.Strings;            use GNAT.Strings; 
  160. with Glib;                    use Glib; 
  161. with Glib.Action;             use Glib.Action; 
  162. with Glib.Action_Group;       use Glib.Action_Group; 
  163. with Glib.Action_Map;         use Glib.Action_Map; 
  164. with Glib.Cancellable;        use Glib.Cancellable; 
  165. with Glib.Generic_Properties; use Glib.Generic_Properties; 
  166. with Glib.Object;             use Glib.Object; 
  167. with Glib.Properties;         use Glib.Properties; 
  168. with Glib.Types;              use Glib.Types; 
  169. with Glib.Variant;            use Glib.Variant; 
  170.  
  171. package Glib.Application is 
  172.  
  173.    type Gapplication_Record is new GObject_Record with null record; 
  174.    type Gapplication is access all Gapplication_Record'Class; 
  175.  
  176.    type GApplication_Flags is mod 2 ** Integer'Size; 
  177.    pragma Convention (C, GApplication_Flags); 
  178.    --  Flags used to define the behaviour of a Glib.Application.Gapplication. 
  179.  
  180.    G_Application_Flags_None : constant GApplication_Flags := 0; 
  181.    G_Application_Is_Service : constant GApplication_Flags := 1; 
  182.    G_Application_Is_Launcher : constant GApplication_Flags := 2; 
  183.    G_Application_Handles_Open : constant GApplication_Flags := 4; 
  184.    G_Application_Handles_Command_Line : constant GApplication_Flags := 8; 
  185.    G_Application_Send_Environment : constant GApplication_Flags := 16; 
  186.    G_Application_Non_Unique : constant GApplication_Flags := 32; 
  187.  
  188.    type Gapplication_Command_Line_Record is new GObject_Record with null record; 
  189.    type Gapplication_Command_Line is access all Gapplication_Command_Line_Record'Class; 
  190.  
  191.    ---------------------------- 
  192.    -- Enumeration Properties -- 
  193.    ---------------------------- 
  194.  
  195.    package GApplication_Flags_Properties is 
  196.       new Generic_Internal_Discrete_Property (GApplication_Flags); 
  197.    type Property_GApplication_Flags is new GApplication_Flags_Properties.Property; 
  198.  
  199.    ------------------ 
  200.    -- Constructors -- 
  201.    ------------------ 
  202.  
  203.    procedure G_New 
  204.       (Self           : out Gapplication; 
  205.        Application_Id : UTF8_String := ""; 
  206.        Flags          : GApplication_Flags); 
  207.    --  Creates a new Glib.Application.Gapplication instance. 
  208.    --  If non-null, the application id must be valid. See 
  209.    --  Glib.Application.Id_Is_Valid. 
  210.    --  If no application ID is given then some features of 
  211.    --  Glib.Application.Gapplication (most notably application uniqueness) will 
  212.    --  be disabled. 
  213.    --  "application_id": the application id 
  214.    --  "flags": the application flags 
  215.  
  216.    procedure Initialize 
  217.       (Self           : not null access Gapplication_Record'Class; 
  218.        Application_Id : UTF8_String := ""; 
  219.        Flags          : GApplication_Flags); 
  220.    --  Creates a new Glib.Application.Gapplication instance. 
  221.    --  If non-null, the application id must be valid. See 
  222.    --  Glib.Application.Id_Is_Valid. 
  223.    --  If no application ID is given then some features of 
  224.    --  Glib.Application.Gapplication (most notably application uniqueness) will 
  225.    --  be disabled. 
  226.    --  "application_id": the application id 
  227.    --  "flags": the application flags 
  228.  
  229.    function Gapplication_New 
  230.       (Application_Id : UTF8_String := ""; 
  231.        Flags          : GApplication_Flags) return Gapplication; 
  232.    --  Creates a new Glib.Application.Gapplication instance. 
  233.    --  If non-null, the application id must be valid. See 
  234.    --  Glib.Application.Id_Is_Valid. 
  235.    --  If no application ID is given then some features of 
  236.    --  Glib.Application.Gapplication (most notably application uniqueness) will 
  237.    --  be disabled. 
  238.    --  "application_id": the application id 
  239.    --  "flags": the application flags 
  240.  
  241.    function Get_Type return Glib.GType; 
  242.    pragma Import (C, Get_Type, "g_application_get_type"); 
  243.  
  244.    function Get_Type_Command_Line return Glib.GType; 
  245.    pragma Import (C, Get_Type_Command_Line, "g_application_command_line_get_type"); 
  246.  
  247.    ------------- 
  248.    -- Methods -- 
  249.    ------------- 
  250.  
  251.    procedure Activate (Self : not null access Gapplication_Record); 
  252.    --  Activates the application. 
  253.    --  In essence, this results in the Glib.Application.Gapplication::activate 
  254.    --  signal being emitted in the primary instance. 
  255.    --  The application must be registered before calling this function. 
  256.    --  Since: gtk+ 2.28 
  257.  
  258.    function Get_Application_Id 
  259.       (Self : not null access Gapplication_Record) return UTF8_String; 
  260.    --  Gets the unique identifier for Application. 
  261.    --  Since: gtk+ 2.28 
  262.  
  263.    procedure Set_Application_Id 
  264.       (Self           : not null access Gapplication_Record; 
  265.        Application_Id : UTF8_String := ""); 
  266.    --  Sets the unique identifier for Application. 
  267.    --  The application id can only be modified if Application has not yet been 
  268.    --  registered. 
  269.    --  If non-null, the application id must be valid. See 
  270.    --  Glib.Application.Id_Is_Valid. 
  271.    --  Since: gtk+ 2.28 
  272.    --  "application_id": the identifier for Application 
  273.  
  274.    function Get_Dbus_Object_Path 
  275.       (Self : not null access Gapplication_Record) return UTF8_String; 
  276.    --  Gets the D-Bus object path being used by the application, or null. 
  277.    --  If Glib.Application.Gapplication is using its D-Bus backend then this 
  278.    --  function will return the D-Bus object path that 
  279.    --  Glib.Application.Gapplication is using. If the application is the 
  280.    --  primary instance then there is an object published at this path. If the 
  281.    --  application is not the primary instance then the result of this function 
  282.    --  is undefined. 
  283.    --  If Glib.Application.Gapplication is not using D-Bus then this function 
  284.    --  will return null. This includes the situation where the D-Bus backend 
  285.    --  would normally be in use but we were unable to connect to the bus. 
  286.    --  This function must not be called before the application has been 
  287.    --  registered. See Glib.Application.Get_Is_Registered. 
  288.    --  Since: gtk+ 2.34 
  289.  
  290.    function Get_Flags 
  291.       (Self : not null access Gapplication_Record) return GApplication_Flags; 
  292.    --  Gets the flags for Application. 
  293.    --  See Glib.Application.GApplication_Flags. 
  294.    --  Since: gtk+ 2.28 
  295.  
  296.    procedure Set_Flags 
  297.       (Self  : not null access Gapplication_Record; 
  298.        Flags : GApplication_Flags); 
  299.    --  Sets the flags for Application. 
  300.    --  The flags can only be modified if Application has not yet been 
  301.    --  registered. 
  302.    --  See Glib.Application.GApplication_Flags. 
  303.    --  Since: gtk+ 2.28 
  304.    --  "flags": the flags for Application 
  305.  
  306.    function Get_Inactivity_Timeout 
  307.       (Self : not null access Gapplication_Record) return Guint; 
  308.    --  Gets the current inactivity timeout for the application. 
  309.    --  This is the amount of time (in milliseconds) after the last call to 
  310.    --  Glib.Application.Release before the application stops running. 
  311.    --  Since: gtk+ 2.28 
  312.  
  313.    procedure Set_Inactivity_Timeout 
  314.       (Self               : not null access Gapplication_Record; 
  315.        Inactivity_Timeout : Guint); 
  316.    --  Sets the current inactivity timeout for the application. 
  317.    --  This is the amount of time (in milliseconds) after the last call to 
  318.    --  Glib.Application.Release before the application stops running. 
  319.    --  This call has no side effects of its own. The value set here is only 
  320.    --  used for next time Glib.Application.Release drops the use count to zero. 
  321.    --  Any timeouts currently in progress are not impacted. 
  322.    --  Since: gtk+ 2.28 
  323.    --  "inactivity_timeout": the timeout, in milliseconds 
  324.  
  325.    function Get_Is_Registered 
  326.       (Self : not null access Gapplication_Record) return Boolean; 
  327.    --  Checks if Application is registered. 
  328.    --  An application is registered if Glib.Application.Register has been 
  329.    --  successfully called. 
  330.    --  Since: gtk+ 2.28 
  331.  
  332.    function Get_Is_Remote 
  333.       (Self : not null access Gapplication_Record) return Boolean; 
  334.    --  Checks if Application is remote. 
  335.    --  If Application is remote then it means that another instance of 
  336.    --  application already exists (the 'primary' instance). Calls to perform 
  337.    --  actions on Application will result in the actions being performed by the 
  338.    --  primary instance. 
  339.    --  The value of this property cannot be accessed before 
  340.    --  Glib.Application.Register has been called. See 
  341.    --  Glib.Application.Get_Is_Registered. 
  342.    --  Since: gtk+ 2.28 
  343.  
  344.    function Get_Is_Remote 
  345.       (Self : not null access Gapplication_Command_Line_Record) 
  346.        return Boolean; 
  347.    --  Determines if Cmdline represents a remote invocation. 
  348.    --  Since: gtk+ 2.28 
  349.  
  350.    procedure Hold (Self : not null access Gapplication_Record); 
  351.    --  Increases the use count of Application. 
  352.    --  Use this function to indicate that the application has a reason to 
  353.    --  continue to run. For example, Glib.Application.Hold is called by GTK+ 
  354.    --  when a toplevel window is on the screen. 
  355.    --  To cancel the hold, call Glib.Application.Release. 
  356.  
  357.    procedure Quit (Self : not null access Gapplication_Record); 
  358.    --  Immediately quits the application. 
  359.    --  Upon return to the mainloop, Glib.Application.Run will return, calling 
  360.    --  only the 'shutdown' function before doing so. 
  361.    --  The hold count is ignored. 
  362.    --  The result of calling Glib.Application.Run again after it returns is 
  363.    --  unspecified. 
  364.    --  Since: gtk+ 2.32 
  365.  
  366.    function Register 
  367.       (Self        : not null access Gapplication_Record; 
  368.        Cancellable : access Glib.Cancellable.Gcancellable_Record'Class) 
  369.        return Boolean; 
  370.    --  Attempts registration of the application. 
  371.    --  This is the point at which the application discovers if it is the 
  372.    --  primary instance or merely acting as a remote for an already-existing 
  373.    --  primary instance. This is implemented by attempting to acquire the 
  374.    --  application identifier as a unique bus name on the session bus using 
  375.    --  GDBus. 
  376.    --  If there is no application ID or if 
  377.    --  Glib.Application.G_Application_Non_Unique was given, then this process 
  378.    --  will always become the primary instance. 
  379.    --  Due to the internal architecture of GDBus, method calls can be 
  380.    --  dispatched at any time (even if a main loop is not running). For this 
  381.    --  reason, you must ensure that any object paths that you wish to register 
  382.    --  are registered before calling this function. 
  383.    --  If the application has already been registered then True is returned 
  384.    --  with no work performed. 
  385.    --  The Glib.Application.Gapplication::startup signal is emitted if 
  386.    --  registration succeeds and Application is the primary instance (including 
  387.    --  the non-unique case). 
  388.    --  In the event of an error (such as Cancellable being cancelled, or a 
  389.    --  failure to connect to the session bus), False is returned and Error is 
  390.    --  set appropriately. 
  391.    --  Note: the return value of this function is not an indicator that this 
  392.    --  instance is or is not the primary instance of the application. See 
  393.    --  Glib.Application.Get_Is_Remote for that. 
  394.    --  Since: gtk+ 2.28 
  395.    --  "cancellable": a Glib.Cancellable.Gcancellable, or null 
  396.  
  397.    procedure Release (Self : not null access Gapplication_Record); 
  398.    --  Decrease the use count of Application. 
  399.    --  When the use count reaches zero, the application will stop running. 
  400.    --  Never call this function except to cancel the effect of a previous call 
  401.    --  to Glib.Application.Hold. 
  402.  
  403.    function Run 
  404.       (Self : not null access Gapplication_Record; 
  405.        Argc : Gint; 
  406.        Argv : GNAT.Strings.String_List) return Gint; 
  407.    --  Runs the application. 
  408.    --  This function is intended to be run from main and its return value is 
  409.    --  intended to be returned by main. Although you are expected to pass the 
  410.    --  Argc, Argv parameters from main to this function, it is possible to pass 
  411.    --  null if Argv is not available or commandline handling is not required. 
  412.    --  First, the local_command_line virtual function is invoked. This 
  413.    --  function always runs on the local instance. It gets passed a pointer to 
  414.    --  a null-terminated copy of Argv and is expected to remove the arguments 
  415.    --  that it handled (shifting up remaining arguments). See <xref 
  416.    --  linkend="gapplication-example-cmdline2"/> for an example of parsing Argv 
  417.    --  manually. Alternatively, you may use the Glib.Option.Goption_Context 
  418.    --  API, after setting 'argc = g_strv_length (argv);'. 
  419.    --  The last argument to local_command_line is a pointer to the Status 
  420.    --  variable which can used to set the exit status that is returned from 
  421.    --  Glib.Application.Run. 
  422.    --  If local_command_line returns True, the command line is expected to be 
  423.    --  completely handled, including possibly registering as the primary 
  424.    --  instance, calling Glib.Application.Activate or g_application_open, etc. 
  425.    --  If local_command_line returns False then the application is registered 
  426.    --  and the Glib.Application.Gapplication::command-line signal is emitted in 
  427.    --  the primary instance (which may or may not be this instance). The signal 
  428.    --  handler gets passed a Glib.Application.Gapplication_Command_Line object 
  429.    --  that (among other things) contains the remaining commandline arguments 
  430.    --  that have not been handled by local_command_line. 
  431.    --  If the application has the 
  432.    --  Glib.Application.G_Application_Handles_Command_Line flag set then the 
  433.    --  default implementation of local_command_line always returns False 
  434.    --  immediately, resulting in the commandline always being handled in the 
  435.    --  primary instance. 
  436.    --  Otherwise, the default implementation of local_command_line tries to do 
  437.    --  a couple of things that are probably reasonable for most applications. 
  438.    --  First, Glib.Application.Register is called to attempt to register the 
  439.    --  application. If that works, then the command line arguments are 
  440.    --  inspected. If no commandline arguments are given, then 
  441.    --  Glib.Application.Activate is called. If commandline arguments are given 
  442.    --  and the Glib.Application.G_Application_Handles_Open flag is set then 
  443.    --  they are assumed to be filenames and g_application_open is called. 
  444.    --  If you need to handle commandline arguments that are not filenames, and 
  445.    --  you don't mind commandline handling to happen in the primary instance, 
  446.    --  you should set Glib.Application.G_Application_Handles_Command_Line and 
  447.    --  process the commandline arguments in your 
  448.    --  Glib.Application.Gapplication::command-line signal handler, either 
  449.    --  manually or using the Glib.Option.Goption_Context API. 
  450.    --  If you are interested in doing more complicated local handling of the 
  451.    --  commandline then you should implement your own 
  452.    --  Glib.Application.Gapplication subclass and override local_command_line. 
  453.    --  In this case, you most likely want to return True from your 
  454.    --  local_command_line implementation to suppress the default handling. See 
  455.    --  <xref linkend="gapplication-example-cmdline2"/> for an example. 
  456.    --  If, after the above is done, the use count of the application is zero 
  457.    --  then the exit status is returned immediately. If the use count is 
  458.    --  non-zero then the default main context is iterated until the use count 
  459.    --  falls to zero, at which point 0 is returned. 
  460.    --  If the Glib.Application.G_Application_Is_Service flag is set, then the 
  461.    --  service will run for as much as 10 seconds with a use count of zero 
  462.    --  while waiting for the message that caused the activation to arrive. 
  463.    --  After that, if the use count falls to zero the application will exit 
  464.    --  immediately, except in the case that 
  465.    --  Glib.Application.Set_Inactivity_Timeout is in use. 
  466.    --  Since: gtk+ 2.28 
  467.    --  "argc": the argc from main (or 0 if Argv is null) 
  468.    --  "argv": the argv from main, or null 
  469.  
  470.    procedure Set_Action_Group 
  471.       (Self         : not null access Gapplication_Record; 
  472.        Action_Group : Glib.Action_Group.Gaction_Group); 
  473.    pragma Obsolescent (Set_Action_Group); 
  474.    --  This used to be how actions were associated with a 
  475.    --  Glib.Application.Gapplication. Now there is Glib.Action_Map.Gaction_Map 
  476.    --  for that. 
  477.    --  Since: gtk+ 2.28 
  478.    --  Deprecated since 2.32:Use the Glib.Action_Map.Gaction_Map interface 
  479.    --  instead. Never ever mix use of this API with use of 
  480.    --  Glib.Action_Map.Gaction_Map on the same Application or things will go 
  481.    --  very badly wrong. This function is known to introduce buggy behaviour 
  482.    --  (ie, signals not emitted on changes to the action group), so you should 
  483.    --  really use Glib.Action_Map.Gaction_Map instead. 
  484.    --  "action_group": a Glib.Action_Group.Gaction_Group, or null 
  485.  
  486.    procedure Set_Default (Self : not null access Gapplication_Record); 
  487.    --  Sets or unsets the default application for the process, as returned by 
  488.    --  Glib.Application.Get_Default. 
  489.    --  This function does not take its own reference on Application. If 
  490.    --  Application is destroyed then the default application will revert back 
  491.    --  to null. 
  492.    --  Since: gtk+ 2.32 
  493.  
  494.    function Get_Arguments 
  495.       (Self : not null access Gapplication_Command_Line_Record) 
  496.        return GNAT.Strings.String_List; 
  497.    --  Gets the list of arguments that was passed on the command line. 
  498.    --  The strings in the array may contain non-utf8 data. 
  499.    --  The return value is null-terminated and should be freed using 
  500.    --  g_strfreev. 
  501.    --  Since: gtk+ 2.28 
  502.  
  503.    function Get_Cwd 
  504.       (Self : not null access Gapplication_Command_Line_Record) 
  505.        return UTF8_String; 
  506.    --  Gets the working directory of the command line invocation. The string 
  507.    --  may contain non-utf8 data. 
  508.    --  It is possible that the remote application did not send a working 
  509.    --  directory, so this may be null. 
  510.    --  The return value should not be modified or freed and is valid for as 
  511.    --  long as Cmdline exists. 
  512.    --  Since: gtk+ 2.28 
  513.  
  514.    function Get_Environ 
  515.       (Self : not null access Gapplication_Command_Line_Record) 
  516.        return GNAT.Strings.String_List; 
  517.    --  Gets the contents of the 'environ' variable of the command line 
  518.    --  invocation, as would be returned by g_get_environ, ie as a 
  519.    --  null-terminated list of strings in the form 'NAME=VALUE'. The strings 
  520.    --  may contain non-utf8 data. 
  521.    --  The remote application usually does not send an environment. Use 
  522.    --  Glib.Application.G_Application_Send_Environment to affect that. Even 
  523.    --  with this flag set it is possible that the environment is still not 
  524.    --  available (due to invocation messages from other applications). 
  525.    --  The return value should not be modified or freed and is valid for as 
  526.    --  long as Cmdline exists. 
  527.    --  See Glib.Application.Getenv if you are only interested in the value of 
  528.    --  a single environment variable. 
  529.    --  Since: gtk+ 2.28 
  530.  
  531.    function Get_Exit_Status 
  532.       (Self : not null access Gapplication_Command_Line_Record) return Gint; 
  533.    --  Gets the exit status of Cmdline. See Glib.Application.Set_Exit_Status 
  534.    --  for more information. 
  535.    --  Since: gtk+ 2.28 
  536.  
  537.    procedure Set_Exit_Status 
  538.       (Self        : not null access Gapplication_Command_Line_Record; 
  539.        Exit_Status : Gint); 
  540.    --  Sets the exit status that will be used when the invoking process exits. 
  541.    --  The return value of the Glib.Application.Gapplication::command-line 
  542.    --  signal is passed to this function when the handler returns. This is the 
  543.    --  usual way of setting the exit status. 
  544.    --  In the event that you want the remote invocation to continue running 
  545.    --  and want to decide on the exit status in the future, you can use this 
  546.    --  call. For the case of a remote invocation, the remote process will 
  547.    --  typically exit when the last reference is dropped on Cmdline. The exit 
  548.    --  status of the remote process will be equal to the last value that was 
  549.    --  set with this function. 
  550.    --  In the case that the commandline invocation is local, the situation is 
  551.    --  slightly more complicated. If the commandline invocation results in the 
  552.    --  mainloop running (ie: because the use-count of the application increased 
  553.    --  to a non-zero value) then the application is considered to have been 
  554.    --  'successful' in a certain sense, and the exit status is always zero. If 
  555.    --  the application use count is zero, though, the exit status of the local 
  556.    --  Glib.Application.Gapplication_Command_Line is used. 
  557.    --  Since: gtk+ 2.28 
  558.    --  "exit_status": the exit status 
  559.  
  560.    function Get_Platform_Data 
  561.       (Self : not null access Gapplication_Command_Line_Record) 
  562.        return Glib.Variant.Gvariant; 
  563.    --  Gets the platform data associated with the invocation of Cmdline. 
  564.    --  This is a Glib.Variant.Gvariant dictionary containing information about 
  565.    --  the context in which the invocation occurred. It typically contains 
  566.    --  information like the current working directory and the startup 
  567.    --  notification ID. 
  568.    --  For local invocation, it will be null. 
  569.    --  Since: gtk+ 2.28 
  570.  
  571.    function Getenv 
  572.       (Self : not null access Gapplication_Command_Line_Record; 
  573.        Name : UTF8_String) return UTF8_String; 
  574.    --  Gets the value of a particular environment variable of the command line 
  575.    --  invocation, as would be returned by g_getenv. The strings may contain 
  576.    --  non-utf8 data. 
  577.    --  The remote application usually does not send an environment. Use 
  578.    --  Glib.Application.G_Application_Send_Environment to affect that. Even 
  579.    --  with this flag set it is possible that the environment is still not 
  580.    --  available (due to invocation messages from other applications). 
  581.    --  The return value should not be modified or freed and is valid for as 
  582.    --  long as Cmdline exists. 
  583.    --  Since: gtk+ 2.28 
  584.    --  "name": the environment variable to get 
  585.  
  586.    ---------------------- 
  587.    -- GtkAda additions -- 
  588.    ---------------------- 
  589.  
  590.    function Run 
  591.      (Self : not null access Gapplication_Record) return Gint; 
  592.    --  Same as above, but automatically sets argc argv from actual values. 
  593.  
  594.    --------------------------------------------- 
  595.    -- Inherited subprograms (from interfaces) -- 
  596.    --------------------------------------------- 
  597.  
  598.    procedure Action_Added 
  599.       (Self        : not null access Gapplication_Record; 
  600.        Action_Name : UTF8_String); 
  601.  
  602.    procedure Action_Enabled_Changed 
  603.       (Self        : not null access Gapplication_Record; 
  604.        Action_Name : UTF8_String; 
  605.        Enabled     : Boolean); 
  606.  
  607.    procedure Action_Removed 
  608.       (Self        : not null access Gapplication_Record; 
  609.        Action_Name : UTF8_String); 
  610.  
  611.    procedure Action_State_Changed 
  612.       (Self        : not null access Gapplication_Record; 
  613.        Action_Name : UTF8_String; 
  614.        State       : Glib.Variant.Gvariant); 
  615.  
  616.    procedure Activate_Action 
  617.       (Self        : not null access Gapplication_Record; 
  618.        Action_Name : UTF8_String; 
  619.        Parameter   : Glib.Variant.Gvariant); 
  620.  
  621.    procedure Change_Action_State 
  622.       (Self        : not null access Gapplication_Record; 
  623.        Action_Name : UTF8_String; 
  624.        Value       : Glib.Variant.Gvariant); 
  625.  
  626.    function Get_Action_Enabled 
  627.       (Self        : not null access Gapplication_Record; 
  628.        Action_Name : UTF8_String) return Boolean; 
  629.  
  630.    function Get_Action_Parameter_Type 
  631.       (Self        : not null access Gapplication_Record; 
  632.        Action_Name : UTF8_String) return Glib.Variant.Gvariant_Type; 
  633.  
  634.    function Get_Action_State 
  635.       (Self        : not null access Gapplication_Record; 
  636.        Action_Name : UTF8_String) return Glib.Variant.Gvariant; 
  637.  
  638.    function Get_Action_State_Hint 
  639.       (Self        : not null access Gapplication_Record; 
  640.        Action_Name : UTF8_String) return Glib.Variant.Gvariant; 
  641.  
  642.    function Get_Action_State_Type 
  643.       (Self        : not null access Gapplication_Record; 
  644.        Action_Name : UTF8_String) return Glib.Variant.Gvariant_Type; 
  645.  
  646.    function Has_Action 
  647.       (Self        : not null access Gapplication_Record; 
  648.        Action_Name : UTF8_String) return Boolean; 
  649.  
  650.    function List_Actions 
  651.       (Self : not null access Gapplication_Record) 
  652.        return GNAT.Strings.String_List; 
  653.  
  654.    function Query_Action 
  655.       (Self           : not null access Gapplication_Record; 
  656.        Action_Name    : UTF8_String; 
  657.        Enabled        : access Boolean; 
  658.        Parameter_Type : access Glib.Variant.Gvariant_Type; 
  659.        State_Type     : access Glib.Variant.Gvariant_Type; 
  660.        State_Hint     : access Glib.Variant.Gvariant; 
  661.        State          : access Glib.Variant.Gvariant) return Boolean; 
  662.  
  663.    procedure Add_Action 
  664.       (Self   : not null access Gapplication_Record; 
  665.        Action : Glib.Action.Gaction); 
  666.  
  667.    procedure Add_Action_Entries 
  668.       (Self      : not null access Gapplication_Record; 
  669.        Entries   : GAction_Entry_Array; 
  670.        User_Data : System.Address := System.Null_Address); 
  671.  
  672.    function Lookup_Action 
  673.       (Self        : not null access Gapplication_Record; 
  674.        Action_Name : UTF8_String) return Glib.Action.Gaction; 
  675.  
  676.    procedure Remove_Action 
  677.       (Self        : not null access Gapplication_Record; 
  678.        Action_Name : UTF8_String); 
  679.  
  680.    --------------- 
  681.    -- Functions -- 
  682.    --------------- 
  683.  
  684.    function Get_Default return Gapplication; 
  685.    --  Returns the default Glib.Application.Gapplication instance for this 
  686.    --  process. 
  687.    --  Normally there is only one Glib.Application.Gapplication per process 
  688.    --  and it becomes the default when it is created. You can exercise more 
  689.    --  control over this by using Glib.Application.Set_Default. 
  690.    --  If there is no default application then null is returned. 
  691.    --  Since: gtk+ 2.32 
  692.  
  693.    function Id_Is_Valid (Application_Id : UTF8_String) return Boolean; 
  694.    --  Checks if Application_Id is a valid application identifier. 
  695.    --  A valid ID is required for calls to Glib.Application.G_New and 
  696.    --  Glib.Application.Set_Application_Id. 
  697.    --  For convenience, the restrictions on application identifiers are 
  698.    --  reproduced here: 
  699.    --  
  700.    --     * Application identifiers must contain only the ASCII characters 
  701.    --  "[A-Z][a-z][0-9]_-." and must not begin with a digit. 
  702.    --     * Application identifiers must contain at least one '.' (period) 
  703.    --  character (and thus at least three elements). 
  704.    --     * Application identifiers must not begin or end with a '.' (period) 
  705.    --  character. 
  706.    --     * Application identifiers must not contain consecutive '.' (period) 
  707.    --  characters. 
  708.    --     * Application identifiers must not exceed 255 characters. 
  709.    --  "application_id": a potential application identifier 
  710.  
  711.    ---------------- 
  712.    -- Properties -- 
  713.    ---------------- 
  714.    --  The following properties are defined for this widget. See 
  715.    --  Glib.Properties for more information on properties) 
  716.    --  The following properties are defined for this widget. See 
  717.    --  Glib.Properties for more information on properties) 
  718.  
  719.    Action_Group_Property : constant Glib.Properties.Property_Object; 
  720.    --  Type: Gtk.Action_Group.Gtk_Action_Group 
  721.    --  Flags: write 
  722.  
  723.    Application_Id_Property : constant Glib.Properties.Property_String; 
  724.  
  725.    Flags_Property : constant Glib.Properties.Property_Boxed; 
  726.    --  Type: Application_Flags 
  727.  
  728.    Inactivity_Timeout_Property : constant Glib.Properties.Property_Uint; 
  729.  
  730.    Is_Registered_Property : constant Glib.Properties.Property_Boolean; 
  731.  
  732.    Is_Remote_Property : constant Glib.Properties.Property_Boolean; 
  733.  
  734.    Arguments_Property : constant Glib.Properties.Property_Object; 
  735.    --  Type: Glib.Variant.Gvariant 
  736.    --  Flags: write 
  737.  
  738.    Platform_Data_Property : constant Glib.Properties.Property_Object; 
  739.    --  Type: Glib.Variant.Gvariant 
  740.    --  Flags: write 
  741.  
  742.    ------------- 
  743.    -- Signals -- 
  744.    ------------- 
  745.  
  746.    type Cb_Gapplication_Void is not null access procedure (Self : access Gapplication_Record'Class); 
  747.  
  748.    type Cb_GObject_Void is not null access procedure 
  749.      (Self : access Glib.Object.GObject_Record'Class); 
  750.  
  751.    Signal_Activate : constant Glib.Signal_Name := "activate"; 
  752.    procedure On_Activate 
  753.       (Self  : not null access Gapplication_Record; 
  754.        Call  : Cb_Gapplication_Void; 
  755.        After : Boolean := False); 
  756.    procedure On_Activate 
  757.       (Self  : not null access Gapplication_Record; 
  758.        Call  : Cb_GObject_Void; 
  759.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  760.        After : Boolean := False); 
  761.    --  The ::activate signal is emitted on the primary instance when an 
  762.    --  activation occurs. See Glib.Application.Activate. 
  763.  
  764.    type Cb_Gapplication_Gapplication_Command_Line_Gint is not null access function 
  765.      (Self         : access Gapplication_Record'Class; 
  766.       Command_Line : not null access Gapplication_Command_Line_Record'Class) 
  767.    return Gint; 
  768.  
  769.    type Cb_GObject_Gapplication_Command_Line_Gint is not null access function 
  770.      (Self         : access Glib.Object.GObject_Record'Class; 
  771.       Command_Line : not null access Gapplication_Command_Line_Record'Class) 
  772.    return Gint; 
  773.  
  774.    Signal_Command_Line : constant Glib.Signal_Name := "command-line"; 
  775.    procedure On_Command_Line 
  776.       (Self  : not null access Gapplication_Record; 
  777.        Call  : Cb_Gapplication_Gapplication_Command_Line_Gint; 
  778.        After : Boolean := False); 
  779.    procedure On_Command_Line 
  780.       (Self  : not null access Gapplication_Record; 
  781.        Call  : Cb_GObject_Gapplication_Command_Line_Gint; 
  782.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  783.        After : Boolean := False); 
  784.    --  The ::command-line signal is emitted on the primary instance when a 
  785.    --  commandline is not handled locally. See Glib.Application.Run and the 
  786.    --  Glib.Application.Gapplication_Command_Line documentation for more 
  787.    --  information. 
  788.    --  
  789.    --  Callback parameters: 
  790.    --    --  "command_line": a Glib.Application.Gapplication_Command_Line 
  791.    --    --  representing the passed commandline 
  792.    --    --  Returns An integer that is set as the exit status for the calling process. See Glib.Application.Set_Exit_Status. 
  793.  
  794.    Signal_Open : constant Glib.Signal_Name := "open"; 
  795.    --  The ::open signal is emitted on the primary instance when there are 
  796.    --  files to open. See g_application_open for more information. 
  797.    --    procedure Handler 
  798.    --       (Self    : access Gapplication_Record'Class; 
  799.    --        Files   : array_of_File; 
  800.    --        N_Files : Gint; 
  801.    --        Hint    : UTF8_String) 
  802.    --  
  803.    --  Callback parameters: 
  804.    --    --  "files": an array of GFiles 
  805.    --    --  "n_files": the length of Files 
  806.    --    --  "hint": a hint provided by the calling instance 
  807.  
  808.    Signal_Shutdown : constant Glib.Signal_Name := "shutdown"; 
  809.    procedure On_Shutdown 
  810.       (Self  : not null access Gapplication_Record; 
  811.        Call  : Cb_Gapplication_Void; 
  812.        After : Boolean := False); 
  813.    procedure On_Shutdown 
  814.       (Self  : not null access Gapplication_Record; 
  815.        Call  : Cb_GObject_Void; 
  816.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  817.        After : Boolean := False); 
  818.    --  The ::shutdown signal is emitted only on the registered primary 
  819.    --  instance immediately after the main loop terminates. 
  820.  
  821.    Signal_Startup : constant Glib.Signal_Name := "startup"; 
  822.    procedure On_Startup 
  823.       (Self  : not null access Gapplication_Record; 
  824.        Call  : Cb_Gapplication_Void; 
  825.        After : Boolean := False); 
  826.    procedure On_Startup 
  827.       (Self  : not null access Gapplication_Record; 
  828.        Call  : Cb_GObject_Void; 
  829.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  830.        After : Boolean := False); 
  831.    --  The ::startup signal is emitted on the primary instance immediately 
  832.    --  after registration. See Glib.Application.Register. 
  833.  
  834.    ---------------- 
  835.    -- Interfaces -- 
  836.    ---------------- 
  837.    --  This class implements several interfaces. See Glib.Types 
  838.    -- 
  839.    --  - "ActionGroup" 
  840.    -- 
  841.    --  - "ActionMap" 
  842.  
  843.    package Implements_Gaction_Group is new Glib.Types.Implements 
  844.      (Glib.Action_Group.Gaction_Group, Gapplication_Record, Gapplication); 
  845.    function "+" 
  846.      (Widget : access Gapplication_Record'Class) 
  847.    return Glib.Action_Group.Gaction_Group 
  848.    renames Implements_Gaction_Group.To_Interface; 
  849.    function "-" 
  850.      (Interf : Glib.Action_Group.Gaction_Group) 
  851.    return Gapplication 
  852.    renames Implements_Gaction_Group.To_Object; 
  853.  
  854.    package Implements_Gaction_Map is new Glib.Types.Implements 
  855.      (Glib.Action_Map.Gaction_Map, Gapplication_Record, Gapplication); 
  856.    function "+" 
  857.      (Widget : access Gapplication_Record'Class) 
  858.    return Glib.Action_Map.Gaction_Map 
  859.    renames Implements_Gaction_Map.To_Interface; 
  860.    function "-" 
  861.      (Interf : Glib.Action_Map.Gaction_Map) 
  862.    return Gapplication 
  863.    renames Implements_Gaction_Map.To_Object; 
  864.  
  865. private 
  866.    Platform_Data_Property : constant Glib.Properties.Property_Object := 
  867.      Glib.Properties.Build ("platform-data"); 
  868.    Arguments_Property : constant Glib.Properties.Property_Object := 
  869.      Glib.Properties.Build ("arguments"); 
  870.    Is_Remote_Property : constant Glib.Properties.Property_Boolean := 
  871.      Glib.Properties.Build ("is-remote"); 
  872.    Is_Registered_Property : constant Glib.Properties.Property_Boolean := 
  873.      Glib.Properties.Build ("is-registered"); 
  874.    Inactivity_Timeout_Property : constant Glib.Properties.Property_Uint := 
  875.      Glib.Properties.Build ("inactivity-timeout"); 
  876.    Flags_Property : constant Glib.Properties.Property_Boxed := 
  877.      Glib.Properties.Build ("flags"); 
  878.    Application_Id_Property : constant Glib.Properties.Property_String := 
  879.      Glib.Properties.Build ("application-id"); 
  880.    Action_Group_Property : constant Glib.Properties.Property_Object := 
  881.      Glib.Properties.Build ("action-group"); 
  882. end Glib.Application;