summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAli Abdallah <ali.slackware@gmail.com>2009-03-25 12:03:07 +0000
committerAli Abdallah <ali.slackware@gmail.com>2009-03-25 12:03:07 +0000
commit0e64ff4535b1eb4ffd250db44622a0f7d8a31d03 (patch)
treef528106de428668a5857f3209aa8123a1dfb34b2 /src
parent1320e5f188f43d8db1d7dca215251225a87e89fc (diff)
downloadixfce4-power-manager-0e64ff4535b1eb4ffd250db44622a0f7d8a31d03.tar.gz
Added xfpm-errors quark for the common errors
(Old svn revision: 6994)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/xfce-power-manager.desktop.in9
-rw-r--r--src/xfpm-engine.c60
-rw-r--r--src/xfpm-errors.c59
-rw-r--r--src/xfpm-errors.h49
-rw-r--r--src/xfpm-inhibit.c36
-rw-r--r--src/xfpm-inhibit.h10
-rw-r--r--src/xfpm-marshal.list1
-rw-r--r--src/xfpm-supply.c17
-rw-r--r--src/xfpm-supply.h1
10 files changed, 173 insertions, 71 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index dc77c8db..467dc8d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,8 @@ xfce4_power_manager_SOURCES = \
xfpm-tray-icon.h \
xfpm-network-manager.c \
xfpm-network-manager.h \
+ xfpm-errors.c \
+ xfpm-errors.h \
xfpm-config.h \
xfpm-enum.h
diff --git a/src/xfce-power-manager.desktop.in b/src/xfce-power-manager.desktop.in
deleted file mode 100644
index ea5506eb..00000000
--- a/src/xfce-power-manager.desktop.in
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-_Name=Xfce Power Manager
-_Comment=Power management for the Xfce desktop
-Icon=gpm-ac-adapter
-Exec=xfce4-power-manager
-Terminal=false
-Type=Application
-OnlyShowIn=XFCE;
-StartupNotify=false \ No newline at end of file
diff --git a/src/xfpm-engine.c b/src/xfpm-engine.c
index 54e5a916..eeb6b681 100644
--- a/src/xfpm-engine.c
+++ b/src/xfpm-engine.c
@@ -45,6 +45,7 @@
#include "libxfpm/hal-device.h"
#include "libxfpm/xfpm-string.h"
#include "libxfpm/xfpm-common.h"
+#include "libxfpm/xfpm-notify.h"
#ifdef HAVE_DPMS
#include "xfpm-dpms.h"
@@ -61,6 +62,7 @@
#include "xfpm-inhibit.h"
#include "xfpm-backlight.h"
#include "xfpm-screen-saver.h"
+#include "xfpm-errors.h"
#include "xfpm-config.h"
/* Init */
@@ -78,6 +80,8 @@ struct XfpmEnginePrivate
{
XfpmXfconf *conf;
XfpmSupply *supply;
+ XfpmNotify *notify;
+
XfpmCpu *cpu;
XfpmButtonXf86 *xf86_button;
XfpmLidHal *lid;
@@ -157,7 +161,7 @@ xfpm_engine_do_shutdown (XfpmEngine *engine)
}
static void
-xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown)
+xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown, gboolean critical)
{
const gchar *action = xfpm_int_to_shutdown_string (shutdown);
@@ -166,7 +170,7 @@ xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown)
TRACE("Sleep button disabled in configuration");
return;
}
- else
+ else if ( !engine->priv->inhibited )
{
TRACE("Going to do %s\n", action);
xfpm_send_message_to_network_manager ("sleep");
@@ -186,14 +190,14 @@ xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown)
if ( engine->priv->lock_screen )
xfpm_lock_screen ();
-
}
}
static void
-xfpm_engine_shutdown_request_battery_cb (XfpmSupply *supply, XfpmShutdownRequest action, XfpmEngine *engine)
+xfpm_engine_shutdown_request_battery_cb (XfpmSupply *supply, gboolean critical,
+ XfpmShutdownRequest action, XfpmEngine *engine)
{
- xfpm_engine_shutdown_request (engine, action);
+ xfpm_engine_shutdown_request (engine, action, critical);
}
static void
@@ -207,7 +211,7 @@ xfpm_engine_xf86_button_pressed_cb (XfpmButtonXf86 *button, XfpmXF86Button type,
return;
TRACE("Accepting shutdown request");
- xfpm_engine_shutdown_request (engine, engine->priv->sleep_button);
+ xfpm_engine_shutdown_request (engine, engine->priv->sleep_button, FALSE);
}
}
@@ -236,7 +240,8 @@ xfpm_engine_lid_closed_cb (XfpmLidHal *lid, XfpmEngine *engine)
xfpm_engine_shutdown_request (engine, engine->priv->on_battery ?
engine->priv->lid_button_battery :
- engine->priv->lid_button_ac);
+ engine->priv->lid_button_ac,
+ FALSE);
}
static void
@@ -462,7 +467,8 @@ xfpm_engine_init (XfpmEngine *engine)
engine->priv = XFPM_ENGINE_GET_PRIVATE(engine);
engine->priv->iface = hal_iface_new ();
- engine->priv->adapter = xfpm_adapter_new ();
+ engine->priv->adapter = xfpm_adapter_new ();
+ engine->priv->notify = xfpm_notify_new ();
engine->priv->inhibit = xfpm_inhibit_new ();
engine->priv->inhibited = FALSE;
@@ -537,6 +543,8 @@ xfpm_engine_finalize (GObject *object)
if ( engine->priv->bk )
g_object_unref (engine->priv->bk);
+ g_object_unref (engine->priv->notify);
+
G_OBJECT_CLASS(xfpm_engine_parent_class)->finalize(object);
}
@@ -605,6 +613,10 @@ xfpm_engine_dbus_class_init(XfpmEngineClass *klass)
{
dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(klass),
&dbus_glib_xfpm_engine_object_info);
+
+ dbus_g_error_domain_register (XFPM_ERROR,
+ "org.freedesktop.PowerManagement",
+ XFPM_TYPE_ERROR);
}
static void
@@ -627,9 +639,20 @@ static gboolean xfpm_engine_dbus_hibernate (XfpmEngine *engine,
"caller-privilege", &caller_privilege,
"can-hibernate", &can_hibernate,
NULL);
+
+ if ( !caller_privilege)
+ {
+ g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED, _("Permission denied"));
+ return FALSE;
+ }
+
+ if ( !can_hibernate )
+ {
+ g_set_error (error, XFPM_ERROR, XFPM_ERROR_HIBERNATE_NOT_SUPPORTED, _("Hibernate not supported"));
+ return FALSE;
+ }
- if ( caller_privilege && can_hibernate )
- xfpm_engine_shutdown_request (engine, XFPM_DO_HIBERNATE);
+ xfpm_engine_shutdown_request (engine, XFPM_DO_HIBERNATE, FALSE);
return TRUE;
}
@@ -644,9 +667,20 @@ static gboolean xfpm_engine_dbus_suspend (XfpmEngine *engine,
"caller-privilege", &caller_privilege,
"can-suspend", &can_suspend,
NULL);
-
- if ( caller_privilege && can_suspend )
- xfpm_engine_shutdown_request (engine, XFPM_DO_SUSPEND);
+
+ if ( !caller_privilege)
+ {
+ g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED, _("Permission denied"));
+ return FALSE;
+ }
+
+ if ( !can_suspend )
+ {
+ g_set_error (error, XFPM_ERROR, XFPM_ERROR_SUSPEND_NOT_SUPPORTED, _("Suspend not supported"));
+ return FALSE;
+ }
+
+ xfpm_engine_shutdown_request (engine, XFPM_DO_SUSPEND, FALSE);
return TRUE;
}
diff --git a/src/xfpm-errors.c b/src/xfpm-errors.c
new file mode 100644
index 00000000..41c26084
--- /dev/null
+++ b/src/xfpm-errors.c
@@ -0,0 +1,59 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov@xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "xfpm-errors.h"
+
+static GQuark xfpm_error_quark = 0;
+
+GQuark
+xfpm_get_error_quark (void)
+{
+ if (xfpm_error_quark == 0)
+ xfpm_error_quark = g_quark_from_static_string ("xfpm-error-quark");
+
+ return xfpm_error_quark;
+}
+
+GType
+xfpm_error_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type)
+ {
+ static const GEnumValue values[] =
+ {
+ { XFPM_ERROR_UNKNOWN, "XFPM_ERROR_UNKNOWN", "Unknown" },
+ { XFPM_ERROR_PERMISSION_DENIED, "XFPM_ERROR_PERMISSION_DENIED", "PermissionDenied" },
+ { XFPM_ERROR_SUSPEND_NOT_SUPPORTED, "XFPM_ERROR_SUSPEND_NOT_SUPPORTED", "SuspendNotSupported" },
+ { XFPM_ERROR_HIBERNATE_NOT_SUPPORTED, "XFPM_ERROR_HIBERNATE_NOT_SUPPORTED", "HibernateNotSupported" },
+ { XFPM_ERROR_SUSPEND_HYBRID_NOT_SUPPORTED, "XFPM_ERROR_SUSPEND_HYBRID_NOT_SUPPORTED", "SuspendHybridNotSupported" },
+ { XFPM_ERROR_INVALID_COOKIE, "XFPM_ERROR_INVALID_COOKIE", "InvalidCookie" },
+ { 0, NULL, NULL }
+ };
+
+ type = g_enum_register_static ("XfpmError", values);
+ }
+ return type;
+}
diff --git a/src/xfpm-errors.h b/src/xfpm-errors.h
new file mode 100644
index 00000000..2c18dd3b
--- /dev/null
+++ b/src/xfpm-errors.h
@@ -0,0 +1,49 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov@xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFPM_ERRORS_H
+#define __XFPM_ERRORS_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_ERROR (xfpm_error_get_type ())
+#define XFPM_ERROR (xfpm_get_error_quark ())
+
+
+typedef enum
+{
+ XFPM_ERROR_UNKNOWN = 0,
+ XFPM_ERROR_PERMISSION_DENIED,
+ XFPM_ERROR_SUSPEND_NOT_SUPPORTED,
+ XFPM_ERROR_HIBERNATE_NOT_SUPPORTED,
+ XFPM_ERROR_SUSPEND_HYBRID_NOT_SUPPORTED,
+ XFPM_ERROR_INVALID_COOKIE
+
+} XfpmError;
+
+GType xfpm_error_get_type () G_GNUC_CONST;
+GQuark xfpm_get_error_quark ();
+
+
+G_END_DECLS
+
+#endif /*__XFPM_ERRORS_H */
diff --git a/src/xfpm-inhibit.c b/src/xfpm-inhibit.c
index 3f1743d8..02894d22 100644
--- a/src/xfpm-inhibit.c
+++ b/src/xfpm-inhibit.c
@@ -42,6 +42,7 @@
#include "xfpm-inhibit.h"
#include "xfpm-screen-saver.h"
+#include "xfpm-errors.h"
/* Init */
static void xfpm_inhibit_class_init (XfpmInhibitClass *klass);
@@ -54,35 +55,6 @@ static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit);
#define XFPM_INHIBIT_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_INHIBIT, XfpmInhibitPrivate))
-GQuark
-xfpm_inhibit_get_error_quark (void)
-{
- static GQuark quark = 0;
- if (!quark)
- quark = g_quark_from_static_string ("Xfce Power Manager inhibit");
-
- return quark;
-}
-
-GType
-xfpm_inhibit_error_get_type (void)
-{
- static GType type = 0;
-
- if (!type)
- {
- static const GEnumValue values[] = {
- { XFPM_INHIBIT_ERROR_UNKNOWN, "XFPM_INHIBIT_ERROR_UNKNOWN", "Unknown" },
- { XFPM_INHIBIT_ERROR_INVALID_COOKIE, "XFPM_INHIBIT_ERROR_INVALID_COOKIE", "InvalidCookie" },
- { 0, NULL, NULL }
- };
-
- type = g_enum_register_static ("XfpmInhibitError", values);
- }
-
- return type;
-}
-
struct XfpmInhibitPrivate
{
XfpmScreenSaver *srv;
@@ -245,9 +217,9 @@ static void xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass)
dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(klass),
&dbus_glib_xfpm_inhibit_object_info);
- dbus_g_error_domain_register (XFPM_INHIBIT_ERROR,
+ dbus_g_error_domain_register (XFPM_ERROR,
"org.freedesktop.PowerManagement.Inhibit",
- XFPM_TYPE_INHIBIT_ERROR);
+ XFPM_TYPE_ERROR);
}
static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit)
@@ -288,7 +260,7 @@ static gboolean xfpm_inhibit_dbus_un_inhibit (XfpmInhibit *inhibit,
if (!xfpm_inhibit_remove_application (inhibit, IN_cookie))
{
- g_set_error (error, XFPM_INHIBIT_ERROR, XFPM_INHIBIT_ERROR_INVALID_COOKIE, _("Invalid cookie"));
+ g_set_error (error, XFPM_ERROR, XFPM_ERROR_INVALID_COOKIE, _("Invalid cookie"));
return FALSE;
}
diff --git a/src/xfpm-inhibit.h b/src/xfpm-inhibit.h
index d5fdd9f2..d5c1f997 100644
--- a/src/xfpm-inhibit.h
+++ b/src/xfpm-inhibit.h
@@ -29,16 +29,6 @@ G_BEGIN_DECLS
#define XFPM_INHIBIT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_INHIBIT, XfpmInhibit))
#define XFPM_IS_INHIBIT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_INHIBIT))
-#define XFPM_TYPE_INHIBIT_ERROR (xfpm_inhibit_error_get_type ())
-#define XFPM_INHIBIT_ERROR (xfpm_inhibit_get_error_quark ())
-
-typedef enum
-{
- XFPM_INHIBIT_ERROR_UNKNOWN = 0,
- XFPM_INHIBIT_ERROR_INVALID_COOKIE
-
-} XfpmInhibitError;
-
typedef struct XfpmInhibitPrivate XfpmInhibitPrivate;
typedef struct
diff --git a/src/xfpm-marshal.list b/src/xfpm-marshal.list
index 596b3c49..c04716a0 100644
--- a/src/xfpm-marshal.list
+++ b/src/xfpm-marshal.list
@@ -1 +1,2 @@
VOID:POINTER,UINT,UINT,UINT
+VOID:BOOLEAN,ENUM
diff --git a/src/xfpm-supply.c b/src/xfpm-supply.c
index 3b633720..ba07a3a6 100644
--- a/src/xfpm-supply.c
+++ b/src/xfpm-supply.c
@@ -43,6 +43,7 @@
#include "xfpm-enum-types.h"
#include "xfpm-xfconf.h"
#include "xfpm-config.h"
+#include "xfpm-marshal.h"
/* Init */
static void xfpm_supply_class_init (XfpmSupplyClass *klass);
@@ -89,8 +90,10 @@ xfpm_supply_class_init(XfpmSupplyClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(XfpmSupplyClass, shutdown_request),
NULL, NULL,
- g_cclosure_marshal_VOID__ENUM,
- G_TYPE_NONE, 1, XFPM_TYPE_SHUTDOWN_REQUEST);
+ _xfpm_marshal_VOID__BOOLEAN_ENUM,
+ G_TYPE_NONE, 2,
+ G_TYPE_BOOLEAN,
+ XFPM_TYPE_SHUTDOWN_REQUEST);
object_class->finalize = xfpm_supply_finalize;
@@ -142,7 +145,7 @@ xfpm_supply_hibernate_cb (GtkWidget *w, XfpmSupply *supply)
if ( ret )
{
- g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_HIBERNATE);
+ g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, FALSE, XFPM_DO_HIBERNATE);
}
}
@@ -156,7 +159,7 @@ xfpm_supply_suspend_cb (GtkWidget *w, XfpmSupply *supply)
if ( ret )
{
- g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_SUSPEND);
+ g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, FALSE, XFPM_DO_SUSPEND);
}
}
@@ -248,16 +251,16 @@ xfpm_supply_process_critical_action (XfpmSupply *supply)
//FIXME: shouldn't happen
g_return_if_fail (supply->priv->critical_action != XFPM_DO_SUSPEND );
- g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, supply->priv->critical_action);
+ g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, TRUE, supply->priv->critical_action);
}
static void
_notify_action_callback (NotifyNotification *n, gchar *action, XfpmSupply *supply)
{
if ( xfpm_strequal(action, "shutdown") )
- g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_SHUTDOWN);
+ g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, TRUE, XFPM_DO_SHUTDOWN);
else if ( xfpm_strequal(action, "hibernate") )
- g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, XFPM_DO_SHUTDOWN);
+ g_signal_emit (G_OBJECT(supply ), signals[SHUTDOWN_REQUEST], 0, TRUE, XFPM_DO_SHUTDOWN);
}
static void
diff --git a/src/xfpm-supply.h b/src/xfpm-supply.h
index 08f54b6e..f25b91a8 100644
--- a/src/xfpm-supply.h
+++ b/src/xfpm-supply.h
@@ -46,6 +46,7 @@ typedef struct
GObjectClass parent_class;
void (*shutdown_request) (XfpmSupply *supply,
+ gboolean critical,
XfpmShutdownRequest action);
} XfpmSupplyClass;