[Xfce4-commits] <xfce4-power-manager:devkit-power> Support for spinning downs hard disks via device-kit-disks to use this feature use has to have the policy kit permission on "org.freedesktop.devicekit.disks.drive-set-spindown"
Ali Abdallah
noreply at xfce.org
Fri Nov 6 18:12:02 CET 2009
Updating branch refs/heads/devkit-power
to f9292aa5c359545cf2043d8c58899367d113bdcf (commit)
from 8510408fe399538d6644428b2dd6c1cbaa72e168 (commit)
commit f9292aa5c359545cf2043d8c58899367d113bdcf
Author: Ali Abdallah <ali at ali-xfce.org>
Date: Fri Nov 6 17:00:06 2009 +0100
Support for spinning downs hard disks via device-kit-disks
to use this feature use has to have the policy kit permission on
"org.freedesktop.devicekit.disks.drive-set-spindown"
data/interfaces/xfpm-settings.ui | 54 +++++--
settings/xfpm-settings-main.c | 6 +-
settings/xfpm-settings.c | 94 ++++++++++---
settings/xfpm-settings.h | 2 +
src/Makefile.am | 2 +
src/xfpm-config.h | 42 +++---
src/xfpm-disks.c | 276 +++++++++++++++++++++++++++++++++++
src/{xfpm-xfconf.h => xfpm-disks.h} | 32 +++--
src/xfpm-main.c | 2 +
src/xfpm-manager.c | 14 ++-
src/xfpm-xfconf.c | 48 ++++++
11 files changed, 504 insertions(+), 68 deletions(-)
diff --git a/data/interfaces/xfpm-settings.ui b/data/interfaces/xfpm-settings.ui
index bc1cded..b4175f4 100644
--- a/data/interfaces/xfpm-settings.ui
+++ b/data/interfaces/xfpm-settings.ui
@@ -464,6 +464,19 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="spin-down-on-ac">
+ <property name="label" translatable="yes">Spin down hard disks</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_ac_spin_changed"/>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
</child>
</object>
@@ -789,20 +802,6 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="power-save">
- <property name="label" translatable="yes">Prefer power savings over performance</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
- <signal name="toggled" handler="power_save_toggled_cb"/>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
<object class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<property name="orientation">vertical</property>
@@ -833,9 +832,36 @@
</child>
</object>
<packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="power-save">
+ <property name="label" translatable="yes">Prefer power savings over performance</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="power_save_toggled_cb"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="spin-down-on-battery">
+ <property name="label" translatable="yes">Spin down hard disks</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_battery_spin_changed"/>
+ </object>
+ <packing>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/settings/xfpm-settings-main.c b/settings/xfpm-settings-main.c
index 9d751e7..b228d7f 100644
--- a/settings/xfpm-settings-main.c
+++ b/settings/xfpm-settings-main.c
@@ -61,6 +61,8 @@ int main (int argc, char **argv)
gboolean has_hibernate_button;
gboolean has_power_button;
gboolean has_lid;
+ gboolean can_spin_down;
+ gboolean devkit_disk;
gboolean start_xfpm_if_not_running;
GdkNativeWindow socket_id = 0;
@@ -159,11 +161,13 @@ int main (int argc, char **argv)
has_power_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "power-button"));
has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "hibernate-button"));
can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-shutdown"));
+ can_spin_down = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-spin"));
+ devkit_disk = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "devkit-disk"));
xfpm_settings_dialog_new (channel, has_battery, auth_hibernate, auth_suspend,
can_shutdown, can_suspend, can_hibernate, has_lcd_brightness,
has_lid, has_sleep_button, has_hibernate_button, has_power_button,
- socket_id);
+ devkit_disk, can_spin_down, socket_id);
gtk_main();
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index 0403c28..8199995 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -148,7 +148,10 @@ void critical_level_value_changed_cb (GtkSpinButton *w,
void lock_screen_toggled_cb (GtkWidget *w,
XfconfChannel *channel);
-void cpu_freq_control_changed_cb (GtkWidget *w,
+void on_battery_spin_changed (GtkWidget *w,
+ XfconfChannel *channel);
+
+void on_ac_spin_changed (GtkWidget *w,
XfconfChannel *channel);
void _cursor_changed_cb (GtkTreeView *view,
@@ -701,24 +704,33 @@ lock_screen_toggled_cb (GtkWidget *w, XfconfChannel *channel)
}
}
-void
-cpu_freq_control_changed_cb (GtkWidget *w, XfconfChannel *channel)
+void on_battery_spin_changed (GtkWidget *w, XfconfChannel *channel)
{
-#ifdef SYSTEM_IS_LINUX
- gboolean val = (gint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
+ gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
- if ( !xfconf_channel_set_bool (channel, PROPERTIES_PREFIX CPU_FREQ_CONTROL, val) )
+ if ( !xfconf_channel_set_bool (channel, SPIN_DOWN_ON_BATTERY, val) )
{
- g_critical ("Unable to set value for property %s\n", CPU_FREQ_CONTROL);
+ g_critical ("Unable to set value for property %s\n", SPIN_DOWN_ON_BATTERY);
}
-#endif
+
}
+void on_ac_spin_changed (GtkWidget *w, XfconfChannel *channel)
+{
+ gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
+
+ if ( !xfconf_channel_set_bool (channel, SPIN_DOWN_ON_AC, val) )
+ {
+ g_critical ("Unable to set value for property %s\n", SPIN_DOWN_ON_AC);
+ }
+}
static void
-xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_hibernate, gboolean auth_suspend,
- gboolean can_shutdown, gboolean can_suspend,
- gboolean can_hibernate, gboolean has_lcd_brightness, gboolean has_lid)
+xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_hibernate,
+ gboolean auth_suspend, gboolean can_shutdown,
+ gboolean can_suspend, gboolean can_hibernate,
+ gboolean has_lcd_brightness, gboolean has_lid,
+ gboolean devkit_disk, gboolean can_spin_down)
{
gboolean valid;
gint list_value;
@@ -733,6 +745,7 @@ xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_hibernate, gbool
GtkWidget *label;
GtkWidget *brg;
GtkWidget *frame;
+ GtkWidget *spin_down;
#ifdef HAVE_DPMS
GtkWidget *dpms_frame_on_battery;
#endif
@@ -891,17 +904,31 @@ xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_hibernate, gbool
gtk_notebook_remove_page (GTK_NOTEBOOK (nt), 1);
}
#endif
+
+ spin_down = GTK_WIDGET (gtk_builder_get_object (xml, "spin-down-on-battery"));
+ gtk_widget_set_sensitive (spin_down, can_spin_down);
+
+ if ( !devkit_disk )
+ {
+ gtk_widget_hide (spin_down);
+ }
+ else if ( !can_spin_down )
+ {
+ gtk_widget_set_tooltip_text (spin_down, _("Spinning down hard disks permission denied"));
+ }
}
static void
-xfpm_settings_on_ac (XfconfChannel *channel, gboolean auth_suspend, gboolean auth_hibernate,
- gboolean can_suspend, gboolean can_hibernate,
- gboolean has_lcd_brightness, gboolean has_lid)
+xfpm_settings_on_ac (XfconfChannel *channel, gboolean auth_suspend,
+ gboolean auth_hibernate, gboolean can_suspend,
+ gboolean can_hibernate, gboolean has_lcd_brightness,
+ gboolean has_lid, gboolean devkit_disk, gboolean can_spin_down)
{
GtkWidget *inact;
GtkWidget *lid;
GtkWidget *frame;
GtkWidget *brg;
+ GtkWidget *spin_down;
GtkListStore *list_store;
GtkTreeIter iter;
guint val;
@@ -1013,6 +1040,19 @@ xfpm_settings_on_ac (XfconfChannel *channel, gboolean auth_suspend, gboolean aut
gtk_notebook_remove_page (GTK_NOTEBOOK (GTK_WIDGET (gtk_builder_get_object (xml, "on-ac-notebook"))), 1);
}
#endif
+
+ spin_down = GTK_WIDGET (gtk_builder_get_object (xml, "spin-down-on-ac"));
+ gtk_widget_set_sensitive (spin_down, can_spin_down);
+
+ if ( !devkit_disk )
+ {
+ gtk_widget_hide (spin_down);
+ }
+ else if ( !can_spin_down )
+ {
+ gtk_widget_set_tooltip_text (spin_down, _("Spinning down hard disks permission denied"));
+ }
+
}
static void
@@ -1535,6 +1575,7 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean system_laptop,
gboolean can_hibernate, gboolean has_lcd_brightness,
gboolean has_lid, gboolean has_sleep_button,
gboolean has_hibernate_button, gboolean has_power_button,
+ gboolean devkit_disk, gboolean can_spin_down,
GdkNativeWindow id)
{
GtkWidget *plug;
@@ -1543,13 +1584,13 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean system_laptop,
GError *error = NULL;
g_debug ("system_laptop=%s auth_hibernate=%s auth_suspend=%s can_shutdown=%s can_suspend=%s can_hibernate=%s has_lcd_brightness=%s has_lid=%s "\
- "has_sleep_button=%s has_hibernate_button=%s has_power_button=%s",
+ "has_sleep_button=%s has_hibernate_button=%s has_power_button=%s can_spin_down=%s",
xfpm_bool_to_string (system_laptop), xfpm_bool_to_string (auth_hibernate),
xfpm_bool_to_string (can_shutdown), xfpm_bool_to_string (auth_suspend),
xfpm_bool_to_string (can_suspend), xfpm_bool_to_string (can_hibernate),
xfpm_bool_to_string (has_lcd_brightness), xfpm_bool_to_string (has_lid),
xfpm_bool_to_string (has_sleep_button), xfpm_bool_to_string (has_hibernate_button),
- xfpm_bool_to_string (has_power_button) );
+ xfpm_bool_to_string (has_power_button), xfpm_bool_to_string (can_spin_down) );
xml = xfpm_builder_new_from_string (xfpm_settings_ui, &error);
@@ -1571,10 +1612,27 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean system_laptop,
dialog = GTK_WIDGET (gtk_builder_get_object (xml, "xfpm-settings-dialog"));
nt = GTK_WIDGET (gtk_builder_get_object (xml, "main-notebook"));
- xfpm_settings_on_ac (channel, auth_hibernate, auth_suspend, can_suspend, can_hibernate, has_lcd_brightness, has_lid );
+ xfpm_settings_on_ac (channel,
+ auth_hibernate,
+ auth_suspend,
+ can_suspend,
+ can_hibernate,
+ has_lcd_brightness,
+ has_lid,
+ devkit_disk,
+ can_spin_down);
if ( system_laptop )
- xfpm_settings_on_battery (channel, auth_hibernate, auth_suspend, can_shutdown, can_suspend, can_hibernate, has_lcd_brightness, has_lid);
+ xfpm_settings_on_battery (channel,
+ auth_hibernate,
+ auth_suspend,
+ can_shutdown,
+ can_suspend,
+ can_hibernate,
+ has_lcd_brightness,
+ has_lid,
+ devkit_disk,
+ can_spin_down);
xfpm_settings_tree_view (channel, system_laptop);
diff --git a/settings/xfpm-settings.h b/settings/xfpm-settings.h
index 2b86d52..0d39852 100644
--- a/settings/xfpm-settings.h
+++ b/settings/xfpm-settings.h
@@ -34,6 +34,8 @@ void xfpm_settings_dialog_new (XfconfChannel *channel,
gboolean has_sleep_button,
gboolean has_hibernate_button,
gboolean has_power_button,
+ gboolean devkit_disk,
+ gboolean can_spin_down,
GdkNativeWindow id);
diff --git a/src/Makefile.am b/src/Makefile.am
index dbf19cd..d999efd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,6 +15,8 @@ xfce4_power_manager_SOURCES = \
xfpm-battery-info.h \
xfpm-xfconf.c \
xfpm-xfconf.h \
+ xfpm-disks.c \
+ xfpm-disks.h \
xfpm-console-kit.c \
xfpm-console-kit.h \
xfpm-idle.c \
diff --git a/src/xfpm-config.h b/src/xfpm-config.h
index 226402c..39b5a75 100644
--- a/src/xfpm-config.h
+++ b/src/xfpm-config.h
@@ -28,10 +28,6 @@
#include <glib.h>
-#if defined(__linux__)
-#define SYSTEM_IS_LINUX 1
-#endif
-
G_BEGIN_DECLS
#define XFPM_CHANNEL_CFG "xfce4-power-manager"
@@ -39,43 +35,49 @@ G_BEGIN_DECLS
/*
* Backward compatibility with old version.
*/
-#define PROPERTIES_PREFIX "/xfce4-power-manager/"
+#define PROPERTIES_PREFIX "/xfce4-power-manager/"
#define POWER_SAVE_ON_BATTERY "power-save-on-battery"
-#define CPU_FREQ_CONTROL "enable-cpu-freq-control"
-#define LOCK_SCREEN_ON_SLEEP "lock-screen-suspend-hibernate"
+#define CPU_FREQ_CONTROL "enable-cpu-freq-control"
+#define LOCK_SCREEN_ON_SLEEP "lock-screen-suspend-hibernate"
#define DPMS_ENABLED_CFG "dpms-enabled"
-#define ON_AC_DPMS_SLEEP "dpms-on-ac-sleep"
+#define ON_AC_DPMS_SLEEP "dpms-on-ac-sleep"
#define ON_AC_DPMS_OFF "dpms-on-ac-off"
-#define ON_BATT_DPMS_SLEEP "dpms-on-battery-sleep"
-#define ON_BATT_DPMS_OFF "dpms-on-battery-off"
-#define DPMS_SLEEP_MODE "dpms-sleep-mode"
+#define ON_BATT_DPMS_SLEEP "dpms-on-battery-sleep"
+#define ON_BATT_DPMS_OFF "dpms-on-battery-off"
+#define DPMS_SLEEP_MODE "dpms-sleep-mode"
#define GENERAL_NOTIFICATION_CFG "general-notification"
-#define ON_AC_INACTIVITY_TIMEOUT "inactivity-on-ac"
-#define ON_BATTERY_INACTIVITY_TIMEOUT "inactivity-on-battery"
-#define INACTIVITY_SLEEP_MODE "inactivity-sleep-mode"
+#define ON_AC_INACTIVITY_TIMEOUT "inactivity-on-ac"
+#define ON_BATTERY_INACTIVITY_TIMEOUT "inactivity-on-battery"
+#define INACTIVITY_SLEEP_MODE "inactivity-sleep-mode"
-#define BRIGHTNESS_ON_AC "brightness-on-ac"
-#define BRIGHTNESS_ON_BATTERY "brightness-on-battery"
+#define BRIGHTNESS_ON_AC "brightness-on-ac"
+#define BRIGHTNESS_ON_BATTERY "brightness-on-battery"
-#define CRITICAL_POWER_LEVEL "critical-power-level"
-#define SHOW_BRIGHTNESS_POPUP "show-brightness-popup"
-#define ENABLE_BRIGHTNESS_CONTROL "change-brightness-on-key-events"
+#define CRITICAL_POWER_LEVEL "critical-power-level"
+#define SHOW_BRIGHTNESS_POPUP "show-brightness-popup"
+#define ENABLE_BRIGHTNESS_CONTROL "change-brightness-on-key-events"
#define SHOW_TRAY_ICON_CFG "show-tray-icon"
#define CRITICAL_BATT_ACTION_CFG "critical-power-action"
#define POWER_SWITCH_CFG "power-button-action"
-#define HIBERNATE_SWITCH_CFG "hibernate-button-action"
+#define HIBERNATE_SWITCH_CFG "hibernate-button-action"
#define SLEEP_SWITCH_CFG "sleep-button-action"
#define LID_SWITCH_ON_AC_CFG "lid-action-on-ac"
#define LID_SWITCH_ON_BATTERY_CFG "lid-action-on-battery"
+#define SPIN_DOWN_ON_AC "spin-down-on-ac"
+#define SPIN_DOWN_ON_BATTERY "spin-down-on-battery"
+
+#define SPIN_DOWN_ON_AC_TIMEOUT "spin-down-on-ac-timeout"
+#define SPIN_DOWN_ON_BATTERY_TIMEOUT "spin-down-on-battery-timeout"
+
G_END_DECLS
#endif /* __XFPM_CONFIG_H */
diff --git a/src/xfpm-disks.c b/src/xfpm-disks.c
new file mode 100644
index 0000000..3f38012
--- /dev/null
+++ b/src/xfpm-disks.c
@@ -0,0 +1,276 @@
+/*
+ * * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dbus/dbus-glib.h>
+
+#include "xfpm-disks.h"
+#include "xfpm-polkit.h"
+#include "xfpm-xfconf.h"
+#include "xfpm-dkp.h"
+#include "xfpm-config.h"
+
+static void xfpm_disks_finalize (GObject *object);
+
+#define XFPM_DISKS_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_DISKS, XfpmDisksPrivate))
+
+struct XfpmDisksPrivate
+{
+ XfpmXfconf *conf;
+ XfpmDkp *dkp;
+ XfpmPolkit *polkit;
+
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
+ gchar *cookie;
+ gboolean set;
+ gboolean can_spin;
+};
+
+G_DEFINE_TYPE (XfpmDisks, xfpm_disks, G_TYPE_OBJECT)
+
+static void
+xfpm_disks_class_init (XfpmDisksClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = xfpm_disks_finalize;
+
+ g_type_class_add_private (klass, sizeof (XfpmDisksPrivate));
+}
+
+static void
+xfpm_disks_disable_spin_down_timeouts (XfpmDisks *disks)
+{
+ GError *error = NULL;
+
+ disks->priv->set = FALSE;
+
+ g_debug ("Clearing spin down timeout");
+
+ dbus_g_proxy_call (disks->priv->proxy, "DriveUnsetAllSpindownTimeouts", &error,
+ G_TYPE_STRING, disks->priv->cookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+ if ( error )
+ {
+ g_warning ("Failed to unset spindown timeouts : %s", error->message);
+ g_error_free (error);
+ disks->priv->set = TRUE;
+ }
+
+ g_free (disks->priv->cookie);
+ disks->priv->cookie = NULL;
+}
+
+static void
+xfpm_disks_enable_spin_down_timeouts (XfpmDisks *disks, gint timeout)
+{
+ GError *error = NULL;
+ const gchar **options = { NULL };
+
+ disks->priv->set = TRUE;
+
+ g_debug ("Setting spin down timeout %d", timeout);
+
+ dbus_g_proxy_call (disks->priv->proxy, "DriveSetAllSpindownTimeouts", &error,
+ G_TYPE_INT, timeout,
+ G_TYPE_STRING, options,
+ G_TYPE_STRING, disks->priv->cookie,
+ G_TYPE_INVALID);
+
+ if ( error )
+ {
+ g_warning ("Failed to unset spindown timeouts : %s", error->message);
+ g_error_free (error);
+ disks->priv->set = FALSE;
+ }
+}
+
+static void
+xfpm_disks_set_spin_timeouts (XfpmDisks *disks)
+{
+ gboolean enabled;
+ gboolean on_battery;
+ gint timeout = 0;
+
+ if (!disks->priv->can_spin )
+ return;
+
+ g_object_get (G_OBJECT (disks),
+ "on-battery", &on_battery,
+ NULL);
+
+ if ( !on_battery )
+ {
+ g_object_get (G_OBJECT (disks->priv->conf),
+ SPIN_DOWN_ON_AC, &enabled,
+ SPIN_DOWN_ON_AC_TIMEOUT, &timeout,
+ NULL);
+ }
+ else
+ {
+ g_object_get (G_OBJECT (disks->priv->conf),
+ SPIN_DOWN_ON_BATTERY, &enabled,
+ SPIN_DOWN_ON_BATTERY_TIMEOUT, &timeout,
+ NULL);
+ }
+
+ g_debug ("On Battery=%d spin_down_enabled=%d timeout=%d\n", on_battery, enabled, timeout);
+
+ if ( !enabled && disks->priv->set && disks->priv->cookie)
+ {
+ xfpm_disks_disable_spin_down_timeouts (disks);
+ }
+ else if ( timeout != 0 && timeout > 120 && !disks->priv->set)
+ {
+ xfpm_disks_enable_spin_down_timeouts (disks, timeout);
+ }
+}
+
+static void
+xfpm_disks_get_is_auth_to_spin (XfpmDisks *disks)
+{
+ disks->priv->can_spin = xfpm_polkit_check_auth (disks->priv->polkit,
+ "org.freedesktop.devicekit.disks.drive-set-spindown");
+
+ g_debug ("Is auth to spin down disks : %d", disks->priv->can_spin);
+}
+
+static void
+xfpm_disks_init (XfpmDisks *disks)
+{
+ GError *error = NULL;
+
+ disks->priv = XFPM_DISKS_GET_PRIVATE (disks);
+
+ disks->priv->can_spin = FALSE;
+ disks->priv->bus = NULL;
+ disks->priv->proxy = NULL;
+ disks->priv->conf = NULL;
+ disks->priv->dkp = NULL;
+ disks->priv->cookie = NULL;
+ disks->priv->polkit = NULL;
+
+ disks->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+
+ if ( error )
+ {
+ g_critical ("Unable to get system bus connection : %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ disks->priv->proxy = dbus_g_proxy_new_for_name (disks->priv->bus,
+ "org.freedesktop.DeviceKit.Disks",
+ "/org/freedesktop/DeviceKit/Disks",
+ "org.freedesktop.DeviceKit.Disks");
+
+ if ( !disks->priv->proxy )
+ {
+ g_warning ("Unable to create proxy for 'org.freedesktop.DeviceKit.Disks'");
+ goto out;
+ }
+
+ disks->priv->conf = xfpm_xfconf_new ();
+ disks->priv->dkp = xfpm_dkp_get ();
+ disks->priv->polkit = xfpm_polkit_get ();
+
+ xfpm_disks_get_is_auth_to_spin (disks);
+
+ g_signal_connect_swapped (disks->priv->polkit, "auth-changed",
+ G_CALLBACK (xfpm_disks_get_is_auth_to_spin), disks);
+
+ g_signal_connect_swapped (disks->priv->dkp, "on-battery-changed",
+ G_CALLBACK (xfpm_disks_set_spin_timeouts), disks);
+
+ g_signal_connect_swapped (disks->priv->conf, "notify::" SPIN_DOWN_ON_AC,
+ G_CALLBACK (xfpm_disks_set_spin_timeouts), disks);
+
+ g_signal_connect_swapped (disks->priv->conf, "notify::" SPIN_DOWN_ON_AC_TIMEOUT,
+ G_CALLBACK (xfpm_disks_set_spin_timeouts), disks);
+
+ g_signal_connect_swapped (disks->priv->conf, "notify::" SPIN_DOWN_ON_BATTERY,
+ G_CALLBACK (xfpm_disks_set_spin_timeouts), disks);
+
+ g_signal_connect_swapped (disks->priv->conf, "notify::" SPIN_DOWN_ON_BATTERY_TIMEOUT,
+ G_CALLBACK (xfpm_disks_set_spin_timeouts), disks);
+
+ xfpm_disks_set_spin_timeouts (disks);
+
+out:
+ ;
+
+}
+
+static void
+xfpm_disks_finalize (GObject *object)
+{
+ XfpmDisks *disks;
+
+ disks = XFPM_DISKS (object);
+
+ if (disks->priv->can_spin && disks->priv->set )
+ xfpm_disks_disable_spin_down_timeouts (disks);
+
+ if ( disks->priv->bus )
+ dbus_g_connection_unref (disks->priv->bus);
+
+ if ( disks->priv->proxy )
+ g_object_unref (disks->priv->proxy);
+
+ if ( disks->priv->polkit )
+ g_object_unref (disks->priv->polkit);
+
+ if ( disks->priv->conf )
+ g_object_unref (disks->priv->conf);
+
+ if ( disks->priv->dkp )
+ g_object_unref (disks->priv->dkp );
+
+ G_OBJECT_CLASS (xfpm_disks_parent_class)->finalize (object);
+}
+
+XfpmDisks *
+xfpm_disks_new (void)
+{
+ XfpmDisks *disks = NULL;
+ disks = g_object_new (XFPM_TYPE_DISKS, NULL);
+ return disks;
+}
+
+gboolean xfpm_disks_get_can_spin (XfpmDisks *disks)
+{
+ return disks->priv->can_spin;
+}
+
+gboolean xfpm_disks_kit_is_running (XfpmDisks *disks)
+{
+ return disks->priv->proxy != NULL ? TRUE : FALSE;
+}
diff --git a/src/xfpm-xfconf.h b/src/xfpm-disks.h
similarity index 56%
copy from src/xfpm-xfconf.h
copy to src/xfpm-disks.h
index 1fb4af1..61a8080 100644
--- a/src/xfpm-xfconf.h
+++ b/src/xfpm-disks.h
@@ -18,36 +18,40 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __XFPM_XFCONF_H
-#define __XFPM_XFCONF_H
+#ifndef __XFPM_DISKS_H
+#define __XFPM_DISKS_H
#include <glib-object.h>
G_BEGIN_DECLS
-#define XFPM_TYPE_XFCONF (xfpm_xfconf_get_type () )
-#define XFPM_XFCONF(o) (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_XFCONF, XfpmXfconf))
-#define XFPM_IS_XFCONF(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_XFCONF))
+#define XFPM_TYPE_DISKS (xfpm_disks_get_type () )
+#define XFPM_DISKS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XFPM_TYPE_DISKS, XfpmDisks))
+#define XFPM_IS_DISKS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFPM_TYPE_DISKS))
-typedef struct XfpmXfconfPrivate XfpmXfconfPrivate;
+typedef struct XfpmDisksPrivate XfpmDisksPrivate;
typedef struct
{
- GObject parent;
- XfpmXfconfPrivate *priv;
+ GObject parent;
+ XfpmDisksPrivate *priv;
-} XfpmXfconf;
+} XfpmDisks;
typedef struct
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
-} XfpmXfconfClass;
+} XfpmDisksClass;
-GType xfpm_xfconf_get_type (void) G_GNUC_CONST;
+GType xfpm_disks_get_type (void) G_GNUC_CONST;
-XfpmXfconf *xfpm_xfconf_new (void);
+XfpmDisks *xfpm_disks_new (void);
+
+gboolean xfpm_disks_get_can_spin (XfpmDisks *disks);
+
+gboolean xfpm_disks_kit_is_running (XfpmDisks *disks);
G_END_DECLS
-#endif /* __XFPM_XFCONF_H */
+#endif /* __XFPM_DISKS_H */
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index 80c2f42..c45a1d8 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -137,6 +137,8 @@ int main (int argc, char **argv)
xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
+ g_set_application_name (PACKAGE_NAME);
+
if (!gtk_init_with_args (&argc, &argv, (gchar *)"", option_entries, (gchar *)PACKAGE, &error))
{
if (G_LIKELY (error))
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index 596fe6f..89b7517 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -40,6 +40,7 @@
#include "xfpm-dkp.h"
#include "xfpm-dbus.h"
+#include "xfpm-disks.h"
#include "xfpm-dpms.h"
#include "xfpm-manager.h"
#include "xfpm-console-kit.h"
@@ -79,6 +80,7 @@ struct XfpmManagerPrivate
XfpmBacklight *backlight;
XfpmConsoleKit *console;
XfpmDBusMonitor *monitor;
+ XfpmDisks *disks;
#ifdef HAVE_DPMS
XfpmDpms *dpms;
@@ -127,6 +129,8 @@ xfpm_manager_finalize (GObject *object)
g_object_unref (manager->priv->client);
g_object_unref (manager->priv->console);
g_object_unref (manager->priv->monitor);
+ g_object_unref (manager->priv->disks);
+
g_timer_destroy (manager->priv->timer);
#ifdef HAVE_DPMS
@@ -358,7 +362,7 @@ xfpm_manager_new (DBusGConnection *bus, const gchar *client_id)
client_id,
current_dir,
restart_command,
- NULL);
+ PACKAGE_NAME ".desktop");
g_free (current_dir);
@@ -395,6 +399,7 @@ void xfpm_manager_start (XfpmManager *manager)
manager->priv->conf = xfpm_xfconf_new ();
manager->priv->console = xfpm_console_kit_new ();
manager->priv->monitor = xfpm_dbus_monitor_new ();
+ manager->priv->disks = xfpm_disks_new ();
g_signal_connect (manager->priv->monitor, "system-bus-connection-changed",
G_CALLBACK (xfpm_manager_system_bus_connection_changed_cb), manager);
@@ -511,6 +516,8 @@ static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
gboolean has_lcd_brightness = TRUE;
gboolean can_shutdown = TRUE;
gboolean has_lid = FALSE;
+ gboolean can_spin = FALSE;
+ gboolean devkit_disk = FALSE;
*OUT_config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -525,6 +532,9 @@ static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
"can-hibernate", &can_hibernate,
"has-lid", &has_lid,
NULL);
+
+ can_spin = xfpm_disks_get_can_spin (manager->priv->disks);
+ devkit_disk = xfpm_disks_kit_is_running (manager->priv->disks);
has_battery = xfpm_dkp_has_battery (manager->priv->dkp);
has_lcd_brightness = xfpm_backlight_has_hw (manager->priv->backlight);
@@ -549,6 +559,8 @@ static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
g_hash_table_insert (*OUT_config, g_strdup ("has-battery"), g_strdup (xfpm_bool_to_string (has_battery)));
g_hash_table_insert (*OUT_config, g_strdup ("has-lid"), g_strdup (xfpm_bool_to_string (has_lid)));
+ g_hash_table_insert (*OUT_config, g_strdup ("can-spin"), g_strdup (xfpm_bool_to_string (can_spin)));
+ g_hash_table_insert (*OUT_config, g_strdup ("devkit-disk"), g_strdup (xfpm_bool_to_string (devkit_disk)));
g_hash_table_insert (*OUT_config, g_strdup ("has-brightness"), g_strdup (xfpm_bool_to_string (has_lcd_brightness)));
diff --git a/src/xfpm-xfconf.c b/src/xfpm-xfconf.c
index 359d0c6..fd562f0 100644
--- a/src/xfpm-xfconf.c
+++ b/src/xfpm-xfconf.c
@@ -78,6 +78,10 @@ enum
PROP_IDLE_SLEEP_MODE,
PROP_DIM_ON_AC_TIMEOUT,
PROP_DIM_ON_BATTERY_TIMEOUT,
+ PROP_SPIN_DOWN_DISK_ON_AC,
+ PROP_SPIN_DOWN_DISK_ON_BATTERY,
+ PROP_SPIN_DOWN_DISK_ON_AC_TIMEOUT,
+ PROP_SPIN_DOWN_DISK_ON_BATTERY_TIMEOUT,
N_PROPERTIES
};
@@ -461,6 +465,50 @@ xfpm_xfconf_class_init (XfpmXfconfClass *klass)
120,
G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::spin-down-on-ac
+ **/
+ g_object_class_install_property (object_class,
+ PROP_SPIN_DOWN_DISK_ON_AC,
+ g_param_spec_boolean (SPIN_DOWN_ON_AC,
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::spin-down-on-battery
+ **/
+ g_object_class_install_property (object_class,
+ PROP_SPIN_DOWN_DISK_ON_BATTERY,
+ g_param_spec_boolean (SPIN_DOWN_ON_BATTERY,
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::spin-down-on-ac-timeout
+ **/
+ g_object_class_install_property (object_class,
+ PROP_SPIN_DOWN_DISK_ON_AC_TIMEOUT,
+ g_param_spec_uint (SPIN_DOWN_ON_AC_TIMEOUT,
+ NULL, NULL,
+ 800,
+ G_MAXUINT,
+ 800,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::spin-down-on-battery-timeout
+ **/
+ g_object_class_install_property (object_class,
+ PROP_SPIN_DOWN_DISK_ON_BATTERY_TIMEOUT,
+ g_param_spec_uint (SPIN_DOWN_ON_BATTERY_TIMEOUT,
+ NULL, NULL,
+ 120,
+ G_MAXUINT,
+ 120,
+ G_PARAM_READWRITE));
+
g_type_class_add_private (klass, sizeof (XfpmXfconfPrivate));
}
More information about the Xfce4-commits
mailing list