Mercurial > pidgin
annotate src/themes.c @ 9709:4d05b6e9e9cd
[gaim-migrate @ 10570]
This patch is freaking massive.
Renamed ui.h to gtkdialogs.h
Renamed dialogs.c to gtkdialogs.c
sed'ed the hell out of the .po files
These files are similar to gtkutil.c/.h. They are meant to contain
dialogs such as the "New Instant Message" window, which does not
belong in gtkblist.c or gtkconv.c, and is called from both places.
Eventually the functions in gtkdialogs.c/.h should be changed to
conform to Gaim's naming convention.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 08 Aug 2004 00:48:19 +0000 |
| parents | ed62fb44aa30 |
| children | 4a15962c344a |
| rev | line source |
|---|---|
| 4263 | 1 /* |
| 2 * Themes for Gaim | |
| 3 * | |
| 8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 4263 | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
23 #include "gtkinternal.h" |
| 4263 | 24 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
25 #include "conversation.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
26 #include "debug.h" |
| 4667 | 27 #include "prpl.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
28 #include "util.h" |
| 4263 | 29 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
30 #include "gtkconv.h" |
| 9709 | 31 #include "gtkdialogs.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
32 #include "gtkimhtml.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
33 |
| 4263 | 34 struct smiley_list { |
| 35 char *sml; | |
| 36 GSList *smileys; | |
| 37 struct smiley_list *next; | |
| 38 }; | |
| 39 | |
| 4892 | 40 GSList *smiley_themes = NULL; |
| 4288 | 41 struct smiley_theme *current_smiley_theme; |
| 4263 | 42 |
| 43 void smiley_themeize(GtkWidget *imhtml) | |
| 44 { | |
| 45 struct smiley_list *list; | |
| 46 if (!current_smiley_theme) | |
| 47 return; | |
| 48 | |
| 49 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml)); | |
| 50 list = current_smiley_theme->list; | |
| 51 while (list) { | |
| 52 char *sml = !strcmp(list->sml, "default") ? NULL : list->sml; | |
| 53 GSList *icons = list->smileys; | |
| 54 while (icons) { | |
| 55 gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), sml, icons->data); | |
| 56 icons = icons->next; | |
| 57 } | |
| 58 list = list->next; | |
| 59 } | |
| 60 } | |
| 61 | |
| 4892 | 62 void load_smiley_theme(const char *file, gboolean load) |
| 4263 | 63 { |
| 64 FILE *f = fopen(file, "r"); | |
| 65 char buf[256]; | |
| 66 char *i; | |
| 67 struct smiley_theme *theme=NULL; | |
| 68 struct smiley_list *list = NULL; | |
| 69 GSList *lst = smiley_themes; | |
| 70 char *dirname; | |
| 4892 | 71 |
| 72 if (!f) | |
| 73 return; | |
| 4630 | 74 |
| 4263 | 75 while (lst) { |
| 76 struct smiley_theme *thm = lst->data; | |
| 4288 | 77 if (!strcmp(thm->path, file)) { |
| 4263 | 78 theme = thm; |
| 79 break; | |
| 80 } | |
| 81 lst = lst->next; | |
| 82 } | |
| 4630 | 83 |
| 4263 | 84 if (!theme) { |
| 85 theme = g_new0(struct smiley_theme, 1); | |
| 4288 | 86 theme->path = g_strdup(file); |
| 4892 | 87 smiley_themes = g_slist_append(smiley_themes, theme); |
| 4263 | 88 } |
| 4630 | 89 |
| 4263 | 90 dirname = g_path_get_dirname(file); |
| 91 if (load) { | |
| 92 if (current_smiley_theme) { | |
| 4288 | 93 GSList *already_freed = NULL; |
| 4892 | 94 struct smiley_list *wer = current_smiley_theme->list, *wer2; |
| 4263 | 95 while (wer) { |
| 4288 | 96 while (wer->smileys) { |
| 97 GtkIMHtmlSmiley *uio = wer->smileys->data; | |
| 4263 | 98 if (uio->icon) |
| 99 g_object_unref(uio->icon); | |
| 4288 | 100 if (!g_slist_find(already_freed, uio->file)) { |
| 101 g_free(uio->file); | |
| 102 already_freed = g_slist_append(already_freed, uio->file); | |
| 103 } | |
| 4263 | 104 g_free(uio->smile); |
| 4288 | 105 g_free(uio); |
| 106 wer->smileys=g_slist_remove(wer->smileys, uio); | |
| 4263 | 107 } |
| 4892 | 108 wer2 = wer->next; |
| 109 g_free(wer->sml); | |
| 110 g_free(wer); | |
| 111 wer = wer2; | |
| 4263 | 112 } |
| 4288 | 113 current_smiley_theme->list = NULL; |
| 114 g_slist_free(already_freed); | |
| 4263 | 115 } |
| 4288 | 116 current_smiley_theme = theme; |
| 4263 | 117 } |
| 4816 | 118 |
| 119 | |
| 4263 | 120 while (!feof(f)) { |
| 121 if (!fgets(buf, sizeof(buf), f)) { | |
| 4288 | 122 break; |
| 4263 | 123 } |
| 4630 | 124 |
| 125 if (buf[0] == '#' || buf[0] == '\0') | |
| 4263 | 126 continue; |
| 4630 | 127 |
| 4263 | 128 i = buf; |
| 129 while (isspace(*i)) | |
| 130 i++; | |
| 4630 | 131 |
| 4816 | 132 if (*i == '[' && strchr(i, ']') && load) { |
| 4263 | 133 struct smiley_list *child = g_new0(struct smiley_list, 1); |
|
6478
338147ea6896
[gaim-migrate @ 6991]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
134 child->sml = g_strndup(i+1, strchr(i, ']') - i - 1); |
| 4816 | 135 if (theme->list) |
| 4263 | 136 list->next = child; |
| 137 else | |
| 138 theme->list = child; | |
| 139 list = child; | |
| 4816 | 140 } else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) { |
| 4892 | 141 if(theme->name) |
| 142 g_free(theme->name); | |
| 4816 | 143 theme->name = g_strdup(i+ strlen("Name=")); |
| 144 theme->name[strlen(theme->name)-1] = 0; | |
| 145 } else if (!g_ascii_strncasecmp(i, "Description=", strlen("Description="))) { | |
| 4892 | 146 if(theme->desc) |
| 147 g_free(theme->desc); | |
| 4816 | 148 theme->desc = g_strdup(i + strlen("Description=")); |
| 149 theme->desc[strlen(theme->desc)-1] = 0; | |
| 150 } else if (!g_ascii_strncasecmp(i, "Icon=", strlen("Icon="))) { | |
| 4892 | 151 if(theme->icon) |
| 152 g_free(theme->icon); | |
| 4816 | 153 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); |
| 154 theme->icon[strlen(theme->icon)-1] = 0; | |
| 155 } else if (!g_ascii_strncasecmp(i, "Author=", strlen("Author="))) { | |
| 4892 | 156 if(theme->author) |
| 157 g_free(theme->author); | |
| 4816 | 158 theme->author = g_strdup(i + strlen("Author=")); |
| 159 theme->author[strlen(theme->author)-1] = 0; | |
| 160 } else if (load && list) { | |
| 4667 | 161 gboolean hidden = FALSE; |
| 4288 | 162 char *sfile = NULL; |
| 4630 | 163 |
| 4266 | 164 if (*i == '!' && *(i + 1) == ' ') { |
| 4263 | 165 hidden = TRUE; |
| 166 i = i + 2; | |
| 167 } | |
| 168 while (*i) { | |
| 169 char l[64]; | |
| 170 int li = 0; | |
| 4630 | 171 while (!isspace(*i)) |
| 4263 | 172 l[li++] = *(i++); |
| 4288 | 173 if (!sfile) { |
| 4263 | 174 l[li] = 0; |
| 4288 | 175 sfile = g_build_filename(dirname, l, NULL); |
| 4263 | 176 } else { |
| 4632 | 177 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); |
| 4263 | 178 l[li] = 0; |
| 4288 | 179 smiley->file = sfile; |
| 4263 | 180 smiley->smile = g_strdup(l); |
| 4667 | 181 smiley->hidden = hidden; |
| 4263 | 182 list->smileys = g_slist_append(list->smileys, smiley); |
| 183 } | |
| 4630 | 184 while (isspace(*i)) |
| 4263 | 185 i++; |
| 4630 | 186 |
| 4263 | 187 } |
| 188 } | |
| 189 } | |
| 4288 | 190 |
| 191 if (load) { | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4341
diff
changeset
|
192 GList *cnv; |
| 4630 | 193 |
|
4375
90eaa3486949
[gaim-migrate @ 4641]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
194 for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) { |
|
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
195 GaimConversation *conv = cnv->data; |
| 4630 | 196 |
| 7736 | 197 if (GAIM_IS_GTK_CONVERSATION(conv)) { |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4341
diff
changeset
|
198 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml); |
| 7736 | 199 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->entry); |
| 200 } | |
|
4338
6c1230d15958
[gaim-migrate @ 4602]
Christian Hammond <chipx86@chipx86.com>
parents:
4323
diff
changeset
|
201 } |
| 4288 | 202 } |
| 203 | |
| 4263 | 204 g_free(dirname); |
| 4989 | 205 fclose(f); |
| 4263 | 206 } |
| 207 | |
| 208 void smiley_theme_probe() | |
| 209 { | |
| 210 GDir *dir; | |
| 211 const gchar *file; | |
| 212 gchar *path; | |
| 213 int l; | |
| 214 | |
| 215 char* probedirs[3]; | |
| 216 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); | |
| 217 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); | |
| 218 probedirs[2] = 0; | |
| 219 for (l=0; probedirs[l]; l++) { | |
| 220 dir = g_dir_open(probedirs[l], 0, NULL); | |
| 221 if (dir) { | |
| 222 while ((file = g_dir_read_name(dir))) { | |
| 4301 | 223 path = g_build_filename(probedirs[l], file, "theme", NULL); |
| 4892 | 224 |
| 4263 | 225 /* Here we check to see that the theme has proper syntax. |
| 226 * We set the second argument to FALSE so that it doesn't load | |
| 227 * the theme yet. | |
| 228 */ | |
| 4892 | 229 load_smiley_theme(path, FALSE); |
| 4263 | 230 g_free(path); |
| 231 } | |
| 232 g_dir_close(dir); | |
| 4341 | 233 } else if (l == 1) { |
| 234 mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); | |
| 4892 | 235 } |
| 4263 | 236 g_free(probedirs[l]); |
| 237 } | |
| 238 } | |
| 4667 | 239 |
| 7956 | 240 GSList *get_proto_smileys(const char *id) { |
| 241 GaimPlugin *proto = gaim_find_prpl(id); | |
| 4667 | 242 struct smiley_list *list, *def; |
| 243 | |
| 244 if(!current_smiley_theme) | |
| 245 return NULL; | |
| 246 | |
| 8892 | 247 if(!current_smiley_theme->list) |
| 248 return NULL; | |
| 249 | |
| 4667 | 250 def = list = current_smiley_theme->list; |
| 251 | |
| 252 while(list) { | |
| 253 if(!strcmp(list->sml, "default")) | |
| 254 def = list; | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4989
diff
changeset
|
255 else if(proto && !strcmp(proto->info->name, list->sml)) |
| 4667 | 256 break; |
| 257 | |
| 258 list = list->next; | |
| 259 } | |
| 260 | |
| 261 return list ? list->smileys : def->smileys; | |
| 262 } |
