[epiphany] Replace libnotify with GNotification



commit 9125af24790cbe044b5cbaa0210495a11d557737
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Sat Apr 25 14:48:35 2020 +0200

    Replace libnotify with GNotification
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1168

 meson.build           |  1 -
 src/ephy-main.c       |  6 ------
 src/ephy-shell.c      | 16 ++++++++++++++++
 src/meson.build       |  3 +--
 src/window-commands.c | 48 +++++++++++++++++-------------------------------
 5 files changed, 34 insertions(+), 40 deletions(-)
---
diff --git a/meson.build b/meson.build
index b2143440d..8242853ce 100644
--- a/meson.build
+++ b/meson.build
@@ -93,7 +93,6 @@ iso_codes_dep = dependency('iso-codes', version: '>= 0.35')
 json_glib_dep = dependency('json-glib-1.0', version: '>= 1.2.4')
 libdazzle_dep = dependency('libdazzle-1.0', version: '>= 3.35.3')
 libhandy_dep = dependency('libhandy-0.0', version: '>= 0.0.10')
-libnotify_dep = dependency('libnotify', version: '>= 0.5.1')
 libsecret_dep = dependency('libsecret-1', version: '>= 0.19.0')
 libsoup_dep = dependency('libsoup-2.4', version: '>= 2.48.0')
 libxml_dep = dependency('libxml-2.0', version: '>= 2.6.12')
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 0f2f79bea..8466c6c1a 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -37,7 +37,6 @@
 #include <gtk/gtk.h>
 #define HANDY_USE_UNSTABLE_API
 #include <handy.h>
-#include <libnotify/notify.h>
 #include <libxml/xmlreader.h>
 #include <libxml/xmlversion.h>
 #include <signal.h>
@@ -191,8 +190,6 @@ main (int   argc,
    */
   LIBXML_TEST_VERSION;
 
-  notify_init ("epiphany");
-
   /* If we're given -remote arguments, translate them */
   if (argc >= 2 && strcmp (argv[1], "-remote") == 0) {
     const char *opening, *closing;
@@ -432,9 +429,6 @@ main (int   argc,
   g_free (desktop_file_basename);
   g_free (profile_directory);
 
-  if (notify_is_initted ())
-    notify_uninit ();
-
   ephy_settings_shutdown ();
   ephy_file_helpers_shutdown ();
   xmlCleanupParser ();
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 2d0dd8997..6a9af5932 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -290,6 +290,21 @@ show_downloads (GSimpleAction *action,
   g_signal_emit_by_name (manager, "show-downloads", NULL);
 }
 
+static void
+launch_app (GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
+{
+  const gchar *desktop_file = g_variant_get_string (parameter, NULL);
+
+  /* We can't get here under flatpak because all web app functionality
+   * is disabled when running under flatpak.
+   */
+  ephy_file_launch_desktop_file (desktop_file,
+                                 gtk_get_current_event_time (),
+                                 EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+}
+
 static GActionEntry app_entries[] = {
   { "new-window", new_window, NULL, NULL, NULL },
   { "new-incognito", new_incognito_window, NULL, NULL, NULL },
@@ -302,6 +317,7 @@ static GActionEntry app_entries[] = {
   { "about", show_about, NULL, NULL, NULL },
   { "quit", quit_application, NULL, NULL, NULL },
   { "show-downloads", show_downloads, NULL, NULL, NULL },
+  { "launch-app", launch_app, "s", NULL, NULL },
 };
 
 static GActionEntry non_incognito_extra_app_entries[] = {
diff --git a/src/meson.build b/src/meson.build
index a4d67ae2d..2a97287dd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -65,8 +65,7 @@ libephymain_deps = [
   ephywidgets_dep,
   gdk_dep,
   gvdb_dep,
-  libhandy_dep,
-  libnotify_dep
+  libhandy_dep
 ]
 
 libephymain_includes = include_directories(
diff --git a/src/window-commands.c b/src/window-commands.c
index 072c81b6a..397cf42fe 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -60,7 +60,6 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <libnotify/notify.h>
 #include <libsoup/soup.h>
 #include <string.h>
 #include <webkit2/webkit2.h>
@@ -1472,21 +1471,6 @@ fill_mobile_capable (EphyApplicationDialogData *data)
   ephy_web_view_get_web_app_mobile_capable (data->view, data->cancellable, fill_mobile_capable_cb, data);
 }
 
-static void
-notify_launch_cb (NotifyNotification *notification,
-                  char               *action,
-                  gpointer            user_data)
-{
-  g_autofree char *desktop_file = user_data;
-
-  /* We can't get here under flatpak because all web app functionality
-   * is disabled when running under flatpak.
-   */
-  ephy_file_launch_desktop_file (desktop_file,
-                                 gtk_get_current_event_time (),
-                                 EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
-}
-
 static gboolean
 confirm_web_application_overwrite (GtkWindow  *parent,
                                    const char *title)
@@ -1578,8 +1562,8 @@ dialog_save_as_application_response_cb (GtkDialog                 *dialog,
     const char *app_name;
     g_autofree gchar *app_id = NULL;
     g_autofree gchar *desktop_file = NULL;
-    char *message;
-    NotifyNotification *notification;
+    g_autofree char *message = NULL;
+    GNotification *notification;
 
     app_name = gtk_entry_get_text (GTK_ENTRY (data->entry));
     app_id = ephy_web_application_get_app_id_from_name (app_name);
@@ -1605,25 +1589,27 @@ dialog_save_as_application_response_cb (GtkDialog                 *dialog,
       message = g_strdup_printf (_("The application ā€œ%sā€ could not be created"),
                                  app_name);
 
-    notification = notify_notification_new (message,
-                                            NULL, NULL);
-    g_free (message);
+    notification = g_notification_new (message);
+
+    if (data->image) {
+      GdkPixbuf *pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (data->image));
+
+      g_notification_set_icon (notification, G_ICON (pixbuf));
+    }
 
     if (desktop_file) {
-      notify_notification_add_action (notification, "launch", _("Launch"),
-                                      (NotifyActionCallback)notify_launch_cb,
-                                      g_path_get_basename (desktop_file),
-                                      NULL);
-      notify_notification_set_icon_from_pixbuf (notification, gtk_image_get_pixbuf (GTK_IMAGE 
(data->image)));
+      g_autofree char *basename = g_path_get_basename (desktop_file);
+
+      /* Translators: Desktop notification when a new web app is created. */
+      g_notification_add_button_with_target (notification, _("Launch"), "app.launch-app", "s", basename);
+      g_notification_set_default_action_and_target (notification, "app.launch-app", "s", basename);
 
       ephy_focus_desktop_app (desktop_file);
     }
 
-    notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
-    notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
-    notify_notification_set_hint (notification, "desktop-entry", g_variant_new_string ("epiphany"));
-    notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE));
-    notify_notification_show (notification, NULL);
+    g_notification_set_priority (notification, G_NOTIFICATION_PRIORITY_LOW);
+
+    g_application_send_notification (G_APPLICATION (g_application_get_default ()), app_name, notification);
   }
 
   ephy_application_dialog_data_free (data);


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