gio/auto/application.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6 ffi, ActionGroup, ActionMap, ApplicationCommandLine, ApplicationFlags, Cancellable,
7 DBusConnection, File, Notification,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// `GApplication` is the core class for application support.
19 ///
20 /// A `GApplication` is the foundation of an application. It wraps some
21 /// low-level platform-specific services and is intended to act as the
22 /// foundation for higher-level application classes such as
23 /// `GtkApplication` or `MxApplication`. In general, you should not use
24 /// this class outside of a higher level framework.
25 ///
26 /// `GApplication` provides convenient life-cycle management by maintaining
27 /// a "use count" for the primary application instance. The use count can
28 /// be changed using [`ApplicationExtManual::hold()`][crate::prelude::ApplicationExtManual::hold()] and
29 /// [`ApplicationExtManual::release()`][crate::prelude::ApplicationExtManual::release()]. If it drops to zero, the application
30 /// exits. Higher-level classes such as `GtkApplication` employ the use count
31 /// to ensure that the application stays alive as long as it has any opened
32 /// windows.
33 ///
34 /// Another feature that `GApplication` (optionally) provides is process
35 /// uniqueness. Applications can make use of this functionality by
36 /// providing a unique application ID. If given, only one application
37 /// with this ID can be running at a time per session. The session
38 /// concept is platform-dependent, but corresponds roughly to a graphical
39 /// desktop login. When your application is launched again, its
40 /// arguments are passed through platform communication to the already
41 /// running program. The already running instance of the program is
42 /// called the "primary instance"; for non-unique applications this is
43 /// always the current instance. On Linux, the D-Bus session bus
44 /// is used for communication.
45 ///
46 /// The use of `GApplication` differs from some other commonly-used
47 /// uniqueness libraries (such as libunique) in important ways. The
48 /// application is not expected to manually register itself and check
49 /// if it is the primary instance. Instead, the main() function of a
50 /// `GApplication` should do very little more than instantiating the
51 /// application instance, possibly connecting signal handlers, then
52 /// calling [`ApplicationExtManual::run()`][crate::prelude::ApplicationExtManual::run()]. All checks for uniqueness are done
53 /// internally. If the application is the primary instance then the
54 /// startup signal is emitted and the mainloop runs. If the application
55 /// is not the primary instance then a signal is sent to the primary
56 /// instance and [`ApplicationExtManual::run()`][crate::prelude::ApplicationExtManual::run()] promptly returns. See the code
57 /// examples below.
58 ///
59 /// If used, the expected form of an application identifier is the
60 /// same as that of a
61 /// [D-Bus well-known bus name](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus).
62 /// Examples include: `com.example.MyApp`, `org.example.internal_apps.Calculator`,
63 /// `org._7_zip.Archiver`.
64 /// For details on valid application identifiers, see [`id_is_valid()`][Self::id_is_valid()].
65 ///
66 /// On Linux, the application identifier is claimed as a well-known bus name
67 /// on the user's session bus. This means that the uniqueness of your
68 /// application is scoped to the current session. It also means that your
69 /// application may provide additional services (through registration of other
70 /// object paths) at that bus name. The registration of these object paths
71 /// should be done with the shared GDBus session bus. Note that due to the
72 /// internal architecture of GDBus, method calls can be dispatched at any time
73 /// (even if a main loop is not running). For this reason, you must ensure that
74 /// any object paths that you wish to register are registered before #GApplication
75 /// attempts to acquire the bus name of your application (which happens in
76 /// [`ApplicationExt::register()`][crate::prelude::ApplicationExt::register()]). Unfortunately, this means that you cannot
77 /// use [`is-remote`][struct@crate::Application#is-remote] to decide if you want to register
78 /// object paths.
79 ///
80 /// `GApplication` also implements the [`ActionGroup`][crate::ActionGroup] and [`ActionMap`][crate::ActionMap]
81 /// interfaces and lets you easily export actions by adding them with
82 /// [`ActionMapExt::add_action()`][crate::prelude::ActionMapExt::add_action()]. When invoking an action by calling
83 /// [`ActionGroupExt::activate_action()`][crate::prelude::ActionGroupExt::activate_action()] on the application, it is always
84 /// invoked in the primary instance. The actions are also exported on
85 /// the session bus, and GIO provides the [`DBusActionGroup`][crate::DBusActionGroup] wrapper to
86 /// conveniently access them remotely. GIO provides a [`DBusMenuModel`][crate::DBusMenuModel] wrapper
87 /// for remote access to exported [`MenuModel`][crate::MenuModel]s.
88 ///
89 /// Note: Due to the fact that actions are exported on the session bus,
90 /// using `maybe` parameters is not supported, since D-Bus does not support
91 /// `maybe` types.
92 ///
93 /// There is a number of different entry points into a `GApplication`:
94 ///
95 /// - via 'Activate' (i.e. just starting the application)
96 ///
97 /// - via 'Open' (i.e. opening some files)
98 ///
99 /// - by handling a command-line
100 ///
101 /// - via activating an action
102 ///
103 /// The [`startup`][struct@crate::Application#startup] signal lets you handle the application
104 /// initialization for all of these in a single place.
105 ///
106 /// Regardless of which of these entry points is used to start the
107 /// application, `GApplication` passes some ‘platform data’ from the
108 /// launching instance to the primary instance, in the form of a
109 /// [`glib::Variant`][struct@crate::glib::Variant] dictionary mapping strings to variants. To use platform
110 /// data, override the [`ApplicationImpl::before_emit()`][crate::subclass::prelude::ApplicationImpl::before_emit()] or
111 /// [`ApplicationImpl::after_emit()`][crate::subclass::prelude::ApplicationImpl::after_emit()] virtual functions
112 /// in your `GApplication` subclass. When dealing with
113 /// [`ApplicationCommandLine`][crate::ApplicationCommandLine] objects, the platform data is
114 /// directly available via [`ApplicationCommandLineExt::cwd()`][crate::prelude::ApplicationCommandLineExt::cwd()],
115 /// [`ApplicationCommandLineExt::environ()`][crate::prelude::ApplicationCommandLineExt::environ()] and
116 /// [`ApplicationCommandLineExt::platform_data()`][crate::prelude::ApplicationCommandLineExt::platform_data()].
117 ///
118 /// As the name indicates, the platform data may vary depending on the
119 /// operating system, but it always includes the current directory (key
120 /// `cwd`), and optionally the environment (ie the set of environment
121 /// variables and their values) of the calling process (key `environ`).
122 /// The environment is only added to the platform data if the
123 /// `G_APPLICATION_SEND_ENVIRONMENT` flag is set. `GApplication` subclasses
124 /// can add their own platform data by overriding the
125 /// `vfunc::Gio::Application::add_platform_data` virtual function. For instance,
126 /// `GtkApplication` adds startup notification data in this way.
127 ///
128 /// To parse commandline arguments you may handle the
129 /// [`command-line`][struct@crate::Application#command-line] signal or override the
130 /// `vfunc::Gio::Application::local_command_line` virtual function, to parse them in
131 /// either the primary instance or the local instance, respectively.
132 ///
133 /// For an example of opening files with a `GApplication`, see
134 /// [gapplication-example-open.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-open.c).
135 ///
136 /// For an example of using actions with `GApplication`, see
137 /// [gapplication-example-actions.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-actions.c).
138 ///
139 /// For an example of using extra D-Bus hooks with `GApplication`, see
140 /// [gapplication-example-dbushooks.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-dbushooks.c).
141 ///
142 /// ## Properties
143 ///
144 ///
145 /// #### `action-group`
146 /// The group of actions that the application exports.
147 ///
148 /// Writeable
149 ///
150 ///
151 /// #### `application-id`
152 /// The unique identifier for the application.
153 ///
154 /// Readable | Writeable | Construct
155 ///
156 ///
157 /// #### `flags`
158 /// Flags specifying the behaviour of the application.
159 ///
160 /// Readable | Writeable
161 ///
162 ///
163 /// #### `inactivity-timeout`
164 /// Time (in milliseconds) to stay alive after becoming idle.
165 ///
166 /// Readable | Writeable
167 ///
168 ///
169 /// #### `is-busy`
170 /// Whether the application is currently marked as busy through
171 /// g_application_mark_busy() or g_application_bind_busy_property().
172 ///
173 /// Readable
174 ///
175 ///
176 /// #### `is-registered`
177 /// Whether [`ApplicationExt::register()`][crate::prelude::ApplicationExt::register()] has been called.
178 ///
179 /// Readable
180 ///
181 ///
182 /// #### `is-remote`
183 /// Whether this application instance is remote.
184 ///
185 /// Readable
186 ///
187 ///
188 /// #### `resource-base-path`
189 /// The base resource path for the application.
190 ///
191 /// Readable | Writeable
192 ///
193 ///
194 /// #### `version`
195 /// The human-readable version number of the application.
196 ///
197 /// Readable | Writeable
198 ///
199 /// ## Signals
200 ///
201 ///
202 /// #### `activate`
203 /// The ::activate signal is emitted on the primary instance when an
204 /// activation occurs. See g_application_activate().
205 ///
206 ///
207 ///
208 ///
209 /// #### `command-line`
210 /// The ::command-line signal is emitted on the primary instance when
211 /// a commandline is not handled locally. See g_application_run() and
212 /// the #GApplicationCommandLine documentation for more information.
213 ///
214 ///
215 ///
216 ///
217 /// #### `handle-local-options`
218 /// The ::handle-local-options signal is emitted on the local instance
219 /// after the parsing of the commandline options has occurred.
220 ///
221 /// You can add options to be recognised during commandline option
222 /// parsing using g_application_add_main_option_entries() and
223 /// g_application_add_option_group().
224 ///
225 /// Signal handlers can inspect @options (along with values pointed to
226 /// from the @arg_data of an installed #GOptionEntrys) in order to
227 /// decide to perform certain actions, including direct local handling
228 /// (which may be useful for options like --version).
229 ///
230 /// In the event that the application is marked
231 /// [`ApplicationFlags::HANDLES_COMMAND_LINE`][crate::ApplicationFlags::HANDLES_COMMAND_LINE] the "normal processing" will
232 /// send the @options dictionary to the primary instance where it can be
233 /// read with g_application_command_line_get_options_dict(). The signal
234 /// handler can modify the dictionary before returning, and the
235 /// modified dictionary will be sent.
236 ///
237 /// In the event that [`ApplicationFlags::HANDLES_COMMAND_LINE`][crate::ApplicationFlags::HANDLES_COMMAND_LINE] is not set,
238 /// "normal processing" will treat the remaining uncollected command
239 /// line arguments as filenames or URIs. If there are no arguments,
240 /// the application is activated by g_application_activate(). One or
241 /// more arguments results in a call to g_application_open().
242 ///
243 /// If you want to handle the local commandline arguments for yourself
244 /// by converting them to calls to g_application_open() or
245 /// g_action_group_activate_action() then you must be sure to register
246 /// the application first. You should probably not call
247 /// g_application_activate() for yourself, however: just return -1 and
248 /// allow the default handler to do it for you. This will ensure that
249 /// the `--gapplication-service` switch works properly (i.e. no activation
250 /// in that case).
251 ///
252 /// Note that this signal is emitted from the default implementation of
253 /// local_command_line(). If you override that function and don't
254 /// chain up then this signal will never be emitted.
255 ///
256 /// You can override local_command_line() if you need more powerful
257 /// capabilities than what is provided here, but this should not
258 /// normally be required.
259 ///
260 ///
261 ///
262 ///
263 /// #### `name-lost`
264 /// The ::name-lost signal is emitted only on the registered primary instance
265 /// when a new instance has taken over. This can only happen if the application
266 /// is using the [`ApplicationFlags::ALLOW_REPLACEMENT`][crate::ApplicationFlags::ALLOW_REPLACEMENT] flag.
267 ///
268 /// The default handler for this signal calls g_application_quit().
269 ///
270 ///
271 ///
272 ///
273 /// #### `open`
274 /// The ::open signal is emitted on the primary instance when there are
275 /// files to open. See g_application_open() for more information.
276 ///
277 ///
278 ///
279 ///
280 /// #### `shutdown`
281 /// The ::shutdown signal is emitted only on the registered primary instance
282 /// immediately after the main loop terminates.
283 ///
284 ///
285 ///
286 ///
287 /// #### `startup`
288 /// The ::startup signal is emitted on the primary instance immediately
289 /// after registration. See g_application_register().
290 ///
291 ///
292 /// <details><summary><h4>ActionGroup</h4></summary>
293 ///
294 ///
295 /// #### `action-added`
296 /// Signals that a new action was just added to the group.
297 ///
298 /// This signal is emitted after the action has been added
299 /// and is now visible.
300 ///
301 /// Detailed
302 ///
303 ///
304 /// #### `action-enabled-changed`
305 /// Signals that the enabled status of the named action has changed.
306 ///
307 /// Detailed
308 ///
309 ///
310 /// #### `action-removed`
311 /// Signals that an action is just about to be removed from the group.
312 ///
313 /// This signal is emitted before the action is removed, so the action
314 /// is still visible and can be queried from the signal handler.
315 ///
316 /// Detailed
317 ///
318 ///
319 /// #### `action-state-changed`
320 /// Signals that the state of the named action has changed.
321 ///
322 /// Detailed
323 /// </details>
324 ///
325 /// # Implements
326 ///
327 /// [`ApplicationExt`][trait@crate::prelude::ApplicationExt], [`trait@glib::ObjectExt`], [`ActionGroupExt`][trait@crate::prelude::ActionGroupExt], [`ActionMapExt`][trait@crate::prelude::ActionMapExt], [`ApplicationExtManual`][trait@crate::prelude::ApplicationExtManual], [`ActionMapExtManual`][trait@crate::prelude::ActionMapExtManual]
328 #[doc(alias = "GApplication")]
329 pub struct Application(Object<ffi::GApplication, ffi::GApplicationClass>) @implements ActionGroup, ActionMap;
330
331 match fn {
332 type_ => || ffi::g_application_get_type(),
333 }
334}
335
336impl Application {
337 pub const NONE: Option<&'static Application> = None;
338
339 /// Creates a new #GApplication instance.
340 ///
341 /// If non-[`None`], the application id must be valid. See
342 /// g_application_id_is_valid().
343 ///
344 /// If no application ID is given then some features of #GApplication
345 /// (most notably application uniqueness) will be disabled.
346 /// ## `application_id`
347 /// the application id
348 /// ## `flags`
349 /// the application flags
350 ///
351 /// # Returns
352 ///
353 /// a new #GApplication instance
354 #[doc(alias = "g_application_new")]
355 pub fn new(application_id: Option<&str>, flags: ApplicationFlags) -> Application {
356 unsafe {
357 from_glib_full(ffi::g_application_new(
358 application_id.to_glib_none().0,
359 flags.into_glib(),
360 ))
361 }
362 }
363
364 // rustdoc-stripper-ignore-next
365 /// Creates a new builder-pattern struct instance to construct [`Application`] objects.
366 ///
367 /// This method returns an instance of [`ApplicationBuilder`](crate::builders::ApplicationBuilder) which can be used to create [`Application`] objects.
368 pub fn builder() -> ApplicationBuilder {
369 ApplicationBuilder::new()
370 }
371
372 /// Returns the default #GApplication instance for this process.
373 ///
374 /// Normally there is only one #GApplication per process and it becomes
375 /// the default when it is created. You can exercise more control over
376 /// this by using g_application_set_default().
377 ///
378 /// If there is no default application then [`None`] is returned.
379 ///
380 /// # Returns
381 ///
382 /// the default application for this process, or [`None`]
383 #[doc(alias = "g_application_get_default")]
384 #[doc(alias = "get_default")]
385 #[allow(clippy::should_implement_trait)]
386 pub fn default() -> Option<Application> {
387 unsafe { from_glib_none(ffi::g_application_get_default()) }
388 }
389
390 /// Checks if @application_id is a valid application identifier.
391 ///
392 /// A valid ID is required for calls to g_application_new() and
393 /// g_application_set_application_id().
394 ///
395 /// Application identifiers follow the same format as
396 /// [D-Bus well-known bus names](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus).
397 /// For convenience, the restrictions on application identifiers are
398 /// reproduced here:
399 ///
400 /// - Application identifiers are composed of 1 or more elements separated by a
401 /// period (`.`) character. All elements must contain at least one character.
402 ///
403 /// - Each element must only contain the ASCII characters `[A-Z][a-z][0-9]_-`,
404 /// with `-` discouraged in new application identifiers. Each element must not
405 /// begin with a digit.
406 ///
407 /// - Application identifiers must contain at least one `.` (period) character
408 /// (and thus at least two elements).
409 ///
410 /// - Application identifiers must not begin with a `.` (period) character.
411 ///
412 /// - Application identifiers must not exceed 255 characters.
413 ///
414 /// Note that the hyphen (`-`) character is allowed in application identifiers,
415 /// but is problematic or not allowed in various specifications and APIs that
416 /// refer to D-Bus, such as
417 /// [Flatpak application IDs](http://docs.flatpak.org/en/latest/introduction.html#identifiers),
418 /// the
419 /// [`DBusActivatable` interface in the Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus),
420 /// and the convention that an application's "main" interface and object path
421 /// resemble its application identifier and bus name. To avoid situations that
422 /// require special-case handling, it is recommended that new application
423 /// identifiers consistently replace hyphens with underscores.
424 ///
425 /// Like D-Bus interface names, application identifiers should start with the
426 /// reversed DNS domain name of the author of the interface (in lower-case), and
427 /// it is conventional for the rest of the application identifier to consist of
428 /// words run together, with initial capital letters.
429 ///
430 /// As with D-Bus interface names, if the author's DNS domain name contains
431 /// hyphen/minus characters they should be replaced by underscores, and if it
432 /// contains leading digits they should be escaped by prepending an underscore.
433 /// For example, if the owner of 7-zip.org used an application identifier for an
434 /// archiving application, it might be named `org._7_zip.Archiver`.
435 /// ## `application_id`
436 /// a potential application identifier
437 ///
438 /// # Returns
439 ///
440 /// [`true`] if @application_id is valid
441 #[doc(alias = "g_application_id_is_valid")]
442 pub fn id_is_valid(application_id: &str) -> bool {
443 unsafe {
444 from_glib(ffi::g_application_id_is_valid(
445 application_id.to_glib_none().0,
446 ))
447 }
448 }
449}
450
451impl Default for Application {
452 fn default() -> Self {
453 glib::object::Object::new::<Self>()
454 }
455}
456
457// rustdoc-stripper-ignore-next
458/// A [builder-pattern] type to construct [`Application`] objects.
459///
460/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
461#[must_use = "The builder must be built to be used"]
462pub struct ApplicationBuilder {
463 builder: glib::object::ObjectBuilder<'static, Application>,
464}
465
466impl ApplicationBuilder {
467 fn new() -> Self {
468 Self {
469 builder: glib::object::Object::builder(),
470 }
471 }
472
473 /// The unique identifier for the application.
474 pub fn application_id(self, application_id: impl Into<glib::GString>) -> Self {
475 Self {
476 builder: self
477 .builder
478 .property("application-id", application_id.into()),
479 }
480 }
481
482 /// Flags specifying the behaviour of the application.
483 pub fn flags(self, flags: ApplicationFlags) -> Self {
484 Self {
485 builder: self.builder.property("flags", flags),
486 }
487 }
488
489 /// Time (in milliseconds) to stay alive after becoming idle.
490 pub fn inactivity_timeout(self, inactivity_timeout: u32) -> Self {
491 Self {
492 builder: self
493 .builder
494 .property("inactivity-timeout", inactivity_timeout),
495 }
496 }
497
498 /// The base resource path for the application.
499 pub fn resource_base_path(self, resource_base_path: impl Into<glib::GString>) -> Self {
500 Self {
501 builder: self
502 .builder
503 .property("resource-base-path", resource_base_path.into()),
504 }
505 }
506
507 /// The human-readable version number of the application.
508 #[cfg(feature = "v2_80")]
509 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
510 pub fn version(self, version: impl Into<glib::GString>) -> Self {
511 Self {
512 builder: self.builder.property("version", version.into()),
513 }
514 }
515
516 // rustdoc-stripper-ignore-next
517 /// Build the [`Application`].
518 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
519 pub fn build(self) -> Application {
520 self.builder.build()
521 }
522}
523
524mod sealed {
525 pub trait Sealed {}
526 impl<T: super::IsA<super::Application>> Sealed for T {}
527}
528
529/// Trait containing all [`struct@Application`] methods.
530///
531/// # Implementors
532///
533/// [`Application`][struct@crate::Application]
534pub trait ApplicationExt: IsA<Application> + sealed::Sealed + 'static {
535 /// Activates the application.
536 ///
537 /// In essence, this results in the #GApplication::activate signal being
538 /// emitted in the primary instance.
539 ///
540 /// The application must be registered before calling this function.
541 #[doc(alias = "g_application_activate")]
542 fn activate(&self) {
543 unsafe {
544 ffi::g_application_activate(self.as_ref().to_glib_none().0);
545 }
546 }
547
548 /// Add an option to be handled by @self.
549 ///
550 /// Calling this function is the equivalent of calling
551 /// g_application_add_main_option_entries() with a single #GOptionEntry
552 /// that has its arg_data member set to [`None`].
553 ///
554 /// The parsed arguments will be packed into a #GVariantDict which
555 /// is passed to #GApplication::handle-local-options. If
556 /// [`ApplicationFlags::HANDLES_COMMAND_LINE`][crate::ApplicationFlags::HANDLES_COMMAND_LINE] is set, then it will also
557 /// be sent to the primary instance. See
558 /// g_application_add_main_option_entries() for more details.
559 ///
560 /// See #GOptionEntry for more documentation of the arguments.
561 /// ## `long_name`
562 /// the long name of an option used to specify it in a commandline
563 /// ## `short_name`
564 /// the short name of an option
565 /// ## `flags`
566 /// flags from #GOptionFlags
567 /// ## `arg`
568 /// the type of the option, as a #GOptionArg
569 /// ## `description`
570 /// the description for the option in `--help` output
571 /// ## `arg_description`
572 /// the placeholder to use for the extra argument
573 /// parsed by the option in `--help` output
574 #[doc(alias = "g_application_add_main_option")]
575 fn add_main_option(
576 &self,
577 long_name: &str,
578 short_name: glib::Char,
579 flags: glib::OptionFlags,
580 arg: glib::OptionArg,
581 description: &str,
582 arg_description: Option<&str>,
583 ) {
584 unsafe {
585 ffi::g_application_add_main_option(
586 self.as_ref().to_glib_none().0,
587 long_name.to_glib_none().0,
588 short_name.into_glib(),
589 flags.into_glib(),
590 arg.into_glib(),
591 description.to_glib_none().0,
592 arg_description.to_glib_none().0,
593 );
594 }
595 }
596
597 //#[doc(alias = "g_application_add_main_option_entries")]
598 //fn add_main_option_entries(&self, entries: /*Ignored*/&[glib::OptionEntry]) {
599 // unsafe { TODO: call ffi:g_application_add_main_option_entries() }
600 //}
601
602 //#[doc(alias = "g_application_add_option_group")]
603 //fn add_option_group(&self, group: /*Ignored*/glib::OptionGroup) {
604 // unsafe { TODO: call ffi:g_application_add_option_group() }
605 //}
606
607 /// Marks @self as busy (see g_application_mark_busy()) while
608 /// @property on @object is [`true`].
609 ///
610 /// The binding holds a reference to @self while it is active, but
611 /// not to @object. Instead, the binding is destroyed when @object is
612 /// finalized.
613 /// ## `object`
614 /// a #GObject
615 /// ## `property`
616 /// the name of a boolean property of @object
617 #[doc(alias = "g_application_bind_busy_property")]
618 fn bind_busy_property(&self, object: &impl IsA<glib::Object>, property: &str) {
619 unsafe {
620 ffi::g_application_bind_busy_property(
621 self.as_ref().to_glib_none().0,
622 object.as_ref().to_glib_none().0,
623 property.to_glib_none().0,
624 );
625 }
626 }
627
628 /// Gets the unique identifier for @self.
629 ///
630 /// # Returns
631 ///
632 /// the identifier for @self, owned by @self
633 #[doc(alias = "g_application_get_application_id")]
634 #[doc(alias = "get_application_id")]
635 #[doc(alias = "application-id")]
636 fn application_id(&self) -> Option<glib::GString> {
637 unsafe {
638 from_glib_none(ffi::g_application_get_application_id(
639 self.as_ref().to_glib_none().0,
640 ))
641 }
642 }
643
644 /// Gets the #GDBusConnection being used by the application, or [`None`].
645 ///
646 /// If #GApplication is using its D-Bus backend then this function will
647 /// return the #GDBusConnection being used for uniqueness and
648 /// communication with the desktop environment and other instances of the
649 /// application.
650 ///
651 /// If #GApplication is not using D-Bus then this function will return
652 /// [`None`]. This includes the situation where the D-Bus backend would
653 /// normally be in use but we were unable to connect to the bus.
654 ///
655 /// This function must not be called before the application has been
656 /// registered. See g_application_get_is_registered().
657 ///
658 /// # Returns
659 ///
660 /// a #GDBusConnection, or [`None`]
661 #[doc(alias = "g_application_get_dbus_connection")]
662 #[doc(alias = "get_dbus_connection")]
663 fn dbus_connection(&self) -> Option<DBusConnection> {
664 unsafe {
665 from_glib_none(ffi::g_application_get_dbus_connection(
666 self.as_ref().to_glib_none().0,
667 ))
668 }
669 }
670
671 /// Gets the D-Bus object path being used by the application, or [`None`].
672 ///
673 /// If #GApplication is using its D-Bus backend then this function will
674 /// return the D-Bus object path that #GApplication is using. If the
675 /// application is the primary instance then there is an object published
676 /// at this path. If the application is not the primary instance then
677 /// the result of this function is undefined.
678 ///
679 /// If #GApplication is not using D-Bus then this function will return
680 /// [`None`]. This includes the situation where the D-Bus backend would
681 /// normally be in use but we were unable to connect to the bus.
682 ///
683 /// This function must not be called before the application has been
684 /// registered. See g_application_get_is_registered().
685 ///
686 /// # Returns
687 ///
688 /// the object path, or [`None`]
689 #[doc(alias = "g_application_get_dbus_object_path")]
690 #[doc(alias = "get_dbus_object_path")]
691 fn dbus_object_path(&self) -> Option<glib::GString> {
692 unsafe {
693 from_glib_none(ffi::g_application_get_dbus_object_path(
694 self.as_ref().to_glib_none().0,
695 ))
696 }
697 }
698
699 /// Gets the flags for @self.
700 ///
701 /// See #GApplicationFlags.
702 ///
703 /// # Returns
704 ///
705 /// the flags for @self
706 #[doc(alias = "g_application_get_flags")]
707 #[doc(alias = "get_flags")]
708 fn flags(&self) -> ApplicationFlags {
709 unsafe { from_glib(ffi::g_application_get_flags(self.as_ref().to_glib_none().0)) }
710 }
711
712 /// Gets the current inactivity timeout for the application.
713 ///
714 /// This is the amount of time (in milliseconds) after the last call to
715 /// g_application_release() before the application stops running.
716 ///
717 /// # Returns
718 ///
719 /// the timeout, in milliseconds
720 #[doc(alias = "g_application_get_inactivity_timeout")]
721 #[doc(alias = "get_inactivity_timeout")]
722 #[doc(alias = "inactivity-timeout")]
723 fn inactivity_timeout(&self) -> u32 {
724 unsafe { ffi::g_application_get_inactivity_timeout(self.as_ref().to_glib_none().0) }
725 }
726
727 /// Gets the application's current busy state, as set through
728 /// g_application_mark_busy() or g_application_bind_busy_property().
729 ///
730 /// # Returns
731 ///
732 /// [`true`] if @self is currently marked as busy
733 #[doc(alias = "g_application_get_is_busy")]
734 #[doc(alias = "get_is_busy")]
735 #[doc(alias = "is-busy")]
736 fn is_busy(&self) -> bool {
737 unsafe {
738 from_glib(ffi::g_application_get_is_busy(
739 self.as_ref().to_glib_none().0,
740 ))
741 }
742 }
743
744 /// Checks if @self is registered.
745 ///
746 /// An application is registered if g_application_register() has been
747 /// successfully called.
748 ///
749 /// # Returns
750 ///
751 /// [`true`] if @self is registered
752 #[doc(alias = "g_application_get_is_registered")]
753 #[doc(alias = "get_is_registered")]
754 #[doc(alias = "is-registered")]
755 fn is_registered(&self) -> bool {
756 unsafe {
757 from_glib(ffi::g_application_get_is_registered(
758 self.as_ref().to_glib_none().0,
759 ))
760 }
761 }
762
763 /// Checks if @self is remote.
764 ///
765 /// If @self is remote then it means that another instance of
766 /// application already exists (the 'primary' instance). Calls to
767 /// perform actions on @self will result in the actions being
768 /// performed by the primary instance.
769 ///
770 /// The value of this property cannot be accessed before
771 /// g_application_register() has been called. See
772 /// g_application_get_is_registered().
773 ///
774 /// # Returns
775 ///
776 /// [`true`] if @self is remote
777 #[doc(alias = "g_application_get_is_remote")]
778 #[doc(alias = "get_is_remote")]
779 #[doc(alias = "is-remote")]
780 fn is_remote(&self) -> bool {
781 unsafe {
782 from_glib(ffi::g_application_get_is_remote(
783 self.as_ref().to_glib_none().0,
784 ))
785 }
786 }
787
788 /// Gets the resource base path of @self.
789 ///
790 /// See g_application_set_resource_base_path() for more information.
791 ///
792 /// # Returns
793 ///
794 /// the base resource path, if one is set
795 #[doc(alias = "g_application_get_resource_base_path")]
796 #[doc(alias = "get_resource_base_path")]
797 #[doc(alias = "resource-base-path")]
798 fn resource_base_path(&self) -> Option<glib::GString> {
799 unsafe {
800 from_glib_none(ffi::g_application_get_resource_base_path(
801 self.as_ref().to_glib_none().0,
802 ))
803 }
804 }
805
806 /// Gets the version of @self.
807 ///
808 /// # Returns
809 ///
810 /// the version of @self
811 #[cfg(feature = "v2_80")]
812 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
813 #[doc(alias = "g_application_get_version")]
814 #[doc(alias = "get_version")]
815 fn version(&self) -> Option<glib::GString> {
816 unsafe {
817 from_glib_none(ffi::g_application_get_version(
818 self.as_ref().to_glib_none().0,
819 ))
820 }
821 }
822
823 /// Opens the given files.
824 ///
825 /// In essence, this results in the #GApplication::open signal being emitted
826 /// in the primary instance.
827 ///
828 /// @n_files must be greater than zero.
829 ///
830 /// @hint is simply passed through to the ::open signal. It is
831 /// intended to be used by applications that have multiple modes for
832 /// opening files (eg: "view" vs "edit", etc). Unless you have a need
833 /// for this functionality, you should use "".
834 ///
835 /// The application must be registered before calling this function
836 /// and it must have the [`ApplicationFlags::HANDLES_OPEN`][crate::ApplicationFlags::HANDLES_OPEN] flag set.
837 /// ## `files`
838 /// an array of #GFiles to open
839 /// ## `hint`
840 /// a hint (or ""), but never [`None`]
841 #[doc(alias = "g_application_open")]
842 fn open(&self, files: &[File], hint: &str) {
843 let n_files = files.len() as _;
844 unsafe {
845 ffi::g_application_open(
846 self.as_ref().to_glib_none().0,
847 files.to_glib_none().0,
848 n_files,
849 hint.to_glib_none().0,
850 );
851 }
852 }
853
854 /// Immediately quits the application.
855 ///
856 /// Upon return to the mainloop, g_application_run() will return,
857 /// calling only the 'shutdown' function before doing so.
858 ///
859 /// The hold count is ignored.
860 /// Take care if your code has called g_application_hold() on the application and
861 /// is therefore still expecting it to exist.
862 /// (Note that you may have called g_application_hold() indirectly, for example
863 /// through gtk_application_add_window().)
864 ///
865 /// The result of calling g_application_run() again after it returns is
866 /// unspecified.
867 #[doc(alias = "g_application_quit")]
868 fn quit(&self) {
869 unsafe {
870 ffi::g_application_quit(self.as_ref().to_glib_none().0);
871 }
872 }
873
874 /// Attempts registration of the application.
875 ///
876 /// This is the point at which the application discovers if it is the
877 /// primary instance or merely acting as a remote for an already-existing
878 /// primary instance. This is implemented by attempting to acquire the
879 /// application identifier as a unique bus name on the session bus using
880 /// GDBus.
881 ///
882 /// If there is no application ID or if [`ApplicationFlags::NON_UNIQUE`][crate::ApplicationFlags::NON_UNIQUE] was
883 /// given, then this process will always become the primary instance.
884 ///
885 /// Due to the internal architecture of GDBus, method calls can be
886 /// dispatched at any time (even if a main loop is not running). For
887 /// this reason, you must ensure that any object paths that you wish to
888 /// register are registered before calling this function.
889 ///
890 /// If the application has already been registered then [`true`] is
891 /// returned with no work performed.
892 ///
893 /// The #GApplication::startup signal is emitted if registration succeeds
894 /// and @self is the primary instance (including the non-unique
895 /// case).
896 ///
897 /// In the event of an error (such as @cancellable being cancelled, or a
898 /// failure to connect to the session bus), [`false`] is returned and @error
899 /// is set appropriately.
900 ///
901 /// Note: the return value of this function is not an indicator that this
902 /// instance is or is not the primary instance of the application. See
903 /// g_application_get_is_remote() for that.
904 /// ## `cancellable`
905 /// a #GCancellable, or [`None`]
906 ///
907 /// # Returns
908 ///
909 /// [`true`] if registration succeeded
910 #[doc(alias = "g_application_register")]
911 fn register(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<(), glib::Error> {
912 unsafe {
913 let mut error = std::ptr::null_mut();
914 let is_ok = ffi::g_application_register(
915 self.as_ref().to_glib_none().0,
916 cancellable.map(|p| p.as_ref()).to_glib_none().0,
917 &mut error,
918 );
919 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
920 if error.is_null() {
921 Ok(())
922 } else {
923 Err(from_glib_full(error))
924 }
925 }
926 }
927
928 /// Sends a notification on behalf of @self to the desktop shell.
929 /// There is no guarantee that the notification is displayed immediately,
930 /// or even at all.
931 ///
932 /// Notifications may persist after the application exits. It will be
933 /// D-Bus-activated when the notification or one of its actions is
934 /// activated.
935 ///
936 /// Modifying @notification after this call has no effect. However, the
937 /// object can be reused for a later call to this function.
938 ///
939 /// @id may be any string that uniquely identifies the event for the
940 /// application. It does not need to be in any special format. For
941 /// example, "new-message" might be appropriate for a notification about
942 /// new messages.
943 ///
944 /// If a previous notification was sent with the same @id, it will be
945 /// replaced with @notification and shown again as if it was a new
946 /// notification. This works even for notifications sent from a previous
947 /// execution of the application, as long as @id is the same string.
948 ///
949 /// @id may be `NULL`, but it is impossible to replace or withdraw
950 /// notifications without an id.
951 ///
952 /// If @notification is no longer relevant, it can be withdrawn with
953 /// [`withdraw_notification()`][Self::withdraw_notification()].
954 ///
955 /// It is an error to call this function if @self has no
956 /// application ID.
957 /// ## `id`
958 /// id of the notification, or [`None`]
959 /// ## `notification`
960 /// the #GNotification to send
961 #[doc(alias = "g_application_send_notification")]
962 fn send_notification(&self, id: Option<&str>, notification: &Notification) {
963 unsafe {
964 ffi::g_application_send_notification(
965 self.as_ref().to_glib_none().0,
966 id.to_glib_none().0,
967 notification.to_glib_none().0,
968 );
969 }
970 }
971
972 /// Sets the unique identifier for @self.
973 ///
974 /// The application id can only be modified if @self has not yet
975 /// been registered.
976 ///
977 /// If non-[`None`], the application id must be valid. See
978 /// g_application_id_is_valid().
979 /// ## `application_id`
980 /// the identifier for @self
981 #[doc(alias = "g_application_set_application_id")]
982 #[doc(alias = "application-id")]
983 fn set_application_id(&self, application_id: Option<&str>) {
984 unsafe {
985 ffi::g_application_set_application_id(
986 self.as_ref().to_glib_none().0,
987 application_id.to_glib_none().0,
988 );
989 }
990 }
991
992 /// Sets or unsets the default application for the process, as returned
993 /// by g_application_get_default().
994 ///
995 /// This function does not take its own reference on @self. If
996 /// @self is destroyed then the default application will revert
997 /// back to [`None`].
998 #[doc(alias = "g_application_set_default")]
999 fn set_default(&self) {
1000 unsafe {
1001 ffi::g_application_set_default(self.as_ref().to_glib_none().0);
1002 }
1003 }
1004
1005 /// Sets the flags for @self.
1006 ///
1007 /// The flags can only be modified if @self has not yet been
1008 /// registered.
1009 ///
1010 /// See #GApplicationFlags.
1011 /// ## `flags`
1012 /// the flags for @self
1013 #[doc(alias = "g_application_set_flags")]
1014 #[doc(alias = "flags")]
1015 fn set_flags(&self, flags: ApplicationFlags) {
1016 unsafe {
1017 ffi::g_application_set_flags(self.as_ref().to_glib_none().0, flags.into_glib());
1018 }
1019 }
1020
1021 /// Sets the current inactivity timeout for the application.
1022 ///
1023 /// This is the amount of time (in milliseconds) after the last call to
1024 /// g_application_release() before the application stops running.
1025 ///
1026 /// This call has no side effects of its own. The value set here is only
1027 /// used for next time g_application_release() drops the use count to
1028 /// zero. Any timeouts currently in progress are not impacted.
1029 /// ## `inactivity_timeout`
1030 /// the timeout, in milliseconds
1031 #[doc(alias = "g_application_set_inactivity_timeout")]
1032 #[doc(alias = "inactivity-timeout")]
1033 fn set_inactivity_timeout(&self, inactivity_timeout: u32) {
1034 unsafe {
1035 ffi::g_application_set_inactivity_timeout(
1036 self.as_ref().to_glib_none().0,
1037 inactivity_timeout,
1038 );
1039 }
1040 }
1041
1042 /// Adds a description to the @self option context.
1043 ///
1044 /// See g_option_context_set_description() for more information.
1045 /// ## `description`
1046 /// a string to be shown in `--help` output
1047 /// after the list of options, or [`None`]
1048 #[doc(alias = "g_application_set_option_context_description")]
1049 fn set_option_context_description(&self, description: Option<&str>) {
1050 unsafe {
1051 ffi::g_application_set_option_context_description(
1052 self.as_ref().to_glib_none().0,
1053 description.to_glib_none().0,
1054 );
1055 }
1056 }
1057
1058 /// Sets the parameter string to be used by the commandline handling of @self.
1059 ///
1060 /// This function registers the argument to be passed to g_option_context_new()
1061 /// when the internal #GOptionContext of @self is created.
1062 ///
1063 /// See g_option_context_new() for more information about @parameter_string.
1064 /// ## `parameter_string`
1065 /// a string which is displayed
1066 /// in the first line of `--help` output, after the usage summary `programname [OPTION...]`.
1067 #[doc(alias = "g_application_set_option_context_parameter_string")]
1068 fn set_option_context_parameter_string(&self, parameter_string: Option<&str>) {
1069 unsafe {
1070 ffi::g_application_set_option_context_parameter_string(
1071 self.as_ref().to_glib_none().0,
1072 parameter_string.to_glib_none().0,
1073 );
1074 }
1075 }
1076
1077 /// Adds a summary to the @self option context.
1078 ///
1079 /// See g_option_context_set_summary() for more information.
1080 /// ## `summary`
1081 /// a string to be shown in `--help` output
1082 /// before the list of options, or [`None`]
1083 #[doc(alias = "g_application_set_option_context_summary")]
1084 fn set_option_context_summary(&self, summary: Option<&str>) {
1085 unsafe {
1086 ffi::g_application_set_option_context_summary(
1087 self.as_ref().to_glib_none().0,
1088 summary.to_glib_none().0,
1089 );
1090 }
1091 }
1092
1093 /// Sets (or unsets) the base resource path of @self.
1094 ///
1095 /// The path is used to automatically load various
1096 /// [application resources][`Resource`][crate::Resource] such as menu layouts and
1097 /// action descriptions. The various types of resources will be found at
1098 /// fixed names relative to the given base path.
1099 ///
1100 /// By default, the resource base path is determined from the application
1101 /// ID by prefixing '/' and replacing each '.' with '/'. This is done at
1102 /// the time that the #GApplication object is constructed. Changes to
1103 /// the application ID after that point will not have an impact on the
1104 /// resource base path.
1105 ///
1106 /// As an example, if the application has an ID of "org.example.app" then
1107 /// the default resource base path will be "/org/example/app". If this
1108 /// is a #GtkApplication (and you have not manually changed the path)
1109 /// then Gtk will then search for the menus of the application at
1110 /// "/org/example/app/gtk/menus.ui".
1111 ///
1112 /// See #GResource for more information about adding resources to your
1113 /// application.
1114 ///
1115 /// You can disable automatic resource loading functionality by setting
1116 /// the path to [`None`].
1117 ///
1118 /// Changing the resource base path once the application is running is
1119 /// not recommended. The point at which the resource path is consulted
1120 /// for forming paths for various purposes is unspecified. When writing
1121 /// a sub-class of #GApplication you should either set the
1122 /// #GApplication:resource-base-path property at construction time, or call
1123 /// this function during the instance initialization. Alternatively, you
1124 /// can call this function in the #GApplicationClass.startup virtual function,
1125 /// before chaining up to the parent implementation.
1126 /// ## `resource_path`
1127 /// the resource path to use
1128 #[doc(alias = "g_application_set_resource_base_path")]
1129 #[doc(alias = "resource-base-path")]
1130 fn set_resource_base_path(&self, resource_path: Option<&str>) {
1131 unsafe {
1132 ffi::g_application_set_resource_base_path(
1133 self.as_ref().to_glib_none().0,
1134 resource_path.to_glib_none().0,
1135 );
1136 }
1137 }
1138
1139 /// Sets the version number of @self. This will be used to implement
1140 /// a `--version` command line argument
1141 ///
1142 /// The application version can only be modified if @self has not yet
1143 /// been registered.
1144 /// ## `version`
1145 /// the version of @self
1146 #[cfg(feature = "v2_80")]
1147 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
1148 #[doc(alias = "g_application_set_version")]
1149 #[doc(alias = "version")]
1150 fn set_version(&self, version: &str) {
1151 unsafe {
1152 ffi::g_application_set_version(
1153 self.as_ref().to_glib_none().0,
1154 version.to_glib_none().0,
1155 );
1156 }
1157 }
1158
1159 /// Destroys a binding between @property and the busy state of
1160 /// @self that was previously created with
1161 /// g_application_bind_busy_property().
1162 /// ## `object`
1163 /// a #GObject
1164 /// ## `property`
1165 /// the name of a boolean property of @object
1166 #[doc(alias = "g_application_unbind_busy_property")]
1167 fn unbind_busy_property(&self, object: &impl IsA<glib::Object>, property: &str) {
1168 unsafe {
1169 ffi::g_application_unbind_busy_property(
1170 self.as_ref().to_glib_none().0,
1171 object.as_ref().to_glib_none().0,
1172 property.to_glib_none().0,
1173 );
1174 }
1175 }
1176
1177 /// Withdraws a notification that was sent with
1178 /// g_application_send_notification().
1179 ///
1180 /// This call does nothing if a notification with @id doesn't exist or
1181 /// the notification was never sent.
1182 ///
1183 /// This function works even for notifications sent in previous
1184 /// executions of this application, as long @id is the same as it was for
1185 /// the sent notification.
1186 ///
1187 /// Note that notifications are dismissed when the user clicks on one
1188 /// of the buttons in a notification or triggers its default action, so
1189 /// there is no need to explicitly withdraw the notification in that case.
1190 /// ## `id`
1191 /// id of a previously sent notification
1192 #[doc(alias = "g_application_withdraw_notification")]
1193 fn withdraw_notification(&self, id: &str) {
1194 unsafe {
1195 ffi::g_application_withdraw_notification(
1196 self.as_ref().to_glib_none().0,
1197 id.to_glib_none().0,
1198 );
1199 }
1200 }
1201
1202 /// The ::activate signal is emitted on the primary instance when an
1203 /// activation occurs. See g_application_activate().
1204 #[doc(alias = "activate")]
1205 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1206 unsafe extern "C" fn activate_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
1207 this: *mut ffi::GApplication,
1208 f: glib::ffi::gpointer,
1209 ) {
1210 let f: &F = &*(f as *const F);
1211 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1212 }
1213 unsafe {
1214 let f: Box_<F> = Box_::new(f);
1215 connect_raw(
1216 self.as_ptr() as *mut _,
1217 b"activate\0".as_ptr() as *const _,
1218 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1219 activate_trampoline::<Self, F> as *const (),
1220 )),
1221 Box_::into_raw(f),
1222 )
1223 }
1224 }
1225
1226 /// The ::command-line signal is emitted on the primary instance when
1227 /// a commandline is not handled locally. See g_application_run() and
1228 /// the #GApplicationCommandLine documentation for more information.
1229 /// ## `command_line`
1230 /// a #GApplicationCommandLine representing the
1231 /// passed commandline
1232 ///
1233 /// # Returns
1234 ///
1235 /// An integer that is set as the exit status for the calling
1236 /// process. See g_application_command_line_set_exit_status().
1237 #[doc(alias = "command-line")]
1238 fn connect_command_line<F: Fn(&Self, &ApplicationCommandLine) -> i32 + 'static>(
1239 &self,
1240 f: F,
1241 ) -> SignalHandlerId {
1242 unsafe extern "C" fn command_line_trampoline<
1243 P: IsA<Application>,
1244 F: Fn(&P, &ApplicationCommandLine) -> i32 + 'static,
1245 >(
1246 this: *mut ffi::GApplication,
1247 command_line: *mut ffi::GApplicationCommandLine,
1248 f: glib::ffi::gpointer,
1249 ) -> std::ffi::c_int {
1250 let f: &F = &*(f as *const F);
1251 f(
1252 Application::from_glib_borrow(this).unsafe_cast_ref(),
1253 &from_glib_borrow(command_line),
1254 )
1255 }
1256 unsafe {
1257 let f: Box_<F> = Box_::new(f);
1258 connect_raw(
1259 self.as_ptr() as *mut _,
1260 b"command-line\0".as_ptr() as *const _,
1261 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1262 command_line_trampoline::<Self, F> as *const (),
1263 )),
1264 Box_::into_raw(f),
1265 )
1266 }
1267 }
1268
1269 /// The ::handle-local-options signal is emitted on the local instance
1270 /// after the parsing of the commandline options has occurred.
1271 ///
1272 /// You can add options to be recognised during commandline option
1273 /// parsing using g_application_add_main_option_entries() and
1274 /// g_application_add_option_group().
1275 ///
1276 /// Signal handlers can inspect @options (along with values pointed to
1277 /// from the @arg_data of an installed #GOptionEntrys) in order to
1278 /// decide to perform certain actions, including direct local handling
1279 /// (which may be useful for options like --version).
1280 ///
1281 /// In the event that the application is marked
1282 /// [`ApplicationFlags::HANDLES_COMMAND_LINE`][crate::ApplicationFlags::HANDLES_COMMAND_LINE] the "normal processing" will
1283 /// send the @options dictionary to the primary instance where it can be
1284 /// read with g_application_command_line_get_options_dict(). The signal
1285 /// handler can modify the dictionary before returning, and the
1286 /// modified dictionary will be sent.
1287 ///
1288 /// In the event that [`ApplicationFlags::HANDLES_COMMAND_LINE`][crate::ApplicationFlags::HANDLES_COMMAND_LINE] is not set,
1289 /// "normal processing" will treat the remaining uncollected command
1290 /// line arguments as filenames or URIs. If there are no arguments,
1291 /// the application is activated by g_application_activate(). One or
1292 /// more arguments results in a call to g_application_open().
1293 ///
1294 /// If you want to handle the local commandline arguments for yourself
1295 /// by converting them to calls to g_application_open() or
1296 /// g_action_group_activate_action() then you must be sure to register
1297 /// the application first. You should probably not call
1298 /// g_application_activate() for yourself, however: just return -1 and
1299 /// allow the default handler to do it for you. This will ensure that
1300 /// the `--gapplication-service` switch works properly (i.e. no activation
1301 /// in that case).
1302 ///
1303 /// Note that this signal is emitted from the default implementation of
1304 /// local_command_line(). If you override that function and don't
1305 /// chain up then this signal will never be emitted.
1306 ///
1307 /// You can override local_command_line() if you need more powerful
1308 /// capabilities than what is provided here, but this should not
1309 /// normally be required.
1310 /// ## `options`
1311 /// the options dictionary
1312 ///
1313 /// # Returns
1314 ///
1315 /// an exit code. If you have handled your options and want
1316 /// to exit the process, return a non-negative option, 0 for success,
1317 /// and a positive value for failure. To continue, return -1 to let
1318 /// the default option processing continue.
1319 #[doc(alias = "handle-local-options")]
1320 fn connect_handle_local_options<F: Fn(&Self, &glib::VariantDict) -> i32 + 'static>(
1321 &self,
1322 f: F,
1323 ) -> SignalHandlerId {
1324 unsafe extern "C" fn handle_local_options_trampoline<
1325 P: IsA<Application>,
1326 F: Fn(&P, &glib::VariantDict) -> i32 + 'static,
1327 >(
1328 this: *mut ffi::GApplication,
1329 options: *mut glib::ffi::GVariantDict,
1330 f: glib::ffi::gpointer,
1331 ) -> std::ffi::c_int {
1332 let f: &F = &*(f as *const F);
1333 f(
1334 Application::from_glib_borrow(this).unsafe_cast_ref(),
1335 &from_glib_borrow(options),
1336 )
1337 }
1338 unsafe {
1339 let f: Box_<F> = Box_::new(f);
1340 connect_raw(
1341 self.as_ptr() as *mut _,
1342 b"handle-local-options\0".as_ptr() as *const _,
1343 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1344 handle_local_options_trampoline::<Self, F> as *const (),
1345 )),
1346 Box_::into_raw(f),
1347 )
1348 }
1349 }
1350
1351 /// The ::name-lost signal is emitted only on the registered primary instance
1352 /// when a new instance has taken over. This can only happen if the application
1353 /// is using the [`ApplicationFlags::ALLOW_REPLACEMENT`][crate::ApplicationFlags::ALLOW_REPLACEMENT] flag.
1354 ///
1355 /// The default handler for this signal calls g_application_quit().
1356 ///
1357 /// # Returns
1358 ///
1359 /// [`true`] if the signal has been handled
1360 #[cfg(feature = "v2_60")]
1361 #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
1362 #[doc(alias = "name-lost")]
1363 fn connect_name_lost<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
1364 unsafe extern "C" fn name_lost_trampoline<
1365 P: IsA<Application>,
1366 F: Fn(&P) -> bool + 'static,
1367 >(
1368 this: *mut ffi::GApplication,
1369 f: glib::ffi::gpointer,
1370 ) -> glib::ffi::gboolean {
1371 let f: &F = &*(f as *const F);
1372 f(Application::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
1373 }
1374 unsafe {
1375 let f: Box_<F> = Box_::new(f);
1376 connect_raw(
1377 self.as_ptr() as *mut _,
1378 b"name-lost\0".as_ptr() as *const _,
1379 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1380 name_lost_trampoline::<Self, F> as *const (),
1381 )),
1382 Box_::into_raw(f),
1383 )
1384 }
1385 }
1386
1387 /// The ::shutdown signal is emitted only on the registered primary instance
1388 /// immediately after the main loop terminates.
1389 #[doc(alias = "shutdown")]
1390 fn connect_shutdown<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1391 unsafe extern "C" fn shutdown_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
1392 this: *mut ffi::GApplication,
1393 f: glib::ffi::gpointer,
1394 ) {
1395 let f: &F = &*(f as *const F);
1396 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1397 }
1398 unsafe {
1399 let f: Box_<F> = Box_::new(f);
1400 connect_raw(
1401 self.as_ptr() as *mut _,
1402 b"shutdown\0".as_ptr() as *const _,
1403 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1404 shutdown_trampoline::<Self, F> as *const (),
1405 )),
1406 Box_::into_raw(f),
1407 )
1408 }
1409 }
1410
1411 /// The ::startup signal is emitted on the primary instance immediately
1412 /// after registration. See g_application_register().
1413 #[doc(alias = "startup")]
1414 fn connect_startup<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1415 unsafe extern "C" fn startup_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
1416 this: *mut ffi::GApplication,
1417 f: glib::ffi::gpointer,
1418 ) {
1419 let f: &F = &*(f as *const F);
1420 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1421 }
1422 unsafe {
1423 let f: Box_<F> = Box_::new(f);
1424 connect_raw(
1425 self.as_ptr() as *mut _,
1426 b"startup\0".as_ptr() as *const _,
1427 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1428 startup_trampoline::<Self, F> as *const (),
1429 )),
1430 Box_::into_raw(f),
1431 )
1432 }
1433 }
1434
1435 #[doc(alias = "application-id")]
1436 fn connect_application_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1437 unsafe extern "C" fn notify_application_id_trampoline<
1438 P: IsA<Application>,
1439 F: Fn(&P) + 'static,
1440 >(
1441 this: *mut ffi::GApplication,
1442 _param_spec: glib::ffi::gpointer,
1443 f: glib::ffi::gpointer,
1444 ) {
1445 let f: &F = &*(f as *const F);
1446 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1447 }
1448 unsafe {
1449 let f: Box_<F> = Box_::new(f);
1450 connect_raw(
1451 self.as_ptr() as *mut _,
1452 b"notify::application-id\0".as_ptr() as *const _,
1453 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1454 notify_application_id_trampoline::<Self, F> as *const (),
1455 )),
1456 Box_::into_raw(f),
1457 )
1458 }
1459 }
1460
1461 #[doc(alias = "flags")]
1462 fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1463 unsafe extern "C" fn notify_flags_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
1464 this: *mut ffi::GApplication,
1465 _param_spec: glib::ffi::gpointer,
1466 f: glib::ffi::gpointer,
1467 ) {
1468 let f: &F = &*(f as *const F);
1469 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1470 }
1471 unsafe {
1472 let f: Box_<F> = Box_::new(f);
1473 connect_raw(
1474 self.as_ptr() as *mut _,
1475 b"notify::flags\0".as_ptr() as *const _,
1476 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1477 notify_flags_trampoline::<Self, F> as *const (),
1478 )),
1479 Box_::into_raw(f),
1480 )
1481 }
1482 }
1483
1484 #[doc(alias = "inactivity-timeout")]
1485 fn connect_inactivity_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1486 unsafe extern "C" fn notify_inactivity_timeout_trampoline<
1487 P: IsA<Application>,
1488 F: Fn(&P) + 'static,
1489 >(
1490 this: *mut ffi::GApplication,
1491 _param_spec: glib::ffi::gpointer,
1492 f: glib::ffi::gpointer,
1493 ) {
1494 let f: &F = &*(f as *const F);
1495 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1496 }
1497 unsafe {
1498 let f: Box_<F> = Box_::new(f);
1499 connect_raw(
1500 self.as_ptr() as *mut _,
1501 b"notify::inactivity-timeout\0".as_ptr() as *const _,
1502 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1503 notify_inactivity_timeout_trampoline::<Self, F> as *const (),
1504 )),
1505 Box_::into_raw(f),
1506 )
1507 }
1508 }
1509
1510 #[doc(alias = "is-busy")]
1511 fn connect_is_busy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1512 unsafe extern "C" fn notify_is_busy_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
1513 this: *mut ffi::GApplication,
1514 _param_spec: glib::ffi::gpointer,
1515 f: glib::ffi::gpointer,
1516 ) {
1517 let f: &F = &*(f as *const F);
1518 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1519 }
1520 unsafe {
1521 let f: Box_<F> = Box_::new(f);
1522 connect_raw(
1523 self.as_ptr() as *mut _,
1524 b"notify::is-busy\0".as_ptr() as *const _,
1525 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1526 notify_is_busy_trampoline::<Self, F> as *const (),
1527 )),
1528 Box_::into_raw(f),
1529 )
1530 }
1531 }
1532
1533 #[doc(alias = "is-registered")]
1534 fn connect_is_registered_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1535 unsafe extern "C" fn notify_is_registered_trampoline<
1536 P: IsA<Application>,
1537 F: Fn(&P) + 'static,
1538 >(
1539 this: *mut ffi::GApplication,
1540 _param_spec: glib::ffi::gpointer,
1541 f: glib::ffi::gpointer,
1542 ) {
1543 let f: &F = &*(f as *const F);
1544 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1545 }
1546 unsafe {
1547 let f: Box_<F> = Box_::new(f);
1548 connect_raw(
1549 self.as_ptr() as *mut _,
1550 b"notify::is-registered\0".as_ptr() as *const _,
1551 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1552 notify_is_registered_trampoline::<Self, F> as *const (),
1553 )),
1554 Box_::into_raw(f),
1555 )
1556 }
1557 }
1558
1559 #[doc(alias = "is-remote")]
1560 fn connect_is_remote_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1561 unsafe extern "C" fn notify_is_remote_trampoline<
1562 P: IsA<Application>,
1563 F: Fn(&P) + 'static,
1564 >(
1565 this: *mut ffi::GApplication,
1566 _param_spec: glib::ffi::gpointer,
1567 f: glib::ffi::gpointer,
1568 ) {
1569 let f: &F = &*(f as *const F);
1570 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1571 }
1572 unsafe {
1573 let f: Box_<F> = Box_::new(f);
1574 connect_raw(
1575 self.as_ptr() as *mut _,
1576 b"notify::is-remote\0".as_ptr() as *const _,
1577 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1578 notify_is_remote_trampoline::<Self, F> as *const (),
1579 )),
1580 Box_::into_raw(f),
1581 )
1582 }
1583 }
1584
1585 #[doc(alias = "resource-base-path")]
1586 fn connect_resource_base_path_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1587 unsafe extern "C" fn notify_resource_base_path_trampoline<
1588 P: IsA<Application>,
1589 F: Fn(&P) + 'static,
1590 >(
1591 this: *mut ffi::GApplication,
1592 _param_spec: glib::ffi::gpointer,
1593 f: glib::ffi::gpointer,
1594 ) {
1595 let f: &F = &*(f as *const F);
1596 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1597 }
1598 unsafe {
1599 let f: Box_<F> = Box_::new(f);
1600 connect_raw(
1601 self.as_ptr() as *mut _,
1602 b"notify::resource-base-path\0".as_ptr() as *const _,
1603 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1604 notify_resource_base_path_trampoline::<Self, F> as *const (),
1605 )),
1606 Box_::into_raw(f),
1607 )
1608 }
1609 }
1610
1611 #[cfg(feature = "v2_80")]
1612 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
1613 #[doc(alias = "version")]
1614 fn connect_version_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1615 unsafe extern "C" fn notify_version_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
1616 this: *mut ffi::GApplication,
1617 _param_spec: glib::ffi::gpointer,
1618 f: glib::ffi::gpointer,
1619 ) {
1620 let f: &F = &*(f as *const F);
1621 f(Application::from_glib_borrow(this).unsafe_cast_ref())
1622 }
1623 unsafe {
1624 let f: Box_<F> = Box_::new(f);
1625 connect_raw(
1626 self.as_ptr() as *mut _,
1627 b"notify::version\0".as_ptr() as *const _,
1628 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1629 notify_version_trampoline::<Self, F> as *const (),
1630 )),
1631 Box_::into_raw(f),
1632 )
1633 }
1634 }
1635}
1636
1637impl<O: IsA<Application>> ApplicationExt for O {}