2010-10-06 19:08:26 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Codethink Limited
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
|
* your option) any later version.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
|
|
|
* Public License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Authors: Ryan Lortie <desrt@desrt.ca>
|
2010-06-07 19:25:39 +02:00
|
|
|
*/
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Prologue {{{1 */
|
2010-10-23 00:40:13 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
#include "gapplication.h"
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-09 23:24:09 +02:00
|
|
|
#include "gapplicationcommandline.h"
|
2010-10-06 19:08:26 +02:00
|
|
|
#include "gapplicationimpl.h"
|
2010-10-11 02:05:13 +02:00
|
|
|
#include "gactiongroup.h"
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
#include "gioenumtypes.h"
|
2010-06-07 19:25:39 +02:00
|
|
|
#include "gio-marshal.h"
|
2010-10-06 19:08:26 +02:00
|
|
|
#include "gioenums.h"
|
|
|
|
#include "gfile.h"
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-23 00:40:13 +02:00
|
|
|
#include "glibintl.h"
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
#include <string.h>
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-23 00:40:13 +02:00
|
|
|
/**
|
|
|
|
* SECTION: gapplication
|
|
|
|
* @title: GApplication
|
|
|
|
* @short_description: Core application class
|
|
|
|
*
|
|
|
|
* A #GApplication is the foundation of an application, unique for a
|
|
|
|
* given application identifier. The GApplication class wraps some
|
|
|
|
* low-level platform-specific services and is intended to act as the
|
|
|
|
* foundation for higher-level application classes such as
|
|
|
|
* #GtkApplication or #MxApplication. In general, you should not use
|
|
|
|
* this class outside of a higher level framework.
|
|
|
|
*
|
|
|
|
* One of the core features that GApplication 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
|
|
|
|
* <firstterm>primary instance</firstterm>.
|
|
|
|
*
|
|
|
|
* Before using GApplication, you must choose an "application identifier".
|
|
|
|
* The expected form of an application identifier is very close to that of
|
|
|
|
* of a <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface">DBus bus name</ulink>.
|
2010-10-23 20:43:36 +02:00
|
|
|
* Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator".
|
|
|
|
* For details on valid application identifiers, see
|
|
|
|
* g_application_id_is_valid().
|
2010-10-23 02:27:39 +02:00
|
|
|
*
|
|
|
|
* GApplication provides convenient life cycle management by maintaining
|
|
|
|
* a <firstterm>use count</firstterm> for the primary application instance.
|
|
|
|
* The use count can be changed using g_application_hold() and
|
|
|
|
* g_application_release(). If it drops to zero, the application exits.
|
|
|
|
*
|
2010-11-01 01:49:53 +01:00
|
|
|
* GApplication also implements the #GActionGroup interface and lets you
|
|
|
|
* easily export actions by adding them with g_application_set_action_group().
|
|
|
|
* When invoking an action by calling g_action_group_activate_action() on
|
|
|
|
* the application, it is always invoked in the primary instance.
|
|
|
|
*
|
2010-11-03 03:39:58 +01:00
|
|
|
* There is a number of different entry points into a #GApplication:
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem>via 'Activate' (i.e. just starting the application)</listitem>
|
|
|
|
* <listitem>via 'Open' (i.e. opening some files)</listitem>
|
|
|
|
* <listitem>via activating an action</listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* The #GApplication::startup signal lets you handle the application
|
|
|
|
* initialization for all of these in a single place.
|
|
|
|
*
|
2010-10-23 20:43:36 +02:00
|
|
|
* <example id="gapplication-example-open"><title>Opening files with a GApplication</title>
|
|
|
|
* <programlisting>
|
|
|
|
* <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-open.c">
|
|
|
|
* <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
|
|
|
|
* </xi:include>
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2010-11-01 01:49:53 +01:00
|
|
|
*
|
|
|
|
* <example id="gapplication-example-actions"><title>A GApplication with actions</title>
|
|
|
|
* <programlisting>
|
|
|
|
* <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-actions.c">
|
|
|
|
* <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
|
|
|
|
* </xi:include>
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2010-10-23 00:40:13 +02:00
|
|
|
*/
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
struct _GApplicationPrivate
|
|
|
|
{
|
|
|
|
GApplicationFlags flags;
|
|
|
|
gchar *id;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
GActionGroup *actions;
|
2010-10-06 19:08:26 +02:00
|
|
|
GMainLoop *mainloop;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
guint inactivity_timeout_id;
|
|
|
|
guint inactivity_timeout;
|
|
|
|
guint use_count;
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
guint is_registered : 1;
|
|
|
|
guint is_remote : 1;
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
GHashTable *remote_actions; /* string -> RemoteActionInfo */
|
2010-10-06 19:08:26 +02:00
|
|
|
GApplicationImpl *impl;
|
|
|
|
};
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
PROP_NONE,
|
2010-06-08 04:21:47 +02:00
|
|
|
PROP_APPLICATION_ID,
|
2010-10-06 19:08:26 +02:00
|
|
|
PROP_FLAGS,
|
|
|
|
PROP_IS_REGISTERED,
|
2010-06-16 06:18:09 +02:00
|
|
|
PROP_IS_REMOTE,
|
2010-10-11 17:54:51 +02:00
|
|
|
PROP_INACTIVITY_TIMEOUT,
|
|
|
|
PROP_ACTION_GROUP
|
2010-06-07 19:25:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
SIGNAL_STARTUP,
|
|
|
|
SIGNAL_ACTIVATE,
|
|
|
|
SIGNAL_OPEN,
|
|
|
|
SIGNAL_ACTION,
|
|
|
|
SIGNAL_COMMAND_LINE,
|
|
|
|
NR_SIGNALS
|
2010-06-07 19:25:39 +02:00
|
|
|
};
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static guint g_application_signals[NR_SIGNALS];
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-11 02:05:13 +02:00
|
|
|
static void g_application_action_group_iface_init (GActionGroupInterface *);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
|
|
|
|
g_application_action_group_iface_init))
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* vfunc defaults {{{1 */
|
|
|
|
static void
|
|
|
|
g_application_real_before_emit (GApplication *application,
|
|
|
|
GVariant *platform_data)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
}
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_real_after_emit (GApplication *application,
|
|
|
|
GVariant *platform_data)
|
|
|
|
{
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_real_startup (GApplication *application)
|
|
|
|
{
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_real_activate (GApplication *application)
|
|
|
|
{
|
|
|
|
if (!g_signal_has_handler_pending (application,
|
|
|
|
g_application_signals[SIGNAL_ACTIVATE],
|
2011-01-21 16:52:48 +01:00
|
|
|
0, TRUE) &&
|
|
|
|
G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)
|
2010-10-06 19:08:26 +02:00
|
|
|
{
|
|
|
|
static gboolean warned;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (warned)
|
|
|
|
return;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_warning ("Your application does not implement "
|
|
|
|
"g_application_activate() and has no handlers connected "
|
|
|
|
"to the 'activate' signal. It should do one of these.");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_real_open (GApplication *application,
|
|
|
|
GFile **files,
|
|
|
|
gint n_files,
|
|
|
|
const gchar *hint)
|
|
|
|
{
|
|
|
|
if (!g_signal_has_handler_pending (application,
|
|
|
|
g_application_signals[SIGNAL_OPEN],
|
2011-01-21 16:52:48 +01:00
|
|
|
0, TRUE) &&
|
|
|
|
G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)
|
2010-10-06 19:08:26 +02:00
|
|
|
{
|
|
|
|
static gboolean warned;
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (warned)
|
|
|
|
return;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_warning ("Your application claims to support opening files "
|
|
|
|
"but does not implement g_application_open() and has no "
|
|
|
|
"handlers connected to the 'open' signal.");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
2010-06-16 06:18:09 +02:00
|
|
|
}
|
|
|
|
|
2010-10-09 23:24:09 +02:00
|
|
|
static int
|
|
|
|
g_application_real_command_line (GApplication *application,
|
|
|
|
GApplicationCommandLine *cmdline)
|
|
|
|
{
|
|
|
|
static gboolean warned;
|
|
|
|
|
|
|
|
if (warned)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
g_warning ("Your application claims to support custom command line "
|
|
|
|
"handling but does not implement g_application_command_line() "
|
|
|
|
"and has no handlers connected to the 'command-line' signal.");
|
|
|
|
|
|
|
|
warned = TRUE;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
static gboolean
|
2010-10-19 19:38:00 +02:00
|
|
|
g_application_real_local_command_line (GApplication *application,
|
|
|
|
gchar ***arguments,
|
|
|
|
int *exit_status)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-09 23:24:09 +02:00
|
|
|
if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
|
2010-06-07 19:25:39 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
else
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
gint n_args;
|
|
|
|
|
|
|
|
if (!g_application_register (application, NULL, &error))
|
|
|
|
{
|
|
|
|
g_critical ("%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
*exit_status = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-19 19:38:00 +02:00
|
|
|
n_args = g_strv_length (*arguments);
|
2010-10-06 19:08:26 +02:00
|
|
|
|
2010-10-09 23:24:09 +02:00
|
|
|
if (application->priv->flags & G_APPLICATION_IS_SERVICE)
|
2010-10-06 19:08:26 +02:00
|
|
|
{
|
2010-10-27 15:26:01 +02:00
|
|
|
if ((*exit_status = n_args > 1))
|
2010-10-06 19:08:26 +02:00
|
|
|
{
|
|
|
|
g_printerr ("GApplication service mode takes no arguments.\n");
|
2010-10-09 23:24:09 +02:00
|
|
|
application->priv->flags &= ~G_APPLICATION_IS_SERVICE;
|
2010-10-06 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_args <= 1)
|
|
|
|
{
|
|
|
|
g_application_activate (application);
|
|
|
|
*exit_status = 0;
|
|
|
|
}
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
else
|
2010-10-06 19:08:26 +02:00
|
|
|
{
|
2010-10-09 23:24:09 +02:00
|
|
|
if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN)
|
2010-10-06 19:08:26 +02:00
|
|
|
{
|
|
|
|
g_critical ("This application can not open files.");
|
|
|
|
*exit_status = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GFile **files;
|
|
|
|
gint n_files;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
n_files = n_args - 1;
|
|
|
|
files = g_new (GFile *, n_files);
|
|
|
|
|
|
|
|
for (i = 0; i < n_files; i++)
|
2010-10-19 19:38:00 +02:00
|
|
|
files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
|
2010-10-06 19:08:26 +02:00
|
|
|
|
|
|
|
g_application_open (application, files, n_files, "");
|
|
|
|
|
|
|
|
for (i = 0; i < n_files; i++)
|
|
|
|
g_object_unref (files[i]);
|
|
|
|
g_free (files);
|
|
|
|
|
|
|
|
*exit_status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_real_add_platform_data (GApplication *application,
|
|
|
|
GVariantBuilder *builder)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_real_quit_mainloop (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->mainloop != NULL)
|
|
|
|
g_main_loop_quit (application->priv->mainloop);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_real_run_mainloop (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
if (application->priv->mainloop == NULL)
|
2010-10-06 19:08:26 +02:00
|
|
|
application->priv->mainloop = g_main_loop_new (NULL, FALSE);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
g_main_loop_run (application->priv->mainloop);
|
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* GObject implementation stuff {{{1 */
|
|
|
|
static void
|
2010-10-23 00:32:45 +02:00
|
|
|
g_application_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-06-16 20:17:26 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
GApplication *application = G_APPLICATION (object);
|
2010-06-16 20:17:26 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_APPLICATION_ID:
|
|
|
|
g_application_set_application_id (application,
|
|
|
|
g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_FLAGS:
|
|
|
|
g_application_set_flags (application, g_value_get_flags (value));
|
|
|
|
break;
|
2010-06-16 20:17:26 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
case PROP_INACTIVITY_TIMEOUT:
|
|
|
|
g_application_set_inactivity_timeout (application,
|
|
|
|
g_value_get_uint (value));
|
|
|
|
break;
|
2010-06-16 20:17:26 +02:00
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
case PROP_ACTION_GROUP:
|
|
|
|
g_application_set_action_group (application,
|
|
|
|
g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2010-06-16 20:17:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
/**
|
|
|
|
* g_application_set_action_group:
|
|
|
|
* @application: a #GApplication
|
2010-12-15 11:17:00 +01:00
|
|
|
* @action_group: (allow-none): a #GActionGroup, or %NULL
|
2010-10-11 17:54:51 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_application_set_action_group (GApplication *application,
|
|
|
|
GActionGroup *action_group)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_APPLICATION (application));
|
2010-10-25 20:32:07 +02:00
|
|
|
g_return_if_fail (!application->priv->is_registered);
|
2010-10-11 17:54:51 +02:00
|
|
|
|
|
|
|
if (application->priv->actions != NULL)
|
|
|
|
g_object_unref (application->priv->actions);
|
|
|
|
|
|
|
|
application->priv->actions = action_group;
|
|
|
|
|
|
|
|
if (application->priv->actions != NULL)
|
|
|
|
g_object_ref (application->priv->actions);
|
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
2010-10-23 00:32:45 +02:00
|
|
|
g_application_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
GApplication *application = G_APPLICATION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_APPLICATION_ID:
|
|
|
|
g_value_set_string (value,
|
|
|
|
g_application_get_application_id (application));
|
|
|
|
break;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
case PROP_FLAGS:
|
|
|
|
g_value_set_flags (value,
|
|
|
|
g_application_get_flags (application));
|
|
|
|
break;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
case PROP_IS_REGISTERED:
|
|
|
|
g_value_set_boolean (value,
|
|
|
|
g_application_get_is_registered (application));
|
|
|
|
break;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
case PROP_IS_REMOTE:
|
|
|
|
g_value_set_boolean (value,
|
|
|
|
g_application_get_is_remote (application));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_INACTIVITY_TIMEOUT:
|
|
|
|
g_value_set_uint (value,
|
|
|
|
g_application_get_inactivity_timeout (application));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_constructed (GObject *object)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
GApplication *application = G_APPLICATION (object);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_assert (application->priv->id != NULL);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_finalize (GObject *object)
|
2010-06-16 06:18:09 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
GApplication *application = G_APPLICATION (object);
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->impl)
|
|
|
|
g_application_impl_destroy (application->priv->impl);
|
|
|
|
g_free (application->priv->id);
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->mainloop)
|
|
|
|
g_main_loop_unref (application->priv->mainloop);
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
G_OBJECT_CLASS (g_application_parent_class)
|
|
|
|
->finalize (object);
|
2010-06-16 06:18:09 +02:00
|
|
|
}
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
static void
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_init (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
|
|
|
|
G_TYPE_APPLICATION,
|
|
|
|
GApplicationPrivate);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static void
|
|
|
|
g_application_class_init (GApplicationClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
object_class->constructed = g_application_constructed;
|
|
|
|
object_class->finalize = g_application_finalize;
|
|
|
|
object_class->get_property = g_application_get_property;
|
|
|
|
object_class->set_property = g_application_set_property;
|
|
|
|
|
|
|
|
class->before_emit = g_application_real_before_emit;
|
|
|
|
class->after_emit = g_application_real_after_emit;
|
|
|
|
class->startup = g_application_real_startup;
|
|
|
|
class->activate = g_application_real_activate;
|
|
|
|
class->open = g_application_real_open;
|
2010-10-09 23:24:09 +02:00
|
|
|
class->command_line = g_application_real_command_line;
|
2010-10-06 19:08:26 +02:00
|
|
|
class->local_command_line = g_application_real_local_command_line;
|
|
|
|
class->add_platform_data = g_application_real_add_platform_data;
|
|
|
|
class->quit_mainloop = g_application_real_quit_mainloop;
|
|
|
|
class->run_mainloop = g_application_real_run_mainloop;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_APPLICATION_ID,
|
2010-10-23 00:40:13 +02:00
|
|
|
g_param_spec_string ("application-id",
|
|
|
|
P_("Application identifier"),
|
|
|
|
P_("The unique identifier for the application"),
|
2010-10-06 19:08:26 +02:00
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_FLAGS,
|
2010-10-23 00:40:13 +02:00
|
|
|
g_param_spec_flags ("flags",
|
|
|
|
P_("Application flags"),
|
|
|
|
P_("Flags specifying the behaviour of the application"),
|
|
|
|
G_TYPE_APPLICATION_FLAGS, G_APPLICATION_FLAGS_NONE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-10-06 19:08:26 +02:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_IS_REGISTERED,
|
2010-10-23 00:40:13 +02:00
|
|
|
g_param_spec_boolean ("is-registered",
|
|
|
|
P_("Is registered"),
|
|
|
|
P_("If g_application_register() has been called"),
|
2010-10-06 19:08:26 +02:00
|
|
|
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_IS_REMOTE,
|
2010-10-23 00:40:13 +02:00
|
|
|
g_param_spec_boolean ("is-remote",
|
|
|
|
P_("Is remote"),
|
|
|
|
P_("If this application instance is remote"),
|
2010-10-06 19:08:26 +02:00
|
|
|
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-10-06 20:05:40 +02:00
|
|
|
g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
|
2010-10-23 14:04:28 +02:00
|
|
|
g_param_spec_uint ("inactivity-timeout",
|
|
|
|
P_("Inactivity timeout"),
|
|
|
|
P_("Iime (ms) to stay alive after becoming idle"),
|
|
|
|
0, G_MAXUINT, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-10-06 20:05:40 +02:00
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
g_object_class_install_property (object_class, PROP_ACTION_GROUP,
|
2010-10-23 00:40:13 +02:00
|
|
|
g_param_spec_object ("action-group",
|
|
|
|
P_("Action group"),
|
|
|
|
P_("The group of actions that the application exports"),
|
2010-10-11 17:54:51 +02:00
|
|
|
G_TYPE_ACTION_GROUP,
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
2010-10-06 19:08:26 +02:00
|
|
|
|
2010-10-23 00:40:13 +02:00
|
|
|
/**
|
|
|
|
* GApplication::startup:
|
|
|
|
* @application: the application
|
|
|
|
*
|
|
|
|
* The ::startup signal is emitted on the primary instance immediately
|
|
|
|
* after registration. See g_activation_register().
|
|
|
|
*/
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_signals[SIGNAL_STARTUP] =
|
|
|
|
g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GApplicationClass, startup),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
|
2010-10-23 00:40:13 +02:00
|
|
|
/**
|
|
|
|
* GApplication::activate:
|
|
|
|
* @application: the application
|
|
|
|
*
|
|
|
|
* The ::activate signal is emitted on the primary instance when an
|
|
|
|
* activation occurs. See g_application_activate().
|
|
|
|
*/
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_signals[SIGNAL_ACTIVATE] =
|
|
|
|
g_signal_new ("activate", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GApplicationClass, activate),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
|
2010-10-23 00:40:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GApplication::open:
|
|
|
|
* @application: the application
|
2010-12-15 11:17:00 +01:00
|
|
|
* @files: (array length=n_files) (element-type GFile): an array of #GFiles
|
2010-10-23 00:40:13 +02:00
|
|
|
* @n_files: the length of @files
|
|
|
|
* @hint: a hint provided by the calling instance
|
|
|
|
*
|
|
|
|
* The ::open signal is emitted on the primary instance when there are
|
|
|
|
* files to open. See g_application_open() for more information.
|
|
|
|
*/
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_signals[SIGNAL_OPEN] =
|
|
|
|
g_signal_new ("open", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GApplicationClass, open),
|
|
|
|
NULL, NULL, _gio_marshal_VOID__POINTER_INT_STRING,
|
|
|
|
G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);
|
|
|
|
|
2010-10-23 00:40:13 +02:00
|
|
|
/**
|
|
|
|
* GApplication::command-line:
|
|
|
|
* @application: the application
|
|
|
|
* @command_line: a #GApplicationCommandLine representing the
|
|
|
|
* passed commandline
|
|
|
|
*
|
|
|
|
* The ::command-line signal is emitted on the primary instance when
|
|
|
|
* a commandline is not handled locally. See g_application_run() for
|
|
|
|
* more information.
|
|
|
|
*/
|
2010-10-09 23:24:09 +02:00
|
|
|
g_application_signals[SIGNAL_COMMAND_LINE] =
|
|
|
|
g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GApplicationClass, command_line),
|
2010-10-13 03:42:59 +02:00
|
|
|
g_signal_accumulator_first_wins, NULL,
|
|
|
|
_gio_marshal_INT__OBJECT,
|
2010-10-09 23:24:09 +02:00
|
|
|
G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_type_class_add_private (class, sizeof (GApplicationPrivate));
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
static GVariant *
|
|
|
|
get_platform_data (GApplication *application)
|
|
|
|
{
|
|
|
|
GVariantBuilder *builder;
|
|
|
|
GVariant *result;
|
|
|
|
|
|
|
|
builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
|
|
|
|
|
|
|
|
{
|
|
|
|
gchar *cwd = g_get_current_dir ();
|
|
|
|
g_variant_builder_add (builder, "{sv}", "cwd",
|
|
|
|
g_variant_new_bytestring (cwd));
|
|
|
|
g_free (cwd);
|
|
|
|
}
|
|
|
|
|
2010-10-29 04:49:12 +02:00
|
|
|
if (application->priv->flags & G_APPLICATION_SEND_ENVIRONMENT)
|
|
|
|
{
|
2010-10-29 22:33:47 +02:00
|
|
|
GVariant *array;
|
|
|
|
gchar **envp;
|
|
|
|
|
|
|
|
envp = g_get_environ ();
|
|
|
|
array = g_variant_new_bytestring_array ((const gchar **) envp, -1);
|
2010-10-29 04:49:12 +02:00
|
|
|
g_strfreev (envp);
|
2010-10-29 22:33:47 +02:00
|
|
|
|
|
|
|
g_variant_builder_add (builder, "{sv}", "environ", array);
|
2010-10-29 04:49:12 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
G_APPLICATION_GET_CLASS (application)->
|
|
|
|
add_platform_data (application, builder);
|
|
|
|
|
|
|
|
result = g_variant_builder_end (builder);
|
|
|
|
g_variant_builder_unref (builder);
|
|
|
|
|
|
|
|
return result;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Application ID validity {{{1 */
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_id_is_valid:
|
|
|
|
* @application_id: a potential application identifier
|
|
|
|
* @returns: %TRUE if @application_id is valid
|
|
|
|
*
|
2010-10-23 20:43:36 +02:00
|
|
|
* Checks if @application_id is a valid application identifier.
|
|
|
|
*
|
|
|
|
* A valid ID is required for calls to g_application_new() and
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_set_application_id().
|
2010-10-23 20:43:36 +02:00
|
|
|
*
|
|
|
|
* 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>
|
2010-10-06 19:08:26 +02:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_application_id_is_valid (const gchar *application_id)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
gboolean allow_dot;
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (strlen (application_id) > 255)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!g_ascii_isalpha (*application_id))
|
|
|
|
return FALSE;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
application_id++;
|
|
|
|
allow_dot = FALSE;
|
|
|
|
for (; *application_id; application_id++)
|
2010-06-16 06:18:09 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
if (g_ascii_isalnum (*application_id) ||
|
|
|
|
(*application_id == '-') ||
|
|
|
|
(*application_id == '_'))
|
|
|
|
allow_dot = TRUE;
|
|
|
|
else if (allow_dot && *application_id == '.')
|
|
|
|
allow_dot = FALSE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2010-06-16 06:18:09 +02:00
|
|
|
}
|
2010-10-06 19:08:26 +02:00
|
|
|
|
|
|
|
return TRUE;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
2010-10-23 00:32:45 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Public Constructor {{{1 */
|
2010-06-07 19:25:39 +02:00
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_new:
|
|
|
|
* @application_id: the application id
|
|
|
|
* @flags: the application flags
|
|
|
|
* @returns: a new #GApplication instance
|
2010-06-08 05:27:21 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Creates a new #GApplication instance.
|
2010-06-16 06:18:09 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* This function calls g_type_init() for you.
|
2010-06-16 06:18:09 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* The application id must be valid. See g_application_id_is_valid().
|
|
|
|
**/
|
2010-06-16 06:18:09 +02:00
|
|
|
GApplication *
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_new (const gchar *application_id,
|
|
|
|
GApplicationFlags flags)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-16 06:18:09 +02:00
|
|
|
g_type_init ();
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return g_object_new (G_TYPE_APPLICATION,
|
|
|
|
"application-id", application_id,
|
|
|
|
"flags", flags,
|
|
|
|
NULL);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Simple get/set: application id, flags, inactivity timeout {{{1 */
|
2010-06-07 19:25:39 +02:00
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_get_application_id:
|
|
|
|
* @application: a #GApplication
|
|
|
|
* @returns: the identifier for @application, owned by @application
|
2010-06-16 06:18:09 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Gets the unique identifier for @application.
|
2010-06-16 06:18:09 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
const gchar *
|
|
|
|
g_application_get_application_id (GApplication *application)
|
2010-06-16 06:18:09 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_val_if_fail (G_IS_APPLICATION (application), NULL);
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return application->priv->id;
|
2010-06-16 06:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_set_application_id:
|
2010-06-17 22:07:52 +02:00
|
|
|
* @application: a #GApplication
|
2010-10-06 19:08:26 +02:00
|
|
|
* @application_id: the identifier for @application
|
2010-06-17 22:07:52 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Sets the unique identifier for @application.
|
2010-06-18 20:19:57 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* The application id can only be modified if @application has not yet
|
|
|
|
* been registered.
|
2010-06-16 06:18:09 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* The application id must be valid. See g_application_id_is_valid().
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_application_set_application_id (GApplication *application,
|
|
|
|
const gchar *application_id)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_if_fail (G_IS_APPLICATION (application));
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (g_strcmp0 (application->priv->id, application_id) != 0)
|
|
|
|
{
|
|
|
|
g_return_if_fail (g_application_id_is_valid (application_id));
|
|
|
|
g_return_if_fail (!application->priv->is_registered);
|
2010-06-17 22:07:52 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_free (application->priv->id);
|
|
|
|
application->priv->id = g_strdup (application_id);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (application), "application-id");
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_get_flags:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
2010-10-06 19:08:26 +02:00
|
|
|
* @returns: the flags for @application
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Gets the flags for @application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* See #GApplicationFlags.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
GApplicationFlags
|
|
|
|
g_application_get_flags (GApplication *application)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_APPLICATION (application), 0);
|
|
|
|
|
|
|
|
return application->priv->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_application_set_flags:
|
|
|
|
* @application: a #GApplication
|
|
|
|
* @flags: the flags for @application
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Sets the flags for @application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* The flags can only be modified if @application has not yet been
|
|
|
|
* registered.
|
|
|
|
*
|
|
|
|
* See #GApplicationFlags.
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
2010-06-07 19:25:39 +02:00
|
|
|
void
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_set_flags (GApplication *application,
|
|
|
|
GApplicationFlags flags)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_APPLICATION (application));
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->flags != flags)
|
|
|
|
{
|
|
|
|
g_return_if_fail (!application->priv->is_registered);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
application->priv->flags = flags;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_object_notify (G_OBJECT (application), "flags");
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_get_inactivity_timeout:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Gets the current inactivity timeout for the application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* This is the amount of time (in milliseconds) after the last call to
|
|
|
|
* g_application_release() before the application stops running.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Returns: the timeout, in milliseconds
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
guint
|
|
|
|
g_application_get_inactivity_timeout (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_val_if_fail (G_IS_APPLICATION (application), 0);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return application->priv->inactivity_timeout;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_set_inactivity_timeout:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
2010-10-06 19:08:26 +02:00
|
|
|
* @inactivity_timeout: the timeout, in milliseconds
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Sets the current inactivity timeout for the application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* This is the amount of time (in milliseconds) after the last call to
|
|
|
|
* g_application_release() before the application stops running.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* 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.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Returns: the timeout, in milliseconds
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
2010-06-07 19:25:39 +02:00
|
|
|
void
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_set_inactivity_timeout (GApplication *application,
|
|
|
|
guint inactivity_timeout)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_APPLICATION (application));
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->inactivity_timeout != inactivity_timeout)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
application->priv->inactivity_timeout = inactivity_timeout;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_object_notify (G_OBJECT (application), "inactivity-timeout");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Read-only property getters (is registered, is remote) {{{1 */
|
|
|
|
/**
|
|
|
|
* g_application_get_is_registered:
|
|
|
|
* @application: a #GApplication
|
|
|
|
* @returns: %TRUE if @application is registered
|
|
|
|
*
|
|
|
|
* Checks if @application is registered.
|
|
|
|
*
|
|
|
|
* An application is registered if g_application_register() has been
|
|
|
|
* successfully called.
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_application_get_is_registered (GApplication *application)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
|
2010-06-16 06:18:09 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return application->priv->is_registered;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_get_is_remote:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
2010-10-06 19:08:26 +02:00
|
|
|
* @returns: %TRUE if @application is remote
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Checks if @application is remote.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* 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.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* The value of this property can not be accessed before
|
|
|
|
* g_application_register() has been called. See
|
|
|
|
* g_application_get_is_registered().
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_application_get_is_remote (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
|
|
|
|
g_return_val_if_fail (application->priv->is_registered, FALSE);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return application->priv->is_remote;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Register {{{1 */
|
2010-06-07 19:25:39 +02:00
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_register:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
2010-10-06 19:08:26 +02:00
|
|
|
* @cancellable: a #GCancellable, or %NULL
|
|
|
|
* @error: a pointer to a NULL #GError, or %NULL
|
|
|
|
* @returns: %TRUE if registration succeeded
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Attempts registration of the application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* 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.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* If the application has already been registered then %TRUE is
|
|
|
|
* returned with no work performed.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 20:43:36 +02:00
|
|
|
* The #GApplication::startup signal is emitted if registration succeeds
|
2010-10-06 19:08:26 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_application_register (GApplication *application,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (!application->priv->is_registered)
|
|
|
|
{
|
|
|
|
application->priv->impl =
|
|
|
|
g_application_impl_register (application, application->priv->id,
|
|
|
|
application->priv->flags,
|
2010-10-25 20:32:07 +02:00
|
|
|
&application->priv->remote_actions,
|
|
|
|
cancellable, error);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->impl == NULL)
|
|
|
|
return FALSE;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
application->priv->is_remote = application->priv->remote_actions != NULL;
|
2010-10-06 19:08:26 +02:00
|
|
|
application->priv->is_registered = TRUE;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (application), "is-registered");
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (!application->priv->is_remote)
|
2010-10-06 19:08:26 +02:00
|
|
|
g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hold/release {{{1 */
|
2010-06-07 19:25:39 +02:00
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_hold:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Increases the use count of @application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Use this function to indicate that the application has a reason to
|
2010-10-23 02:27:39 +02:00
|
|
|
* continue to run. For example, g_application_hold() is called by GTK+
|
2010-10-06 19:08:26 +02:00
|
|
|
* when a toplevel window is on the screen.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* To cancel the hold, call g_application_release().
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_application_hold (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->inactivity_timeout_id)
|
|
|
|
{
|
|
|
|
g_source_remove (application->priv->inactivity_timeout_id);
|
|
|
|
application->priv->inactivity_timeout_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
application->priv->use_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
inactivity_timeout_expired (gpointer data)
|
|
|
|
{
|
|
|
|
GApplication *application = G_APPLICATION (data);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
G_APPLICATION_GET_CLASS (application)
|
|
|
|
->quit_mainloop (application);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return FALSE;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_release:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Decrease the use count of @application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* When the use count reaches zero, the application will stop running.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Never call this function except to cancel the effect of a previous
|
|
|
|
* call to g_application_hold().
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_application_release (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
application->priv->use_count--;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->use_count == 0)
|
|
|
|
{
|
|
|
|
if (application->priv->inactivity_timeout)
|
|
|
|
application->priv->inactivity_timeout_id =
|
|
|
|
g_timeout_add (application->priv->inactivity_timeout,
|
|
|
|
inactivity_timeout_expired, application);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
else
|
|
|
|
G_APPLICATION_GET_CLASS (application)
|
|
|
|
->quit_mainloop (application);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Activate, Open {{{1 */
|
2010-06-07 19:25:39 +02:00
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_activate:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Activates the application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 20:43:36 +02:00
|
|
|
* In essence, this results in the #GApplication::activate() signal being
|
|
|
|
* emitted in the primary instance.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* The application must be registered before calling this function.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Since: 2.28
|
|
|
|
**/
|
2010-06-07 19:25:39 +02:00
|
|
|
void
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_activate (GApplication *application)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_APPLICATION (application));
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_if_fail (application->priv->is_registered);
|
|
|
|
|
|
|
|
if (application->priv->is_remote)
|
|
|
|
g_application_impl_activate (application->priv->impl,
|
|
|
|
get_platform_data (application));
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
else
|
|
|
|
g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_open:
|
2010-06-07 19:25:39 +02:00
|
|
|
* @application: a #GApplication
|
2010-12-15 11:17:00 +01:00
|
|
|
* @files: (array length=n_files): an array of #GFiles to open
|
2010-10-06 19:08:26 +02:00
|
|
|
* @n_files: the length of the @files array
|
|
|
|
* @hint: a hint (or ""), but never %NULL
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Opens the given files.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 20:43:36 +02:00
|
|
|
* In essence, this results in the #GApplication::open signal being emitted
|
2010-10-06 19:08:26 +02:00
|
|
|
* in the primary instance.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* @n_files must be greater than zero.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 20:43:36 +02:00
|
|
|
* @hint is simply passed through to the ::open signal. It is
|
2010-10-06 19:08:26 +02:00
|
|
|
* 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 "".
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 20:43:36 +02:00
|
|
|
* The application must be registered before calling this function
|
|
|
|
* and it must have the %G_APPLICATION_HANDLES_OPEN flag set.
|
2010-10-06 19:08:26 +02:00
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_application_open (GApplication *application,
|
|
|
|
GFile **files,
|
|
|
|
gint n_files,
|
|
|
|
const gchar *hint)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_if_fail (G_IS_APPLICATION (application));
|
|
|
|
g_return_if_fail (application->priv->flags &
|
2010-10-09 23:24:09 +02:00
|
|
|
G_APPLICATION_HANDLES_OPEN);
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_if_fail (application->priv->is_registered);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
if (application->priv->is_remote)
|
2010-10-06 19:08:26 +02:00
|
|
|
g_application_impl_open (application->priv->impl,
|
|
|
|
files, n_files, hint,
|
|
|
|
get_platform_data (application));
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
else
|
|
|
|
g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
|
|
|
|
0, files, n_files, hint);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Run {{{1 */
|
2010-06-07 19:25:39 +02:00
|
|
|
/**
|
2010-10-06 19:08:26 +02:00
|
|
|
* g_application_run:
|
|
|
|
* @application: a #GApplication
|
|
|
|
* @argc: the argc from main()
|
2010-12-15 11:17:00 +01:00
|
|
|
* @argv: (array length=argc): the argv from main()
|
2010-10-06 19:08:26 +02:00
|
|
|
* @returns: the exit status
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Runs the application.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* This function is intended to be run from main() and its return value
|
|
|
|
* is intended to be returned by main().
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 11:54:50 +02:00
|
|
|
* First, the local_command_line() virtual function is invoked. This
|
2010-10-06 19:08:26 +02:00
|
|
|
* function always runs on the local instance. If that function returns
|
2010-10-23 00:40:13 +02:00
|
|
|
* %FALSE then the application is registered and the #GApplication::command-line
|
|
|
|
* signal is emitted in the primary instance (which may or may not be
|
|
|
|
* this instance).
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 00:40:13 +02:00
|
|
|
* If the application has the %G_APPLICATION_HANDLES_COMMAND_LINE
|
2010-10-23 11:54:50 +02:00
|
|
|
* flag set then the default implementation of local_command_line()
|
2010-10-06 19:08:26 +02:00
|
|
|
* always returns %FALSE immediately, resulting in the commandline
|
|
|
|
* always being handled in the primary instance.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-23 11:54:50 +02:00
|
|
|
* Otherwise, the default implementation of local_command_line() tries
|
2010-10-23 00:32:45 +02:00
|
|
|
* to do a couple of things that are probably reasonable for most
|
2010-10-06 19:08:26 +02:00
|
|
|
* 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
|
2010-10-23 00:40:13 +02:00
|
|
|
* given and the %G_APPLICATION_HANDLES_OPEN flag is set then they
|
2010-10-06 19:08:26 +02:00
|
|
|
* are assumed to be filenames and g_application_open() is called.
|
2010-06-07 19:25:39 +02:00
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* If you are interested in doing more complicated local handling of the
|
2010-10-23 11:54:50 +02:00
|
|
|
* commandline then you should implement your own #GApplication subclass
|
|
|
|
* and override local_command_line(). See
|
|
|
|
* <xref linkend="gapplication-example-cmdline2"/> for an example.
|
2010-10-06 19:08:26 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2010-10-23 00:40:13 +02:00
|
|
|
* If the %G_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 <emphasis>service</emphasis> to others).
|
|
|
|
*
|
2010-10-06 19:08:26 +02:00
|
|
|
* Since: 2.28
|
|
|
|
**/
|
|
|
|
int
|
|
|
|
g_application_run (GApplication *application,
|
|
|
|
int argc,
|
|
|
|
char **argv)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-19 19:38:00 +02:00
|
|
|
gchar **arguments;
|
2010-10-06 19:08:26 +02:00
|
|
|
int status;
|
2010-10-19 19:38:00 +02:00
|
|
|
gint i;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
g_return_val_if_fail (G_IS_APPLICATION (application), 1);
|
2010-10-19 19:38:00 +02:00
|
|
|
g_return_val_if_fail (argc == 0 || argv != NULL, 1);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-19 19:38:00 +02:00
|
|
|
arguments = g_new (gchar *, argc + 1);
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
arguments[i] = g_strdup (argv[i]);
|
|
|
|
arguments[i] = NULL;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-19 19:38:00 +02:00
|
|
|
if (g_get_prgname () == NULL && argc > 0)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
gchar *prgname;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-19 19:38:00 +02:00
|
|
|
prgname = g_path_get_basename (argv[0]);
|
2010-10-06 19:08:26 +02:00
|
|
|
g_set_prgname (prgname);
|
|
|
|
g_free (prgname);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (!G_APPLICATION_GET_CLASS (application)
|
|
|
|
->local_command_line (application, &arguments, &status))
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-09 23:24:09 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (!g_application_register (application, NULL, &error))
|
|
|
|
{
|
|
|
|
g_printerr ("%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (application->priv->is_remote)
|
|
|
|
{
|
|
|
|
GVariant *platform_data;
|
|
|
|
|
|
|
|
platform_data = get_platform_data (application);
|
|
|
|
status = g_application_impl_command_line (application->priv->impl,
|
|
|
|
arguments, platform_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GApplicationCommandLine *cmdline;
|
2010-10-21 14:02:41 +02:00
|
|
|
GVariant *v;
|
2010-10-09 23:24:09 +02:00
|
|
|
|
2010-10-21 14:02:41 +02:00
|
|
|
v = g_variant_new_bytestring_array ((const gchar **) arguments, -1);
|
2010-10-09 23:24:09 +02:00
|
|
|
cmdline = g_object_new (G_TYPE_APPLICATION_COMMAND_LINE,
|
2010-10-21 14:02:41 +02:00
|
|
|
"arguments", v, NULL);
|
2010-10-09 23:24:09 +02:00
|
|
|
g_signal_emit (application,
|
|
|
|
g_application_signals[SIGNAL_COMMAND_LINE],
|
|
|
|
0, cmdline, &status);
|
|
|
|
g_object_unref (cmdline);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-19 19:38:00 +02:00
|
|
|
g_strfreev (arguments);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-09 23:24:09 +02:00
|
|
|
if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
|
2010-10-23 14:04:28 +02:00
|
|
|
application->priv->is_registered &&
|
2010-10-06 20:05:40 +02:00
|
|
|
!application->priv->use_count &&
|
|
|
|
!application->priv->inactivity_timeout_id)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-10-06 20:05:40 +02:00
|
|
|
application->priv->inactivity_timeout_id =
|
|
|
|
g_timeout_add (10000, inactivity_timeout_expired, application);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 20:05:40 +02:00
|
|
|
if (application->priv->use_count ||
|
|
|
|
application->priv->inactivity_timeout_id)
|
|
|
|
{
|
2010-10-06 19:08:26 +02:00
|
|
|
G_APPLICATION_GET_CLASS (application)
|
|
|
|
->run_mainloop (application);
|
|
|
|
status = 0;
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
if (application->priv->impl)
|
|
|
|
g_application_impl_flush (application->priv->impl);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
return status;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-10-11 02:05:13 +02:00
|
|
|
static gboolean
|
|
|
|
g_application_has_action (GActionGroup *action_group,
|
|
|
|
const gchar *action_name)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_val_if_fail (application->priv->is_registered, FALSE);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->remote_actions != NULL)
|
|
|
|
return g_hash_table_lookup (application->priv->remote_actions,
|
|
|
|
action_name) != NULL;
|
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
return application->priv->actions &&
|
|
|
|
g_action_group_has_action (application->priv->actions, action_name);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar **
|
|
|
|
g_application_list_actions (GActionGroup *action_group)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_val_if_fail (application->priv->is_registered, NULL);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->remote_actions != NULL)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gint n, i = 0;
|
|
|
|
gchar **keys;
|
|
|
|
gpointer key;
|
|
|
|
|
|
|
|
n = g_hash_table_size (application->priv->remote_actions);
|
|
|
|
keys = g_new (gchar *, n + 1);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, application->priv->remote_actions);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, NULL))
|
|
|
|
keys[i++] = g_strdup (key);
|
|
|
|
g_assert_cmpint (i, ==, n);
|
|
|
|
keys[n] = NULL;
|
|
|
|
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (application->priv->actions != NULL)
|
2010-10-11 17:54:51 +02:00
|
|
|
return g_action_group_list_actions (application->priv->actions);
|
|
|
|
|
|
|
|
else
|
|
|
|
/* empty string array */
|
|
|
|
return g_new0 (gchar *, 1);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_application_get_action_enabled (GActionGroup *action_group,
|
|
|
|
const gchar *action_name)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_val_if_fail (application->priv->actions != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (application->priv->is_registered, FALSE);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->remote_actions)
|
|
|
|
{
|
|
|
|
RemoteActionInfo *info;
|
|
|
|
|
|
|
|
info = g_hash_table_lookup (application->priv->remote_actions,
|
|
|
|
action_name);
|
|
|
|
|
|
|
|
return info && info->enabled;
|
|
|
|
}
|
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
return g_action_group_get_action_enabled (application->priv->actions,
|
|
|
|
action_name);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GVariantType *
|
|
|
|
g_application_get_action_parameter_type (GActionGroup *action_group,
|
|
|
|
const gchar *action_name)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_val_if_fail (application->priv->actions != NULL, NULL);
|
|
|
|
g_return_val_if_fail (application->priv->is_registered, NULL);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->remote_actions)
|
|
|
|
{
|
|
|
|
RemoteActionInfo *info;
|
|
|
|
|
|
|
|
info = g_hash_table_lookup (application->priv->remote_actions,
|
|
|
|
action_name);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
return info->parameter_type;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
return g_action_group_get_action_parameter_type (application->priv->actions,
|
|
|
|
action_name);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GVariantType *
|
|
|
|
g_application_get_action_state_type (GActionGroup *action_group,
|
|
|
|
const gchar *action_name)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_val_if_fail (application->priv->actions != NULL, NULL);
|
|
|
|
g_return_val_if_fail (application->priv->is_registered, NULL);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->remote_actions)
|
|
|
|
{
|
|
|
|
RemoteActionInfo *info;
|
2010-10-11 02:05:13 +02:00
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
info = g_hash_table_lookup (application->priv->remote_actions,
|
|
|
|
action_name);
|
2010-10-11 17:54:51 +02:00
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (info && info->state)
|
|
|
|
return g_variant_get_type (info->state);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-11 17:54:51 +02:00
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
return g_action_group_get_action_state_type (application->priv->actions,
|
2010-10-11 17:54:51 +02:00
|
|
|
action_name);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
g_application_get_action_state (GActionGroup *action_group,
|
|
|
|
const gchar *action_name)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_val_if_fail (application->priv->actions != NULL, NULL);
|
|
|
|
g_return_val_if_fail (application->priv->is_registered, NULL);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->remote_actions)
|
|
|
|
{
|
|
|
|
RemoteActionInfo *info;
|
|
|
|
|
|
|
|
info = g_hash_table_lookup (application->priv->remote_actions,
|
|
|
|
action_name);
|
|
|
|
|
|
|
|
if (info && info->state)
|
|
|
|
return g_variant_ref (info->state);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-11 17:54:51 +02:00
|
|
|
return g_action_group_get_action_state (application->priv->actions,
|
|
|
|
action_name);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_application_change_action_state (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_if_fail (application->priv->is_registered);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->is_remote)
|
|
|
|
g_application_impl_change_action_state (application->priv->impl,
|
|
|
|
action_name, value,
|
|
|
|
get_platform_data (application));
|
|
|
|
|
|
|
|
else
|
|
|
|
g_action_group_change_action_state (application->priv->actions,
|
|
|
|
action_name, value);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_application_activate_action (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *parameter)
|
|
|
|
{
|
2010-10-11 17:54:51 +02:00
|
|
|
GApplication *application = G_APPLICATION (action_group);
|
|
|
|
|
|
|
|
g_return_if_fail (application->priv->is_registered);
|
|
|
|
|
2010-10-25 20:32:07 +02:00
|
|
|
if (application->priv->is_remote)
|
|
|
|
g_application_impl_activate_action (application->priv->impl,
|
|
|
|
action_name, parameter,
|
|
|
|
get_platform_data (application));
|
|
|
|
|
|
|
|
else
|
|
|
|
g_action_group_activate_action (application->priv->actions,
|
|
|
|
action_name, parameter);
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_application_action_group_iface_init (GActionGroupInterface *iface)
|
|
|
|
{
|
|
|
|
iface->has_action = g_application_has_action;
|
|
|
|
iface->list_actions = g_application_list_actions;
|
|
|
|
|
2010-10-11 16:45:51 +02:00
|
|
|
iface->get_action_enabled = g_application_get_action_enabled;
|
|
|
|
iface->get_action_parameter_type = g_application_get_action_parameter_type;
|
|
|
|
iface->get_action_state_type = g_application_get_action_state_type;
|
|
|
|
iface->get_action_state = g_application_get_action_state;
|
|
|
|
iface->change_action_state = g_application_change_action_state;
|
|
|
|
iface->activate_action = g_application_activate_action;
|
2010-10-11 02:05:13 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:08:26 +02:00
|
|
|
/* Epilogue {{{1 */
|
|
|
|
/* vim:set foldmethod=marker: */
|