[Xfce4-commits] [xfce/xfce4-power-manager] 01/01: Light Locker Integration (Bug #11488)

noreply at xfce.org noreply at xfce.org
Sat Feb 7 10:00:15 CET 2015


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

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

commit 10076da7caa49320b3e907d319a9f27ee6702969
Author: Sean Davis <bluesabre at ubuntu.com>
Date:   Sat Feb 7 11:49:31 2015 +0300

    Light Locker Integration (Bug #11488)
    
    Integrate Light Locker configuration into Xfce Power Manager. This
    allows proper settings synchronization between the two applications
    and eliminates some of the hackiness used in Light Locker Settings
    to accomplish the same effect, and streamlines similar tools into
    a single location. This depends on light-locker 1.5.1 configured
    with the GSettings backend.
    
    Signed-off-by: Eric Koegel <eric.koegel at gmail.com>
---
 data/interfaces/xfpm-settings.ui |  212 ++++++++++++++++++++++++++++++++++-
 settings/xfpm-settings.c         |  225 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 436 insertions(+), 1 deletion(-)

diff --git a/data/interfaces/xfpm-settings.ui b/data/interfaces/xfpm-settings.ui
index bdc0aec..e5b6dfb 100644
--- a/data/interfaces/xfpm-settings.ui
+++ b/data/interfaces/xfpm-settings.ui
@@ -65,6 +65,34 @@
     <property name="value">3</property>
     <property name="step_increment">1</property>
   </object>
+  <object class="GtkAdjustment" id="light-locker-late-locking-adjustment">
+    <property name="lower">1</property>
+    <property name="upper">120</property>
+    <property name="value">1</property>
+    <property name="step_increment">1</property>
+  </object>
+  <object class="GtkListStore" id="liststore1">
+    <columns>
+      <!-- column-name value -->
+      <column type="gint"/>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">0</col>
+        <col id="1" translatable="yes">Never</col>
+      </row>
+      <row>
+        <col id="0">1</col>
+        <col id="1" translatable="yes">When the screensaver is activated</col>
+      </row>
+      <row>
+        <col id="0">2</col>
+        <col id="1" translatable="yes">When the screensaver is deactivated</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkListStore" id="model1">
     <columns>
       <!-- column-name gchararray -->
@@ -87,6 +115,17 @@
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="model11">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Nothing</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkListStore" id="model3">
     <columns>
       <!-- column-name gchararray -->
@@ -374,7 +413,6 @@
                                         <signal name="toggled" handler="brightness_handle_keys_toggled_cb" swapped="no"/>
                                       </object>
                                       <packing>
-                                        <property name="left_attach">0</property>
                                         <property name="right_attach">2</property>
                                         <property name="top_attach">3</property>
                                         <property name="bottom_attach">4</property>
@@ -522,6 +560,15 @@
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </object>
                             </child>
                           </object>
@@ -778,6 +825,15 @@
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </object>
                             </child>
                           </object>
@@ -977,6 +1033,9 @@
                       </packing>
                     </child>
                   </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
                 </child>
                 <child type="tab">
                   <object class="GtkLabel" id="system">
@@ -985,6 +1044,7 @@
                     <property name="label" translatable="yes">System</property>
                   </object>
                   <packing>
+                    <property name="position">1</property>
                     <property name="tab_fill">False</property>
                   </packing>
                 </child>
@@ -1574,6 +1634,156 @@
                     <property name="tab_fill">False</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkVBox" id="light-locker-vbox1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="border_width">12</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkFrame" id="light-locker-frame">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label_xalign">0</property>
+                        <property name="shadow_type">none</property>
+                        <child>
+                          <object class="GtkAlignment" id="light-locker-alignment">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="border_width">6</property>
+                            <property name="bottom_padding">18</property>
+                            <property name="left_padding">12</property>
+                            <child>
+                              <object class="GtkVBox" id="light-locker-vbox2">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">5</property>
+                                <child>
+                                  <object class="GtkTable" id="light-locker-table">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="n_rows">3</property>
+                                    <property name="n_columns">2</property>
+                                    <property name="column_spacing">6</property>
+                                    <property name="row_spacing">6</property>
+                                    <child>
+                                      <object class="GtkLabel" id="light-locker-automatic-locking-label">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Automatically lock the session:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="x_options">GTK_FILL</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkComboBox" id="light-locker-automatic-locking-combo">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="model">liststore1</property>
+                                        <property name="active">0</property>
+                                        <signal name="changed" handler="light_locker_automatic_locking_changed_cb" swapped="no"/>
+                                        <child>
+                                          <object class="GtkCellRendererText" id="renderer11"/>
+                                          <attributes>
+                                            <attribute name="text">1</attribute>
+                                          </attributes>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="light-locker-late-locking-label">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Delay locking after screensaver for</property>
+                                      </object>
+                                      <packing>
+                                        <property name="top_attach">1</property>
+                                        <property name="x_options">GTK_FILL</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkHScale" id="light-locker-late-locking-scale">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="update_policy">discontinuous</property>
+                                        <property name="adjustment">light-locker-late-locking-adjustment</property>
+                                        <property name="round_digits">0</property>
+                                        <property name="digits">0</property>
+                                        <property name="value_pos">bottom</property>
+                                        <signal name="format-value" handler="format_light_locker_value_cb" swapped="no"/>
+                                        <signal name="value-changed" handler="light_locker_late_locking_value_changed_cb" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">1</property>
+                                        <property name="bottom_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkCheckButton" id="light-locker-suspend">
+                                        <property name="label" translatable="yes">Lock screen when system is going for sleep</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="lock_screen_toggled_cb" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">2</property>
+                                        <property name="bottom_attach">3</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <child type="label">
+                          <object class="GtkLabel" id="light-locker-frame-label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes"><b>Light Locker</b></property>
+                            <property name="use_markup">True</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child type="tab">
+                  <object class="GtkLabel" id="light-locker-tab-label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Security</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">True</property>
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index a0e116d..90c7012 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -63,6 +63,14 @@ static  GtkWidget *on_ac_dpms_off 		= NULL;
 static  GtkWidget *sideview                 = NULL; /* Sidebar tree view - all devices are in the sideview */
 static  GtkWidget *device_details_notebook  = NULL; /* Displays the details of a deivce */
 
+/* Light Locker Integration */
+static  GtkWidget *light_locker_tab             = NULL;
+static  GtkWidget *light_locker_autolock        = NULL;
+static  GtkWidget *light_locker_delay           = NULL;
+static  GtkWidget *light_locker_sleep           = NULL;
+static  GSettings *light_locker_settings        = NULL;
+/* END Light Locker Integration */
+
 static  gboolean  lcd_brightness = FALSE;
 static  gchar *starting_device_id = NULL;
 static  UpClient *upower = NULL;
@@ -190,6 +198,19 @@ void        on_ac_sleep_mode_changed_cb 	   (GtkWidget *w,
 void        on_battery_sleep_mode_changed_cb	   (GtkWidget *w,
 						    XfconfChannel *channel);
 
+/* Light Locker Integration */
+gchar      *format_light_locker_value_cb           (GtkScale *scale,
+                                                    gdouble value,
+                                                    gpointer data);
+
+void        light_locker_late_locking_value_changed_cb (GtkWidget *w,
+                                                        XfconfChannel *channel);
+
+void        light_locker_automatic_locking_changed_cb (GtkWidget *w,
+                                                       XfconfChannel *channel);
+
+void        xfpm_update_logind_handle_lid_switch   (XfconfChannel *channel);
+/* END Light Locker Integration */
 
 void brightness_level_on_ac (GtkWidget *w,  XfconfChannel *channel)
 {
@@ -744,6 +765,7 @@ on_battery_lid_changed_cb (GtkWidget *w, XfconfChannel *channel)
     {
 	g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_BATTERY_CFG);
     }
+    xfpm_update_logind_handle_lid_switch (channel);
 }
 
 void
@@ -768,6 +790,7 @@ on_ac_lid_changed_cb (GtkWidget *w, XfconfChannel *channel)
     {
 	g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_AC_CFG);
     }
+    xfpm_update_logind_handle_lid_switch (channel);
 } 
 
 void
