/soc/2013/ankitkv/gobjectification: 38043ecaf4a6: Finished imple...
Ankit Vani
a at nevitus.org
Sat Aug 31 15:28:41 EDT 2013
Changeset: 38043ecaf4a62c6ec3d9cf97d126c8882bb12591
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-01 00:36 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/38043ecaf4a6
Description:
Finished implementing functions for protocols.[ch].
Moved PurpleBuddyIconSpec to buddyicon.[ch].
diffstat:
libpurple/buddyicon.c | 58 ++++++++++++++++++++++++--
libpurple/buddyicon.h | 62 +++++++++++++++++++++++++++-
libpurple/protocol.c | 2 +-
libpurple/protocol.h | 1 +
libpurple/protocols.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++--
libpurple/protocols.h | 108 +++++--------------------------------------------
6 files changed, 226 insertions(+), 111 deletions(-)
diffs (truncated from 551 to 300 lines):
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -1103,7 +1103,55 @@ purple_buddy_icons_uninit()
cache_dir = NULL;
}
-void purple_buddy_icon_get_scale_size(PurpleBuddyIconSpec *spec, int *width, int *height)
+GType
+purple_buddy_icon_get_type(void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ type = g_boxed_type_register_static("PurpleBuddyIcon",
+ (GBoxedCopyFunc)purple_buddy_icon_ref,
+ (GBoxedFreeFunc)purple_buddy_icon_unref);
+ }
+
+ return type;
+}
+
+PurpleBuddyIconSpec *
+purple_buddy_icon_spec_new(char *format, int min_width, int min_height,
+ int max_width, int max_height, size_t max_filesize,
+ PurpleIconScaleRules scale_rules)
+{
+ PurpleBuddyIconSpec *icon_spec;
+
+ icon_spec = g_new0(PurpleBuddyIconSpec, 1);
+
+ icon_spec->format = format;
+ icon_spec->min_width = min_width;
+ icon_spec->min_height = min_height;
+ icon_spec->max_width = max_width;
+ icon_spec->max_height = max_height;
+ icon_spec->max_filesize = max_filesize;
+ icon_spec->scale_rules = scale_rules;
+
+ return icon_spec;
+}
+
+static PurpleBuddyIconSpec *
+purple_buddy_icon_spec_copy(PurpleBuddyIconSpec *icon_spec)
+{
+ PurpleBuddyIconSpec *icon_spec_copy;
+
+ g_return_val_if_fail(icon_spec != NULL, NULL);
+
+ icon_spec_copy = g_new0(PurpleBuddyIconSpec, 1);
+ *icon_spec_copy = *icon_spec;
+
+ return icon_spec_copy;
+}
+
+void purple_buddy_icon_spec_get_scaled_size(PurpleBuddyIconSpec *spec,
+ int *width, int *height)
{
int new_width, new_height;
@@ -1133,14 +1181,14 @@ void purple_buddy_icon_get_scale_size(Pu
}
GType
-purple_buddy_icon_get_type(void)
+purple_buddy_icon_spec_get_type(void)
{
static GType type = 0;
if (type == 0) {
- type = g_boxed_type_register_static("PurpleBuddyIcon",
- (GBoxedCopyFunc)purple_buddy_icon_ref,
- (GBoxedFreeFunc)purple_buddy_icon_unref);
+ type = g_boxed_type_register_static("PurpleBuddyIconSpec",
+ (GBoxedCopyFunc)purple_buddy_icon_spec_copy,
+ (GBoxedFreeFunc)g_free);
}
return type;
diff --git a/libpurple/buddyicon.h b/libpurple/buddyicon.h
--- a/libpurple/buddyicon.h
+++ b/libpurple/buddyicon.h
@@ -35,12 +35,39 @@
*/
typedef struct _PurpleBuddyIcon PurpleBuddyIcon;
+#define PURPLE_TYPE_BUDDY_ICON_SPEC (purple_buddy_icon_spec_get_type())
+
+/**
+ * A description of a Buddy Icon specification. This tells Purple what kind of
+ * image file it should give a protocol, and what kind of image file it should
+ * expect back. Dimensions less than 1 should be ignored and the image not
+ * scaled.
+ */
+typedef struct _PurpleBuddyIconSpec PurpleBuddyIconSpec;
+
#include "account.h"
#include "buddylist.h"
#include "imgstore.h"
#include "protocols.h"
#include "util.h"
+/** @copydoc PurpleBuddyIconSpec */
+struct _PurpleBuddyIconSpec {
+ /** This is a comma-delimited list of image formats or @c NULL if icons
+ * are not supported. Neither the core nor the protocol will actually
+ * check to see if the data it's given matches this; it's entirely up
+ * to the UI to do what it wants
+ */
+ char *format;
+
+ int min_width; /**< Minimum width of this icon */
+ int min_height; /**< Minimum height of this icon */
+ int max_width; /**< Maximum width of this icon */
+ int max_height; /**< Maximum height of this icon */
+ size_t max_filesize; /**< Maximum size in bytes */
+ PurpleIconScaleRules scale_rules; /**< How to stretch this icon */
+};
+
G_BEGIN_DECLS
/**************************************************************************/
@@ -388,14 +415,45 @@ void purple_buddy_icons_uninit(void);
/*@}*/
/**************************************************************************/
-/** @name Buddy Icon Helper API */
+/** @name Buddy Icon Spec API */
/**************************************************************************/
/*@{*/
/**
+ * Returns the GType for the #PurpleBuddyIconSpec boxed structure.
+ */
+GType purple_buddy_icon_spec_get_type(void);
+
+/**
+ * Creates a new #PurpleBuddyIconSpec instance.
+ *
+ * @param format A comma-delimited list of image formats or @c NULL if
+ * icons are not supported
+ * @param min_width Minimum width of an icon
+ * @param min_height Minimum height of an icon
+ * @param max_width Maximum width of an icon
+ * @param max_height Maximum height of an icon
+ * @param max_filesize Maximum file size in bytes
+ * @param scale_rules How to stretch this icon
+ *
+ * @return A new buddy icon spec.
+ */
+PurpleBuddyIconSpec *purple_buddy_icon_spec_new(char *format, int min_width,
+ int min_height, int max_width, int max_height, size_t max_filesize,
+ PurpleIconScaleRules scale_rules);
+
+/**
+ * Frees a #PurpleBuddyIconSpec instance.
+ *
+ * @param icon_spec The icon spec to destroy.
+ */
+void purple_buddy_icon_spec_free(PurpleBuddyIconSpec *icon_spec);
+
+/**
* Gets display size for a buddy icon
*/
-void purple_buddy_icon_get_scale_size(PurpleBuddyIconSpec *spec, int *width, int *height);
+void purple_buddy_icon_spec_get_scaled_size(PurpleBuddyIconSpec *spec,
+ int *width, int *height);
/*@}*/
diff --git a/libpurple/protocol.c b/libpurple/protocol.c
--- a/libpurple/protocol.c
+++ b/libpurple/protocol.c
@@ -175,7 +175,7 @@ purple_protocol_base_finalize(PurpleProt
klass->protocol_options);
}
- purple_buddy_icon_spec_destroy(klass->icon_spec);
+ purple_buddy_icon_spec_free(klass->icon_spec);
}
GType
diff --git a/libpurple/protocol.h b/libpurple/protocol.h
--- a/libpurple/protocol.h
+++ b/libpurple/protocol.h
@@ -48,6 +48,7 @@ typedef struct _PurpleProtocolInterface
#include "account.h"
#include "accountopt.h"
+#include "buddyicon.h"
#include "buddylist.h"
#include "connection.h"
#include "conversations.h"
diff --git a/libpurple/protocols.c b/libpurple/protocols.c
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -144,8 +144,70 @@ purple_attention_type_get_unlocalized_na
return type->unlocalized_name;
}
+/**************************************************************************
+ * GBoxed code for PurpleAttentionType
+ **************************************************************************/
+
+static PurpleAttentionType *
+purple_attention_type_copy(PurpleAttentionType *attn)
+{
+ PurpleAttentionType *attn_copy;
+
+ g_return_val_if_fail(attn != NULL, NULL);
+
+ attn_copy = g_new(PurpleAttentionType, 1);
+ *attn_copy = *attn;
+
+ return attn_copy;
+}
+
+GType
+purple_attention_type_get_type(void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ type = g_boxed_type_register_static("PurpleAttentionType",
+ (GBoxedCopyFunc)purple_attention_type_copy,
+ (GBoxedFreeFunc)g_free);
+ }
+
+ return type;
+}
+
+/**************************************************************************
+ * GBoxed code for PurpleProtocolChatEntry
+ **************************************************************************/
+
+static PurpleProtocolChatEntry *
+purple_protocol_chat_entry_copy(PurpleProtocolChatEntry *pce)
+{
+ PurpleProtocolChatEntry *pce_copy;
+
+ g_return_val_if_fail(pce != NULL, NULL);
+
+ pce_copy = g_new(PurpleProtocolChatEntry, 1);
+ *pce_copy = *pce;
+
+ return pce_copy;
+}
+
+GType
+purple_protocol_chat_entry_get_type(void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ type = g_boxed_type_register_static("PurpleProtocolChatEntry",
+ (GBoxedCopyFunc)purple_protocol_chat_entry_copy,
+ (GBoxedFreeFunc)g_free);
+ }
+
+ return type;
+}
+
/**************************************************************************/
-/** @name Protocol Plugin API */
+/** @name Protocol API */
/**************************************************************************/
void
purple_protocol_got_account_idle(PurpleAccount *account, gboolean idle,
@@ -375,7 +437,7 @@ do_protocol_change_account_status(Purple
*/
return;
- protocol = purple_find_protocol_info(purple_account_get_protocol_id(account));
+ protocol = purple_protocols_find(purple_account_get_protocol_id(account));
if (protocol == NULL)
return;
@@ -444,7 +506,7 @@ purple_protocol_send_attention(PurpleCon
g_return_if_fail(gc != NULL);
g_return_if_fail(who != NULL);
- protocol = purple_find_protocol_info(purple_account_get_protocol_id(purple_connection_get_account(gc)));
+ protocol = purple_protocols_find(purple_account_get_protocol_id(purple_connection_get_account(gc)));
g_return_if_fail(PURPLE_PROTOCOL_IMPLEMENTS(protocol, send_attention));
mtime = time(NULL);
@@ -614,6 +676,10 @@ purple_protocol_got_media_caps(PurpleAcc
#endif
}
+/**************************************************************************/
+/** @name Protocol Action API */
+/**************************************************************************/
+
PurpleProtocolAction *
purple_protocol_action_new(const char* label,
PurpleProtocolActionCallback callback)
@@ -640,11 +706,39 @@ purple_protocol_action_free(PurpleProtoc
}
More information about the Commits
mailing list