diff options
author | Claudio Saavedra <[email protected]> | 2011-06-09 22:33:30 +0300 |
---|---|---|
committer | raveit65 <[email protected]> | 2018-07-08 12:19:44 +0200 |
commit | 20d704b7b4f2560ee27cc9be25359107ceb4a14b (patch) | |
tree | 202e9a1335722c7f288019972b4e4afe5ae0f98a /src/eom-application.c | |
parent | 63a6313edf251919487047f47ad1f08228e7ba8d (diff) | |
download | eom-20d704b7b4f2560ee27cc9be25359107ceb4a14b.tar.bz2 eom-20d704b7b4f2560ee27cc9be25359107ceb4a14b.tar.xz |
Port EomApplication 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
origin commit:
https://gitlab.gnome.org/GNOME/eog/commit/3d39587
Enable TotemScreensaver unconditionally
It uses GDBus instead of libdbus now. It can be enabled even if
libdbus is not available as GDBus/GIO is always present.
origin commit:
https://gitlab.gnome.org/GNOME/eog/commit/4c32882
Diffstat (limited to 'src/eom-application.c')
-rw-r--r-- | src/eom-application.c | 223 |
1 files changed, 86 insertions, 137 deletions
diff --git a/src/eom-application.c b/src/eom-application.c index 1515d70..dbf1cb1 100644 --- a/src/eom-application.c +++ b/src/eom-application.c @@ -32,9 +32,7 @@ #include "eom-application.h" #include "eom-util.h" -#ifdef HAVE_DBUS #include "totem-scrsaver.h" -#endif #include <string.h> #include <glib.h> @@ -43,12 +41,7 @@ #include <gtk/gtk.h> #include <gdk/gdkx.h> -#ifdef HAVE_DBUS -#include "eom-application-service.h" -#include <dbus/dbus-glib-bindings.h> - #define APPLICATION_SERVICE_NAME "org.mate.eom.ApplicationService" -#endif static void eom_application_load_accelerators (void); static void eom_application_save_accelerators (void); @@ -56,81 +49,103 @@ static void eom_application_save_accelerators (void); #define EOM_APPLICATION_GET_PRIVATE(object) \ (G_TYPE_INSTANCE_GET_PRIVATE ((object), EOM_TYPE_APPLICATION, EomApplicationPrivate)) -G_DEFINE_TYPE (EomApplication, eom_application, G_TYPE_OBJECT); +G_DEFINE_TYPE (EomApplication, eom_application, GTK_TYPE_APPLICATION); -#ifdef HAVE_DBUS +static void +eom_application_activate (GApplication *application) +{ + eom_application_open_window (EOM_APPLICATION (application), + GDK_CURRENT_TIME, + EOM_APPLICATION (application)->flags, + NULL); +} -/** - * eom_application_register_service: - * @application: An #EomApplication. - * - * Registers #EomApplication<!-- -->'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 -eom_application_register_service (EomApplication *application) +static void +eom_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); + eom_application_open_file_list (EOM_APPLICATION (application), + list, GDK_CURRENT_TIME, + EOM_APPLICATION (application)->flags, + NULL); +} - return FALSE; - } +static void +eom_application_finalize (GObject *object) +{ + EomApplication *application = EOM_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; } + eom_application_save_accelerators (); +} - dbus_g_object_type_install_info (EOM_TYPE_APPLICATION, - &dbus_glib_eom_application_object_info); +static void +eom_application_add_platform_data (GApplication *application, + GVariantBuilder *builder) +{ + EomApplication *app = EOM_APPLICATION (application); - dbus_g_connection_register_g_object (connection, - "/org/mate/eom/Eom", - G_OBJECT (application)); + G_APPLICATION_CLASS (eom_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}", + "eom-application-startup-flags", + g_variant_new_byte (app->flags)); + } +} - return TRUE; +static void +eom_application_before_emit (GApplication *application, + GVariant *platform_data) +{ + GVariantIter iter; + const gchar *key; + GVariant *value; + + EOM_APPLICATION (application)->flags = 0; + g_variant_iter_init (&iter, platform_data); + while (g_variant_iter_loop (&iter, "{&sv}", &key, &value)) { + if (strcmp (key, "eom-application-startup-flags") == 0) { + EOM_APPLICATION (application)->flags = g_variant_get_byte (value); + } + } + + G_APPLICATION_CLASS (eom_application_parent_class)->before_emit (application, + platform_data); } -#endif /* ENABLE_DBUS */ static void eom_application_class_init (EomApplicationClass *eom_application_class) { + GApplicationClass *application_class; + GObjectClass *object_class; + + application_class = (GApplicationClass *) eom_application_class; + object_class = (GObjectClass *) eom_application_class; + + object_class->finalize = eom_application_finalize; + + application_class->activate = eom_application_activate; + application_class->open = eom_application_open; + application_class->add_platform_data = eom_application_add_platform_data; + application_class->before_emit = eom_application_before_emit; } static void @@ -140,9 +155,9 @@ eom_application_init (EomApplication *eom_application) eom_session_init (eom_application); - eom_application->plugin_engine = eom_plugin_engine_new (); - eom_application->toolbars_model = egg_toolbars_model_new (); + eom_application->plugin_engine = eom_plugin_engine_new (); + eom_application->flags = 0; egg_toolbars_model_load_names (eom_application->toolbars_model, EOM_DATA_DIR "/eom-toolbar.xml"); @@ -178,7 +193,10 @@ eom_application_get_instance (void) static EomApplication *instance; if (!instance) { - instance = EOM_APPLICATION (g_object_new (EOM_TYPE_APPLICATION, NULL)); + instance = EOM_APPLICATION (g_object_new (EOM_TYPE_APPLICATION, + "application-id", APPLICATION_SERVICE_NAME, + "flags", G_APPLICATION_HANDLES_OPEN, + NULL)); } return instance; @@ -193,7 +211,7 @@ eom_application_get_empty_window (EomApplication *application) g_return_val_if_fail (EOM_IS_APPLICATION (application), NULL); - windows = eom_application_get_windows (application); + windows = gtk_application_get_windows (GTK_APPLICATION (application)); for (l = windows; l != NULL; l = l->next) { EomWindow *window = EOM_WINDOW (l->data); @@ -204,8 +222,6 @@ eom_application_get_empty_window (EomApplication *application) } } - g_list_free (windows); - return empty_window; } @@ -386,7 +402,6 @@ eom_application_open_uri_list (EomApplication *application, error); } -#ifdef HAVE_DBUS /** * eom_application_open_uris: * @application: an #EomApplication @@ -415,70 +430,6 @@ eom_application_open_uris (EomApplication *application, return eom_application_open_file_list (application, file_list, timestamp, flags, error); } -#endif - -/** - * eom_application_shutdown: - * @application: An #EomApplication. - * - * Takes care of shutting down the Eye of MATE, and quits. - **/ -void -eom_application_shutdown (EomApplication *application) -{ - g_return_if_fail (EOM_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; - } - - eom_application_save_accelerators (); - - g_object_unref (application); - - gtk_main_quit (); -} - -/** - * eom_application_get_windows: - * @application: An #EomApplication. - * - * Gets the list of existing #EomApplication<!-- -->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 EomWindow) (transfer container): A new list of #EomWindow<!-- -->s. - **/ -GList * -eom_application_get_windows (EomApplication *application) -{ - GList *l, *toplevels; - GList *windows = NULL; - - g_return_val_if_fail (EOM_IS_APPLICATION (application), NULL); - - toplevels = gtk_window_list_toplevels (); - - for (l = toplevels; l != NULL; l = l->next) { - if (EOM_IS_WINDOW (l->data)) { - windows = g_list_append (windows, l->data); - } - } - - g_list_free (toplevels); - - return windows; -} /** * eom_application_get_toolbars_model: @@ -534,7 +485,6 @@ eom_application_reset_toolbars_model (EomApplication *app) EGG_TB_MODEL_NOT_REMOVABLE); } -#ifdef HAVE_DBUS /** * eom_application_screensaver_enable: * @application: an #EomApplication. @@ -562,7 +512,6 @@ eom_application_screensaver_disable (EomApplication *application) if (application->scr_saver) totem_scrsaver_disable (application->scr_saver); } -#endif static void eom_application_load_accelerators (void) |