@@ -796,8 +819,34 @@ lock_screen_toggled_cb (GtkWidget *w, XfconfChannel *channel)
     {
 	g_critical ("Unable to set value for property %s\n", LOCK_SCREEN_ON_SLEEP);
     }
+
+    /* Light Locker Integration */
+    if ( light_locker_settings )
+    {
+        GtkWidget *widget;
+        GVariant *variant;
+        variant = g_variant_new_boolean (val);
+        if (!g_settings_set_value (light_locker_settings, "lock-on-suspend", variant))
+            g_critical ("Cannot set value for property lock-on-suspend\n");
+
+	xfpm_update_logind_handle_lid_switch (channel);
+    }
+    /* END Light Locker Integration */
 }
 
+/* Light Locker Integration */
+void
+xfpm_update_logind_handle_lid_switch (XfconfChannel *channel)
+{
+    gboolean lock_on_suspend = xfconf_channel_get_bool (channel, PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
+    guint lid_switch_on_ac = xfconf_channel_get_uint (channel, PROPERTIES_PREFIX LID_SWITCH_ON_AC_CFG, LID_TRIGGER_LOCK_SCREEN);
+    guint lid_switch_on_battery = xfconf_channel_get_uint (channel, PROPERTIES_PREFIX LID_SWITCH_ON_BATTERY_CFG, LID_TRIGGER_LOCK_SCREEN);
+
+    // logind-handle-lid-switch = true when: lock_on_suspend == true and (lid_switch_on_ac == suspend or lid_switch_on_battery == suspend)
+    xfconf_channel_set_bool (channel, PROPERTIES_PREFIX LOGIND_HANDLE_LID_SWITCH, lock_on_suspend && (lid_switch_on_ac == 1 || lid_switch_on_battery == 1));
+}
+/* END Light Locker Integration */
+
 static void
 xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_suspend,
                           gboolean auth_hibernate, gboolean can_suspend,
@@ -1469,6 +1518,178 @@ xfpm_settings_advanced (XfconfChannel *channel, gboolean auth_suspend,
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(brg_handle_keys), val);
 }
 
