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