cpw.nader.asynclogging-3: 4e43c630: Cleaned up history.c and updated it to u...

morshed.nader at gmail.com morshed.nader at gmail.com
Sun Jan 8 01:21:10 EST 2012


----------------------------------------------------------------------
Revision: 4e43c6306b76d23c49961d43d070032aff67ac60
Parent:   7ce90c0f4577f787f7e88577fe383b0c1d3fd597
Author:   morshed.nader at gmail.com
Date:     01/07/12 14:16:36
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/4e43c6306b76d23c49961d43d070032aff67ac60

Changelog: 

Cleaned up history.c and updated it to use the new logging API

Changes against parent 7ce90c0f4577f787f7e88577fe383b0c1d3fd597

  patched  pidgin/plugins/history.c

-------------- next part --------------
============================================================
--- pidgin/plugins/history.c	1e52608b9376780106bbd3c771250868ef51e731
+++ pidgin/plugins/history.c	94b564ba4c8faf776ad84c53448f4c6687dfd00c
@@ -30,18 +30,18 @@ typedef struct {
 	const gchar *alias;
 	gulong delete_handle;
 	guint count;
-} _historize_callback_data;
+} historize_callback_data;
 
 static void historize(PurpleConversation *);
 static gboolean _scroll_webview_to_end(gpointer);
 static PurpleLog *get_last_log(GList *, PurpleLog *);
 static void historize_log_read_cb(GObject *, GAsyncResult *, gpointer);
 static void historize_log_list_cb(GObject *, GAsyncResult *, gpointer);
-static void historize_log_list_cb_done(_historize_callback_data *);
+static void historize_log_list_cb_done(historize_callback_data *);
 static void historize_log_collector_cb(GObject *, GAsyncResult *, gpointer);
-static void historize_log_collector_cb_done(_historize_callback_data *);
+static void historize_log_collector_cb_done(historize_callback_data *);
 static void historize_stop(PurpleConversation *, gpointer);
-static void historize_log_free(_historize_callback_data *);
+static void historize_log_free(historize_callback_data *);
 static void history_prefs_check(PurplePlugin *);
 static void history_prefs_cb(const gchar *, PurplePrefType, gconstpointer, gpointer);
 static gboolean plugin_load(PurplePlugin *);
@@ -51,7 +51,7 @@ historize(PurpleConversation *c)
 static void
 historize(PurpleConversation *c)
 {
-	_historize_callback_data *callback_data;
+	historize_callback_data *data;
 	PurpleAccount *account = purple_conversation_get_account(c);
 	PurpleConversationType convtype = purple_conversation_get_type(c);
 	PidginConversation *gtkconv = PIDGIN_CONVERSATION(c);
@@ -60,12 +60,12 @@ historize(PurpleConversation *c)
 	g_return_if_fail(gtkconv != NULL);
 	g_return_if_fail(gtkconv->convs != NULL);
 
-	callback_data = g_new0(_historize_callback_data, 1);
-	callback_data->conv = c;
-	callback_data->alias = alias;
-	callback_data->name = name;
-	callback_data->account = account;
-	callback_data->cancel = g_cancellable_new();
+	data = g_new0(historize_callback_data, 1);
+	data->conv = c;
+	data->alias = alias;
+	data->name = name;
+	data->account = account;
+	data->cancel = g_cancellable_new();
 
 	if (convtype == PURPLE_CONV_TYPE_IM && !gtkconv->convs->next) {
 		GSList *buddies, *cur;
@@ -73,8 +73,8 @@ historize(PurpleConversation *c)
 		/* If we're not logging, don't show anything.
 		 * Otherwise, we might show a very old log. */
 		if (!purple_prefs_get_bool("/purple/logging/log_ims")) {
-			g_object_unref(callback_data->cancel);
-			g_free(callback_data);
+			g_object_unref(data->cancel);
+			g_free(data);
 
 			return;
 		}
@@ -106,11 +106,11 @@ historize(PurpleConversation *c)
 				{
 					PurpleBuddy *buddy = PURPLE_BUDDY(node2);
 
-					callback_data->count++;
+					data->count++;
 
-					purple_logs_list_logs_async(PURPLE_LOG_IM, purple_buddy_get_name(buddy),
+					purple_logs_list_async(PURPLE_LOG_IM, purple_buddy_get_name(buddy),
 						purple_buddy_get_account(buddy), G_PRIORITY_DEFAULT,
-						callback_data->cancel, historize_log_collector_cb, callback_data);
+						data->cancel, historize_log_collector_cb, data);
 				}
 
 				break;
@@ -122,20 +122,20 @@ historize(PurpleConversation *c)
 		/* If we're not logging, don't show anything.
 		 * Otherwise, we might show a very old log. */
 		if (!purple_prefs_get_bool("/purple/logging/log_chats")) {
-			g_object_unref(callback_data->cancel);
-			g_free(callback_data);
+			g_object_unref(data->cancel);
+			g_free(data);
 
 			return;
 		}
 
-		callback_data->count = 1;
+		data->count = 1;
 
-		purple_logs_list_logs_async(PURPLE_LOG_CHAT, name, account, G_PRIORITY_DEFAULT,
-			callback_data->cancel, historize_log_list_cb, callback_data);
+		purple_logs_list_async(PURPLE_LOG_CHAT, name, account, G_PRIORITY_DEFAULT,
+			data->cancel, historize_log_list_cb, data);
 	}
 
-	callback_data->delete_handle = purple_signal_connect(purple_conversations_get_handle(),
-		"deleting-conversation", c, PURPLE_CALLBACK(historize_stop), callback_data);
+	data->delete_handle = purple_signal_connect(purple_conversations_get_handle(),
+		"deleting-conversation", c, PURPLE_CALLBACK(historize_stop), data);
 }
 
 static gboolean
