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 "stdlib.h"
21 
22 #include "applet-struct.h"
23 #include "applet-config.h"
24 #include "applet-notifications.h"
25 #include "applet-reboot-required.h"
26 #include "applet-timer.h"
27 #include "applet-init.h"
28 
29 CD_APPLET_DEFINE_BEGIN ("logout",
30 	2, 0, 0,
31 	CAIRO_DOCK_CATEGORY_APPLET_DESKTOP,
32 	N_("This applet lets you manage the current session. You can either:\n"
33 	"shut down, restart, hibernate, suspend, log out, lock the screen, switch to another user, or program an automatic shutdown\n"
34 	"It will also tell you if your system needs to be restarted.\n"
35 	"<b>Click</b> on the icon to pop the menu up.\n"
36 	"You can bind a <b>shortcut</b> to it, and also to lock the screen."),
37 	"Fabounet (Fabrice Rey)")
38 	CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE
39 	CD_APPLET_REDEFINE_TITLE (N_("Log out"))
40 CD_APPLET_DEFINE_END
41 
42 
43 CD_APPLET_INIT_BEGIN
44 	if (myDesklet)
45 	{
46 		CD_APPLET_SET_DESKLET_RENDERER ("Simple");
47 	}
48 
49 	CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;  // set the default icon if none is specified in conf.
50 
51 	if (g_iDesktopEnv == CAIRO_DOCK_GNOME)  // on prend le controle de l'icone de la fenetre.
52 		CD_APPLET_MANAGE_APPLICATION ("gnome-session");  // x-session-manager before 2.28
53 	else if (g_iDesktopEnv == CAIRO_DOCK_XFCE)
54 		CD_APPLET_MANAGE_APPLICATION ("xfce4-session-logout");  // x-session-manager before 4.8
55 	else if (g_iDesktopEnv == CAIRO_DOCK_KDE)
56 		CD_APPLET_MANAGE_APPLICATION ("ksmserver");  /// pas du tout sur...
57 
58 	myData.iDesiredIconSize = cairo_dock_search_icon_size (GTK_ICON_SIZE_MENU);
59 
60 	//\_______________ On enregistre nos notifications.
61 	CD_APPLET_REGISTER_FOR_CLICK_EVENT;
62 	CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
63 	CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
64 
65 	// shortkey
66 
67 	myData.pKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortkey,
68 		D_("Lock the screen"),
69 		"Configuration", "shortkey",
70 		(CDBindkeyHandler) cd_logout_on_keybinding_pull);
71 	myData.pKeyBinding2 = CD_APPLET_BIND_KEY (myConfig.cShortkey2,
72 		D_("Show the log-out menu"),
73 		"Configuration", "shortkey2",
74 		(CDBindkeyHandler) cd_logout_on_keybinding_pull2);
75 
76 	//\_______________ On (re)lance l'eteignage programme.
77 	cd_logout_set_timer ();
78 
79 	//\_______________ We monitor files in order to know if a reboot/logout is needed
80 	cairo_dock_fm_add_monitor_full (CD_REBOOT_NEEDED_FILE, FALSE, NULL, (CairoDockFMMonitorCallback) cd_logout_check_reboot_required, NULL);
81 	// maybe not very clean to directly use 'CD_REBOOT_NEEDED' but it's just to not use two new variables for this tiny enum ;)
82 	cd_logout_check_reboot_required_init ();
83 
84 CD_APPLET_INIT_END
85 
86 
87 CD_APPLET_STOP_BEGIN
88 	//\_______________ On se desabonne de nos notifications.
89 	CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
90 	CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
91 	CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
92 
93 	gldi_object_unref (GLDI_OBJECT(myData.pKeyBinding));
94 	gldi_object_unref (GLDI_OBJECT(myData.pKeyBinding2));
95 
96 	gchar *cNull = NULL;
97 	CD_APPLET_MANAGE_APPLICATION (cNull);  // on relache le controle de l'icone de la fenetre.
98 
99 	gldi_task_discard (myData.pTask);
100 
101 	if (myData.iSidTimer != 0)
102 		g_source_remove (myData.iSidTimer);
103 
104 	cairo_dock_fm_remove_monitor_full (CD_REBOOT_NEEDED_FILE, FALSE, NULL);
105 CD_APPLET_STOP_END
106 
107 
108 CD_APPLET_RELOAD_BEGIN
109 	if (CD_APPLET_MY_CONFIG_CHANGED)
110 	{
111 		if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED)  // we are now in a desklet, set a renderer.
112 		{
113 			CD_APPLET_SET_DESKLET_RENDERER ("Simple");
114 		}
115 
116 		CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;  // set the default icon if none is specified in conf.
117 
118 		// the icon can be changed.
119 		cd_logout_check_reboot_required_init ();
120 
121 		gldi_shortkey_rebind (myData.pKeyBinding, myConfig.cShortkey, NULL);
122 		gldi_shortkey_rebind (myData.pKeyBinding2, myConfig.cShortkey2, NULL);
123 	}
124 CD_APPLET_RELOAD_END
125