/soc/2013/ankitkv/gobjectification: d728ec173fc5: Refactored pid...

Ankit Vani a at nevitus.org
Thu Sep 19 07:42:33 EDT 2013


Changeset: d728ec173fc5e00f4c85d836a33e7895e90ce236
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-19 17:12 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/d728ec173fc5

Description:

Refactored pidgin cap plugin to use the new APIs

diffstat:

 pidgin/plugins/cap/cap.c |  159 +++++++++++++++++++++-------------------------
 pidgin/plugins/cap/cap.h |    7 +-
 2 files changed, 77 insertions(+), 89 deletions(-)

diffs (272 lines):

diff --git a/pidgin/plugins/cap/cap.c b/pidgin/plugins/cap/cap.c
--- a/pidgin/plugins/cap/cap.c
+++ b/pidgin/plugins/cap/cap.c
@@ -33,9 +33,9 @@ static void generate_prediction(CapStati
 static double generate_prediction_for(PurpleBuddy *buddy) {
 	double prediction = 1.0f;
 	gboolean generated = FALSE;
-	gchar *buddy_name = buddy->name;
-	const gchar *protocol_id = purple_account_get_protocol_id(buddy->account);
-	const gchar *account_id = purple_account_get_username(buddy->account);
+	const gchar *buddy_name = purple_buddy_get_name(buddy);
+	const gchar *protocol_id = purple_account_get_protocol_id(purple_buddy_get_account(buddy));
+	const gchar *account_id = purple_account_get_username(purple_buddy_get_account(buddy));
 	const gchar *status_id = purple_status_get_id(get_status_for(buddy));
 	time_t t = time(NULL);
 	struct tm *current_time = localtime(&t);
@@ -113,7 +113,7 @@ static CapStatistics * get_stats_for(Pur
 
 	g_return_val_if_fail(buddy != NULL, NULL);
 
-	stats = g_hash_table_lookup(_buddy_stats, buddy->name);
+	stats = g_hash_table_lookup(_buddy_stats, purple_buddy_get_name(buddy));
 	if(!stats) {
 		stats = g_malloc0(sizeof(CapStatistics));
 		stats->last_message = -1;
@@ -121,7 +121,7 @@ static CapStatistics * get_stats_for(Pur
 		stats->last_seen = -1;
 		stats->last_status_id = "";
 
-		g_hash_table_insert(_buddy_stats, g_strdup(buddy->name), stats);
+		g_hash_table_insert(_buddy_stats, g_strdup(purple_buddy_get_name(buddy)), stats);
 	} else {
 		/* This may actually be a different PurpleBuddy than what is in stats.
 		 * We replace stats->buddy to make sure we're looking at a valid pointer. */
@@ -290,9 +290,9 @@ insert_cap_status_count_failed(const cha
 }
 
 static void insert_cap_success(CapStatistics *stats) {
-	gchar *buddy_name = stats->buddy->name;
-	const gchar *protocol_id = purple_account_get_protocol_id(stats->buddy->account);
-	const gchar *account_id = purple_account_get_username(stats->buddy->account);
+	gchar *buddy_name = purple_buddy_get_name(stats->buddy);
+	const gchar *protocol_id = purple_account_get_protocol_id(purple_buddy_get_account(stats->buddy));
+	const gchar *account_id = purple_account_get_username(purple_buddy_get_account(stats->buddy));
 	const gchar *status_id = (stats->last_message_status_id) ?
 		stats->last_message_status_id :
 		purple_status_get_id(get_status_for(stats->buddy));
@@ -316,9 +316,9 @@ static void insert_cap_success(CapStatis
 }
 
 static void insert_cap_failure(CapStatistics *stats) {
-	gchar *buddy_name = stats->buddy->name;
-	const gchar *protocol_id = purple_account_get_protocol_id(stats->buddy->account);
-	const gchar *account_id = purple_account_get_username(stats->buddy->account);
+	gchar *buddy_name = purple_buddy_get_name(stats->buddy);
+	const gchar *protocol_id = purple_account_get_protocol_id(purple_buddy_get_account(stats->buddy));
+	const gchar *account_id = purple_account_get_username(purple_buddy_get_account(stats->buddy));
 	const gchar *status_id = (stats->last_message_status_id) ?
 		stats->last_message_status_id :
 		purple_status_get_id(get_status_for(stats->buddy));
@@ -438,7 +438,7 @@ static void buddy_signed_off(PurpleBuddy
 
 /* drawing-tooltip */
 static void drawing_tooltip(PurpleBlistNode *node, GString *text, gboolean full) {
-	if(node->type == PURPLE_BLIST_BUDDY_NODE) {
+	if(PURPLE_IS_BUDDY(node)) {
 		PurpleBuddy *buddy = PURPLE_BUDDY(node);
 		CapStatistics *stats = get_stats_for(buddy);
 		/* get the probability that this buddy will respond and add to the tooltip */
@@ -625,9 +625,9 @@ static void insert_status_change_from_pu
 		return;
 
 	status_id = purple_status_get_id(status);
-	buddy_name = statistics->buddy->name;
-	protocol_id = purple_account_get_protocol_id(statistics->buddy->account);
-	account_id = purple_account_get_username(statistics->buddy->account);
+	buddy_name = purple_buddy_get_name(statistics->buddy);
+	protocol_id = purple_account_get_protocol_id(purple_buddy_get_account(statistics->buddy));
+	account_id = purple_account_get_username(purple_buddy_get_account(statistics->buddy));
 
 	statistics->last_status_id = purple_status_get_id(status);
 
@@ -646,25 +646,6 @@ static void insert_word_count(const char
 
 /* Purple plugin specific code */
 
-static gboolean plugin_load(PurplePlugin *plugin) {
-	_plugin_pointer = plugin;
-	_signals_connected = FALSE;
-
-	/* buddy_stats is a hashtable where strings are keys
-	 * and the keys are a buddies account id (PurpleBuddy.name).
-	 * keys/values are automatically deleted */
-	_buddy_stats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_stats);
-
-	/* ? - Can't remember at the moment
-	 */
-	_my_offline_times = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
-
-	if(create_database_connection()) {
-		add_plugin_functionality(plugin);
-	}
-	return TRUE;
-}
-
 static void add_plugin_functionality(PurplePlugin *plugin) {
 	if(_signals_connected)
 		return;
@@ -751,21 +732,6 @@ static void write_stats_on_unload(gpoint
 	}
 }
 
-static gboolean plugin_unload(PurplePlugin *plugin) {
-	purple_debug_info("cap", "CAP plugin unloading\n");
-
-	/* clean up memory allocations */
-	if(_buddy_stats) {
-		g_hash_table_foreach(_buddy_stats, write_stats_on_unload, NULL);
-		g_hash_table_destroy(_buddy_stats);
-	}
-
-	 /* close database connection */
-	 destroy_database_connection();
-
-	return TRUE;
-}
-
 static CapPrefsUI * create_cap_prefs_ui() {
 	CapPrefsUI *ui = g_malloc(sizeof(CapPrefsUI));
 
@@ -868,7 +834,7 @@ static CapPrefsUI * create_cap_prefs_ui(
 	return ui;
 }
 
-static void cap_prefs_ui_destroy_cb(GtkObject *object, gpointer user_data) {
+static void cap_prefs_ui_destroy_cb(GObject *object, gpointer user_data) {
 	CapPrefsUI *ui = user_data;
 	if(_db) {
 		add_plugin_functionality(_plugin_pointer);
@@ -880,39 +846,6 @@ static void numeric_spinner_prefs_cb(Gtk
 	purple_prefs_set_int(user_data, gtk_spin_button_get_value_as_int(spinbutton));
 }
 
-static PidginPluginUiInfo ui_info = {
-	get_config_frame,
-	0 /* page_num (reserved) */,
-	NULL,NULL,NULL,NULL
-};
-
-static PurplePluginInfo info = {
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,							/**< type		*/
-	PIDGIN_PLUGIN_TYPE,							/**< ui_requirement */
-	0,												/**< flags		*/
-	NULL,											/**< dependencies   */
-	PURPLE_PRIORITY_DEFAULT,							/**< priority		*/
-	CAP_PLUGIN_ID,									/**< id			*/
-	N_("Contact Availability Prediction"),				/**< name		*/
-	DISPLAY_VERSION,									/**< version		*/
-	N_("Contact Availability Prediction plugin."),	/**  summary		*/
-	N_("Displays statistical information about your buddies' availability"),
-	/**  description	*/
-	"Geoffrey Foster <geoffrey.foster at gmail.com>",	/**< author		*/
-	PURPLE_WEBSITE,									/**< homepage		*/
-	plugin_load,									/**< load		*/
-	plugin_unload,									/**< unload		*/
-	NULL,											/**< destroy		*/
-	&ui_info,										/**< ui_info		*/
-	NULL,											/**< extra_info	 */
-	NULL,											/**< prefs_info		*/
-	NULL,
-	NULL,NULL,NULL,NULL
-};
-
 static GtkWidget * get_config_frame(PurplePlugin *plugin) {
 	CapPrefsUI *ui = create_cap_prefs_ui();
 
@@ -924,11 +857,67 @@ static GtkWidget * get_config_frame(Purp
 	return ui->ret;
 }
 
-static void init_plugin(PurplePlugin *plugin) {
+static PidginPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Geoffrey Foster <geoffrey.foster at gmail.com>",
+		NULL
+	};
+
+	return pidgin_plugin_info_new(
+		"id",                   CAP_PLUGIN_ID,
+		"name",                 N_("Contact Availability Prediction"),
+		"version",              DISPLAY_VERSION,
+		"category",             N_("Utility"),
+		"summary",              N_("Contact Availability Prediction plugin."),
+		"description",          N_("Displays statistical information about "
+		                           "your buddies' availability"),
+		"authors",              authors,
+		"website",              PURPLE_WEBSITE,
+		"abi-version",          PURPLE_ABI_VERSION,
+		"pidgin-config-frame",  get_config_frame,
+		NULL
+	);
+}
+
+static gboolean plugin_load(PurplePlugin *plugin, GError **error) {
 	purple_prefs_add_none("/plugins/gtk/cap");
 	purple_prefs_add_int("/plugins/gtk/cap/max_seen_difference", 1);
 	purple_prefs_add_int("/plugins/gtk/cap/max_msg_difference", 10);
 	purple_prefs_add_int("/plugins/gtk/cap/threshold", 5);
+
+	_plugin_pointer = plugin;
+	_signals_connected = FALSE;
+
+	/* buddy_stats is a hashtable where strings are keys
+	 * and the keys are a buddies account id (PurpleBuddy.name).
+	 * keys/values are automatically deleted */
+	_buddy_stats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_stats);
+
+	/* ? - Can't remember at the moment
+	 */
+	_my_offline_times = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
+	if(create_database_connection()) {
+		add_plugin_functionality(plugin);
+	}
+	return TRUE;
 }
 
-PURPLE_INIT_PLUGIN(cap, init_plugin, info);
+static gboolean plugin_unload(PurplePlugin *plugin, GError **error) {
+	purple_debug_info("cap", "CAP plugin unloading\n");
+
+	/* clean up memory allocations */
+	if(_buddy_stats) {
+		g_hash_table_foreach(_buddy_stats, write_stats_on_unload, NULL);
+		g_hash_table_destroy(_buddy_stats);
+	}
+
+	 /* close database connection */
+	 destroy_database_connection();
+
+	return TRUE;
+}
+
+PURPLE_PLUGIN_INIT(cap, plugin_query, plugin_load, plugin_unload);
diff --git a/pidgin/plugins/cap/cap.h b/pidgin/plugins/cap/cap.h
--- a/pidgin/plugins/cap/cap.h
+++ b/pidgin/plugins/cap/cap.h
@@ -113,16 +113,15 @@ static guint word_count(const gchar *str
 static void insert_status_change(CapStatistics *statistics);
 static void insert_status_change_from_purple_status(CapStatistics *statistics, PurpleStatus *status);
 static void insert_word_count(const char *sender, const char *receiver, guint count);
-static gboolean plugin_load(PurplePlugin *plugin);
+static gboolean plugin_load(PurplePlugin *plugin, GError **error);
 static void add_plugin_functionality(PurplePlugin *plugin);
 static void cancel_conversation_timeouts(gpointer key, gpointer value, gpointer user_data);
 static void remove_plugin_functionality(PurplePlugin *plugin);
 static void write_stats_on_unload(gpointer key, gpointer value, gpointer user_data);
-static gboolean plugin_unload(PurplePlugin *plugin);
+static gboolean plugin_unload(PurplePlugin *plugin, GError **error);
 static CapPrefsUI * create_cap_prefs_ui(void);
-static void cap_prefs_ui_destroy_cb(GtkObject *object, gpointer user_data);
+static void cap_prefs_ui_destroy_cb(GObject *object, gpointer user_data);
 static void numeric_spinner_prefs_cb(GtkSpinButton *spinbutton, gpointer user_data);
 static GtkWidget * get_config_frame(PurplePlugin *plugin);
-static void init_plugin(PurplePlugin *plugin);
 
 #endif



More information about the Commits mailing list