2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "applet-struct.h"
23
#include "applet-logout.h"
24
#include "applet-reboot-required.h"
26
static gboolean s_bRebootRequired = FALSE;
27
static gboolean s_bMonitored = FALSE;
29
static const gchar * _get_default_message (void)
31
if (myConfig.cDefaultLabel) // has another default name
32
return myConfig.cDefaultLabel;
34
return myApplet->pModule->pVisitCard->cTitle;
37
static gchar * _get_reboot_message (void)
39
gchar *cMessage = NULL;
41
g_file_get_contents (CD_REBOOT_NEEDED_FILE,
47
int len = strlen (cMessage);
48
if (cMessage[len-1] == '\n')
49
cMessage[len-1] = '\0';
55
static void _notify_action_required (void)
57
CD_APPLET_DEMANDS_ATTENTION ("pulse", 20);
58
gldi_dialogs_remove_on_icon (myIcon);
60
// it's not a good idea to reboot the computer before the end of the update ;)
61
gchar *cName = g_strdup_printf ("%s\n%s", myIcon->cName,
62
D_("Please do that at the end of the update."));
64
gldi_dialog_show_temporary_with_icon (cName, myIcon, myContainer, 15e3, "same icon");
68
gint iIconSize = MAX (myIcon->image.iWidth, myIcon->image.iHeight);
69
gchar *cImagePath = cd_logout_check_icon (myConfig.cEmblemPath,
70
(myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM ?
75
cImagePath = cd_logout_check_icon (GTK_STOCK_REFRESH,
76
(myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM ?
80
cImagePath = g_strdup (MY_APPLET_SHARE_DATA_DIR"/system-restart.svg");
83
if (myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM)
84
CD_APPLET_PRINT_OVERLAY_ON_MY_ICON (cImagePath, CAIRO_OVERLAY_UPPER_RIGHT);
86
CD_APPLET_SET_IMAGE_ON_MY_ICON (cImagePath);
90
static void _stop_notify_action_required (void)
92
// should not happen... mainly for the tests.
93
gldi_dialogs_remove_on_icon (myIcon);
94
if (myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM)
95
CD_APPLET_PRINT_OVERLAY_ON_MY_ICON (NULL, CAIRO_OVERLAY_UPPER_RIGHT);
97
CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cDefaultIcon);
98
CD_APPLET_STOP_DEMANDING_ATTENTION;
101
static gboolean _notify_reboot_requiered (gpointer pData)
103
if (! myApplet || ! s_bRebootRequired)
105
s_bMonitored = FALSE;
109
CairoDockFMEventType iEventType = GPOINTER_TO_INT (pData);
111
gchar *cMessage = _get_reboot_message ();
112
if (cMessage && *cMessage != '\0')
113
CD_APPLET_SET_NAME_FOR_MY_ICON (cMessage);
115
CD_APPLET_SET_NAME_FOR_MY_ICON (_get_default_message ());
116
if (iEventType == CAIRO_DOCK_FILE_CREATED)
117
_notify_action_required ();
120
s_bMonitored = FALSE;
125
void cd_logout_check_reboot_required (CairoDockFMEventType iEventType, const gchar *cURI)
129
case CAIRO_DOCK_FILE_MODIFIED: // new message
130
case CAIRO_DOCK_FILE_CREATED: // reboot required
131
s_bRebootRequired = TRUE;
135
gpointer pEventType = GINT_TO_POINTER (iEventType);
136
#ifdef END_INSTALLATION_PID
137
cairo_dock_fm_monitor_pid (END_INSTALLATION_PID, FALSE,
138
_notify_reboot_requiered, TRUE, pEventType);
140
_notify_reboot_requiered (pEventType);
145
case CAIRO_DOCK_FILE_DELETED: // reboot/logout no more required (shouldn't happen)
146
s_bRebootRequired = FALSE;
147
_stop_notify_action_required (); // default icon
148
CD_APPLET_SET_NAME_FOR_MY_ICON (_get_default_message ());
155
void cd_logout_check_reboot_required_init (void)
157
if (g_file_test (CD_REBOOT_NEEDED_FILE, G_FILE_TEST_EXISTS))
159
cd_logout_check_reboot_required (CAIRO_DOCK_FILE_CREATED, CD_REBOOT_NEEDED_FILE);
163
gboolean cd_logout_can_safety_shutdown (void)
165
gboolean bResult = ! s_bMonitored || ! s_bRebootRequired;
166
#ifdef END_INSTALLATION_PID
167
bResult &= cairo_dock_fm_get_pid (END_INSTALLATION_PID) == -1;
b'\\ No newline at end of file'