@@ -175,10 +175,10 @@ historize_log_read_cb(GObject *object, G
 static void
 historize_log_read_cb(GObject *object, GAsyncResult *res, gpointer userdata)
 {
-	_historize_callback_data *callback_data = userdata;
+	historize_callback_data *data = userdata;
 	PurpleLog *log = PURPLE_LOG(object);
 	PurpleLogReadFlags flags;
-	PidginConversation *gtkconv = PIDGIN_CONVERSATION(callback_data->conv);
+	PidginConversation *gtkconv = PIDGIN_CONVERSATION(data->conv);
 	GtkWebView *wv = GTK_WEBVIEW(gtkconv->webview);
 	GError *err = NULL;
 	const gchar *header_date;
@@ -186,10 +186,10 @@ historize_log_read_cb(GObject *object, G
 	const struct tm *log_tm;
 
 	if (res == NULL) {
-		callback_data->count--;
+		data->count--;
 
-		if (callback_data->count < 1)
-			historize_log_free(callback_data);
+		if (data->count < 1)
+			historize_log_free(data);
 
 		return;
 	}
@@ -221,7 +221,7 @@ historize_log_read_cb(GObject *object, G
 		header_date = purple_date_format_full(localtime(&log_time));
 	}
 
-	escaped_alias = g_markup_escape_text(callback_data->alias, -1);
+	escaped_alias = g_markup_escape_text(data->alias, -1);
 	full_header = g_strdup_printf(_("Conversation with %s on %s"), escaped_alias, header_date);
 	header = g_strdup_printf("<b>%s:</b><br>", full_header);
 
@@ -258,116 +258,116 @@ historize_log_read_cb(GObject *object, G
 #endif
 
 	g_clear_error(&err);
-	callback_data->count--;
+	data->count--;
 
-	if (callback_data->count < 1)
-		historize_log_free(callback_data);
+	if (data->count < 1)
+		historize_log_free(data);
 }
 
 static void
 historize_log_list_cb(GObject *object, GAsyncResult *res, gpointer userdata)
 {
-	_historize_callback_data *callback_data = userdata;
+	historize_callback_data *data = userdata;
 	GList *list;
 	GError *err = NULL;
 
 	if (res == NULL) {
-		callback_data->count--;
+		data->count--;
 
-		if (callback_data->count < 1)
-			historize_log_list_cb_done(callback_data);
+		if (data->count < 1)
+			historize_log_list_cb_done(data);
 
 		return;
 	}
 
-	list = purple_logs_list_logs_finish(res, &err);
+	list = purple_logs_list_finish(res, &err);
 
 	if (list != NULL)
-		callback_data->log = get_last_log(list, callback_data->log);
+		data->log = get_last_log(list, data->log);
 	else if (err != NULL && err->code != G_IO_ERROR_CANCELLED)
 		purple_debug_error("history", "%s\n", err->message);
 
 	g_clear_error(&err);
 
-	callback_data->count--;
+	data->count--;
 
-	if (callback_data->count < 1)
-		historize_log_list_cb_done(callback_data);
+	if (data->count < 1)
+		historize_log_list_cb_done(data);
 }
 
 static void
-historize_log_list_cb_done(_historize_callback_data *callback_data)
+historize_log_list_cb_done(historize_callback_data *data)
 {
-	callback_data->count++;
+	data->count++;
 
-	if (callback_data->log != NULL)
-		purple_log_read_async(callback_data->log, G_PRIORITY_DEFAULT,
-			callback_data->cancel, historize_log_read_cb,
-			callback_data);
+	if (data->log != NULL)
+		purple_log_read_async(data->log, G_PRIORITY_DEFAULT,
+			data->cancel, historize_log_read_cb,
+			data);
 	else
-		historize_log_read_cb(NULL, NULL, callback_data);
+		historize_log_read_cb(NULL, NULL, data);
 }
 
 static void
 historize_log_collector_cb(GObject *object, GAsyncResult *res, gpointer userdata)
 {
-	_historize_callback_data *callback_data = userdata;
+	historize_callback_data *data = userdata;
 	GList *list;
 	GError *err = NULL;
 
-	list = purple_logs_list_logs_finish(res, &err);
+	list = purple_logs_list_finish(res, &err);
 
 	if (list != NULL)
-		callback_data->log = get_last_log(list, callback_data->log);
+		data->log = get_last_log(list, data->log);
 	else if (err != NULL && err->code != G_IO_ERROR_CANCELLED)
 		purple_debug_error("history", "%s\n", err->message);
 
 	g_clear_error(&err);
 
-	callback_data->count--;
+	data->count--;
 
-	if (callback_data->count < 1)
+	if (data->count < 1)
 		historize_log_collector_cb_done(userdata);
 }
 
 static void
-historize_log_collector_cb_done(_historize_callback_data *callback_data)
+historize_log_collector_cb_done(historize_callback_data *data)
 {
-	callback_data->count++;
+	data->count++;
 
-	if (callback_data->log == NULL)
-		purple_logs_list_logs_async(PURPLE_LOG_IM, callback_data->name,
-			callback_data->account, G_PRIORITY_DEFAULT, callback_data->cancel,
-			historize_log_list_cb, callback_data);
+	if (data->log == NULL)
+		purple_logs_list_async(PURPLE_LOG_IM, data->name,
+			data->account, G_PRIORITY_DEFAULT, data->cancel,
+			historize_log_list_cb, data);
 	else
-		historize_log_list_cb(NULL, NULL, callback_data);
+		historize_log_list_cb(NULL, NULL, data);
 }
 
 static void
 historize_stop(PurpleConversation *c, gpointer userdata)
 {
-	_historize_callback_data *callback_data = userdata;
+	historize_callback_data *data = userdata;
 
-	if (callback_data->cancel != NULL)
-		g_cancellable_cancel(callback_data->cancel);
+	if (data->cancel != NULL)
+		g_cancellable_cancel(data->cancel);
 
 	purple_signal_disconnect(purple_conversations_get_handle(), "deleting-conversation",
 		c, PURPLE_CALLBACK(historize_stop));
 }
 
 static void
-historize_log_free(_historize_callback_data *callback_data)
+historize_log_free(historize_callback_data *data)
 {
-	if (callback_data->log != NULL)
-		g_object_unref(callback_data->log);
+	if (data->log != NULL)
+		g_object_unref(data->log);
 
 	/* Why on earth does pidgin give us gulong to refer to our connected signal if it
 	   offers no API to disconnect it with!? */
 	purple_signal_disconnect(purple_conversations_get_handle(), "deleting-conversation",
-		callback_data->conv, PURPLE_CALLBACK(historize_stop));
+		data->conv, PURPLE_CALLBACK(historize_stop));
 
-	g_object_unref(callback_data->cancel);
-	g_free(callback_data);
+	g_object_unref(data->cancel);
+	g_free(data);
 }
 
 static void


More information about the Commits mailing list