/soc/2013/ankitkv/gobjectification: 7b1fefd1e2ee: Added protocol...

Ankit Vani a at nevitus.org
Sat Sep 7 12:16:17 EDT 2013


Changeset: 7b1fefd1e2eebfa148a5b532bf0fe1f13bae6c52
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-07 14:50 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/7b1fefd1e2ee

Description:

Added protocol interface methods connection_new, roomlist_new, whiteboard_new, xfer_new.
These functions can be used to return protocol-specific derived types.
'state' from PurpleWhiteboard has been removed since only yahoo uses it. Yahoo's whiteboard subclass can handle this.

diffstat:

 libpurple/connection.c |  30 ++++++++++++++++--------
 libpurple/protocol.c   |  32 +++++++++++++++++++++++++
 libpurple/protocol.h   |  48 ++++++++++++++++++++++++++++++++++++++
 libpurple/roomlist.c   |  22 ++++++++++++++---
 libpurple/whiteboard.c |  62 ++++++++++++++++---------------------------------
 libpurple/whiteboard.h |  20 +---------------
 libpurple/xfer.c       |  26 ++++++++++++++++----
 7 files changed, 159 insertions(+), 81 deletions(-)

diffs (truncated from 391 to 300 lines):

diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -903,11 +903,16 @@ 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, connection_new))
+		gc = purple_protocol_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 +968,16 @@ 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, connection_new))
+		gc = purple_protocol_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/protocol.c b/libpurple/protocol.c
--- a/libpurple/protocol.c
+++ b/libpurple/protocol.c
@@ -255,6 +255,38 @@ purple_protocol_iface_get_type(void)
 	else \
 		return defaultreturn;
 
+PurpleConnection *
+purple_protocol_iface_connection_new(PurpleProtocol *protocol,
+                                     PurpleAccount *account,
+                                     const char *password)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, connection_new, protocol,
+	                                 account, password);
+}
+
+PurpleRoomlist *
+purple_protocol_iface_roomlist_new(PurpleProtocol *protocol,
+                                   PurpleAccount *account)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, roomlist_new, account);
+}
+
+PurpleWhiteboard *
+purple_protocol_iface_whiteboard_new(PurpleProtocol *protocol,
+                                     PurpleAccount *account, const char *who)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, whiteboard_new, account,
+	                                 who);
+}
+
+PurpleXfer *
+purple_protocol_iface_xfer_new(PurpleProtocol *protocol, PurpleAccount *account,
+                               PurpleXferType type, const char *who)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, xfer_new, account, type,
+	                                 who);
+}
+
 GList *
 purple_protocol_iface_get_actions(PurpleProtocol *protocol,
                                   PurpleConnection *gc)
diff --git a/libpurple/protocol.h b/libpurple/protocol.h
--- a/libpurple/protocol.h
+++ b/libpurple/protocol.h
@@ -128,6 +128,34 @@ struct _PurpleProtocolInterface
 	GTypeInterface parent_iface;
 
 	/**
+	 * Creates a new protocol-specific connection object that inherits
+	 * PurpleConnection.
+	 */
+	PurpleConnection *(*connection_new)(PurpleProtocol *protocol,
+	                                    PurpleAccount *account,
+	                                    const char *password);
+
+	/**
+	 * Creates a new protocol-specific room list object that inherits
+	 * PurpleRoomlist.
+	 */
+	PurpleRoomlist *(*roomlist_new)(PurpleAccount *account);
+
+	/**
+	 * Creates a new protocol-specific whiteboard object that inherits
+	 * PurpleWhiteboard.
+	 */
+	PurpleWhiteboard *(*whiteboard_new)(PurpleAccount *account,
+	                                    const char *who);
+
+	/**
+	 * Creates a new protocol-specific file transfer object that inherits
+	 * PurpleXfer.
+	 */
+	PurpleXfer *(*xfer_new)(PurpleAccount *account, PurpleXferType type,
+	                        const char *who);
+
+	/**
 	 * Returns the actions the protocol can perform. These will show up in the
 	 * Accounts menu, under a submenu with the name of the account.
 	 */
