/soc/2013/ankitkv/gobjectification: 313d07370a7b: Use the protoc...
Ankit Vani
a at nevitus.org
Sun Sep 15 03:32:30 EDT 2013
Changeset: 313d07370a7bd7fa0d5d4c29e9efdf83568ae108
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-15 11:49 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/313d07370a7b
Description:
Use the protocol factory interface functions
diffstat:
libpurple/connection.c | 32 ++++++++++++++++++++++----------
libpurple/roomlist.c | 22 ++++++++++++++++++----
libpurple/whiteboard.c | 27 +++++++++++++++++++++------
libpurple/xfer.c | 33 ++++++++++++++++++++++++---------
4 files changed, 85 insertions(+), 29 deletions(-)
diffs (165 lines):
diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -903,11 +903,17 @@ void
}
}
- gc = g_object_new(PURPLE_TYPE_CONNECTION,
- PROP_PROTOCOL_S, protocol,
- PROP_PASSWORD_S, password,
- PROP_ACCOUNT_S, account,
- NULL);
+ if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY_IFACE, connection_new))
+ gc = purple_protocol_factory_iface_connection_new(protocol, account,
+ password);
+ else
+ gc = g_object_new(PURPLE_TYPE_CONNECTION,
+ PROP_PROTOCOL_S, protocol,
+ PROP_ACCOUNT_S, account,
+ PROP_PASSWORD_S, password,
+ NULL);
+
+ g_return_if_fail(gc != NULL);
if (regist)
{
@@ -963,11 +969,17 @@ void
return;
}
- gc = g_object_new(PURPLE_TYPE_CONNECTION,
- PROP_PROTOCOL_S, protocol,
- PROP_PASSWORD_S, password,
- PROP_ACCOUNT_S, account,
- NULL);
+ if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY_IFACE, connection_new))
+ gc = purple_protocol_factory_iface_connection_new(protocol, account,
+ password);
+ else
+ gc = g_object_new(PURPLE_TYPE_CONNECTION,
+ PROP_PROTOCOL_S, protocol,
+ PROP_ACCOUNT_S, account,
+ PROP_PASSWORD_S, password,
+ NULL);
+
+ g_return_if_fail(gc != NULL);
purple_debug_info("connection", "Unregistering. gc = %p\n", gc);
diff --git a/libpurple/roomlist.c b/libpurple/roomlist.c
--- a/libpurple/roomlist.c
+++ b/libpurple/roomlist.c
@@ -419,12 +419,26 @@ purple_roomlist_get_type(void)
PurpleRoomlist *purple_roomlist_new(PurpleAccount *account)
{
+ PurpleRoomlist *list;
+ PurpleProtocol *protocol;
+
g_return_val_if_fail(account != NULL, NULL);
- return g_object_new(PURPLE_TYPE_ROOMLIST,
- PROP_ACCOUNT_S, account,
- NULL
- );
+ protocol = purple_protocols_find(purple_account_get_protocol_id(account));
+
+ g_return_val_if_fail(protocol != NULL, NULL);
+
+ if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY_IFACE, roomlist_new))
+ list = purple_protocol_factory_iface_roomlist_new(protocol, account);
+ else
+ list = g_object_new(PURPLE_TYPE_ROOMLIST,
+ PROP_ACCOUNT_S, account,
+ NULL
+ );
+
+ g_return_val_if_fail(list != NULL, NULL);
+
+ return list;
}
/*@}*/
diff --git a/libpurple/whiteboard.c b/libpurple/whiteboard.c
--- a/libpurple/whiteboard.c
+++ b/libpurple/whiteboard.c
@@ -507,13 +507,28 @@ purple_whiteboard_get_type(void)
PurpleWhiteboard *purple_whiteboard_new(PurpleAccount *account, const char *who, int state)
{
+ PurpleWhiteboard *wb;
+ PurpleProtocol *protocol;
+
g_return_val_if_fail(account != NULL, NULL);
g_return_val_if_fail(who != NULL, NULL);
- return g_object_new(PURPLE_TYPE_WHITEBOARD,
- PROP_ACCOUNT_S, account,
- PROP_WHO_S, who,
- PROP_STATE_S, state,
- NULL
- );
+ protocol = purple_protocols_find(purple_account_get_protocol_id(account));
+
+ g_return_val_if_fail(protocol != NULL, NULL);
+
+ if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY_IFACE, whiteboard_new))
+ wb = purple_protocol_factory_iface_whiteboard_new(protocol, account,
+ who, state);
+ else
+ wb = g_object_new(PURPLE_TYPE_WHITEBOARD,
+ PROP_ACCOUNT_S, account,
+ PROP_WHO_S, who,
+ PROP_STATE_S, state,
+ NULL
+ );
+
+ g_return_val_if_fail(wb != NULL, NULL);
+
+ return wb;
}
diff --git a/libpurple/xfer.c b/libpurple/xfer.c
--- a/libpurple/xfer.c
+++ b/libpurple/xfer.c
@@ -2327,16 +2327,31 @@ purple_xfer_get_type(void)
PurpleXfer *
purple_xfer_new(PurpleAccount *account, PurpleXferType type, const char *who)
{
+ PurpleXfer *xfer;
+ PurpleProtocol *protocol;
+
g_return_val_if_fail(type != PURPLE_XFER_TYPE_UNKNOWN, NULL);
- g_return_val_if_fail(account != NULL, NULL);
- g_return_val_if_fail(who != NULL, NULL);
-
- return g_object_new(PURPLE_TYPE_XFER,
- PROP_TYPE_S, type,
- PROP_ACCOUNT_S, account,
- PROP_REMOTE_USER_S, who,
- NULL
- );
+ g_return_val_if_fail(account != NULL, NULL);
+ g_return_val_if_fail(who != NULL, NULL);
+
+ protocol = purple_protocols_find(purple_account_get_protocol_id(account));
+
+ g_return_val_if_fail(protocol != NULL, NULL);
+
+ if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, FACTORY_IFACE, xfer_new))
+ xfer = purple_protocol_factory_iface_xfer_new(protocol, account, type,
+ who);
+ else
+ xfer = g_object_new(PURPLE_TYPE_XFER,
+ PROP_ACCOUNT_S, account,
+ PROP_TYPE_S, type,
+ PROP_REMOTE_USER_S, who,
+ NULL
+ );
+
+ g_return_val_if_fail(xfer != NULL, NULL);
+
+ return xfer;
}
/**************************************************************************
More information about the Commits
mailing list