libpurple/smiley-parser.c

Tue, 01 Apr 2014 15:20:43 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Tue, 01 Apr 2014 15:20:43 +0200
changeset 35713
4423f463a782
parent 35709
0d7a84931572
child 35716
80bedd712883
permissions
-rw-r--r--

Smileys in PidginWebviewToolbar

35709
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
1 /* purple
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
2 *
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
5 * source distribution.
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
6 *
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
11 *
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
16 *
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
20 */
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
21
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
22 #include "smiley-parser.h"
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
23
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
24 #include "smiley-theme.h"
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
25
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
26 static gboolean purple_smiley_parse_cb(GString *out, const gchar *word,
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
27 gpointer _smiley, gpointer _unused)
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
28 {
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
29 PurpleSmiley *smiley = _smiley;
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
30
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
31 g_string_append_printf(out, "<img alt=\"%s\" src=\"%s\" />",
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
32 word, purple_smiley_get_path(smiley));
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
33
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
34 return TRUE;
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
35 }
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
36
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
37 gchar *
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
38 purple_smiley_parse(const gchar *message, gpointer ui_data)
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
39 {
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
40 PurpleSmileyTheme *theme;
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
41 PurpleSmileyList *theme_smileys;
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
42 PurpleTrie *theme_trie;
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
43
35713
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35709
diff changeset
44 if (message == NULL || message[0] == '\0')
35709
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
45 return g_strdup(message);
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
46
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
47 theme = purple_smiley_theme_get_current();
35713
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35709
diff changeset
48 if (theme == NULL)
35709
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
49 return g_strdup(message);
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
50
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
51 theme_smileys = purple_smiley_theme_get_smileys(theme, ui_data);
35713
4423f463a782 Smileys in PidginWebviewToolbar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35709
diff changeset
52 if (theme_smileys == NULL)
35709
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
53 return g_strdup(message);
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
54
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
55 theme_trie = purple_smiley_list_get_trie(theme_smileys);
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
56 g_return_val_if_fail(theme_trie != NULL, g_strdup(message));
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
57
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
58 /* TODO: don't replace text within tags, ie. <span style=":)"> */
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
59 return purple_trie_replace(theme_trie, message,
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
60 purple_smiley_parse_cb, NULL);
0d7a84931572 Smileys: implement and use new parser, only themes for now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
61 }

mercurial