Trait gio::prelude::ApplicationExt

source ·
pub trait ApplicationExt: IsA<Application> + Sealed + 'static {
Show 44 methods // Provided methods fn activate(&self) { ... } fn add_main_option( &self, long_name: &str, short_name: Char, flags: OptionFlags, arg: OptionArg, description: &str, arg_description: Option<&str>, ) { ... } fn bind_busy_property(&self, object: &impl IsA<Object>, property: &str) { ... } fn application_id(&self) -> Option<GString> { ... } fn dbus_connection(&self) -> Option<DBusConnection> { ... } fn dbus_object_path(&self) -> Option<GString> { ... } fn flags(&self) -> ApplicationFlags { ... } fn inactivity_timeout(&self) -> u32 { ... } fn is_busy(&self) -> bool { ... } fn is_registered(&self) -> bool { ... } fn is_remote(&self) -> bool { ... } fn resource_base_path(&self) -> Option<GString> { ... } fn version(&self) -> Option<GString> { ... } fn open(&self, files: &[File], hint: &str) { ... } fn quit(&self) { ... } fn register( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error> { ... } fn send_notification(&self, id: Option<&str>, notification: &Notification) { ... } fn set_application_id(&self, application_id: Option<&str>) { ... } fn set_default(&self) { ... } fn set_flags(&self, flags: ApplicationFlags) { ... } fn set_inactivity_timeout(&self, inactivity_timeout: u32) { ... } fn set_option_context_description(&self, description: Option<&str>) { ... } fn set_option_context_parameter_string( &self, parameter_string: Option<&str>, ) { ... } fn set_option_context_summary(&self, summary: Option<&str>) { ... } fn set_resource_base_path(&self, resource_path: Option<&str>) { ... } fn set_version(&self, version: &str) { ... } fn unbind_busy_property(&self, object: &impl IsA<Object>, property: &str) { ... } fn withdraw_notification(&self, id: &str) { ... } fn set_action_group<P: IsA<ActionGroup>>(&self, action_group: Option<&P>) { ... } fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { ... } fn connect_command_line<F: Fn(&Self, &ApplicationCommandLine) -> i32 + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_handle_local_options<F: Fn(&Self, &VariantDict) -> i32 + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_name_lost<F: Fn(&Self) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_shutdown<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { ... } fn connect_startup<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { ... } fn connect_action_group_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_application_id_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_flags_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_inactivity_timeout_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_is_busy_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_is_registered_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_is_remote_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_resource_base_path_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_version_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all Application methods.

§Implementors

Application

Provided Methods§

source

fn activate(&self)

Activates the application.

In essence, this results in the #GApplication::activate signal being emitted in the primary instance.

The application must be registered before calling this function.

source

fn add_main_option( &self, long_name: &str, short_name: Char, flags: OptionFlags, arg: OptionArg, description: &str, arg_description: Option<&str>, )

Add an option to be handled by @self.

Calling this function is the equivalent of calling g_application_add_main_option_entries() with a single #GOptionEntry that has its arg_data member set to None.

The parsed arguments will be packed into a #GVariantDict which is passed to #GApplication::handle-local-options. If ApplicationFlags::HANDLES_COMMAND_LINE is set, then it will also be sent to the primary instance. See g_application_add_main_option_entries() for more details.

See #GOptionEntry for more documentation of the arguments.

§long_name

the long name of an option used to specify it in a commandline

§short_name

the short name of an option

§flags

flags from #GOptionFlags

§arg

the type of the option, as a #GOptionArg

§description

the description for the option in --help output

§arg_description

the placeholder to use for the extra argument parsed by the option in --help output

source

fn bind_busy_property(&self, object: &impl IsA<Object>, property: &str)

Marks @self as busy (see g_application_mark_busy()) while @property on @object is true.

The binding holds a reference to @self while it is active, but not to @object. Instead, the binding is destroyed when @object is finalized.

§object

a #GObject

§property

the name of a boolean property of @object

source

fn application_id(&self) -> Option<GString>

Gets the unique identifier for @self.

§Returns

the identifier for @self, owned by @self

source

fn dbus_connection(&self) -> Option<DBusConnection>

