[gnome-control-center] usage: Use AdwComboRow for "Automatically Delete Period"
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] usage: Use AdwComboRow for "Automatically Delete Period"
- Date: Sat, 12 Feb 2022 21:37:47 +0000 (UTC)
commit a95b57061b8abc2262d8faa3e3a9311637a54adf
Author: Christopher Davis <christopherdavis gnome org>
Date: Sat Feb 12 12:36:30 2022 -0800
usage: Use AdwComboRow for "Automatically Delete Period"
panels/usage/cc-usage-panel.c | 111 ++++++++++++++++++++++-------------------
panels/usage/cc-usage-panel.h | 13 +++++
panels/usage/cc-usage-panel.ui | 69 ++++---------------------
panels/usage/meson.build | 5 ++
4 files changed, 86 insertions(+), 112 deletions(-)
---
diff --git a/panels/usage/cc-usage-panel.c b/panels/usage/cc-usage-panel.c
index 659d906a4..e9d18d3b5 100644
--- a/panels/usage/cc-usage-panel.c
+++ b/panels/usage/cc-usage-panel.c
@@ -19,6 +19,7 @@
*/
#include "cc-usage-panel.h"
+#include "cc-usage-panel-enums.h"
#include "cc-usage-resources.h"
#include "cc-util.h"
@@ -36,73 +37,80 @@ struct _CcUsagePanel
GtkSwitch *purge_trash_switch;
GtkSwitch *purge_temp_switch;
- GtkComboBox *purge_after_combo;
+ AdwComboRow *purge_after_combo;
GtkButton *purge_temp_button;
GtkButton *purge_trash_button;
};
CC_PANEL_REGISTER (CcUsagePanel, cc_usage_panel)
+static char *
+purge_after_name_cb (AdwEnumListItem *item,
+ gpointer user_data)
+{
+ switch (adw_enum_list_item_get_value (item))
+ {
+ case CC_USAGE_PANEL_PURGE_AFTER_1_HOUR:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "1 hour"));
+ case CC_USAGE_PANEL_PURGE_AFTER_1_DAY:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "1 day"));
+ case CC_USAGE_PANEL_PURGE_AFTER_2_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "2 days"));
+ case CC_USAGE_PANEL_PURGE_AFTER_3_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "3 days"));
+ case CC_USAGE_PANEL_PURGE_AFTER_4_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "4 days"));
+ case CC_USAGE_PANEL_PURGE_AFTER_5_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "5 days"));
+ case CC_USAGE_PANEL_PURGE_AFTER_6_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "6 days"));
+ case CC_USAGE_PANEL_PURGE_AFTER_7_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "7 days"));
+ case CC_USAGE_PANEL_PURGE_AFTER_14_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "14 days"));
+ case CC_USAGE_PANEL_PURGE_AFTER_30_DAYS:
+ /* Translators: Option for "Automatically Delete Period" in "Trash & Temporary Files" group */
+ return g_strdup (C_("purge_files", "30 days"));
+ default:
+ return NULL;
+ }
+}
+
static void
-purge_after_combo_changed_cb (CcUsagePanel *self)
+purge_after_combo_changed_cb (AdwComboRow *combo_row,
+ GParamSpec *pspec,
+ CcUsagePanel *self)
{
- GtkTreeIter iter;
- GtkTreeModel *model;
- guint value;
- gboolean ret;
+ AdwEnumListItem *item;
+ CcUsagePanelPurgeAfter value;
- /* no selection */
- ret = gtk_combo_box_get_active_iter (self->purge_after_combo, &iter);
- if (!ret)
- return;
+ item = ADW_ENUM_LIST_ITEM (adw_combo_row_get_selected_item (combo_row));
+ value = adw_enum_list_item_get_value (item);
- /* get entry */
- model = gtk_combo_box_get_model (self->purge_after_combo);
- gtk_tree_model_get (model, &iter,
- 1, &value,
- -1);
g_settings_set (self->privacy_settings, "old-files-age", "u", value);
}
static void
-set_purge_after_value_for_combo (GtkComboBox *combo_box,
+set_purge_after_value_for_combo (AdwComboRow *combo_row,
CcUsagePanel *self)
{
- GtkTreeIter iter;
- GtkTreeModel *model;
+ AdwEnumListModel *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;
+ model = ADW_ENUM_LIST_MODEL (adw_combo_row_get_model (combo_row));
- /* try to make the UI match the purge setting */
g_settings_get (self->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);
+ adw_combo_row_set_selected (combo_row,
+ adw_enum_list_model_find_position (model, value));
}
static GtkDialog *
@@ -290,6 +298,8 @@ cc_usage_panel_init (CcUsagePanel *self)
{
g_resources_register (cc_usage_get_resource ());
+ g_type_ensure (CC_TYPE_USAGE_PANEL_PURGE_AFTER);
+
gtk_widget_init_template (GTK_WIDGET (self));
self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
@@ -322,11 +332,6 @@ cc_usage_panel_init (CcUsagePanel *self)
G_SETTINGS_BIND_DEFAULT);
set_purge_after_value_for_combo (self->purge_after_combo, self);
- g_signal_connect_object (self->purge_after_combo,
- "changed",
- G_CALLBACK (purge_after_combo_changed_cb),
- self,
- G_CONNECT_SWAPPED);
g_signal_connect_object (self->purge_trash_button, "clicked", G_CALLBACK (empty_trash), self,
G_CONNECT_SWAPPED);
g_signal_connect_object (self->purge_temp_button, "clicked", G_CALLBACK (purge_temp), self,
G_CONNECT_SWAPPED);
@@ -360,4 +365,6 @@ cc_usage_panel_class_init (CcUsagePanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcUsagePanel, retain_history_combo);
gtk_widget_class_bind_template_callback (widget_class, clear_recent);
+ gtk_widget_class_bind_template_callback (widget_class, purge_after_name_cb);
+ gtk_widget_class_bind_template_callback (widget_class, purge_after_combo_changed_cb);
}
diff --git a/panels/usage/cc-usage-panel.h b/panels/usage/cc-usage-panel.h
index 83dc6fc82..7c5a1b331 100644
--- a/panels/usage/cc-usage-panel.h
+++ b/panels/usage/cc-usage-panel.h
@@ -27,4 +27,17 @@ 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)
+typedef enum {
+ CC_USAGE_PANEL_PURGE_AFTER_1_HOUR = 0,
+ CC_USAGE_PANEL_PURGE_AFTER_1_DAY = 1,
+ CC_USAGE_PANEL_PURGE_AFTER_2_DAYS = 2,
+ CC_USAGE_PANEL_PURGE_AFTER_3_DAYS = 3,
+ CC_USAGE_PANEL_PURGE_AFTER_4_DAYS = 4,
+ CC_USAGE_PANEL_PURGE_AFTER_5_DAYS = 5,
+ CC_USAGE_PANEL_PURGE_AFTER_6_DAYS = 6,
+ CC_USAGE_PANEL_PURGE_AFTER_7_DAYS = 7,
+ CC_USAGE_PANEL_PURGE_AFTER_14_DAYS = 14,
+ CC_USAGE_PANEL_PURGE_AFTER_30_DAYS = 30,
+} CcUsagePanelPurgeAfter;
+
G_END_DECLS
diff --git a/panels/usage/cc-usage-panel.ui b/panels/usage/cc-usage-panel.ui
index 39c50c4a3..db1252f08 100644
--- a/panels/usage/cc-usage-panel.ui
+++ b/panels/usage/cc-usage-panel.ui
@@ -87,18 +87,18 @@
</object>
</child>
<child>
- <object class="AdwActionRow">
+ <object class="AdwComboRow" id="purge_after_combo">
<property name="title" translatable="yes">Automatically Delete _Period</property>
- <property name="activatable_widget">purge_after_combo</property>
- <property name="sensitive" bind-source="purge_after_combo" bind-property="sensitive"/>
<property name="use-underline">true</property>
- <child type="suffix">
- <object class="GtkComboBoxText" id="purge_after_combo">
- <property name="valign">center</property>
- <property name="entry_text_column">0</property>
- <property name="model">purge_after_model</property>
+ <signal name="notify::selected-item" handler="purge_after_combo_changed_cb"/>
+ <property name="model">
+ <object class="AdwEnumListModel">
+ <property name="enum-type">CcUsagePanelPurgeAfter</property>
</object>
- </child>
+ </property>
+ <property name="expression">
+ <closure type="gchararray" function="purge_after_name_cb"/>
+ </property>
</object>
</child>
<child>
@@ -138,57 +138,6 @@
</child>
</template>
- <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" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">1 hour</col>
- <col id="1">0</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">1 day</col>
- <col id="1">1</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">2 days</col>
- <col id="1">2</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">3 days</col>
- <col id="1">3</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">4 days</col>
- <col id="1">4</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">5 days</col>
- <col id="1">5</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">6 days</col>
- <col id="1">6</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">7 days</col>
- <col id="1">7</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">14 days</col>
- <col id="1">14</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="purge_files" comments="Translators: Option for "Purge
After" in "Purge Trash & Temporary Files" dialog.">30 days</col>
- <col id="1">30</col>
- </row>
- </data>
- </object>
-
<object class="GtkListStore" id="retain_history_model">
<columns>
<!-- column-name name -->
diff --git a/panels/usage/meson.build b/panels/usage/meson.build
index 522568ccc..8365b8365 100644
--- a/panels/usage/meson.build
+++ b/panels/usage/meson.build
@@ -20,6 +20,11 @@ sources = files('cc-usage-panel.c')
resource_data = files('cc-usage-panel.ui')
+sources += gnome.mkenums_simple(
+ 'cc-usage-panel-enums',
+ sources: ['cc-usage-panel.h'],
+)
+
sources += gnome.compile_resources(
'cc-' + cappletname + '-resources',
cappletname + '.gresource.xml',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]