Mercurial > projects > pk-update-icon
annotate main.c @ 2:847ae02bc13b
added GPLv2 headers
author | Pavol Rusnak <stick@gk2.sk> |
---|---|
date | Tue, 27 Sep 2011 02:31:31 +0200 |
parents | 483f5fe9d2b2 |
children | f8ad23e60000 |
rev | line source |
---|---|
2 | 1 /* |
2 * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk> | |
3 * | |
4 * Licensed under the GNU General Public License Version 2 | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
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 | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
20 | |
0 | 21 #include "notify.h" |
22 #include "packagekit.h" | |
23 #include <gtk/gtk.h> | |
24 | |
25 struct updates_info { | |
26 int normal; | |
27 int critical; | |
28 } UpdatesInfo; | |
29 | |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
30 GtkStatusIcon *tray_icon; |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
31 |
0 | 32 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) |
33 { | |
34 char *argv[2] = { "gpk-update-viewer", NULL }; | |
35 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); | |
36 } | |
37 | |
38 static void tray_menu_destroy(GtkWidget *menu, gpointer userdata) | |
39 { | |
40 gtk_widget_destroy(menu); | |
41 g_object_unref(menu); | |
42 } | |
43 | |
44 void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) | |
45 { | |
46 GtkWidget *item; | |
47 GtkWidget *menu = gtk_menu_new(); | |
48 item = gtk_menu_item_new_with_mnemonic("_Quit"); | |
49 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
50 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data); | |
51 gtk_widget_show(item); | |
52 g_object_ref(menu); | |
53 g_object_ref_sink(menu); | |
54 g_object_unref(menu); | |
55 g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(tray_menu_destroy), NULL); | |
56 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, user_data, button, activate_time); | |
57 gtk_widget_show_all(GTK_WIDGET(menu)); | |
58 } | |
59 | |
60 static GtkStatusIcon *create_tray_icon() | |
61 { | |
62 tray_icon = gtk_status_icon_new(); | |
63 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); | |
65 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); | |
66 gtk_status_icon_set_title(tray_icon, "Software Update"); | |
67 gtk_status_icon_set_visible(tray_icon, TRUE); | |
68 | |
69 return tray_icon; | |
70 } | |
71 | |
72 gboolean periodic_check(gpointer user_data) | |
73 { | |
74 struct UpdatesInfo info; | |
75 query_packagekit(&info); | |
76 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
|
77 if (info.critical > 0) { |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
78 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
|
79 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
|
80 } else |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
81 if (info.normal > 0) { |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
82 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
|
83 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
|
84 } |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
85 return TRUE; |
0 | 86 } |
87 | |
88 int main(int argc, char **argv) | |
89 { | |
90 GtkStatusIcon *tray_icon; | |
91 | |
92 gtk_init(&argc, &argv); | |
93 tray_icon = create_tray_icon(); | |
94 init_notify(); | |
95 | |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
96 periodic_check(NULL); |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
97 g_timeout_add(15 * 60 * 1000, periodic_check, NULL); |
0 | 98 |
99 gtk_main(); | |
100 | |
101 return 0; | |
102 } |