Gets the #GDBusConnection being used by the application, or None.

If #GApplication is using its D-Bus backend then this function will return the #GDBusConnection being used for uniqueness and communication with the desktop environment and other instances of the application.

If #GApplication is not using D-Bus then this function will return None. This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus.

This function must not be called before the application has been registered. See g_application_get_is_registered().

§Returns

a #GDBusConnection, or None

source

fn dbus_object_path(&self) -> Option<GString>

Gets the D-Bus object path being used by the application, or None.

If #GApplication is using its D-Bus backend then this function will return the D-Bus object path that #GApplication is using. If the application is the primary instance then there is an object published at this path. If the application is not the primary instance then the result of this function is undefined.

If #GApplication is not using D-Bus then this function will return None. This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus.

This function must not be called before the application has been registered. See g_application_get_is_registered().

§Returns

the object path, or None

source

fn flags(&self) -> ApplicationFlags

Gets the flags for @self.

See #GApplicationFlags.

§Returns

the flags for @self

source

fn inactivity_timeout(&self) -> u32

Gets the current inactivity timeout for the application.

This is the amount of time (in milliseconds) after the last call to g_application_release() before the application stops running.

§Returns

the timeout, in milliseconds

source

fn is_busy(&self) -> bool

Gets the application’s current busy state, as set through g_application_mark_busy() or g_application_bind_busy_property().

§Returns

true if @self is currently marked as busy

source

fn is_registered(&self) -> bool

Checks if @self is registered.

An application is registered if g_application_register() has been successfully called.

§Returns

true if @self is registered

source

fn is_remote(&self) -> bool

Checks if @self is remote.

If @self is remote then it means that another instance of application already exists (the ‘primary’ instance). Calls to perform actions on @self will result in the actions being performed by the primary instance.

The value of this property cannot be accessed before g_application_register() has been called. See g_application_get_is_registered().

§Returns

true if @self is remote

source

fn resource_base_path(&self) -> Option<GString>

Gets the resource base path of @self.

See g_application_set_resource_base_path() for more information.

§Returns

the base resource path, if one is set

source

fn version(&self) -> Option<GString>

Available on crate feature v2_80 only.

Gets the version of @self.

§Returns

the version of @self

source

fn open(&self, files: &[File], hint: &str)

Opens the given files.

In essence, this results in the #GApplication::open signal being emitted in the primary instance.

@n_files must be greater than zero.

@hint is simply passed through to the ::open signal. It is intended to be used by applications that have multiple modes for opening files (eg: “view” vs “edit”, etc). Unless you have a need for this functionality, you should use “”.

The application must be registered before calling this function and it must have the ApplicationFlags::HANDLES_OPEN flag set.

§files

an array of #GFiles to open

§hint

a hint (or “”), but never None

source

fn quit(&self)

Immediately quits the application.

Upon return to the mainloop, g_application_run() will return, calling only the ‘shutdown’ function before doing so.

The hold count is ignored. Take care if your code has called g_application_hold() on the application and is therefore still expecting it to exist. (Note that you may have called g_application_hold() indirectly, for example through gtk_application_add_window().)

The result of calling g_application_run() again after it returns is unspecified.

source

