2
* Copyright (C) 2004 Lukas Lipka <lukas@pmad.net>
3
* (C) 2004 Michael Vogt <mvo@debian.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
24
#include <glade/glade.h>
25
#include "eggtrayicon.h"
27
#define ICON_FILE PACKAGE_DATA_DIR"/pixmaps/upgrade-notifier.png"
28
#define UPGRADE_CHECKER PACKAGE_LIB_DIR"/upgrade-notifier/apt-check"
29
#define PACKAGE_MANAGER "/usr/sbin/synaptic"
31
const char * gksu_message = _("Please enter the root password to start the package manager");
33
// tick is each (1/1000)sec
34
#define TIMEOUT 1000*60*60
36
EggTrayIcon *tray_icon = NULL;
37
GtkWidget *icon = NULL;
38
GtkWidget *box = NULL;
39
GtkTooltips *tt = NULL;
40
GtkWidget *menu = NULL;
44
GString *all_upgrades = NULL;
47
static void start_package_manager()
50
cmd = g_strdup_printf("gksu -u root -m \"%s\" "
51
" \"%s ; killall -HUP upgrade-notifier \" &",
52
gksu_message, PACKAGE_MANAGER);
57
static void create_menu ()
61
menu = gtk_menu_new ();
63
menuitem = gtk_menu_item_new_with_label (_("Start package manager"));
64
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
65
g_signal_connect (G_OBJECT (menuitem), "activate",
66
G_CALLBACK (start_package_manager), 0);
68
menuitem = gtk_separator_menu_item_new ();
69
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
71
menuitem = gtk_menu_item_new_with_label (_("Exit"));
72
g_signal_connect (G_OBJECT (menuitem), "activate",
73
G_CALLBACK (gtk_main_quit), 0);
74
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
76
gtk_widget_show_all (menu);
79
static void tray_icon_load ()
83
pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (icon));
86
g_object_unref (G_OBJECT (pixbuf));
88
pixbuf = gdk_pixbuf_new_from_file (ICON_FILE, NULL);
90
gtk_image_set_from_pixbuf (GTK_IMAGE (icon), pixbuf);
93
gtk_image_set_from_stock(GTK_IMAGE(icon),
95
GTK_ICON_SIZE_SMALL_TOOLBAR);
99
gtk_widget_hide(icon);
102
static void clicked (GtkWidget *widget, GdkEventButton *event, gpointer data)
104
GtkWidget *view, *dia;
105
GtkTextBuffer *buffer;
108
if(event->button == 1 && event->type==GDK_2BUTTON_PRESS) {
110
//xml = glade_xml_new("upgrade-dialog.glade",NULL, NULL);
111
dia = glade_xml_get_widget(xml, "dialog_upgrades");
113
view = glade_xml_get_widget(xml, "textview_upgrades");
114
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
115
gtk_text_buffer_set_text (buffer, all_upgrades->str, -1);
117
if(gtk_dialog_run(dia) == GTK_RESPONSE_OK)
118
start_package_manager();
119
gtk_widget_hide (dia);
122
if(event->button == 3)
123
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
124
event->button, event->time);
130
tt = gtk_tooltips_new();
134
xml = glade_xml_new(PACKAGE_LIB_DIR"/upgrade-notifier/upgrade-dialog.glade",NULL, NULL);
136
tray_icon = egg_tray_icon_new ("apt upgrade-notifier");
137
box = gtk_event_box_new ();
138
icon = gtk_image_new ();
140
gtk_container_add (GTK_CONTAINER (box), icon);
141
gtk_container_add (GTK_CONTAINER (tray_icon), box);
142
gtk_widget_show_all (GTK_WIDGET (tray_icon));
144
g_signal_connect (G_OBJECT (box), "button-press-event",
145
G_CALLBACK (clicked), NULL);
153
pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (icon));
155
g_object_unref (G_OBJECT (pixbuf));
156
gtk_widget_destroy (icon);
157
gtk_widget_destroy (GTK_WIDGET (tray_icon));
161
void timer(gpointer data)
166
if(all_upgrades != NULL)
167
g_string_free(all_upgrades, TRUE);
168
all_upgrades = g_string_new("");
170
FILE *f = popen(UPGRADE_CHECKER,"r");
172
gboolean upgrade_available = FALSE;
173
while( fgets(s, 400, f) != NULL) {
174
strarray = g_strsplit(s," ", 0);
175
g_string_append(all_upgrades, strarray[1]);
176
g_string_append(all_upgrades, "\n");
177
g_strfreev(strarray);
183
if(num_upgrades > 0) {
185
s = g_strdup_printf(_("%i system upgrades available"), num_upgrades);
186
gtk_tooltips_set_tip(tt, GTK_WIDGET(box), s, NULL);
188
gtk_widget_show(icon);
190
gtk_widget_hide(icon);
194
void sighup_handler(int j, siginfo_t *i, void *d)
196
//g_print("sighub_handler\n");
202
int main (int argc, char *argv[])
205
gnome_program_init ("upgrade-notifier", "0.3", LIBGNOMEUI_MODULE,
206
argc, argv, GNOME_PARAM_NONE);
208
client = gnome_master_client ();
209
gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY);
210
// make sure we die if the session dies
211
gtk_signal_connect (GTK_OBJECT (client), "die",
212
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
214
struct sigaction new_act;
215
memset( &new_act, 0, sizeof( new_act ) );
216
new_act.sa_handler = sighup_handler;
217
sigaction( SIGHUP, &new_act, NULL);
219
// create icons and menu
222
// fire timer up once, then set timeout
224
timer_id = gtk_timeout_add(TIMEOUT, (GtkFunction)timer, NULL);
226
// run, the eventloop now takes care