+/* Light Locker Integration */
+static gchar*
+get_light_locker_path (void)
+{
+    gchar** paths = NULL;
+    gchar* path = NULL;
+    int i = 0;
+
+    /* Check if executable in path */
+    paths = g_strsplit(g_getenv("PATH"), ":", 0);
+    for (i = 0; i < g_strv_length(paths); i++) {
+        path = g_strdup(g_build_filename(paths[i], "light-locker", NULL));
+        if (g_file_test(path, G_FILE_TEST_EXISTS))
+        {
+            break;
+        }
+        g_free(path);
+        path = NULL;
+    }
+    g_strfreev(paths);
+
+    return path;
+}
+
+gchar *
+format_light_locker_value_cb (GtkScale *scale, gdouble value, gpointer data)
+{
+    gint h, min;
+
+    if ( (gint)value <= 0 )
+        return g_strdup (_("Never"));
+    else if ( (gint)value < 60 )
+        return g_strdup_printf ("%d %s", (gint)value, _("Seconds"));
+    else if ( (gint)value == 60)
+        return g_strdup (_("One Minute"));
+
+    /* value > 60 */
+    min = (gint)value - 60;
+
+    return g_strdup_printf ("%d %s", (gint)min, _("Minutes"));
+}
+
+void
+light_locker_late_locking_value_changed_cb (GtkWidget *widget, XfconfChannel *channel)
+{
+    GVariant *variant;
+    gint      value = (gint)gtk_range_get_value (GTK_RANGE (widget));
+
+    if (value > 60) {
+        value = (value - 60) * 60;
+    }
+
+    variant = g_variant_new_uint32 (value);
+
+    if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
+    {
+        g_critical ("Cannot set value for property lock-after-screensaver\n");
+    }
+}
+
+void
+light_locker_automatic_locking_changed_cb (GtkWidget *widget, XfconfChannel *channel)
+{
+    GVariant *variant;
+    gint      value;
+    gint      lock_after_screensaver;
+    gboolean  late_locking = FALSE;
+
+    value = gtk_combo_box_get_active (GTK_COMBO_BOX(widget));
+    gtk_widget_set_sensitive (light_locker_delay, value != 0);
+
+    if (value == 0)
+        lock_after_screensaver = 0;
+    else {
+        lock_after_screensaver = (gint)gtk_range_get_value (GTK_RANGE (light_locker_delay));
+        if (lock_after_screensaver > 60) {
+            lock_after_screensaver = (lock_after_screensaver - 60) * 60;
+        }
+    }
+
+    if (value == 2)
+        late_locking = TRUE;
+
+    variant = g_variant_new_uint32 (lock_after_screensaver);
+    if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
+        g_critical ("Cannot set value for property lock-after-screensaver\n");
+
+    variant = g_variant_new_boolean (late_locking);
+    if (!g_settings_set_value (light_locker_settings, "late-locking", variant))
+        g_critical ("Cannot set value for property late-locking\n");
+}
+
+static void xfpm_settings_light_locker (XfconfChannel *channel,
+                                        gboolean auth_suspend, gboolean auth_hibernate,
+                                        gboolean can_suspend, gboolean can_hibernate)
+{
+    GSettingsSchemaSource *schema_source;
+    GSettingsSchema       *schema;
+    GVariant              *variant;
+    gboolean               late_locking, lock_on_suspend, xfpm_lock_on_suspend;
+    guint32                lock_after_screensaver;
+    GtkWidget             *security_frame;
+
+    /* Collect the Light Locker widgets */
+    light_locker_tab = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-vbox1"));
+    light_locker_autolock = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-automatic-locking-combo"));
+    light_locker_delay = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-late-locking-scale"));
+    light_locker_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-suspend"));
+
+    if ( !can_suspend && !can_hibernate )
+    {
+        gtk_widget_set_sensitive (light_locker_sleep, FALSE);
+        gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not supported"));
+    }
+    else if ( !auth_hibernate && !auth_suspend)
+    {
+        gtk_widget_set_sensitive (light_locker_sleep, FALSE);
+        gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not permitted"));
+    }
+
+    schema_source = g_settings_schema_source_get_default();
+    schema = g_settings_schema_source_lookup (schema_source, "apps.light-locker", FALSE);
+
+    if (schema != NULL && get_light_locker_path() != NULL) {
+        security_frame = GTK_WIDGET (gtk_builder_get_object (xml, "security-frame"));
+        gtk_widget_hide(security_frame);
+        /* Load the settings (Light Locker compiled with GSettings backend required) */
+        light_locker_settings = g_settings_new ("apps.light-locker");
+
+        variant = g_settings_get_value (light_locker_settings, "late-locking");
+        late_locking = g_variant_get_boolean (variant);
+
+        variant = g_settings_get_value (light_locker_settings, "lock-on-suspend");
+        lock_on_suspend = g_variant_get_boolean (variant);
+        xfpm_lock_on_suspend = xfconf_channel_get_bool (channel, PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
+        if (lock_on_suspend != xfpm_lock_on_suspend) {
+            variant = g_variant_new_boolean (xfpm_lock_on_suspend);
+            g_settings_set_value (light_locker_settings, "lock-on-suspend", variant);
+            lock_on_suspend = xfpm_lock_on_suspend;
+        }
+
+        variant = g_settings_get_value (light_locker_settings, "lock-after-screensaver");
+        lock_after_screensaver = g_variant_get_uint32 (variant);
+
+        gtk_widget_set_sensitive (light_locker_delay, lock_after_screensaver != 0);
+
+        if (lock_after_screensaver > 60) {
+            lock_after_screensaver = (lock_after_screensaver / 60) + 60;
+        }
+
+        /* Apply the settings */
+        if (lock_after_screensaver == 0) {
+            gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 0);
+        } else {
+            if (!late_locking) {
+                gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 1);
+            } else {
+                gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 2);
+            }
+            gtk_range_set_value (GTK_RANGE(light_locker_delay), lock_after_screensaver);
+        }
+
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(light_locker_sleep), lock_on_suspend);
+
+        g_settings_schema_unref (schema);
+    } else {
+        g_warning("Schema \"apps.light-locker\" not found. Not configuring Light Locker.");
+        gtk_widget_hide (light_locker_tab);
+    }
+}
+/* END Light Locker Integration */
+
 /* Call gtk_tree_iter_free when done with the tree iter */
 static GtkTreeIter*
 find_device_in_tree (const gchar *object_path)
@@ -2181,6 +2402,10 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean auth_suspend,
 
     xfpm_settings_advanced (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate, has_battery);
 
+    /* Light Locker Integration */
+    xfpm_settings_light_locker (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate);
+    /* END Light Locker Integration */
+
     if ( !has_lcd_brightness )
     {
     frame = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-frame"));

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


More information about the Xfce4-commits mailing list