2
* * Copyright (C) 2009 Ali <aliov@xfce.org>
4
* Licensed under the GNU General Public License Version 2
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* 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, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29
#include <dbus/dbus-glib.h>
31
#include "xfpm-console-kit.h"
32
#include "xfpm-dbus-monitor.h"
35
static void xfpm_console_kit_finalize (GObject *object);
37
static void xfpm_console_kit_get_property (GObject *object,
42
#define XFPM_CONSOLE_KIT_GET_PRIVATE(o) \
43
(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_CONSOLE_KIT, XfpmConsoleKitPrivate))
45
struct XfpmConsoleKitPrivate
50
XfpmDBusMonitor *monitor;
52
gboolean can_shutdown;
63
G_DEFINE_TYPE (XfpmConsoleKit, xfpm_console_kit, G_TYPE_OBJECT)
66
xfpm_console_kit_get_info (XfpmConsoleKit *console)
70
dbus_g_proxy_call (console->priv->proxy, "CanStop", &error,
72
G_TYPE_BOOLEAN, &console->priv->can_shutdown,
77
g_warning ("'CanStop' method failed : %s", error->message);
82
dbus_g_proxy_call (console->priv->proxy, "CanRestart", &error,
84
G_TYPE_BOOLEAN, &console->priv->can_restart,
89
g_warning ("'CanRestart' method failed : %s", error->message);
97
xfpm_console_kit_class_init (XfpmConsoleKitClass *klass)
99
GObjectClass *object_class = G_OBJECT_CLASS (klass);
101
object_class->finalize = xfpm_console_kit_finalize;
103
object_class->get_property = xfpm_console_kit_get_property;
105
g_object_class_install_property (object_class,
107
g_param_spec_boolean ("can-restart",
112
g_object_class_install_property (object_class,
114
g_param_spec_boolean ("can-shutdown",
119
g_type_class_add_private (klass, sizeof (XfpmConsoleKitPrivate));
123
xfpm_console_kit_init (XfpmConsoleKit *console)
125
GError *error = NULL;
127
console->priv = XFPM_CONSOLE_KIT_GET_PRIVATE (console);
128
console->priv->can_shutdown = FALSE;
129
console->priv->can_restart = FALSE;
131
console->priv->bus = NULL;
132
console->priv->proxy = NULL;
134
console->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
138
g_critical ("Unable to get system bus connection : %s", error->message);
139
g_error_free (error);
143
console->priv->proxy = dbus_g_proxy_new_for_name_owner (console->priv->bus,
144
"org.freedesktop.ConsoleKit",
145
"/org/freedesktop/ConsoleKit/Manager",
146
"org.freedesktop.ConsoleKit.Manager",
149
if ( !console->priv->proxy )
151
g_warning ("Unable to create proxy for 'org.freedesktop.ConsoleKit'");
155
xfpm_console_kit_get_info (console);
161
static void xfpm_console_kit_get_property (GObject *object,
166
XfpmConsoleKit *console;
167
console = XFPM_CONSOLE_KIT (object);
171
case PROP_CAN_SHUTDOWN:
172
g_value_set_boolean (value, console->priv->can_shutdown);
174
case PROP_CAN_RESTART:
175
g_value_set_boolean (value, console->priv->can_restart);
178
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
184
xfpm_console_kit_finalize (GObject *object)
186
XfpmConsoleKit *console;
188
console = XFPM_CONSOLE_KIT (object);
190
if ( console->priv->bus )
191
dbus_g_connection_unref (console->priv->bus);
193
if ( console->priv->proxy )
194
g_object_unref (console->priv->proxy);
196
G_OBJECT_CLASS (xfpm_console_kit_parent_class)->finalize (object);
200
xfpm_console_kit_new (void)
202
static gpointer console_obj = NULL;
204
if ( G_LIKELY (console_obj != NULL ) )
206
g_object_ref (console_obj);
210
console_obj = g_object_new (XFPM_TYPE_CONSOLE_KIT, NULL);
211
g_object_add_weak_pointer (console_obj, &console_obj);
214
return XFPM_CONSOLE_KIT (console_obj);
217
void xfpm_console_kit_shutdown (XfpmConsoleKit *console, GError **error)
219
g_return_if_fail (console->priv->proxy != NULL );
221
dbus_g_proxy_call (console->priv->proxy, "Stop", error,
223
G_TYPE_BOOLEAN, &console->priv->can_shutdown,
227
void xfpm_console_kit_reboot (XfpmConsoleKit *console, GError **error)
229
g_return_if_fail (console->priv->proxy != NULL );
231
dbus_g_proxy_call (console->priv->proxy, "Restart", error,
233
G_TYPE_BOOLEAN, &console->priv->can_shutdown,