Mercurial > projects > pk-update-icon
annotate 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 |
rev | line source |
---|---|
0 | 1 #include "notify.h" |
2 #include "packagekit.h" | |
3 #include <gtk/gtk.h> | |
4 | |
5 struct updates_info { | |
6 int normal; | |
7 int critical; | |
8 } UpdatesInfo; | |
9 | |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
10 GtkStatusIcon *tray_icon; |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
11 |
0 | 12 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) |
13 { | |
14 char *argv[2] = { "gpk-update-viewer", NULL }; | |
15 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); | |
16 } | |
17 | |
18 static void tray_menu_destroy(GtkWidget *menu, gpointer userdata) | |
19 { | |
20 gtk_widget_destroy(menu); | |
21 g_object_unref(menu); | |
22 } | |
23 | |
24 void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) | |
25 { | |
26 GtkWidget *item; | |
27 GtkWidget *menu = gtk_menu_new(); | |
28 item = gtk_menu_item_new_with_mnemonic("_Quit"); | |
29 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
30 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data); | |
31 gtk_widget_show(item); | |
32 g_object_ref(menu); | |
33 g_object_ref_sink(menu); | |
34 g_object_unref(menu); | |
35 g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(tray_menu_destroy), NULL); | |
36 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, user_data, button, activate_time); | |
37 gtk_widget_show_all(GTK_WIDGET(menu)); | |
38 } | |
39 | |
40 static GtkStatusIcon *create_tray_icon() | |
41 { | |
42 tray_icon = gtk_status_icon_new(); | |
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); | |
45 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); | |
46 gtk_status_icon_set_title(tray_icon, "Software Update"); | |
47 gtk_status_icon_set_visible(tray_icon, TRUE); | |
48 | |
49 return tray_icon; | |
50 } | |
51 | |
52 gboolean periodic_check(gpointer user_data) | |
53 { | |
54 struct UpdatesInfo info; | |
55 query_packagekit(&info); | |
56 send_notify(info.normal, info.critical); | |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
57 if (info.critical > 0) { |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
58 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-urgent"); |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
59 gtk_status_icon_set_tooltip_text(tray_icon, "Critical updates available."); |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
60 } else |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
61 if (info.normal > 0) { |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
62 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-available"); |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
63 gtk_status_icon_set_tooltip_text(tray_icon, "Updates available."); |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
64 } |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
65 return TRUE; |
0 | 66 } |
67 | |
68 int main(int argc, char **argv) | |
69 { | |
70 GtkStatusIcon *tray_icon; | |
71 | |
72 gtk_init(&argc, &argv); | |
73 tray_icon = create_tray_icon(); | |
74 init_notify(); | |
75 | |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
76 periodic_check(NULL); |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
77 g_timeout_add(15 * 60 * 1000, periodic_check, NULL); |
0 | 78 |
79 gtk_main(); | |
80 | |
81 return 0; | |
82 } |