[gnome-control-center] lock: Use AdwComboRow for screen lock delay
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] lock: Use AdwComboRow for screen lock delay
- Date: Mon, 24 Jan 2022 21:38:03 +0000 (UTC)
commit 0c5d3fb50d1b6a8d1fabd2254b8cc55c78b73aeb
Author: Christopher Davis <christopherdavis gnome org>
Date: Fri Jan 21 15:13:18 2022 -0800
lock: Use AdwComboRow for screen lock delay
panels/lock/cc-lock-panel.c | 103 +++++++++++++++++++++++--------------------
panels/lock/cc-lock-panel.h | 11 +++++
panels/lock/cc-lock-panel.ui | 70 ++++-------------------------
panels/lock/meson.build | 5 +++
4 files changed, 81 insertions(+), 108 deletions(-)
---
diff --git a/panels/lock/cc-lock-panel.c b/panels/lock/cc-lock-panel.c
index 0541d5571..4427a389d 100644
--- a/panels/lock/cc-lock-panel.c
+++ b/panels/lock/cc-lock-panel.c
@@ -20,9 +20,11 @@
*/
#include "cc-lock-panel.h"
+#include "cc-lock-panel-enums.h"
#include "cc-lock-resources.h"
#include "cc-util.h"
+#include <adwaita.h>
#include <gio/gdesktopappinfo.h>
#include <glib/gi18n.h>
@@ -39,7 +41,7 @@ struct _CcLockPanel
GtkSwitch *automatic_screen_lock_switch;
GtkComboBox *blank_screen_combo;
- GtkComboBox *lock_after_combo;
+ AdwComboRow *lock_after_row;
GtkSwitch *show_notifications_switch;
GtkSwitch *usb_protection_switch;
GDBusProxy *usb_proxy;
@@ -48,64 +50,68 @@ struct _CcLockPanel
CC_PANEL_REGISTER (CcLockPanel, cc_lock_panel)
+static char *
+lock_after_name_cb (AdwEnumListItem *item,
+ gpointer user_data)
+{
+
+ switch (adw_enum_list_item_get_value (item))
+ {
+ case CC_LOCK_PANEL_LOCK_AFTER_SCREEN_OFF:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup(C_("lock_screen", "Screen Turns Off"));
+ case CC_LOCK_PANEL_LOCK_AFTER_30_SEC:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup (C_("lock_screen", "30 seconds"));
+ case CC_LOCK_PANEL_LOCK_AFTER_1_MIN:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup (C_("lock_screen", "1 minute"));
+ case CC_LOCK_PANEL_LOCK_AFTER_2_MIN:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup (C_("lock_screen", "2 minutes"));
+ case CC_LOCK_PANEL_LOCK_AFTER_3_MIN:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup (C_("lock_screen", "3 minutes"));
+ case CC_LOCK_PANEL_LOCK_AFTER_5_MIN:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup (C_("lock_screen", "3 minutes"));
+ case CC_LOCK_PANEL_LOCK_AFTER_30_MIN:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup (C_("lock_screen", "30 minutes"));
+ case CC_LOCK_PANEL_LOCK_AFTER_1_HR:
+ /* Translators: Option for "Lock screen after blank" in "Screen Lock" panel */
+ return g_strdup (C_("lock_screen", "1 hour"));
+ default:
+ return NULL;
+ }
+}
+
static void
-on_lock_combo_changed_cb (GtkWidget *widget,
+on_lock_combo_changed_cb (AdwComboRow *combo_row,
+ GParamSpec *pspec,
CcLockPanel *self)
{
- GtkTreeIter iter;
- GtkTreeModel *model;
- guint delay;
- gboolean ret;
+ AdwEnumListItem *item;
+ CcLockPanelLockAfter delay;
- ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
- if (!ret)
- return;
+ item = ADW_ENUM_LIST_ITEM (adw_combo_row_get_selected_item (combo_row));
+ delay = adw_enum_list_item_get_value (item);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
- gtk_tree_model_get (model, &iter,
- 1, &delay,
- -1);
g_settings_set (self->lock_settings, "lock-delay", "u", delay);
}
static void
-set_lock_value_for_combo (GtkComboBox *combo_box,
+set_lock_value_for_combo (AdwComboRow *combo_row,
CcLockPanel *self)
{
- GtkTreeIter iter;
- GtkTreeModel *model;
+ AdwEnumListModel *model;
guint 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;
+ model = ADW_ENUM_LIST_MODEL (adw_combo_row_get_model (combo_row));
g_settings_get (self->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));
-
- 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 void
@@ -259,16 +265,19 @@ cc_lock_panel_class_init (CcLockPanelClass *klass)
oclass->finalize = cc_lock_panel_finalize;
+ g_type_ensure (CC_TYPE_LOCK_PANEL_LOCK_AFTER);
+
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/lock/cc-lock-panel.ui");
gtk_widget_class_bind_template_child (widget_class, CcLockPanel, automatic_screen_lock_switch);
gtk_widget_class_bind_template_child (widget_class, CcLockPanel, blank_screen_combo);
- gtk_widget_class_bind_template_child (widget_class, CcLockPanel, lock_after_combo);
+ gtk_widget_class_bind_template_child (widget_class, CcLockPanel, lock_after_row);
gtk_widget_class_bind_template_child (widget_class, CcLockPanel, show_notifications_switch);
gtk_widget_class_bind_template_child (widget_class, CcLockPanel, usb_protection_switch);
gtk_widget_class_bind_template_child (widget_class, CcLockPanel, usb_protection_row);
gtk_widget_class_bind_template_callback (widget_class, on_blank_screen_delay_changed_cb);
+ gtk_widget_class_bind_template_callback (widget_class, lock_after_name_cb);
gtk_widget_class_bind_template_callback (widget_class, on_lock_combo_changed_cb);
}
@@ -296,11 +305,11 @@ cc_lock_panel_init (CcLockPanel *self)
g_settings_bind (self->lock_settings,
"lock-enabled",
- self->lock_after_combo,
+ self->lock_after_row,
"sensitive",
G_SETTINGS_BIND_GET);
- set_lock_value_for_combo (self->lock_after_combo, self);
+ set_lock_value_for_combo (self->lock_after_row, self);
g_settings_bind (self->notification_settings,
"show-in-lock-screen",
diff --git a/panels/lock/cc-lock-panel.h b/panels/lock/cc-lock-panel.h
index c8db1b9ca..0737a914a 100644
--- a/panels/lock/cc-lock-panel.h
+++ b/panels/lock/cc-lock-panel.h
@@ -27,4 +27,15 @@ G_BEGIN_DECLS
#define CC_TYPE_LOCK_PANEL (cc_lock_panel_get_type ())
G_DECLARE_FINAL_TYPE (CcLockPanel, cc_lock_panel, CC, LOCK_PANEL, CcPanel)
+typedef enum {
+ CC_LOCK_PANEL_LOCK_AFTER_SCREEN_OFF = 0,
+ CC_LOCK_PANEL_LOCK_AFTER_30_SEC = 30,
+ CC_LOCK_PANEL_LOCK_AFTER_1_MIN = 60,
+ CC_LOCK_PANEL_LOCK_AFTER_2_MIN = 120,
+ CC_LOCK_PANEL_LOCK_AFTER_3_MIN = 180,
+ CC_LOCK_PANEL_LOCK_AFTER_5_MIN = 300,
+ CC_LOCK_PANEL_LOCK_AFTER_30_MIN = 1800,
+ CC_LOCK_PANEL_LOCK_AFTER_1_HR = 3600,
+} CcLockPanelLockAfter;
+
G_END_DECLS
diff --git a/panels/lock/cc-lock-panel.ui b/panels/lock/cc-lock-panel.ui
index 706fb178e..cf168ac5d 100644
--- a/panels/lock/cc-lock-panel.ui
+++ b/panels/lock/cc-lock-panel.ui
@@ -44,21 +44,20 @@
<!-- Automatic Screen Lock Delay row -->
<child>
- <object class="AdwActionRow">
+ <object class="AdwComboRow" id="lock_after_row">
<property name="title" translatable="yes">Automatic _Screen Lock Delay</property>
<property name="subtitle" translatable="yes">Period after the screen blanks when the screen
is automatically locked.</property>
<property name="subtitle-lines">2</property>
- <property name="activatable-widget">lock_after_combo</property>
- <property name="sensitive" bind-source="lock_after_combo" bind-property="sensitive"/>
<property name="use-underline">true</property>
- <child>
- <object class="GtkComboBoxText" id="lock_after_combo">
- <property name="valign">center</property>
- <property name="entry_text_column">0</property>
- <property name="model">lock_after_model</property>
- <signal name="changed" handler="on_lock_combo_changed_cb" object="CcLockPanel"
swapped="no" />
+ <signal name="notify::selected-item" handler="on_lock_combo_changed_cb"/>
+ <property name="model">
+ <object class="AdwEnumListModel">
+ <property name="enum-type">CcLockPanelLockAfter</property>
</object>
- </child>
+ </property>
+ <property name="expression">
+ <closure type="gchararray" function="lock_after_name_cb"/>
+ </property>
</object>
</child>
@@ -101,57 +100,6 @@
</child>
</template>
- <object class="GtkSizeGroup">
- <property name="mode">horizontal</property>
- <widgets>
- <widget name="blank_screen_combo" />
- <widget name="lock_after_combo" />
- </widgets>
- </object>
-
- <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" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">Screen Turns Off</col>
- <col id="1">0</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">30 seconds</col>
- <col id="1">30</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">1 minute</col>
- <col id="1">60</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">2 minutes</col>
- <col id="1">120</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">3 minutes</col>
- <col id="1">180</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">5 minutes</col>
- <col id="1">300</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">30 minutes</col>
- <col id="1">1800</col>
- </row>
- <row>
- <col id="0" translatable="yes" context="lock_screen" comments="Translators: Option for "Lock
screen after blank for" in "Screen Lock" dialog.">1 hour</col>
- <col id="1">3600</col>
- </row>
- </data>
- </object>
-
<object class="GtkListStore" id="blank_screen_model">
<columns>
<!-- column-name name -->
diff --git a/panels/lock/meson.build b/panels/lock/meson.build
index 18dbfb2b3..cc2e8f51a 100644
--- a/panels/lock/meson.build
+++ b/panels/lock/meson.build
@@ -20,6 +20,11 @@ sources = files('cc-lock-panel.c')
resource_data = files('cc-lock-panel.ui')
+sources += gnome.mkenums_simple(
+ 'cc-lock-panel-enums',
+ sources: ['cc-lock-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]