[eog] Port EogApplication to GtkApplication
- From: Claudio Saavedra <csaavedra src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog] Port EogApplication to GtkApplication
- Date: Sat, 11 Jun 2011 11:50:26 +0000 (UTC)
commit 3d39587751ead63a5f6458ce6daf5dd1acf8165a
Author: Claudio Saavedra <csaavedra igalia com>
Date: Thu Jun 9 22:33:30 2011 +0300
Port EogApplication to GtkApplication
This removes the direct dependency on dbus and makes use of the
GApplication/GtkApplication facilities for uniqueness and activation.
Bump the glib requirement to 2.29.4, since we need
G_APPLICATION_NON_UNIQUE.
https://bugzilla.gnome.org/show_bug.cgi?id=622876
configure.ac | 27 +------
src/Makefile.am | 11 ---
src/eog-application.c | 214 +++++++++++++++++++-----------------------------
src/eog-application.h | 15 +---
src/eog-util.c | 2 -
src/eog-util.h | 2 -
src/eog-window.c | 21 +-----
src/main.c | 116 +++------------------------
8 files changed, 101 insertions(+), 307 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 98543fa..b38b061 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,7 +84,7 @@ GNOME_DOC_INIT
# **********
GTK_REQUIRED=3.0.2
-GLIB_REQUIRED=2.25.15
+GLIB_REQUIRED=2.29.4
GNOME_DESKTOP_REQUIRED=2.91.2
GDKPIXBUF_REQUIRED=2.4.0
GTK_PRINT_REQUIRED=2.90.4
@@ -259,30 +259,6 @@ AC_SUBST(LIBJPEG)
AM_CONDITIONAL(ENABLE_JPEG, test x$have_jpeg = xyes)
AM_CONDITIONAL(HAVE_LIBJPEG_80, test "x$have_libjpeg_80" = xyes)
-# ****************
-# D-Bus activation
-# ****************
-
-DBUS_GLIB_REQUIRED=0.71
-
-AC_ARG_WITH([dbus], AC_HELP_STRING([--without-dbus], [disable dbus based activation]))
-have_dbus=no
-if test x$with_dbus != xno; then
- PKG_CHECK_MODULES([DBUS], [dbus-glib-1 >= $DBUS_GLIB_REQUIRED], have_dbus=yes, have_dbus=no)
-fi
-if test x$have_dbus = xyes; then
- AC_PATH_PROG([DBUS_BINDING_TOOL], [dbus-binding-tool], [no])
-
- if test x$DBUS_BINDING_TOOL = "xno" ; then
- AC_MSG_ERROR([dbus-binding-tool executable not found in your path - should be installed with dbus glib bindings])
- fi
-
- AC_DEFINE(HAVE_DBUS, 1, [DBUS based activation.])
- EOG_MODULES="$EOG_MODULES dbus-glib-1 >= $DBUS_GLIB_REQUIRED"
-fi
-
-AM_CONDITIONAL([HAVE_DBUS], [test "x$have_dbus" = "xyes"])
-
# ************************************
# libXML2 (required for toolbareditor)
# ************************************
@@ -394,6 +370,5 @@ Configure summary:
XMP support ................: ${have_exempi}
JPEG support ...............: ${have_jpeg}
Colour management support ..: ${have_lcms}
- D-Bus activation............: ${have_dbus}
GObject Introspection.......: ${have_introspection}
"
diff --git a/src/Makefile.am b/src/Makefile.am
index 600cf84..718d393 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -200,17 +200,6 @@ EXTRA_DIST = \
eog-enum-types.c.template \
eog-marshal.list
-if HAVE_DBUS
-
-BUILT_SOURCES += eog-application-service.h
-
-EXTRA_DIST += eog-application-service.xml
-
-eog-application-service.h: eog-application-service.xml
- $(AM_V_GEN)dbus-binding-tool --prefix=eog_application --mode=glib-server --output=eog-application-service.h $<
-
-endif
-
CLEANFILES = $(BUILT_SOURCES)
if HAVE_INTROSPECTION
diff --git a/src/eog-application.c b/src/eog-application.c
index 64270ea..258db1b 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -41,12 +41,7 @@
#include <glib-object.h>
#include <gtk/gtk.h>
-#ifdef HAVE_DBUS
-#include "eog-application-service.h"
-#include <dbus/dbus-glib-bindings.h>
-
#define APPLICATION_SERVICE_NAME "org.gnome.eog.ApplicationService"
-#endif
static void eog_application_load_accelerators (void);
static void eog_application_save_accelerators (void);
@@ -54,81 +49,103 @@ static void eog_application_save_accelerators (void);
#define EOG_APPLICATION_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE ((object), EOG_TYPE_APPLICATION, EogApplicationPrivate))
-G_DEFINE_TYPE (EogApplication, eog_application, G_TYPE_OBJECT);
+G_DEFINE_TYPE (EogApplication, eog_application, GTK_TYPE_APPLICATION);
-#ifdef HAVE_DBUS
+static void
+eog_application_activate (GApplication *application)
+{
+ eog_application_open_window (EOG_APPLICATION (application),
+ GDK_CURRENT_TIME,
+ EOG_APPLICATION (application)->flags,
+ NULL);
+}
-/**
- * eog_application_register_service:
- * @application: An #EogApplication.
- *
- * Registers #EogApplication<!-- -->'s DBus service, to allow
- * remote calls. If the DBus service is already registered,
- * or there is any other connection error, returns %FALSE.
- *
- * Returns: %TRUE if the service was registered succesfully. %FALSE
- * otherwise.
- **/
-gboolean
-eog_application_register_service (EogApplication *application)
+static void
+eog_application_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
{
- static DBusGConnection *connection = NULL;
- DBusGProxy *driver_proxy;
- GError *err = NULL;
- guint request_name_result;
-
- if (connection) {
- g_warning ("Service already registered.");
- return FALSE;
- }
+ GSList *list = NULL;
- connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
+ while (n_files--)
+ list = g_slist_prepend (list, files[n_files]);
- if (connection == NULL) {
- g_warning ("Service registration failed.");
- g_error_free (err);
+ eog_application_open_file_list (EOG_APPLICATION (application),
+ list, GDK_CURRENT_TIME,
+ EOG_APPLICATION (application)->flags,
+ NULL);
+}
- return FALSE;
- }
+static void
+eog_application_finalize (GObject *object)
+{
+ EogApplication *application = EOG_APPLICATION (object);
- driver_proxy = dbus_g_proxy_new_for_name (connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
-
- if (!org_freedesktop_DBus_request_name (driver_proxy,
- APPLICATION_SERVICE_NAME,
- DBUS_NAME_FLAG_DO_NOT_QUEUE,
- &request_name_result, &err)) {
- g_warning ("Service registration failed.");
- g_clear_error (&err);
+ if (application->toolbars_model) {
+ g_object_unref (application->toolbars_model);
+ application->toolbars_model = NULL;
+ g_free (application->toolbars_file);
+ application->toolbars_file = NULL;
}
-
- g_object_unref (driver_proxy);
-
- if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
- return FALSE;
+ if (application->plugin_engine) {
+ g_object_unref (application->plugin_engine);
+ application->plugin_engine = NULL;
}
+ eog_application_save_accelerators ();
+}
- dbus_g_object_type_install_info (EOG_TYPE_APPLICATION,
- &dbus_glib_eog_application_object_info);
+static void
+eog_application_add_platform_data (GApplication *application,
+ GVariantBuilder *builder)
+{
+ EogApplication *app = EOG_APPLICATION (application);
- dbus_g_connection_register_g_object (connection,
- "/org/gnome/eog/Eog",
- G_OBJECT (application));
+ G_APPLICATION_CLASS (eog_application_parent_class)->add_platform_data (application,
+ builder);
- application->scr_saver = totem_scrsaver_new ();
- g_object_set (application->scr_saver,
- "reason", _("Running in fullscreen mode"),
- NULL);
+ if (app->flags) {
+ g_variant_builder_add (builder, "{sv}",
+ "eog-application-startup-flags",
+ g_variant_new_byte (app->flags));
+ }
+}
- return TRUE;
+static void
+eog_application_before_emit (GApplication *application,
+ GVariant *platform_data)
+{
+ GVariantIter iter;
+ const gchar *key;
+ GVariant *value;
+
+ EOG_APPLICATION (application)->flags = 0;
+ g_variant_iter_init (&iter, platform_data);
+ while (g_variant_iter_loop (&iter, "{&sv}", &key, &value)) {
+ if (strcmp (key, "eog-application-startup-flags") == 0) {
+ EOG_APPLICATION (application)->flags = g_variant_get_byte (value);
+ }
+ }
+
+ G_APPLICATION_CLASS (eog_application_parent_class)->before_emit (application,
+ platform_data);
}
-#endif /* ENABLE_DBUS */
static void
eog_application_class_init (EogApplicationClass *eog_application_class)
{
+ GApplicationClass *application_class;
+ GObjectClass *object_class;
+
+ application_class = (GApplicationClass *) eog_application_class;
+ object_class = (GObjectClass *) eog_application_class;
+
+ object_class->finalize = eog_application_finalize;
+
+ application_class->activate = eog_application_activate;
+ application_class->open = eog_application_open;
+ application_class->add_platform_data = eog_application_add_platform_data;
+ application_class->before_emit = eog_application_before_emit;
}
static void
@@ -140,6 +157,7 @@ eog_application_init (EogApplication *eog_application)
eog_application->toolbars_model = egg_toolbars_model_new ();
eog_application->plugin_engine = eog_plugin_engine_new ();
+ eog_application->flags = 0;
egg_toolbars_model_load_names (eog_application->toolbars_model,
EOG_DATA_DIR "/eog-toolbar.xml");
@@ -175,7 +193,10 @@ eog_application_get_instance (void)
static EogApplication *instance;
if (!instance) {
- instance = EOG_APPLICATION (g_object_new (EOG_TYPE_APPLICATION, NULL));
+ instance = EOG_APPLICATION (g_object_new (EOG_TYPE_APPLICATION,
+ "application-id", APPLICATION_SERVICE_NAME,
+ "flags", G_APPLICATION_HANDLES_OPEN,
+ NULL));
}
return instance;
@@ -190,7 +211,7 @@ eog_application_get_empty_window (EogApplication *application)
g_return_val_if_fail (EOG_IS_APPLICATION (application), NULL);
- windows = eog_application_get_windows (application);
+ windows = gtk_application_get_windows (GTK_APPLICATION (application));
for (l = windows; l != NULL; l = l->next) {
EogWindow *window = EOG_WINDOW (l->data);
@@ -201,8 +222,6 @@ eog_application_get_empty_window (EogApplication *application)
}
}
- g_list_free (windows);
-
return empty_window;
}
@@ -367,7 +386,6 @@ eog_application_open_uri_list (EogApplication *application,
error);
}
-#ifdef HAVE_DBUS
/**
* eog_application_open_uris:
* @application: an #EogApplication
@@ -396,69 +414,7 @@ eog_application_open_uris (EogApplication *application,
return eog_application_open_file_list (application, file_list, timestamp,
flags, error);
}
-#endif
-
-/**
- * eog_application_shutdown:
- * @application: An #EogApplication.
- *
- * Takes care of shutting down the Eye of GNOME, and quits.
- **/
-void
-eog_application_shutdown (EogApplication *application)
-{
- g_return_if_fail (EOG_IS_APPLICATION (application));
-
- if (application->toolbars_model) {
- g_object_unref (application->toolbars_model);
- application->toolbars_model = NULL;
-
- g_free (application->toolbars_file);
- application->toolbars_file = NULL;
- }
- if (application->plugin_engine) {
- g_object_unref (application->plugin_engine);
- application->plugin_engine = NULL;
- }
-
- eog_application_save_accelerators ();
-
- g_object_unref (application);
-
- gtk_main_quit ();
-}
-/**
- * eog_application_get_windows:
- * @application: An #EogApplication.
- *
- * Gets the list of existing #EogApplication<!-- -->s. The windows
- * in this list are not individually referenced, you need to keep
- * your own references if you want to perform actions that may destroy
- * them.
- *
- * Returns: (element-type EogWindow) (transfer container): A new list of #EogWindow<!-- -->s.
- **/
-GList *
-eog_application_get_windows (EogApplication *application)
-{
- GList *l, *toplevels;
- GList *windows = NULL;
-
- g_return_val_if_fail (EOG_IS_APPLICATION (application), NULL);
-
- toplevels = gtk_window_list_toplevels ();
-
- for (l = toplevels; l != NULL; l = l->next) {
- if (EOG_IS_WINDOW (l->data)) {
- windows = g_list_append (windows, l->data);
- }
- }
-
- g_list_free (toplevels);
-
- return windows;
-}
/**
* eog_application_get_toolbars_model:
diff --git a/src/eog-application.h b/src/eog-application.h
index 2d36b3c..22c32cd 100644
--- a/src/eog-application.h
+++ b/src/eog-application.h
@@ -50,29 +50,24 @@ typedef struct _EogApplicationPrivate EogApplicationPrivate;
#define EOG_APP (eog_application_get_instance ())
struct _EogApplication {
- GObject base_instance;
+ GtkApplication base_instance;
EggToolbarsModel *toolbars_model;
gchar *toolbars_file;
EogPluginEngine *plugin_engine;
TotemScrsaver *scr_saver;
+ EogStartupFlags flags;
};
struct _EogApplicationClass {
- GObjectClass parent_class;
+ GtkApplicationClass parent_class;
};
GType eog_application_get_type (void) G_GNUC_CONST;
EogApplication *eog_application_get_instance (void);
-#ifdef HAVE_DBUS
-gboolean eog_application_register_service (EogApplication *application);
-#endif
-
-void eog_application_shutdown (EogApplication *application);
-
gboolean eog_application_open_window (EogApplication *application,
guint timestamp,
EogStartupFlags flags,
@@ -90,15 +85,11 @@ gboolean eog_application_open_file_list (EogApplication *applicati
EogStartupFlags flags,
GError **error);
-#ifdef HAVE_DBUS
gboolean eog_application_open_uris (EogApplication *application,
gchar **uris,
guint timestamp,
EogStartupFlags flags,
GError **error);
-#endif
-
-GList *eog_application_get_windows (EogApplication *application);
EggToolbarsModel *eog_application_get_toolbars_model (EogApplication *application);
diff --git a/src/eog-util.c b/src/eog-util.c
index 40d0d61..4df7fbb 100644
--- a/src/eog-util.c
+++ b/src/eog-util.c
@@ -157,7 +157,6 @@ eog_util_string_list_to_file_list (GSList *string_list)
return g_slist_reverse (file_list);
}
-#ifdef HAVE_DBUS
GSList*
eog_util_strings_to_file_list (gchar **strings)
{
@@ -171,7 +170,6 @@ eog_util_strings_to_file_list (gchar **strings)
return g_slist_reverse (file_list);
}
-#endif
GSList*
eog_util_string_array_to_list (const gchar **files, gboolean create_uri)
diff --git a/src/eog-util.h b/src/eog-util.h
index aa711f3..37d7525 100644
--- a/src/eog-util.h
+++ b/src/eog-util.h
@@ -42,10 +42,8 @@ GSList *eog_util_parse_uri_string_list_to_file_list (const gchar *uri_list);
G_GNUC_INTERNAL
GSList *eog_util_string_list_to_file_list (GSList *string_list);
-#ifdef HAVE_DBUS
G_GNUC_INTERNAL
GSList *eog_util_strings_to_file_list (gchar **strings);
-#endif
G_GNUC_INTERNAL
GSList *eog_util_string_array_to_list (const gchar **files,
diff --git a/src/eog-window.c b/src/eog-window.c
index 2f58f88..fc05bf5 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -4666,6 +4666,8 @@ eog_window_init (EogWindow *window)
window->priv->save_disabled = FALSE;
window->priv->page_setup = NULL;
+
+ gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (EOG_APP));
}
static void
@@ -4804,24 +4806,6 @@ eog_window_dispose (GObject *object)
G_OBJECT_CLASS (eog_window_parent_class)->dispose (object);
}
-static void
-eog_window_finalize (GObject *object)
-{
- GList *windows = eog_application_get_windows (EOG_APP);
-
- g_return_if_fail (EOG_IS_WINDOW (object));
-
- eog_debug (DEBUG_WINDOW);
-
- if (windows == NULL) {
- eog_application_shutdown (EOG_APP);
- } else {
- g_list_free (windows);
- }
-
- G_OBJECT_CLASS (eog_window_parent_class)->finalize (object);
-}
-
static gint
eog_window_delete (GtkWidget *widget, GdkEventAny *event)
{
@@ -5176,7 +5160,6 @@ eog_window_class_init (EogWindowClass *class)
g_object_class->constructor = eog_window_constructor;
g_object_class->dispose = eog_window_dispose;
- g_object_class->finalize = eog_window_finalize;
g_object_class->set_property = eog_window_set_property;
g_object_class->get_property = eog_window_get_property;
diff --git a/src/main.c b/src/main.c
index eeefc21..542bd11 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,10 +26,6 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#ifdef HAVE_DBUS
-#include <dbus/dbus-glib-bindings.h>
-#include <gdk/gdkx.h>
-#endif
#ifdef HAVE_INTROSPECTION
#include <girepository.h>
#endif
@@ -55,9 +51,7 @@ static EogStartupFlags flags;
static gboolean fullscreen = FALSE;
static gboolean slide_show = FALSE;
static gboolean disable_gallery = FALSE;
-#if HAVE_DBUS
static gboolean force_new_instance = FALSE;
-#endif
static gchar **startup_files = NULL;
static gboolean
@@ -76,12 +70,9 @@ static const GOptionEntry goption_options[] =
{ "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen, N_("Open in fullscreen mode"), NULL },
{ "disable-gallery", 'g', 0, G_OPTION_ARG_NONE, &disable_gallery, N_("Disable image gallery"), NULL },
{ "slide-show", 's', 0, G_OPTION_ARG_NONE, &slide_show, N_("Open in slideshow mode"), NULL },
-#if HAVE_DBUS
{ "new-instance", 'n', 0, G_OPTION_ARG_NONE, &force_new_instance, N_("Start a new instance instead of reusing an existing one"), NULL },
-#endif
{ "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
_print_version_and_exit, N_("Show the application's version"), NULL},
- { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &startup_files, NULL, N_("[FILEâ?¦]") },
{ NULL }
};
@@ -98,90 +89,6 @@ set_startup_flags (void)
flags |= EOG_STARTUP_SLIDE_SHOW;
}
-static void
-load_files (void)
-{
- GSList *files = NULL;
-
- files = eog_util_string_array_to_list ((const gchar **) startup_files, TRUE);
-
- eog_application_open_uri_list (EOG_APP,
- files,
- GDK_CURRENT_TIME,
- flags,
- NULL);
-
- g_slist_foreach (files, (GFunc) g_free, NULL);
- g_slist_free (files);
-}
-
-#ifdef HAVE_DBUS
-static gboolean
-load_files_remote (void)
-{
- GError *error = NULL;
- DBusGConnection *connection;
- DBusGProxy *remote_object;
- gboolean result = TRUE;
- GdkDisplay *display;
- guint32 timestamp;
- gchar **files;
-
- display = gdk_display_get_default ();
-
- timestamp = gdk_x11_display_get_user_time (display);
- connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
-
- if (connection == NULL) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- return FALSE;
- }
-
- files = eog_util_string_array_make_absolute (startup_files);
-
- remote_object = dbus_g_proxy_new_for_name (connection,
- "org.gnome.eog.ApplicationService",
- "/org/gnome/eog/Eog",
- "org.gnome.eog.Application");
-
- if (!files) {
- if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error,
- G_TYPE_UINT, timestamp,
- G_TYPE_UCHAR, flags,
- G_TYPE_INVALID,
- G_TYPE_INVALID)) {
- g_warning ("%s", error->message);
- g_clear_error (&error);
-
- result = FALSE;
- }
- } else {
- if (!dbus_g_proxy_call (remote_object, "OpenUris", &error,
- G_TYPE_STRV, files,
- G_TYPE_UINT, timestamp,
- G_TYPE_UCHAR, flags,
- G_TYPE_INVALID,
- G_TYPE_INVALID)) {
- g_warning ("%s", error->message);
- g_clear_error (&error);
-
- result = FALSE;
- }
-
- g_strfreev (files);
- }
-
- g_object_unref (remote_object);
- dbus_g_connection_unref (connection);
-
- gdk_notify_startup_complete ();
-
- return result;
-}
-#endif /* HAVE_DBUS */
-
int
main (int argc, char **argv)
{
@@ -198,7 +105,7 @@ main (int argc, char **argv)
gtk_rc_parse (EOG_DATA_DIR G_DIR_SEPARATOR_S "gtkrc");
- ctx = g_option_context_new (NULL);
+ ctx = g_option_context_new (_("[FILEâ?¦]"));
g_option_context_add_main_entries (ctx, goption_options, PACKAGE);
/* Option groups are free'd together with the context
* Using gtk_get_option_group here initializes gtk during parsing */
@@ -226,15 +133,6 @@ main (int argc, char **argv)
set_startup_flags ();
-#ifdef HAVE_DBUS
- if (!force_new_instance &&
- !eog_application_register_service (EOG_APP)) {
- if (load_files_remote ()) {
- return 0;
- }
- }
-#endif /* HAVE_DBUS */
-
#ifdef HAVE_EXEMPI
xmp_init();
#endif
@@ -258,11 +156,17 @@ main (int argc, char **argv)
"gtk-application-prefer-dark-theme", TRUE,
NULL);
- load_files ();
-
gdk_threads_enter ();
- gtk_main ();
+ EOG_APP->flags = flags;
+ if (force_new_instance) {
+ GApplicationFlags app_flags = g_application_get_flags (G_APPLICATION (EOG_APP));
+ app_flags |= G_APPLICATION_NON_UNIQUE;
+ g_application_set_flags (G_APPLICATION (EOG_APP), app_flags);
+ }
+
+ g_application_run (G_APPLICATION (EOG_APP), argc, argv);
+ g_object_unref (EOG_APP);
gdk_threads_leave ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]