123
119
static void _cd_logout_guest_session (GtkMenuItem *menu_item, gpointer data)
126
gchar *cResult = cairo_dock_launch_command_sync ("which guest-session");
127
if (cResult != NULL && *cResult == '/')
128
cairo_dock_launch_command ("guest-session");
129
else if (g_file_test (GUEST_SESSION_LAUNCHER, G_FILE_TEST_EXISTS))
130
cairo_dock_launch_command (GUEST_SESSION_LAUNCHER);
122
cd_logout_launch_guest_session ();
132
123
CD_APPLET_LEAVE ();
135
126
static void _cd_logout_program_shutdown (GtkMenuItem *menu_item, gpointer data)
138
int iDeltaT = (int) (cairo_dock_show_value_and_wait (D_("Choose in how many minutes your PC will stop:"), myIcon, myContainer, 30, 150) * 60);
139
if (iDeltaT == -1) // cancel
143
time_t t_cur = (time_t) time (NULL);
146
//g_print ("iShutdownTime <- %ld + %d\n", t_cur, iDeltaT);
147
myConfig.iShutdownTime = (int) (t_cur + iDeltaT);
149
else if (iDeltaT == 0) // on annule l'eventuel precedent.
151
myConfig.iShutdownTime = 0;
153
cairo_dock_update_conf_file (CD_APPLET_MY_CONF_FILE,
154
G_TYPE_INT, "Configuration", "shutdown time", myConfig.iShutdownTime,
156
cd_logout_set_timer ();
129
cd_logout_program_shutdown ();
157
130
CD_APPLET_LEAVE ();
159
132
CD_APPLET_ON_BUILD_MENU_BEGIN
161
134
GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
164
if (myConfig.iActionOnClick != CD_LOGOUT) // logout action not on click => put it in the menu
166
if (myConfig.iActionOnMiddleClick == CD_LOGOUT) // logout action on middle-click
167
cLabel = g_strdup_printf ("%s (%s)", D_("Log out"), D_("middle-click"));
169
cLabel = g_strdup (D_("Log out"));
170
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE, _cd_logout, CD_APPLET_MY_MENU);
173
if (myConfig.iActionOnClick != CD_SHUTDOWN) // shutdown action not on click => put it in the menu
175
if (myConfig.iActionOnMiddleClick == CD_SHUTDOWN) // logout action on middle-click
176
cLabel = g_strdup_printf ("%s (%s)", D_("Shut down"), D_("middle-click"));
178
cLabel = g_strdup (D_("Shut down"));
179
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE, _cd_shutdown, CD_APPLET_MY_MENU);
182
if (myConfig.iActionOnClick != CD_LOCK_SCREEN) // lockscreen action not on click => put it in the menu
184
if (myConfig.iActionOnMiddleClick == CD_LOCK_SCREEN) // lockscreen action on middle-click
185
cLabel = g_strdup_printf ("%s (%s)", D_("Lock screen"), D_("middle-click"));
187
cLabel = g_strdup (D_("Lock screen"));
188
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/icon-lock.png", _cd_lock_screen, CD_APPLET_MY_MENU);
191
if (g_file_test (GUEST_SESSION_LAUNCHER, G_FILE_TEST_EXISTS)) // Guest Session
193
CD_APPLET_ADD_IN_MENU (D_("Guest session"), _cd_logout_guest_session, CD_APPLET_MY_MENU);
197
gchar *cResult = cairo_dock_launch_command_sync ("which guest-session");
198
if (cResult != NULL && *cResult == '/')
199
CD_APPLET_ADD_IN_MENU (D_("Guest session"), _cd_logout_guest_session, CD_APPLET_MY_MENU);
137
if (! myData.bCapabilitiesChecked) // if we're using our own logout methods, they are all accessible from the left-click, so no need to add the following actions in the right-click menu.
139
if (myConfig.iActionOnClick != CD_LOGOUT) // logout action not on click => put it in the menu
141
if (myConfig.iActionOnMiddleClick == CD_LOGOUT) // logout action on middle-click
142
cLabel = g_strdup_printf ("%s (%s)", D_("Log out"), D_("middle-click"));
144
cLabel = g_strdup (D_("Log out"));
145
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/system-log-out.svg", _cd_logout, CD_APPLET_MY_MENU);
148
if (myConfig.iActionOnClick != CD_SHUTDOWN) // shutdown action not on click => put it in the menu
150
if (myConfig.iActionOnMiddleClick == CD_SHUTDOWN) // logout action on middle-click
151
cLabel = g_strdup_printf ("%s (%s)", D_("Shut down"), D_("middle-click"));
153
cLabel = g_strdup (D_("Shut down"));
154
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/system-shutdown.svg", _cd_shutdown, CD_APPLET_MY_MENU);
157
if (myConfig.iActionOnClick != CD_LOCK_SCREEN) // lockscreen action not on click => put it in the menu
159
if (myConfig.iActionOnMiddleClick == CD_LOCK_SCREEN) // lockscreen action on middle-click
160
cLabel = g_strdup_printf ("%s (%s)", D_("Lock screen"), D_("middle-click"));
162
cLabel = g_strdup (D_("Lock screen"));
163
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/locked.svg", _cd_lock_screen, CD_APPLET_MY_MENU);
167
if (cd_logout_have_guest_session ()) // Guest Session
169
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Guest session"), MY_APPLET_SHARE_DATA_DIR"/system-guest.svg", _cd_logout_guest_session, CD_APPLET_MY_MENU);
203
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Program an automatic shut-down"), MY_APPLET_SHARE_DATA_DIR"/icon-scheduling.png", _cd_logout_program_shutdown, CD_APPLET_MY_MENU); // pas beaucoup d'entrees => on le met dans le menu global.
172
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Program an automatic shut-down"), MY_APPLET_SHARE_DATA_DIR"/icon-scheduling.svg", _cd_logout_program_shutdown, CD_APPLET_MY_MENU); // pas beaucoup d'entrees => on le met dans le menu global.
205
174
CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
207
176
CD_APPLET_ON_BUILD_MENU_END
211
static gboolean _timer (gpointer data)
214
time_t t_cur = (time_t) time (NULL);
215
if (t_cur >= myConfig.iShutdownTime)
217
cd_debug ("shutdown !\n");
218
if (g_iDesktopEnv == CAIRO_DOCK_KDE)
219
cairo_dock_launch_command ("dbus-send --session --type=method_call --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout int32:0 int32:2 int32:2");
221
///cairo_dock_launch_command ("dbus-send --session --type=method_call --dest=org.freedesktop.PowerManagement /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Shutdown"); // --print-reply --reply-timeout=2000
222
cairo_dock_launch_command ("dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop"); // Suspend est aussi possible
224
myData.iSidTimer = 0;
225
CD_APPLET_LEAVE (FALSE); // inutile de faire quoique ce soit d'autre, puisque l'ordi s'eteint.
229
cd_debug ("shutdown in %d minutes\n", (int) (myConfig.iShutdownTime - t_cur) / 60);
230
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%dmn", (int) ceil ((double)(myConfig.iShutdownTime - t_cur) / 60.));
231
CD_APPLET_REDRAW_MY_ICON;
232
if (t_cur >= myConfig.iShutdownTime - 60)
233
cairo_dock_show_temporary_dialog_with_icon (D_("Your computer will shut-down in 1 minute."), myIcon, myContainer, 8000, "same icon");
235
CD_APPLET_LEAVE (TRUE);
238
void cd_logout_set_timer (void)
240
time_t t_cur = (time_t) time (NULL);
241
if (myConfig.iShutdownTime > t_cur)
243
if (myData.iSidTimer == 0)
244
myData.iSidTimer = g_timeout_add_seconds (60, _timer, NULL);
247
else if (myData.iSidTimer != 0)
249
g_source_remove (myData.iSidTimer);
250
myData.iSidTimer = 0;
251
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
255
static void _set_reboot_message (void)
257
gchar *cMessage = NULL;
259
g_file_get_contents (CD_REBOOT_NEEDED_FILE,
263
if (cMessage != NULL)
265
int len = strlen (cMessage);
266
if (cMessage[len-1] == '\n')
267
cMessage[len-1] = '\0';
268
CD_APPLET_SET_NAME_FOR_MY_ICON (cMessage);
271
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.cDefaultLabel);
274
void cd_logout_check_reboot_required (CairoDockFMEventType iEventType, const gchar *cURI, gpointer data)
278
case CAIRO_DOCK_FILE_MODIFIED: // new message
279
_set_reboot_message ();
282
case CAIRO_DOCK_FILE_DELETED: // reboot no more required (shouldn't happen)
283
myData.bRebootNeeded = FALSE;
284
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.cDefaultLabel);
285
CD_APPLET_STOP_DEMANDING_ATTENTION;
288
case CAIRO_DOCK_FILE_CREATED: // reboot required
289
myData.bRebootNeeded = TRUE;
290
_set_reboot_message ();
291
CD_APPLET_DEMANDS_ATTENTION ("pulse", 20);
292
cairo_dock_show_temporary_dialog_with_icon (myIcon->cName, myIcon, myContainer, 5e3, "same icon");
293
if (myConfig.cEmblemPath != NULL && *myConfig.cEmblemPath != '\0' && g_file_test (myConfig.cEmblemPath, G_FILE_TEST_EXISTS))
294
CD_APPLET_SET_EMBLEM_ON_MY_ICON (myConfig.cEmblemPath, CAIRO_DOCK_EMBLEM_UPPER_RIGHT);
296
CD_APPLET_SET_EMBLEM_ON_MY_ICON (MY_APPLET_SHARE_DATA_DIR"/emblem-reboot.png", CAIRO_DOCK_EMBLEM_UPPER_RIGHT);
303
void cd_logout_check_reboot_required_init (void)
305
if (g_file_test (CD_REBOOT_NEEDED_FILE, G_FILE_TEST_EXISTS))
307
cd_logout_check_reboot_required (CAIRO_DOCK_FILE_CREATED, CD_REBOOT_NEEDED_FILE, NULL);