[gnome-control-center] privacy: Add screen lock



commit 80914dad247dedf66f52174a3cabe6e5a9f532b0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Nov 17 10:38:08 2012 -0500

    privacy: Add screen lock
    
    These controls duplicate what we currently have in the screen
    panel - it will have to be removed there.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687774

 panels/privacy/cc-privacy-panel.c |  185 +++++++++++++++++++++++++++++++++
 panels/privacy/privacy.ui         |  202 +++++++++++++++++++++++++++++++++++++
 2 files changed, 387 insertions(+), 0 deletions(-)
---
diff --git a/panels/privacy/cc-privacy-panel.c b/panels/privacy/cc-privacy-panel.c
index 4ba2230..004fa65 100644
--- a/panels/privacy/cc-privacy-panel.c
+++ b/panels/privacy/cc-privacy-panel.c
@@ -34,15 +34,193 @@ struct _CcPrivacyPanelPrivate
   GtkBuilder *builder;
   GtkWidget  *list_box;
 
+  GSettings  *lockdown_settings;
   GSettings  *lock_settings;
 };
 
 static void
+update_lock_screen_sensitivity (CcPrivacyPanel *self)
+{
+  GtkWidget *widget;
+  gboolean   locked;
+
+  locked = g_settings_get_boolean (self->priv->lockdown_settings, "disable-lock-screen");
+
+  widget = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "screen_lock_dialog_grid"));
+  gtk_widget_set_sensitive (widget, !locked);
+}
+
+static void
+on_lockdown_settings_changed (GSettings      *settings,
+                              const char     *key,
+                              CcPrivacyPanel *panel)
+{
+  if (g_str_equal (key, "disable-lock-screen") == FALSE)
+    return;
+
+  update_lock_screen_sensitivity (panel);
+}
+
+static gboolean
+on_off_label_mapping_get (GValue   *value,
+                          GVariant *variant,
+                          gpointer  user_data)
+{
+  g_value_set_string (value, g_variant_get_boolean (variant) ? _("On") : _("Off"));
+
+  return TRUE;
+}
+
+static GtkWidget *
+get_on_off_label (GSettings *settings,
+                  const gchar *key)
+{
+  GtkWidget *w;
+
+  w = gtk_label_new ("");
+  g_settings_bind_with_mapping (settings, key,
+                                w, "label",
+                                G_SETTINGS_BIND_GET,
+                                on_off_label_mapping_get,
+                                NULL,
+                                NULL,
+                                NULL);
+  return w;
+}
+
+static void
+add_row (CcPrivacyPanel *self,
+         const gchar    *label,
+         const gchar    *dialog_id,
+         GtkWidget      *status)
+{
+  GtkWidget *box, *w;
+
+  gtk_widget_set_valign (self->priv->list_box, GTK_ALIGN_FILL);
+
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+  g_object_set_data (G_OBJECT (box), "dialog-id", (gpointer)dialog_id);
+  gtk_widget_set_hexpand (box, TRUE);
+  gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+  gtk_container_add (GTK_CONTAINER (self->priv->list_box), box);
+
+  w = gtk_label_new (label);
+  gtk_container_add (GTK_CONTAINER (box), w);
+  gtk_box_pack_end (GTK_BOX (box), status, FALSE, FALSE, 0);
+
+  gtk_widget_show_all (box);
+}
+
+static void
+lock_combo_changed_cb (GtkWidget      *widget,
+                       CcPrivacyPanel *self)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  guint delay;
+  gboolean ret;
+
+  /* no selection */
+  ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX(widget), &iter);
+  if (!ret)
+    return;
+
+  /* get entry */
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX(widget));
+  gtk_tree_model_get (model, &iter,
+                      1, &delay,
+                      -1);
+  g_settings_set (self->priv->lock_settings, "lock-delay", "u", delay);
+}
+
+static void
+set_lock_value_for_combo (GtkComboBox    *combo_box,
+                          CcPrivacyPanel *self)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  guint value;
+  gint value_tmp, value_prev;
+  gboolean ret;
+  guint i;
+
+  /* get entry */
+  model = gtk_combo_box_get_model (combo_box);
+  ret = gtk_tree_model_get_iter_first (model, &iter);
+  if (!ret)
+    return;
+
+  value_prev = 0;
+  i = 0;
+
+  /* try to make the UI match the lock setting */
+  g_settings_get (self->priv->lock_settings, "lock-delay", "u", &value);
+  do
+    {
+      gtk_tree_model_get (model, &iter,
+                          1, &value_tmp,
+                          -1);
+      if (value == value_tmp ||
+          (value_tmp > value_prev && value < value_tmp))
+        {
+          gtk_combo_box_set_active_iter (combo_box, &iter);
+          return;
+        }
+      value_prev = value_tmp;
+      i++;
+    } while (gtk_tree_model_iter_next (model, &iter));
+
+  /* If we didn't find the setting in the list */
+  gtk_combo_box_set_active (combo_box, i - 1);
+}
+
+static void
+add_screen_lock (CcPrivacyPanel *self)
+{
+  GtkWidget *w;
+  GtkWidget *dialog;
+
+  self->priv->lock_settings = g_settings_new ("org.gnome.desktop.screensaver");
+  w = get_on_off_label (self->priv->lock_settings, "lock-enabled");
+  add_row (self, _("Screen Lock"), "screen_lock_dialog", w);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "screen_lock_done"));
+  dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "screen_lock_dialog"));
+  g_signal_connect_swapped (w, "clicked",
+                            G_CALLBACK (gtk_widget_hide), dialog);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "automatic_screen_lock"));
+  g_settings_bind (self->priv->lock_settings, "lock-enabled",
+                   w, "active",
+                   G_SETTINGS_BIND_DEFAULT);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "lock_after_label"));
+  g_settings_bind (self->priv->lock_settings, "lock-enabled",
+                   w, "sensitive",
+                   G_SETTINGS_BIND_GET);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "lock_after_combo"));
+  g_settings_bind (self->priv->lock_settings, "lock-enabled",
+                   w, "sensitive",
+                   G_SETTINGS_BIND_GET);
+
+  set_lock_value_for_combo (GTK_COMBO_BOX (w), self);
+  g_signal_connect (w, "changed",
+                    G_CALLBACK (lock_combo_changed_cb), self);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "show_notifications"));
+  g_settings_bind (self->priv->lock_settings, "show-notifications",
+                   w, "active",
+                   G_SETTINGS_BIND_DEFAULT);
+}
+
+static void
 cc_privacy_panel_finalize (GObject *object)
 {
   CcPrivacyPanelPrivate *priv = CC_PRIVACY_PANEL (object)->priv;
 
   g_clear_object (&priv->builder);
+  g_clear_object (&priv->lockdown_settings);
   g_clear_object (&priv->lock_settings);
 
   G_OBJECT_CLASS (cc_privacy_panel_parent_class)->finalize (object);
@@ -122,6 +300,13 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
                                     update_separator_func,
                                     NULL, NULL);
 
