cpw.nader.asynclogging-3: 111f3d1b: Fixed up most of the bugs in gntlog.c, s...

nader.morshed at pidgin.im nader.morshed at pidgin.im
Fri Jan 14 17:01:01 EST 2011


----------------------------------------------------------------------
Revision: 111f3d1b6c3d71752734f01d53d6169a67572d6d
Parent:   a6916d3a58ecb85740b781e9b7cffa7e1838413b
Author:   nader.morshed at pidgin.im
Date:     01/05/11 11:05:41
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/111f3d1b6c3d71752734f01d53d6169a67572d6d

Changelog: 

Fixed up most of the bugs in gntlog.c, still needs the init/construct functions set up though

Changes against parent a6916d3a58ecb85740b781e9b7cffa7e1838413b

  patched  finch/gntlog.c
  patched  finch/gntlog.h

-------------- next part --------------
============================================================
--- finch/gntlog.c	6e36a0fcdd40b5c463cd80c038cd9edcfbf3e903
+++ finch/gntlog.c	af70ae08aec62a6375f93b09edc4ee9a4e5f6c57
@@ -45,7 +45,7 @@
 
 #include "gntlog.h"
 
-G_DEFINE_TYPE (FinchLogViewer, finch_log_viewer, GNT_TYPE_DIALOG)
+G_DEFINE_TYPE (FinchLogViewer, finch_log_viewer, GNT_TYPE_WINDOW)
 
 enum {
 	PROP_0,
@@ -96,6 +96,7 @@ typedef struct {
 typedef struct {
 	FinchLogViewer *log_viewer;
 	PurpleLog *log;
+	gchar *string;
 
 	gboolean is_window_open;
 	gulong destroy_handler_id;
@@ -114,16 +115,13 @@ static void finch_window_destroy_cb(_fin
 
 static void finch_log_data_free(_finch_log_data *);
 static void finch_window_destroy_cb(_finch_log_data *);
-static void finch_log_viewer_set_read_cancel(FinchLogViewer *, GCancellable *);
-static void finch_log_viewer_set_search_cancel(FinchLogViewer *, GCancellable *);
-static void finch_log_viewer_set_list_cancel(FinchLogViewer *, GCancellable *);
 static guint log_viewer_hash(gconstpointer);
 static gboolean log_viewer_equal(gconstpointer, gconstpointer);
 static const gchar *log_get_date(PurpleLog *);
 static void finch_log_search_done_cb(_finch_log_data *);
 static void finch_log_search_cb(GObject *, GAsyncResult *, gpointer);
 static void search_cb(GntWidget *, FinchLogViewer *);
-static void destroy_cb(GntWidget *, log_viewer_hash_t *);
+static void destroy_cb(FinchLogViewer *, log_viewer_hash_t *);
 static void finch_log_read_cb(GObject *, GAsyncResult *, gpointer);
 static void log_select_cb(GntWidget *, gpointer, gpointer, FinchLogViewer *);
 static void populate_log_tree(FinchLogViewer *);
@@ -208,8 +206,7 @@ finch_log_data_free(_finch_log_data *dat
 finch_log_data_free(_finch_log_data *data)
 {
 	if (data->destroy_handler_id > 0)
-		g_signal_handler_disconnect(data->log_viewer->lv->window,
-			data->destroy_handler_id);
+		g_signal_handler_disconnect(data->log_viewer, data->destroy_handler_id);
 
 	g_free(data);
 }
@@ -238,28 +235,35 @@ finch_log_search_cb(GObject *object, GAs
 {
 	_finch_log_data *finch_log_data = userdata;
 	PurpleLog *log = PURPLE_LOG(object);
-	GError *err = NULL;
-	gchar *read;
+	GError *error = NULL;
+	gchar *text;
 
-	read = purple_log_read_finish(log, res, NULL, &err);
+	text = purple_log_read_finish(log, res, NULL, &error);
 	finch_log_data->count--;
 
 	if (read == NULL) {
-		if (err->code != G_IO_ERROR_CANCELLED)
-			purple_debug_error("gntlog", "%s", err->message);
+		if (error->code != G_IO_ERROR_CANCELLED)
+			purple_debug_error("gntlog", "%s", error->message);
 	} else if (finch_log_data->is_window_open) {
-		FinchLogViewer *lv = finch_log_data->log_viewer->lv;
+		FinchLogViewer *lv = finch_log_data->log_viewer;
+		GntTree *tree = GNT_TREE(finch_log_viewer_get_tree(lv));
 
-		if (*read && purple_strcasestr(read, lv->search))
-			gnt_tree_add_row_last(GNT_TREE(lv->tree), log,
-				gnt_tree_create_row(GNT_TREE(lv->tree),
-					log_get_date(log)),
+		if (*text && purple_strcasestr(text, finch_log_data->string))
+			gnt_tree_add_row_last(tree, log,
+				gnt_tree_create_row(tree, log_get_date(log)),
 				NULL);
 	}
 
-	g_clear_error(&err);
-	finch_log_viewer_update_search_bar(finch_log_data);
+	g_clear_error(&error);
 
+	if (finch_log_data->is_window_open) {
+		const gchar *cur_search =
+			finch_log_viewer_get_search_string(finch_log_data->log_viewer);
+
+		if (purple_strequal(finch_log_data->string, cur_search))
+			finch_log_viewer_update_search_bar(finch_log_data);
+	}
+
 	if (finch_log_data->count < 1)
 		finch_log_search_done_cb(finch_log_data);
 }
@@ -304,7 +308,7 @@ search_cb(GntWidget *button, FinchLogVie
 
 	finch_log_viewer_set_search_string(lv, search_term);
 	gnt_tree_remove_all(tree);
-	gnt_text_view_clear(lv->text));
+	gnt_text_view_clear(view);
 
 	finch_log_data = g_new0(_finch_log_data, 1);
 	finch_log_data->is_window_open = TRUE;
@@ -329,14 +333,14 @@ static void
 }
 
 static void
-destroy_cb(GntWidget *w, log_viewer_hash_t *ht)
+destroy_cb(FinchLogViewer *lv, log_viewer_hash_t *ht)
 {
 	if (ht != NULL) {
 		G_LOCK(log_viewers);
 		g_hash_table_remove(log_viewers, ht);
 		G_UNLOCK(log_viewers);
 
-		g_free(ht->buddyname);
+		g_free(ht->username);
 		g_free(ht);
 	} else {
 		G_LOCK(syslog_viewer);
@@ -358,7 +362,6 @@ finch_log_read_cb(GObject *object, GAsyn
 		FinchLogViewer *lv = finch_log_data->log_viewer;
 		GntTextView *view = GNT_TEXT_VIEW(finch_log_viewer_get_text_area(lv));
 		GError *error = NULL;
-		const gchar *search = finch_log_viewer_get_search_string(lv);
 		gchar *text, *strip;
 
 		text = purple_log_read_finish(log, res, &flags, &error);
@@ -499,7 +502,7 @@ finch_log_viewer_new(log_viewer_hash_t *
 {
 	FinchLogViewer *lv;
 
-	lv = g_object_new(Finch_TYPE_LOG_VIEWER,
+	lv = g_object_new(FINCH_TYPE_LOG_VIEWER,
 		"viewer-title", title,
 		"viewer-type", ht != NULL ? ht->chat_type : PURPLE_LOG_SYSTEM,
 		"need-log-size", need_log_size,
@@ -609,7 +612,7 @@ finch_log_done_cb(_finch_log_data *finch
 {
 	if (finch_log_data->is_window_open) {
 		FinchLogViewer *lv = finch_log_data->log_viewer;
-		GntWidget *bar = finch_log_viewer_get_list_bar(lv);
+//		GntWidget *bar = finch_log_viewer_get_list_bar(lv);
 		GList *logs = finch_log_viewer_get_logs(lv);
 
 //		gnt_widget_hide(bar);
@@ -635,9 +638,9 @@ finch_log_done_cb(_finch_log_data *finch
 						"\"Log all chats\" preference is enabled.");
 			}
 
-			purple_notify_info(NULL, GNT_BOX(lv->window)->title,
+			purple_notify_info(NULL, GNT_BOX(lv)->title,
 				_("No logs were found"), log_preferences);
-			gnt_widget_destroy(lv->window);
+			gnt_widget_destroy(GNT_WIDGET(lv));
 		}
 	}
 
@@ -660,7 +663,7 @@ finch_log_viewer_update_search_bar(_finc
 finch_log_viewer_update_search_bar(_finch_log_data *finch_log_data)
 {
 	FinchLogViewer *lv = finch_log_data->log_viewer;
-	GtkWidget *bar = finch_log_viewer_get_search_bar(lv);
+	GntWidget *bar = finch_log_viewer_get_search_bar(lv);
 	gdouble fraction;
 
 	fraction = (gdouble) finch_log_data->count /
@@ -743,7 +746,7 @@ finch_log_system_list_cb(GObject *object
 	} else if (finch_log_data->is_window_open)
 		finch_log_viewer_add_logs(finch_log_data->log_viewer, list);
 
-	g_clear_error(&err);
+	g_clear_error(&error);
 
 	if (finch_log_data->is_window_open)
 		finch_log_viewer_update_list_bar(finch_log_data);
@@ -826,7 +829,7 @@ finch_log_show(PurpleLogChatType chat_ty
 	G_UNLOCK(log_viewers);
 
 	if (lv != NULL) {
-		gnt_window_present(GNT_WINDOW(lv));
+		gnt_window_present(GNT_WIDGET(lv));
 
 		g_free(ht->username);
 		g_free(ht);
@@ -908,7 +911,7 @@ finch_log_show_contact(PurpleContact *co
 	G_UNLOCK(log_viewers);
 
 	if (lv != NULL) {
-		gnt_window_present(GNT_WINDOW(lv));
+		gnt_window_present(GNT_WIDGET(lv));
 		g_free(ht);
 
 		return;
@@ -972,7 +975,7 @@ finch_syslog_show(void)
 finch_syslog_show(void)
 {
 	_finch_log_data *finch_log_data;
-	PidginLogViewer *lv;
+	FinchLogViewer *lv;
 	GCancellable *cancel;
 	GList *accounts = NULL;
 
@@ -981,7 +984,7 @@ finch_syslog_show(void)
 	G_UNLOCK(syslog_viewer);
 
 	if (lv != NULL) {
-		gnt_window_present(GNT_WINDOW(lv));
+		gnt_window_present(GNT_WIDGET(lv));
 		return;
 	}
 
@@ -1041,7 +1044,7 @@ finch_log_viewer_get_text_area(FinchLogV
 {
 	g_return_val_if_fail(FINCH_IS_LOG_VIEWER(lv), NULL);
 
-	return FINCH_LOG_VIEWER_GET_PRIVATE(lv)->imhtml;
+	return FINCH_LOG_VIEWER_GET_PRIVATE(lv)->text;
 }
 
 G_CONST_RETURN gchar *
@@ -1121,27 +1124,20 @@ finch_log_viewer_get_viewer_title(FinchL
 {
 	g_return_val_if_fail(FINCH_IS_LOG_VIEWER(lv), FALSE);
 
-	return FINCH_LOG_VIEWER_GET_PRIVATE(lv)->title;
+	return GNT_BOX(lv)->title;
 }
 
 void
 finch_log_viewer_add_logs(FinchLogViewer *lv, GList *logs)
 {
 	FinchLogViewerPrivate *priv;
-	GList *list;
 
 	g_return_if_fail(FINCH_IS_LOG_VIEWER(lv));
 
 	priv = FINCH_LOG_VIEWER_GET_PRIVATE(lv);
-	logs = g_list_sort(logs, purple_log_compare);
 
-	// faster if we reverse the list?
-
-	for (list = logs; list != NULL; list = g_list_next(list))
-		insert_log_viewer_log(lv, list->data);
-
 	priv->logs = g_list_concat(priv->logs, logs);
-	priv->logs = g_list_sort(priv->logs, purple_log_compare);
+	populate_log_tree(lv);
 
 	g_object_notify(G_OBJECT(lv), "logs");
 }
@@ -1159,7 +1155,6 @@ finch_log_viewer_set_logs(FinchLogViewer
 	g_list_free(priv->logs);
 
 	priv->logs = logs;
-
 	populate_log_tree(lv);
 
 	g_object_notify(G_OBJECT(lv), "logs");
@@ -1300,9 +1295,9 @@ finch_log_viewer_set_viewer_title(FinchL
 finch_log_viewer_set_viewer_title(FinchLogViewer *lv, const gchar *title)
 {
 	g_return_if_fail(FINCH_IS_LOG_VIEWER(lv));
-	g_return_if_fail(title != NULL
+	g_return_if_fail(title != NULL);
 
-	FINCH_LOG_VIEWER_GET_PRIVATE(lv)->title = g_strdup(title);
+	GNT_BOX(lv)->title = g_strdup(title);
 
 	g_object_notify(G_OBJECT(lv), "viewer-title");
 }
@@ -1372,6 +1367,9 @@ finch_log_viewer_set_property(GObject *o
 	case PROP_NEED_LOG_SIZE:
 		finch_log_viewer_set_need_log_size(lv, g_value_get_boolean(value));
 		break;
+	case PROP_VIEWER_TITLE:
+		finch_log_viewer_set_viewer_title(lv, g_value_get_string(value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 		break;
@@ -1420,6 +1418,9 @@ finch_log_viewer_get_property(GObject *o
 	case PROP_NEED_LOG_SIZE:
 		g_value_set_boolean(value, finch_log_viewer_get_need_log_size(lv));
 		break;
+	case PROP_VIEWER_TITLE:
+		g_value_set_string(value, finch_log_viewer_get_viewer_title(lv));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 		break;
============================================================
--- finch/gntlog.h	70db9cdb8cb3a641f176bbfc3d5f517b3e889422
+++ finch/gntlog.h	6a26538a41bdc14a45bdef9728995e5e2dfce31f
@@ -91,6 +91,8 @@ gboolean finch_log_viewer_get_need_log_s
 PurpleLogChatType finch_log_viewer_get_viewer_type(FinchLogViewer *lv);
 //
 gboolean finch_log_viewer_get_need_log_size(FinchLogViewer *lv);
+//
+G_CONST_RETURN gchar *finch_log_viewer_get_viewer_title(FinchLogViewer *lv);
 
 //
 void finch_log_viewer_add_logs(FinchLogViewer *lv, GList *logs);
@@ -115,6 +117,8 @@ void finch_log_viewer_set_read_cancel(Fi
 
 /*@{*/
 
+GType finch_log_viewer_get_type(void);
+
 /**
  * Displays the logs of a certain type for a buddy or chat on an account
  *


More information about the Commits mailing list