[gnome-control-center/wip/privacy-swarm: 13/14] Add a usage panel



commit 63346c6c69ee721d1daf7faeffb438c2c23346a9
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 11 14:25:32 2018 -0500

    Add a usage panel
    
    This is a broken out version of the privacy panel dialog.

 panels/usage/cc-usage-panel.c                | 160 ++++++++++++++++++++++
 panels/usage/cc-usage-panel.h                |  30 ++++
 panels/usage/cc-usage-panel.ui               | 198 +++++++++++++++++++++++++++
 panels/usage/gnome-usage-panel.desktop.in.in |  19 +++
 panels/usage/meson.build                     |  40 ++++++
 panels/usage/usage.gresource.xml             |   6 +
 6 files changed, 453 insertions(+)
---
diff --git a/panels/usage/cc-usage-panel.c b/panels/usage/cc-usage-panel.c
new file mode 100644
index 000000000..099aac1ef
--- /dev/null
+++ b/panels/usage/cc-usage-panel.c
@@ -0,0 +1,160 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2018 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "list-box-helper.h"
+#include "cc-usage-panel.h"
+#include "cc-usage-resources.h"
+#include "cc-util.h"
+
+#include <gio/gdesktopappinfo.h>
+#include <glib/gi18n.h>
+
+struct _CcUsagePanel
+{
+  CcPanel     parent_instance;
+
+  GSettings  *privacy_settings;
+
+  GtkListBox *usage_list_box;
+  GtkSwitch   *recently_used_switch;
+  GtkComboBox *retain_history_combo;
+};
+
+CC_PANEL_REGISTER (CcUsagePanel, cc_usage_panel)
+
+static void
+cc_usage_panel_finalize (GObject *object)
+{
+  CcUsagePanel *self = CC_USAGE_PANEL (object);
+
+  g_clear_object (&self->privacy_settings);
+
+  G_OBJECT_CLASS (cc_usage_panel_parent_class)->finalize (object);
+}
+
+static void
+retain_history_combo_changed_cb (GtkWidget *widget,
+                                 CcUsagePanel *self)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  gint value;
+  gboolean ret;
+
+  ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
+  if (!ret)
+    return;
+
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX(widget));
+  gtk_tree_model_get (model, &iter,
+                      1, &value,
+                      -1);
+  g_settings_set (self->privacy_settings, "recent-files-max-age", "i", value);
+}
+
+static void
+set_retain_history_value_for_combo (GtkComboBox  *combo_box,
+                                    CcUsagePanel *self)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  gint value;
+  gint value_tmp, value_prev;
+  gboolean ret;
+  guint i;
+
+  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;
+
+  g_settings_get (self->privacy_settings, "recent-files-max-age", "i", &value);
+  do
+    {
+      gtk_tree_model_get (model, &iter,
+                          1, &value_tmp,
+                          -1);
+      if (value == value_tmp ||
+          (value > 0 && 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));
+
+  gtk_combo_box_set_active (combo_box, i - 1);
+}
+
+static void
+cc_usage_panel_init (CcUsagePanel *self)
+{
+  g_resources_register (cc_usage_get_resource ());
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  gtk_list_box_set_header_func (self->usage_list_box,
+                                cc_list_box_update_header_func,
+                                NULL, NULL);
+
+  self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
+
+  g_settings_bind (self->privacy_settings, "remember-recent-files",
+                   self->recently_used_switch, "active",
+                   G_SETTINGS_BIND_DEFAULT);
+
+  set_retain_history_value_for_combo (self->retain_history_combo, self);
+  g_signal_connect (self->retain_history_combo, "changed",
+                    G_CALLBACK (retain_history_combo_changed_cb), self);
+
+  g_settings_bind (self->privacy_settings, "remember-recent-files",
+                   self->retain_history_combo, "sensitive",
+                   G_SETTINGS_BIND_GET);
+}
+
+static void
+clear_recent (CcUsagePanel *self)
+{
+  GtkRecentManager *m;
+
+  m = gtk_recent_manager_get_default ();
+  gtk_recent_manager_purge_items (m, NULL);
+}
+
+static void
+cc_usage_panel_class_init (CcUsagePanelClass *klass)
+{
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  oclass->finalize = cc_usage_panel_finalize;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/usage/cc-usage-panel.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, CcUsagePanel, usage_list_box);
+  gtk_widget_class_bind_template_child (widget_class, CcUsagePanel, recently_used_switch);
+  gtk_widget_class_bind_template_child (widget_class, CcUsagePanel, retain_history_combo);
+
+  gtk_widget_class_bind_template_callback (widget_class, clear_recent);
+}
diff --git a/panels/usage/cc-usage-panel.h b/panels/usage/cc-usage-panel.h
new file mode 100644
index 000000000..83dc6fc82
--- /dev/null
+++ b/panels/usage/cc-usage-panel.h
@@ -0,0 +1,30 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2018 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Matthias Clasen <mclasen redhat com>
+ */
+
+#pragma once
+
+#include <shell/cc-panel.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_USAGE_PANEL (cc_usage_panel_get_type ())
+G_DECLARE_FINAL_TYPE (CcUsagePanel, cc_usage_panel, CC, USAGE_PANEL, CcPanel)
+
+G_END_DECLS
diff --git a/panels/usage/cc-usage-panel.ui b/panels/usage/cc-usage-panel.ui
new file mode 100644
index 000000000..af6e8d271
--- /dev/null
+++ b/panels/usage/cc-usage-panel.ui
@@ -0,0 +1,198 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.14"/>
+  <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" context="retain_history" comments="Translators: Option for 
&quot;Retain History&quot; in &quot;Usage &amp; History&quot; dialog.">1 day</col>
+        <col id="1">1</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes" context="retain_history" comments="Translators: Option for 
&quot;Retain History&quot; in &quot;Usage &amp; History&quot; dialog.">7 days</col>
+        <col id="1">7</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes" context="retain_history" comments="Translators: Option for 
&quot;Retain History&quot; in &quot;Usage &amp; History&quot; dialog.">30 days</col>
+        <col id="1">30</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes" context="retain_history" comments="Translators: Option for 
&quot;Retain History&quot; in &quot;Usage &amp; History&quot; dialog.">Forever</col>
+        <col id="1">-1</col>
+      </row>
+    </data>
+  </object>
+  <template class="CcUsagePanel" parent="CcPanel">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">1</property>
+        <property name="hscrollbar-policy">never</property>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">1</property>
+            <!-- Stub boxes to make the content cover 1/3 of the screen -->
+            <child>
+              <object class="GtkBox">
+                <property name="visible">1</property>
+                <property name="hexpand">1</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">1</property>
+                <property name="hexpand">1</property>
+              </object>
+              <packing>
+                <property name="pack-type">end</property>
+              </packing>
+            </child>
+            <!-- Content -->
+            <child>
+              <object class="GtkBox">
+                <property name="visible">1</property>
+                <property name="orientation">vertical</property>
+                <property name="margin">32</property>
+                <property name="hexpand">1</property>
+                <child>
+                  <object class="GtkLabel" id="usage_description_label">
+                    <property name="visible">1</property>
+                    <property name="margin-bottom">12</property>
+                    <property name="label" translatable="yes">Remembering your history of recently used 
applications and files makes things easier to find again. These items are never shared over the 
network.</property>
+                    <property name="wrap">1</property>
+                    <property name="max-width-chars">50</property>
+                    <property name="xalign">0</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkListBox" id="usage_list_box">
+                    <property name="visible">1</property>
+                    <property name="can-focus">1</property>
+                    <property name="selection-mode">none</property>
+                    <child>
+                      <object class="GtkListBoxRow">
+                        <property name="visible">1</property>
+                        <child>
+                          <object class="GtkBox">
+                            <property name="visible">1</property>
+                        <property name="margin_start">12</property>
+                        <property name="margin_end">12</property>
+                        <property name="margin_top">12</property>
+                        <property name="margin_bottom">12</property>
+                            <child>
+                              <object class="GtkLabel">
+                                <property name="visible">1</property>
+                                <property name="label" translatable="yes">_Recently Used</property>
+                                <property name="use_underline">1</property>
+                                <property name="mnemonic_widget">recently_used_switch</property>
+                                <property name="xalign">0</property>
+                                <property name="valign">center</property>
+                              </object>
+                              <packing>
+                                <property name="expand">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkSwitch" id="recently_used_switch">
+                                <property name="visible">1</property>
+                                <property name="halign">end</property>
+                                <property name="valign">center</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkListBoxRow">
+                        <property name="visible">1</property>
+                        <child>
+                          <object class="GtkBox">
+                            <property name="visible">1</property>
+                        <property name="margin_start">12</property>
+                        <property name="margin_end">12</property>
+                        <property name="margin_top">12</property>
+                        <property name="margin_bottom">12</property>
+                            <child>
+                              <object class="GtkLabel">
+                                <property name="visible">1</property>
+                                <property name="label" translatable="yes">Retain _History</property>
+                                <property name="use_underline">1</property>
+                                <property name="mnemonic_widget">retain_history_combo</property>
+                                <property name="sensitive" bind-source="retain_history_combo" 
bind-property="sensitive"/>
+                                <property name="xalign">0</property>
+                                <property name="valign">center</property>
+                              </object>
+                              <packing>
+                                <property name="expand">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkComboBoxText" id="retain_history_combo">
+                                <property name="visible">1</property>
+                                <property name="valign">center</property>
+                                <property name="entry_text_column">0</property>
+                                <property name="model">retain_history_model</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkListBoxRow">
+                        <property name="visible">1</property>
+                        <child>
+                          <object class="GtkBox">
+                            <property name="visible">1</property>
+                        <property name="margin_start">12</property>
+                        <property name="margin_end">12</property>
+                        <property name="margin_top">12</property>
+                        <property name="margin_bottom">12</property>
+                            <child>
+                              <object class="GtkLabel">
+                                <property name="visible">1</property>
+                                <property name="label" translatable="yes">History</property>
+                                <property name="xalign">0</property>
+                                <property name="valign">center</property>
+                              </object>
+                              <packing>
+                                <property name="expand">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="clear_recent_button">
+                                <property name="visible">1</property>
+                                <property name="valign">center</property>
+                                <property name="label" translatable="yes">_Clear Recent History</property>
+                                <property name="use_underline">1</property>
+                                <signal name="clicked" handler="clear_recent" swapped="yes"/>
+                                <style>
+                                  <class name="destructive-action"/>
+                                </style>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <style>
+                      <class name="view"/>
+                      <class name="frame"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/panels/usage/gnome-usage-panel.desktop.in.in b/panels/usage/gnome-usage-panel.desktop.in.in
new file mode 100644
index 000000000..3f4a6adec
--- /dev/null
+++ b/panels/usage/gnome-usage-panel.desktop.in.in
@@ -0,0 +1,19 @@
+[Desktop Entry]
+Name=Usage
+Comment=Don't leave traces
+Exec=gnome-control-center usage
+# FIXME
+# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
+Icon=preferences-system-time
+Terminal=false
+Type=Application
+NoDisplay=true
+StartupNotify=true
+Categories=GNOME;GTK;Settings;DesktopSettings;X-GNOME-Settings-Panel;X-GNOME-PrivacySettings;
+OnlyShowIn=GNOME;Unity;
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-control-center
+X-GNOME-Bugzilla-Component=privacy
+X-GNOME-Bugzilla-Version=@VERSION@
+# Translators: Search terms to find the Privacy panel. Do NOT translate or localize the semicolons! The list 
MUST also end with a semicolon!
+Keywords=screen;lock;diagnostics;crash;private;recent;temporary;tmp;index;name;network;identity;
diff --git a/panels/usage/meson.build b/panels/usage/meson.build
new file mode 100644
index 000000000..74f720ecd
--- /dev/null
+++ b/panels/usage/meson.build
@@ -0,0 +1,40 @@
+panels_list += cappletname
+desktop = 'gnome-@0@-panel.desktop'.format(cappletname)
+
+desktop_in = configure_file(
+  input: desktop + '.in.in',
+  output: desktop + '.in',
+  configuration: desktop_conf
+)
+
+i18n.merge_file(
+  desktop,
+  type: 'desktop',
+  input: desktop_in,
+  output: desktop,
+  po_dir: po_dir,
+  install: true,
+  install_dir: control_center_desktopdir
+)
+
+sources = files('cc-usage-panel.c')
+
+resource_data = files('cc-usage-panel.ui')
+
+sources += gnome.compile_resources(
+  'cc-' + cappletname + '-resources',
+  cappletname + '.gresource.xml',
+  c_name: 'cc_' + cappletname,
+  dependencies: resource_data,
+  export: true
+)
+
+cflags += '-DGNOMELOCALEDIR="@0@"'.format(control_center_localedir)
+
+panels_libs += static_library(
+  cappletname,
+  sources: sources,
+  include_directories: [top_inc, common_inc],
+  dependencies: common_deps,
+  c_args: cflags
+)
diff --git a/panels/usage/usage.gresource.xml b/panels/usage/usage.gresource.xml
new file mode 100644
index 000000000..3f55dbff0
--- /dev/null
+++ b/panels/usage/usage.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/control-center/usage">
+    <file preprocess="xml-stripblanks">cc-usage-panel.ui</file>
+  </gresource>
+</gresources>


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