comparison src/themes.c @ 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 9ccb6c521cb2
children cddb50734169
comparison
equal deleted inserted replaced
4287:f98e27e2cb10 4288:a723d060620a
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 */ 20 */
21 21
22 #include "gaim.h"
23 #include "ui.h"
22 #include "gtkimhtml.h" 24 #include "gtkimhtml.h"
23 #include <stdio.h> 25 #include <stdio.h>
24 26
25 struct smiley_list { 27 struct smiley_list {
26 char *sml; 28 char *sml;
27 GSList *smileys; 29 GSList *smileys;
28 struct smiley_list *next; 30 struct smiley_list *next;
29 }; 31 };
30 32
31 struct smiley_theme {
32 char *path;
33 char *name;
34 char *desc;
35 char *icon;
36 char *author;
37
38 struct smiley_list *list;
39 };
40
41 GSList *smiley_themes; 33 GSList *smiley_themes;
42 static struct smiley_theme *current_smiley_theme; 34 struct smiley_theme *current_smiley_theme;
43 35
44 void smiley_themeize(GtkWidget *imhtml) 36 void smiley_themeize(GtkWidget *imhtml)
45 { 37 {
46 struct smiley_list *list; 38 struct smiley_list *list;
47 if (!current_smiley_theme) 39 if (!current_smiley_theme)
48 return; 40 return;
49 41
50
51
52 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml)); 42 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml));
53 list = current_smiley_theme->list; 43 list = current_smiley_theme->list;
54 while (list) { 44 while (list) {
55 char *sml = !strcmp(list->sml, "default") ? NULL : list->sml; 45 char *sml = !strcmp(list->sml, "default") ? NULL : list->sml;
56 GSList *icons = list->smileys; 46 GSList *icons = list->smileys;
73 GSList *lst = smiley_themes; 63 GSList *lst = smiley_themes;
74 char *dirname; 64 char *dirname;
75 65
76 while (lst) { 66 while (lst) {
77 struct smiley_theme *thm = lst->data; 67 struct smiley_theme *thm = lst->data;
78 if (!g_strcasecmp(thm->path, file)) { 68 if (!strcmp(thm->path, file)) {
79 theme = thm; 69 theme = thm;
80 break; 70 break;
81 } 71 }
82 lst = lst->next; 72 lst = lst->next;
83 } 73 }
84 if (!theme) { 74 if (!theme) {
85 theme = g_new0(struct smiley_theme, 1); 75 theme = g_new0(struct smiley_theme, 1);
86 theme->path = file; 76 theme->path = g_strdup(file);
87 } 77 }
88 if (!f) 78 if (!f)
89 return NULL; 79 return NULL;
90 80
91 dirname = g_path_get_dirname(file); 81 dirname = g_path_get_dirname(file);
92 if (load) { 82 if (load) {
93 if (current_smiley_theme) { 83 if (current_smiley_theme) {
84 GSList *already_freed = NULL;
94 struct smiley_list *wer = current_smiley_theme->list; 85 struct smiley_list *wer = current_smiley_theme->list;
95 while (wer) { 86 while (wer) {
96 char *nds = !strcmp(wer->sml, "default") ? NULL : wer->sml; 87 char *nds = !strcmp(wer->sml, "default") ? NULL : wer->sml;
97 GSList *dfg = wer->smileys; 88 GSList *already_freed = NULL;
98 while (dfg) { 89 while (wer->smileys) {
99 GtkIMHtmlSmiley *uio = dfg->data; 90 GtkIMHtmlSmiley *uio = wer->smileys->data;
100 if (uio->icon) 91 if (uio->icon)
101 g_object_unref(uio->icon); 92 g_object_unref(uio->icon);
102 g_free(uio->file); 93 if (!g_slist_find(already_freed, uio->file)) {
94 g_free(uio->file);
95 already_freed = g_slist_append(already_freed, uio->file);
96 }
103 g_free(uio->smile); 97 g_free(uio->smile);
104 dfg = dfg->next; 98 g_free(uio);
99 wer->smileys=g_slist_remove(wer->smileys, uio);
105 } 100 }
106 wer = wer->next; 101 wer = wer->next;
107 } 102 }
108 } 103 current_smiley_theme->list = NULL;
109 current_smiley_theme = theme; 104 g_slist_free(already_freed);
105 }
106 current_smiley_theme = theme;
110 } 107 }
111 108
112 109
113 while (!feof(f)) { 110 while (!feof(f)) {
114 if (!fgets(buf, sizeof(buf), f)) { 111 if (!fgets(buf, sizeof(buf), f)) {
115 g_free(dirname); 112 break;
116 return NULL;
117 } 113 }
118 114
119 if (buf[0] == '#' || buf[0] == '\0') 115 if (buf[0] == '#' || buf[0] == '\0')
120 continue; 116 continue;
121 117
131 else 127 else
132 theme->list = child; 128 theme->list = child;
133 list = child; 129 list = child;
134 } else if (!g_strncasecmp(i, "Name=", strlen("Name="))) { 130 } else if (!g_strncasecmp(i, "Name=", strlen("Name="))) {
135 theme->name = g_strdup(i+ strlen("Name=")); 131 theme->name = g_strdup(i+ strlen("Name="));
132 theme->name[strlen(theme->name)-1] = 0;
136 } else if (!g_strncasecmp(i, "Description=", strlen("Description="))) { 133 } else if (!g_strncasecmp(i, "Description=", strlen("Description="))) {
137 theme->desc = g_strdup(i + strlen("Description=")); 134 theme->desc = g_strdup(i + strlen("Description="));
135 theme->desc[strlen(theme->desc)-1] = 0;
138 } else if (!g_strncasecmp(i, "Icon=", strlen("Icon="))) { 136 } else if (!g_strncasecmp(i, "Icon=", strlen("Icon="))) {
139 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); 137 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL);
140 } else if (!g_strncasecmp(i, "Author=", strlen("Author"))) { 138 theme->icon[strlen(theme->icon)-1] = 0;
141 theme->desc = g_strdup(i + strlen("Author")); 139 } else if (!g_strncasecmp(i, "Author=", strlen("Author="))) {
140 theme->author = g_strdup(i + strlen("Author="));
141 theme->author[strlen(theme->author)-1] = 0;
142 } else if (load && list) { 142 } else if (load && list) {
143 gboolean hidden; 143 gboolean hidden;
144 char *file = NULL; 144 char *sfile = NULL;
145 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); 145 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1);
146 146
147 if (*i == '!' && *(i + 1) == ' ') { 147 if (*i == '!' && *(i + 1) == ' ') {
148 hidden = TRUE; 148 hidden = TRUE;
149 i = i + 2; 149 i = i + 2;
151 while (*i) { 151 while (*i) {
152 char l[64]; 152 char l[64];
153 int li = 0; 153 int li = 0;
154 while (!isspace(*i)) 154 while (!isspace(*i))
155 l[li++] = *(i++); 155 l[li++] = *(i++);
156 if (!file) { 156 if (!sfile) {
157 l[li] = 0; 157 l[li] = 0;
158 file = g_build_filename(dirname, l, NULL); 158 sfile = g_build_filename(dirname, l, NULL);
159 } else { 159 } else {
160 l[li] = 0; 160 l[li] = 0;
161 smiley = g_new0(GtkIMHtmlSmiley, 1); 161 smiley = g_new0(GtkIMHtmlSmiley, 1);
162 smiley->file = file; 162 smiley->file = sfile;
163 smiley->smile = g_strdup(l); 163 smiley->smile = g_strdup(l);
164 list->smileys = g_slist_append(list->smileys, smiley); 164 list->smileys = g_slist_append(list->smileys, smiley);
165 } 165 }
166 while (isspace(*i)) 166 while (isspace(*i))
167 i++; 167 i++;
168 } 168
169 } 169 }
170 } 170 }
171 }
172
173 if (load) {
174 GList *cnv = conversations;
175 while (cnv) {
176 struct conversation *c = cnv->data;
177 smiley_themeize(c->text);
178 cnv=cnv->next;
179 }
180 }
181
171 g_free(dirname); 182 g_free(dirname);
172 return theme; 183 return theme;
173 } 184 }
174 185
175 void smiley_theme_probe() 186 void smiley_theme_probe()
192 203
193 /* Here we check to see that the theme has proper syntax. 204 /* Here we check to see that the theme has proper syntax.
194 * We set the second argument to FALSE so that it doesn't load 205 * We set the second argument to FALSE so that it doesn't load
195 * the theme yet. 206 * the theme yet.
196 */ 207 */
197 if (smile = load_smiley_theme(path, TRUE)) { 208 if (smile = load_smiley_theme(path, FALSE)) {
198 smiley_themes = g_slist_append(smiley_themes, smile); 209 smiley_themes = g_slist_append(smiley_themes, smile);
199 } 210 }
200 g_free(path); 211 g_free(path);
201 } 212 }
202 g_dir_close(dir); 213 g_dir_close(dir);