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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
1 #include "notify.h"
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
2 #include "packagekit.h"
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
3 #include <gtk/gtk.h>
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
4
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
5 struct updates_info {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
6 int normal;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
7 int critical;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
8 } UpdatesInfo;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
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
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
12 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
13 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
14 char *argv[2] = { "gpk-update-viewer", NULL };
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
15 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
16 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
17
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
18 static void tray_menu_destroy(GtkWidget *menu, gpointer userdata)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
19 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
20 gtk_widget_destroy(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
21 g_object_unref(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
22 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
23
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
24 void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
25 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
26 GtkWidget *item;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
27 GtkWidget *menu = gtk_menu_new();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
28 item = gtk_menu_item_new_with_mnemonic("_Quit");
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
29 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
30 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
31 gtk_widget_show(item);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
32 g_object_ref(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
33 g_object_ref_sink(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
34 g_object_unref(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
35 g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(tray_menu_destroy), NULL);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
36 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, user_data, button, activate_time);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
37 gtk_widget_show_all(GTK_WIDGET(menu));
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
38 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
39
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
40 static GtkStatusIcon *create_tray_icon()
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
41 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
42 tray_icon = gtk_status_icon_new();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
43 g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
44 g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
45 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update");
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
46 gtk_status_icon_set_title(tray_icon, "Software Update");
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
47 gtk_status_icon_set_visible(tray_icon, TRUE);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
48
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
49 return tray_icon;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
50 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
51
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
52 gboolean periodic_check(gpointer user_data)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
53 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
54 struct UpdatesInfo info;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
55 query_packagekit(&info);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
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
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
66 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
67
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
68 int main(int argc, char **argv)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
69 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
70 GtkStatusIcon *tray_icon;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
71
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
72 gtk_init(&argc, &argv);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
73 tray_icon = create_tray_icon();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
74 init_notify();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
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
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
78
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
79 gtk_main();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
80
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
81 return 0;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
82 }