Wed, 04 Sep 2013 20:38:42 +0530
Added PurpleProtocolOverrideFlags and purple_protocol_override()
--- a/libpurple/Makefile.am Wed Sep 04 20:11:40 2013 +0530 +++ b/libpurple/Makefile.am Wed Sep 04 20:38:42 2013 +0530 @@ -195,6 +195,7 @@ conversation.h \ conversationtypes.h \ plugins.h \ + protocol.h \ protocols.h \ status.h
--- a/libpurple/protocol.c Wed Sep 04 20:11:40 2013 +0530 +++ b/libpurple/protocol.c Wed Sep 04 20:38:42 2013 +0530 @@ -85,6 +85,56 @@ 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 @@ { 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); }
--- a/libpurple/protocol.h Wed Sep 04 20:11:40 2013 +0530 +++ b/libpurple/protocol.h Wed Sep 04 20:38:42 2013 +0530 @@ -63,6 +63,19 @@ #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 @@ */ 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); + /*@}*/ /**************************************************************************/
--- a/libpurple/protocols.h Wed Sep 04 20:11:40 2013 +0530 +++ b/libpurple/protocols.h Wed Sep 04 20:38:42 2013 +0530 @@ -46,7 +46,8 @@ /** @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 @@ * * 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.
--- a/libpurple/protocols/yahoo/yahoojp.c Wed Sep 04 20:11:40 2013 +0530 +++ b/libpurple/protocols/yahoo/yahoojp.c Wed Sep 04 20:38:42 2013 +0530 @@ -94,7 +94,7 @@ 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);