/dev/tomkiewicz/new-smileys: d71c41a54bb3: Smileys: implement ge...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Fri Apr 4 10:02:22 EDT 2014
Changeset: d71c41a54bb3b7390853f3be1b21b2283ad21935
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-04 16:02 +0200
Branch: default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/d71c41a54bb3
Description:
Smileys: implement get_image interface
diffstat:
libpurple/smiley-remote.c | 37 ++++++++++++++++++++++++++++++++++++-
libpurple/smiley.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
libpurple/smiley.h | 8 ++++++++
3 files changed, 91 insertions(+), 1 deletions(-)
diffs (205 lines):
diff --git a/libpurple/smiley-remote.c b/libpurple/smiley-remote.c
--- a/libpurple/smiley-remote.c
+++ b/libpurple/smiley-remote.c
@@ -31,6 +31,7 @@
typedef struct {
GString *contents;
+ PurpleStoredImage *image; /* it's not the same as in parent */
gboolean failed;
} PurpleRemoteSmileyPrivate;
@@ -87,6 +88,8 @@ purple_remote_smiley_close(PurpleRemoteS
g_return_if_fail(priv != NULL);
g_return_if_fail(!priv->failed);
g_return_if_fail(!purple_smiley_is_ready(PURPLE_SMILEY(smiley)));
+ g_return_if_fail(priv->contents != NULL);
+ g_return_if_fail(priv->image == NULL);
if (priv->contents->len == 0) {
purple_debug_error("smiley-remote", "Smiley is empty");
@@ -94,6 +97,12 @@ purple_remote_smiley_close(PurpleRemoteS
return;
}
+ priv->image = purple_imgstore_new(priv->contents->str,
+ priv->contents->len, NULL);
+ g_return_if_fail(priv->image != NULL);
+ g_string_free(priv->contents, FALSE);
+ priv->contents = NULL;
+
g_object_set(smiley, "is-ready", TRUE, NULL);
/* TODO: call ready signal */
}
@@ -114,6 +123,26 @@ purple_remote_smiley_failed(PurpleRemote
/* TODO: call failed signal */
}
+static PurpleStoredImage *
+purple_remote_smiley_get_image_impl(PurpleSmiley *smiley)
+{
+ PurpleRemoteSmileyPrivate *priv =
+ PURPLE_REMOTE_SMILEY_GET_PRIVATE(smiley);
+
+ g_return_val_if_fail(priv != NULL, FALSE);
+
+ if (purple_smiley_get_path(smiley))
+ return PURPLE_SMILEY_CLASS(parent_class)->get_image(smiley);
+
+ if (!priv->image) {
+ purple_debug_error("smiley-remote",
+ "Remote smiley is not ready yet");
+ return NULL;
+ }
+
+ return priv->image;
+}
+
/******************************************************************************
* Object stuff
******************************************************************************/
@@ -135,7 +164,10 @@ purple_remote_smiley_finalize(GObject *o
PurpleRemoteSmileyPrivate *priv =
PURPLE_REMOTE_SMILEY_GET_PRIVATE(smiley);
- g_string_free(priv->contents, TRUE);
+ if (priv->contents)
+ g_string_free(priv->contents, TRUE);
+ if (priv->image)
+ purple_imgstore_unref(priv->image);
G_OBJECT_CLASS(parent_class)->finalize(obj);
}
@@ -174,6 +206,7 @@ static void
purple_remote_smiley_class_init(PurpleRemoteSmileyClass *klass)
{
GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
+ PurpleSmileyClass *ps_class = PURPLE_SMILEY_CLASS(klass);
parent_class = g_type_class_peek_parent(klass);
@@ -181,6 +214,8 @@ purple_remote_smiley_class_init(PurpleRe
gobj_class->finalize = purple_remote_smiley_finalize;
+ ps_class->get_image = purple_remote_smiley_get_image_impl;
+
#if 0
gobj_class->get_property = purple_remote_smiley_get_property;
gobj_class->set_property = purple_remote_smiley_set_property;
diff --git a/libpurple/smiley.c b/libpurple/smiley.c
--- a/libpurple/smiley.c
+++ b/libpurple/smiley.c
@@ -34,6 +34,7 @@
typedef struct {
gchar *shortcut;
gchar *path;
+ PurpleStoredImage *image;
gboolean is_ready;
} PurpleSmileyPrivate;
@@ -103,6 +104,46 @@ purple_smiley_get_path(PurpleSmiley *smi
return priv->path;
}
+static PurpleStoredImage *
+purple_smiley_get_image_impl(PurpleSmiley *smiley)
+{
+ PurpleSmileyPrivate *priv = PURPLE_SMILEY_GET_PRIVATE(smiley);
+ const gchar *path;
+
+ g_return_val_if_fail(priv != NULL, FALSE);
+
+ if (priv->image)
+ return priv->image;
+
+ path = purple_smiley_get_path(smiley);
+
+ if (!path) {
+ purple_debug_error("smiley", "Can't get smiley data "
+ "without a path");
+ return NULL;
+ }
+
+ priv->image = purple_imgstore_new_from_file(path);
+ if (!priv->image) {
+ purple_debug_error("smiley", "Couldn't load smiley data ");
+ return NULL;
+ }
+ return priv->image;
+}
+
+PurpleStoredImage *
+purple_smiley_get_image(PurpleSmiley *smiley)
+{
+ PurpleSmileyClass *klass;
+
+ g_return_val_if_fail(PURPLE_IS_SMILEY(smiley), NULL);
+ klass = PURPLE_SMILEY_GET_CLASS(smiley);
+ g_return_val_if_fail(klass != NULL, NULL);
+ g_return_val_if_fail(klass->get_image != NULL, NULL);
+
+ return klass->get_image(smiley);
+}
+
/*******************************************************************************
* Object stuff
@@ -124,6 +165,9 @@ purple_smiley_finalize(GObject *obj)
g_free(priv->shortcut);
g_free(priv->path);
+ if (priv->image)
+ purple_imgstore_unref(priv->image);
+
PURPLE_DBUS_UNREGISTER_POINTER(smiley);
}
@@ -179,6 +223,7 @@ static void
purple_smiley_class_init(PurpleSmileyClass *klass)
{
GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
+ PurpleSmileyClass *ps_class = PURPLE_SMILEY_CLASS(klass);
parent_class = g_type_class_peek_parent(klass);
@@ -188,6 +233,8 @@ purple_smiley_class_init(PurpleSmileyCla
gobj_class->set_property = purple_smiley_set_property;
gobj_class->finalize = purple_smiley_finalize;
+ ps_class->get_image = purple_smiley_get_image_impl;
+
properties[PROP_SHORTCUT] = g_param_spec_string("shortcut", "Shortcut",
"The text-shortcut for the smiley", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
diff --git a/libpurple/smiley.h b/libpurple/smiley.h
--- a/libpurple/smiley.h
+++ b/libpurple/smiley.h
@@ -60,6 +60,8 @@ struct _PurpleSmileyClass
/*< private >*/
GObjectClass parent_class;
+ PurpleStoredImage * (*get_image)(PurpleSmiley *smiley);
+
void (*purple_reserved1)(void);
void (*purple_reserved2)(void);
void (*purple_reserved3)(void);
@@ -112,12 +114,18 @@ purple_smiley_is_ready(const PurpleSmile
*
* Returns a full path to a smiley file.
*
+ * A smiley may not be saved to disk (the path will be NULL), but could still be
+ * accessible using purple_smiley_get_data.
+ *
* Returns: A full path to the file, or %NULL under various conditions.
* The caller should use g_free to free the returned string.
*/
const gchar *
purple_smiley_get_path(PurpleSmiley *smiley);
+PurpleStoredImage *
+purple_smiley_get_image(PurpleSmiley *smiley);
+
G_END_DECLS
#endif /* _PURPLE_SMILEY_H_ */
More information about the Commits
mailing list