+  add_screen_lock (self);
+
+  self->priv->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown");
+  g_signal_connect (self->priv->lockdown_settings, "changed",
+                    G_CALLBACK (on_lockdown_settings_changed), self);
+  update_lock_screen_sensitivity (self);
+
   widget = WID ("privacy_vbox");
   gtk_widget_reparent (widget, (GtkWidget *) self);
 }
diff --git a/panels/privacy/privacy.ui b/panels/privacy/privacy.ui
index 620fee4..85e9a23 100644
--- a/panels/privacy/privacy.ui
+++ b/panels/privacy/privacy.ui
@@ -1,6 +1,208 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkListStore" id="lock_after_model">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+      <!-- column-name value -->
+      <column type="gint"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Screen Turns Off</col>
+        <col id="1">0</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">30 seconds</col>
+        <col id="1">30</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">1 minute</col>
+        <col id="1">60</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">2 minutes</col>
+        <col id="1">120</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">3 minutes</col>
+        <col id="1">180</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">5 minutes</col>
+        <col id="1">300</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">30 minutes</col>
+        <col id="1">1800</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">1 hour</col>
+        <col id="1">3600</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkDialog" id="screen_lock_dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="type_hint">dialog</property>
+    <property name="title" translatable="yes">Screen Lock</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="screen_lock_done">
+                <property name="label" translatable="yes">_Done</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_bottom">12</property>
+            <property name="label" translatable="yes">The Screen Lock protects your privacy when you are away.</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="screen_lock_dialog_grid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">6</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Automatic Screen _Lock</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">automatic_screen_lock</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSwitch" id="automatic_screen_lock">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="lock_after_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Lock Screen _After</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">lock_after_combo</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="lock_after_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+                <property name="model">lock_after_model</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Show _Notifications</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">show_notifications</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSwitch" id="show_notifications">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-1">screen_lock_done</action-widget>
+    </action-widgets>
+  </object>
   <object class="GtkWindow" id="window1">
     <property name="can_focus">False</property>
     <child>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]