diff pkui-icon.c @ 19:38b37e4a4d63

added a button for installing updates to the notification
author Guido Berhoerster <guido@berhoerster.name>
date Thu, 20 Oct 2011 13:37:50 +0200
parents 9537882d759f
children bae8a7e20382
line wrap: on
line diff
--- a/pkui-icon.c	Thu Oct 20 13:03:37 2011 +0200
+++ b/pkui-icon.c	Thu Oct 20 13:37:50 2011 +0200
@@ -43,7 +43,9 @@
 static void icon_popup_menu_popup(GtkStatusIcon *status_icon, guint button,
     guint activate_time, gpointer user_data);
 static void icon_activated(GtkStatusIcon *status_icon, gpointer user_data);
+static void hide_notification(PkuiIcon *self);
 static void backend_state_changed(PkuiBackend *backend, gpointer user_data);
+static void update_viewer_exited(GPid pid, gint status, gpointer user_data);
 
 static void
 pkui_icon_finalize(GObject *gobject)
@@ -98,6 +100,29 @@
 }
 
 static void
+exec_update_viewer(PkuiIcon *self)
+{
+	static const gchar *argv[] = { UPDATE_VIEWER_COMMAND, NULL };
+	GPid		pid;
+	gboolean	retval;
+
+	g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend));
+
+	g_debug("executing " UPDATE_VIEWER_COMMAND);
+
+	retval = g_spawn_async(NULL, (gchar **)argv, NULL,
+	    G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL);
+	if (!retval) {
+		g_warning("Could not execute" UPDATE_VIEWER_COMMAND);
+		return;
+	}
+	g_child_watch_add(pid, (GChildWatchFunc)update_viewer_exited, self);
+
+	pkui_backend_set_inhibit_check(self->priv->backend, TRUE);
+	hide_notification(self);
+}
+
+static void
 about_dialog_show(GtkMenuItem *item, gpointer user_data)
 {
 	static const gchar *copyright = "Copyright \xc2\xa9 2011 Guido "
@@ -184,6 +209,16 @@
 }
 
 static void
+notification_handle_action(NotifyNotification *notification, gchar *action,
+    gpointer user_data)
+{
+	PkuiIcon *self = PKUI_ICON(user_data);
+
+	if (strcmp(action, "install-updates") == 0)
+		exec_update_viewer(self);
+}
+
+static void
 update_notification(PkuiIcon *self, guint updates_normal,
     guint updates_important)
 {
@@ -219,14 +254,18 @@
 	gtk_status_icon_set_from_icon_name(self->priv->status_icon, icon);
 	gtk_status_icon_set_visible(self->priv->status_icon, TRUE);
 
-	if (self->priv->notification == NULL)
+	if (self->priv->notification == NULL) {
 		self->priv->notification = notify_notification_new(title,
 		    message, icon
 #if (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7)
 		    , NULL
 #endif
 		    );
-	else
+		notify_notification_add_action(self->priv->notification,
+		     "install-updates", ngettext("Install Update",
+		     "Install Updates", updates_normal + updates_important),
+		     notification_handle_action, self, NULL);
+	} else
 		notify_notification_update(self->priv->notification, title,
 		    message, icon);
 
@@ -282,22 +321,8 @@
 icon_activated(GtkStatusIcon *status_icon, gpointer user_data)
 {
 	PkuiIcon	*self = PKUI_ICON(user_data);
-	static const gchar *argv[] = { UPDATE_VIEWER_COMMAND, NULL };
-	GPid		pid;
-	gboolean	retval;
 
-	g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend));
-
-	retval = g_spawn_async(NULL, (gchar **)argv, NULL,
-	    G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL);
-	if (!retval) {
-		g_warning("Could not execute" UPDATE_VIEWER_COMMAND);
-		return;
-	}
-	g_child_watch_add(pid, (GChildWatchFunc)update_viewer_exited, self);
-
-	pkui_backend_set_inhibit_check(self->priv->backend, TRUE);
-	hide_notification(self);
+	exec_update_viewer(self);
 }
 
 PkuiIcon *