[Xfce4-commits] [xfce/xfce4-power-manager] 09/14: Split up inactivity sleep mode for on battery / on AC

noreply at xfce.org noreply at xfce.org
Sun Jul 27 13:04:11 CEST 2014


This is an automated email from the git hooks/post-receive script.

hjudt pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit c8905336926d1f0b71b85665bce4d596a0bf0a86
Author: Harald Judt <h.judt at gmx.at>
Date:   Fri Jul 25 13:12:13 2014 +0200

    Split up inactivity sleep mode for on battery / on AC
---
 settings/xfpm-settings.c |  257 ++++++++++++++++++++++++++++++----------------
 src/xfpm-config.h        |    3 +-
 src/xfpm-manager.c       |   11 +-
 src/xfpm-xfconf.c        |   24 +++--
 4 files changed, 198 insertions(+), 97 deletions(-)

diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index 7c970fb..6f97bab 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -327,14 +327,14 @@ notify_toggled_cb (GtkWidget *w, XfconfChannel *channel)
 }
 
 void
-on_sleep_mode_changed_cb (GtkWidget *w, XfconfChannel *channel)
+on_ac_sleep_mode_changed_cb (GtkWidget *w, XfconfChannel *channel)
 {
     GtkTreeModel     *model;
     GtkTreeIter       selected_row;
     gchar *value = "";
-    
+
     if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
-	return;
+    return;
 
     model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
 
@@ -343,10 +343,34 @@ on_sleep_mode_changed_cb (GtkWidget *w, XfconfChannel *channel)
                        0,
                        &value,
                        -1);
-    
-    if (!xfconf_channel_set_string (channel, PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE, value) )
+
+    if (!xfconf_channel_set_string (channel, PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_AC, value) )
+    {
+    g_critical ("Cannot set value for property %s\n", INACTIVITY_SLEEP_MODE_ON_AC);
+    }
+}
+
+void
+on_battery_sleep_mode_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    GtkTreeModel     *model;
+    GtkTreeIter       selected_row;
+    gchar *value = "";
+
+    if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+    return;
+
+    model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+
+    gtk_tree_model_get(model,
+                       &selected_row,
+                       0,
+                       &value,
+                       -1);
+
+    if (!xfconf_channel_set_string (channel, PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_BATTERY, value) )
     {
-	g_critical ("Cannot set value for property %s\n", INACTIVITY_SLEEP_MODE);
+    g_critical ("Cannot set value for property %s\n", INACTIVITY_SLEEP_MODE_ON_BATTERY);
     }
 }
 
@@ -708,33 +732,93 @@ xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_suspend,
     gboolean valid;
     gint list_value;
     gint val;
+    gchar *str;
+    gchar *list_str;
     GtkListStore *list_store;
     GtkTreeIter iter;
-    GtkWidget *inact;
+    GtkWidget *inact_timeout, *inact_action;
     GtkWidget *battery_critical;
     GtkWidget *lid;
     GtkWidget *label;
     GtkWidget *brg;
     GtkWidget *brg_level;
 
-    battery_critical = GTK_WIDGET (gtk_builder_get_object (xml, "battery-critical-combox"));
-    
-    inact = GTK_WIDGET (gtk_builder_get_object (xml, "inactivity-on-battery"));
-    
+    /*
+     * Inactivity sleep mode on battery
+     */
+    list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+    inact_action = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-mode-on-battery"));
+    gtk_combo_box_set_model (GTK_COMBO_BOX(inact_action), GTK_TREE_MODEL(list_store));
+
+    if ( can_suspend )
+    {
+    gtk_list_store_append (list_store, &iter);
+    gtk_list_store_set (list_store, &iter, 0, _("Suspend"), -1);
+    }
+    else if ( !auth_suspend )
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not permitted"));
+    }
+    else
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not supported"));
+    }
+
+    if ( can_hibernate )
+    {
+    gtk_list_store_append (list_store, &iter);
+    gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), -1);
+    }
+    else if ( !auth_hibernate )
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not permitted"));
+    }
+    else
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not supported"));
+    }
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (inact_action), 0);
+
+    str = xfconf_channel_get_string (channel, PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_BATTERY, "Hibernate");
+    for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+      valid;
+      valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+    {
+    gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+                0, &list_str, -1);
+    if ( g_strcmp0 (str, list_str) )
+    {
+        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (inact_action), &iter);
+        break;
+    }
+    }
+    g_free (str);
+
+    /*
+     * Inactivity timeout on battery
+     */
+    inact_timeout = GTK_WIDGET (gtk_builder_get_object (xml, "inactivity-on-battery"));
+
     if ( !can_suspend && !can_hibernate )
     {
-	gtk_widget_set_sensitive (inact, FALSE);
-	gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not supported"));
+    gtk_widget_set_sensitive (inact_timeout, FALSE);
+    gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not supported"));
     }
