9
#include <libnotify/notify.h>
10
#include <dbus/dbus-glib.h>
11
#include <dbus/dbus.h>
13
#include "update-notifier.h"
16
static GtkBuilder *builder;
19
show_notification (TrayApplet *ta)
21
NotifyNotification *n;
23
// only show once the icon is realy availabe
24
if(!gtk_status_icon_get_visible(ta->tray_icon))
27
/* Create and show the notification */
28
n = notify_notification_new(
29
_("System restart required"),
30
_("To complete the update of your system, "
31
"please restart it.\n\n"
32
"Click on the notification icon for "
34
GTK_STOCK_DIALOG_WARNING);
35
notify_notification_set_timeout (n, 60000);
36
notify_notification_show (n, NULL);
44
DBusGConnection *connection;
49
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
50
if (connection == NULL) {
55
proxy = dbus_g_proxy_new_for_name (connection,
56
"org.gnome.SessionManager",
57
"/org/gnome/SessionManager",
58
"org.gnome.SessionManager");
63
if (!dbus_g_proxy_call (proxy, "RequestReboot", &error,
64
G_TYPE_INVALID, G_TYPE_INVALID)) {
74
DBusGConnection *connection;
79
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
80
if (connection == NULL) {
85
proxy = dbus_g_proxy_new_for_name (connection,
86
"org.freedesktop.ConsoleKit",
87
"/org/freedesktop/ConsoleKit/Manager",
88
"org.freedesktop.ConsoleKit.Manager");
93
if (!dbus_g_proxy_call (proxy, "Restart", &error,
94
G_TYPE_INVALID, G_TYPE_INVALID)) {
103
request_reboot (void)
105
if(!gdm_action_reboot() && !ck_action_reboot()) {
106
const char *fmt, *msg, *details;
107
fmt = "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s\n";
108
msg = _("Reboot failed");
109
details = _("Failed to request reboot, please shutdown manually");
110
GtkWidget *dlg = gtk_message_dialog_new_with_markup(NULL, 0,
114
gtk_dialog_run(GTK_DIALOG(dlg));
115
gtk_widget_destroy(dlg);
121
ask_reboot_required(TrayApplet *ta, gboolean focus_on_map)
125
dia = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_reboot"));
126
gtk_window_set_focus_on_map(GTK_WINDOW(dia), focus_on_map);
127
if (gtk_dialog_run (GTK_DIALOG(dia)) == GTK_RESPONSE_OK)
129
gtk_widget_hide (dia);
133
is_aptdaemon_on_the_system_bus ()
135
DBusConnection *connection;
136
DBusError *dbus_error = NULL;
137
DBusMessage *message, *reply;
138
const char *aptdaemon_bus_name = "org.debian.apt";
141
connection = dbus_bus_get(DBUS_BUS_SYSTEM, dbus_error);
142
if (dbus_error != NULL) {
143
g_warning("failed to connect to the system bus");
146
message = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
150
if (message == NULL) {
151
g_warning ("failed to create dbus message");
155
dbus_message_append_args(message,
156
DBUS_TYPE_STRING, &aptdaemon_bus_name,
159
reply = dbus_connection_send_with_reply_and_block(connection,
163
dbus_message_unref(message);
166
dbus_message_unref(reply);
172
g_debug("aptdaemon on bus: %i", res);
177
aptdaemon_pending_transactions ()
179
DBusGConnection *connection;
182
char *current = NULL;
183
char **pending = NULL;
185
if (!is_aptdaemon_on_the_system_bus())
189
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
190
if (connection == NULL) {
191
g_debug ("Failed to open connection to bus: %s\n", error->message);
192
g_error_free (error);
196
proxy = dbus_g_proxy_new_for_name (connection,
201
if (!dbus_g_proxy_call (proxy, "GetActiveTransactions", &error,
203
G_TYPE_STRING, ¤t,
204
G_TYPE_STRV, &pending,
206
g_debug ("error during dbus call: %s\n", error->message);
207
g_error_free (error);
208
g_object_unref (proxy);
212
gboolean has_pending = FALSE;
213
if ((current && strcmp(current,"") != 0) || g_strv_length(pending) > 0)
216
g_object_unref (proxy);
218
g_strfreev (pending);
224
do_reboot_check (TrayApplet *ta)
228
// if we are not supposed to show the reboot notification
230
if(gconf_client_get_bool((GConfClient*) ta->user_data,
231
GCONF_KEY_HIDE_REBOOT, NULL))
233
// no auto-open of this dialog
234
if(gconf_client_get_bool((GConfClient*) ta->user_data,
235
GCONF_KEY_AUTO_LAUNCH, NULL)) {
236
g_debug ("Skipping reboot required");
240
/* If the file doesn't exist, we don't need to reboot */
241
if (stat (REBOOT_FILE, &statbuf)) {
242
NotifyNotification *n;
244
gtk_status_icon_set_visible (ta->tray_icon, FALSE);
245
/* Hide any notification popup */
246
n = g_object_get_data (G_OBJECT(ta->tray_icon), "notification");
248
notify_notification_close (n, NULL);
249
g_object_set_data (G_OBJECT(ta->tray_icon), "notification", NULL);
254
/* Skip the rest if the icon is already visible */
255
if (gtk_status_icon_get_visible (ta->tray_icon))
257
gtk_status_icon_set_tooltip (ta->tray_icon,
258
_("System restart required"));
259
gtk_status_icon_set_visible (ta->tray_icon, TRUE);
261
/* Check whether the user doesn't like notifications */
262
if (gconf_client_get_bool ((GConfClient*) ta->user_data,
263
GCONF_KEY_NO_UPDATE_NOTIFICATIONS, NULL))
266
/* Show the notification, after a delay so it doesn't look ugly
267
* if we've just logged in */
268
g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
273
reboot_check (TrayApplet *ta)
275
if (aptdaemon_pending_transactions())
276
g_timeout_add_seconds (5, (GSourceFunc)reboot_check, ta);
283
button_release_cb (GtkWidget *widget,
286
ask_reboot_required(ta, TRUE);
293
reboot_tray_icon_init (TrayApplet *ta)
296
GError* error = NULL;
298
builder = gtk_builder_new ();
299
if (!gtk_builder_add_from_file (builder, UIDIR"reboot-dialog.ui", &error)) {
300
g_warning ("Couldn't load builder file: %s", error->message);
301
g_error_free (error);
304
widget = GTK_WIDGET (gtk_builder_get_object (builder, "image"));
305
GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
306
GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (icon_theme, "un-reboot",
308
gtk_status_icon_set_from_pixbuf (ta->tray_icon, pixbuf);
309
ta->user_data = gconf_client_get_default();
311
g_signal_connect (G_OBJECT(ta->tray_icon),
313
G_CALLBACK (button_release_cb),
316
gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);
318
/* Check for updates for the first time */