Mercurial > projects > pk-update-icon
comparison main.c @ 1:483f5fe9d2b2
change icon and tooltip of the tray icon
author | Pavol Rusnak <stick@gk2.sk> |
---|---|
date | Mon, 26 Sep 2011 18:59:14 +0200 |
parents | f5e03fc667f8 |
children | 847ae02bc13b |
comparison
equal
deleted
inserted
replaced
0:f5e03fc667f8 | 1:483f5fe9d2b2 |
---|---|
4 | 4 |
5 struct updates_info { | 5 struct updates_info { |
6 int normal; | 6 int normal; |
7 int critical; | 7 int critical; |
8 } UpdatesInfo; | 8 } UpdatesInfo; |
9 | |
10 GtkStatusIcon *tray_icon; | |
9 | 11 |
10 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) | 12 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) |
11 { | 13 { |
12 char *argv[2] = { "gpk-update-viewer", NULL }; | 14 char *argv[2] = { "gpk-update-viewer", NULL }; |
13 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); | 15 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); |
35 gtk_widget_show_all(GTK_WIDGET(menu)); | 37 gtk_widget_show_all(GTK_WIDGET(menu)); |
36 } | 38 } |
37 | 39 |
38 static GtkStatusIcon *create_tray_icon() | 40 static GtkStatusIcon *create_tray_icon() |
39 { | 41 { |
40 GtkStatusIcon *tray_icon; | |
41 | |
42 tray_icon = gtk_status_icon_new(); | 42 tray_icon = gtk_status_icon_new(); |
43 g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); | 43 g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); |
44 g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); | 44 g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); |
45 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); | 45 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); |
46 gtk_status_icon_set_title(tray_icon, "Software Update"); | 46 gtk_status_icon_set_title(tray_icon, "Software Update"); |
52 gboolean periodic_check(gpointer user_data) | 52 gboolean periodic_check(gpointer user_data) |
53 { | 53 { |
54 struct UpdatesInfo info; | 54 struct UpdatesInfo info; |
55 query_packagekit(&info); | 55 query_packagekit(&info); |
56 send_notify(info.normal, info.critical); | 56 send_notify(info.normal, info.critical); |
57 return FALSE; | 57 if (info.critical > 0) { |
58 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-urgent"); | |
59 gtk_status_icon_set_tooltip_text(tray_icon, "Critical updates available."); | |
60 } else | |
61 if (info.normal > 0) { | |
62 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-available"); | |
63 gtk_status_icon_set_tooltip_text(tray_icon, "Updates available."); | |
64 } | |
65 return TRUE; | |
58 } | 66 } |
59 | 67 |
60 int main(int argc, char **argv) | 68 int main(int argc, char **argv) |
61 { | 69 { |
62 GtkStatusIcon *tray_icon; | 70 GtkStatusIcon *tray_icon; |
63 | 71 |
64 gtk_init(&argc, &argv); | 72 gtk_init(&argc, &argv); |
65 tray_icon = create_tray_icon(); | 73 tray_icon = create_tray_icon(); |
66 init_notify(); | 74 init_notify(); |
67 | 75 |
68 g_timeout_add(3000, periodic_check, NULL); | 76 periodic_check(NULL); |
77 g_timeout_add(15 * 60 * 1000, periodic_check, NULL); | |
69 | 78 |
70 gtk_main(); | 79 gtk_main(); |
71 | 80 |
72 return 0; | 81 return 0; |
73 } | 82 } |