/pidgin/main: e62c5033bd54: PurpleImage: drop get_image class ca...

Tomasz Wasilczyk twasilczyk at pidgin.im
Sat Apr 12 20:11:10 EDT 2014


Changeset: e62c5033bd54603c6fff65038a0417a2e82ad374
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-13 02:11 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/e62c5033bd54

Description:

PurpleImage: drop get_image class callback and path property

diffstat:

 libpurple/smiley.c |  80 ++++++++++++-----------------------------------------
 libpurple/smiley.h |  11 +++----
 2 files changed, 23 insertions(+), 68 deletions(-)

diffs (204 lines):

diff --git a/libpurple/smiley.c b/libpurple/smiley.c
--- a/libpurple/smiley.c
+++ b/libpurple/smiley.c
@@ -32,7 +32,6 @@
 
 typedef struct {
 	gchar *shortcut;
-	gchar *path;
 	PurpleImage *image;
 } PurpleSmileyPrivate;
 
@@ -40,7 +39,6 @@ enum
 {
 	PROP_0,
 	PROP_SHORTCUT,
-	PROP_PATH,
 	PROP_LAST
 };
 
@@ -54,13 +52,25 @@ static GParamSpec *properties[PROP_LAST]
 PurpleSmiley *
 purple_smiley_new(const gchar *shortcut, const gchar *path)
 {
+	PurpleSmiley *smiley;
+	PurpleSmileyPrivate *priv;
+
 	g_return_val_if_fail(shortcut != NULL, NULL);
 	g_return_val_if_fail(path != NULL, NULL);
 
-	return g_object_new(PURPLE_TYPE_SMILEY,
+	smiley = g_object_new(PURPLE_TYPE_SMILEY,
 		"shortcut", shortcut,
-		"path", path,
 		NULL);
+	priv = PURPLE_SMILEY_GET_PRIVATE(smiley);
+
+	priv->image = purple_image_new_from_file(path, FALSE);
+	if (!priv->image) {
+		purple_debug_error("smiley", "Couldn't load smiley data ");
+		g_object_unref(smiley);
+		return NULL;
+	}
+
+	return smiley;
 }
 
 PurpleSmiley *
@@ -91,56 +101,17 @@ purple_smiley_get_shortcut(const PurpleS
 	return priv->shortcut;
 }
 
-static const gchar *
-purple_smiley_get_path(PurpleSmiley *smiley)
+PurpleImage *
+purple_smiley_get_image(PurpleSmiley *smiley)
 {
 	PurpleSmileyPrivate *priv = PURPLE_SMILEY_GET_PRIVATE(smiley);
 
-	g_return_val_if_fail(priv != NULL, FALSE);
+	g_return_val_if_fail(priv != NULL, NULL);
+	g_return_val_if_fail(priv->image != NULL, NULL);
 
-	return priv->path;
-}
-
-static PurpleImage *
-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_image_new_from_file(path, TRUE);
-	if (!priv->image) {
-		purple_debug_error("smiley", "Couldn't load smiley data ");
-		return NULL;
-	}
 	return priv->image;
 }
 
-PurpleImage *
-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
@@ -160,7 +131,6 @@ purple_smiley_finalize(GObject *obj)
 	PurpleSmileyPrivate *priv = PURPLE_SMILEY_GET_PRIVATE(smiley);
 
 	g_free(priv->shortcut);
-	g_free(priv->path);
 
 	if (priv->image)
 		g_object_unref(priv->image);
@@ -181,9 +151,6 @@ purple_smiley_get_property(GObject *obje
 		case PROP_SHORTCUT:
 			g_value_set_string(value, priv->shortcut);
 			break;
-		case PROP_PATH:
-			g_value_set_string(value, priv->path);
-			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
 			break;
@@ -202,10 +169,6 @@ purple_smiley_set_property(GObject *obje
 			g_free(priv->shortcut);
 			priv->shortcut = g_strdup(g_value_get_string(value));
 			break;
-		case PROP_PATH:
-			g_free(priv->path);
-			priv->path = g_strdup(g_value_get_string(value));
-			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
 			break;
@@ -216,7 +179,6 @@ 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);
 
@@ -226,16 +188,10 @@ 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",
 		"A non-escaped textual representation of a smiley.", NULL,
 		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
-	properties[PROP_PATH] = g_param_spec_string("path", "Path",
-		"The full path to the smiley image file.", NULL,
-		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
 	g_object_class_install_properties(gobj_class, PROP_LAST, properties);
 }
 
diff --git a/libpurple/smiley.h b/libpurple/smiley.h
--- a/libpurple/smiley.h
+++ b/libpurple/smiley.h
@@ -64,8 +64,6 @@ struct _PurpleSmiley
 
 /**
  * PurpleSmileyClass:
- * @get_image: gets image contents for a @smiley. May not require
- *             #PurpleSmiley:path being set. See #purple_smiley_get_image.
  *
  * Base class for #PurpleSmiley objects.
  */
@@ -74,9 +72,6 @@ struct _PurpleSmileyClass
 	/*< private >*/
 	GObjectClass parent_class;
 
-	/*< public >*/
-	PurpleImage * (*get_image)(PurpleSmiley *smiley);
-
 	/*< private >*/
 	void (*purple_reserved1)(void);
 	void (*purple_reserved2)(void);
@@ -109,6 +104,8 @@ purple_smiley_new(const gchar *shortcut,
 
 /**
  * Consider using #purple_conversation_add_remote_smiley.
+ *
+ * TODO: desc
  */
 PurpleSmiley *
 purple_smiley_new_remote(const gchar *shortcut);
@@ -129,7 +126,9 @@ purple_smiley_get_shortcut(const PurpleS
  * purple_smiley_get_image:
  * @smiley: the smiley.
  *
- * Returns (and possibly loads) the image contents for a @smiley.
+ * Returns the image contents for a @smiley. It may not be ready for remote
+ * smileys, so check it with #purple_image_is_ready.
+ *
  * If you want to save it, increase a ref count for the returned object.
  *
  * Returns: (transfer none): the image contents for a @smiley.



More information about the Commits mailing list