/soc/2013/ankitkv/gobjectification: 9807e4acf281: Added PurplePr...
Ankit Vani
a at nevitus.org
Wed Sep 4 11:09:07 EDT 2013
Changeset: 9807e4acf281f43ed2658dc5531f157c24faa2b2
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-04 20:38 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/9807e4acf281
Description:
Added PurpleProtocolOverrideFlags and purple_protocol_override()
diffstat:
libpurple/Makefile.am | 1 +
libpurple/protocol.c | 69 ++++++++++++++++++++++++++++--------
libpurple/protocol.h | 25 +++++++++++++
libpurple/protocols.h | 5 +-
libpurple/protocols/yahoo/yahoojp.c | 2 +-
5 files changed, 83 insertions(+), 19 deletions(-)
diffs (173 lines):
diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -195,6 +195,7 @@ purple_enumheaders = \
conversation.h \
conversationtypes.h \
plugins.h \
+ protocol.h \
protocols.h \
status.h
diff --git a/libpurple/protocol.c b/libpurple/protocol.c
--- a/libpurple/protocol.c
+++ b/libpurple/protocol.c
@@ -85,6 +85,56 @@ purple_protocol_get_whiteboard_ops(const
return protocol->whiteboard_ops;
}
+static void
+user_splits_free(PurpleProtocol *protocol)
+{
+ g_return_if_fail(protocol != NULL);
+
+ while (protocol->user_splits) {
+ PurpleAccountUserSplit *split = protocol->user_splits->data;
+ purple_account_user_split_destroy(split);
+ protocol->user_splits = g_list_delete_link(protocol->user_splits,
+ protocol->user_splits);
+ }
+}
+
+static void
+protocol_options_free(PurpleProtocol *protocol)
+{
+ g_return_if_fail(protocol != NULL);
+
+ while (protocol->protocol_options) {
+ PurpleAccountOption *option = protocol->protocol_options->data;
+ purple_account_option_destroy(option);
+ protocol->protocol_options =
+ g_list_delete_link(protocol->protocol_options,
+ protocol->protocol_options);
+ }
+}
+
+static void
+icon_spec_free(PurpleProtocol *protocol)
+{
+ g_return_if_fail(protocol != NULL);
+
+ purple_buddy_icon_spec_free(protocol->icon_spec);
+ protocol->icon_spec = NULL;
+}
+
+void
+purple_protocol_override(PurpleProtocol *protocol,
+ PurpleProtocolOverrideFlags flags)
+{
+ g_return_if_fail(PURPLE_IS_PROTOCOL(protocol));
+
+ if (flags & PURPLE_PROTOCOL_OVERRIDE_USER_SPLITS)
+ user_splits_free(protocol);
+ if (flags & PURPLE_PROTOCOL_OVERRIDE_PROTOCOL_OPTIONS)
+ protocol_options_free(protocol);
+ if (flags & PURPLE_PROTOCOL_OVERRIDE_ICON_SPEC)
+ icon_spec_free(protocol);
+}
+
/**************************************************************************
* GObject stuff
**************************************************************************/
@@ -132,22 +182,9 @@ purple_protocol_finalize(GObject *object
{
PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
- while (protocol->user_splits) {
- PurpleAccountUserSplit *split = protocol->user_splits->data;
- purple_account_user_split_destroy(split);
- protocol->user_splits = g_list_delete_link(protocol->user_splits,
- protocol->user_splits);
- }
-
- while (protocol->protocol_options) {
- PurpleAccountOption *option = protocol->protocol_options->data;
- purple_account_option_destroy(option);
- protocol->protocol_options =
- g_list_delete_link(protocol->protocol_options,
- protocol->protocol_options);
- }
-
- purple_buddy_icon_spec_free(protocol->icon_spec);
+ user_splits_free(protocol);
+ protocol_options_free(protocol);
+ icon_spec_free(protocol);
parent_class->finalize(object);
}
diff --git a/libpurple/protocol.h b/libpurple/protocol.h
--- a/libpurple/protocol.h
+++ b/libpurple/protocol.h
@@ -63,6 +63,19 @@ typedef struct _PurpleProtocolInterface
#include "whiteboard.h"
/**
+ * Flags to indicate what base protocol's data a derived protocol wants to
+ * override.
+ *
+ * @see purple_protocol_override()
+ */
+typedef enum /*< flags >*/
+{
+ PURPLE_PROTOCOL_OVERRIDE_USER_SPLITS = 1 << 1,
+ PURPLE_PROTOCOL_OVERRIDE_PROTOCOL_OPTIONS = 1 << 2,
+ PURPLE_PROTOCOL_OVERRIDE_ICON_SPEC = 1 << 3,
+} PurpleProtocolOverrideFlags;
+
+/**
* Represents an instance of a protocol registered with the protocols
* subsystem. Protocols must initialize the members to appropriate values.
*/
@@ -695,6 +708,18 @@ PurpleBuddyIconSpec *purple_protocol_get
*/
PurpleWhiteboardOps *purple_protocol_get_whiteboard_ops(const PurpleProtocol *protocol);
+/**
+ * Lets derived protocol types override the base type's instance data, such as
+ * protocol options, user splits, icon spec, etc.
+ * This function is called in the *_init() function of your derived protocol,
+ * to delete the parent type's data so you can define your own.
+ *
+ * @param protocol The protocol instance.
+ * @param flags What instance data to delete.
+ */
+void purple_protocol_override(PurpleProtocol *protocol,
+ PurpleProtocolOverrideFlags flags);
+
/*@}*/
/**************************************************************************/
diff --git a/libpurple/protocols.h b/libpurple/protocols.h
--- a/libpurple/protocols.h
+++ b/libpurple/protocols.h
@@ -46,7 +46,8 @@ typedef struct _PurpleAttentionType Purp
/** @name Basic Protocol Information */
/**************************************************************************/
-typedef enum {
+typedef enum /*< flags >*/
+{
PURPLE_ICON_SCALE_DISPLAY = 0x01, /**< We scale the icon when we display it */
PURPLE_ICON_SCALE_SEND = 0x02 /**< We scale the icon before we send it to the server */
} PurpleIconScaleRules;
@@ -62,7 +63,7 @@ typedef struct _PurpleProtocolChatEntry
*
* These should all be stuff that some protocols can do and others can't.
*/
-typedef enum
+typedef enum /*< flags >*/
{
/**
* User names are unique to a chat and are not shared between rooms.
diff --git a/libpurple/protocols/yahoo/yahoojp.c b/libpurple/protocols/yahoo/yahoojp.c
--- a/libpurple/protocols/yahoo/yahoojp.c
+++ b/libpurple/protocols/yahoo/yahoojp.c
@@ -94,7 +94,7 @@ yahoojp_protocol_init(PurpleProtocol *pr
protocol->name = "Yahoo JAPAN";
/* delete yahoo's protocol options */
- purple_protocol_options_free(protocol->protocol_options);
+ purple_protocol_override(protocol, PURPLE_PROTOCOL_OVERRIDE_PROTOCOL_OPTIONS);
option = purple_account_option_int_new(_("Pager port"), "port", YAHOO_PAGER_PORT);
protocol->protocol_options = g_list_append(protocol->protocol_options, option);
More information about the Commits
mailing list