Mercurial > projects > pk-update-icon
comparison 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 |
comparison
equal
deleted
inserted
replaced
18:9537882d759f | 19:38b37e4a4d63 |
---|---|
41 | 41 |
42 static GtkWidget* icon_popup_menu_create(PkuiIcon *self); | 42 static GtkWidget* icon_popup_menu_create(PkuiIcon *self); |
43 static void icon_popup_menu_popup(GtkStatusIcon *status_icon, guint button, | 43 static void icon_popup_menu_popup(GtkStatusIcon *status_icon, guint button, |
44 guint activate_time, gpointer user_data); | 44 guint activate_time, gpointer user_data); |
45 static void icon_activated(GtkStatusIcon *status_icon, gpointer user_data); | 45 static void icon_activated(GtkStatusIcon *status_icon, gpointer user_data); |
46 static void hide_notification(PkuiIcon *self); | |
46 static void backend_state_changed(PkuiBackend *backend, gpointer user_data); | 47 static void backend_state_changed(PkuiBackend *backend, gpointer user_data); |
48 static void update_viewer_exited(GPid pid, gint status, gpointer user_data); | |
47 | 49 |
48 static void | 50 static void |
49 pkui_icon_finalize(GObject *gobject) | 51 pkui_icon_finalize(GObject *gobject) |
50 { | 52 { |
51 PkuiIcon *self = PKUI_ICON(gobject); | 53 PkuiIcon *self = PKUI_ICON(gobject); |
93 G_CALLBACK(icon_popup_menu_popup), self); | 95 G_CALLBACK(icon_popup_menu_popup), self); |
94 | 96 |
95 self->priv->notification = NULL; | 97 self->priv->notification = NULL; |
96 | 98 |
97 self->priv->backend = NULL; | 99 self->priv->backend = NULL; |
100 } | |
101 | |
102 static void | |
103 exec_update_viewer(PkuiIcon *self) | |
104 { | |
105 static const gchar *argv[] = { UPDATE_VIEWER_COMMAND, NULL }; | |
106 GPid pid; | |
107 gboolean retval; | |
108 | |
109 g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend)); | |
110 | |
111 g_debug("executing " UPDATE_VIEWER_COMMAND); | |
112 | |
113 retval = g_spawn_async(NULL, (gchar **)argv, NULL, | |
114 G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL); | |
115 if (!retval) { | |
116 g_warning("Could not execute" UPDATE_VIEWER_COMMAND); | |
117 return; | |
118 } | |
119 g_child_watch_add(pid, (GChildWatchFunc)update_viewer_exited, self); | |
120 | |
121 pkui_backend_set_inhibit_check(self->priv->backend, TRUE); | |
122 hide_notification(self); | |
98 } | 123 } |
99 | 124 |
100 static void | 125 static void |
101 about_dialog_show(GtkMenuItem *item, gpointer user_data) | 126 about_dialog_show(GtkMenuItem *item, gpointer user_data) |
102 { | 127 { |
182 gtk_menu_popup(GTK_MENU(self->priv->status_icon_popup_menu), NULL, NULL, | 207 gtk_menu_popup(GTK_MENU(self->priv->status_icon_popup_menu), NULL, NULL, |
183 NULL, NULL, button, activate_time); | 208 NULL, NULL, button, activate_time); |
184 } | 209 } |
185 | 210 |
186 static void | 211 static void |
212 notification_handle_action(NotifyNotification *notification, gchar *action, | |
213 gpointer user_data) | |
214 { | |
215 PkuiIcon *self = PKUI_ICON(user_data); | |
216 | |
217 if (strcmp(action, "install-updates") == 0) | |
218 exec_update_viewer(self); | |
219 } | |
220 | |
221 static void | |
187 update_notification(PkuiIcon *self, guint updates_normal, | 222 update_notification(PkuiIcon *self, guint updates_normal, |
188 guint updates_important) | 223 guint updates_important) |
189 { | 224 { |
190 gchar *message; | 225 gchar *message; |
191 gchar *title = updates_important ? | 226 gchar *title = updates_important ? |
217 | 252 |
218 gtk_status_icon_set_tooltip(self->priv->status_icon, message); | 253 gtk_status_icon_set_tooltip(self->priv->status_icon, message); |
219 gtk_status_icon_set_from_icon_name(self->priv->status_icon, icon); | 254 gtk_status_icon_set_from_icon_name(self->priv->status_icon, icon); |
220 gtk_status_icon_set_visible(self->priv->status_icon, TRUE); | 255 gtk_status_icon_set_visible(self->priv->status_icon, TRUE); |
221 | 256 |
222 if (self->priv->notification == NULL) | 257 if (self->priv->notification == NULL) { |
223 self->priv->notification = notify_notification_new(title, | 258 self->priv->notification = notify_notification_new(title, |
224 message, icon | 259 message, icon |
225 #if (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7) | 260 #if (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7) |
226 , NULL | 261 , NULL |
227 #endif | 262 #endif |
228 ); | 263 ); |
229 else | 264 notify_notification_add_action(self->priv->notification, |
265 "install-updates", ngettext("Install Update", | |
266 "Install Updates", updates_normal + updates_important), | |
267 notification_handle_action, self, NULL); | |
268 } else | |
230 notify_notification_update(self->priv->notification, title, | 269 notify_notification_update(self->priv->notification, title, |
231 message, icon); | 270 message, icon); |
232 | 271 |
233 notify_notification_set_timeout(self->priv->notification, | 272 notify_notification_set_timeout(self->priv->notification, |
234 NOTIFY_EXPIRES_NEVER); | 273 NOTIFY_EXPIRES_NEVER); |
280 | 319 |
281 static void | 320 static void |
282 icon_activated(GtkStatusIcon *status_icon, gpointer user_data) | 321 icon_activated(GtkStatusIcon *status_icon, gpointer user_data) |
283 { | 322 { |
284 PkuiIcon *self = PKUI_ICON(user_data); | 323 PkuiIcon *self = PKUI_ICON(user_data); |
285 static const gchar *argv[] = { UPDATE_VIEWER_COMMAND, NULL }; | 324 |
286 GPid pid; | 325 exec_update_viewer(self); |
287 gboolean retval; | |
288 | |
289 g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend)); | |
290 | |
291 retval = g_spawn_async(NULL, (gchar **)argv, NULL, | |
292 G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL); | |
293 if (!retval) { | |
294 g_warning("Could not execute" UPDATE_VIEWER_COMMAND); | |
295 return; | |
296 } | |
297 g_child_watch_add(pid, (GChildWatchFunc)update_viewer_exited, self); | |
298 | |
299 pkui_backend_set_inhibit_check(self->priv->backend, TRUE); | |
300 hide_notification(self); | |
301 } | 326 } |
302 | 327 |
303 PkuiIcon * | 328 PkuiIcon * |
304 pkui_icon_new(guint startup_delay, guint check_interval) | 329 pkui_icon_new(guint startup_delay, guint check_interval) |
305 { | 330 { |