[gnome-screenshot] screenshot: simplify GApplication code
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-screenshot] screenshot: simplify GApplication code
- Date: Tue, 8 May 2012 19:22:14 +0000 (UTC)
commit 08d2693290c560d782b3738e25daf877172b3da0
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue May 8 12:41:44 2012 -0400
screenshot: simplify GApplication code
Use g_application_get_default() to handle the singleton instance, and
use g_application_get_dbus_connection() instead of our hand rolled
implementation of the same thing.
src/gnome-screenshot.c | 2 +-
src/screenshot-application.c | 41 ++++-------------------------------------
src/screenshot-application.h | 3 +--
src/screenshot-utils.c | 2 +-
4 files changed, 7 insertions(+), 41 deletions(-)
---
diff --git a/src/gnome-screenshot.c b/src/gnome-screenshot.c
index a1467c6..0fe7cf2 100644
--- a/src/gnome-screenshot.c
+++ b/src/gnome-screenshot.c
@@ -45,7 +45,7 @@ main (int argc, char *argv[])
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- app = screenshot_application_get ();
+ app = screenshot_application_new ();
result = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index 0542921..3ddedb7 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -45,13 +45,9 @@
G_DEFINE_TYPE (ScreenshotApplication, screenshot_application, GTK_TYPE_APPLICATION);
-static ScreenshotApplication *_app_singleton = NULL;
-
static void screenshot_save_to_file (ScreenshotApplication *self);
struct _ScreenshotApplicationPriv {
- GDBusConnection *connection;
-
gchar *icc_profile_base64;
GdkPixbuf *screenshot;
@@ -614,39 +610,16 @@ interactive_dialog_response_cb (GtkWidget *d,
}
}
-static ScreenshotApplication *
-get_singleton (void)
-{
- if (_app_singleton == NULL)
- _app_singleton = g_object_new (SCREENSHOT_TYPE_APPLICATION,
- "application-id", "org.gnome.Screenshot",
- NULL);
-
- return _app_singleton;
-}
-
static void
screenshot_application_startup (GApplication *app)
{
ScreenshotApplication *self = SCREENSHOT_APPLICATION (app);
- GError *error = NULL;
G_APPLICATION_CLASS (screenshot_application_parent_class)->startup (app);
gtk_window_set_default_icon_name (SCREENSHOOTER_ICON);
screenshooter_init_stock_icons ();
- self->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-
- if (error != NULL)
- {
- g_critical ("Unable to connect to the session bus: %s",
- error->message);
- g_error_free (error);
-
- return;
- }
-
/* interactive mode: trigger the dialog and wait for the response */
if (screenshot_config->interactive)
{
@@ -669,7 +642,6 @@ screenshot_application_finalize (GObject *object)
{
ScreenshotApplication *self = SCREENSHOT_APPLICATION (object);
- g_clear_object (&self->priv->connection);
g_clear_object (&self->priv->screenshot);
g_free (self->priv->icc_profile_base64);
g_free (self->priv->save_uri);
@@ -698,15 +670,10 @@ screenshot_application_init (ScreenshotApplication *self)
ScreenshotApplicationPriv);
}
-GDBusConnection *
-screenshot_application_get_session_bus (void)
-{
- ScreenshotApplication *self = get_singleton ();
- return self->priv->connection;
-}
-
ScreenshotApplication *
-screenshot_application_get (void)
+screenshot_application_new (void)
{
- return get_singleton ();
+ return g_object_new (SCREENSHOT_TYPE_APPLICATION,
+ "application-id", "org.gnome.Screenshot",
+ NULL);
}
diff --git a/src/screenshot-application.h b/src/screenshot-application.h
index 96624f4..31cecd6 100644
--- a/src/screenshot-application.h
+++ b/src/screenshot-application.h
@@ -49,7 +49,6 @@ typedef struct {
} ScreenshotApplicationClass;
GType screenshot_application_get_type (void);
-ScreenshotApplication * screenshot_application_get (void);
-GDBusConnection * screenshot_application_get_session_bus (void);
+ScreenshotApplication * screenshot_application_new (void);
#endif /* __SCREENSHOT_APPLICATION_H__ */
diff --git a/src/screenshot-utils.c b/src/screenshot-utils.c
index 7aafeb3..6c5d08d 100644
--- a/src/screenshot-utils.c
+++ b/src/screenshot-utils.c
@@ -630,7 +630,7 @@ screenshot_get_pixbuf (GdkRectangle *rectangle)
filename);
}
- connection = screenshot_application_get_session_bus ();
+ connection = g_application_get_dbus_connection (g_application_get_default ());
g_dbus_connection_call_sync (connection,
"org.gnome.Shell",
"/org/gnome/Shell",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]