14
by Ted Gould
I forgot to put legal agreements on the top of all the C/H files. Oops. |
1 |
/*
|
2 |
A small wrapper utility to load indicators and put them as menu items
|
|
3 |
into the gnome-panel using it's applet interface.
|
|
4 |
||
5 |
Copyright 2009 Canonical Ltd.
|
|
6 |
||
7 |
Authors:
|
|
8 |
Ted Gould <ted@canonical.com>
|
|
19.3.1
by Christoph Korn
These patches introduce a gconf key whether the logout/restart/shutdown confirmations |
9 |
Christoph Korn <c_korn@gmx.de>
|
14
by Ted Gould
I forgot to put legal agreements on the top of all the C/H files. Oops. |
10 |
|
322
by Charles Kerr
clearing house: the remainder of bugfixes & readability changes |
11 |
This program is free software: you can redistribute it and/or modify it
|
12 |
under the terms of the GNU General Public License version 3, as published
|
|
14
by Ted Gould
I forgot to put legal agreements on the top of all the C/H files. Oops. |
13 |
by the Free Software Foundation.
|
14 |
||
322
by Charles Kerr
clearing house: the remainder of bugfixes & readability changes |
15 |
This program is distributed in the hope that it will be useful, but
|
16 |
WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
17 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
14
by Ted Gould
I forgot to put legal agreements on the top of all the C/H files. Oops. |
18 |
PURPOSE. See the GNU General Public License for more details.
|
19 |
||
322
by Charles Kerr
clearing house: the remainder of bugfixes & readability changes |
20 |
You should have received a copy of the GNU General Public License along
|
14
by Ted Gould
I forgot to put legal agreements on the top of all the C/H files. Oops. |
21 |
with this program. If not, see <http://www.gnu.org/licenses/>.
|
22 |
*/
|
|
23 |
||
331
by Charles Kerr
copyediting |
24 |
#include "config.h" |
25 |
||
245.2.3
by Allan LeSage
Advised changes to fix implicit declarations. |
26 |
#include <locale.h> |
9.1.74
by Ted Gould
Basic command line parsing. Not working 100% yet. |
27 |
#include <glib.h> |
318
by Charles Kerr
a step in merging the two menus: consolidate & clean up the code in session-menu-mgr |
28 |
#include <glib/gi18n.h> /* textdomain(), bindtextdomain() */ |
9.1.71
by Ted Gould
Make a dialog pop up. Not really the right one, but one. |
29 |
#include <gtk/gtk.h> |
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
30 |
#include "dialog.h" |
322
by Charles Kerr
clearing house: the remainder of bugfixes & readability changes |
31 |
#include "shared-names.h" |
9.1.71
by Ted Gould
Make a dialog pop up. Not really the right one, but one. |
32 |
|
376.1.1
by Robert Ancell
Use GDbus |
33 |
static GVariant * |
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
34 |
call_logind (const gchar *method, GVariant *parameters, GError **error) |
376.1.1
by Robert Ancell
Use GDbus |
35 |
{
|
36 |
GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error); |
|
37 |
if (!bus) |
|
38 |
{
|
|
39 |
g_variant_unref (parameters); |
|
40 |
return NULL; |
|
41 |
}
|
|
42 |
||
43 |
GVariant *result = g_dbus_connection_call_sync(bus, |
|
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
44 |
"org.freedesktop.login1", |
45 |
"/org/freedesktop/login1", |
|
46 |
"org.freedesktop.login1.Manager", |
|
376.1.1
by Robert Ancell
Use GDbus |
47 |
method, |
48 |
parameters, |
|
49 |
NULL, |
|
50 |
G_DBUS_CALL_FLAGS_NONE, |
|
51 |
-1, |
|
52 |
NULL, |
|
53 |
error); |
|
54 |
g_object_unref (bus); |
|
55 |
||
56 |
return result; |
|
57 |
}
|
|
58 |
||
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
59 |
static void |
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
60 |
logind_fallback (LogoutDialogType action) |
79.2.1
by Ted Gould
Adding a fallback for now gnome-session detected. |
61 |
{
|
376.1.1
by Robert Ancell
Use GDbus |
62 |
GError * error = NULL; |
63 |
GVariant *result = NULL; |
|
64 |
||
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
65 |
g_debug("Falling back to using logind for action"); |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
66 |
|
79.2.1
by Ted Gould
Adding a fallback for now gnome-session detected. |
67 |
switch (action) { |
79.4.13
by Ted Gould
Updating merge to new enums. |
68 |
case LOGOUT_DIALOG_TYPE_LOG_OUT: |
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
69 |
g_warning("Unable to fallback to logind for logout as it's a session issue. We need some sort of session handler."); |
79.2.1
by Ted Gould
Adding a fallback for now gnome-session detected. |
70 |
break; |
79.4.13
by Ted Gould
Updating merge to new enums. |
71 |
case LOGOUT_DIALOG_TYPE_SHUTDOWN: |
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
72 |
g_debug("Telling logind to 'PowerOff'"); |
387.1.6
by Iain Lane
Pass 'FALSE' for the PK interactivity argument, to match not checking for 'allowed' any more |
73 |
result = call_logind ("PowerOff", g_variant_new ("(b)", FALSE), &error); |
79.2.2
by Ted Gould
Adding in shutdown and restart |
74 |
break; |
79.4.13
by Ted Gould
Updating merge to new enums. |
75 |
case LOGOUT_DIALOG_TYPE_RESTART: |
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
76 |
g_debug("Telling logind to 'Reboot'"); |
387.1.6
by Iain Lane
Pass 'FALSE' for the PK interactivity argument, to match not checking for 'allowed' any more |
77 |
result = call_logind ("Reboot", g_variant_new ("(b)", FALSE), &error); |
79.2.2
by Ted Gould
Adding in shutdown and restart |
78 |
break; |
79.2.1
by Ted Gould
Adding a fallback for now gnome-session detected. |
79 |
default: |
80 |
g_warning("Unknown action"); |
|
81 |
break; |
|
82 |
}
|
|
83 |
||
376.1.1
by Robert Ancell
Use GDbus |
84 |
if (!result) { |
85 |
if (error != NULL) { |
|
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
86 |
g_warning ("logind action failed: %s", error->message); |
376.1.1
by Robert Ancell
Use GDbus |
87 |
} else { |
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
88 |
g_warning ("logind action failed: unknown error"); |
376.1.1
by Robert Ancell
Use GDbus |
89 |
}
|
79.2.4
by Ted Gould
can't really use async as we dont' have a mainloop here |
90 |
}
|
376.1.1
by Robert Ancell
Use GDbus |
91 |
else
|
92 |
g_variant_unref (result); |
|
93 |
g_clear_error (&error); |
|
79.2.4
by Ted Gould
can't really use async as we dont' have a mainloop here |
94 |
|
79.2.2
by Ted Gould
Adding in shutdown and restart |
95 |
return; |
79.2.1
by Ted Gould
Adding a fallback for now gnome-session detected. |
96 |
}
|
97 |
||
376.1.1
by Robert Ancell
Use GDbus |
98 |
static GVariant * |
99 |
call_gnome_session (const gchar *method, GVariant *parameters, GError **error) |
|
100 |
{
|
|
101 |
GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error); |
|
102 |
if (!bus) |
|
103 |
{
|
|
104 |
g_variant_unref (parameters); |
|
105 |
return NULL; |
|
106 |
}
|
|
107 |
||
108 |
GVariant *result = g_dbus_connection_call_sync(bus, |
|
109 |
"org.gnome.SessionManager", |
|
110 |
"/org/gnome/SessionManager", |
|
111 |
"org.gnome.SessionManager", |
|
112 |
method, |
|
113 |
parameters, |
|
114 |
NULL, |
|
115 |
G_DBUS_CALL_FLAGS_NONE, |
|
116 |
G_MAXINT, |
|
117 |
NULL, |
|
118 |
error); |
|
119 |
g_object_unref (bus); |
|
120 |
||
121 |
return result; |
|
122 |
}
|
|
123 |
||
79.2.1
by Ted Gould
Adding a fallback for now gnome-session detected. |
124 |
static void |
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
125 |
session_action (LogoutDialogType action) |
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
126 |
{
|
127 |
GError * error = NULL; |
|
376.1.1
by Robert Ancell
Use GDbus |
128 |
GVariant *result = NULL; |
79.2.1
by Ted Gould
Adding a fallback for now gnome-session detected. |
129 |
|
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
130 |
if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) { |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
131 |
g_debug("Asking Session manager to 'Logout'"); |
376.1.1
by Robert Ancell
Use GDbus |
132 |
result = call_gnome_session ("Logout", g_variant_new ("(u)", 1), &error); |
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
133 |
} else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) { |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
134 |
g_debug("Asking Session manager to 'RequestShutdown'"); |
376.1.1
by Robert Ancell
Use GDbus |
135 |
result = call_gnome_session ("RequestShutdown", g_variant_new ("()"), &error); |
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
136 |
} else if (action == LOGOUT_DIALOG_TYPE_RESTART) { |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
137 |
g_debug("Asking Session manager to 'RequestReboot'"); |
376.1.1
by Robert Ancell
Use GDbus |
138 |
result = call_gnome_session ("RequestReboot", g_variant_new ("()"), &error); |
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
139 |
} else { |
140 |
g_warning ("Unknown session action"); |
|
141 |
}
|
|
142 |
||
376.1.1
by Robert Ancell
Use GDbus |
143 |
if (!result) { |
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
144 |
if (error != NULL) { |
145 |
g_warning ("SessionManager action failed: %s", error->message); |
|
146 |
} else { |
|
147 |
g_warning ("SessionManager action failed: unknown error"); |
|
148 |
}
|
|
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
149 |
|
387.1.1
by Iain Lane
Initial port from ConsoleKit to Logind for session tracking. |
150 |
logind_fallback(action); |
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
151 |
}
|
376.1.1
by Robert Ancell
Use GDbus |
152 |
else
|
153 |
g_variant_unref (result); |
|
309
by Charles Kerr
use g_clear_object() |
154 |
g_clear_error (&error); |
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
155 |
|
156 |
return; |
|
157 |
}
|
|
158 |
||
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
159 |
static LogoutDialogType type = LOGOUT_DIALOG_TYPE_LOG_OUT; |
9.1.74
by Ted Gould
Basic command line parsing. Not working 100% yet. |
160 |
|
161 |
static gboolean |
|
9.1.75
by Ted Gould
Getting all the parameters working so that we can set the dialog type |
162 |
option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error) |
163 |
{
|
|
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
164 |
type = LOGOUT_DIALOG_TYPE_LOG_OUT; |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
165 |
g_debug("Dialog type: logout"); |
9.1.75
by Ted Gould
Getting all the parameters working so that we can set the dialog type |
166 |
return TRUE; |
167 |
}
|
|
168 |
||
169 |
static gboolean |
|
170 |
option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error) |
|
171 |
{
|
|
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
172 |
type = LOGOUT_DIALOG_TYPE_SHUTDOWN; |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
173 |
g_debug("Dialog type: shutdown"); |
9.1.75
by Ted Gould
Getting all the parameters working so that we can set the dialog type |
174 |
return TRUE; |
175 |
}
|
|
176 |
||
177 |
static gboolean |
|
178 |
option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error) |
|
179 |
{
|
|
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
180 |
type = LOGOUT_DIALOG_TYPE_RESTART; |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
181 |
g_debug("Dialog type: restart"); |
9.1.74
by Ted Gould
Basic command line parsing. Not working 100% yet. |
182 |
return TRUE; |
183 |
}
|
|
184 |
||
185 |
static GOptionEntry options[] = { |
|
9.1.75
by Ted Gould
Getting all the parameters working so that we can set the dialog type |
186 |
{"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL}, |
78.2.1
by Ted Gould
Changing shutdowns to switch offs |
187 |
{"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Switch off the entire system", NULL}, |
9.1.75
by Ted Gould
Getting all the parameters working so that we can set the dialog type |
188 |
{"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL}, |
9.1.74
by Ted Gould
Basic command line parsing. Not working 100% yet. |
189 |
|
190 |
{NULL} |
|
191 |
};
|
|
192 |
||
322
by Charles Kerr
clearing house: the remainder of bugfixes & readability changes |
193 |
static gboolean |
194 |
suppress_confirmations (void) |
|
195 |
{
|
|
196 |
GSettings * s = g_settings_new (SESSION_SCHEMA); |
|
197 |
const gboolean suppress = g_settings_get_boolean (s, SUPPRESS_KEY); |
|
198 |
g_clear_object (&s); |
|
199 |
return suppress; |
|
200 |
}
|
|
201 |
||
202 |
||
203 |
||
9.1.66
by Ted Gould
Building a little dialog. Now it's kinda linked into the build system. |
204 |
int
|
205 |
main (int argc, char * argv[]) |
|
206 |
{
|
|
9.1.71
by Ted Gould
Make a dialog pop up. Not really the right one, but one. |
207 |
gtk_init(&argc, &argv); |
9.1.66
by Ted Gould
Building a little dialog. Now it's kinda linked into the build system. |
208 |
|
29.1.2
by Ted Gould
Adding locale stuff in here too! Fun. |
209 |
/* Setting up i18n and gettext. Apparently, we need
|
210 |
all of these. */
|
|
211 |
setlocale (LC_ALL, ""); |
|
212 |
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
|
213 |
textdomain (GETTEXT_PACKAGE); |
|
214 |
||
9.1.74
by Ted Gould
Basic command line parsing. Not working 100% yet. |
215 |
GError * error = NULL; |
216 |
GOptionContext * context = g_option_context_new(" - logout of the current session"); |
|
217 |
g_option_context_add_main_entries(context, options, "gtk-logout-helper"); |
|
218 |
g_option_context_add_group(context, gtk_get_option_group(TRUE)); |
|
219 |
g_option_context_set_help_enabled(context, TRUE); |
|
220 |
||
221 |
if (!g_option_context_parse(context, &argc, &argv, &error)) { |
|
222 |
g_debug("Option parsing failed: %s", error->message); |
|
223 |
g_error_free(error); |
|
224 |
return 1; |
|
225 |
}
|
|
226 |
||
24.3.1
by Ted Gould
Grabbing the icons from the indicator dir where we install them. |
227 |
/* Init some theme/icon stuff */
|
228 |
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), |
|
229 |
INDICATOR_ICONS_DIR); |
|
230 |
||
9.1.76
by Ted Gould
Now check for the PK dialog and otherwise run ours. If we get restart, restart |
231 |
GtkWidget * dialog = NULL; |
322
by Charles Kerr
clearing house: the remainder of bugfixes & readability changes |
232 |
if (!suppress_confirmations()) { |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
233 |
g_debug("Showing dialog to ask for user confirmation"); |
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
234 |
dialog = GTK_WIDGET(logout_dialog_new(type)); |
9.1.76
by Ted Gould
Now check for the PK dialog and otherwise run ours. If we get restart, restart |
235 |
}
|
236 |
||
237 |
if (dialog != NULL) { |
|
238 |
GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog)); |
|
239 |
gtk_widget_hide(dialog); |
|
240 |
||
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
241 |
if (response == GTK_RESPONSE_OK) { |
242 |
g_debug("Dialog return response: 'okay'"); |
|
243 |
} else if (response == GTK_RESPONSE_HELP) { |
|
244 |
g_debug("Dialog return response: 'help'"); |
|
245 |
} else { |
|
246 |
g_debug("Dialog return response: %d", response); |
|
247 |
}
|
|
248 |
||
9.1.76
by Ted Gould
Now check for the PK dialog and otherwise run ours. If we get restart, restart |
249 |
if (response == GTK_RESPONSE_HELP) { |
79.4.4
by Ted Gould
Changing to new enums and function prototypes. |
250 |
type = LOGOUT_DIALOG_TYPE_RESTART; |
9.1.76
by Ted Gould
Now check for the PK dialog and otherwise run ours. If we get restart, restart |
251 |
response = GTK_RESPONSE_OK; |
252 |
}
|
|
253 |
||
254 |
if (response != GTK_RESPONSE_OK) { |
|
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
255 |
g_debug("Final response was not okay, quiting"); |
9.1.76
by Ted Gould
Now check for the PK dialog and otherwise run ours. If we get restart, restart |
256 |
return 0; |
257 |
}
|
|
258 |
}
|
|
9.1.66
by Ted Gould
Building a little dialog. Now it's kinda linked into the build system. |
259 |
|
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
260 |
session_action(type); |
198.3.1
by Ted Gould
Lots of debug messages for the logout helper |
261 |
g_debug("Finished action, quiting"); |
9.1.77
by Ted Gould
Adding in the action code from our previous patches to FUSA |
262 |
|
9.1.66
by Ted Gould
Building a little dialog. Now it's kinda linked into the build system. |
263 |
return 0; |
264 |
}
|