[gnome-software] Use GNotification



commit 6382283b8290401fe27d191c30bbdf48b9fb679a
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 21 19:59:51 2013 -0400

    Use GNotification
    
    This new API needs testers, and we're volunteering...
    
    This bumps the GLib dependency to 2.39.0

 configure.ac            |    2 +-
 src/gs-application.c    |   42 ++++++++++++++++++++++++++++++---
 src/gs-update-monitor.c |   58 +++++++---------------------------------------
 src/gs-utils.c          |   53 +++++--------------------------------------
 4 files changed, 54 insertions(+), 101 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8de8568..093a868 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,7 +65,7 @@ GETTEXT_PACKAGE=AC_PACKAGE_NAME
 AC_SUBST(GETTEXT_PACKAGE)
 AC_DEFINE(GETTEXT_PACKAGE, "AC_PACKAGE_NAME", [gnome-software])
 
-AM_PATH_GLIB_2_0(2.31.10, :, AC_MSG_ERROR([GLib is required]), gobject gmodule gio)
+AM_PATH_GLIB_2_0(2.39.0, :, AC_MSG_ERROR([GLib is required]), gobject gmodule gio)
 AM_GLIB_GNU_GETTEXT
 GLIB_GSETTINGS
 
diff --git a/src/gs-application.c b/src/gs-application.c
index 199c429..988d667 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -27,7 +27,7 @@
 #include <stdlib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <libnotify/notify.h>
+#include <gio/gdesktopappinfo.h>
 
 #include "gs-box.h"
 #include "gs-shell.h"
@@ -335,6 +335,40 @@ details_activated (GSimpleAction *action,
        gs_shell_show_search_result (app->shell, id, search);
 }
 