@@ -732,6 +760,26 @@ void purple_protocol_override(PurpleProt
  */
 GType purple_protocol_iface_get_type(void);
 
+/** @copydoc  _PurpleProtocolInterface::connection_new */
+PurpleConnection *purple_protocol_iface_connection_new(PurpleProtocol *protocol,
+                                                       PurpleAccount *account,
+                                                       const char *password);
+
+/** @copydoc  _PurpleProtocolInterface::roomlist_new */
+PurpleRoomlist *purple_protocol_iface_roomlist_new(PurpleProtocol *,
+                                                   PurpleAccount *account);
+
+/** @copydoc  _PurpleProtocolInterface::whiteboard_new */
+PurpleWhiteboard *purple_protocol_iface_whiteboard_new(PurpleProtocol *,
+                                                       PurpleAccount *account,
+                                                       const char *who);
+
+/** @copydoc  _PurpleProtocolInterface::xfer_new */
+PurpleXfer *purple_protocol_iface_xfer_new(PurpleProtocol *,
+                                           PurpleAccount *account,
+                                           PurpleXferType type,
+                                           const char *who);
+
 /** @copydoc  _PurpleProtocolInterface::get_actions */
 GList *purple_protocol_iface_get_actions(PurpleProtocol *, PurpleConnection *);
 
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, roomlist_new))
+		list = purple_protocol_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
@@ -34,8 +34,6 @@ typedef struct _PurpleWhiteboardPrivate 
 /** Private data for a whiteboard */
 struct _PurpleWhiteboardPrivate
 {
-	int state;                      /**< State of whiteboard session          */
-
 	PurpleAccount *account;         /**< Account associated with this session */
 	char *who;                      /**< Name of the remote user              */
 
@@ -52,7 +50,6 @@ struct _PurpleWhiteboardPrivate
 enum
 {
 	PROP_0,
-	PROP_STATE,
 	PROP_ACCOUNT,
 	PROP_WHO,
 	PROP_DRAW_LIST,
@@ -106,24 +103,6 @@ const char *purple_whiteboard_get_who(co
 	return priv->who;	
 }
 
-void purple_whiteboard_set_state(PurpleWhiteboard *wb, int state)
-{
-	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
-
-	g_return_if_fail(priv != NULL);
-
-	priv->state = state;
-}
-
-int purple_whiteboard_get_state(const PurpleWhiteboard *wb)
-{
-	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
-
-	g_return_val_if_fail(priv != NULL, -1);
-
-	return priv->state;
-}
-
 void purple_whiteboard_start(PurpleWhiteboard *wb)
 {
 	/* Create frontend for whiteboard */
@@ -321,7 +300,6 @@ gpointer purple_whiteboard_get_ui_data(c
  * GObject code
  *****************************************************************************/
 /* GObject Property names */
-#define PROP_STATE_S      "state"
 #define PROP_ACCOUNT_S    "account"
 #define PROP_WHO_S        "who"
 #define PROP_DRAW_LIST_S  "draw-list"
@@ -335,9 +313,6 @@ purple_whiteboard_set_property(GObject *
 	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
 
 	switch (param_id) {
-		case PROP_STATE:
-			purple_whiteboard_set_state(wb, g_value_get_int(value));
-			break;
 		case PROP_ACCOUNT:
 			priv->account = g_value_get_object(value);
 			break;
@@ -361,9 +336,6 @@ purple_whiteboard_get_property(GObject *
 	PurpleWhiteboard *wb = PURPLE_WHITEBOARD(obj);
 
 	switch (param_id) {
-		case PROP_STATE:
-			g_value_set_int(value, purple_whiteboard_get_state(wb));
-			break;
 		case PROP_ACCOUNT:
 			g_value_set_object(value, purple_whiteboard_get_account(wb));
 			break;
@@ -451,13 +423,6 @@ purple_whiteboard_class_init(PurpleWhite
 	obj_class->get_property = purple_whiteboard_get_property;
 	obj_class->set_property = purple_whiteboard_set_property;
 
-	g_object_class_install_property(obj_class, PROP_STATE,
-			g_param_spec_int(PROP_STATE_S, _("State"),
-				_("State of the whiteboard."),
-				G_MININT, G_MAXINT, 0,
-				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
-			);
-
 	g_object_class_install_property(obj_class, PROP_ACCOUNT,
 			g_param_spec_object(PROP_ACCOUNT_S, _("Account"),
 				_("The whiteboard's account."), PURPLE_TYPE_ACCOUNT,
@@ -505,15 +470,28 @@ purple_whiteboard_get_type(void)
 	return type;
 }
 
-PurpleWhiteboard *purple_whiteboard_new(PurpleAccount *account, const char *who, int state)
+PurpleWhiteboard *purple_whiteboard_new(PurpleAccount *account, const char *who)
 {
+	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, whiteboard_new))
+		wb = purple_protocol_iface_whiteboard_new(protocol, account, who);



More information about the Commits mailing list