[gnome-photos] application: Make it a singleton
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] application: Make it a singleton
- Date: Mon, 23 Apr 2012 23:12:04 +0000 (UTC)
commit d4926ac5718bebac14a7e89a3699b790f6199e73
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Apr 23 19:42:11 2012 +0200
application: Make it a singleton
src/photos-application.c | 28 ++++++++++++++++++++++------
src/photos-application.h | 3 +--
src/photos-main.c | 2 +-
3 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index abb2e0a..8b157fe 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -156,6 +156,24 @@ photos_application_startup (GApplication *application)
}
+static GObject *
+photos_application_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params)
+{
+ static GObject *self = NULL;
+
+ if (self == NULL)
+ {
+ self = G_OBJECT_CLASS (photos_application_parent_class)->constructor (type,
+ n_construct_params,
+ construct_params);
+ g_object_add_weak_pointer (self, (gpointer) &self);
+ return self;
+ }
+
+ return g_object_ref (self);
+}
+
+
static void
photos_application_dispose (GObject *object)
{
@@ -200,6 +218,7 @@ photos_application_class_init (PhotosApplicationClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
GApplicationClass *application_class = G_APPLICATION_CLASS (class);
+ object_class->constructor = photos_application_constructor;
object_class->dispose = photos_application_dispose;
application_class->activate = photos_application_activate;
application_class->startup = photos_application_startup;
@@ -209,14 +228,11 @@ photos_application_class_init (PhotosApplicationClass *class)
GtkApplication *
-photos_application_new (const gchar *application_id,
- GApplicationFlags flags)
+photos_application_new (void)
{
- g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
-
g_type_init ();
return g_object_new (PHOTOS_TYPE_APPLICATION,
- "application-id", application_id,
- "flags", flags,
+ "application-id", "org.gnome." PACKAGE_NAME,
+ "flags", G_APPLICATION_FLAGS_NONE,
NULL);
}
diff --git a/src/photos-application.h b/src/photos-application.h
index b76cf7f..1d48a01 100644
--- a/src/photos-application.h
+++ b/src/photos-application.h
@@ -49,8 +49,7 @@ struct _PhotosApplicationClass
GType photos_application_get_type (void) G_GNUC_CONST;
-GtkApplication *photos_application_new (const gchar *application_id,
- GApplicationFlags flags);
+GtkApplication *photos_application_new (void);
G_END_DECLS
diff --git a/src/photos-main.c b/src/photos-main.c
index ee00c3a..1276046 100644
--- a/src/photos-main.c
+++ b/src/photos-main.c
@@ -39,7 +39,7 @@ main (gint argc, gchar *argv[])
g_set_prgname (PACKAGE_TARNAME);
- app = photos_application_new ("org.gnome." PACKAGE_NAME, G_APPLICATION_FLAGS_NONE);
+ app = photos_application_new ();
exit_status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]