[Goodies-commits] r6994 - in xfce4-power-manager/trunk: . src
Ali Abdallah
aliov at xfce.org
Wed Mar 25 13:03:07 CET 2009
Author: aliov
Date: 2009-03-25 12:03:07 +0000 (Wed, 25 Mar 2009)
New Revision: 6994
Added:
xfce4-power-manager/trunk/src/xfpm-errors.c
xfce4-power-manager/trunk/src/xfpm-errors.h
Removed:
xfce4-power-manager/trunk/src/xfce-power-manager.desktop.in
Modified:
xfce4-power-manager/trunk/ChangeLog
xfce4-power-manager/trunk/src/Makefile.am
xfce4-power-manager/trunk/src/xfpm-engine.c
xfce4-power-manager/trunk/src/xfpm-inhibit.c
xfce4-power-manager/trunk/src/xfpm-inhibit.h
xfce4-power-manager/trunk/src/xfpm-marshal.list
xfce4-power-manager/trunk/src/xfpm-supply.c
xfce4-power-manager/trunk/src/xfpm-supply.h
Log:
Added xfpm-errors quark for the common errors
Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/ChangeLog 2009-03-25 12:03:07 UTC (rev 6994)
@@ -1,4 +1,7 @@
+2009-03-25 13:03 Ali aliov at xfce.org
+ * : Added xfpm-errors quark for the common errors
+
2009-03-24 16:34 Ali aliov at xfce.org
* : Fix missing files in the POTFILES+rename the settings desktop file
Modified: xfce4-power-manager/trunk/src/Makefile.am
===================================================================
--- xfce4-power-manager/trunk/src/Makefile.am 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/src/Makefile.am 2009-03-25 12:03:07 UTC (rev 6994)
@@ -47,6 +47,8 @@
xfpm-tray-icon.h \
xfpm-network-manager.c \
xfpm-network-manager.h \
+ xfpm-errors.c \
+ xfpm-errors.h \
xfpm-config.h \
xfpm-enum.h
Modified: xfce4-power-manager/trunk/src/xfpm-engine.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-engine.c 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/src/xfpm-engine.c 2009-03-25 12:03:07 UTC (rev 6994)
@@ -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 @@
{
XfpmXfconf *conf;
XfpmSupply *supply;
+ XfpmNotify *notify;
+
XfpmCpu *cpu;
XfpmButtonXf86 *xf86_button;
XfpmLidHal *lid;
@@ -157,7 +161,7 @@
}
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 @@
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 @@
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 @@
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_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 @@
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 @@
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 @@
{
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 @@
"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,10 +667,21 @@
"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;
}
Added: xfce4-power-manager/trunk/src/xfpm-errors.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-errors.c (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-errors.c 2009-03-25 12:03:07 UTC (rev 6994)
@@ -0,0 +1,59 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at 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;
+}
Added: xfce4-power-manager/trunk/src/xfpm-errors.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-errors.h (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-errors.h 2009-03-25 12:03:07 UTC (rev 6994)
@@ -0,0 +1,49 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at 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 */
Modified: xfce4-power-manager/trunk/src/xfpm-inhibit.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-inhibit.c 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/src/xfpm-inhibit.c 2009-03-25 12:03:07 UTC (rev 6994)
@@ -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 @@
#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 @@
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 @@
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;
}
Modified: xfce4-power-manager/trunk/src/xfpm-inhibit.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-inhibit.h 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/src/xfpm-inhibit.h 2009-03-25 12:03:07 UTC (rev 6994)
@@ -29,16 +29,6 @@
#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
Modified: xfce4-power-manager/trunk/src/xfpm-marshal.list
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-marshal.list 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/src/xfpm-marshal.list 2009-03-25 12:03:07 UTC (rev 6994)
@@ -1 +1,2 @@
VOID:POINTER,UINT,UINT,UINT
+VOID:BOOLEAN,ENUM
Modified: xfce4-power-manager/trunk/src/xfpm-supply.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-supply.c 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/src/xfpm-supply.c 2009-03-25 12:03:07 UTC (rev 6994)
@@ -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 @@
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 @@
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 @@
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 @@
//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
Modified: xfce4-power-manager/trunk/src/xfpm-supply.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-supply.h 2009-03-25 09:05:33 UTC (rev 6993)
+++ xfce4-power-manager/trunk/src/xfpm-supply.h 2009-03-25 12:03:07 UTC (rev 6994)
@@ -46,6 +46,7 @@
GObjectClass parent_class;
void (*shutdown_request) (XfpmSupply *supply,
+ gboolean critical,
XfpmShutdownRequest action);
} XfpmSupplyClass;
More information about the Goodies-commits
mailing list