[gnome-software] Move notify install code to gs-utils



commit 205299a49a413c71085189da8b71382b429cb781
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Sep 5 07:35:09 2013 -0400

    Move notify install code to gs-utils
    
    This will let us share the code with all places where we
    install applications.

 src/gs-shell-details.c |   61 +--------------------------------------------
 src/gs-utils.c         |   63 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-utils.h         |    4 +++
 3 files changed, 69 insertions(+), 59 deletions(-)
---
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 9148368..892df86 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -23,9 +23,8 @@
 
 #include <string.h>
 #include <glib/gi18n.h>
-#include <gio/gdesktopappinfo.h>
 
-#include <libnotify/notify.h>
+#include "gs-utils.h"
 
 #include "gs-shell-details.h"
 
@@ -233,69 +232,13 @@ gs_shell_details_get_app (GsShellDetails *shell_details)
 }
 
 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);
-}
-
-static void
-gs_shell_details_notify_app_installed (GsShellDetails *shell, GsApp *app)
-{
-        gchar *summary;
-        NotifyNotification *n;
-
-        summary = g_strdup_printf (_("%s is now installed"), gs_app_get_name (app));
-        n = notify_notification_new (summary, NULL, "system-software-install");
-        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_free (summary);
-}
-
-static void
 gs_shell_details_installed_func (GsPluginLoader *plugin_loader, GsApp *app, gpointer user_data)
 {
        GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
        gs_shell_details_refresh (shell_details);
 
         if (app) {
-                gs_shell_details_notify_app_installed (shell_details, app);
+                gs_app_notify_installed (app);
         }
 }
 
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 07e8d68..999dc2a 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -21,6 +21,11 @@
 
 #include "config.h"
 
+#include <glib/gi18n.h>
+#include <gio/gdesktopappinfo.h>
+#include <libnotify/notify.h>
+
+#include "gs-app.h"
 #include "gs-utils.h"
 
 #define SPINNER_DELAY 500
@@ -109,3 +114,61 @@ gs_grab_focus_when_mapped (GtkWidget *widget)
                 g_signal_connect_after (widget, "map",
                                         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;
+
+        summary = g_strdup_printf (_("%s is now installed"), gs_app_get_name (app));
+        n = notify_notification_new (summary, NULL, "system-software-install");
+        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_free (summary);
+}
+
diff --git a/src/gs-utils.h b/src/gs-utils.h
index c60e9a9..2deda32 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -24,6 +24,8 @@
 
 #include <gtk/gtk.h>
 
+#include "gs-app.h"
+
 G_BEGIN_DECLS
 
 void gs_start_spinner (GtkSpinner *spinner);
@@ -31,6 +33,8 @@ void gs_stop_spinner (GtkSpinner *spinner);
 void gs_container_remove_all (GtkContainer *container);
 void gs_grab_focus_when_mapped (GtkWidget *widget);
 
+void gs_app_notify_installed (GsApp *app);
+
 G_END_DECLS
 
 #endif /* __GS_UTILS_H */


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