fn register( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Attempts registration of the application.

This is the point at which the application discovers if it is the primary instance or merely acting as a remote for an already-existing primary instance. This is implemented by attempting to acquire the application identifier as a unique bus name on the session bus using GDBus.

If there is no application ID or if ApplicationFlags::NON_UNIQUE was given, then this process will always become the primary instance.

Due to the internal architecture of GDBus, method calls can be dispatched at any time (even if a main loop is not running). For this reason, you must ensure that any object paths that you wish to register are registered before calling this function.

If the application has already been registered then true is returned with no work performed.

The #GApplication::startup signal is emitted if registration succeeds and @self is the primary instance (including the non-unique case).

In the event of an error (such as @cancellable being cancelled, or a failure to connect to the session bus), false is returned and @error is set appropriately.

Note: the return value of this function is not an indicator that this instance is or is not the primary instance of the application. See g_application_get_is_remote() for that.

§cancellable

a #GCancellable, or None

§Returns

true if registration succeeded

source

fn send_notification(&self, id: Option<&str>, notification: &Notification)

Sends a notification on behalf of @self to the desktop shell. There is no guarantee that the notification is displayed immediately, or even at all.

Notifications may persist after the application exits. It will be D-Bus-activated when the notification or one of its actions is activated.

Modifying @notification after this call has no effect. However, the object can be reused for a later call to this function.

@id may be any string that uniquely identifies the event for the application. It does not need to be in any special format. For example, “new-message” might be appropriate for a notification about new messages.

If a previous notification was sent with the same @id, it will be replaced with @notification and shown again as if it was a new notification. This works even for notifications sent from a previous execution of the application, as long as @id is the same string.

@id may be None, but it is impossible to replace or withdraw notifications without an id.

If @notification is no longer relevant, it can be withdrawn with g_application_withdraw_notification().

It is an error to call this function if @self has no application ID.

§id

id of the notification, or None

§notification

the #GNotification to send

source

fn set_application_id(&self, application_id: Option<&str>)

Sets the unique identifier for @self.

The application id can only be modified if @self has not yet been registered.

If non-None, the application id must be valid. See g_application_id_is_valid().

§application_id

the identifier for @self

source

fn set_default(&self)

Sets or unsets the default application for the process, as returned by g_application_get_default().

This function does not take its own reference on @self. If @self is destroyed then the default application will revert back to None.

source

fn set_flags(&self, flags: ApplicationFlags)

Sets the flags for @self.

The flags can only be modified if @self has not yet been registered.

See #GApplicationFlags.

§flags

the flags for @self

source

fn set_inactivity_timeout(&self, inactivity_timeout: u32)

Sets the current inactivity timeout for the application.

This is the amount of time (in milliseconds) after the last call to g_application_release() before the application stops running.

This call has no side effects of its own. The value set here is only used for next time g_application_release() drops the use count to zero. Any timeouts currently in progress are not impacted.

§inactivity_timeout

the timeout, in milliseconds

source

fn set_option_context_description(&self, description: Option<&str>)

Adds a description to the @self option context.

See g_option_context_set_description() for more information.

§description

a string to be shown in --help output after the list of options, or None

source

fn set_option_context_parameter_string(&self, parameter_string: Option<&str>)

Sets the parameter string to be used by the commandline handling of @self.

This function registers the argument to be passed to g_option_context_new() when the internal #GOptionContext of @self is created.

See g_option_context_new() for more information about @parameter_string.

§parameter_string

a string which is displayed in the first line of --help output, after the usage summary programname [OPTION...].

source

fn set_option_context_summary(&self, summary: Option<&str>)

Adds a summary to the @self option context.

See g_option_context_set_summary() for more information.

§summary

a string to be shown in --help output before the list of options, or None

source

fn set_resource_base_path(&self, resource_path: Option<&str>)

Sets (or unsets) the base resource path of @self.

The path is used to automatically load various [application resources][gresource] such as menu layouts and action descriptions. The various types of resources will be found at fixed names relative to the given base path.

By default, the resource base path is determined from the application ID by prefixing ‘/’ and replacing each ‘.’ with ‘/’. This is done at the time that the #GApplication object is constructed. Changes to the application ID after that point will not have an impact on the resource base path.

As an example, if the application has an ID of “org.example.app” then the default resource base path will be “/org/example/app”. If this is a #GtkApplication (and you have not manually changed the path) then Gtk will then search for the menus of the application at “/org/example/app/gtk/menus.ui”.

See #GResource for more information about adding resources to your application.

You can disable automatic resource loading functionality by setting the path to None.

Changing the resource base path once the application is running is not recommended. The point at which the resource path is consulted for forming paths for various purposes is unspecified. When writing a sub-class of #GApplication you should either set the #GApplication:resource-base-path property at construction time, or call this function during the instance initialization. Alternatively, you can call this function in the #GApplicationClass.startup virtual function, before chaining up to the parent implementation.

§resource_path

the resource path to use

source

fn set_version(&self, version: &str)

Available on crate feature v2_80 only.

Sets the version number of @self. This will be used to implement a --version command line argument

The application version can only be modified if @self has not yet been registered.

§version

the version of @self

source

fn unbind_busy_property(&self, object: &impl IsA<Object>, property: &str)

Destroys a binding between @property and the busy state of @self that was previously created with g_application_bind_busy_property().

§object

a #GObject

§property

the name of a boolean property of @object

source

fn withdraw_notification(&self, id: &str)

Withdraws a notification that was sent with g_application_send_notification().

This call does nothing if a notification with @id doesn’t exist or the notification was never sent.

This function works even for notifications sent in previous executions of this application, as long @id is the same as it was for the sent notification.

Note that notifications are dismissed when the user clicks on one of the buttons in a notification or triggers its default action, so there is no need to explicitly withdraw the notification in that case.

§id

id of a previously sent notification

source

fn set_action_group<P: IsA<ActionGroup>>(&self, action_group: Option<&P>)

The group of actions that the application exports.

source

fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

The ::activate signal is emitted on the primary instance when an activation occurs. See g_application_activate().

source

fn connect_command_line<F: Fn(&Self, &ApplicationCommandLine) -> i32 + 'static>( &self, f: F, ) -> SignalHandlerId

The ::command-line signal is emitted on the primary instance when a commandline is not handled locally. See g_application_run() and the #GApplicationCommandLine documentation for more information.

§command_line

a #GApplicationCommandLine representing the passed commandline

§Returns

An integer that is set as the exit status for the calling process. See g_application_command_line_set_exit_status().

source

fn connect_handle_local_options<F: Fn(&Self, &VariantDict) -> i32 + 'static>( &self, f: F, ) -> SignalHandlerId

The ::handle-local-options signal is emitted on the local instance after the parsing of the commandline options has occurred.

You can add options to be recognised during commandline option parsing using g_application_add_main_option_entries() and g_application_add_option_group().

Signal handlers can inspect @options (along with values pointed to from the @arg_data of an installed #GOptionEntrys) in order to decide to perform certain actions, including direct local handling (which may be useful for options like –version).

In the event that the application is marked ApplicationFlags::HANDLES_COMMAND_LINE the “normal processing” will send the @options dictionary to the primary instance where it can be read with g_application_command_line_get_options_dict(). The signal handler can modify the dictionary before returning, and the modified dictionary will be sent.

In the event that ApplicationFlags::HANDLES_COMMAND_LINE is not set, “normal processing” will treat the remaining uncollected command line arguments as filenames or URIs. If there are no arguments, the application is activated by g_application_activate(). One or more arguments results in a call to g_application_open().

If you want to handle the local commandline arguments for yourself by converting them to calls to g_application_open() or g_action_group_activate_action() then you must be sure to register the application first. You should probably not call g_application_activate() for yourself, however: just return -1 and allow the default handler to do it for you. This will ensure that the --gapplication-service switch works properly (i.e. no activation in that case).

Note that this signal is emitted from the default implementation of local_command_line(). If you override that function and don’t chain up then this signal will never be emitted.

You can override local_command_line() if you need more powerful capabilities than what is provided here, but this should not normally be required.

§options

the options dictionary

§Returns

an exit code. If you have handled your options and want to exit the process, return a non-negative option, 0 for success, and a positive value for failure. To continue, return -1 to let the default option processing continue.

source

fn connect_name_lost<F: Fn(&Self) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId

Available on crate feature v2_60 only.

The ::name-lost signal is emitted only on the registered primary instance when a new instance has taken over. This can only happen if the application is using the ApplicationFlags::ALLOW_REPLACEMENT flag.

The default handler for this signal calls g_application_quit().

§Returns

true if the signal has been handled

source

fn connect_shutdown<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

The ::shutdown signal is emitted only on the registered primary instance immediately after the main loop terminates.

source

fn connect_startup<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

The ::startup signal is emitted on the primary instance immediately after registration. See g_application_register().

source

fn connect_action_group_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

source

fn connect_application_id_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

source

fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

source

fn connect_inactivity_timeout_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

source

fn connect_is_busy_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

source

fn connect_is_registered_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

source

fn connect_is_remote_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

source

fn connect_resource_base_path_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

source

fn connect_version_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Available on crate feature v2_80 only.

Object Safety§

This trait is not object safe.

Implementors§