[file-roller] Use GNotification instead of libnotify



commit 731e73776f197a95e8a537e33f8d70807cbaad04
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Thu Mar 3 17:12:59 2022 +0100

    Use GNotification instead of libnotify

 default.nix          |  1 -
 meson.build          |  8 ------
 nautilus/meson.build |  1 -
 src/fr-application.c | 34 +++++++++++++++++------
 src/fr-window.c      | 76 +++++++++-------------------------------------------
 src/meson.build      |  1 -
 6 files changed, 38 insertions(+), 83 deletions(-)
---
diff --git a/default.nix b/default.nix
index 60146a58..d3b581ce 100644
--- a/default.nix
+++ b/default.nix
@@ -112,7 +112,6 @@ makeDerivation rec {
     json-glib
     libarchive
     libhandy
-    libnotify
   ];
 
   inherit doCheck;
diff --git a/meson.build b/meson.build
index f38cb604..4bb09ab9 100644
--- a/meson.build
+++ b/meson.build
@@ -9,7 +9,6 @@ gtk_version = '>=3.22.0'
 hdy_version = '>=1.5.0'
 nautilus_version = '>=3.28.0'
 json_glib_version = '>=0.14.0'
-libnotify_version = '>=0.4.3'
 libarchive_version = '>=3.1.900a'
 
 gnome = import('gnome')
@@ -41,9 +40,6 @@ build_nautilus_actions = libnautilus_extension_dep.found()
 
 libjson_glib_dep = dependency('json-glib-1.0', version : json_glib_version, required : false)
 use_json_glib = libjson_glib_dep.found()
- 
-libnotify_dep = dependency('libnotify', version : libnotify_version, required : get_option('notification'))
-use_libnotify = libnotify_dep.found()
 
 libarchive_dep = dependency('libarchive', version : libarchive_version, required : get_option('libarchive'))
 use_libarchive = libarchive_dep.found()
@@ -83,9 +79,6 @@ endif
 if use_json_glib
   config_data.set('HAVE_JSON_GLIB', 1)
 endif
-if use_libnotify
-  config_data.set('ENABLE_NOTIFICATION', 1)
-endif
 if use_libarchive
   config_data.set('ENABLE_LIBARCHIVE', 1)
 endif
@@ -149,7 +142,6 @@ summary = [
   '           project: @0@ @1@'.format(meson.project_name(), meson.project_version()),
   '            prefix: @0@'.format(prefix),
   '  nautilus actions: @0@'.format(build_nautilus_actions),
-  '     notifications: @0@'.format(use_libnotify),
   '        packagekit: @0@'.format(get_option('packagekit')),
   '        libarchive: @0@'.format(use_libarchive),
   '      have mkdtemp: @0@'.format(have_mkdtemp),
diff --git a/nautilus/meson.build b/nautilus/meson.build
index 19fabbe4..5d989033 100644
--- a/nautilus/meson.build
+++ b/nautilus/meson.build
@@ -11,7 +11,6 @@ shared_module('nautilus-fileroller',
     gtk_dep, 
     libnautilus_extension_dep,
     use_json_glib ? libjson_glib_dep : [],
-    use_libnotify ? libnotify_dep : []    
   ],  
   include_directories : config_inc,
   c_args : c_args,
diff --git a/src/fr-application.c b/src/fr-application.c
index 114f9fb3..b0e5f21e 100644
--- a/src/fr-application.c
+++ b/src/fr-application.c
@@ -29,9 +29,6 @@
 #include <gtk/gtk.h>
 #include <glib/gprintf.h>
 #include <handy.h>
-#ifdef ENABLE_NOTIFICATION
-#  include <libnotify/notify.h>
-#endif
 #ifdef ENABLE_INTROSPECTION
 #  include <girepository.h>
 #endif
@@ -115,6 +112,28 @@ static const GOptionEntry options[] = {
 };
 
 
+static void
+action_open_archive (GSimpleAction      *action,
+                    GVariant           *value,
+                    gpointer            user_data)
+{
+       g_autoptr(GFile)  saved_file;
+       GtkWidget        *new_window;
+
+       saved_file = g_file_new_for_path (g_variant_get_string (value, NULL));
+       new_window = fr_window_new ();
+       gtk_widget_show (new_window);
+       fr_window_archive_open (FR_WINDOW (new_window),
+                               saved_file,
+                               GTK_WINDOW (new_window));
+}
+
+
+static GActionEntry entries[] = {
+       { "open-archive", action_open_archive, "s", NULL, NULL },
+};
+
+
 /* -- service -- */
 
 
@@ -469,11 +488,6 @@ fr_application_startup (GApplication *application)
        g_set_application_name (_("Archive Manager"));
        gtk_window_set_default_icon_name ("org.gnome.ArchiveManager");
 
-#ifdef ENABLE_NOTIFICATION
-       if (! notify_init (g_get_application_name ()))
-                g_warning ("Cannot initialize notification system.");
-#endif /* ENABLE_NOTIFICATION */
-
        fr_application_register_archive_manager_service (FR_APPLICATION (application));
        initialize_data ();
 
@@ -492,6 +506,10 @@ fr_application_startup (GApplication *application)
                initialize_app_menubar (application);
        else
                initialize_app_menu (application);
+
+       /* Setup actions */
+       g_action_map_add_action_entries (G_ACTION_MAP (application), entries,
+                                        G_N_ELEMENTS (entries), NULL);
 }
 
 
