[gnome-control-center] privacy: Implement trash & temp purging



commit 4d3208a6e1f584cd2776c4dcbdfc19e5945b0246
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 25 13:52:54 2012 -0500

    privacy: Implement trash & temp purging
    
    This relies on new settings and D-Bus API in the g-s-d
    housekeeping plugin.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687774

 panels/privacy/cc-privacy-panel.c |  176 ++++++++++++++++++++++++
 panels/privacy/privacy.ui         |  268 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 439 insertions(+), 5 deletions(-)
---
diff --git a/panels/privacy/cc-privacy-panel.c b/panels/privacy/cc-privacy-panel.c
index 9da81bb..d311047 100644
--- a/panels/privacy/cc-privacy-panel.c
+++ b/panels/privacy/cc-privacy-panel.c
@@ -29,6 +29,10 @@ CC_PANEL_REGISTER (CcPrivacyPanel, cc_privacy_panel)
 
 #define WID(s) GTK_WIDGET (gtk_builder_get_object (self->priv->builder, s))
 
+#define REMOVE_OLD_TRASH_FILES "remove-old-trash-files"
+#define REMOVE_OLD_TEMP_FILES "remove-old-temp-files"
+#define OLD_FILES_AGE "old-files-age"
+
 struct _CcPrivacyPanelPrivate
 {
   GtkBuilder *builder;
@@ -37,6 +41,7 @@ struct _CcPrivacyPanelPrivate
   GSettings  *lockdown_settings;
   GSettings  *lock_settings;
   GSettings  *shell_settings;
+  GSettings  *housekeeping_settings;
   GSettings  *privacy_settings;
 };
 
@@ -117,6 +122,47 @@ get_visible_label (GSettings *settings,
   return w;
 }
 
+typedef struct
+{
+  GtkWidget *label;
+  const gchar *key1;
+  const gchar *key2;
+} Label2Data;
+
+static void
+set_on_off_label2 (GSettings   *settings,
+                   const gchar *key,
+                   gpointer     user_data)
+{
+  Label2Data *data = user_data;
+  gboolean v1, v2;
+
+  v1 = g_settings_get_boolean (settings, data->key1);
+  v2 = g_settings_get_boolean (settings, data->key2);
+
+  gtk_label_set_label (GTK_LABEL (data->label), (v1 || v2) ? _("On") : _("Off"));
+}
+
+static GtkWidget *
+get_on_off_label2 (GSettings *settings,
+                   const gchar *key1,
+                   const gchar *key2)
+{
+  Label2Data *data;
+
+  data = g_new (Label2Data, 1);
+  data->label = gtk_label_new ("");
+  data->key1 = g_strdup (key1);
+  data->key2 = g_strdup (key2);
+
+  g_signal_connect (settings, "changed",
+                    G_CALLBACK (set_on_off_label2), data);
+
+  set_on_off_label2 (settings, key1, data);
+
+  return data->label;
+}
+
 static void
 add_row (CcPrivacyPanel *self,
          const gchar    *label,
@@ -300,7 +346,134 @@ add_name_visibility (CcPrivacyPanel *self)
 
   g_signal_connect (self->priv->privacy_settings, "changed::hide-identity",
                     G_CALLBACK (stealth_mode_changed), self);
+}
+
+static void
+purge_after_combo_changed_cb (GtkWidget      *widget,
+                              CcPrivacyPanel *self)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  guint 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, OLD_FILES_AGE, "u", value);
+}
+
+static void
+set_purge_after_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 purge setting */
+  g_settings_get (self->priv->privacy_settings, OLD_FILES_AGE, "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
+empty_trash (CcPrivacyPanel *self)
+{
+  GDBusConnection *bus;
+  bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+  g_dbus_connection_call (bus,
+                          "org.gnome.SettingsDaemon",
+                          "/org/gnome/SettingsDaemon/Housekeeping",
+                          "org.gnome.SettingsDaemon.Housekeeping",
+                          "EmptyTrash",
+                          NULL, NULL, 0, -1, NULL, NULL, NULL);
+  g_object_unref (bus);
+}
+
+static void
+purge_temp (CcPrivacyPanel *self)
+{
+  GDBusConnection *bus;
+  bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+  g_dbus_connection_call (bus,
+                          "org.gnome.SettingsDaemon",
+                          "/org/gnome/SettingsDaemon/Housekeeping",
+                          "org.gnome.SettingsDaemon.Housekeeping",
+                          "RemoveTempFiles",
+                          NULL, NULL, 0, -1, NULL, NULL, NULL);
+  g_object_unref (bus);
+}
+
+static void
+add_trash_temp (CcPrivacyPanel *self)
+{
+  GtkWidget *w;
+  GtkWidget *dialog;
+
+  w = get_on_off_label2 (self->priv->privacy_settings, REMOVE_OLD_TRASH_FILES, REMOVE_OLD_TEMP_FILES);
+  add_row (self, _("Purge Trash & Temporary Files"), "trash_dialog", w);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "trash_done"));
+  dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "trash_dialog"));
+  g_signal_connect_swapped (w, "clicked",
+                            G_CALLBACK (gtk_widget_hide), dialog);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "purge_trash_switch"));
+  g_settings_bind (self->priv->privacy_settings, REMOVE_OLD_TRASH_FILES,
+                   w, "active",
+                   G_SETTINGS_BIND_DEFAULT);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "purge_temp_switch"));
+  g_settings_bind (self->priv->privacy_settings, REMOVE_OLD_TEMP_FILES,
+                   w, "active",
+                   G_SETTINGS_BIND_DEFAULT);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "purge_after_combo"));
+
+  set_purge_after_value_for_combo (GTK_COMBO_BOX (w), self);
+  g_signal_connect (w, "changed",
+                    G_CALLBACK (purge_after_combo_changed_cb), self);
+
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "empty_trash_button"));
+  g_signal_connect_swapped (w, "clicked", G_CALLBACK (empty_trash), self);
 
