From 1488053d665862595f467bc0a7f7388d6f23e012 Mon Sep 17 00:00:00 2001 From: Chen Wei Date: Mon, 12 Dec 2022 16:58:06 +0800 Subject: [PATCH] power: Correctly lookup or insert new items into combobox From b5711c59eccb90a547921af6e0f11e5e3dd249f5 Mon Sep 17 00:00:00 2001 From: Benjamin Berg 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 --- ...-Correctly-lookup-or-insert-new-item.patch | 90 +++++++++++++++++++ gnome-control-center.spec | 8 +- 2 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 backport-bugfix-power-Correctly-lookup-or-insert-new-item.patch diff --git a/backport-bugfix-power-Correctly-lookup-or-insert-new-item.patch b/backport-bugfix-power-Correctly-lookup-or-insert-new-item.patch new file mode 100644 index 0000000..bed48d5 --- /dev/null +++ b/backport-bugfix-power-Correctly-lookup-or-insert-new-item.patch @@ -0,0 +1,90 @@ +From ff677952619771e0f3c97dd5626f4303ffc1b264 Mon Sep 17 00:00:00 2001 +From: Chen Wei +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 +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 +--- + 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 + diff --git a/gnome-control-center.spec b/gnome-control-center.spec index 09c8c53..e380ccf 100644 --- a/gnome-control-center.spec +++ b/gnome-control-center.spec @@ -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 - 3.30.1-13 +- power: correctly lookup or insert new items into combobox + * Sat Dec 10 2022 Wei Chen - 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 - 3.30.1-11 - Delete BuildRequires libXxf86misc-devel