[gnome-terminal/gsettings] server: Make TerminalApp subclass GtkApplication
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/gsettings] server: Make TerminalApp subclass GtkApplication
- Date: Fri, 30 Mar 2012 17:57:22 +0000 (UTC)
commit e6ba6d28c295a721ac12989b907cfeb8a27cf63b
Author: Christian Persch <chpe gnome org>
Date: Fri Mar 30 19:38:27 2012 +0200
server: Make TerminalApp subclass GtkApplication
src/server.c | 25 ++++------------------
src/terminal-app.c | 57 +++++++++++++++++++++++++++++++++++++++------------
src/terminal-app.h | 2 +
3 files changed, 50 insertions(+), 34 deletions(-)
---
diff --git a/src/server.c b/src/server.c
index e6f0e8f..bba1d57 100644
--- a/src/server.c
+++ b/src/server.c
@@ -39,7 +39,6 @@
#include "terminal-util.h"
#include "terminal-defines.h"
-GDBusObjectManagerServer *object_manager;
static char *bus_name = NULL;
static gboolean
@@ -67,8 +66,8 @@ static const GOptionEntry options[] = {
typedef struct {
- GMainLoop *loop;
GApplication *app;
+ GMainLoop *loop;
gboolean owns_name;
} MainData;
@@ -77,6 +76,8 @@ bus_acquired_cb (GDBusConnection *connection,
const char *name,
gpointer user_data)
{
+ MainData *data = (MainData *) user_data;
+ GDBusObjectManagerServer *object_manager;
TerminalObjectSkeleton *object;
TerminalFactory *factory;
@@ -88,6 +89,7 @@ bus_acquired_cb (GDBusConnection *connection,
terminal_object_skeleton_set_factory (object, factory);
g_object_unref (factory);
+ object_manager = terminal_app_get_object_manager (TERMINAL_APP (data->app));
g_dbus_object_manager_server_export (object_manager, G_DBUS_OBJECT_SKELETON (object));
g_object_unref (object);
@@ -130,13 +132,6 @@ name_lost_cb (GDBusConnection *connection,
g_main_loop_quit (data->loop);
}
-static void
-app_activate_cb (GApplication *app,
- gpointer user_data)
-{
- /* No-op required because GApplication is stupid */
-}
-
int
main (int argc, char **argv)
{
@@ -173,10 +168,9 @@ main (int argc, char **argv)
exit (EXIT_FAILURE);
}
- object_manager = g_dbus_object_manager_server_new (TERMINAL_OBJECT_PATH_PREFIX);
+ data.app = terminal_app_new (bus_name ? bus_name : TERMINAL_UNIQUE_NAME);
data.loop = g_main_loop_new (NULL, FALSE);
- data.app = NULL;
data.owns_name = FALSE;
owner_id = g_bus_own_name (G_BUS_TYPE_STARTER,
@@ -195,20 +189,11 @@ main (int argc, char **argv)
if (!data.owns_name)
goto out;
- data.app = (GApplication *) gtk_application_new (bus_name ? bus_name : TERMINAL_UNIQUE_NAME,
- G_APPLICATION_NON_UNIQUE |
- G_APPLICATION_IS_SERVICE);
- g_application_hold (data.app);
- g_signal_connect (data.app, "activate", G_CALLBACK (app_activate_cb), NULL);
- g_signal_connect_swapped (terminal_app_get (), "quit", G_CALLBACK (g_application_release), data.app);
exit_code = g_application_run (data.app, 0, NULL);
- g_clear_object (&data.app);
g_bus_unown_name (owner_id);
out:
- g_dbus_object_manager_server_unexport (object_manager, TERMINAL_FACTORY_OBJECT_PATH);
- g_clear_object (&object_manager);
terminal_app_shutdown ();
diff --git a/src/terminal-app.c b/src/terminal-app.c
index c9516f2..bcfc218 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -48,8 +48,6 @@
#define SYSTEM_PROXY_SETTINGS_SCHEMA "org.gnome.system.proxy"
-extern GDBusObjectManagerServer *object_manager;
-
/*
* Session state is stored entirely in the RestartCommand command line.
*
@@ -60,7 +58,7 @@ extern GDBusObjectManagerServer *object_manager;
*/
struct _TerminalAppClass {
- GObjectClass parent_class;
+ GtkApplicationClass parent_class;
void (* quit) (TerminalApp *app);
void (* profile_list_changed) (TerminalApp *app);
@@ -69,7 +67,9 @@ struct _TerminalAppClass {
struct _TerminalApp
{
- GObject parent_instance;
+ GtkApplication parent_instance;
+
+ GDBusObjectManagerServer *object_manager;
GList *windows;
GtkWidget *new_profile_dialog;
@@ -1035,7 +1035,17 @@ terminal_app_manage_profiles (TerminalApp *app,
/* Class implementation */
-G_DEFINE_TYPE (TerminalApp, terminal_app, G_TYPE_OBJECT)
+G_DEFINE_TYPE (TerminalApp, terminal_app, GTK_TYPE_APPLICATION)
+
+/* GApplicationClass impl */
+
+static void
+terminal_app_activate (GApplication *gapp)
+{
+ /* No-op required because GApplication is stupid */
+}
+
+/* GObjectClass impl */
static void
terminal_app_init (TerminalApp *app)
@@ -1075,6 +1085,9 @@ terminal_app_init (TerminalApp *app)
#endif
terminal_accels_init ();
+
+ /* FIXMEchpe: find out why this is necessary... */
+ g_application_hold (G_APPLICATION (app));
}
static void
@@ -1101,6 +1114,11 @@ terminal_app_finalize (GObject *object)
terminal_accels_shutdown ();
+ if (app->object_manager) {
+ g_dbus_object_manager_server_unexport (app->object_manager, TERMINAL_FACTORY_OBJECT_PATH);
+ g_object_unref (app->object_manager);
+ }
+
G_OBJECT_CLASS (terminal_app_parent_class)->finalize (object);
global_app = NULL;
@@ -1109,15 +1127,20 @@ terminal_app_finalize (GObject *object)
static void
terminal_app_real_quit (TerminalApp *app)
{
+ /* Release the hold added when creating the app */
+ g_application_release (G_APPLICATION (app));
}
static void
terminal_app_class_init (TerminalAppClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GApplicationClass *g_application_class = G_APPLICATION_CLASS (klass);
object_class->finalize = terminal_app_finalize;
+ g_application_class->activate = terminal_app_activate;
+
klass->quit = terminal_app_real_quit;
signals[QUIT] =
@@ -1150,14 +1173,20 @@ terminal_app_class_init (TerminalAppClass *klass)
/* Public API */
+GApplication *
+terminal_app_new (const char *id)
+{
+ return g_object_new (TERMINAL_TYPE_APP,
+ "application-id", id,
+ "flags", (glong) (G_APPLICATION_NON_UNIQUE | G_APPLICATION_IS_SERVICE),
+ NULL);
+}
+
TerminalApp*
terminal_app_get (void)
{
- if (global_app == NULL) {
- g_object_new (TERMINAL_TYPE_APP, NULL);
- g_assert (global_app != NULL);
- }
-
+ g_assert (global_app != NULL);
+ g_assert (global_app != NULL);
return global_app;
}
@@ -1169,8 +1198,6 @@ terminal_app_shutdown (void)
g_object_unref (global_app);
g_assert (global_app == NULL);
-
- g_settings_sync ();
}
TerminalWindow *
@@ -1520,5 +1547,7 @@ terminal_app_get_system_font (TerminalApp *app)
GDBusObjectManagerServer *
terminal_app_get_object_manager (TerminalApp *app)
{
- return object_manager;
-}
\ No newline at end of file
+ if (app->object_manager == NULL)
+ app->object_manager = g_dbus_object_manager_server_new (TERMINAL_OBJECT_PATH_PREFIX);
+ return app->object_manager;
+}
diff --git a/src/terminal-app.h b/src/terminal-app.h
index d6b80de..a383e0a 100644
--- a/src/terminal-app.h
+++ b/src/terminal-app.h
@@ -46,6 +46,8 @@ typedef struct _TerminalApp TerminalApp;
GType terminal_app_get_type (void);
+GApplication *terminal_app_new (const char *id);
+
TerminalApp* terminal_app_get (void);
void terminal_app_shutdown (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]