-    else if ( !auth_suspend && !auth_hibernate )
+    else  if ( !auth_suspend && !auth_hibernate )
     {
-	gtk_widget_set_sensitive (inact, FALSE);
-	gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not permitted"));
+    gtk_widget_set_sensitive (inact_timeout, FALSE);
+    gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not permitted"));
     }
-    
+
     val = xfconf_channel_get_uint (channel, PROPERTIES_PREFIX ON_BATTERY_INACTIVITY_TIMEOUT, 14);
-    gtk_range_set_value (GTK_RANGE (inact), val);
-    
+    gtk_range_set_value (GTK_RANGE (inact_timeout), val);
+
+
+    /*
+     * Battery critical
+     */
+    battery_critical = GTK_WIDGET (gtk_builder_get_object (xml, "battery-critical-combox"));
     
     list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
     
@@ -872,34 +956,91 @@ xfpm_settings_on_ac (XfconfChannel *channel, gboolean auth_suspend,
                      gboolean can_hibernate, gboolean has_lcd_brightness,
                      gboolean has_lid)
 {
-    GtkWidget *inact;
+    GtkWidget *inact_timeout, *inact_action;
     GtkWidget *lid;
     GtkWidget *label;
     GtkWidget *frame;
     GtkWidget *brg;
     GtkWidget *brg_level;
+    gchar *str;
+    gchar *list_str;
     GtkListStore *list_store;
     GtkTreeIter iter;
     guint val;
     gboolean valid;
     guint list_value;
     
-    inact = GTK_WIDGET (gtk_builder_get_object (xml, "inactivity-on-ac"));
-    
+    /*
+     * Inactivity sleep mode on AC
+     */
+    list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+    inact_action = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-mode-on-ac"));
+    gtk_combo_box_set_model (GTK_COMBO_BOX(inact_action), GTK_TREE_MODEL(list_store));
+
+    if ( can_suspend )
+    {
+    gtk_list_store_append (list_store, &iter);
+    gtk_list_store_set (list_store, &iter, 0, _("Suspend"), -1);
+    }
+    else if ( !auth_suspend )
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not permitted"));
+    }
+    else
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not supported"));
+    }
+
+    if ( can_hibernate )
+    {
+    gtk_list_store_append (list_store, &iter);
+    gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), -1);
+    }
+    else if ( !auth_hibernate )
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not permitted"));
+    }
+    else
+    {
+    gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not supported"));
+    }
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (inact_action), 0);
+
+    str = xfconf_channel_get_string (channel, PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_AC, "Suspend");
+    for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+      valid;
+      valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+    {
+    gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+                0, &list_str, -1);
+    if ( g_strcmp0 (str, list_str) )
+    {
+        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (inact_action), &iter);
+        break;
+    }
+    }
+    g_free (str);
+
+    /*
+     * Inactivity timeout on AC
+     */
+    inact_timeout = GTK_WIDGET (gtk_builder_get_object (xml, "inactivity-on-ac"));
+
     if ( !can_suspend && !can_hibernate )
     {
-	gtk_widget_set_sensitive (inact, FALSE);
-	gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not supported"));
+    gtk_widget_set_sensitive (inact_timeout, FALSE);
+    gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not supported"));
     }
     else  if ( !auth_suspend && !auth_hibernate )
     {
-	gtk_widget_set_sensitive (inact, FALSE);
-	gtk_widget_set_tooltip_text (inact, _("Hibernate and suspend operations not permitted"));
+    gtk_widget_set_sensitive (inact_timeout, FALSE);
+    gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not permitted"));
     }
-    
+
     val = xfconf_channel_get_uint (channel, PROPERTIES_PREFIX ON_AC_INACTIVITY_TIMEOUT, 14);
-    gtk_range_set_value (GTK_RANGE (inact), val);
-   
+    gtk_range_set_value (GTK_RANGE (inact_timeout), val);
+
 #ifdef HAVE_DPMS
     /*
      * DPMS settings when running on AC power 
@@ -1200,70 +1341,12 @@ xfpm_settings_advanced (XfconfChannel *channel, gboolean auth_suspend,
                         gboolean can_hibernate, gboolean has_battery)
 {
     guint val;
-    gchar *str;
     GtkWidget *critical_level;
     GtkWidget *lock;
     GtkWidget *label;
     GtkWidget *sleep_mode;
     GtkWidget *brg_handle_keys;
 
-    gchar *list_str;
-    gboolean valid;
-    GtkListStore *list_store;
-    GtkTreeIter iter;
-
-    /*
-     * Computer sleep mode
-     */
-    list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
-    sleep_mode = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-mode"));
-    gtk_combo_box_set_model (GTK_COMBO_BOX(sleep_mode), GTK_TREE_MODEL(list_store));
-    
-    if ( can_suspend )
-    {
-	gtk_list_store_append (list_store, &iter);
-	gtk_list_store_set (list_store, &iter, 0, _("Suspend"), -1);
-    }
-    else if ( !auth_suspend )
-    {
-	gtk_widget_set_tooltip_text (sleep_mode, _("Suspend operation not permitted"));
-    }
-    else
-    {
-	gtk_widget_set_tooltip_text (sleep_mode, _("Suspend operation not supported"));
-    }
-    
-    if ( can_hibernate )
-    {
-	gtk_list_store_append (list_store, &iter);
-	gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), -1);
-    }
-    else if ( !auth_hibernate )
-    {
-	gtk_widget_set_tooltip_text (sleep_mode, _("Hibernate operation not permitted"));
-    }
-    else
-    {
-	gtk_widget_set_tooltip_text (sleep_mode, _("Hibernate operation not supported"));
-    }
-
-    gtk_combo_box_set_active (GTK_COMBO_BOX (sleep_mode), 0);
-
-    str = xfconf_channel_get_string (channel, PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE, "Suspend");
-    for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
-	  valid;
-	  valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
-    {
-	gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
-			    0, &list_str, -1);
-	if ( g_strcmp0 (str, list_str) )
-	{
-	    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (sleep_mode), &iter);
-	    break;
-	}
-    }
-    g_free (str);
-
     /*
      * Critical battery level
      */
