Finished implementing functions for protocols.[ch]. soc.2013.gobjectification.plugins

Sun, 01 Sep 2013 00:36:19 +0530

author
Ankit Vani <a@nevitus.org>
date
Sun, 01 Sep 2013 00:36:19 +0530
branch
soc.2013.gobjectification.plugins
changeset 36624
38043ecaf4a6
parent 36623
caaadef03507
child 36625
e6febbd8cbec

Finished implementing functions for protocols.[ch].
Moved PurpleBuddyIconSpec to buddyicon.[ch].

libpurple/buddyicon.c file | annotate | diff | comparison | revisions
libpurple/buddyicon.h file | annotate | diff | comparison | revisions
libpurple/protocol.c file | annotate | diff | comparison | revisions
libpurple/protocol.h file | annotate | diff | comparison | revisions
libpurple/protocols.c file | annotate | diff | comparison | revisions
libpurple/protocols.h file | annotate | diff | comparison | revisions
--- a/libpurple/buddyicon.c	Sat Aug 31 23:22:35 2013 +0530
+++ b/libpurple/buddyicon.c	Sun Sep 01 00:36:19 2013 +0530
@@ -1103,7 +1103,55 @@
 	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 @@
 }
 
 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;
--- a/libpurple/buddyicon.h	Sat Aug 31 23:22:35 2013 +0530
+++ b/libpurple/buddyicon.h	Sun Sep 01 00:36:19 2013 +0530
@@ -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 @@
 /*@}*/
 
 /**************************************************************************/
-/** @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);
 
 /*@}*/
 
--- a/libpurple/protocol.c	Sat Aug 31 23:22:35 2013 +0530
+++ b/libpurple/protocol.c	Sun Sep 01 00:36:19 2013 +0530
@@ -175,7 +175,7 @@
 				klass->protocol_options);
 	}
 
-	purple_buddy_icon_spec_destroy(klass->icon_spec);
+	purple_buddy_icon_spec_free(klass->icon_spec);
 }
 
 GType
--- a/libpurple/protocol.h	Sat Aug 31 23:22:35 2013 +0530
+++ b/libpurple/protocol.h	Sun Sep 01 00:36:19 2013 +0530
@@ -48,6 +48,7 @@
 
 #include "account.h"
 #include "accountopt.h"
+#include "buddyicon.h"
 #include "buddylist.h"
 #include "connection.h"
 #include "conversations.h"
--- a/libpurple/protocols.c	Sat Aug 31 23:22:35 2013 +0530
+++ b/libpurple/protocols.c	Sun Sep 01 00:36:19 2013 +0530
@@ -144,8 +144,70 @@
 	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 @@
 		 */
 		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 @@
 	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 @@
 #endif
 }
 
+/**************************************************************************/
+/** @name Protocol Action API                                             */
+/**************************************************************************/
+
 PurpleProtocolAction *
 purple_protocol_action_new(const char* label,
 		PurpleProtocolActionCallback callback)
@@ -640,11 +706,39 @@
 }
 
 /**************************************************************************
+ * GBoxed code for PurpleProtocolAction
+ **************************************************************************/
+
+static PurpleProtocolAction *
+purple_protocol_action_copy(PurpleProtocolAction *action)
+{
+	g_return_val_if_fail(action != NULL, NULL);
+
+	return purple_protocol_action_new(action->label, action->callback);
+}
+
+GType
+purple_protocol_action_get_type(void)
+{
+	static GType type = 0;
+
+	if (type == 0) {
+		type = g_boxed_type_register_static("PurpleProtocolAction",
+				(GBoxedCopyFunc)purple_protocol_action_copy,
+				(GBoxedFreeFunc)purple_protocol_action_free);
+	}
+
+	return type;
+}
+
+/**************************************************************************
  * Protocols API
  **************************************************************************/
 PurpleProtocol *
-purple_find_protocol_info(const char *id)
+purple_protocols_find(const char *id)
 {
+	g_return_if_fail(protocols != NULL && id != NULL);
+
 	return g_hash_table_lookup(protocols, id);
 }
 
@@ -657,7 +751,7 @@
 	                     protocol_type != G_TYPE_NONE, NULL);
 
 	protocol = g_object_new(protocol_type, NULL);