+  w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "purge_temp_button"));
+  g_signal_connect_swapped (w, "clicked", G_CALLBACK (purge_temp), self);
 }
 
 static void
@@ -312,6 +485,7 @@ cc_privacy_panel_finalize (GObject *object)
   g_clear_object (&priv->lockdown_settings);
   g_clear_object (&priv->lock_settings);
   g_clear_object (&priv->shell_settings);
+  g_clear_object (&priv->housekeeping_settings);
   g_clear_object (&priv->privacy_settings);
 
   G_OBJECT_CLASS (cc_privacy_panel_parent_class)->finalize (object);
@@ -394,10 +568,12 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
   self->priv->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown");
   self->priv->lock_settings = g_settings_new ("org.gnome.desktop.screensaver");
   self->priv->shell_settings = g_settings_new ("org.gnome.shell");
+  self->priv->housekeeping_settings = g_settings_new ("org.gnome.settings-daemon.plugins.housekeeping");
   self->priv->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
 
   add_screen_lock (self);
   add_name_visibility (self);
+  add_trash_temp (self);
 
   g_signal_connect (self->priv->lockdown_settings, "changed",
                     G_CALLBACK (on_lockdown_settings_changed), self);
diff --git a/panels/privacy/privacy.ui b/panels/privacy/privacy.ui
index 2fce149..c12d68b 100644
--- a/panels/privacy/privacy.ui
+++ b/panels/privacy/privacy.ui
@@ -99,12 +99,13 @@
           <object class="GtkGrid" id="grid1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="row_spacing">12</property>
-            <property name="column_spacing">6</property>
             <property name="margin_left">12</property>
             <property name="margin_right">12</property>
             <property name="margin_top">12</property>
             <property name="margin_bottom">12</property>
+            <property name="border_width">6</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">6</property>
             <child>
               <object class="GtkLabel" id="full_name_top_bar_label">
                 <property name="visible">True</property>
@@ -211,6 +212,56 @@
       <action-widget response="0">name_done</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkListStore" id="purge_after_model">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+      <!-- column-name value -->
+      <column type="guint"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Immediately</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">2 days</col>
+        <col id="1">2</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">3 days</col>
+        <col id="1">3</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">4 days</col>
+        <col id="1">4</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">5 days</col>
+        <col id="1">5</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">6 days</col>
+        <col id="1">6</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">7 days</col>
+        <col id="1">7</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">14 days</col>
+        <col id="1">14</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">30 days</col>
+        <col id="1">30</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkDialog" id="screen_lock_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -267,12 +318,13 @@
           <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>
             <property name="margin_left">12</property>
             <property name="margin_right">12</property>
+            <property name="margin_top">12</property>
             <property name="margin_bottom">12</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>
@@ -380,6 +432,212 @@
       <action-widget response="-1">screen_lock_done</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkDialog" id="trash_dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Purge Trash &amp; Temporary Files</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox4">
+        <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_area4">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="empty_trash_button">
+                <property name="label" translatable="yes">_Empty Trash</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="hexpand">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="purge_temp_button">
+                <property name="label" translatable="yes">_Purge Temporary Files</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="hexpand">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>
+            <child>
+              <object class="GtkButton" id="trash_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">2</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="label5">
+            <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">Automatically purge the Trash and temporary files to help keep your computer free of unnecessary sensitive information.</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">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid2">
+            <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="hexpand">True</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="purge_trash_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Automatically Empty _Trash</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">purge_trash_switch</property>
+                <property name="track_visited_links">False</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="purge_trash_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="purge_temp_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Automatically Purge Temporary _Files</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">purge_temp_switch</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="GtkSwitch" id="purge_temp_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">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="purge_after_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Purge _After</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">purge_after_combo</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="GtkComboBoxText" id="purge_after_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="model">purge_after_model</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="0">empty_trash_button</action-widget>
+      <action-widget response="0">purge_temp_button</action-widget>
+      <action-widget response="0">trash_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]