Debian Codegraph @

logout/src/applet-notifications.c

raw
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 #include <string.h>
22
23 #include "applet-struct.h"
24 #include "applet-logout.h"
25 #include "applet-notifications.h"
26
27
28 CD_APPLET_ON_CLICK_BEGIN
29
30 cd_logout_display_actions ();
31
32 CD_APPLET_ON_CLICK_END
33
34
35 static void _logout (void)
36 {
37 if (myConfig.cUserAction != NULL)
38 {
39 cairo_dock_launch_command (myConfig.cUserAction);
40 }
41 else
42 {
43 gboolean bLoggedOut = cairo_dock_fm_logout ();
44 if (! bLoggedOut)
45 {
46 cd_logout_display_actions ();
47 }
48 }
49 }
50 static void _shutdown (void)
51 {
52 if (myConfig.cUserActionShutdown != NULL)
53 {
54 cairo_dock_launch_command (myConfig.cUserActionShutdown);
55 }
56 else
57 {
58 gboolean bShutdowned = cairo_dock_fm_shutdown ();
59 if (! bShutdowned)
60 {
61 cd_logout_display_actions ();
62 }
63 }
64 }
65 static inline void _execute_action (gint iAction)
66 {
67 switch (iAction)
68 {
69 case CD_LOGOUT:
70 _logout ();
71 break;
72 case CD_SHUTDOWN:
73 _shutdown ();
74 break;
75 case CD_LOCK_SCREEN:
76 cairo_dock_fm_lock_screen ();
77 break;
78 case CD_POP_UP_MENU:
79 default:
80 cd_logout_display_actions ();
81 break;
82 }
83 }
84 CD_APPLET_ON_MIDDLE_CLICK_BEGIN
85
86 _execute_action (myConfig.iActionOnMiddleClick);
87
88 CD_APPLET_ON_MIDDLE_CLICK_END
89
90
91 static void cd_logout_manage_users (GtkMenuItem *menu_item, gchar *cUserName)
92 {
93 GError * error = NULL;
94 if (! g_spawn_command_line_async("gnome-control-center user-accounts", &error)) // Gnome3
95 {
96 cd_warning ("Couldn't launch 'gnome-control-center user-accounts': %s", error->message);
97 g_error_free(error);
98 } /// TODO: handle other DE ...
99 }
100 CD_APPLET_ON_BUILD_MENU_BEGIN
101 if (g_iDesktopEnv == CAIRO_DOCK_GNOME)
102 {
103 CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Manage users"), GLDI_ICON_NAME_EDIT, cd_logout_manage_users, CD_APPLET_MY_MENU);
104 }
105 CD_APPLET_ON_BUILD_MENU_END
106
107
108 void cd_logout_on_keybinding_pull (const gchar *keystring, gpointer user_data)
109 {
110 cairo_dock_fm_lock_screen ();
111 }
112
113 void cd_logout_on_keybinding_pull2 (const gchar *keystring, gpointer user_data)
114 {
115 cd_logout_display_actions ();
116 }