-	if (purple_find_protocol_info(purple_protocol_get_id(protocol))) {
+	if (purple_protocols_find(purple_protocol_get_id(protocol))) {
 		g_object_unref(protocol);
 		return NULL;
 	}
@@ -669,7 +763,7 @@
 
 gboolean purple_protocols_remove(PurpleProtocol *protocol)
 {
-	if (purple_find_protocol_info(purple_protocol_get_id(protocol)) == NULL)
+	if (purple_protocols_find(purple_protocol_get_id(protocol)) == NULL)
 		return FALSE;
 
 	g_hash_table_remove(protocols, purple_protocol_get_id(protocol));
--- a/libpurple/protocols.h	Sat Aug 31 23:22:35 2013 +0530
+++ b/libpurple/protocols.h	Sun Sep 01 00:36:19 2013 +0530
@@ -49,24 +49,6 @@
 	PURPLE_ICON_SCALE_SEND = 0x02			/**< We scale the icon before we send it to the server */
 } PurpleIconScaleRules;
 
-#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 this 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;
-
-#define PURPLE_TYPE_THUMBNAIL_SPEC  (purple_thumbnail_spec_get_type())
-
-/**
- * A description of a file transfer thumbnail specification.
- * This tells the UI if and what image formats the protocol support for file
- * transfer thumbnails.
- */
-typedef struct _PurpleThumbnailSpec PurpleThumbnailSpec;
-
 /**
  * Represents an entry containing information that must be supplied by the
  * user when joining a chat.
@@ -168,26 +150,7 @@
 
 } PurpleProtocolOptions;
 
-/** @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 */
-};
-
-#include "media.h"
 #include "protocol.h"
-#include "status.h"
 
 #define PURPLE_TYPE_PROTOCOL_CHAT_ENTRY  (purple_protocol_chat_entry_get_type())
 
@@ -220,7 +183,7 @@
 /**************************************************************************/
 /*@{*/
 
-/** TODO
+/**
  * Returns the GType for the #PurpleAttentionType boxed structure.
  */
 GType purple_attention_type_get_type(void);
@@ -337,12 +300,12 @@
 /**************************************************************************/
 /*@{*/
 
-/** TODO
+/**
  * Returns the GType for the #PurpleProtocolAction boxed structure.
  */
 GType purple_protocol_action_get_type(void);
 
-/** TODO A sanity check is needed
+/**
  * Allocates and returns a new PurpleProtocolAction. Use this to add actions in
  * a list in the get_actions function of the protocol.
  *
@@ -352,7 +315,7 @@
 PurpleProtocolAction *purple_protocol_action_new(const char* label,
 		PurpleProtocolActionCallback callback);
 
-/** TODO A sanity check is needed
+/**
  * Frees a PurpleProtocolAction
  *
  * @param action The PurpleProtocolAction to free.
@@ -362,60 +325,11 @@
 /*@}*/
 
 /**************************************************************************/
-/** @name Buddy Icon Spec API                                             */
-/**************************************************************************/
-/*@{*/
-
-/** TODO
- * Returns the GType for the #PurpleBuddyIconSpec boxed structure.
- */
-GType purple_buddy_icon_spec_get_type(void);
-
-/** TODO
- * 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);
-
-/** TODO needed?
- * Destroys a #PurpleBuddyIconSpec instance.
- *
- * @param icon_spec  The icon spec to destroy.
- */
-void purple_buddy_icon_spec_destroy(PurpleBuddyIconSpec *icon_spec);
-
-/*@}*/
-
-/**************************************************************************/
-/** @name Thumbnail API                                                   */
-/**************************************************************************/
-/*@{*/
-
-/** TODO
- * Returns the GType for the #PurpleThumbnailSpec boxed structure.
- */
-GType purple_thumbnail_spec_get_type(void);
-
-/*@}*/
-
-/**************************************************************************/
 /** @name Protocol Chat Entry API                                         */
 /**************************************************************************/
 /*@{*/
 
-/** TODO
+/**
  * Returns the GType for the #PurpleProtocolChatEntry boxed structure.
  */
 GType purple_protocol_chat_entry_get_type(void);
@@ -639,14 +553,14 @@
 /**************************************************************************/
 /*@{*/
 
-/** TODO rename
+/**
  * Finds a protocol by ID.
  *
  * @param id The protocol's ID.
  */
-PurpleProtocol *purple_find_protocol_info(const char *id);
+PurpleProtocol *purple_protocols_find(const char *id);
 
-/** TODO A sanity check is needed
+/**
  * Adds a protocol to the list of protocols.
  *
  * @param protocol_type  The type of the protocol to add.
@@ -655,7 +569,7 @@
  */
 PurpleProtocol *purple_protocols_add(GType protocol_type);
 
-/** TODO A sanity check is needed
+/**
  * Removes a protocol from the list of protocols. This will disconnect all
  * connected accounts using this protocol, and free the protocol's user splits
  * and protocol options.
@@ -666,7 +580,7 @@
  */
 gboolean purple_protocols_remove(PurpleProtocol *protocol);
 
-/** TODO A sanity check is needed
+/**
  * Returns a list of all loaded protocols.
  *
  * @constreturn A list of all loaded protocols.
@@ -685,7 +599,7 @@
  */
 void purple_protocols_init(void);
 
-/** TODO Make protocols use this handle, instead of plugins handle
+/**
  * Returns the protocols subsystem handle.
  *
  * @return The protocols subsystem handle.

mercurial