9
#include <libnotify/notify.h>
10
#include <dbus/dbus-glib.h>
12
#include "update-notifier.h"
15
static GtkBuilder *builder;
18
show_notification (TrayApplet *ta)
20
NotifyNotification *n;
23
gtk_status_icon_get_geometry(ta->tray_icon, NULL, &area, NULL);
25
// no usefull coordiante yet, do another timeout
26
if(area.x <= 0 || area.y <= 0 || area.width <= 0 || area.height <= 0)
29
// only show once the icon is realy availabe
30
if(!gtk_status_icon_get_visible(ta->tray_icon))
33
/* Create and show the notification */
34
n = notify_notification_new_with_status_icon(
35
_("System restart required"),
36
_("To complete the update of your system, "
37
"please restart it.\n\n"
38
"Click on the notification icon for "
40
GTK_STOCK_DIALOG_WARNING,
42
notify_notification_set_timeout (n, 60000);
43
notify_notification_show (n, NULL);
44
g_object_set_data (G_OBJECT(ta->tray_icon), "notification", n);
52
DBusGConnection *connection;
57
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
58
if (connection == NULL) {
63
proxy = dbus_g_proxy_new_for_name (connection,
64
"org.gnome.SessionManager",
65
"/org/gnome/SessionManager",
66
"org.gnome.SessionManager");
71
if (!dbus_g_proxy_call (proxy, "RequestReboot", &error,
72
G_TYPE_INVALID, G_TYPE_INVALID)) {
82
DBusGConnection *connection;
87
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
88
if (connection == NULL) {
93
proxy = dbus_g_proxy_new_for_name (connection,
94
"org.freedesktop.Hal",
95
"/org/freedesktop/Hal/devices/computer",
96
"org.freedesktop.Hal.Device.SystemPowerManagement");
101
if (!dbus_g_proxy_call (proxy, "Reboot", &error,
102
G_TYPE_INVALID, G_TYPE_INVALID)) {
103
g_error_free (error);
111
request_reboot (void)
113
if(!gdm_action_reboot() && !hal_action_reboot()) {
114
const char *fmt, *msg, *details;
115
fmt = "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s\n";
116
msg = _("Reboot failed");
117
details = _("Failed to request reboot, please shutdown manually");
118
GtkWidget *dlg = gtk_message_dialog_new_with_markup(NULL, 0,
122
gtk_dialog_run(GTK_DIALOG(dlg));
123
gtk_widget_destroy(dlg);
129
ask_reboot_required(TrayApplet *ta, gboolean focus_on_map)
133
dia = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_reboot"));
134
gtk_window_set_focus_on_map(GTK_WINDOW(dia), focus_on_map);
135
if (gtk_dialog_run (GTK_DIALOG(dia)) == GTK_RESPONSE_OK)
137
gtk_widget_hide (dia);
141
aptdaemon_pending_transactions ()
143
DBusGConnection *connection;
146
char *current = NULL;
147
char **pending = NULL;
150
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
151
if (connection == NULL) {
152
g_debug ("Failed to open connection to bus: %s\n", error->message);
153
g_error_free (error);
157
proxy = dbus_g_proxy_new_for_name (connection,
162
if (!dbus_g_proxy_call (proxy, "GetActiveTransactions", &error,
164
G_TYPE_STRING, ¤t,
165
G_TYPE_STRV, &pending,
167
g_debug ("error during dbus call: %s\n", error->message);
168
g_error_free (error);
169
g_object_unref (proxy);
173
gboolean has_pending = FALSE;
174
if ((current && strcmp(current,"") != 0) || g_strv_length(pending) > 0)
177
g_object_unref (proxy);
179
g_strfreev (pending);
185
do_reboot_check (TrayApplet *ta)
189
// if we are not supposed to show the reboot notification
191
if(gconf_client_get_bool((GConfClient*) ta->user_data,
192
GCONF_KEY_HIDE_REBOOT, NULL))
194
// no auto-open of this dialog
195
if(gconf_client_get_bool((GConfClient*) ta->user_data,
196
GCONF_KEY_AUTO_LAUNCH, NULL)) {
197
g_debug ("Skipping reboot required");
201
/* If the file doesn't exist, we don't need to reboot */
202
if (stat (REBOOT_FILE, &statbuf)) {
203
NotifyNotification *n;
205
gtk_status_icon_set_visible (ta->tray_icon, FALSE);
206
/* Hide any notification popup */
207
n = g_object_get_data (G_OBJECT(ta->tray_icon), "notification");
209
notify_notification_close (n, NULL);
210
g_object_set_data (G_OBJECT(ta->tray_icon), "notification", NULL);
215
/* Skip the rest if the icon is already visible */
216
if (gtk_status_icon_get_visible (ta->tray_icon))
218
gtk_status_icon_set_tooltip (ta->tray_icon,
219
_("System restart required"));
220
gtk_status_icon_set_visible (ta->tray_icon, TRUE);
222
/* Check whether the user doesn't like notifications */
223
if (gconf_client_get_bool ((GConfClient*) ta->user_data,
224
GCONF_KEY_NO_UPDATE_NOTIFICATIONS, NULL))
227
/* Show the notification, after a delay so it doesn't look ugly
228
* if we've just logged in */
229
g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
234
reboot_check (TrayApplet *ta)
236
if (aptdaemon_pending_transactions())
237
g_timeout_add_seconds (5, (GSourceFunc)reboot_check, ta);
244
button_release_cb (GtkWidget *widget,
247
ask_reboot_required(ta, TRUE);
254
reboot_tray_icon_init (TrayApplet *ta)
257
GError* error = NULL;
259
builder = gtk_builder_new ();
260
if (!gtk_builder_add_from_file (builder, UIDIR"reboot-dialog.ui", &error)) {
261
g_warning ("Couldn't load builder file: %s", error->message);
262
g_error_free (error);
265
widget = GTK_WIDGET (gtk_builder_get_object (builder, "image"));
266
GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
267
GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (icon_theme, "un-reboot",
269
gtk_status_icon_set_from_pixbuf (ta->tray_icon, pixbuf);
270
ta->user_data = gconf_client_get_default();
272
g_signal_connect (G_OBJECT(ta->tray_icon),
274
G_CALLBACK (button_release_cb),
277
gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);
279
/* Check for updates for the first time */