/soc/2013/ankitkv/gobjectification: 9da9eeae0cc4: Refactored mxi...
Ankit Vani
a at nevitus.org
Sun Aug 11 16:23:13 EDT 2013
Changeset: 9da9eeae0cc4fd9543a2cbedb23f123506dbfdf2
Author: Ankit Vani <a at nevitus.org>
Date: 2013-08-12 01:52 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/9da9eeae0cc4
Description:
Refactored mxit to use the new plugin API
diffstat:
libpurple/protocols/mxit/actions.c | 41 +++++++++---------
libpurple/protocols/mxit/actions.h | 2 +-
libpurple/protocols/mxit/mxit.c | 83 +++++++++++++++++++++----------------
libpurple/protocols/mxit/mxit.h | 3 +-
4 files changed, 69 insertions(+), 60 deletions(-)
diffs (271 lines):
diff --git a/libpurple/protocols/mxit/actions.c b/libpurple/protocols/mxit/actions.c
--- a/libpurple/protocols/mxit/actions.c
+++ b/libpurple/protocols/mxit/actions.c
@@ -207,9 +207,9 @@ out:
*
* @param action The action object
*/
-static void mxit_profile_action( PurplePluginAction* action )
+static void mxit_profile_action( PurpleProtocolAction* action )
{
- PurpleConnection* gc = (PurpleConnection*) action->context;
+ PurpleConnection* gc = action->connection;
struct MXitSession* session = purple_connection_get_protocol_data( gc );
struct MXitProfile* profile = session->profile;
@@ -382,9 +382,9 @@ out:
*
* @param action The action object
*/
-static void mxit_change_pin_action( PurplePluginAction* action )
+static void mxit_change_pin_action( PurpleProtocolAction* action )
{
- PurpleConnection* gc = (PurpleConnection*) action->context;
+ PurpleConnection* gc = action->connection;
PurpleRequestFields* fields = NULL;
PurpleRequestFieldGroup* group = NULL;
@@ -417,9 +417,9 @@ static void mxit_change_pin_action( Purp
*
* @param action The action object
*/
-static void mxit_splash_action( PurplePluginAction* action )
+static void mxit_splash_action( PurpleProtocolAction* action )
{
- PurpleConnection* gc = (PurpleConnection*) action->context;
+ PurpleConnection* gc = action->connection;
struct MXitSession* session = purple_connection_get_protocol_data( gc );
if ( splash_current( session ) != NULL )
@@ -434,7 +434,7 @@ static void mxit_splash_action( PurplePl
*
* @param action The action object
*/
-static void mxit_about_action( PurplePluginAction* action )
+static void mxit_about_action( PurpleProtocolAction* action )
{
char version[256];
@@ -454,9 +454,9 @@ static void mxit_about_action( PurplePlu
*
* @param action The action object
*/
-static void mxit_suggested_friends_action( PurplePluginAction* action )
+static void mxit_suggested_friends_action( PurpleProtocolAction* action )
{
- PurpleConnection* gc = (PurpleConnection*) action->context;
+ PurpleConnection* gc = action->connection;
struct MXitSession* session = purple_connection_get_protocol_data( gc );
const char* profilelist[] = {
CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME, CP_PROFILE_FIRSTNAME,
@@ -489,9 +489,9 @@ static void mxit_user_search_cb( PurpleC
*
* @param action The action object
*/
-static void mxit_user_search_action( PurplePluginAction* action )
+static void mxit_user_search_action( PurpleProtocolAction* action )
{
- PurpleConnection* gc = (PurpleConnection*) action->context;
+ PurpleConnection* gc = action->connection;
purple_request_input( gc, _( "Search for user" ),
_( "Search for a MXit contact" ),
@@ -507,37 +507,36 @@ static void mxit_user_search_action( Pur
/*------------------------------------------------------------------------
* Associate actions with the MXit plugin.
*
- * @param plugin The MXit protocol plugin
- * @param context The connection context (if available)
+ * @param gc The connection
* @return The list of plugin actions
*/
-GList* mxit_actions( PurplePlugin* plugin, gpointer context )
+GList* mxit_get_actions( PurpleConnection *gc )
{
- PurplePluginAction* action = NULL;
+ PurpleProtocolAction* action = NULL;
GList* m = NULL;
/* display / change profile */
- action = purple_plugin_action_new( _( "Change Profile..." ), mxit_profile_action );
+ action = purple_protocol_action_new( _( "Change Profile..." ), mxit_profile_action );
m = g_list_append( m, action );
/* change PIN */
- action = purple_plugin_action_new( _( "Change PIN..." ), mxit_change_pin_action );
+ action = purple_protocol_action_new( _( "Change PIN..." ), mxit_change_pin_action );
m = g_list_append( m, action );
/* suggested friends */
- action = purple_plugin_action_new( _( "Suggested friends..." ), mxit_suggested_friends_action );
+ action = purple_protocol_action_new( _( "Suggested friends..." ), mxit_suggested_friends_action );
m = g_list_append( m, action );
/* search for contacts */
- action = purple_plugin_action_new( _( "Search for contacts..." ), mxit_user_search_action );
+ action = purple_protocol_action_new( _( "Search for contacts..." ), mxit_user_search_action );
m = g_list_append( m, action );
/* display splash-screen */
- action = purple_plugin_action_new( _( "View Splash..." ), mxit_splash_action );
+ action = purple_protocol_action_new( _( "View Splash..." ), mxit_splash_action );
m = g_list_append( m, action );
/* display plugin version */
- action = purple_plugin_action_new( _( "About..." ), mxit_about_action );
+ action = purple_protocol_action_new( _( "About..." ), mxit_about_action );
m = g_list_append( m, action );
return m;
diff --git a/libpurple/protocols/mxit/actions.h b/libpurple/protocols/mxit/actions.h
--- a/libpurple/protocols/mxit/actions.h
+++ b/libpurple/protocols/mxit/actions.h
@@ -28,7 +28,7 @@
/* callbacks */
-GList* mxit_actions( PurplePlugin* plugin, gpointer context );
+GList* mxit_get_actions( PurpleConnection *gc );
#endif /* _MXIT_ACTIONS_H_ */
diff --git a/libpurple/protocols/mxit/mxit.c b/libpurple/protocols/mxit/mxit.c
--- a/libpurple/protocols/mxit/mxit.c
+++ b/libpurple/protocols/mxit/mxit.c
@@ -26,6 +26,7 @@
#include "internal.h"
#include "debug.h"
#include "accountopt.h"
+#include "plugins.h"
#include "version.h"
#include "mxit.h"
@@ -719,6 +720,8 @@ static unsigned int mxit_send_typing( Pu
/*========================================================================================================================*/
static PurplePluginProtocolInfo proto_info = {
+ MXIT_PLUGIN_ID, /* protocol id (must be unique) */
+ MXIT_PLUGIN_NAME, /* protocol name (this will be displayed in the UI) */
sizeof( PurplePluginProtocolInfo ), /* struct_size */
OPT_PROTO_REGISTER_NOSCREENNAME | OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_IM_IMAGE | OPT_PROTO_INVITE_MESSAGE | OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE, /* options */
NULL, /* user_splits */
@@ -730,6 +733,7 @@ static PurplePluginProtocolInfo proto_in
CP_MAX_FILESIZE, /* max filesize */
PURPLE_ICON_SCALE_SEND | PURPLE_ICON_SCALE_DISPLAY /* scaling rules */
},
+ mxit_get_actions, /* get_actions [actions.c] */
mxit_list_icon, /* list_icon */
mxit_list_emblem, /* list_emblem */
mxit_status_text, /* status_text */
@@ -799,48 +803,35 @@ static PurplePluginProtocolInfo proto_in
};
-static PurplePluginInfo plugin_info = {
- PURPLE_PLUGIN_MAGIC, /* purple magic, this must always be PURPLE_PLUGIN_MAGIC */
- PURPLE_MAJOR_VERSION, /* libpurple version */
- PURPLE_MINOR_VERSION, /* libpurple version */
- PURPLE_PLUGIN_PROTOCOL, /* plugin type (connecting to another network) */
- NULL, /* UI requirement (NULL for core plugin) */
- 0, /* plugin flags (zero is default) */
- NULL, /* plugin dependencies (set this value to NULL no matter what) */
- PURPLE_PRIORITY_DEFAULT, /* libpurple priority */
-
- MXIT_PLUGIN_ID, /* plugin id (must be unique) */
- MXIT_PLUGIN_NAME, /* plugin name (this will be displayed in the UI) */
- DISPLAY_VERSION, /* version of the plugin */
-
- MXIT_PLUGIN_SUMMARY, /* short summary of the plugin */
- MXIT_PLUGIN_DESC, /* description of the plugin (can be long) */
- MXIT_PLUGIN_EMAIL, /* plugin author name and email address */
- MXIT_PLUGIN_WWW, /* plugin website (to find new versions and reporting of bugs) */
-
- NULL, /* function pointer for loading the plugin */
- NULL, /* function pointer for unloading the plugin */
- NULL, /* function pointer for destroying the plugin */
-
- NULL, /* pointer to an UI-specific struct */
- &proto_info, /* pointer to either a PurplePluginLoaderInfo or PurplePluginProtocolInfo struct */
- NULL, /* pointer to a PurplePluginUiInfo struct */
- mxit_actions, /* function pointer where you can define plugin-actions */
-
- /* padding */
- NULL, /* pointer reserved for future use */
- NULL, /* pointer reserved for future use */
- NULL, /* pointer reserved for future use */
- NULL /* pointer reserved for future use */
-};
+/*------------------------------------------------------------------------
+ * Querying the MXit plugin.
+ *
+ * @param error Query error (if any)
+ */
+static PurplePluginInfo *plugin_query( GError **error )
+{
+ return purple_plugin_info_new(
+ "id", MXIT_PLUGIN_ID, /* plugin id (must be unique) */
+ "name", MXIT_PLUGIN_NAME, /* plugin name (this will be displayed in the UI) */
+ "version", DISPLAY_VERSION, /* version of the plugin */
+ "category", MXIT_PLUGIN_CATEGORY, /* category of the plugin */
+ "summary", MXIT_PLUGIN_SUMMARY, /* short summary of the plugin */
+ "description", MXIT_PLUGIN_DESC, /* description of the plugin (can be long) */
+ "author", MXIT_PLUGIN_AUTHOR, /* plugin author name and email address */
+ "website", MXIT_PLUGIN_WWW, /* plugin website (to find new versions and reporting of bugs) */
+ "abi-version", PURPLE_ABI_VERSION, /* ABI version required by the plugin */
+ NULL
+ );
+}
/*------------------------------------------------------------------------
- * Initialising the MXit plugin.
+ * Loading the MXit plugin.
*
* @param plugin The plugin object
+ * @param error Load error (if any)
*/
-static void init_plugin( PurplePlugin* plugin )
+static gboolean plugin_load( PurplePlugin* plugin, GError **error )
{
PurpleAccountOption* option;
@@ -857,7 +848,25 @@ static void init_plugin( PurplePlugin* p
option = purple_account_option_bool_new( _( "Enable splash-screen popup" ), MXIT_CONFIG_SPLASHPOPUP, FALSE );
proto_info.protocol_options = g_list_append( proto_info.protocol_options, option );
+
+ purple_protocols_add( &proto_info );
+
+ return TRUE;
}
-PURPLE_INIT_PLUGIN( mxit, init_plugin, plugin_info );
+/*------------------------------------------------------------------------
+ * Unloading the MXit plugin.
+ *
+ * @param plugin The plugin object
+ * @param error Unload error (if any)
+ */
+static gboolean plugin_unload( PurplePlugin* plugin, GError **error )
+{
+ purple_protocols_remove( &proto_info );
+
+ return TRUE;
+}
+
+PURPLE_PLUGIN_INIT( mxit, plugin_query, plugin_load, plugin_unload );
+
diff --git a/libpurple/protocols/mxit/mxit.h b/libpurple/protocols/mxit/mxit.h
--- a/libpurple/protocols/mxit/mxit.h
+++ b/libpurple/protocols/mxit/mxit.h
@@ -64,7 +64,8 @@
/* Plugin details */
#define MXIT_PLUGIN_ID "prpl-loubserp-mxit"
#define MXIT_PLUGIN_NAME "MXit"
-#define MXIT_PLUGIN_EMAIL "Pieter Loubser <libpurple at mxit.com>"
+#define MXIT_PLUGIN_CATEGORY "Protocol"
+#define MXIT_PLUGIN_AUTHOR "Pieter Loubser <libpurple at mxit.com>"
#define MXIT_PLUGIN_WWW "http://www.mxit.com"
#define MXIT_PLUGIN_SUMMARY "MXit Protocol Plugin"
#define MXIT_PLUGIN_DESC "MXit"
More information about the Commits
mailing list