diff --git a/src/xfpm-config.h b/src/xfpm-config.h
index 1281822..581fb1e 100644
--- a/src/xfpm-config.h
+++ b/src/xfpm-config.h
@@ -54,7 +54,8 @@ G_BEGIN_DECLS
 
 #define     	ON_AC_INACTIVITY_TIMEOUT     	"inactivity-on-ac"
 #define     	ON_BATTERY_INACTIVITY_TIMEOUT 	"inactivity-on-battery"
-#define     	INACTIVITY_SLEEP_MODE        	"inactivity-sleep-mode"
+#define     	INACTIVITY_SLEEP_MODE_ON_AC   	"inactivity-sleep-mode-on-ac"
+#define     	INACTIVITY_SLEEP_MODE_ON_BATTERY   	"inactivity-sleep-mode-on-battery"
 
 #define     	BRIGHTNESS_ON_AC             	"brightness-on-ac"
 #define     	BRIGHTNESS_ON_BATTERY        	"brightness-on-battery"
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index f24777f..a1d47af 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -420,9 +420,14 @@ xfpm_manager_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmManager *manager
 	    return;
 	}
 
-	g_object_get (G_OBJECT (manager->priv->conf),
-		      INACTIVITY_SLEEP_MODE, &sleep_mode,
-		      NULL);
+    if ( id == TIMEOUT_INACTIVITY_ON_AC)
+        g_object_get (G_OBJECT (manager->priv->conf),
+                      INACTIVITY_SLEEP_MODE_ON_AC, &sleep_mode,
+                      NULL);
+    else
+        g_object_get (G_OBJECT (manager->priv->conf),
+                      INACTIVITY_SLEEP_MODE_ON_BATTERY, &sleep_mode,
+                      NULL);
 
 	g_object_get (G_OBJECT (manager->priv->power),
 		      "on-battery", &on_battery,
diff --git a/src/xfpm-xfconf.c b/src/xfpm-xfconf.c
index 08d6d9f..4321ce8 100644
--- a/src/xfpm-xfconf.c
+++ b/src/xfpm-xfconf.c
@@ -80,7 +80,8 @@ enum
 #endif
     PROP_IDLE_ON_AC,
     PROP_IDLE_ON_BATTERY,
-    PROP_IDLE_SLEEP_MODE,
+    PROP_IDLE_SLEEP_MODE_ON_AC,
+    PROP_IDLE_SLEEP_MODE_ON_BATTERY,
     PROP_DIM_ON_AC_TIMEOUT,
     PROP_DIM_ON_BATTERY_TIMEOUT,
 #ifdef WITH_NETWORK_MANAGER
@@ -492,15 +493,26 @@ xfpm_xfconf_class_init (XfpmXfconfClass *klass)
 							14,
                                                         G_PARAM_READWRITE));
 
-     /**
-     * XfpmXfconf::inactivity-sleep-mode
+    /**
+     * XfpmXfconf::inactivity-sleep-mode-on-battery
      **/
     g_object_class_install_property (object_class,
-                                     PROP_IDLE_SLEEP_MODE,
-                                     g_param_spec_string (INACTIVITY_SLEEP_MODE,
+                                     PROP_IDLE_SLEEP_MODE_ON_BATTERY,
+                                     g_param_spec_string (INACTIVITY_SLEEP_MODE_ON_BATTERY,
                                                           NULL, NULL,
-							  "Suspend",
+                                                          "Hibernate",
                                                           G_PARAM_READWRITE));
+
+    /**
+     * XfpmXfconf::inactivity-sleep-mode-on-ac
+     **/
+    g_object_class_install_property (object_class,
+                                     PROP_IDLE_SLEEP_MODE_ON_AC,
+                                     g_param_spec_string (INACTIVITY_SLEEP_MODE_ON_AC,
+                                                          NULL, NULL,
+                                                          "Suspend",
+                                                          G_PARAM_READWRITE));
+
     /**
      * XfpmXfconf::brightness-on-ac
      **/

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list