[gnome-software] Add a gs_container_remove_all utility
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add a gs_container_remove_all utility
- Date: Fri, 30 Aug 2013 03:22:32 +0000 (UTC)
commit 05b8730ca5ddd0efdb92cba9892f7e7658fdcc93
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Aug 29 23:22:01 2013 -0400
Add a gs_container_remove_all utility
This code was duplicated in almost all shell files.
src/gs-shell-category.c | 13 ++-----------
src/gs-shell-installed.c | 23 +----------------------
src/gs-shell-search.c | 23 +----------------------
src/gs-shell-updates.c | 23 +----------------------
src/gs-utils.c | 13 +++++++++++++
src/gs-utils.h | 1 +
6 files changed, 19 insertions(+), 77 deletions(-)
---
diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c
index 8c7c1a3..2842ce9 100644
--- a/src/gs-shell-category.c
+++ b/src/gs-shell-category.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <glib/gi18n.h>
+#include "gs-utils.h"
#include "gs-shell-category.h"
static void gs_shell_category_finalize (GObject *object);
@@ -53,16 +54,6 @@ gs_shell_category_refresh (GsShellCategory *shell)
}
static void
-container_remove_all (GtkContainer *container)
-{
- GList *children, *l;
- children = gtk_container_get_children (container);
- for (l = children; l; l = l->next)
- gtk_container_remove (container, GTK_WIDGET (l->data));
- g_list_free (children);
-}
-
-static void
app_tile_clicked (GtkButton *button, gpointer data)
{
GsShellCategory *shell = GS_SHELL_CATEGORY (data);
@@ -235,7 +226,7 @@ gs_shell_category_set_category (GsShellCategory *shell, GsCategory *category)
g_object_ref (priv->category);
grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "category_detail_grid"));
- container_remove_all (GTK_CONTAINER (grid));
+ gs_container_remove_all (GTK_CONTAINER (grid));
subcategory = create_filter_list (shell, category);
gs_shell_category_populate_filtered (shell, subcategory);
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index b471522..e96a4df 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -58,27 +58,6 @@ gs_shell_installed_invalidate (GsShellInstalled *shell_installed)
shell_installed->priv->cache_valid = FALSE;
}
-/**
- * _gtk_container_remove_all_cb:
- **/
-static void
-_gtk_container_remove_all_cb (GtkWidget *widget, gpointer user_data)
-{
- GtkContainer *container = GTK_CONTAINER (user_data);
- gtk_container_remove (container, widget);
-}
-
-/**
- * _gtk_container_remove_all:
- **/
-static void
-_gtk_container_remove_all (GtkContainer *container)
-{
- gtk_container_foreach (container,
- _gtk_container_remove_all_cb,
- container);
-}
-
static void
gs_shell_installed_app_widget_activated_cb (GtkListBox *list_box,
GtkListBoxRow *row,
@@ -365,7 +344,7 @@ gs_shell_installed_refresh (GsShellInstalled *shell_installed)
return;
/* remove old entries */
- _gtk_container_remove_all (GTK_CONTAINER (priv->list_box_installed));
+ gs_container_remove_all (GTK_CONTAINER (priv->list_box_installed));
/* get popular apps */
gs_plugin_loader_get_installed_async (priv->plugin_loader,
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 0005a7c..e68aa9d 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -46,27 +46,6 @@ struct GsShellSearchPrivate
G_DEFINE_TYPE (GsShellSearch, gs_shell_search, G_TYPE_OBJECT)
-/**
- * _gtk_container_remove_all_cb:
- **/
-static void
-_gtk_container_remove_all_cb (GtkWidget *widget, gpointer user_data)
-{
- GtkContainer *container = GTK_CONTAINER (user_data);
- gtk_container_remove (container, widget);
-}
-
-/**
- * _gtk_container_remove_all:
- **/
-static void
-_gtk_container_remove_all (GtkContainer *container)
-{
- gtk_container_foreach (container,
- _gtk_container_remove_all_cb,
- container);
-}
-
static void
gs_shell_search_app_widget_activated_cb (GtkListBox *list_box,
GtkListBoxRow *row,
@@ -293,7 +272,7 @@ gs_shell_search_refresh (GsShellSearch *shell_search, const gchar *value)
return;
/* remove old entries */
- _gtk_container_remove_all (GTK_CONTAINER (priv->list_box_search));
+ gs_container_remove_all (GTK_CONTAINER (priv->list_box_search));
/* search for apps */
gs_plugin_loader_search_async (priv->plugin_loader,
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 5f3b11c..3dffa2c 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -64,27 +64,6 @@ gs_shell_updates_invalidate (GsShellUpdates *shell_updates)
}
/**
- * _gtk_container_remove_all_cb:
- **/
-static void
-_gtk_container_remove_all_cb (GtkWidget *widget, gpointer user_data)
-{
- GtkContainer *container = GTK_CONTAINER (user_data);
- gtk_container_remove (container, widget);
-}
-
-/**
- * _gtk_container_remove_all:
- **/
-static void
-_gtk_container_remove_all (GtkContainer *container)
-{
- gtk_container_foreach (container,
- _gtk_container_remove_all_cb,
- container);
-}
-
-/**
* gs_shell_updates_get_updates_cb:
**/
static void
@@ -183,7 +162,7 @@ gs_shell_updates_refresh (GsShellUpdates *shell_updates)
if (priv->waiting)
return;
- _gtk_container_remove_all (GTK_CONTAINER (priv->list_box_updates));
+ gs_container_remove_all (GTK_CONTAINER (priv->list_box_updates));
gs_plugin_loader_get_updates_async (priv->plugin_loader,
priv->cancellable,
diff --git a/src/gs-utils.c b/src/gs-utils.c
index f6943a6..613ea7a 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -82,3 +82,16 @@ gs_start_spinner (GtkSpinner *spinner)
GUINT_TO_POINTER (id), remove_source);
}
+static void
+remove_all_cb (GtkWidget *widget, gpointer user_data)
+{
+ GtkContainer *container = GTK_CONTAINER (user_data);
+ gtk_container_remove (container, widget);
+}
+
+void
+gs_container_remove_all (GtkContainer *container)
+{
+ gtk_container_foreach (container, remove_all_cb, container);
+}
+
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 33ac881..0ebf5a1 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
void gs_start_spinner (GtkSpinner *spinner);
void gs_stop_spinner (GtkSpinner *spinner);
+void gs_container_remove_all (GtkContainer *container);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]