3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 * A generic smiley. It can either be a theme smiley, or a custom smiley.
29 struct _PurpleSmiley
{
36 } PurpleSmileyPrivate
;
45 static GParamSpec
*properties
[PROP_LAST
];
47 G_DEFINE_TYPE_WITH_PRIVATE(PurpleSmiley
, purple_smiley
, PURPLE_TYPE_IMAGE
);
49 /*******************************************************************************
51 ******************************************************************************/
53 _purple_smiley_set_shortcut(PurpleSmiley
*smiley
, const gchar
*shortcut
) {
54 PurpleSmileyPrivate
*priv
= purple_smiley_get_instance_private(smiley
);
56 g_free(priv
->shortcut
);
58 priv
->shortcut
= g_strdup(shortcut
);
60 g_object_notify(G_OBJECT(smiley
), "shortcut");
63 /*******************************************************************************
65 ******************************************************************************/
68 purple_smiley_init(PurpleSmiley
*smiley
) {
72 purple_smiley_finalize(GObject
*obj
) {
73 PurpleSmiley
*smiley
= PURPLE_SMILEY(obj
);
74 PurpleSmileyPrivate
*priv
= purple_smiley_get_instance_private(smiley
);
76 g_free(priv
->shortcut
);
78 G_OBJECT_CLASS(purple_smiley_parent_class
)->finalize(obj
);
82 purple_smiley_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
85 PurpleSmiley
*smiley
= PURPLE_SMILEY(obj
);
89 g_value_set_string(value
, purple_smiley_get_shortcut(smiley
));
92 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
98 purple_smiley_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
101 PurpleSmiley
*smiley
= PURPLE_SMILEY(obj
);
105 _purple_smiley_set_shortcut(smiley
, g_value_get_string(value
));
108 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
114 purple_smiley_class_init(PurpleSmileyClass
*klass
) {
115 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
117 obj_class
->get_property
= purple_smiley_get_property
;
118 obj_class
->set_property
= purple_smiley_set_property
;
119 obj_class
->finalize
= purple_smiley_finalize
;
121 properties
[PROP_SHORTCUT
] = g_param_spec_string(
124 "A non-escaped textual representation of a smiley.",
126 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
129 g_object_class_install_properties(obj_class
, PROP_LAST
, properties
);
132 /*******************************************************************************
134 ******************************************************************************/
136 purple_smiley_new(const gchar
*shortcut
, const gchar
*path
)
138 PurpleSmiley
*smiley
= NULL
;
139 GBytes
*bytes
= NULL
;
140 gchar
*contents
= NULL
;
143 g_return_val_if_fail(shortcut
!= NULL
, NULL
);
144 g_return_val_if_fail(path
!= NULL
, NULL
);
146 if(!g_file_get_contents(path
, &contents
, &length
, NULL
)) {
150 bytes
= g_bytes_new_take(contents
, length
);
152 smiley
= g_object_new(
156 "shortcut", shortcut
,
160 g_bytes_unref(bytes
);
166 purple_smiley_new_from_data(const gchar
*shortcut
,
170 PurpleSmiley
*smiley
= NULL
;
171 GBytes
*bytes
= NULL
;
173 g_return_val_if_fail(shortcut
!= NULL
, NULL
);
175 bytes
= g_bytes_new(data
, length
);
177 smiley
= g_object_new(
179 "shortcut", shortcut
,
184 g_bytes_unref(bytes
);
191 purple_smiley_new_remote(const gchar
*shortcut
) {
192 g_return_val_if_fail(shortcut
!= NULL
, NULL
);
196 "shortcut", shortcut
,
202 purple_smiley_get_shortcut(PurpleSmiley
*smiley
)
204 PurpleSmileyPrivate
*priv
= NULL
;
206 g_return_val_if_fail(PURPLE_IS_SMILEY(smiley
), NULL
);
208 priv
= purple_smiley_get_instance_private(smiley
);
210 return priv
->shortcut
;