!20 power: Correctly lookup or insert new items into combobox

From: @chenwei_kernel 
Reviewed-by: @t_feng 
Signed-off-by: @t_feng
This commit is contained in:
openeuler-ci-bot 2022-12-13 06:47:58 +00:00 committed by Gitee
commit fa0b741b50
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 96 additions and 2 deletions

View File

@ -0,0 +1,90 @@
From ff677952619771e0f3c97dd5626f4303ffc1b264 Mon Sep 17 00:00:00 2001
From: Chen Wei <chenwei@xfusion.com>
Date: Sat, 10 Dec 2022 10:15:12 +0800
Subject: [PATCH] power: Correctly lookup or insert new items into combobox
From b5711c59eccb90a547921af6e0f11e5e3dd249f5 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Mon, 5 Nov 2018 13:27:12 +0100
Subject: [PATCH] power: Correctly lookup or insert new items into combobox
The code to lookup or insert items into the combobox had a few issues.
It would assume that the items are sorted, causing existing items to not
be found and be inserted instead. It also would simply forget to insert
an item if it was larger than all existing items.
This code is now changed to iterate over all items, finding the best
insertion point in the process (next item has a larger value, or the
values are not increasing anymore). The item will only be inserted if it
has not been found.
https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/261
Signed-off-by: Chen Wei <chenwei@xfusion.com>
---
panels/power/cc-power-panel.c | 38 ++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index bfac953..d30f834 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -1197,9 +1197,12 @@ static void
set_value_for_combo (GtkComboBox *combo_box, gint value)
{
GtkTreeIter iter;
- GtkTreeIter last;
+ g_autoptr(GtkTreeIter) insert = NULL;
+ GtkTreeIter new;
GtkTreeModel *model;
gint value_tmp;
+ gint value_last = 0;
+ g_autofree gchar *text = NULL;
gboolean ret;
/* get entry */
@@ -1219,25 +1222,24 @@ set_value_for_combo (GtkComboBox *combo_box, gint value)
gtk_combo_box_set_active_iter (combo_box, &iter);
return;
}
- else if (value_tmp > value)
- {
- GtkTreeIter new;
- g_autofree gchar *text = NULL;
-
- /* This is an unlisted value, add it to the drop-down */
- gtk_list_store_insert_before (GTK_LIST_STORE (model), &new, &iter);
- text = time_to_string_text (value * 1000);
- gtk_list_store_set (GTK_LIST_STORE (model), &new,
- ACTION_MODEL_TEXT, text,
- ACTION_MODEL_VALUE, value,
- -1);
- gtk_combo_box_set_active_iter (combo_box, &new);
- return;
- }
- last = iter;
+
+ /* Insert before if the next value is larger or the value is lower
+ * again (i.e. "Never" is zero and last). */
+ if (!insert && (value_tmp > value || value_last > value_tmp))
+ insert = gtk_tree_iter_copy (&iter);
+
+ value_last = value_tmp;
} while (gtk_tree_model_iter_next (model, &iter));
- gtk_combo_box_set_active_iter (combo_box, &last);
+ /* The value is not listed, so add it at the best point (or the end). */
+ gtk_list_store_insert_before (GTK_LIST_STORE (model), &new, insert);
+
+ text = time_to_string_text (value * 1000);
+ gtk_list_store_set (GTK_LIST_STORE (model), &new,
+ ACTION_MODEL_TEXT, text,
+ ACTION_MODEL_VALUE, value,
+ -1);
+ gtk_combo_box_set_active_iter (combo_box, &new);
}
static void
--
2.33.0

View File

@ -1,6 +1,6 @@
Name: gnome-control-center
Version: 3.30.1
Release: 12
Release: 13
Summary: GNOME Settings is GNOME's main interface for configuration of various aspects of your desktop.
License: GPLv2+ and CC-BY-3.0
URL: http://www.gnome.org
@ -40,6 +40,7 @@ Patch9004: bugfix-duplicate-Current-passwd.patch
Patch9005: gnome-control-center-remove-country-in-the-name-of-timezone.patch
Patch9006: Fix-crashes-when-retrieving-disk-size.patch
Patch9007: backport-bugfix-power-set-no-show-all-to-TRUE-on-wifi-and.patch
Patch9008: backport-bugfix-power-Correctly-lookup-or-insert-new-item.patch
%description
Gnome-control-center is a graphical user interface to configure
@ -104,8 +105,11 @@ chrpath --delete %{buildroot}%{_bindir}/gnome-control-center
%{_mandir}/man1/*.gz
%changelog
* Mon Dec 12 2022 Wei Chen <chenwei@xfusion.com> - 3.30.1-13
- power: correctly lookup or insert new items into combobox
* Sat Dec 10 2022 Wei Chen <chenwei@xfusion.com> - 3.30.1-12
- power: fix no-show-all to TRUE on wifi and mobile rows
- power: set no-show-all to TRUE on wifi and mobile rows
* Sat Aug 29 2020 jinzhimin <jinzhimin2@huawei.com> - 3.30.1-11
- Delete BuildRequires libXxf86misc-devel