2
* Copyright (C) 2004 Lukas Lipka <lukas@pmad.net>
3
* (C) 2004 Michael Vogt <mvo@debian.org>
4
* (C) 2004 Michiel Sikkes <michiel@eyesopened.nl>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library 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 GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
26
#define DBUS_API_SUBJECT_TO_CHANGE 1
32
#include <dbus/dbus.h>
33
#include <dbus/dbus-glib.h>
35
#include "upgrade-notifier.h"
36
#include "eggtrayicon.h"
38
#define ICON_FILE PACKAGE_DATA_DIR"/pixmaps/upgrade-notifier.png"
39
#define UPGRADE_CHECKER PACKAGE_LIB_DIR"/upgrade-notifier/apt-check"
40
#define PKG_MANAGER PACKAGE_LIB_DIR"/upgrade-notifier/upgrade-app"
42
#define TIMEOUT 1000*60*60
45
invoke_update_manager ()
47
//g_print("invoke_update_manager ()\n");
50
cmd = g_strdup_printf ("%s", PKG_MANAGER);
52
g_spawn_async (NULL, argv, NULL, 0/*G_SPAWN_LEAVE_DESCRIPTORS_OPEN*/, NULL, NULL, NULL, NULL);
58
button_release_cb (GtkWidget *widget,
59
GdkEventButton *event,
62
if (event->button == 1 && event->type == GDK_BUTTON_RELEASE) {
63
invoke_update_manager ();
68
trayicon_update_tooltip (UpgradeNotifier *un)
70
//g_print("update_tooltip: %x \n", un);
74
updates = g_strdup_printf(_("There are %i updates available!"),
77
explanation = g_strdup(_("Press this icon to show the updates."));
79
gtk_tooltips_set_tip(GTK_TOOLTIPS(un->tooltip),
80
GTK_WIDGET (un->eventbox),
81
updates, explanation);
88
trayicon_load (UpgradeNotifier *un)
92
pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (un->icon));
95
g_object_unref (G_OBJECT (pixbuf));
97
pixbuf = gdk_pixbuf_new_from_file (ICON_FILE, NULL);
99
gtk_image_set_from_pixbuf (GTK_IMAGE (un->icon), pixbuf);
103
trayicon_create (UpgradeNotifier *un)
105
//g_print("trayicon_create()\n");
106
un->tooltip = gtk_tooltips_new ();
107
un->tray_icon = egg_tray_icon_new ("apt upgrade-notifier");
108
un->eventbox = gtk_event_box_new ();
109
un->icon = gtk_image_new ();
113
gtk_container_add (GTK_CONTAINER (un->eventbox), un->icon);
114
gtk_container_add (GTK_CONTAINER (un->tray_icon), un->eventbox);
116
g_signal_connect (G_OBJECT(un->tray_icon),
117
"button-release-event",
118
G_CALLBACK (button_release_cb),
121
gtk_widget_show_all (GTK_WIDGET (un->tray_icon));
123
/* Initial tooltip update */
124
trayicon_update_tooltip (un);
130
update_check (UpgradeNotifier *un)
132
//g_print("upgrade_check(): %x \n", un);
133
FILE *f = popen(UPGRADE_CHECKER, "r");
136
un->num_upgrades = 0;
138
/* Check the number of upgrades trough the helper script */
139
while (fgets (s, 400, f) != NULL) {
145
if (un->num_upgrades == 0) {
146
/* We don't have any updates. */
147
if (un->is_displayed) {
148
/* We're still displayed, shoot ourselves */
149
gtk_widget_destroy (GTK_WIDGET (un->tray_icon));
150
un->is_displayed = FALSE;
153
/* There are updates */
154
if (un->is_displayed) {
155
/* We're already displayed, update tooltip */
156
trayicon_update_tooltip (un);
158
/* We're not already displayed, display ourselves */
159
if (trayicon_create (un))
160
un->is_displayed = TRUE;
163
//g_print("upgrades: %i\n", un->num_upgrades);
166
static DBusHandlerResult
167
signal_filter(DBusConnection *connection, DBusMessage *message, void *data)
169
#if 0 // DEBUG stuff to better understand about dbus
170
g_print("path: %s\n", dbus_message_get_path(message));
171
g_print("interface: %s\n", dbus_message_get_interface(message));
172
g_print("type: %i\n", dbus_message_get_type(message));
173
g_print("dest: %s\n", dbus_message_get_destination(message));
174
g_print("member: %s\n", dbus_message_get_member(message));
176
//g_print("signal_filter: %x\n");
178
if(dbus_message_is_signal(message, "app.apt.dbus", "changed")
179
|| dbus_message_is_signal(message, "app.apt.dbus", "updated")) {
181
gboolean finished=FALSE;
182
dbus_error_init(&error);
183
if(dbus_message_get_args(message, &error,
184
DBUS_TYPE_BOOLEAN, &finished,
185
DBUS_TYPE_INVALID)) {
187
//g_print("dbus message triggered update_check\n");
194
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
198
main (int argc, char *argv[])
206
gnome_program_init (PACKAGE, PACKAGE_VERSION,
211
client = gnome_master_client ();
213
/* Make sure we die when the session dies */
214
g_signal_connect (G_OBJECT (client), "die",
215
G_CALLBACK (gtk_main_quit), NULL);
217
gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY);
219
/* Create the UpgradeNotifier object */
220
un = g_new0 (UpgradeNotifier, 1);
222
/* setup a dbus channel */
223
loop = g_main_loop_new(NULL, FALSE);
224
dbus_error_init(&error);
225
bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
227
g_error("Failed to connect to D-BUS: %s",error.message);
230
dbus_connection_setup_with_g_main(bus, NULL);
231
dbus_bus_add_match(bus, "type='signal',interface='app.apt.dbus'",
233
dbus_connection_add_filter(bus, signal_filter, un, NULL);
235
/* Check for updates for the first time */
238
/* Set a time-out for the update check */
239
g_timeout_add (TIMEOUT, (GSourceFunc)update_check, un);
241
/* Start the main gtk loop */