[glib/application] add signals to GApplication
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/application] add signals to GApplication
- Date: Wed, 11 Aug 2010 02:50:05 +0000 (UTC)
commit 52fa2c1090c4f05cf560b7e5459931b743149550
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Aug 10 22:49:05 2010 -0400
add signals to GApplication
gio/gapplication.c | 182 ++++++++++++++++++++++++++++++++++----------------
gio/gio-marshal.list | 3 +
2 files changed, 127 insertions(+), 58 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index ccb466a..42f8528 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -1,6 +1,31 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ * Copyright © 2010 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ * Colin Walters <walters verbum org>
+ * Emmanuele Bassi <ebassi linux intel com>
+ */
+
#include "gapplication.h"
#include "string.h"
#include "gapplicationcommandline.h"
+#include "gio-marshal.h"
#include "gioenums.h"
#include "gioenumtypes.h"
#include "gfile.h"
@@ -43,29 +68,29 @@ void g_application_command_line_setup_remote (GApplicationCommandLine *,
#include "gapplicationimpl-null.c"
#endif
-typedef struct {
- gchar *name;
- gchar *description;
-
+typedef struct
+{
+ gchar *name;
+ gchar *description;
GVariantType *type;
- gboolean enabled;
+ gboolean enabled;
} GApplicationAction;
struct _GApplicationPrivate
{
- GApplicationFlags flags;
- gchar *id;
+ GApplicationFlags flags;
+ gchar *id;
- GHashTable *actions; /* string -> GApplicationAction */
- GMainLoop *mainloop;
+ GHashTable *actions; /* string -> GApplicationAction */
+ GMainLoop *mainloop;
- guint inactivity_timeout;
- guint use_count;
+ guint inactivity_timeout;
+ guint use_count;
- guint is_registered : 1;
- guint is_remote : 1;
+ guint is_registered : 1;
+ guint is_remote : 1;
- GApplicationImpl impl;
+ GApplicationImpl impl;
};
enum
@@ -77,6 +102,18 @@ enum
PROP_IS_REMOTE
};
+enum
+{
+ SIGNAL_STARTUP,
+ SIGNAL_ACTIVATE,
+ SIGNAL_OPEN,
+ SIGNAL_ACTION,
+ SIGNAL_COMMAND_LINE,
+ NR_SIGNALS
+};
+
+static guint g_application_signals[NR_SIGNALS];
+
G_DEFINE_TYPE (GApplication, g_application, G_TYPE_OBJECT)
static void
@@ -188,16 +225,14 @@ g_application_real_handle_command_line (GApplication *application,
void
g_application_real_emit_startup (GApplication *application)
{
- G_APPLICATION_GET_CLASS (application)
- ->startup (application);
+ g_signal_emit (application, g_application_signals[SIGNAL_STARTUP], 0);
}
static void
g_application_real_emit_activate (GApplication *application,
GVariant *platform_data)
{
- G_APPLICATION_GET_CLASS (application)
- ->activate (application);
+ g_application_activate (application);
}
static void
@@ -207,8 +242,7 @@ g_application_real_emit_open (GApplication *application,
const gchar *hint,
GVariant *platform_data)
{
- G_APPLICATION_GET_CLASS (application)
- ->open (application, files, n_files, hint);
+ g_application_open (application, files, n_files, hint);
}
static void
@@ -217,8 +251,7 @@ g_application_real_emit_action (GApplication *application,
GVariant *parameters,
GVariant *platform_data)
{
- G_APPLICATION_GET_CLASS (application)
- ->action (application, action_name, parameters);
+ g_application_action (application, action_name, parameters);
}
static GApplicationCommandLine *
@@ -236,8 +269,12 @@ static int
g_application_real_emit_command_line (GApplication *application,
GApplicationCommandLine *command_line)
{
- return G_APPLICATION_GET_CLASS (application)
- ->command_line (application, command_line);
+ int status;
+
+ g_signal_emit (application, g_application_signals[SIGNAL_COMMAND_LINE],
+ 0, command_line, &status);
+
+ return status;
}
void
@@ -395,6 +432,35 @@ g_application_class_init (GApplicationClass *class)
"If this application instance is remote",
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ 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);
+
+ 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);
+
+ 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);
+
+ g_application_signals[SIGNAL_ACTION] =
+ g_signal_new ("action", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, action),
+ NULL, NULL, _gio_marshal_VOID__STRING_VARIANT,
+ G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VARIANT);
+
+ g_application_signals[SIGNAL_COMMAND_LINE] =
+ g_signal_new ("command-line", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GApplicationClass, command_line),
+ NULL, NULL, _gio_marshal_INT__OBJECT,
+ G_TYPE_INT, 1, G_TYPE_APPLICATION_COMMAND_LINE);
+
g_type_class_add_private (class, sizeof (GApplicationPrivate));
}
@@ -922,34 +988,6 @@ g_application_get_action_description (GApplication *application,
}
/**
- * g_application_activate:
- * @application: a #GApplication
- *
- * Activates the application.
- *
- * In essence, this results in the activate() virtual function being
- * invoked in the primary instance.
- *
- * The application must be registered before calling this function.
- *
- * Since: 2.26
- **/
-void
-g_application_activate (GApplication *application)
-{
- g_return_if_fail (G_IS_APPLICATION (application));
- g_return_if_fail (application->priv->is_registered);
-
- if (application->priv->is_remote)
- g_application_impl_activate (&application->priv->impl,
- get_platform_data (application));
-
- else
- G_APPLICATION_GET_CLASS (application)
- ->emit_activate (application, NULL);
-}
-
-/**
* g_application_hold:
* @application: a #GApplication
*
@@ -995,6 +1033,33 @@ g_application_release (GApplication *application)
}
/**
+ * g_application_activate:
+ * @application: a #GApplication
+ *
+ * Activates the application.
+ *
+ * In essence, this results in the activate() virtual function being
+ * invoked in the primary instance.
+ *
+ * The application must be registered before calling this function.
+ *
+ * Since: 2.26
+ **/
+void
+g_application_activate (GApplication *application)
+{
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (application->priv->is_registered);
+
+ if (application->priv->is_remote)
+ g_application_impl_activate (&application->priv->impl,
+ get_platform_data (application));
+
+ else
+ g_signal_emit (application, g_application_signals[SIGNAL_ACTIVATE], 0);
+}
+
+/**
* g_application_open:
* @application: a #GApplication
* @files: an array of #GFile<!-- -->s to open
@@ -1036,8 +1101,8 @@ g_application_open (GApplication *application,
get_platform_data (application));
else
- G_APPLICATION_GET_CLASS (application)
- ->emit_open (application, files, n_files, hint, NULL);
+ g_signal_emit (application, g_application_signals[SIGNAL_OPEN],
+ 0, files, n_files, hint);
}
/**
@@ -1081,8 +1146,8 @@ g_application_action (GApplication *application,
get_platform_data (application));
else
- G_APPLICATION_GET_CLASS (application)
- ->emit_action (application, action, parameters, NULL);
+ g_signal_emit (application, g_application_signals[SIGNAL_ACTION],
+ 0, action, parameters);
}
/**
@@ -1180,8 +1245,9 @@ g_application_run_with_arguments (GApplication *application,
command_line = G_APPLICATION_GET_CLASS (application)
->create_command_line (application, arguments, NULL);
- status = G_APPLICATION_GET_CLASS (application)
- ->emit_command_line (application, command_line);
+ g_signal_emit (application,
+ g_application_signals[SIGNAL_COMMAND_LINE],
+ 0, command_line, &status);
g_object_unref (command_line);
}
diff --git a/gio/gio-marshal.list b/gio/gio-marshal.list
index c75d5c4..4db6b19 100644
--- a/gio/gio-marshal.list
+++ b/gio/gio-marshal.list
@@ -18,3 +18,6 @@ VOID:STRING,UINT
VOID:BOXED,BOXED
VOID:VARIANT,BOXED
VOID:STRING,STRING,VARIANT
+VOID:POINTER,INT,STRING
+VOID:STRING,VARIANT
+INT:OBJECT
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]