changeset 4288:a723d060620a

[gaim-migrate @ 4541] Here. Now you can like have lots of themes and like make your own and like switch them and stuff. It's kidna neat, I suppose. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 11 Jan 2003 04:48:10 +0000
parents f98e27e2cb10
children 971684503905
files pixmaps/smileys/default/theme src/aim.c src/gaimrc.c src/gtkimhtml.c src/prefs.c src/themes.c src/ui.h
diffstat 7 files changed, 166 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/pixmaps/smileys/default/theme	Sat Jan 11 00:38:22 2003 +0000
+++ b/pixmaps/smileys/default/theme	Sat Jan 11 04:48:10 2003 +0000
@@ -1,7 +1,7 @@
 Name=Default
 Description=Emoticons from each protocol's official client.
 Icon=smile.png
-Author=
+Author=Penguin Pimps
 
 [default]
 ! luke.png          	C:-) C:)
--- a/src/aim.c	Sat Jan 11 00:38:22 2003 +0000
+++ b/src/aim.c	Sat Jan 11 04:48:10 2003 +0000
@@ -491,6 +491,8 @@
 	GdkPixbuf *icon = NULL;
 
 	smiley_theme_probe();
+	if (current_smiley_theme == NULL && smiley_themes)
+		load_smiley_theme(smiley_themes->data);
 
 	/* use the nice PNG icon for all the windows */
 	icon = gdk_pixbuf_new_from_file(DATADIR G_DIR_SEPARATOR_S "pixmaps" G_DIR_SEPARATOR_S "gaim.png",NULL);
--- a/src/gaimrc.c	Sat Jan 11 00:38:22 2003 +0000
+++ b/src/gaimrc.c	Sat Jan 11 04:48:10 2003 +0000
@@ -807,6 +807,8 @@
 			web_browser = atoi(p->value[0]);
 		} else if (!strcmp(p->option, "web_command")) {
 			strcpy(web_command, p->value[0]);
+		} else if (!strcmp(p->option, "smiley_theme")) {
+			load_smiley_theme(p->value[0], TRUE);
 		} else if (!strcmp(p->option, "conv_size")) {
 			conv_size.width = atoi(p->value[0]);
 			conv_size.height = atoi(p->value[1]);
@@ -904,6 +906,8 @@
 	fprintf(f, "\treport_idle { %d }\n", report_idle);
 	fprintf(f, "\tweb_browser { %d }\n", web_browser);
 	fprintf(f, "\tweb_command { %s }\n", web_command);
+	if (current_smiley_theme)
+		fprintf(f, "\tsmiley_theme { %s }\n", current_smiley_theme->path);
 	fprintf(f, "\tblist_pos { %d } { %d } { %d } { %d }\n",
 		blist_pos.x, blist_pos.y, blist_pos.width, blist_pos.height);
 	fprintf(f, "\tconv_size { %d } { %d } { %d }\n",
--- a/src/gtkimhtml.c	Sat Jan 11 00:38:22 2003 +0000
+++ b/src/gtkimhtml.c	Sat Jan 11 04:48:10 2003 +0000
@@ -1015,7 +1015,13 @@
 void       gtk_imhtml_set_img_handler  (GtkIMHtml        *imhtml,
 	GtkIMHtmlImage    handler){}
 
-void       gtk_imhtml_remove_smileys   (GtkIMHtml        *imhtml){}
+void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) 
+{ 
+	g_hash_table_destroy(imhtml->smiley_data);
+	gtk_smiley_tree_destroy(imhtml->default_smilies);
+	imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal);
+	imhtml->default_smilies = gtk_smiley_tree_new();
+}
 void       gtk_imhtml_show_smileys     (GtkIMHtml        *imhtml,
 					gboolean          show)
 {
--- a/src/prefs.c	Sat Jan 11 00:38:22 2003 +0000
+++ b/src/prefs.c	Sat Jan 11 04:48:10 2003 +0000
@@ -198,6 +198,99 @@
 	return ret;
 }
 
