annotate libpurple/smiley.c @ 23136:6c4f47b9d201

Make PurpleSmiley a GObject. Removed some functions from the API that are not really necessary, including purple_smileys_add and purple_smileys_remove. They are called automatically when a new smiley is created or removed. PurpleSmiley has a 'destroy' signal, and 'shortcut' and 'image' properties. These might be of interest to UIs.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 10 May 2008 16:31:06 +0000
parents 3da84b370eda
children 53b3c75c9e26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 /**
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2 * @file smiley.c Simley API
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 * @ingroup core
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 */
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 /* purple
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 * source distribution.
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
15 * (at your option) any later version.
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
16 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20 * GNU General Public License for more details.
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
25 */
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 #include "internal.h"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 #include "xmlnode.h"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 #include "debug.h"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 #include "imgstore.h"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 #include "smiley.h"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 #include "util.h"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 /**************************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 /* Main structures, members and constants */
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 /**************************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37
22880
2ab289f312d0 Hide PurpleSmiley internals.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22877
diff changeset
38 struct _PurpleSmiley
2ab289f312d0 Hide PurpleSmiley internals.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22877
diff changeset
39 {
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
40 GObject parent;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
41 PurpleStoredImage *img; /**< The id of the stored image with the
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
42 the smiley data. */
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
43 char *shortcut; /**< Shortcut associated with the custom
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
44 smiley. This field will work as a
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
45 unique key by this API. */
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
46 char *checksum; /**< The smiley checksum. */
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
47 };
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
48
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
49 struct _PurpleSmileyClass
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
50 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
51 GObjectClass parent_class;
22880
2ab289f312d0 Hide PurpleSmiley internals.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22877
diff changeset
52 };
2ab289f312d0 Hide PurpleSmiley internals.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22877
diff changeset
53
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
54 static GHashTable *smiley_shortcut_index = NULL; /* shortcut (char *) => smiley (PurpleSmiley*) */
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
55 static GHashTable *smiley_checksum_index = NULL; /* checksum (char *) => smiley (PurpleSmiley*) */
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 static guint save_timer = 0;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 static gboolean smileys_loaded = FALSE;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59 static char *smileys_dir = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61 #define SMILEYS_DEFAULT_FOLDER "custom_smiley"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62 #define SMILEYS_LOG_ID "smileys"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64 #define XML_FILE_NAME "smileys.xml"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
66 #define XML_ROOT_TAG "smileys"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67 #define XML_PROFILE_TAG "profile"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68 #define XML_PROFILE_NAME_ATTRIB_TAG "name"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
69 #define XML_ACCOUNT_TAG "account"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
70 #define XML_ACCOUNT_USERID_ATTRIB_TAG "userid"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71 #define XML_SMILEY_SET_TAG "smiley_set"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72 #define XML_SMILEY_TAG "smiley"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73 #define XML_SHORTCUT_ATTRIB_TAG "shortcut"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 #define XML_CHECKSUM_ATRIB_TAG "checksum"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75 #define XML_FILENAME_ATRIB_TAG "filename"
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
76
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
77
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
78 /******************************************************************************
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
79 * XML descriptor file layout *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
80 ******************************************************************************
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
82 * Althought we are creating the profile XML structure here, now we
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
83 * won't handle it.
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
84 * So, we just add one profile named "default" that has no associated
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
85 * account elements, and have only the smiley_set that will contain
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
86 * all existent custom smiley.
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88 * It's our "Highlander Profile" :-)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 ******************************************************************************
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92 * <smileys>
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
93 * <profile name="john.doe">
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
94 * <account userid="john.doe@jabber.org">
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
95 * <account userid="john.doe@gmail.com">
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96 * <smiley_set>
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97 * <smiley shortcut="aaa" checksum="xxxxxxxx" filename="file_name1.gif"/>
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
98 * <smiley shortcut="bbb" checksum="yyyyyyy" filename="file_name2.gif"/>
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
99 * </smiley_set>
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
100 * </profile>
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101 * </smiley>
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
102 *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 *****************************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
104
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
105
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106 /*********************************************************************
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 * Forward declarations *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108 *********************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 static gboolean read_smiley_file(const char *path, guchar **data, size_t *len);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
111
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
112 static char *get_file_full_path(const char *filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
113
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114 static PurpleSmiley *purple_smiley_create(const char *shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115
22877
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
116 static PurpleSmiley *purple_smiley_load_file(const char *shortcut, const char *checksum,
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117 const char *filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118
22877
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
119 static void
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
120 purple_smiley_set_data_impl(PurpleSmiley *smiley, guchar *smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
121 size_t smiley_data_len, const char *filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
123 static void
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
124 purple_smiley_data_store(PurpleStoredImage *stored_img);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
125
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
126 static void
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
127 purple_smiley_data_unstore(const char *filename);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
128
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
129 /*********************************************************************
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
130 * Writing to disk *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
131 *********************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
132
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
133 static xmlnode *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
134 smiley_to_xmlnode(PurpleSmiley *smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
135 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
136 xmlnode *smiley_node = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
137
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
138 smiley_node = xmlnode_new(XML_SMILEY_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
139
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
140 if (!smiley_node)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
141 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
142
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
143 xmlnode_set_attrib(smiley_node, XML_SHORTCUT_ATTRIB_TAG,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
144 smiley->shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
145
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
146 xmlnode_set_attrib(smiley_node, XML_CHECKSUM_ATRIB_TAG,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
147 smiley->checksum);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
148
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
149 xmlnode_set_attrib(smiley_node, XML_FILENAME_ATRIB_TAG,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
150 purple_imgstore_get_filename(smiley->img));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
151
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
152 return smiley_node;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
153 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
154
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
155 static void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
156 add_smiley_to_main_node(gpointer key, gpointer value, gpointer user_data)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
157 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
158 xmlnode *child_node;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
159
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
160 child_node = smiley_to_xmlnode(value);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
161 xmlnode_insert_child((xmlnode*)user_data, child_node);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
162 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
163
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
164 static xmlnode *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
165 smileys_to_xmlnode()
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
166 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
167 xmlnode *root_node, *profile_node, *smileyset_node;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
168
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
169 root_node = xmlnode_new(XML_ROOT_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170 xmlnode_set_attrib(root_node, "version", "1.0");
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
172 /* See the top comment's above to understand why initial tag elements
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
173 * are not being considered by now. */
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174 profile_node = xmlnode_new(XML_PROFILE_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
175 if (profile_node) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
176 xmlnode_set_attrib(profile_node, XML_PROFILE_NAME_ATTRIB_TAG, "Default");
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
177 xmlnode_insert_child(root_node, profile_node);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
178
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
179 smileyset_node = xmlnode_new(XML_SMILEY_SET_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
180 if (smileyset_node) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
181 xmlnode_insert_child(profile_node, smileyset_node);
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
182 g_hash_table_foreach(smiley_shortcut_index, add_smiley_to_main_node, smileyset_node);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
183 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
184 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
185
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
186 return root_node;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
187 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
188
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
189 static void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
190 sync_smileys()
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
191 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
192 xmlnode *root_node;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
193 char *data;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
194
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
195 if (!smileys_loaded) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
196 purple_debug_error(SMILEYS_LOG_ID, "Attempted to save smileys before it "
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
197 "was read!\n");
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
198 return;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
199 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
200
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
201 root_node = smileys_to_xmlnode();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
202 data = xmlnode_to_formatted_str(root_node, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
203 purple_util_write_data_to_file(XML_FILE_NAME, data, -1);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
204
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
205 g_free(data);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
206 xmlnode_free(root_node);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
207 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
208
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
209 static gboolean
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
210 save_smileys_cb(gpointer data)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
211 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
212 sync_smileys();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
213 save_timer = 0;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
214 return FALSE;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
215 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
216
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
217 static void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
218 purple_smileys_save()
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
219 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
220 if (save_timer == 0)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
221 save_timer = purple_timeout_add_seconds(5, save_smileys_cb, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
222 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
223
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
224
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
225 /*********************************************************************
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
226 * Reading from disk *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
227 *********************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
228
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
229 static PurpleSmiley *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
230 parse_smiley(xmlnode *smiley_node)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
231 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
232 PurpleSmiley *smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
233 const char *shortcut = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
234 const char *checksum = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
235 const char *filename = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
236
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
237 shortcut = xmlnode_get_attrib(smiley_node, XML_SHORTCUT_ATTRIB_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
238 checksum = xmlnode_get_attrib(smiley_node, XML_CHECKSUM_ATRIB_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
239 filename = xmlnode_get_attrib(smiley_node, XML_FILENAME_ATRIB_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
240
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
241 if ((shortcut == NULL) || (checksum == NULL) || (filename == NULL))
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
242 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
243
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
244 smiley = purple_smiley_load_file(shortcut, checksum, filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
245
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
246 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
247 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
248
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
249 static void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
250 purple_smileys_load()
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
251 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
252 xmlnode *root_node, *profile_node;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
253 xmlnode *smileyset_node = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
254 xmlnode *smiley_node;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
255
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
256 smileys_loaded = TRUE;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
257
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
258 root_node = purple_util_read_xml_from_file(XML_FILE_NAME,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
259 _(SMILEYS_LOG_ID));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
260
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
261 if (root_node == NULL)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
262 return;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
263
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
264 /* See the top comment's above to understand why initial tag elements
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
265 * are not being considered by now. */
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
266 profile_node = xmlnode_get_child(root_node, XML_PROFILE_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
267 if (profile_node)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
268 smileyset_node = xmlnode_get_child(profile_node, XML_SMILEY_SET_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
269
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
270 if (smileyset_node) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
271 smiley_node = xmlnode_get_child(smileyset_node, XML_SMILEY_TAG);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
272 for (; smiley_node != NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
273 smiley_node = xmlnode_get_next_twin(smiley_node)) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
274 PurpleSmiley *smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
275
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
276 smiley = parse_smiley(smiley_node);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
277 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
278 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
279
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
280 xmlnode_free(root_node);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
281 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
282
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
283 /*********************************************************************
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
284 * GObject Stuff *
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
285 *********************************************************************/
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
286 enum
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
287 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
288 PROP_0,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
289 PROP_SHORTCUT,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
290 PROP_IMGSTORE,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
291 };
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
292
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
293 #define PROP_SHORTCUT_S "shortcut"
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
294 #define PROP_IMGSTORE_S "image"
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
295
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
296 enum
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
297 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
298 SIG_DESTROY,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
299 SIG_LAST
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
300 };
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
301
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
302 static guint signals[SIG_LAST];
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
303
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
304 static void
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
305 purple_smiley_init(GTypeInstance *instance, gpointer klass)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
306 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
307 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
308
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
309 static void
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
310 purple_smiley_get_property(GObject *object, guint param_id, GValue *value,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
311 GParamSpec *spec)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
312 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
313 PurpleSmiley *smiley = PURPLE_SMILEY(object);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
314 switch (param_id) {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
315 case PROP_SHORTCUT:
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
316 g_value_set_string(value, smiley->shortcut);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
317 break;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
318 case PROP_IMGSTORE:
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
319 g_value_set_pointer(value, smiley->img);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
320 break;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
321 default:
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
322 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, spec);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
323 break;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
324 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
325 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
326
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
327 static void
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
328 purple_smiley_set_property(GObject *object, guint param_id, const GValue *value,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
329 GParamSpec *spec)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
330 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
331 PurpleSmiley *smiley = PURPLE_SMILEY(object);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
332 switch (param_id) {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
333 case PROP_SHORTCUT:
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
334 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
335 const char *shortcut = g_value_get_string(value);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
336 purple_smiley_set_shortcut(smiley, shortcut);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
337 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
338 break;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
339 case PROP_IMGSTORE:
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
340 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
341 PurpleStoredImage *img = g_value_get_pointer(value);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
342
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
343 purple_imgstore_unref(smiley->img);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
344 g_free(smiley->checksum);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
345
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
346 smiley->img = img;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
347 if (img) {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
348 smiley->checksum = purple_util_get_image_checksum(
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
349 purple_imgstore_get_data(img),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
350 purple_imgstore_get_size(img));
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
351 purple_smiley_data_store(img);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
352 } else {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
353 smiley->checksum = NULL;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
354 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
355
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
356 g_object_notify(object, PROP_IMGSTORE_S);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
357 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
358 break;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
359 default:
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
360 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, spec);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
361 break;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
362 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
363 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
364
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
365 static void
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
366 purple_smiley_finalize(GObject *obj)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
367 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
368 PurpleSmiley *smiley = PURPLE_SMILEY(obj);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
369 g_signal_emit(obj, signals[SIG_DESTROY], 0);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
370
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
371 if (g_hash_table_lookup(smiley_shortcut_index, smiley->shortcut)) {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
372 g_hash_table_remove(smiley_shortcut_index, smiley->shortcut);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
373 g_hash_table_remove(smiley_checksum_index, smiley->checksum);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
374 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
375
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
376 g_free(smiley->shortcut);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
377 g_free(smiley->checksum);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
378 if (smiley->img)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
379 purple_smiley_data_unstore(purple_imgstore_get_filename(smiley->img));
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
380 purple_imgstore_unref(smiley->img);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
381
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
382 purple_smileys_save();
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
383 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
384
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
385 static void
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
386 purple_smiley_class_init(PurpleSmileyClass *klass)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
387 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
388 GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
389 GParamSpec *pspec;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
390
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
391 gobj_class->get_property = purple_smiley_get_property;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
392 gobj_class->set_property = purple_smiley_set_property;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
393 gobj_class->finalize = purple_smiley_finalize;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
394
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
395 /* Shortcut */
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
396 pspec = g_param_spec_string(PROP_SHORTCUT_S, _("Shortcut"),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
397 _("The text-shortcut for the smiley"),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
398 NULL,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
399 G_PARAM_READWRITE);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
400 g_object_class_install_property(gobj_class, PROP_SHORTCUT, pspec);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
401
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
402 /* Stored Image */
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
403 pspec = g_param_spec_pointer(PROP_IMGSTORE_S, _("Stored Image"),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
404 _("Stored Image. (that'll have to do for now)"),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
405 G_PARAM_READWRITE);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
406 g_object_class_install_property(gobj_class, PROP_IMGSTORE, pspec);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
407
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
408 signals[SIG_DESTROY] = g_signal_new("destroy",
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
409 G_OBJECT_CLASS_TYPE(klass),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
410 G_SIGNAL_RUN_LAST,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
411 0, NULL, NULL,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
412 g_cclosure_marshal_VOID__VOID,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
413 G_TYPE_NONE, 0);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
414 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
415
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
416 GType
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
417 purple_smiley_get_type(void)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
418 {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
419 static GType type = 0;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
420
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
421 if(type == 0) {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
422 static const GTypeInfo info = {
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
423 sizeof(PurpleSmileyClass),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
424 NULL,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
425 NULL,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
426 (GClassInitFunc)purple_smiley_class_init,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
427 NULL,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
428 NULL,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
429 sizeof(PurpleSmiley),
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
430 0,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
431 purple_smiley_init,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
432 NULL,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
433 };
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
434
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
435 type = g_type_register_static(G_TYPE_OBJECT,
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
436 "PurpleSmiley",
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
437 &info, 0);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
438 }
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
439
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
440 return type;
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
441 }
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
442
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
443 /*********************************************************************
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
444 * Other Stuff *
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
445 *********************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
446
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
447 static char *get_file_full_path(const char *filename)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
448 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
449 char *path;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
450
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
451 path = g_build_filename(purple_smileys_get_storing_dir(), filename, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
452
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
453 if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
454 g_free(path);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
455 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
456 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
457
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
458 return path;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
459 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
460
22877
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
461 static PurpleSmiley *
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
462 purple_smiley_load_file(const char *shortcut, const char *checksum, const char *filename)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
463 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
464 PurpleSmiley *smiley = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
465 guchar *smiley_data;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
466 size_t smiley_data_len;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
467 char *fullpath = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
468
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
469 g_return_val_if_fail(shortcut != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
470 g_return_val_if_fail(checksum != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
471 g_return_val_if_fail(filename != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
472
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
473 fullpath = get_file_full_path(filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
474 if (!fullpath)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
475 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
476
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
477 smiley = purple_smiley_create(shortcut);
22877
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
478 if (!smiley) {
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
479 g_free(fullpath);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
480 return NULL;
22877
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
481 }
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
482
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
483 smiley->checksum = g_strdup(checksum);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
484
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
485 if (read_smiley_file(fullpath, &smiley_data, &smiley_data_len))
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
486 purple_smiley_set_data_impl(smiley, smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
487 smiley_data_len, filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
488 else
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
489 purple_smiley_delete(smiley);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
490
22877
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
491 g_free(fullpath);
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
492
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
493 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
494 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
495
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
496 static void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
497 purple_smiley_data_store(PurpleStoredImage *stored_img)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
498 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
499 const char *dirname;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
500 char *path;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
501 FILE *file = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
502
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
503 g_return_if_fail(stored_img != NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
504
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
505 if (!smileys_loaded)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
506 return;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
507
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
508 dirname = purple_smileys_get_storing_dir();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
509 path = g_build_filename(dirname, purple_imgstore_get_filename(stored_img), NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
510
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
511 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
512 purple_debug_info(SMILEYS_LOG_ID, "Creating smileys directory.\n");
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
513
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
514 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
515 purple_debug_error(SMILEYS_LOG_ID,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
516 "Unable to create directory %s: %s\n",
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
517 dirname, g_strerror(errno));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
518 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
519 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
520
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
521 if ((file = g_fopen(path, "wb")) != NULL) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
522 if (!fwrite(purple_imgstore_get_data(stored_img),
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
523 purple_imgstore_get_size(stored_img), 1, file)) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
524 purple_debug_error(SMILEYS_LOG_ID, "Error writing %s: %s\n",
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
525 path, g_strerror(errno));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
526 } else {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
527 purple_debug_info(SMILEYS_LOG_ID, "Wrote cache file: %s\n", path);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
528 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
529
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
530 fclose(file);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
531 } else {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
532 purple_debug_error(SMILEYS_LOG_ID, "Unable to create file %s: %s\n",
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
533 path, g_strerror(errno));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
534 g_free(path);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
535
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
536 return;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
537 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
538
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
539 g_free(path);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
540 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
541
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
542 static void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
543 purple_smiley_data_unstore(const char *filename)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
544 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
545 const char *dirname;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
546 char *path;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
547
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
548 g_return_if_fail(filename != NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
549
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
550 dirname = purple_smileys_get_storing_dir();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
551 path = g_build_filename(dirname, filename, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
552
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
553 if (g_file_test(path, G_FILE_TEST_EXISTS)) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
554 if (g_unlink(path))
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
555 purple_debug_error(SMILEYS_LOG_ID, "Failed to delete %s: %s\n",
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
556 path, g_strerror(errno));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
557 else
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
558 purple_debug_info(SMILEYS_LOG_ID, "Deleted cache file: %s\n", path);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
559 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
560
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
561 g_free(path);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
562 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
563
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
564 static gboolean
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
565 read_smiley_file(const char *path, guchar **data, size_t *len)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
566 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
567 GError *err = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
568
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
569 if (!g_file_get_contents(path, (gchar **)data, len, &err)) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
570 purple_debug_error(SMILEYS_LOG_ID, "Error reading %s: %s\n",
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
571 path, err->message);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
572 g_error_free(err);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
573
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
574 return FALSE;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
575 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
576
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
577 return TRUE;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
578 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
579
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
580 static PurpleStoredImage *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
581 purple_smiley_data_new(guchar *smiley_data, size_t smiley_data_len)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
582 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
583 char *filename;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
584 PurpleStoredImage *stored_img;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
585
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
586 g_return_val_if_fail(smiley_data != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
587 g_return_val_if_fail(smiley_data_len > 0, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
588
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
589 filename = purple_util_get_image_filename(smiley_data, smiley_data_len);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
590
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
591 if (filename == NULL) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
592 g_free(smiley_data);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
593 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
594 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
595
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
596 stored_img = purple_imgstore_add(smiley_data, smiley_data_len, filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
597
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
598 g_free(filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
599
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
600 return stored_img;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
601 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
602
22877
76fa93017695 Make some functions static, plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
603 static void
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
604 purple_smiley_set_data_impl(PurpleSmiley *smiley, guchar *smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
605 size_t smiley_data_len, const char *filename)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
606 {
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
607 PurpleStoredImage *old_img, *new_img;
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
608 const char *old_filename = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
609 const char *new_filename = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
610
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
611 g_return_if_fail(smiley != NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
612 g_return_if_fail(smiley_data != NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
613 g_return_if_fail(smiley_data_len > 0);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
614
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
615 old_img = smiley->img;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
616
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
617 if (filename)
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
618 new_img = purple_imgstore_add(smiley_data, smiley_data_len, filename);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
619 else
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
620 new_img = purple_smiley_data_new(smiley_data, smiley_data_len);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
621
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
622 g_object_set(G_OBJECT(smiley), PROP_IMGSTORE_S, new_img, NULL);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
623
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
624 /* If the old and new image files have different names we need
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
625 * to unstore old image file. */
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
626 if (!old_img)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
627 return;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
628
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
629 old_filename = purple_imgstore_get_filename(old_img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
630 new_filename = purple_imgstore_get_filename(smiley->img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
631
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
632 if (g_ascii_strcasecmp(old_filename, new_filename)) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
633 purple_smiley_data_unstore(old_filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
634 purple_imgstore_unref(old_img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
635 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
636 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
637
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
638
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
639 /*****************************************************************************
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
640 * Public API functions *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
641 *****************************************************************************/
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
642
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
643 static PurpleSmiley *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
644 purple_smiley_create(const char *shortcut)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
645 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
646 PurpleSmiley *smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
647
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
648 smiley = PURPLE_SMILEY(g_object_new(PURPLE_TYPE_SMILEY, PROP_SHORTCUT_S, shortcut, NULL));
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
649
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
650 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
651 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
652
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
653 PurpleSmiley *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
654 purple_smiley_new(PurpleStoredImage *img, const char *shortcut)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
655 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
656 PurpleSmiley *smiley = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
657
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
658 g_return_val_if_fail(shortcut != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
659 g_return_val_if_fail(img != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
660
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
661 smiley = purple_smileys_find_by_shortcut(shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
662 if (smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
663 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
664
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
665 smiley = purple_smiley_create(shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
666 if (!smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
667 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
668
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
669 g_object_set(G_OBJECT(smiley), PROP_IMGSTORE_S, img, NULL);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
670
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
671 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
672 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
673
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
674 static PurpleSmiley *
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
675 purple_smiley_new_from_stream(const char *shortcut, guchar *smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
676 size_t smiley_data_len, const char *filename)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
677 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
678 PurpleSmiley *smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
679
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
680 g_return_val_if_fail(shortcut != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
681 g_return_val_if_fail(smiley_data != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
682 g_return_val_if_fail(smiley_data_len > 0, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
683
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
684 smiley = purple_smileys_find_by_shortcut(shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
685 if (smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
686 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
687
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
688 /* purple_smiley_create() sets shortcut */
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
689 smiley = purple_smiley_create(shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
690 if (!smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
691 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
692
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
693 purple_smiley_set_data_impl(smiley, smiley_data, smiley_data_len, filename);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
694
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
695 purple_smiley_data_store(smiley->img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
696
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
697 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
698 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
699
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
700 PurpleSmiley *
23127
3da84b370eda Remove undocumented and [apparently] unnecessary parameter from
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22882
diff changeset
701 purple_smiley_new_from_file(const char *shortcut, const char *filepath)
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
702 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
703 PurpleSmiley *smiley = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
704 guchar *smiley_data;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
705 size_t smiley_data_len;
23127
3da84b370eda Remove undocumented and [apparently] unnecessary parameter from
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22882
diff changeset
706 char *filename;
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
707
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
708 g_return_val_if_fail(shortcut != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
709 g_return_val_if_fail(filepath != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
710
23127
3da84b370eda Remove undocumented and [apparently] unnecessary parameter from
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22882
diff changeset
711 filename = g_path_get_basename(filepath);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
712 if (read_smiley_file(filepath, &smiley_data, &smiley_data_len))
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
713 smiley = purple_smiley_new_from_stream(shortcut, smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
714 smiley_data_len, filename);
23127
3da84b370eda Remove undocumented and [apparently] unnecessary parameter from
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22882
diff changeset
715 g_free(filename);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
716
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
717 return smiley;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
718 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
719
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
720 void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
721 purple_smiley_delete(PurpleSmiley *smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
722 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
723 g_return_if_fail(smiley != NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
724
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
725 g_object_unref(smiley);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
726 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
727
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
728 gboolean
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
729 purple_smiley_set_shortcut(PurpleSmiley *smiley, const char *shortcut)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
730 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
731 g_return_val_if_fail(smiley != NULL, FALSE);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
732 g_return_val_if_fail(shortcut != NULL, FALSE);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
733
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
734 /* Check out whether the new shortcut is already being used. */
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
735 if (g_hash_table_lookup(smiley_shortcut_index, shortcut))
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
736 return FALSE;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
737
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
738 /* Remove the old shortcut. */
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
739 if (smiley->shortcut)
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
740 g_hash_table_remove(smiley_shortcut_index, smiley->shortcut);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
741
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
742 /* Insert the new shortcut. */
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
743 g_hash_table_insert(smiley_shortcut_index, g_strdup(shortcut), smiley);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
744
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
745 g_free(smiley->shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
746 smiley->shortcut = g_strdup(shortcut);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
747
23136
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
748 g_object_notify(G_OBJECT(smiley), PROP_SHORTCUT_S);
6c4f47b9d201 Make PurpleSmiley a GObject.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23127
diff changeset
749
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
750 purple_smileys_save();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
751
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
752 return TRUE;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
753 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
754
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
755 void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
756 purple_smiley_set_data(PurpleSmiley *smiley, guchar *smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
757 size_t smiley_data_len, gboolean keepfilename)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
758 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
759 g_return_if_fail(smiley != NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
760 g_return_if_fail(smiley_data != NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
761 g_return_if_fail(smiley_data_len > 0);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
762
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
763 /* Remove the previous entry */
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
764 g_hash_table_remove(smiley_checksum_index, smiley->checksum);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
765
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
766 /* Update the file data. This also updates the checksum. */
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
767 if ((keepfilename) && (smiley->img) &&
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
768 (purple_imgstore_get_filename(smiley->img)))
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
769 purple_smiley_set_data_impl(smiley, smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
770 smiley_data_len,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
771 purple_imgstore_get_filename(smiley->img));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
772 else
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
773 purple_smiley_set_data_impl(smiley, smiley_data,
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
774 smiley_data_len, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
775
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
776 /* Reinsert the index item. */
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
777 g_hash_table_insert(smiley_checksum_index, g_strdup(smiley->checksum), smiley);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
778
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
779 purple_smileys_save();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
780 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
781
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
782 PurpleStoredImage *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
783 purple_smiley_get_stored_image(const PurpleSmiley *smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
784 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
785 return purple_imgstore_ref(smiley->img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
786 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
787
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
788 const char *purple_smiley_get_shortcut(const PurpleSmiley *smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
789 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
790 g_return_val_if_fail(smiley != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
791
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
792 return smiley->shortcut;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
793 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
794
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
795 const char *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
796 purple_smiley_get_checksum(const PurpleSmiley *smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
797 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
798 g_return_val_if_fail(smiley != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
799
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
800 return smiley->checksum;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
801 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
802
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
803 gconstpointer
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
804 purple_smiley_get_data(const PurpleSmiley *smiley, size_t *len)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
805 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
806 g_return_val_if_fail(smiley != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
807
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
808 if (smiley->img) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
809 if (len != NULL)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
810 *len = purple_imgstore_get_size(smiley->img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
811
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
812 return purple_imgstore_get_data(smiley->img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
813 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
814
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
815 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
816 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
817
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
818 const char *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
819 purple_smiley_get_extension(const PurpleSmiley *smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
820 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
821 if (smiley->img != NULL)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
822 return purple_imgstore_get_extension(smiley->img);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
823
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
824 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
825 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
826
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
827 char *purple_smiley_get_full_path(PurpleSmiley *smiley)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
828 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
829 g_return_val_if_fail(smiley != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
830
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
831 if (smiley->img == NULL)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
832 return NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
833
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
834 return get_file_full_path(purple_imgstore_get_filename(smiley->img));
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
835 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
836
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
837 static void add_smiley_to_list(gpointer key, gpointer value, gpointer user_data)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
838 {
22881
d1bcb54920f8 Fix a leak, and correct the docs.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22880
diff changeset
839 GList** returninglist = (GList**)user_data;
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
840
22881
d1bcb54920f8 Fix a leak, and correct the docs.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22880
diff changeset
841 *returninglist = g_list_append(*returninglist, value);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
842 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
843
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
844 GList *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
845 purple_smileys_get_all(void)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
846 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
847 GList *returninglist = NULL;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
848
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
849 g_hash_table_foreach(smiley_shortcut_index, add_smiley_to_list, &returninglist);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
850
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
851 return returninglist;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
852 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
853
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
854 PurpleSmiley *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
855 purple_smileys_find_by_shortcut(const char *shortcut)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
856 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
857 g_return_val_if_fail(shortcut != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
858
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
859 return g_hash_table_lookup(smiley_shortcut_index, shortcut);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
860 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
861
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
862 PurpleSmiley *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
863 purple_smileys_find_by_checksum(const char *checksum)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
864 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
865 g_return_val_if_fail(checksum != NULL, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
866
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
867 return g_hash_table_lookup(smiley_checksum_index, checksum);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
868 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
869
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
870 const char *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
871 purple_smileys_get_storing_dir(void)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
872 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
873 return smileys_dir;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
874 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
875
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
876 void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
877 purple_smileys_init()
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
878 {
22882
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
879 smiley_shortcut_index = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
d30bee8d6bdf Modified patch ('big_smiley_change.patch') from Mauro and Jorge (Masca) to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22881
diff changeset
880 smiley_checksum_index = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
881
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
882 smileys_dir = g_build_filename(purple_user_dir(), SMILEYS_DEFAULT_FOLDER, NULL);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
883
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
884 purple_smileys_load();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
885 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
886
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
887 void
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
888 purple_smileys_uninit()
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
889 {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
890 if (save_timer != 0) {
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
891 purple_timeout_remove(save_timer);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
892 save_timer = 0;
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
893 sync_smileys();
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
894 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
895
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
896 g_hash_table_destroy(smiley_shortcut_index);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
897 g_hash_table_destroy(smiley_checksum_index);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
898 g_free(smileys_dir);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
899 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villaseo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
900