summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2019-09-25 18:39:47 -0300
committerRobert Ancell <robert.ancell@canonical.com>2019-11-07 14:40:07 +1300
commite677539b28bd5c39df927cf8445e282ec6c1e88d (patch)
tree09e4b5d66a5d088b99e351aa9ce7e9034ce32c5f /shell
parenta4bdc3776050e576f2d8e4bab2e8bbcf466d6f4a (diff)
downloadgnome-control-center-e677539b28bd5c39df927cf8445e282ec6c1e88d.tar.gz
panel-list: Only use panel id to sort
Right now, the sort function checks for two different fields when comparing panel rows: the category of the row, and the id of the panel. When comparing using the category, it relies on the order of the enum values of CcPanelCategory. When comparing by panel ids, it uses the hardcoded positions defined in the 'panel_order' array. Using categories, however, is unecessary for our case, and makes sorting a tad more complicated than it should be. Remove the category comparison of the sort function, and rely only on the positions defined in 'panel_order'.
Diffstat (limited to 'shell')
-rw-r--r--shell/cc-panel-list.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/shell/cc-panel-list.c b/shell/cc-panel-list.c
index 1c7ff7394..78a800978 100644
--- a/shell/cc-panel-list.c
+++ b/shell/cc-panel-list.c
@@ -255,6 +255,26 @@ update_search (CcPanelList *self)
gtk_list_box_unselect_all (GTK_LIST_BOX (self->search_listbox));
}
+static const gchar*
+get_panel_id_from_row (CcPanelList *self,
+ GtkListBoxRow *row)
+{
+
+ RowData *row_data;
+
+ if (row == self->details_row)
+ return "details";
+ else if (row == self->devices_row)
+ return "devices";
+ else if (row == self->privacy_row)
+ return "privacy";
+
+ row_data = g_object_get_data (G_OBJECT (row), "data");
+
+ g_assert (row_data != NULL);
+ return row_data->id;
+}
+
/*
* RowData functions
*/
@@ -398,6 +418,9 @@ static const gchar * const panel_order[] = {
"sound",
"power",
"network",
+ "privacy",
+ "devices",
+ "details",
/* Privacy page */
"location",
@@ -445,32 +468,12 @@ sort_function (GtkListBoxRow *a,
gpointer user_data)
{
CcPanelList *self = CC_PANEL_LIST (user_data);
- RowData *a_data, *b_data;
- GtkListBoxRow *special[3] = { self->privacy_row, self->devices_row, self->details_row };
- int ai = -1;
- int bi = -1;
- int i;
-
- for (i = 0; i < 3; i++)
- {
- if (a == special[i]) ai = i;
- if (b == special[i]) bi = i;
- }
-
- if (ai >= 0 || bi >= 0)
- return ai - bi;
-
- /*
- * We can only retrieve the data after assuring that none
- * of the rows are Devices and Details.
- */
- a_data = g_object_get_data (G_OBJECT (a), "data");
- b_data = g_object_get_data (G_OBJECT (b), "data");
+ const gchar *a_id, *b_id;
- if (a_data->category != b_data->category)
- return a_data->category - b_data->category;
+ a_id = get_panel_id_from_row (self, a);
+ b_id = get_panel_id_from_row (self, b);
- return get_panel_id_index (a_data->id) - get_panel_id_index (b_data->id);
+ return get_panel_id_index (a_id) - get_panel_id_index (b_id);
}
static gint