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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
1 /*
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
2 * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
3 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
4 * Licensed under the GNU General Public License Version 2
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
5 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
6 * This program is free software; you can redistribute it and/or modify
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
7 * it under the terms of the GNU General Public License as published by
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
9 * (at your option) any later version.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
10 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
11 * This program is distributed in the hope that it will be useful,
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
14 * GNU General Public License for more details.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
15 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
16 * You should have received a copy of the GNU General Public License
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
17 * along with this program; if not, write to the Free Software
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
19 */
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
20
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
21 #include "notify.h"
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
22 #include "packagekit.h"
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
23 #include <gtk/gtk.h>
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
24
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
25 struct updates_info {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
26 int normal;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
27 int critical;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
28 } UpdatesInfo;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
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
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
32 void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
33 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
34 char *argv[2] = { "gpk-update-viewer", NULL };
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
35 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
36 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
37
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
38 static void tray_menu_destroy(GtkWidget *menu, gpointer userdata)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
39 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
40 gtk_widget_destroy(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
41 g_object_unref(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
42 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
43
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
44 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
45 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
46 GtkWidget *item;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
47 GtkWidget *menu = gtk_menu_new();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
48 item = gtk_menu_item_new_with_mnemonic("_Quit");
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
49 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
50 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
51 gtk_widget_show(item);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
52 g_object_ref(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
53 g_object_ref_sink(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
54 g_object_unref(menu);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
55 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
56 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
57 gtk_widget_show_all(GTK_WIDGET(menu));
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
58 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
59
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
60 static GtkStatusIcon *create_tray_icon()
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
61 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
62 tray_icon = gtk_status_icon_new();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
63 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
64 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
65 gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update");
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
66 gtk_status_icon_set_title(tray_icon, "Software Update");
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
67 gtk_status_icon_set_visible(tray_icon, TRUE);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
68
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
69 return tray_icon;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
70 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
71
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
72 gboolean periodic_check(gpointer user_data)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
73 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
74 struct UpdatesInfo info;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
75 query_packagekit(&info);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
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
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
86 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
87
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
88 int main(int argc, char **argv)
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
89 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
90 GtkStatusIcon *tray_icon;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
91
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
92 gtk_init(&argc, &argv);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
93 tray_icon = create_tray_icon();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
94 init_notify();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
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
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
98
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
99 gtk_main();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
100
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
101 return 0;
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
102 }