Mercurial > projects > pk-update-icon
comparison main.c @ 3:f8ad23e60000
code rework, show notify window just once
author | Pavol Rusnak <stick@gk2.sk> |
---|---|
date | Tue, 27 Sep 2011 12:15:39 +0200 |
parents | 847ae02bc13b |
children | 58a3312a1c59 |
comparison
equal
deleted
inserted
replaced
2:847ae02bc13b | 3:f8ad23e60000 |
---|---|
16 * You should have received a copy of the GNU General Public License | 16 * You should have received a copy of the GNU General Public License |
17 * along with this program; if not, write to the Free Software | 17 * along with this program; if not, write to the Free Software |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "main.h" | |
21 #include "notify.h" | 22 #include "notify.h" |
22 #include "packagekit.h" | 23 #include "packagekit.h" |
23 #include <gtk/gtk.h> | 24 #include <gtk/gtk.h> |
24 | 25 |
25 struct updates_info { | 26 struct UpdatesInfo info; |
26 int normal; | |
27 int critical; | |
28 } UpdatesInfo; | |
29 | 27 |
30 GtkStatusIcon *tray_icon; | 28 GtkStatusIcon *tray_icon; |
31 | 29 |
32 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) | 30 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) |
33 { | 31 { |
63 g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); | 61 g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); |
64 g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); | 62 g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); |
65 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); | 63 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); |
66 gtk_status_icon_set_title(tray_icon, "Software Update"); | 64 gtk_status_icon_set_title(tray_icon, "Software Update"); |
67 gtk_status_icon_set_visible(tray_icon, TRUE); | 65 gtk_status_icon_set_visible(tray_icon, TRUE); |
68 | |
69 return tray_icon; | 66 return tray_icon; |
70 } | 67 } |
71 | 68 |
72 gboolean periodic_check(gpointer user_data) | 69 gboolean periodic_check(gpointer user_data) |
73 { | 70 { |
74 struct UpdatesInfo info; | |
75 query_packagekit(&info); | 71 query_packagekit(&info); |
76 send_notify(info.normal, info.critical); | |
77 if (info.critical > 0) { | 72 if (info.critical > 0) { |
78 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-urgent"); | 73 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-urgent"); |
79 gtk_status_icon_set_tooltip_text(tray_icon, "Critical updates available."); | 74 gtk_status_icon_set_tooltip_text(tray_icon, notify_text(&info)); |
80 } else | 75 } else |
81 if (info.normal > 0) { | 76 if (info.normal > 0) { |
82 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-available"); | 77 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-available"); |
83 gtk_status_icon_set_tooltip_text(tray_icon, "Updates available."); | 78 gtk_status_icon_set_tooltip_text(tray_icon, notify_text(&info)); |
84 } | 79 } |
85 return TRUE; | 80 return TRUE; |
86 } | 81 } |
87 | 82 |
88 int main(int argc, char **argv) | 83 int main(int argc, char **argv) |
92 gtk_init(&argc, &argv); | 87 gtk_init(&argc, &argv); |
93 tray_icon = create_tray_icon(); | 88 tray_icon = create_tray_icon(); |
94 init_notify(); | 89 init_notify(); |
95 | 90 |
96 periodic_check(NULL); | 91 periodic_check(NULL); |
97 g_timeout_add(15 * 60 * 1000, periodic_check, NULL); | 92 send_notify(&info); |
93 // update tray icon and tooltip every 2 hours | |
94 g_timeout_add_seconds(2*3600, periodic_check, NULL); | |
98 | 95 |
99 gtk_main(); | 96 gtk_main(); |
100 | 97 |
101 return 0; | 98 return 0; |
102 } | 99 } |