diff --git a/src/fr-window.c b/src/fr-window.c
index f4883b30..0c06cb65 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -31,9 +31,6 @@
 #endif
 #include <gdk/gdkkeysyms.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
-#ifdef ENABLE_NOTIFICATION
-#  include <libnotify/notify.h>
-#endif
 #include "dlg-batch-add.h"
 #include "dlg-delete.h"
 #include "dlg-extract.h"
@@ -6187,81 +6184,32 @@ fr_window_archive_reload (FrWindow *window)
 }
 
 
-/**/
-
-
-#ifdef ENABLE_NOTIFICATION
-
-
-static void
-notify_action_open_archive_cb (NotifyNotification *notification,
-                              char               *action,
-                              gpointer            user_data)
-{
-       GFile     *saved_file = user_data;
-       GtkWidget *new_window;
-
-       new_window = fr_window_new ();
-       gtk_widget_show (new_window);
-       fr_window_archive_open (FR_WINDOW (new_window),
-                               saved_file,
-                               GTK_WINDOW (new_window));
-}
-
-
 static void
 _fr_window_notify_creation_complete (FrWindow *window)
 {
-       char               *basename;
-       char               *message;
-       NotifyNotification *notification;
-       gboolean            notification_supports_actions;
-       GList              *caps;
+       char                     *basename;
+       char                     *message;
+       g_autoptr(GNotification)  notification;
 
        basename = _g_file_get_display_basename (window->priv->saving_file);
        /* Translators: %s is a filename */
        message = g_strdup_printf (_("ā€œ%sā€ created successfully"), basename);
-       notification = notify_notification_new (window->priv->batch_title, message, "file-roller");
-       notify_notification_set_hint_string (notification, "desktop-entry", "file-roller");
+       notification = g_notification_new (window->priv->batch_title);
+       g_notification_set_body (notification, message);
+       g_notification_set_icon (notification, g_themed_icon_new ("document-open-symbolic"));
+       g_notification_add_button_with_target (notification,
+                                              C_("Action", "Open"),
+                                              "app.open-archive",
+                                              "s", g_file_get_path (window->priv->saving_file));
 
-       notification_supports_actions = FALSE;
-       caps = notify_get_server_caps ();
-       if (caps != NULL) {
-               notification_supports_actions = g_list_find_custom (caps, "actions", (GCompareFunc) strcmp) 
!= NULL;
-               _g_string_list_free (caps);
-       }
+       g_application_send_notification (g_application_get_default (), NULL,
+                                        notification);
 
-       if (notification_supports_actions) {
-               notify_notification_add_action (notification,
-                                               "document-open-symbolic",
-                                               C_("Action", "Open"),
-                                               notify_action_open_archive_cb,
-                                               g_object_ref (window->priv->saving_file),
-                                               g_object_unref);
-               /*notify_notification_set_hint (notification,
-                                             "action-icons",
-                                             g_variant_new_boolean (TRUE));*/
-       }
-
-       notify_notification_show (notification, NULL);
        g_free (message);
        g_free (basename);
 }
 
 
-#else
-
-
-static void
-_fr_window_notify_creation_complete (FrWindow *window)
-{
-       gtk_window_present (GTK_WINDOW (window->priv->progress_dialog));
-}
-
-
-#endif
-
-
 static void
 archive_add_files_ready_cb (GObject      *source_object,
                            GAsyncResult *result,
diff --git a/src/meson.build b/src/meson.build
index 850f322f..7e75ae6c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -132,7 +132,6 @@ fr_exe = executable('file-roller',
     hdy_dep,
     use_gobject_introspection ? gobject_introspection_dep : [],
     use_json_glib ? libjson_glib_dep : [],
-    use_libnotify ? libnotify_dep : [],
     use_libarchive ? libarchive_dep : []
   ],
   link_args: [


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]