[gnome-software] Notify when an app is installed
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Notify when an app is installed
- Date: Thu, 5 Sep 2013 04:06:45 +0000 (UTC)
commit 47df9f6385c399ab66e73d3f6d005ed7d04610de
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Sep 5 00:06:15 2013 -0400
Notify when an app is installed
https://bugzilla.gnome.org/show_bug.cgi?id=707318
configure.ac | 3 +-
src/Makefile.am | 2 +
src/gs-application.c | 3 ++
src/gs-shell-details.c | 79 ++++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 80 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 78f0c64..2529222 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,9 +72,10 @@ GLIB_GSETTINGS
dnl ---------------------------------------------------------------------------
dnl - Check library dependencies
dnl ---------------------------------------------------------------------------
-PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.9.12)
+PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.9.12 gio-unix-2.0)
PKG_CHECK_MODULES(PACKAGEKIT, packagekit-glib2 >= 0.8.10)
PKG_CHECK_MODULES(SQLITE, sqlite3)
+PKG_CHECK_MODULES(NOTIFY, libnotify)
AC_ARG_ENABLE(man,
[AS_HELP_STRING([--enable-man],
[generate man pages [default=auto]])],,
diff --git a/src/Makefile.am b/src/Makefile.am
index f34b7e4..2803401 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@ AM_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(PACKAGEKIT_CFLAGS) \
+ $(NOTIFY_CFLAGS) \
-DG_LOG_DOMAIN=\"Gs\" \
-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \
-DLIBDIR=\"$(libdir)\" \
@@ -70,6 +71,7 @@ gnome_software_LDADD = \
$(GLIB_LIBS) \
$(GTK_LIBS) \
$(PACKAGEKIT_LIBS) \
+ $(NOTIFY_LIBS) \
-lm
gnome_software_CFLAGS = \
diff --git a/src/gs-application.c b/src/gs-application.c
index 4026f78..c13c3a9 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -27,6 +27,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <packagekit-glib2/packagekit.h>
+#include <libnotify/notify.h>
#include "gs-box.h"
#include "gs-shell.h"
@@ -121,6 +122,8 @@ gs_application_startup (GApplication *application)
G_APPLICATION_CLASS (gs_application_parent_class)->startup (application);
+ notify_init ("gnome-software");
+
g_type_ensure (GS_TYPE_BOX);
/* set up the app menu */
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index f0fc13e..9148368 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -23,6 +23,9 @@
#include <string.h>
#include <glib/gi18n.h>
+#include <gio/gdesktopappinfo.h>
+
+#include <libnotify/notify.h>
#include "gs-shell-details.h"
@@ -229,11 +232,75 @@ gs_shell_details_get_app (GsShellDetails *shell_details)
return shell_details->priv->app;
}
-/**
- * gs_shell_details_finished_func:
- **/
static void
-gs_shell_details_finished_func (GsPluginLoader *plugin_loader, GsApp *app, gpointer user_data)
+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);
+ }
+}
+
+static void
+gs_shell_details_removed_func (GsPluginLoader *plugin_loader, GsApp *app, gpointer user_data)
{
GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
gs_shell_details_refresh (shell_details);
@@ -274,7 +341,7 @@ gs_shell_details_app_remove_button_cb (GtkWidget *widget, GsShellDetails *shell_
gs_plugin_loader_app_remove (priv->plugin_loader,
priv->app,
priv->cancellable,
- gs_shell_details_finished_func,
+ gs_shell_details_removed_func,
shell_details);
}
g_string_free (markup, TRUE);
@@ -291,7 +358,7 @@ gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *shell
gs_plugin_loader_app_install (priv->plugin_loader,
priv->app,
priv->cancellable,
- gs_shell_details_finished_func,
+ gs_shell_details_installed_func,
shell_details);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]