1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <glade/glade.h>
#include <libnotify/notify.h>
#include "update-notifier.h"
#include "update.h"
#define GDM_SIGNAL "/usr/bin/gdm-signal"
static GladeXML *xml;
static gboolean
show_notification (TrayApplet *ta)
{
NotifyNotification *n;
int x, y;
GdkRectangle area;
gtk_status_icon_get_geometry(ta->tray_icon, NULL, &area, NULL);
// no usefull coordiante yet, do another timeout
if(area.x <= 0 || area.y <= 0 || area.width <= 0 || area.height <= 0)
return TRUE;
// only show once the icon is realy availabe
if(!gtk_status_icon_get_visible(ta->tray_icon))
return TRUE;
/* Create and show the notification */
n = notify_notification_new_with_status_icon(
_("System restart required"),
_("To complete the update of your system, "
"restart your system.\n\n"
"Click on the notification icon to "
"restart your system."),
GTK_STOCK_DIALOG_WARNING,
ta->tray_icon);
notify_notification_set_timeout (n, 60000);
notify_notification_show (n, NULL);
g_object_set_data (G_OBJECT(ta->tray_icon), "notification", n);
return FALSE;
}
gboolean
reboot_check (TrayApplet *ta)
{
struct stat statbuf;
/* If the file doesn't exist, we don't need to reboot */
if (stat (REBOOT_FILE, &statbuf)) {
NotifyNotification *n;
gtk_status_icon_set_visible (ta->tray_icon, FALSE);
/* Hide any notification popup */
n = g_object_get_data (G_OBJECT(ta->tray_icon), "notification");
if (n)
notify_notification_close (n, NULL);
g_object_set_data (G_OBJECT(ta->tray_icon), "notification", NULL);
return TRUE;
}
/* Skip the rest if the icon is already visible */
if (gtk_status_icon_get_visible (ta->tray_icon))
return TRUE;
gtk_status_icon_set_tooltip (ta->tray_icon,
_("System restart required"));
gtk_status_icon_set_visible (ta->tray_icon, TRUE);
/* Check whether the user doesn't like notifications */
if (gconf_client_get_bool ((GConfClient*) ta->user_data,
GCONF_KEY_NO_UPDATE_NOTIFICATIONS, NULL))
return TRUE;
/* Show the notification, after a delay so it doesn't look ugly
* if we've just logged in */
g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
return TRUE;
}
static void
request_reboot (void)
{
GnomeClient *client;
char *cmd[] = { GDM_SIGNAL, "--reboot", NULL };
client = gnome_master_client ();
g_return_if_fail (client != NULL);
/* Tell gdm to reboot once we exit the session */
g_spawn_sync (NULL, cmd, NULL, G_SPAWN_STDOUT_TO_DEV_NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
/* Tell gnome-session to save and exit the session without asking
* the user. */
gnome_client_request_save (client,
GNOME_SAVE_GLOBAL,
TRUE,
GNOME_INTERACT_NONE,
FALSE,
TRUE);
}
static gboolean
button_release_cb (GtkWidget *widget,
TrayApplet *ta)
{
GtkWidget *dia;
dia = glade_xml_get_widget (xml, "dialog_reboot");
if (gtk_dialog_run (GTK_DIALOG(dia)) == GTK_RESPONSE_OK)
request_reboot ();
gtk_widget_hide (dia);
return TRUE;
}
void
reboot_tray_icon_init (TrayApplet *ta)
{
GtkWidget *widget;
GtkImage *image;
xml = glade_xml_new (GLADEDIR"reboot-dialog.glade", NULL, NULL);
widget = glade_xml_get_widget (xml, "image");
GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (icon_theme, "un-reboot",
48, 0,NULL);
gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);
ta->user_data = gconf_client_get_default();
g_signal_connect (G_OBJECT(ta->tray_icon),
"activate",
G_CALLBACK (button_release_cb),
ta);
/* Check for updates for the first time */
reboot_check (ta);
}
|