[gnome-control-center/wip/privacy] privacy: Implement recent files



commit 4ce4217445070361060fce8656e1a9325ecb50ca
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 25 16:51:34 2012 -0500

    privacy: Implement recent files
    
    This relies on patches that turn the recent-files-max-age gtk
    setting into an X setting which is backed by a gsetting.

 panels/privacy/cc-privacy-panel.c |  121 ++++++++++++++++++++++-
 panels/privacy/privacy.ui         |  192 +++++++++++++++++++++++++++++++++++++
 2 files changed, 308 insertions(+), 5 deletions(-)
---
diff --git a/panels/privacy/cc-privacy-panel.c b/panels/privacy/cc-privacy-panel.c
index e82aa5c..63194c3 100644
--- a/panels/privacy/cc-privacy-panel.c
+++ b/panels/privacy/cc-privacy-panel.c
@@ -250,6 +250,7 @@ add_screen_lock (CcPrivacyPanel *self)
 {
   GtkWidget *w;
   GtkWidget *dialog;
+  GtkWidget *label;
 
   w = get_on_off_label (self->priv->lock_settings, "lock-enabled");
   add_row (self, _("Screen Lock"), "screen_lock_dialog", w);
@@ -264,16 +265,15 @@ add_screen_lock (CcPrivacyPanel *self)
                    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);
 
+  label = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "lock_after_label"));
+
+  g_object_bind_property (w, "sensitive", label, "sensitive", G_BINDING_DEFAULT);
+
   set_lock_value_for_combo (GTK_COMBO_BOX (w), self);
   g_signal_connect (w, "changed",
                     G_CALLBACK (lock_combo_changed_cb), self);
@@ -345,6 +345,116 @@ add_name_visibility (CcPrivacyPanel *self)
 }
 
 static void
+retain_history_combo_changed_cb (GtkWidget      *widget,
+                                 CcPrivacyPanel *self)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  gint value;
+  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, &value,
+                      -1);
+  g_settings_set (self->priv->privacy_settings, "retain-recent-files-for", "i", value);
+}
+
+static void
+set_retain_history_value_for_combo (GtkComboBox    *combo_box,
+                                    CcPrivacyPanel *self)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  gint 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 setting */
+  g_settings_get (self->priv->privacy_settings, "retain-recent-files-for", "i", &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
+clear_recent (CcPrivacyPanel *self)
+{
+  GtkRecentManager *m;
+
+  m = gtk_recent_manager_get_default ();
+  gtk_recent_manager_purge_items (m, NULL);
+}
+
+static void
+add_usage_history (CcPrivacyPanel *self)
+{
+  GtkWidget *w;
+  GtkWidget *dialog;
+  GtkWidget *label;
+
+  w = get_on_off_label (self->priv->privacy_settings, "keep-recent-files");
+  add_row (self, _("Usage & History"), "recent_dialog", w);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "recent_done"));
+  dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "recent_dialog"));
+  g_signal_connect_swapped (w, "clicked",
+                            G_CALLBACK (gtk_widget_hide), dialog);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "recently_used_switch"));
+  g_settings_bind (self->priv->privacy_settings, "keep-recent-files",
+                   w, "active",
+                   G_SETTINGS_BIND_DEFAULT);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "retain_history_combo"));
+  set_retain_history_value_for_combo (GTK_COMBO_BOX (w), self);
+  g_signal_connect (w, "changed",
+                    G_CALLBACK (retain_history_combo_changed_cb), self);
+
+  g_settings_bind (self->priv->privacy_settings, "keep-recent-files",
+                   w, "sensitive",
+                   G_SETTINGS_BIND_GET);
+
+  label = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "retain_history_label"));
+
+  g_object_bind_property (w, "sensitive", label, "sensitive", G_BINDING_DEFAULT);
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "clear_recent_button"));
+  g_signal_connect_swapped (w, "clicked",
+                            G_CALLBACK (clear_recent), self);
+
+}
+
+static void
 purge_after_combo_changed_cb (GtkWidget      *widget,
                               CcPrivacyPanel *self)
 {
@@ -568,6 +678,7 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
 
   add_screen_lock (self);
   add_name_visibility (self);
+  add_usage_history (self);
   add_trash_temp (self);
 
   g_signal_connect (self->priv->lockdown_settings, "changed",
diff --git a/panels/privacy/privacy.ui b/panels/privacy/privacy.ui
index c12d68b..8f006cc 100644
--- a/panels/privacy/privacy.ui
+++ b/panels/privacy/privacy.ui
@@ -62,6 +62,8 @@
                 <property name="label" translatable="yes">_Done</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_underline">True</property>
               </object>
@@ -262,6 +264,192 @@
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="retain_history_model">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+      <!-- column-name value -->
+      <column type="gint"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Don't retain history</col>
+        <col id="1">0</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">1 day</col>
+        <col id="1">1</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">7 days</col>
+        <col id="1">7</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">30 days</col>
+        <col id="1">30</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Forever</col>
+        <col id="1">-1</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkDialog" id="recent_dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="type_hint">dialog</property>
+    <property name="title" translatable="yes">Usage &amp; History</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox5">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkLabel" id="label6">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="margin_right">6</property>
+            <property name="margin_top">12</property>
+            <property name="margin_bottom">12</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Remembering your history makes things easier to find again. These items are never shared over the network.</property>
+            <property name="wrap">True</property>
+            <property name="max_width_chars">50</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area5">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="clear_recent_button">
+                <property name="label" translatable="yes">_Clear Recent History</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">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="recent_done">
+                <property name="label" translatable="yes">_Done</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">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="GtkGrid" id="grid3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="margin_right">6</property>
+            <property name="margin_top">12</property>
+            <property name="margin_bottom">12</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="recently_used_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">_Recently Used</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">recently_used_switch</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="recently_used_switch">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="halign">end</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="retain_history_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Retain _History</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">retain_history_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="retain_history_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="entry_text_column">0</property>
+                <property name="model">retain_history_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>
+          </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="0">clear_recent_button</action-widget>
+      <action-widget response="0">recent_done</action-widget>
+    </action-widgets>
+  </object>
   <object class="GtkDialog" id="screen_lock_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -281,6 +469,8 @@
                 <property name="label" translatable="yes">_Done</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_underline">True</property>
               </object>
@@ -485,6 +675,8 @@
                 <property name="label" translatable="yes">_Done</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_underline">True</property>
               </object>



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