Mercurial > projects > pk-update-icon
comparison main.c @ 0:f5e03fc667f8
initial commit
author | Pavol Rusnak <stick@gk2.sk> |
---|---|
date | Mon, 26 Sep 2011 18:52:04 +0200 |
parents | |
children | 483f5fe9d2b2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f5e03fc667f8 |
---|---|
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 | |
10 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) | |
11 { | |
12 char *argv[2] = { "gpk-update-viewer", NULL }; | |
13 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); | |
14 } | |
15 | |
16 static void tray_menu_destroy(GtkWidget *menu, gpointer userdata) | |
17 { | |
18 gtk_widget_destroy(menu); | |
19 g_object_unref(menu); | |
20 } | |
21 | |
22 void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) | |
23 { | |
24 GtkWidget *item; | |
25 GtkWidget *menu = gtk_menu_new(); | |
26 item = gtk_menu_item_new_with_mnemonic("_Quit"); | |
27 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
28 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data); | |
29 gtk_widget_show(item); | |
30 g_object_ref(menu); | |
31 g_object_ref_sink(menu); | |
32 g_object_unref(menu); | |
33 g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(tray_menu_destroy), NULL); | |
34 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, user_data, button, activate_time); | |
35 gtk_widget_show_all(GTK_WIDGET(menu)); | |
36 } | |
37 | |
38 static GtkStatusIcon *create_tray_icon() | |
39 { | |
40 GtkStatusIcon *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); | |
57 return FALSE; | |
58 } | |
59 | |
60 int main(int argc, char **argv) | |
61 { | |
62 GtkStatusIcon *tray_icon; | |
63 | |
64 gtk_init(&argc, &argv); | |
65 tray_icon = create_tray_icon(); | |
66 init_notify(); | |
67 | |
68 g_timeout_add(3000, periodic_check, NULL); | |
69 | |
70 gtk_main(); | |
71 | |
72 return 0; | |
73 } |