+static void
+launch_activated (GSimpleAction *action,
+                 GVariant      *parameter,
+                 gpointer       data)
+{
+       const gchar *id;
+       gchar *desktop_id;
+       GdkDisplay *display;
+       GAppInfo *appinfo;
+       GAppLaunchContext *context;
+       GError *error = NULL;
+
+       id = g_variant_get_string (parameter, NULL);
+       display = gdk_display_get_default ();
+       desktop_id = g_strconcat (id, ".desktop", NULL);
+       appinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));
+       if (!appinfo) {
+               g_warning ("no such desktop file: %s", desktop_id);
+               goto out;
+       }
+
+       context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
+       if (!g_app_info_launch (appinfo, NULL, context, &error)) {
+               g_warning ("launching %s failed: %s", id, error->message);
+               g_error_free (error);
+       }
+
+       g_object_unref (appinfo);
+       g_object_unref (context);
+
+out:
+       g_free (desktop_id);
+}
+
 static GActionEntry actions[] = {
        { "about", about_activated, NULL, NULL, NULL },
        { "quit", quit_activated, NULL, NULL, NULL },
@@ -342,7 +376,9 @@ static GActionEntry actions[] = {
        { "set-mode", set_mode_activated, "s", NULL, NULL },
        { "search", search_activated, "s", NULL, NULL },
        { "set-debug-level", set_debug_level_activated, "i", NULL, NULL },
-       { "details", details_activated, "(ss)", NULL, NULL }
+       { "details", details_activated, "(ss)", NULL, NULL },
+       { "launch", launch_activated, "s", NULL, NULL },
+       { "nop", NULL, NULL, NULL }
 };
 
 static void
@@ -350,8 +386,6 @@ gs_application_startup (GApplication *application)
 {
        G_APPLICATION_CLASS (gs_application_parent_class)->startup (application);
 
-       notify_init ("gnome-software");
-
        g_type_ensure (GS_TYPE_BOX);
 
        g_action_map_add_action_entries (G_ACTION_MAP (application),
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 4e20d16..e7a6806 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -24,7 +24,6 @@
 
 #include <string.h>
 #include <glib/gi18n.h>
-#include <libnotify/notify.h>
 
 #include "gs-update-monitor.h"
 
@@ -45,22 +44,6 @@ struct _GsUpdateMonitorClass {
 
 G_DEFINE_TYPE (GsUpdateMonitor, gs_update_monitor, G_TYPE_OBJECT)
 
-static void
-offline_update_action_cb (NotifyNotification *notification,
-                         gchar              *action,
-                         gpointer            user_data)
-{
-       GsUpdateMonitor *monitor = user_data;
-
-       notify_notification_close (notification, NULL);
-
-       if (g_strcmp0 (action, "view") == 0) {
-               g_action_group_activate_action (G_ACTION_GROUP (monitor->application),
-                                               "set-mode",
-                                               g_variant_new_string ("updates"));
-       }
-}
-
 static gboolean
 reenable_offline_update (gpointer data)
 {
@@ -72,19 +55,11 @@ reenable_offline_update (gpointer data)
 }
 
 static void
-on_notification_closed (NotifyNotification *notification, gpointer data)
-{
-       g_object_unref (notification);
-}
-
-static void
 notify_offline_update_available (GsUpdateMonitor *monitor)
 {
-       NotifyNotification *notification;
+       GNotification *n;
        const gchar *title;
        const gchar *body;
-       gboolean ret;
-       GError *error = NULL;
 
        if (!g_file_query_exists (monitor->offline_update_file, NULL))
                return;
@@ -97,30 +72,15 @@ notify_offline_update_available (GsUpdateMonitor *monitor)
        /* don't notify more often than every 5 minutes */
        g_timeout_add_seconds (300, reenable_offline_update, monitor);
 
-       title = _("Software Updates available");
+       title = _("Software Updates Available");
        body = _("Important OS and application updates are ready to be installed");
-       notification = notify_notification_new (title, body,
-                                               GSD_UPDATES_ICON_NORMAL);
-       notify_notification_set_hint_string (notification, "desktop-entry", "gnome-software");
-       notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
-       notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
-       notify_notification_add_action (notification, "ignore",
-                                       /* TRANSLATORS: don't install updates now */
-                                       _("Not Now"),
-                                       offline_update_action_cb,
-                                       monitor, NULL);
-       notify_notification_add_action (notification, "view",
-                                               /* TRANSLATORS: view available updates */
-                                       _("View"),
-                                       offline_update_action_cb,
-                                       monitor, NULL);
-       g_signal_connect (notification, "closed",
-                         G_CALLBACK (on_notification_closed), NULL);
-       ret = notify_notification_show (notification, &error);
-       if (!ret) {
-               g_warning ("error: %s", error->message);
-               g_error_free (error);
-       }
+       n = g_notification_new (title);
+       g_notification_set_body (n, body);
+       g_notification_add_button_with_target (n, _("View"), "app.set-mode", "s", "updates");
+       g_notification_add_button (n, _("Not Now"), "app.nop");
+       g_notification_set_default_action_and_target (n, "app.set-mode", "s", "updates");
+       g_application_send_notification (g_application_get_default (), "updates-available", n);
+       g_object_unref (n);
 }
 
 static void
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 697169b..82b50b8 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -23,7 +23,6 @@
 
 #include <glib/gi18n.h>
 #include <gio/gdesktopappinfo.h>
-#include <libnotify/notify.h>
 #include <errno.h>
 
 #include "gs-app.h"
@@ -117,61 +116,21 @@ gs_grab_focus_when_mapped (GtkWidget *widget)
                                        G_CALLBACK (grab_focus), NULL);
 }
 
-static void
-launch_app (NotifyNotification *n, gchar *action, gpointer data)
-{
-       GsApp *app = data;
-       GdkDisplay *display;
-       GAppLaunchContext *context;
-       gchar *id;
-       GAppInfo *appinfo;
-       GError *error = NULL;
-
-       notify_notification_close (n, NULL);
-       if (g_strcmp0 (action, "launch") == 0) {
-               display = gdk_display_get_default ();
-               id = g_strconcat (gs_app_get_id (app), ".desktop", NULL);
-               appinfo = G_APP_INFO (g_desktop_app_info_new (id));
-               if (!appinfo) {
-                       g_warning ("no such desktop file: %s", id);
-                       goto out;
-               }
-               g_free (id);
-
-               context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
-               if (!g_app_info_launch (appinfo, NULL, context, &error)) {
-                       g_warning ("launching %s failed: %s",
-                                  gs_app_get_id (app), error->message);
-                       g_error_free (error);
-               }
-
-               g_object_unref (appinfo);
-               g_object_unref (context);
-       }
-out: ;
-}
-
-static void
-on_notification_closed (NotifyNotification *n, gpointer data)
-{
-       g_object_unref (n);
-}
-
 void
 gs_app_notify_installed (GsApp *app)
 {
        gchar *summary;
-       NotifyNotification *n;
+       GNotification *n;
 
        /* TRANSLATORS: this is the summary of a notification that an application
         * has been successfully installed */
        summary = g_strdup_printf (_("%s is now installed"), gs_app_get_name (app));
-       n = notify_notification_new (summary, NULL, "gnome-software");
+       n = g_notification_new (summary);
        /* TRANSLATORS: this is button that opens the newly installed application */
-       notify_notification_add_action (n, "launch", _("Launch"),
-                                       launch_app, g_object_ref (app), g_object_unref);
-       g_signal_connect (n, "closed", G_CALLBACK (on_notification_closed), NULL);
-       notify_notification_show (n, NULL);
+       g_notification_add_button_with_target (n, _("Launch"), "app.launch", "s", gs_app_get_id (app));
+       g_notification_set_default_action_and_target  (n, "app.details", "(ss)", gs_app_get_id (app), ""); 
+       g_application_send_notification (g_application_get_default (), "installed", n);
+       g_object_unref (n);
 
        g_free (summary);
 }


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