Mercurial > projects > pk-update-icon
annotate 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 |
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 | |
3
f8ad23e60000
code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents:
2
diff
changeset
|
21 #include "main.h" |
0 | 22 #include "notify.h" |
23 #include "packagekit.h" | |
24 #include <gtk/gtk.h> | |
25 | |
3
f8ad23e60000
code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents:
2
diff
changeset
|
26 struct UpdatesInfo info; |
0 | 27 |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
28 GtkStatusIcon *tray_icon; |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
29 |
0 | 30 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) |
31 { | |
32 char *argv[2] = { "gpk-update-viewer", NULL }; | |
33 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); | |
34 } | |
35 | |
36 static void tray_menu_destroy(GtkWidget *menu, gpointer userdata) | |
37 { | |
38 gtk_widget_destroy(menu); | |
39 g_object_unref(menu); | |
40 } | |
41 | |
42 void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) | |
43 { | |
44 GtkWidget *item; | |
45 GtkWidget *menu = gtk_menu_new(); | |
46 item = gtk_menu_item_new_with_mnemonic("_Quit"); | |
47 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
48 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data); | |
49 gtk_widget_show(item); | |
50 g_object_ref(menu); | |
51 g_object_ref_sink(menu); | |
52 g_object_unref(menu); | |
53 g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(tray_menu_destroy), NULL); | |
54 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, user_data, button, activate_time); | |
55 gtk_widget_show_all(GTK_WIDGET(menu)); | |
56 } | |
57 | |
58 static GtkStatusIcon *create_tray_icon() | |
59 { | |
60 tray_icon = gtk_status_icon_new(); | |
61 g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); | |
62 g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); | |
63 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); | |
64 gtk_status_icon_set_title(tray_icon, "Software Update"); | |
65 gtk_status_icon_set_visible(tray_icon, TRUE); | |
66 return tray_icon; | |
67 } | |
68 | |
69 gboolean periodic_check(gpointer user_data) | |
70 { | |
71 query_packagekit(&info); | |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
72 if (info.critical > 0) { |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
73 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-urgent"); |
3
f8ad23e60000
code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents:
2
diff
changeset
|
74 gtk_status_icon_set_tooltip_text(tray_icon, notify_text(&info)); |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
75 } else |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
76 if (info.normal > 0) { |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
77 gtk_status_icon_set_from_icon_name(tray_icon, "software-update-available"); |
3
f8ad23e60000
code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents:
2
diff
changeset
|
78 gtk_status_icon_set_tooltip_text(tray_icon, notify_text(&info)); |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
79 } |
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
80 return TRUE; |
0 | 81 } |
82 | |
83 int main(int argc, char **argv) | |
84 { | |
85 GtkStatusIcon *tray_icon; | |
86 | |
87 gtk_init(&argc, &argv); | |
88 tray_icon = create_tray_icon(); | |
89 init_notify(); | |
90 | |
1
483f5fe9d2b2
change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents:
0
diff
changeset
|
91 periodic_check(NULL); |
3
f8ad23e60000
code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents:
2
diff
changeset
|
92 send_notify(&info); |
f8ad23e60000
code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents:
2
diff
changeset
|
93 // update tray icon and tooltip every 2 hours |
f8ad23e60000
code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents:
2
diff
changeset
|
94 g_timeout_add_seconds(2*3600, periodic_check, NULL); |
0 | 95 |
96 gtk_main(); | |
97 | |
98 return 0; | |
99 } |