changeset 16133:019092f88c43

Pull out the same block of code from two places and put it into a static function
author Mark Doliner <mark@kingant.net>
date Sun, 15 Apr 2007 18:02:11 +0000
parents 9699941af4c4
children 813258bec80c
files pidgin/gtkthemes.c
diffstat 1 files changed, 32 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkthemes.c	Sun Apr 15 17:47:45 2007 +0000
+++ b/pidgin/gtkthemes.c	Sun Apr 15 18:02:11 2007 +0000
@@ -63,6 +63,35 @@
 	}
 }
 
+static void
+pidginthemes_destroy_smiley_theme(struct smiley_theme *theme)
+{
+	GSList *already_freed = NULL;
+	struct smiley_list *wer = theme->list, *wer2;
+
+	while (wer) {
+		while (wer->smileys) {
+			GtkIMHtmlSmiley *uio = wer->smileys->data;
+			if (uio->icon)
+				g_object_unref(uio->icon);
+			if (!g_slist_find(already_freed, uio->file)) {
+				g_free(uio->file);
+				already_freed = g_slist_append(already_freed, uio->file);
+			}
+			g_free(uio->smile);
+			g_free(uio);
+			wer->smileys = g_slist_remove(wer->smileys, uio);
+		}
+		wer2 = wer->next;
+		g_free(wer->sml);
+		g_free(wer);
+		wer = wer2;
+	}
+
+	g_slist_free(already_freed);
+	theme->list = NULL;
+}
+
 void pidginthemes_load_smiley_theme(const char *file, gboolean load)
 {
 	FILE *f = g_fopen(file, "r");
@@ -180,31 +209,9 @@
 	fclose(f);
 
 	if (!theme->name || !theme->desc || !theme->author) {
-		GSList *already_freed = NULL;
-		struct smiley_list *wer = theme->list, *wer2;
-
 		purple_debug_error("gtkthemes", "Invalid file format, not loading smiley theme from '%s'\n", file);
 
-		while (wer) {
-			while (wer->smileys) {
-				GtkIMHtmlSmiley *uio = wer->smileys->data;
-				if (uio->icon)
-					g_object_unref(uio->icon);
-				if (!g_slist_find(already_freed, uio->file)) {
-					g_free(uio->file);
-					already_freed = g_slist_append(already_freed, uio->file);
-				}
-				g_free(uio->smile);
-				g_free(uio);
-				wer->smileys = g_slist_remove(wer->smileys, uio);
-			}
-			wer2 = wer->next;
-			g_free(wer->sml);
-			g_free(wer);
-			wer = wer2;
-		}
-		theme->list = NULL;
-		g_slist_free(already_freed);
+		pidginthemes_destroy_smiley_theme(theme);
 
 		g_free(theme->name);
 		g_free(theme->desc);
@@ -223,30 +230,8 @@
 	if (load) {
 		GList *cnv;
 
-		if (current_smiley_theme) {
-			GSList *already_freed = NULL;
-			struct smiley_list *wer = current_smiley_theme->list, *wer2;
-			while (wer) {
-				while (wer->smileys) {
-					GtkIMHtmlSmiley *uio = wer->smileys->data;
-					if (uio->icon)
-						g_object_unref(uio->icon);
-					if (!g_slist_find(already_freed, uio->file)) {
-						g_free(uio->file);
-						already_freed = g_slist_append(already_freed, uio->file);
-					}
-					g_free(uio->smile);
-					g_free(uio);
-					wer->smileys = g_slist_remove(wer->smileys, uio);
-				}
-				wer2 = wer->next;
-				g_free(wer->sml);
-				g_free(wer);
-				wer = wer2;
-			}
-			current_smiley_theme->list = NULL;
-			g_slist_free(already_freed);
-		}
+		if (current_smiley_theme)
+			pidginthemes_destroy_smiley_theme(current_smiley_theme);
 		current_smiley_theme = theme;
 
 		for (cnv = purple_get_conversations(); cnv != NULL; cnv = cnv->next) {