[epiphany/wip/exalm/container: 1/5] Stop using gtk_container_get_children() for GtkListBox and GtkFlowBox
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/container: 1/5] Stop using gtk_container_get_children() for GtkListBox and GtkFlowBox
- Date: Fri, 18 Feb 2022 07:49:47 +0000 (UTC)
commit 79a30286f8330acd7542ccffe3cac98a3ca8acbe
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Feb 16 13:45:21 2022 +0500
Stop using gtk_container_get_children() for GtkListBox and GtkFlowBox
Leave one instance in EphyHistoryDialog that gets the last child of the
listbox - that would be painful to do with gtk_list_box_get_row_at_index()
and in GTK4 we'll just use gtk_widget_get_last_child() instead.
lib/widgets/ephy-downloads-popover.c | 36 ++++-------
src/bookmarks/ephy-bookmark-properties.c | 9 ++-
src/bookmarks/ephy-bookmarks-popover.c | 96 +++++++++++++---------------
src/ephy-encoding-dialog.c | 32 ++++------
src/ephy-history-dialog.c | 53 +++++++--------
src/ephy-web-extension-dialog.c | 10 +--
src/preferences/ephy-search-engine-listbox.c | 15 ++---
src/preferences/passwords-view.c | 11 +---
src/preferences/prefs-general-page.c | 6 +-
9 files changed, 112 insertions(+), 156 deletions(-)
---
diff --git a/lib/widgets/ephy-downloads-popover.c b/lib/widgets/ephy-downloads-popover.c
index c91857671..86e2541f0 100644
--- a/lib/widgets/ephy-downloads-popover.c
+++ b/lib/widgets/ephy-downloads-popover.c
@@ -95,29 +95,22 @@ static void
download_removed_cb (EphyDownloadsPopover *popover,
EphyDownload *download)
{
- g_autoptr (GList) children = NULL;
- GList *l;
EphyDownloadsManager *manager;
-
- children = gtk_container_get_children (GTK_CONTAINER (popover->downloads_box));
+ GtkListBoxRow *row;
+ int i = 0;
/* Hide the popover before removing the last download widget so it "crumples"
* more smoothly */
- if (g_list_length (children) == 1)
+ if (!gtk_list_box_get_row_at_index (GTK_LIST_BOX (popover->downloads_box), 2))
gtk_widget_hide (GTK_WIDGET (popover));
- for (l = children; l; l = g_list_next (l)) {
- GtkWidget *widget;
-
- if (!GTK_IS_LIST_BOX_ROW (l->data))
- continue;
-
- widget = gtk_bin_get_child (GTK_BIN (l->data));
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (popover->downloads_box), i++))) {
+ GtkWidget *widget = gtk_bin_get_child (GTK_BIN (row));
if (!EPHY_IS_DOWNLOAD_WIDGET (widget))
continue;
if (ephy_download_widget_get_download (EPHY_DOWNLOAD_WIDGET (widget)) == download) {
- gtk_widget_destroy (l->data);
+ gtk_container_remove (GTK_CONTAINER (popover->downloads_box), GTK_WIDGET (row));
break;
}
}
@@ -129,31 +122,24 @@ download_removed_cb (EphyDownloadsPopover *popover,
static void
clear_button_clicked_cb (EphyDownloadsPopover *popover)
{
- g_autoptr (GList) children = NULL;
- GList *l;
EphyDownloadsManager *manager;
+ GtkListBoxRow *row;
gtk_widget_hide (GTK_WIDGET (popover));
manager = ephy_embed_shell_get_downloads_manager (ephy_embed_shell_get_default ());
g_signal_handlers_block_by_func (manager, download_removed_cb, popover);
- children = gtk_container_get_children (GTK_CONTAINER (popover->downloads_box));
- for (l = children; l; l = g_list_next (l)) {
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (popover->downloads_box), 0))) {
GtkWidget *widget;
EphyDownload *download;
- if (!GTK_IS_LIST_BOX_ROW (l->data))
- continue;
-
- widget = gtk_bin_get_child (GTK_BIN (l->data));
- if (!EPHY_IS_DOWNLOAD_WIDGET (widget))
- continue;
-
+ widget = gtk_bin_get_child (GTK_BIN (row));
download = ephy_download_widget_get_download (EPHY_DOWNLOAD_WIDGET (widget));
+
if (!ephy_download_is_active (download)) {
ephy_downloads_manager_remove_download (manager, download);
- gtk_widget_destroy (l->data);
+ gtk_container_remove (GTK_CONTAINER (popover->downloads_box), GTK_WIDGET (row));
}
}
gtk_widget_set_sensitive (popover->clear_button, FALSE);
diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c
index 67c7dd3bb..238f27541 100644
--- a/src/bookmarks/ephy-bookmark-properties.c
+++ b/src/bookmarks/ephy-bookmark-properties.c
@@ -95,15 +95,14 @@ flow_box_sort_func (GtkFlowBoxChild *child1,
static void
update_tags_scrollbar (EphyBookmarkProperties *self)
{
- g_autoptr (GList) children = NULL;
- gint n_tags;
+ gboolean show_scrollbar;
- children = gtk_container_get_children (GTK_CONTAINER (self->tags_box));
- n_tags = g_list_length (children);
+ /* We only allow showing scrollbar if we have 4 or more tags. */
+ show_scrollbar = !!gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (self->tags_box), 3);
g_object_set (self->tags_scrolled_window,
"vscrollbar-policy",
- (n_tags > 3) ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
+ show_scrollbar ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
NULL);
}
diff --git a/src/bookmarks/ephy-bookmarks-popover.c b/src/bookmarks/ephy-bookmarks-popover.c
index 65ebccb80..4d5077d2d 100644
--- a/src/bookmarks/ephy-bookmarks-popover.c
+++ b/src/bookmarks/ephy-bookmarks-popover.c
@@ -53,24 +53,23 @@ static GtkWidget * create_bookmark_row (gpointer item, gpointer user_data);
static GtkWidget *create_tag_row (const char *tag);
static void
-remove_bookmark_row_from_container (GtkContainer *container,
- const char *url)
+remove_bookmark_row (GtkListBox *list_box,
+ const char *url)
{
- GList *children;
+ GtkListBoxRow *row;
+ int i = 0;
- g_assert (GTK_IS_CONTAINER (container));
+ g_assert (GTK_IS_LIST_BOX (list_box));
- children = gtk_container_get_children (container);
- for (GList *l = children; l && l->data; l = l->next) {
- const char *type = g_object_get_data (l->data, "type");
+ while ((row = gtk_list_box_get_row_at_index (list_box, i++))) {
+ const char *type = g_object_get_data (G_OBJECT (row), "type");
if (g_strcmp0 (type, EPHY_LIST_BOX_ROW_TYPE_BOOKMARK) == 0 &&
- g_strcmp0 (ephy_bookmark_row_get_bookmark_url (l->data), url) == 0) {
- gtk_container_remove (container, l->data);
+ g_strcmp0 (ephy_bookmark_row_get_bookmark_url (EPHY_BOOKMARK_ROW (row)), url) == 0) {
+ gtk_container_remove (GTK_CONTAINER (list_box), GTK_WIDGET (row));
break;
}
}
- g_list_free (children);
}
static void
@@ -79,21 +78,18 @@ ephy_bookmarks_popover_bookmark_tag_added_cb (EphyBookmarksPopover *self,
const char *tag,
EphyBookmarksManager *manager)
{
- GtkWidget *tag_row;
- GList *children;
- GList *l;
gboolean exists;
const char *visible_stack_child;
- const char *title;
- const char *type;
+ GtkListBoxRow *row;
+ int i = 0;
g_assert (EPHY_IS_BOOKMARK (bookmark));
g_assert (EPHY_IS_BOOKMARKS_POPOVER (self));
/* If the bookmark no longer has 0 tags, we remove it from the tags list box */
if (g_sequence_get_length (ephy_bookmark_get_tags (bookmark)) == 1)
- remove_bookmark_row_from_container (GTK_CONTAINER (self->tags_list_box),
- ephy_bookmark_get_url (bookmark));
+ remove_bookmark_row (GTK_LIST_BOX (self->tags_list_box),
+ ephy_bookmark_get_url (bookmark));
/* If we are on the tag detail list box, then the user has toggled the state
* of the tag widget multiple times. The first time the bookmark was removed
@@ -101,17 +97,17 @@ ephy_bookmarks_popover_bookmark_tag_added_cb (EphyBookmarksPopover *self,
visible_stack_child = gtk_stack_get_visible_child_name (GTK_STACK (self->toplevel_stack));
if (g_strcmp0 (visible_stack_child, "tag_detail") == 0 &&
g_strcmp0 (self->tag_detail_tag, tag) == 0) {
- GtkWidget *row;
+ GtkWidget *bookmark_row;
- row = create_bookmark_row (bookmark, self);
- gtk_container_add (GTK_CONTAINER (self->tag_detail_list_box), row);
+ bookmark_row = create_bookmark_row (bookmark, self);
+ gtk_container_add (GTK_CONTAINER (self->tag_detail_list_box), bookmark_row);
}
exists = FALSE;
- children = gtk_container_get_children (GTK_CONTAINER (self->tags_list_box));
- for (l = children; l != NULL; l = l->next) {
- title = g_object_get_data (G_OBJECT (l->data), "title");
- type = g_object_get_data (G_OBJECT (l->data), "type");
+
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->tags_list_box), i++))) {
+ const char *title = g_object_get_data (G_OBJECT (row), "title");
+ const char *type = g_object_get_data (G_OBJECT (row), "type");
if (g_strcmp0 (title, tag) == 0 &&
g_strcmp0 (type, EPHY_LIST_BOX_ROW_TYPE_TAG) == 0) {
@@ -119,10 +115,9 @@ ephy_bookmarks_popover_bookmark_tag_added_cb (EphyBookmarksPopover *self,
break;
}
}
- g_list_free (children);
if (!exists) {
- tag_row = create_tag_row (tag);
+ GtkWidget *tag_row = create_tag_row (tag);
gtk_container_add (GTK_CONTAINER (self->tags_list_box), tag_row);
}
}
@@ -133,12 +128,8 @@ ephy_bookmarks_popover_bookmark_tag_removed_cb (EphyBookmarksPopover *self,
const char *tag,
EphyBookmarksManager *manager)
{
- GtkWidget *row;
- GList *children;
- GList *l;
const char *visible_stack_child;
gboolean exists;
- gpointer title;
g_assert (EPHY_IS_BOOKMARK (bookmark));
g_assert (EPHY_IS_BOOKMARKS_POPOVER (self));
@@ -146,13 +137,15 @@ ephy_bookmarks_popover_bookmark_tag_removed_cb (EphyBookmarksPopover *self,
/* If the bookmark has 0 tags after removing one, we add it to the tags list
* box */
if (g_sequence_is_empty (ephy_bookmark_get_tags (bookmark))) {
+ GtkListBoxRow *row;
+ int i = 0;
+
exists = FALSE;
- children = gtk_container_get_children (GTK_CONTAINER (self->tags_list_box));
- for (l = children; l != NULL; l = l->next) {
- const char *type = g_object_get_data (l->data, "type");
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->tags_list_box), i++))) {
+ const char *type = g_object_get_data (G_OBJECT (row), "type");
if (g_strcmp0 (type, EPHY_LIST_BOX_ROW_TYPE_BOOKMARK) == 0) {
- const char *url = ephy_bookmark_row_get_bookmark_url (l->data);
+ const char *url = ephy_bookmark_row_get_bookmark_url (EPHY_BOOKMARK_ROW (row));
if (g_strcmp0 (ephy_bookmark_get_url (bookmark), url) == 0) {
exists = TRUE;
@@ -160,10 +153,9 @@ ephy_bookmarks_popover_bookmark_tag_removed_cb (EphyBookmarksPopover *self,
}
}
}
- g_list_free (children);
if (!exists) {
- row = create_bookmark_row (bookmark, self);
+ GtkWidget *row = create_bookmark_row (bookmark, self);
gtk_container_add (GTK_CONTAINER (self->tags_list_box), row);
}
}
@@ -173,8 +165,8 @@ ephy_bookmarks_popover_bookmark_tag_removed_cb (EphyBookmarksPopover *self,
visible_stack_child = gtk_stack_get_visible_child_name (GTK_STACK (self->toplevel_stack));
if (g_strcmp0 (visible_stack_child, "tag_detail") == 0 &&
g_strcmp0 (self->tag_detail_tag, tag) == 0) {
- remove_bookmark_row_from_container (GTK_CONTAINER (self->tag_detail_list_box),
- ephy_bookmark_get_url (bookmark));
+ remove_bookmark_row (GTK_LIST_BOX (self->tag_detail_list_box),
+ ephy_bookmark_get_url (bookmark));
/* If we removed the tag's last bookmark, switch back to the tags list. */
if (ephy_bookmarks_manager_has_bookmarks_with_tag (self->manager, tag)) {
@@ -189,13 +181,15 @@ ephy_bookmarks_popover_bookmark_tag_removed_cb (EphyBookmarksPopover *self,
/* If the tag no longer contains bookmarks, remove it from the tags list */
if (ephy_bookmarks_manager_has_bookmarks_with_tag (self->manager, tag)) {
- children = gtk_container_get_children (GTK_CONTAINER (self->tags_list_box));
- for (l = children; l != NULL; l = l->next) {
- title = g_object_get_data (G_OBJECT (l->data), "title");
+ GtkListBoxRow *row;
+ int i = 0;
+
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->tags_list_box), i++))) {
+ const char *title = g_object_get_data (G_OBJECT (row), "title");
+
if (g_strcmp0 (title, tag) == 0)
- gtk_container_remove (GTK_CONTAINER (self->tags_list_box), GTK_WIDGET (l->data));
+ gtk_container_remove (GTK_CONTAINER (self->tags_list_box), GTK_WIDGET (row));
}
- g_list_free (children);
}
}
@@ -284,10 +278,10 @@ ephy_bookmarks_popover_bookmark_removed_cb (EphyBookmarksPopover *self,
g_assert (EPHY_IS_BOOKMARK (bookmark));
g_assert (EPHY_IS_BOOKMARKS_MANAGER (manager));
- remove_bookmark_row_from_container (GTK_CONTAINER (self->tags_list_box),
- ephy_bookmark_get_url (bookmark));
- remove_bookmark_row_from_container (GTK_CONTAINER (self->tag_detail_list_box),
- ephy_bookmark_get_url (bookmark));
+ remove_bookmark_row (GTK_LIST_BOX (self->tags_list_box),
+ ephy_bookmark_get_url (bookmark));
+ remove_bookmark_row (GTK_LIST_BOX (self->tag_detail_list_box),
+ ephy_bookmark_get_url (bookmark));
if (g_list_model_get_n_items (G_LIST_MODEL (self->manager)) == 0) {
gtk_stack_set_visible_child_name (GTK_STACK (self->toplevel_stack), "empty-state");
@@ -380,17 +374,15 @@ ephy_bookmarks_popover_actions_tag_detail_back (GSimpleAction *action,
gpointer user_data)
{
EphyBookmarksPopover *self = user_data;
- GList *children;
+ GtkListBoxRow *row;
g_assert (EPHY_IS_BOOKMARKS_POPOVER (self));
gtk_stack_set_visible_child_name (GTK_STACK (self->toplevel_stack),
"default");
- children = gtk_container_get_children (GTK_CONTAINER (self->tag_detail_list_box));
- for (GList *l = children; l != NULL; l = l->next)
- gtk_container_remove (GTK_CONTAINER (self->tag_detail_list_box), l->data);
- g_list_free (children);
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->tag_detail_list_box), 0)))
+ gtk_container_remove (GTK_CONTAINER (self->tag_detail_list_box), GTK_WIDGET (row));
}
static void
diff --git a/src/ephy-encoding-dialog.c b/src/ephy-encoding-dialog.c
index 862d13aed..e305bb14e 100644
--- a/src/ephy-encoding-dialog.c
+++ b/src/ephy-encoding-dialog.c
@@ -77,30 +77,29 @@ select_encoding_row (GtkListBox *list_box,
EphyEncoding *encoding)
{
const char *target_encoding;
- GList *rows, *r;
+ GtkListBoxRow *row;
+ int i = 0;
target_encoding = ephy_encoding_get_encoding (encoding);
- rows = gtk_container_get_children (GTK_CONTAINER (list_box));
- for (r = rows; r != NULL; r = r->next) {
+ while ((row = gtk_list_box_get_row_at_index (list_box, i++))) {
EphyEncodingRow *ephy_encoding_row;
EphyEncoding *ephy_encoding;
const char *encoding_string = NULL;
- ephy_encoding_row = EPHY_ENCODING_ROW (gtk_bin_get_child (GTK_BIN (r->data)));
+ ephy_encoding_row = EPHY_ENCODING_ROW (gtk_bin_get_child (GTK_BIN (row)));
ephy_encoding = ephy_encoding_row_get_encoding (ephy_encoding_row);
encoding_string = ephy_encoding_get_encoding (ephy_encoding);
if (g_strcmp0 (encoding_string, target_encoding) == 0) {
ephy_encoding_row_set_selected (ephy_encoding_row, TRUE);
- gtk_list_box_select_row (list_box, GTK_LIST_BOX_ROW (r->data));
+ gtk_list_box_select_row (list_box, row);
/* TODO scroll to row */
break;
}
}
- g_list_free (rows);
}
static void
@@ -220,22 +219,17 @@ ephy_encoding_dialog_response_cb (GtkWidget *widget,
gtk_widget_destroy (GTK_WIDGET (dialog));
}
-static void
-clean_selected_row (gpointer row,
- gpointer null_pointer)
-{
- EphyEncodingRow *ephy_encoding_row;
- ephy_encoding_row = EPHY_ENCODING_ROW (gtk_bin_get_child (GTK_BIN (row)));
- ephy_encoding_row_set_selected (ephy_encoding_row, FALSE);
-}
-
static void
clean_selected_list_box (GtkListBox *list_box)
{
- GList *rows;
- rows = gtk_container_get_children (GTK_CONTAINER (list_box));
- g_list_foreach (rows, (GFunc)clean_selected_row, NULL);
- g_list_free (rows);
+ GtkListBoxRow *row;
+ int i = 0;
+
+ while ((row = gtk_list_box_get_row_at_index (list_box, i++))) {
+ EphyEncodingRow *ephy_encoding_row =
+ EPHY_ENCODING_ROW (gtk_bin_get_child (GTK_BIN (row)));
+ ephy_encoding_row_set_selected (ephy_encoding_row, FALSE);
+ }
}
static void
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index 201908c70..64bf10e76 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -195,15 +195,14 @@ static void
set_selection_active (EphyHistoryDialog *self,
gboolean selection_active)
{
- g_autoptr (GList) rows = gtk_container_get_children (GTK_CONTAINER (self->listbox));
- GList *iter = NULL;
+ GtkListBoxRow *row;
+ int i = 0;
self->selection_active = selection_active;
- for (iter = rows; iter != NULL; iter = g_list_next (iter)) {
- GObject *row = iter->data;
- GtkWidget *check_button = GTK_WIDGET (g_object_get_data (row, "check-button"));
- GtkWidget *separator = GTK_WIDGET (g_object_get_data (row, "separator"));
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->listbox), i++))) {
+ GtkWidget *check_button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "check-button"));
+ GtkWidget *separator = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "separator"));
/* Uncheck all rows when toggling selection mode */
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), FALSE);
@@ -254,15 +253,10 @@ get_url_from_row (GtkListBoxRow *row)
static void
clear_listbox (GtkWidget *listbox)
{
- GList *children, *iter;
-
- children = gtk_container_get_children (GTK_CONTAINER (listbox));
-
- for (iter = children; iter; iter = g_list_next (iter)) {
- gtk_widget_destroy (GTK_WIDGET (iter->data));
- }
+ GtkListBoxRow *row;
- g_list_free (children);
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (listbox), 0)))
+ gtk_container_remove (GTK_CONTAINER (listbox), GTK_WIDGET (row));
}
static void
@@ -345,13 +339,13 @@ filter_now (EphyHistoryDialog *self)
static GList *
get_checked_rows (EphyHistoryDialog *self)
{
- g_autoptr (GList) rows_list = gtk_container_get_children (GTK_CONTAINER (self->listbox));
GList *checked_rows = NULL;
- GList *iter = NULL;
+ GtkListBoxRow *row;
+ int i = 0;
- for (iter = rows_list; iter != NULL; iter = g_list_next (iter)) {
- GObject *row = iter->data;
- GtkCheckButton *check_button = GTK_CHECK_BUTTON (g_object_get_data (row, "check-button"));
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->listbox), i++))) {
+ GtkCheckButton *check_button =
+ GTK_CHECK_BUTTON (g_object_get_data (G_OBJECT (row), "check-button"));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button)))
checked_rows = g_list_prepend (checked_rows, row);
@@ -489,15 +483,14 @@ add_urls_source (EphyHistoryDialog *self)
EphyHistoryURL *url;
GList *element;
GtkWidget *row;
- GList *children;
+ gboolean has_results;
set_is_loading (self, FALSE);
- children = gtk_container_get_children (GTK_CONTAINER (self->listbox));
- set_has_search_results (self, !!children);
- if (!children)
+ has_results = !!gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->listbox), 0);
+ set_has_search_results (self, has_results);
+ if (!has_results)
set_has_data (self, FALSE);
- g_list_free (children);
if (!self->urls || !self->num_fetch) {
self->sorter_source = 0;
@@ -630,7 +623,7 @@ on_key_press_event (EphyHistoryDialog *self,
if (focus == last) {
load_further_data (self);
- return GDK_EVENT_STOP;
+ return GDK_EVENT_PROPAGATE;
}
}
@@ -729,12 +722,12 @@ handle_selection_row_activated_event (EphyHistoryDialog *self,
} else {
/* If there are zero or more than one other rows checked,
* then we check the clicked row and uncheck all the others */
- g_autoptr (GList) rows = gtk_container_get_children (GTK_CONTAINER (self->listbox));
- GList *iter = NULL;
+ GtkListBoxRow *row;
+ int i = 0;
- for (iter = rows; iter != NULL; iter = g_list_next (iter)) {
- GObject *row = iter->data;
- GtkCheckButton *row_check_btn = GTK_CHECK_BUTTON (g_object_get_data (row, "check-button"));
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->listbox), i++))) {
+ GtkCheckButton *row_check_btn =
+ GTK_CHECK_BUTTON (g_object_get_data (G_OBJECT (row), "check-button"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (row_check_btn), FALSE);
}
diff --git a/src/ephy-web-extension-dialog.c b/src/ephy-web-extension-dialog.c
index b8255f2e5..d0344c950 100644
--- a/src/ephy-web-extension-dialog.c
+++ b/src/ephy-web-extension-dialog.c
@@ -42,14 +42,10 @@ G_DEFINE_TYPE (EphyWebExtensionDialog, ephy_web_extension_dialog, HDY_TYPE_WINDO
static void
clear_listbox (GtkWidget *listbox)
{
- GList *children, *iter;
-
- children = gtk_container_get_children (GTK_CONTAINER (listbox));
-
- for (iter = children; iter && iter->data; iter = g_list_next (iter))
- gtk_widget_destroy (GTK_WIDGET (iter->data));
+ GtkListBoxRow *row;
- g_list_free (children);
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (listbox), 0)))
+ gtk_container_remove (GTK_CONTAINER (listbox), GTK_WIDGET (row));
}
static void
diff --git a/src/preferences/ephy-search-engine-listbox.c b/src/preferences/ephy-search-engine-listbox.c
index 111546185..32a81b3be 100644
--- a/src/preferences/ephy-search-engine-listbox.c
+++ b/src/preferences/ephy-search-engine-listbox.c
@@ -253,26 +253,25 @@ on_list_box_manager_items_changed_cb (GListModel *list,
static void
on_row_expand_state_changed_cb (EphySearchEngineRow *expanded_row,
GParamSpec *pspec,
- EphySearchEngineListBox *parent_list_box)
+ EphySearchEngineListBox *self)
{
- g_autoptr (GList) children = gtk_container_get_children (GTK_CONTAINER (parent_list_box));
+ GtkListBoxRow *row;
+ int i = 0;
/* We only unexpand other rows if this is a notify signal for an expanded row. */
if (!hdy_expander_row_get_expanded (HDY_EXPANDER_ROW (expanded_row)))
return;
- for (; children->next != NULL; children = children->next) {
- EphySearchEngineRow *iterated_row = children->data;
-
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self), i++))) {
/* Ignore this row if not a search engine row ("add search engine" row). */
- if (!EPHY_IS_SEARCH_ENGINE_ROW (iterated_row))
+ if (!EPHY_IS_SEARCH_ENGINE_ROW (row))
continue;
/* Ignore the row that was just expanded. */
- if (iterated_row == expanded_row)
+ if (row == GTK_LIST_BOX_ROW (expanded_row))
continue;
- hdy_expander_row_set_expanded (HDY_EXPANDER_ROW (iterated_row), FALSE);
+ hdy_expander_row_set_expanded (HDY_EXPANDER_ROW (row), FALSE);
}
}
diff --git a/src/preferences/passwords-view.c b/src/preferences/passwords-view.c
index f4969f7d6..cd19acf7a 100644
--- a/src/preferences/passwords-view.c
+++ b/src/preferences/passwords-view.c
@@ -67,15 +67,10 @@ ephy_passwords_view_dispose (GObject *object)
static void
clear_listbox (GtkWidget *listbox)
{
- GList *children, *iter;
+ GtkListBoxRow *row;
- children = gtk_container_get_children (GTK_CONTAINER (listbox));
-
- for (iter = children; iter; iter = g_list_next (iter)) {
- gtk_widget_destroy (GTK_WIDGET (iter->data));
- }
-
- g_list_free (children);
+ while ((row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (listbox), 0)))
+ gtk_container_remove (GTK_CONTAINER (listbox), GTK_WIDGET (row));
}
static void
diff --git a/src/preferences/prefs-general-page.c b/src/preferences/prefs-general-page.c
index 286651358..0613796a1 100644
--- a/src/preferences/prefs-general-page.c
+++ b/src/preferences/prefs-general-page.c
@@ -115,9 +115,11 @@ prefs_general_page_finalize (GObject *object)
static int
get_list_box_length (GtkListBox *list_box)
{
- g_autoptr (GList) children = gtk_container_get_children (GTK_CONTAINER (list_box));
+ int i = -1;
- return g_list_length (children);
+ while (gtk_list_box_get_row_at_index (list_box, ++i));
+
+ return i;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]