+static void smiley_sel (GtkTreeSelection *sel, GtkTreeModel *model) {
+	GtkTreeIter  iter;
+	char *filename;
+	GValue val = { 0, };
+	
+	if (! gtk_tree_selection_get_selected (sel, &model, &iter))
+		return;
+	gtk_tree_model_get_value (model, &iter, 2, &val);
+	filename = g_value_get_string(&val);
+	load_smiley_theme(filename, TRUE);
+	g_value_unset (&val);
+}
+
+GtkWidget *theme_page() {
+	GtkWidget *ret;
+	GtkWidget *sw;
+	GSList *themes = smiley_themes;
+	GtkTreeIter iter;
+	GtkWidget *view;
+	GtkListStore *ls;
+	GtkCellRenderer *rend;
+	GtkTreeViewColumn *col;
+	GtkTreeSelection *sel;
+	GtkTreePath *path;
+	GtkListStore *store;
+	GdkPixbuf *pixbuf;
+	int ind =0;
+
+	ret = gtk_vbox_new(FALSE, 18);
+	gtk_container_set_border_width (GTK_CONTAINER (ret), 12);
+
+	sw = gtk_scrolled_window_new(NULL,NULL);
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
+
+	gtk_box_pack_start(GTK_BOX(ret), sw, TRUE, TRUE, 0);
+	store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
+	while (themes) {
+		struct smiley_theme *theme = themes->data;
+		char *description = g_strdup_printf("<span size='larger' weight='bold'>%s</span> - %s\n"
+						    "<span size='smaller' foreground='gray'>%s</span>",
+						    theme->name, theme->author, theme->desc);; 
+		gtk_list_store_append (store, &iter);
+		pixbuf = gdk_pixbuf_new_from_file(theme->icon, NULL);
+		
+		gtk_list_store_set(store, &iter,
+				   0, pixbuf,
+				   1, description,
+				   2, theme->path,
+				   -1);
+		g_free(description);
+		themes = themes->next;
+		if (current_smiley_theme && !strcmp(theme->path, current_smiley_theme->path)) {
+			/* path = gtk_tree_path_new_from_indices(ind); */
+			char *iwishihadgtk2_2 = g_strdup_printf("%d", ind);
+			path = gtk_tree_path_new_from_string(iwishihadgtk2_2);
+			g_free(iwishihadgtk2_2);
+		}
+		ind++;
+	}
+	
+	view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store));
+	
+	rend = gtk_cell_renderer_pixbuf_new();
+	sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+	
+	gtk_tree_selection_select_path(sel, path);
+	gtk_tree_path_free(path);
+
+	col = gtk_tree_view_column_new_with_attributes ("Icon",
+							rend,
+							"pixbuf", 0,
+							NULL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW(view), col);
+
+	rend = gtk_cell_renderer_text_new();
+	col = gtk_tree_view_column_new_with_attributes ("Description",
+							rend,
+							"markup", 1,
+							NULL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW(view), col);
+	g_object_unref(G_OBJECT(store));
+	gtk_container_add(GTK_CONTAINER(sw), view);
+
+	g_signal_connect (G_OBJECT (sel), "changed",
+			  G_CALLBACK (smiley_sel),
+			  NULL);
+
+
+	gtk_widget_show_all(ret);
+	return ret;
+}
+
 GtkWidget *font_page() {
 	GtkWidget *ret;
 	GtkWidget *button;
@@ -1400,6 +1493,7 @@
 	struct gaim_plugin *plug;
 #endif
 	prefs_notebook_add_page(_("Interface"), NULL, interface_page(), &p, NULL, notebook_page++);
+	prefs_notebook_add_page(_("Themes"), NULL, theme_page(), &c, &p, notebook_page++);
 	prefs_notebook_add_page(_("Fonts"), NULL, font_page(), &c, &p, notebook_page++);
 	prefs_notebook_add_page(_("Message Text"), NULL, messages_page(), &c, &p, notebook_page++);
 	prefs_notebook_add_page(_("Shortcuts"), NULL, hotkeys_page(), &c, &p, notebook_page++);
--- a/src/themes.c	Sat Jan 11 00:38:22 2003 +0000
+++ b/src/themes.c	Sat Jan 11 04:48:10 2003 +0000
@@ -19,6 +19,8 @@
  *
  */
 
+#include "gaim.h"
+#include "ui.h"
 #include "gtkimhtml.h"
 #include <stdio.h>
 
@@ -28,18 +30,8 @@
 	struct smiley_list *next;
 };
 
-struct smiley_theme {
-	char *path;
-	char *name;
-	char *desc;
-	char *icon;
-	char *author;
-	
-	struct smiley_list *list;
-};
-
 GSList *smiley_themes;
