GApplication: make distinction about menus
[platform/upstream/glib.git] / gio / gapplication.h
1 /*
2  * Copyright © 2010 Codethink Limited
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2 of the licence or (at
7  * your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17  * Boston, MA 02111-1307, USA.
18  *
19  * Authors: Ryan Lortie <desrt@desrt.ca>
20  */
21
22 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
23 #error "Only <gio/gio.h> can be included directly."
24 #endif
25
26 #ifndef __G_APPLICATION_H__
27 #define __G_APPLICATION_H__
28
29 #include <gio/giotypes.h>
30
31 G_BEGIN_DECLS
32
33 #define G_TYPE_APPLICATION                                  (g_application_get_type ())
34 #define G_APPLICATION(inst)                                 (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
35                                                              G_TYPE_APPLICATION, GApplication))
36 #define G_APPLICATION_CLASS(class)                          (G_TYPE_CHECK_CLASS_CAST ((class),                       \
37                                                              G_TYPE_APPLICATION, GApplicationClass))
38 #define G_IS_APPLICATION(inst)                              (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_APPLICATION))
39 #define G_IS_APPLICATION_CLASS(class)                       (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_APPLICATION))
40 #define G_APPLICATION_GET_CLASS(inst)                       (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
41                                                              G_TYPE_APPLICATION, GApplicationClass))
42
43 typedef struct _GApplicationPrivate                         GApplicationPrivate;
44 typedef struct _GApplicationClass                           GApplicationClass;
45
46 /**
47  * GApplication:
48  *
49  * The <structname>GApplication</structname> structure contains private
50  * data and should only be accessed using the provided API
51  *
52  * Since: 2.28
53  */
54 struct _GApplication
55 {
56   /*< private >*/
57   GObject parent_instance;
58
59   GApplicationPrivate *priv;
60 };
61
62 /**
63  * GApplicationClass:
64  * @startup: invoked on the primary instance immediately after registration
65  * @shutdown: invoked only on the registered primary instance immediately
66  *      after the main loop terminates
67  * @activate: invoked on the primary instance when an activation occurs
68  * @open: invoked on the primary instance when there are files to open
69  * @command_line: invoked on the primary instance when a command-line is
70  *   not handled locally
71  * @local_command_line: invoked (locally) when the process has been invoked
72  *     via commandline execution (as opposed to, say, D-Bus activation - which
73  *     is not currently supported by GApplication). The virtual function has
74  *     the chance to inspect (and possibly replace) the list of command line
75  *     arguments. See g_application_run() for more information.
76  * @before_emit: invoked on the primary instance before 'activate', 'open',
77  *     'command-line' or any action invocation, gets the 'platform data' from
78  *     the calling instance
79  * @after_emit: invoked on the primary instance after 'activate', 'open',
80  *     'command-line' or any action invocation, gets the 'platform data' from
81  *     the calling instance
82  * @add_platform_data: invoked (locally) to add 'platform data' to be sent to
83  *     the primary instance when activating, opening or invoking actions
84  * @quit_mainloop: Used to be invoked on the primary instance when the use
85  *     count of the application drops to zero (and after any inactivity
86  *     timeout, if requested). Not used anymore since 2.32
87  * @run_mainloop: Used to be invoked on the primary instance from
88  *     g_application_run() if the use-count is non-zero. Since 2.32,
89  *     GApplication is iterating the main context directly and is not
90  *     using @run_mainloop anymore
91  *
92  * Since: 2.28
93  */
94 struct _GApplicationClass
95 {
96   /*< private >*/
97   GObjectClass parent_class;
98
99   /*< public >*/
100   /* signals */
101   void                      (* startup)             (GApplication              *application);
102
103   void                      (* activate)            (GApplication              *application);
104
105   void                      (* open)                (GApplication              *application,
106                                                      GFile                    **files,
107                                                      gint                       n_files,
108                                                      const gchar               *hint);
109
110   int                       (* command_line)        (GApplication              *application,
111                                                      GApplicationCommandLine   *command_line);
112
113   /* vfuncs */
114   gboolean                  (* local_command_line)  (GApplication              *application,
115                                                      gchar                   ***arguments,
116                                                      int                       *exit_status);
117
118   void                      (* before_emit)         (GApplication              *application,
119                                                      GVariant                  *platform_data);
120   void                      (* after_emit)          (GApplication              *application,
121                                                      GVariant                  *platform_data);
122   void                      (* add_platform_data)   (GApplication              *application,
123                                                      GVariantBuilder           *builder);
124   void                      (* quit_mainloop)       (GApplication              *application);
125   void                      (* run_mainloop)        (GApplication              *application);
126   void                      (* shutdown)            (GApplication              *application);
127
128   /*< private >*/
129   gpointer padding[11];
130 };
131
132 GType                   g_application_get_type                          (void) G_GNUC_CONST;
133
134 gboolean                g_application_id_is_valid                       (const gchar              *application_id);
135
136 GApplication *          g_application_new                               (const gchar              *application_id,
137                                                                          GApplicationFlags         flags);
138
139 const gchar *           g_application_get_application_id                (GApplication             *application);
140 void                    g_application_set_application_id                (GApplication             *application,
141                                                                          const gchar              *application_id);
142
143 guint                   g_application_get_inactivity_timeout            (GApplication             *application);
144 void                    g_application_set_inactivity_timeout            (GApplication             *application,
145                                                                          guint                     inactivity_timeout);
146
147 GApplicationFlags       g_application_get_flags                         (GApplication             *application);
148 void                    g_application_set_flags                         (GApplication             *application,
149                                                                          GApplicationFlags         flags);
150
151 void                    g_application_set_action_group                  (GApplication             *application,
152                                                                          GActionGroup             *action_group);
153
154 void                    g_application_set_app_menu                      (GApplication             *application,
155                                                                          GMenuModel               *app_menu);
156 GMenuModel             *g_application_get_app_menu                      (GApplication             *application);
157
158 void                    g_application_set_menubar                       (GApplication             *application,
159                                                                          GMenuModel               *menubar);
160 GMenuModel *            g_application_get_menubar                       (GApplication             *application);
161
162 gboolean                g_application_get_is_registered                 (GApplication             *application);
163 gboolean                g_application_get_is_remote                     (GApplication             *application);
164
165 gboolean                g_application_register                          (GApplication             *application,
166                                                                          GCancellable             *cancellable,
167                                                                          GError                  **error);
168
169 void                    g_application_hold                              (GApplication             *application);
170 void                    g_application_release                           (GApplication             *application);
171
172 void                    g_application_activate                          (GApplication             *application);
173
174 void                    g_application_open                              (GApplication             *application,
175                                                                          GFile                   **files,
176                                                                          gint                      n_files,
177                                                                          const gchar              *hint);
178
179 int                     g_application_run                               (GApplication             *application,
180                                                                          int                       argc,
181                                                                          char                    **argv);
182
183 GApplication *          g_application_get_default                       (void);
184 void                    g_application_set_default                       (GApplication             *application);
185
186 G_END_DECLS
187
188 #endif /* __G_APPLICATION_H__ */