/soc/2013/ankitkv/gobjectification: 3d44db6dd9b4: Refactored joi...
Ankit Vani
a at nevitus.org
Mon Sep 16 07:54:47 EDT 2013
Changeset: 3d44db6dd9b49fc5316e6d26cc9662217222d4b0
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-16 16:48 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/3d44db6dd9b4
Description:
Refactored joinpart to use the new plugin API
diffstat:
libpurple/plugins/joinpart.c | 157 ++++++++++++++++--------------------------
1 files changed, 60 insertions(+), 97 deletions(-)
diffs (189 lines):
diff --git a/libpurple/plugins/joinpart.c b/libpurple/plugins/joinpart.c
--- a/libpurple/plugins/joinpart.c
+++ b/libpurple/plugins/joinpart.c
@@ -51,6 +51,10 @@ struct joinpart_key
char *user;
};
+static GHashTable *users;
+static guint id;
+
+
static guint joinpart_key_hash(const struct joinpart_key *key)
{
g_return_val_if_fail(key != NULL, 0);
@@ -173,52 +177,6 @@ static gboolean clean_users_hash(GHashTa
return TRUE;
}
-static gboolean plugin_load(PurplePlugin *plugin)
-{
- void *conv_handle;
- GHashTable *users;
- guint id;
- gpointer *data;
-
- users = g_hash_table_new_full((GHashFunc)joinpart_key_hash,
- (GEqualFunc)joinpart_key_equal,
- (GDestroyNotify)joinpart_key_destroy,
- g_free);
-
- conv_handle = purple_conversations_get_handle();
- purple_signal_connect(conv_handle, "chat-user-joining", plugin,
- PURPLE_CALLBACK(chat_user_joining_cb), users);
- purple_signal_connect(conv_handle, "chat-user-leaving", plugin,
- PURPLE_CALLBACK(chat_user_leaving_cb), users);
- purple_signal_connect(conv_handle, "received-chat-msg", plugin,
- PURPLE_CALLBACK(received_chat_msg_cb), users);
-
- /* Cleanup every 5 minutes */
- id = purple_timeout_add_seconds(60 * 5, (GSourceFunc)clean_users_hash, users);
-
- data = g_new(gpointer, 2);
- data[0] = users;
- data[1] = GUINT_TO_POINTER(id);
- plugin->extra = data;
-
- return TRUE;
-}
-
-static gboolean plugin_unload(PurplePlugin *plugin)
-{
- gpointer *data = plugin->extra;
-
- /* Destroy the hash table. The core plugin code will
- * disconnect the signals, and since Purple is single-threaded,
- * we don't have to worry one will be called after this. */
- g_hash_table_destroy((GHashTable *)data[0]);
-
- purple_timeout_remove(GPOINTER_TO_UINT(data[1]));
- g_free(data);
-
- return TRUE;
-}
-
static PurplePluginPrefFrame *
get_plugin_pref_frame(PurplePlugin *plugin)
{
@@ -250,65 +208,70 @@ get_plugin_pref_frame(PurplePlugin *plug
return frame;
}
-static PurplePluginUiInfo prefs_info = {
- get_plugin_pref_frame,
- 0, /* page_num (reserved) */
- NULL, /* frame (reserved) */
+static PurplePluginInfo *
+plugin_query(GError **error)
+{
+ const gchar * const authors[] = {
+ "Richard Laager <rlaager at pidgin.im>",
+ NULL
+ };
- /* padding */
- NULL,
- NULL,
- NULL,
- NULL
-};
+ return purple_plugin_info_new(
+ "id", JOINPART_PLUGIN_ID,
+ "name", N_("Join/Part Hiding"),
+ "version", DISPLAY_VERSION,
+ "category", N_("Utility"),
+ "summary", N_("Hides extraneous join/part messages."),
+ "description", N_("This plugin hides join/part messages in "
+ "large rooms, except for those users actively "
+ "taking part in a conversation."),
+ "authors", authors,
+ "website", PURPLE_WEBSITE,
+ "abi-version", PURPLE_ABI_VERSION,
+ "preferences-frame", get_plugin_pref_frame,
+ NULL
+ );
+}
-static PurplePluginInfo info =
+static gboolean plugin_load(PurplePlugin *plugin, GError **error)
{
- PURPLE_PLUGIN_MAGIC,
- PURPLE_MAJOR_VERSION,
- PURPLE_MINOR_VERSION,
- PURPLE_PLUGIN_STANDARD, /**< type */
- NULL, /**< ui_requirement */
- 0, /**< flags */
- NULL, /**< dependencies */
- PURPLE_PRIORITY_DEFAULT, /**< priority */
+ void *conv_handle;
- JOINPART_PLUGIN_ID, /**< id */
- N_("Join/Part Hiding"), /**< name */
- DISPLAY_VERSION, /**< version */
- /** summary */
- N_("Hides extraneous join/part messages."),
- /** description */
- N_("This plugin hides join/part messages in large "
- "rooms, except for those users actively taking "
- "part in a conversation."),
- "Richard Laager <rlaager at pidgin.im>", /**< author */
- PURPLE_WEBSITE, /**< homepage */
-
- plugin_load, /**< load */
- plugin_unload, /**< unload */
- NULL, /**< destroy */
-
- NULL, /**< ui_info */
- NULL, /**< extra_info */
- &prefs_info, /**< prefs_info */
- NULL, /**< actions */
-
- /* padding */
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
purple_prefs_add_none("/plugins/core/joinpart");
purple_prefs_add_int(DELAY_PREF, DELAY_DEFAULT);
purple_prefs_add_int(THRESHOLD_PREF, THRESHOLD_DEFAULT);
purple_prefs_add_bool(HIDE_BUDDIES_PREF, HIDE_BUDDIES_DEFAULT);
+
+ users = g_hash_table_new_full((GHashFunc)joinpart_key_hash,
+ (GEqualFunc)joinpart_key_equal,
+ (GDestroyNotify)joinpart_key_destroy,
+ g_free);
+
+ conv_handle = purple_conversations_get_handle();
+ purple_signal_connect(conv_handle, "chat-user-joining", plugin,
+ PURPLE_CALLBACK(chat_user_joining_cb), users);
+ purple_signal_connect(conv_handle, "chat-user-leaving", plugin,
+ PURPLE_CALLBACK(chat_user_leaving_cb), users);
+ purple_signal_connect(conv_handle, "received-chat-msg", plugin,
+ PURPLE_CALLBACK(received_chat_msg_cb), users);
+
+ /* Cleanup every 5 minutes */
+ id = purple_timeout_add_seconds(60 * 5, (GSourceFunc)clean_users_hash, users);
+
+ return TRUE;
}
-PURPLE_INIT_PLUGIN(joinpart, init_plugin, info)
+static gboolean plugin_unload(PurplePlugin *plugin, GError **error)
+{
+ /* Destroy the hash table. The core plugin code will
+ * disconnect the signals, and since Purple is single-threaded,
+ * we don't have to worry one will be called after this. */
+ g_hash_table_destroy(users);
+
+ purple_timeout_remove(id);
+
+ return TRUE;
+}
+
+PURPLE_PLUGIN_INIT(joinpart, plugin_query, plugin_load, plugin_unload);
More information about the Commits
mailing list