/soc/2013/ankitkv/gobjectification: 44cfe9e574d8: Refactored mys...
Ankit Vani
a at nevitus.org
Sun Aug 11 17:24:22 EDT 2013
Changeset: 44cfe9e574d85eff79f6ebb0eff44bd5a669e882
Author: Ankit Vani <a at nevitus.org>
Date: 2013-08-12 02:52 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/44cfe9e574d8
Description:
Refactored myspace to use the new plugin API
diffstat:
libpurple/protocols/myspace/myspace.c | 279 ++++++++++++++++-----------------
1 files changed, 132 insertions(+), 147 deletions(-)
diffs (truncated from 335 to 300 lines):
diff --git a/libpurple/protocols/myspace/myspace.c b/libpurple/protocols/myspace/myspace.c
--- a/libpurple/protocols/myspace/myspace.c
+++ b/libpurple/protocols/myspace/myspace.c
@@ -32,8 +32,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
-#define PURPLE_PLUGIN
-
+#include "plugins.h"
#include "myspace.h"
static void msim_set_status(PurpleAccount *account, PurpleStatus *status);
@@ -3002,9 +3001,99 @@ msim_get_account_text_table(PurpleAccoun
}
/**
+ * Called when friends have been imported to buddy list on server.
+ */
+static void
+msim_import_friends_cb(MsimSession *session, const MsimMessage *reply, gpointer user_data)
+{
+ MsimMessage *body;
+ gchar *completed;
+
+ /* Check if the friends were imported successfully. */
+ body = msim_msg_get_dictionary(reply, "body");
+ g_return_if_fail(body != NULL);
+ completed = msim_msg_get_string(body, "Completed");
+ msim_msg_free(body);
+ g_return_if_fail(completed != NULL);
+ if (!g_str_equal(completed, "True"))
+ {
+ purple_debug_info("msim_import_friends_cb",
+ "failed to import friends: %s", completed);
+ purple_notify_error(session->account, _("Add friends from MySpace.com"),
+ _("Importing friends failed"), NULL);
+ g_free(completed);
+ return;
+ }
+ g_free(completed);
+
+ purple_debug_info("msim_import_friends_cb",
+ "added friends to server-side buddy list, requesting new contacts from server");
+
+ msim_get_contact_list(session, MSIM_CONTACT_LIST_IMPORT_ALL_FRIENDS);
+
+ /* TODO: show, X friends have been added */
+}
+
+/**
+ * Import friends from myspace.com.
+ */
+static void msim_import_friends(PurpleProtocolAction *action)
+{
+ PurpleConnection *gc;
+ MsimSession *session;
+ gchar *group_name;
+
+ gc = action->connection;
+ session = purple_connection_get_protocol_data(gc);
+
+ group_name = "MySpace Friends";
+
+ g_return_if_fail(msim_send(session,
+ "persist", MSIM_TYPE_INTEGER, 1,
+ "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
+ "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_PUT,
+ "dsn", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_DSN,
+ "lid", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_LID,
+ "uid", MSIM_TYPE_INTEGER, session->userid,
+ "rid", MSIM_TYPE_INTEGER,
+ msim_new_reply_callback(session, msim_import_friends_cb, NULL),
+ "body", MSIM_TYPE_STRING,
+ g_strdup_printf("GroupName=%s", group_name),
+ NULL));
+}
+
+/**
+ * Actions menu for account.
+ */
+static GList *
+msim_get_actions(PurpleConnection *gc)
+{
+ GList *menu;
+ PurpleProtocolAction *act;
+
+ menu = NULL;
+
+#if 0
+ /* TODO: find out how */
+ act = purple_protocol_action_new(_("Find people..."), msim_);
+ menu = g_list_append(menu, act);
+
+ act = purple_protocol_action_new(_("Change IM name..."), NULL);
+ menu = g_list_append(menu, act);
+#endif
+
+ act = purple_protocol_action_new(_("Add friends from MySpace.com"), msim_import_friends);
+ menu = g_list_append(menu, act);
+
+ return menu;
+}
+
+/**
* Callbacks called by Purple, to access this plugin.
*/
static PurplePluginProtocolInfo prpl_info = {
+ "prpl-myspace", /* id */
+ "MySpaceIM", /* name */
sizeof(PurplePluginProtocolInfo), /* struct_size */
/* options */
OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */
@@ -3014,6 +3103,7 @@ static PurplePluginProtocolInfo prpl_inf
NULL, /* user_splits */
NULL, /* protocol_options */
NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */
+ msim_get_actions, /* get_actions */
msim_list_icon, /* list_icon */
NULL, /* list_emblems */
msim_status_text, /* status_text */
@@ -3082,139 +3172,6 @@ static PurplePluginProtocolInfo prpl_inf
NULL /* get_public_alias */
};
-/**
- * Load the plugin.
- */
-static gboolean
-msim_load(PurplePlugin *plugin)
-{
- return TRUE;
-}
-
-/**
- * Called when friends have been imported to buddy list on server.
- */
-static void
-msim_import_friends_cb(MsimSession *session, const MsimMessage *reply, gpointer user_data)
-{
- MsimMessage *body;
- gchar *completed;
-
- /* Check if the friends were imported successfully. */
- body = msim_msg_get_dictionary(reply, "body");
- g_return_if_fail(body != NULL);
- completed = msim_msg_get_string(body, "Completed");
- msim_msg_free(body);
- g_return_if_fail(completed != NULL);
- if (!g_str_equal(completed, "True"))
- {
- purple_debug_info("msim_import_friends_cb",
- "failed to import friends: %s", completed);
- purple_notify_error(session->account, _("Add friends from MySpace.com"),
- _("Importing friends failed"), NULL);
- g_free(completed);
- return;
- }
- g_free(completed);
-
- purple_debug_info("msim_import_friends_cb",
- "added friends to server-side buddy list, requesting new contacts from server");
-
- msim_get_contact_list(session, MSIM_CONTACT_LIST_IMPORT_ALL_FRIENDS);
-
- /* TODO: show, X friends have been added */
-}
-
-/**
- * Import friends from myspace.com.
- */
-static void msim_import_friends(PurplePluginAction *action)
-{
- PurpleConnection *gc;
- MsimSession *session;
- gchar *group_name;
-
- gc = (PurpleConnection *)action->context;
- session = purple_connection_get_protocol_data(gc);
-
- group_name = "MySpace Friends";
-
- g_return_if_fail(msim_send(session,
- "persist", MSIM_TYPE_INTEGER, 1,
- "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
- "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_PUT,
- "dsn", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_DSN,
- "lid", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_LID,
- "uid", MSIM_TYPE_INTEGER, session->userid,
- "rid", MSIM_TYPE_INTEGER,
- msim_new_reply_callback(session, msim_import_friends_cb, NULL),
- "body", MSIM_TYPE_STRING,
- g_strdup_printf("GroupName=%s", group_name),
- NULL));
-}
-
-/**
- * Actions menu for account.
- */
-static GList *
-msim_actions(PurplePlugin *plugin, gpointer context /* PurpleConnection* */)
-{
- GList *menu;
- PurplePluginAction *act;
-
- menu = NULL;
-
-#if 0
- /* TODO: find out how */
- act = purple_plugin_action_new(_("Find people..."), msim_);
- menu = g_list_append(menu, act);
-
- act = purple_plugin_action_new(_("Change IM name..."), NULL);
- menu = g_list_append(menu, act);
-#endif
-
- act = purple_plugin_action_new(_("Add friends from MySpace.com"), msim_import_friends);
- menu = g_list_append(menu, act);
-
- return menu;
-}
-
-/**
- * Based on MSN's plugin info comments.
- */
-static PurplePluginInfo info = {
- PURPLE_PLUGIN_MAGIC,
- PURPLE_MAJOR_VERSION,
- PURPLE_MINOR_VERSION,
- PURPLE_PLUGIN_PROTOCOL, /**< type */
- NULL, /**< ui_requirement */
- 0, /**< flags */
- NULL, /**< dependencies */
- PURPLE_PRIORITY_DEFAULT, /**< priority */
-
- "prpl-myspace", /**< id */
- "MySpaceIM", /**< name */
- MSIM_PRPL_VERSION_STRING, /**< version */
- /** summary */
- "MySpaceIM Protocol Plugin",
- /** description */
- "MySpaceIM Protocol Plugin",
- "Jeff Connelly <jeff2 at soc.pidgin.im>", /**< author */
- "https://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */
-
- msim_load, /**< load */
- NULL, /**< unload */
- NULL, /**< destroy */
- NULL, /**< ui_info */
- &prpl_info, /**< extra_info */
- NULL, /**< prefs_info */
- msim_actions, /**< msim_actions */
- NULL, /**< reserved1 */
- NULL, /**< reserved2 */
- NULL, /**< reserved3 */
- NULL /**< reserved4 */
-};
-
#ifdef MSIM_SELF_TEST
/*
* Test functions.
@@ -3504,10 +3461,30 @@ msim_uri_handler(const gchar *proto, con
}
/**
- * Initialize plugin.
+ * Query the plugin
*/
-static void
-init_plugin(PurplePlugin *plugin)
+static PurplePluginInfo *
+plugin_query(GError **error)
+{
+ return purple_plugin_info_new(
+ "id", "prpl-myspace",
+ "name", "MySpaceIM",
+ "version", MSIM_PRPL_VERSION_STRING,
+ "category", "Protocol",
+ "summary", "MySpaceIM Protocol Plugin",
+ "description", "MySpaceIM Protocol Plugin",
+ "author", "Jeff Connelly <jeff2 at soc.pidgin.im>",
+ "website", "https://developer.pidgin.im/wiki/MySpaceIM/",
+ "abi-version", PURPLE_ABI_VERSION,
+ NULL
+ );
+}
+
+/**
+ * Load the plugin.
+ */
+static gboolean
+plugin_load(PurplePlugin *plugin, GError **error)
{
#ifdef MSIM_SELF_TEST
msim_test_all();
@@ -3515,7 +3492,6 @@ init_plugin(PurplePlugin *plugin)
#endif /* MSIM_SELF_TEST */
PurpleAccountOption *option;
- static gboolean initialized = FALSE;
More information about the Commits
mailing list