| 1 |
/** |
| 2 |
* This file is a part of the Cairo-Dock project |
| 3 |
* |
| 4 |
* Copyright : (C) see the 'copyright' file. |
| 5 |
* E-mail : see the 'copyright' file. |
| 6 |
* |
| 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. |
| 11 |
* |
| 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/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <math.h> |
| 21 |
|
| 22 |
#include "applet-struct.h" |
| 23 |
#include "applet-timer.h" |
| 24 |
|
| 25 |
//////////////////// |
| 26 |
/// REBOOT TIMER /// |
| 27 |
//////////////////// |
| 28 |
|
| 29 |
static gboolean _timer (gpointer data) |
| 30 |
{ |
| 31 |
CD_APPLET_ENTER; |
| 32 |
time_t t_cur = (time_t) time (NULL); |
| 33 |
if (t_cur >= myConfig.iShutdownTime) |
| 34 |
{ |
| 35 |
cd_debug ("shutdown !\n"); |
| 36 |
if (g_iDesktopEnv == CAIRO_DOCK_KDE) |
| 37 |
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"); |
| 38 |
else |
| 39 |
cairo_dock_launch_command ("dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop"); |
| 40 |
|
| 41 |
myData.iSidTimer = 0; |
| 42 |
CD_APPLET_LEAVE (FALSE); // inutile de faire quoique ce soit d'autre, puisque l'ordi s'eteint. |
| 43 |
} |
| 44 |
else |
| 45 |
{ |
| 46 |
cd_debug ("shutdown in %d minutes", (int) (myConfig.iShutdownTime - t_cur) / 60); |
| 47 |
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%dmn", (int) ceil ((double)(myConfig.iShutdownTime - t_cur) / 60.)); |
| 48 |
CD_APPLET_REDRAW_MY_ICON; |
| 49 |
if (t_cur >= myConfig.iShutdownTime - 60) |
| 50 |
gldi_dialog_show_temporary_with_icon (D_("Your computer will shut-down in 1 minute."), myIcon, myContainer, 8000, "same icon"); |
| 51 |
} |
| 52 |
CD_APPLET_LEAVE (TRUE); |
| 53 |
|
| 54 |
} |
| 55 |
void cd_logout_set_timer (void) |
| 56 |
{ |
| 57 |
time_t t_cur = (time_t) time (NULL); |
| 58 |
if (myConfig.iShutdownTime > t_cur) |
| 59 |
{ |
| 60 |
if (myData.iSidTimer == 0) |
| 61 |
myData.iSidTimer = g_timeout_add_seconds (60, _timer, NULL); |
| 62 |
_timer (NULL); |
| 63 |
} |
| 64 |
else if (myData.iSidTimer != 0) |
| 65 |
{ |
| 66 |
g_source_remove (myData.iSidTimer); |
| 67 |
myData.iSidTimer = 0; |
| 68 |
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
static void _on_program_shutdown (int iClickedButton, GtkWidget *pInteractiveWidget, gpointer data, CairoDialog *pDialog) |
| 73 |
{ |
| 74 |
CD_APPLET_ENTER; |
| 75 |
if (iClickedButton == 0 || iClickedButton == -1) // ok button or Enter. |
| 76 |
{ |
| 77 |
int iDeltaT = 60 * gtk_range_get_value (GTK_RANGE (pInteractiveWidget)); |
| 78 |
if (iDeltaT > 0) // set the new time |
| 79 |
{ |
| 80 |
//g_print ("iShutdownTime <- %ld + %d\n", t_cur, iDeltaT); |
| 81 |
time_t t_cur = (time_t) time (NULL); |
| 82 |
myConfig.iShutdownTime = (int) (t_cur + iDeltaT); |
| 83 |
} |
| 84 |
else if (iDeltaT == 0) // cancel any previous shutdown |
| 85 |
{ |
| 86 |
myConfig.iShutdownTime = 0; |
| 87 |
} |
| 88 |
cairo_dock_update_conf_file (CD_APPLET_MY_CONF_FILE, |
| 89 |
G_TYPE_INT, "Configuration", "shutdown time", myConfig.iShutdownTime, |
| 90 |
G_TYPE_INVALID); |
| 91 |
cd_logout_set_timer (); |
| 92 |
} |
| 93 |
CD_APPLET_LEAVE (); |
| 94 |
} |
| 95 |
void cd_logout_program_shutdown (void) |
| 96 |
{ |
| 97 |
gldi_dialog_show_with_value (D_("Choose in how many minutes your PC will stop:"), |
| 98 |
myIcon, myContainer, |
| 99 |
"same icon", |
| 100 |
30, 150, |
| 101 |
(CairoDockActionOnAnswerFunc) _on_program_shutdown, NULL, (GFreeFunc)NULL); |
| 102 |
} |