Application - Core application class. More...
#include <giomm/application.h>
Public Types | |
typedef std::vector < Glib::RefPtr< File > > | type_vec_files |
Public Member Functions | |
virtual | ~Application () |
GApplication* | gobj () |
Provides access to the underlying C GObject. | |
const GApplication* | gobj () const |
Provides access to the underlying C GObject. | |
GApplication* | gobj_copy () |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. | |
Glib::ustring | get_id () const |
Gets the unique identifier for application. | |
void | set_id (const Glib::ustring& application_id) |
Sets the unique identifier for application. | |
guint | get_inactivity_timeout () const |
Gets the current inactivity timeout for the application. | |
void | set_inactivity_timeout (guint inactivity_timeout) |
Sets the current inactivity timeout for the application. | |
ApplicationFlags | get_flags () const |
Gets the flags for application. | |
void | set_flags (ApplicationFlags flags) |
Sets the flags for application. | |
void | set_action_group (const Glib::RefPtr< ActionGroup >& action_group) |
Sets or unsets the group of actions associated with the application. | |
bool | is_registered () const |
Checks if application is registered. | |
bool | is_remote () const |
Checks if application is remote. | |
bool | register_application (const Glib::RefPtr< Gio::Cancellable >& cancellable) |
Attempts registration of the application. | |
bool | register_application () |
Non-cancellable version of register_application(). | |
void | hold () |
Increases the use count of application. | |
void | release () |
Decrease the use count of application. | |
void | activate () |
Activates the application. | |
void | open (const type_vec_files& files, const Glib::ustring& hint=Glib::ustring()) |
int | run (int argc, char** argv) |
Runs the application. | |
Glib::PropertyProxy_WriteOnly < Glib::RefPtr< ActionGroup > > | property_action_group () |
The group of actions that the application exports. | |
Glib::PropertyProxy < Glib::ustring > | property_application_id () |
The unique identifier for the application. | |
Glib::PropertyProxy_ReadOnly < Glib::ustring > | property_application_id () const |
The unique identifier for the application. | |
Glib::PropertyProxy < ApplicationFlags > | property_flags () |
Flags specifying the behaviour of the application. | |
Glib::PropertyProxy_ReadOnly < ApplicationFlags > | property_flags () const |
Flags specifying the behaviour of the application. | |
Glib::PropertyProxy< guint > | property_inactivity_timeout () |
Iime (ms) to stay alive after becoming idle. | |
Glib::PropertyProxy_ReadOnly < guint > | property_inactivity_timeout () const |
Iime (ms) to stay alive after becoming idle. | |
Glib::PropertyProxy_ReadOnly < bool > | property_is_registered () const |
If g_application_register() has been called. | |
Glib::PropertyProxy_ReadOnly < bool > | property_is_remote () const |
If this application instance is remote. | |
Glib::SignalProxy0< void > | signal_startup () |
Glib::SignalProxy0< void > | signal_activate () |
Glib::SignalProxy2< void, const type_vec_files &, const Glib::ustring& > | signal_open () |
Glib::SignalProxy1< bool, const Glib::RefPtr < ApplicationCommandLine >& > | signal_command_line () |
Static Public Member Functions | |
static Glib::RefPtr< Application > | create (const Glib::ustring& application_id, ApplicationFlags flags=APPLICATION_FLAGS_NONE) |
static bool | id_is_valid (const Glib::ustring& application_id) |
Checks if application_id is a valid application identifier. | |
Protected Member Functions | |
Application (const Glib::ustring& application_id, ApplicationFlags flags=APPLICATION_FLAGS_NONE) | |
virtual void | on_open (const type_vec_files& files, const Glib::ustring& hint) |
virtual void | on_startup () |
virtual void | on_activate () |
virtual bool | on_command_line (const Glib::RefPtr< ApplicationCommandLine >& command_line) |
Related Functions | |
(Note that these are not member functions.) | |
Glib::RefPtr< Gio::Application > | wrap (GApplication* object, bool take_copy=false) |
A Glib::wrap() method for this object. |
Application - Core application class.
An Application is the foundation of an application, unique for a given application identifier. The Application class wraps some low-level platform-specific services and is intended to act as the foundation for higher-level application classes such as Gtk::Application or MxApplication. In general, you should not use this class outside of a higher level framework.
One of the core features that Application provides is process uniqueness, in the context of a "session". The session concept is platform-dependent, but corresponds roughly to a graphical desktop login. When your application is launched again, its arguments are passed through platform communication to the already running program. The already running instance of the program is called the primary instance.
Before using Application, you must choose an "application identifier". The expected form of an application identifier is very close to that of of a DBus bus name. Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator". For details on valid application identifiers, see id_is_valid().
Application provides convenient life cycle management by maintaining a use count for the primary application instance. The use count can be changed using hold() and release(). If it drops to zero, the application exits.
Application also implements the ActionGroup interface and lets you easily export actions by adding them with set_action_group(). When invoking an action by calling Gio::ActionGroup::activate_action() on the application, it is always invoked in the primary instance.
There is a number of different entry points into an Application:
The signal_startup() signal lets you handle the application initialization for all of these in a single place.
See the C API docs for an example.
typedef std::vector< Glib::RefPtr<File> > Gio::Application::type_vec_files |
virtual Gio::Application::~Application | ( | ) | [virtual] |
Gio::Application::Application | ( | const Glib::ustring& | application_id, |
ApplicationFlags | flags = APPLICATION_FLAGS_NONE |
||
) | [explicit, protected] |
void Gio::Application::activate | ( | ) |
Activates the application.
In essence, this results in the Application::activate() signal being emitted in the primary instance.
The application must be registered before calling this function.
static Glib::RefPtr<Application> Gio::Application::create | ( | const Glib::ustring& | application_id, |
ApplicationFlags | flags = APPLICATION_FLAGS_NONE |
||
) | [static] |
ApplicationFlags Gio::Application::get_flags | ( | ) | const |
Gets the flags for application.
See ApplicationFlags.
Glib::ustring Gio::Application::get_id | ( | ) | const |
Gets the unique identifier for application.
guint Gio::Application::get_inactivity_timeout | ( | ) | const |
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.
const GApplication* Gio::Application::gobj | ( | ) | const [inline] |
Provides access to the underlying C GObject.
Reimplemented from Glib::ObjectBase.
GApplication* Gio::Application::gobj | ( | ) | [inline] |
Provides access to the underlying C GObject.
Reimplemented from Glib::ObjectBase.
GApplication* Gio::Application::gobj_copy | ( | ) |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
void Gio::Application::hold | ( | ) |
Increases the use count of application.
Use this function to indicate that the application has a reason to continue to run. For example, g_application_hold() is called by GTK+ when a toplevel window is on the screen.
To cancel the hold, call g_application_release().
static bool Gio::Application::id_is_valid | ( | const Glib::ustring& | application_id ) | [static] |
Checks if application_id is a valid application identifier.
A valid ID is required for calls to g_application_new() and g_application_set_application_id().
For convenience, the restrictions on application identifiers are reproduced here: <itemizedlist> <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-" and must not begin with a digit.</listitem> <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least two elements).</listitem> <listitem>Application identifiers must not begin with a '.' (period) character.</listitem> <listitem>Application identifiers must not contain consecutive '.' (period) characters.</listitem> <listitem>Application identifiers must not exceed 255 characters.</listitem> </itemizedlist>
application_id | A potential application identifier. |
true
if application_id is valid. bool Gio::Application::is_registered | ( | ) | const |
Checks if application is registered.
An application is registered if g_application_register() has been successfully called.
true
if application is registered. bool Gio::Application::is_remote | ( | ) | const |
Checks if application is remote.
If application is remote then it means that another instance of application already exists (the 'primary' instance). Calls to perform actions on application will result in the actions being performed by the primary instance.
The value of this property can not be accessed before g_application_register() has been called. See g_application_get_is_registered().
true
if application is remote. virtual void Gio::Application::on_activate | ( | ) | [protected, virtual] |
virtual bool Gio::Application::on_command_line | ( | const Glib::RefPtr< ApplicationCommandLine >& | command_line ) | [protected, virtual] |
virtual void Gio::Application::on_open | ( | const type_vec_files & | files, |
const Glib::ustring& | hint | ||
) | [protected, virtual] |
virtual void Gio::Application::on_startup | ( | ) | [protected, virtual] |
void Gio::Application::open | ( | const type_vec_files & | files, |
const Glib::ustring& | hint = Glib::ustring() |
||
) |
Glib::PropertyProxy_WriteOnly< Glib::RefPtr<ActionGroup> > Gio::Application::property_action_group | ( | ) |
The group of actions that the application exports.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy<Glib::ustring> Gio::Application::property_application_id | ( | ) |
The unique identifier for the application.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy_ReadOnly<Glib::ustring> Gio::Application::property_application_id | ( | ) | const |
The unique identifier for the application.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy<ApplicationFlags> Gio::Application::property_flags | ( | ) |
Flags specifying the behaviour of the application.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy_ReadOnly<ApplicationFlags> Gio::Application::property_flags | ( | ) | const |
Flags specifying the behaviour of the application.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy<guint> Gio::Application::property_inactivity_timeout | ( | ) |
Iime (ms) to stay alive after becoming idle.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy_ReadOnly<guint> Gio::Application::property_inactivity_timeout | ( | ) | const |
Iime (ms) to stay alive after becoming idle.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy_ReadOnly<bool> Gio::Application::property_is_registered | ( | ) | const |
If g_application_register() has been called.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
Glib::PropertyProxy_ReadOnly<bool> Gio::Application::property_is_remote | ( | ) | const |
If this application instance is remote.
You rarely need to use properties because there are get_ and set_ methods for almost all of them.
bool Gio::Application::register_application | ( | ) |
Non-cancellable version of register_application().
bool Gio::Application::register_application | ( | const Glib::RefPtr< Gio::Cancellable >& | cancellable ) |
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 uniue bus name on the session bus using GDBus.
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 Application::startup signal is emitted if registration succeeds and application is the primary instance.
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.
cancellable | A Cancellable, or 0 . |
true
if registration succeeded. void Gio::Application::release | ( | ) |
Decrease the use count of application.
When the use count reaches zero, the application will stop running.
Never call this function except to cancel the effect of a previous call to g_application_hold().
int Gio::Application::run | ( | int | argc, |
char ** | argv | ||
) |
Runs the application.
This function is intended to be run from main() and its return value is intended to be returned by main().
First, the local_command_line() virtual function is invoked. This function always runs on the local instance. If that function returns false
then the application is registered and the Application::command-line signal is emitted in the primary instance (which may or may not be this instance).
If the application has the APPLICATION_HANDLES_COMMAND_LINE flag set then the default implementation of local_command_line() always returns false
immediately, resulting in the commandline always being handled in the primary instance.
Otherwise, the default implementation of local_command_line() tries to do a couple of things that are probably reasonable for most applications. First, g_application_register() is called to attempt to register the application. If that works, then the command line arguments are inspected. If no commandline arguments are given, then g_application_activate() is called. If commandline arguments are given and the APPLICATION_HANDLES_OPEN flag is set then they are assumed to be filenames and g_application_open() is called.
If you are interested in doing more complicated local handling of the commandline then you should implement your own Application subclass and override local_command_line(). See <xref linkend="gapplication-example-cmdline2"> for an example.
If, after the above is done, the use count of the application is zero then the exit status is returned immediately. If the use count is non-zero then the mainloop is run until the use count falls to zero, at which point 0 is returned.
If the APPLICATION_IS_SERVICE flag is set, then the exiting at use count of zero is delayed for a while (ie: the instance stays around to provide its service to others).
argc | The argc from main(). |
argv | The argv from main(). |
void Gio::Application::set_action_group | ( | const Glib::RefPtr< ActionGroup >& | action_group ) |
Sets or unsets the group of actions associated with the application.
These actions are the actions that can be remotely invoked.
It is an error to call this function after the application has been registered.
action_group | A ActionGroup, or 0 . |
void Gio::Application::set_flags | ( | ApplicationFlags | flags ) |
Sets the flags for application.
The flags can only be modified if application has not yet been registered.
See ApplicationFlags.
flags | The flags for application. |
void Gio::Application::set_id | ( | const Glib::ustring& | application_id ) |
Sets the unique identifier for application.
The application id can only be modified if application has not yet been registered.
The application id must be valid. See g_application_id_is_valid().
application_id | The identifier for application. |
void Gio::Application::set_inactivity_timeout | ( | guint | inactivity_timeout ) |
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. |
Glib::SignalProxy0< void > Gio::Application::signal_activate | ( | ) |
void on_my_activate()
Glib::SignalProxy1< bool,const Glib::RefPtr<ApplicationCommandLine>& > Gio::Application::signal_command_line | ( | ) |
bool on_my_command_line(const Glib::RefPtr<ApplicationCommandLine>& command_line)
Glib::SignalProxy2< void, const type_vec_files&, const Glib::ustring& > Gio::Application::signal_open | ( | ) |
Glib::SignalProxy0< void > Gio::Application::signal_startup | ( | ) |
void on_my_startup()
Glib::RefPtr< Gio::Application > wrap | ( | GApplication * | object, |
bool | take_copy = false |
||
) | [related] |
A Glib::wrap() method for this object.
object | The C instance. |
take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref. |