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
23 #include "glibcompat.h"
24 #include "dbus-maybe.h"
30 #define PURPLE_SMILEY_GET_PRIVATE(obj) \
31 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_SMILEY, PurpleSmileyPrivate))
36 } PurpleSmileyPrivate
;
45 static GObjectClass
*parent_class
;
46 static GParamSpec
*properties
[PROP_LAST
];
48 /*******************************************************************************
50 ******************************************************************************/
53 purple_smiley_new(const gchar
*shortcut
, const gchar
*path
)
56 PurpleSmileyPrivate
*priv
;
58 g_return_val_if_fail(shortcut
!= NULL
, NULL
);
59 g_return_val_if_fail(path
!= NULL
, NULL
);
61 smiley
= g_object_new(PURPLE_TYPE_SMILEY
,
64 priv
= PURPLE_SMILEY_GET_PRIVATE(smiley
);
66 priv
->image
= purple_image_new_from_file(path
, FALSE
);
68 purple_debug_error("smiley", "Couldn't load smiley data ");
69 g_object_unref(smiley
);
77 purple_smiley_new_remote(const gchar
*shortcut
)
80 PurpleSmileyPrivate
*priv
;
82 g_return_val_if_fail(shortcut
!= NULL
, NULL
);
84 smiley
= g_object_new(PURPLE_TYPE_SMILEY
,
87 priv
= PURPLE_SMILEY_GET_PRIVATE(smiley
);
89 priv
->image
= purple_image_transfer_new();
95 purple_smiley_get_shortcut(const PurpleSmiley
*smiley
)
97 PurpleSmileyPrivate
*priv
= PURPLE_SMILEY_GET_PRIVATE(smiley
);
99 g_return_val_if_fail(priv
!= NULL
, NULL
);
101 return priv
->shortcut
;
105 purple_smiley_get_image(PurpleSmiley
*smiley
)
107 PurpleSmileyPrivate
*priv
= PURPLE_SMILEY_GET_PRIVATE(smiley
);
109 g_return_val_if_fail(priv
!= NULL
, NULL
);
110 g_return_val_if_fail(priv
->image
!= NULL
, NULL
);
116 /*******************************************************************************
118 ******************************************************************************/
121 purple_smiley_init(GTypeInstance
*instance
, gpointer klass
)
123 PurpleSmiley
*smiley
= PURPLE_SMILEY(instance
);
124 PURPLE_DBUS_REGISTER_POINTER(smiley
, PurpleSmiley
);
128 purple_smiley_finalize(GObject
*obj
)
130 PurpleSmiley
*smiley
= PURPLE_SMILEY(obj
);
131 PurpleSmileyPrivate
*priv
= PURPLE_SMILEY_GET_PRIVATE(smiley
);
133 g_free(priv
->shortcut
);
136 g_object_unref(priv
->image
);
138 PURPLE_DBUS_UNREGISTER_POINTER(smiley
);
140 G_OBJECT_CLASS(parent_class
)->finalize(obj
);
144 purple_smiley_get_property(GObject
*object
, guint par_id
, GValue
*value
,
147 PurpleSmiley
*smiley
= PURPLE_SMILEY(object
);
148 PurpleSmileyPrivate
*priv
= PURPLE_SMILEY_GET_PRIVATE(smiley
);
152 g_value_set_string(value
, priv
->shortcut
);
155 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, par_id
, pspec
);
161 purple_smiley_set_property(GObject
*object
, guint par_id
, const GValue
*value
,
164 PurpleSmiley
*smiley
= PURPLE_SMILEY(object
);
165 PurpleSmileyPrivate
*priv
= PURPLE_SMILEY_GET_PRIVATE(smiley
);
169 g_free(priv
->shortcut
);
170 priv
->shortcut
= g_strdup(g_value_get_string(value
));
173 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, par_id
, pspec
);
179 purple_smiley_class_init(PurpleSmileyClass
*klass
)
181 GObjectClass
*gobj_class
= G_OBJECT_CLASS(klass
);
183 parent_class
= g_type_class_peek_parent(klass
);
185 g_type_class_add_private(klass
, sizeof(PurpleSmileyPrivate
));
187 gobj_class
->get_property
= purple_smiley_get_property
;
188 gobj_class
->set_property
= purple_smiley_set_property
;
189 gobj_class
->finalize
= purple_smiley_finalize
;
191 properties
[PROP_SHORTCUT
] = g_param_spec_string("shortcut", "Shortcut",
192 "A non-escaped textual representation of a smiley.", NULL
,
193 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
195 g_object_class_install_properties(gobj_class
, PROP_LAST
, properties
);
199 purple_smiley_get_type(void)
201 static GType type
= 0;
203 if (G_UNLIKELY(type
== 0)) {
204 static const GTypeInfo info
= {
205 .class_size
= sizeof(PurpleSmileyClass
),
206 .class_init
= (GClassInitFunc
)purple_smiley_class_init
,
207 .instance_size
= sizeof(PurpleSmiley
),
208 .instance_init
= purple_smiley_init
,
211 type
= g_type_register_static(G_TYPE_OBJECT
,
212 "PurpleSmiley", &info
, 0);