-static struct smiley_theme *current_smiley_theme;
+struct smiley_theme *current_smiley_theme;
 
 void smiley_themeize(GtkWidget *imhtml)
 {
@@ -47,8 +39,6 @@
 	if (!current_smiley_theme)
 		return;
 	
-	
-
 	gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml));
 	list = current_smiley_theme->list;
 	while (list) {
@@ -75,7 +65,7 @@
 	
 	while (lst) {
 		struct smiley_theme *thm = lst->data;
-		if (!g_strcasecmp(thm->path, file)) {
+		if (!strcmp(thm->path, file)) {
 			theme = thm;
 			break;
 		}
@@ -83,7 +73,7 @@
 	}
 	if (!theme) {
 		theme = g_new0(struct smiley_theme, 1);
-		theme->path = file;
+		theme->path = g_strdup(file);
 	}
 	if (!f)
 		return NULL;
@@ -91,29 +81,35 @@
 	dirname = g_path_get_dirname(file);
 	if (load) {
 		if (current_smiley_theme) {
+			GSList *already_freed = NULL;
 			struct smiley_list *wer = current_smiley_theme->list;
 			while (wer) {
 				char *nds = !strcmp(wer->sml, "default") ? NULL : wer->sml;
-				GSList *dfg = wer->smileys;
-				while (dfg) {
-					GtkIMHtmlSmiley *uio = dfg->data;
+				GSList *already_freed = NULL;
+				while (wer->smileys) {
+					GtkIMHtmlSmiley *uio = wer->smileys->data;
 					if (uio->icon)
 						g_object_unref(uio->icon);
-					g_free(uio->file);
+					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);
-					dfg = dfg->next;
+					g_free(uio);
+					wer->smileys=g_slist_remove(wer->smileys, uio);
 				}
 				wer = wer->next;
 			}
+			current_smiley_theme->list = NULL;
+			g_slist_free(already_freed);
 		}
-	current_smiley_theme = theme;
+		current_smiley_theme = theme;
 	}
 	
 	
 	while (!feof(f)) {
 		if (!fgets(buf, sizeof(buf), f)) {
-			g_free(dirname);
-			return NULL;
+			break;
 		}
 				
 		if (buf[0] == '#' || buf[0] == '\0') 
@@ -133,15 +129,19 @@
 			list = child;
 		} else if (!g_strncasecmp(i, "Name=", strlen("Name="))) {
 			theme->name = g_strdup(i+ strlen("Name="));
+			theme->name[strlen(theme->name)-1] = 0;
 		} else if (!g_strncasecmp(i, "Description=", strlen("Description="))) {
 			theme->desc = g_strdup(i + strlen("Description="));
+			theme->desc[strlen(theme->desc)-1] = 0;
 		} else if (!g_strncasecmp(i, "Icon=", strlen("Icon="))) {
 			theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL);
-		} else if (!g_strncasecmp(i, "Author=", strlen("Author"))) {
-			theme->desc = g_strdup(i + strlen("Author"));
+			theme->icon[strlen(theme->icon)-1] = 0;
+		} else if (!g_strncasecmp(i, "Author=", strlen("Author="))) {
+			theme->author = g_strdup(i + strlen("Author="));
+			theme->author[strlen(theme->author)-1] = 0;
 		} else if (load && list) {
 			gboolean hidden;
-			char *file = NULL;
+			char *sfile = NULL;
 			GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1);
 			
 			if (*i == '!' && *(i + 1) == ' ') {
@@ -153,21 +153,32 @@
 				int li = 0;
 				while (!isspace(*i)) 
 					l[li++] = *(i++);
-				if (!file) {
+				if (!sfile) {
 					l[li] = 0;
-					file = g_build_filename(dirname, l, NULL);
+					sfile = g_build_filename(dirname, l, NULL);
 				} else {
 					l[li] = 0;
 					smiley = g_new0(GtkIMHtmlSmiley, 1);
-					smiley->file = file;
+					smiley->file = sfile;
 					smiley->smile = g_strdup(l);
 					list->smileys = g_slist_append(list->smileys, smiley);
 				}
-				while (isspace(*i))
+				while (isspace(*i)) 
 					i++;
+				
 			}
 		}
 	}
+
+	if (load) {
+		GList *cnv = conversations;
+		while (cnv) {
+			struct conversation *c = cnv->data;
+			smiley_themeize(c->text);
+			cnv=cnv->next;
+		}
+	}
+
 	g_free(dirname);
 	return theme;
 }
@@ -194,7 +205,7 @@
 				 * We set the second argument to FALSE so that it doesn't load
 				 * the theme yet.
 				 */
-				if (smile = load_smiley_theme(path, TRUE)) {
+				if (smile = load_smiley_theme(path, FALSE)) {
 					smiley_themes = g_slist_append(smiley_themes, smile);
 				}
 				g_free(path);
--- a/src/ui.h	Sat Jan 11 00:38:22 2003 +0000
+++ b/src/ui.h	Sat Jan 11 04:48:10 2003 +0000
@@ -266,6 +266,17 @@
 	GtkWidget *register_user;
 };
 
+struct smiley_theme {
+	char *path;
+	char *name;
+	char *desc;
+	char *icon;
+	char *author;
+	
+	struct smiley_list *list;
+};
+
+
 #define EDIT_GC    0
 #define EDIT_GROUP 1
 #define EDIT_BUDDY 2
@@ -320,6 +331,11 @@
 /* Globals in sound.c */
 extern gboolean mute_sounds;
 
+/* Globals in themes.c */
+extern struct smiley_theme *current_smiley_theme;
+extern GSList *smiley_themes;
+
+
 /* Functions in about.c */
 extern void show_about(GtkWidget *, void *);
 extern void gaim_help(GtkWidget *, void *);