changeset 23288:5f9793c8510a

Added "View All Logs" menu in the buddylist to display a list of all IM logs.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 05 Jun 2008 10:23:58 +0000
parents 173c612752ea
children 48aea903d270
files ChangeLog finch/gntblist.c finch/gntlog.c
diffstat 3 files changed, 67 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 05 10:16:23 2008 +0000
+++ b/ChangeLog	Thu Jun 05 10:23:58 2008 +0000
@@ -20,6 +20,8 @@
 
 	Finch:
 	* Added "Invite..." menu to chats.
+	* Added "View All Logs" menu in the buddylist to display a list of all IM
+	  logs.
 
 version 2.4.2 (05/17/2008):
 	libpurple:
--- a/finch/gntblist.c	Thu Jun 05 10:16:23 2008 +0000
+++ b/finch/gntblist.c	Thu Jun 05 10:23:58 2008 +0000
@@ -2851,6 +2851,12 @@
 }
 
 static void
+view_all_logs_cb(GntMenuItem *item, gpointer n)
+{
+	finch_log_show(PURPLE_LOG_IM, NULL, NULL);
+}
+
+static void
 menu_add_buddy_cb(GntMenuItem *item, gpointer null)
 {
 	purple_blist_request_add_buddy(NULL, NULL, NULL, NULL);
@@ -2915,6 +2921,11 @@
 	gnt_menu_add_item(GNT_MENU(sub), item);
 	gnt_menuitem_set_callback(GNT_MENU_ITEM(item), view_log_cb, NULL);
 
+	item = gnt_menuitem_new(_("View All Logs"));
+	gnt_menuitem_set_id(GNT_MENU_ITEM(item), "view-all-logs");
+	gnt_menu_add_item(GNT_MENU(sub), item);
+	gnt_menuitem_set_callback(GNT_MENU_ITEM(item), view_all_logs_cb, NULL);
+
 	item = gnt_menuitem_new(_("Show"));
 	gnt_menu_add_item(GNT_MENU(sub), item);
 	subsub = gnt_menu_new(GNT_MENU_POPUP);
--- a/finch/gntlog.c	Thu Jun 05 10:16:23 2008 +0000
+++ b/finch/gntlog.c	Thu Jun 05 10:23:58 2008 +0000
@@ -61,8 +61,12 @@
 	if (viewer->contact != NULL)
 		return g_direct_hash(viewer->contact);
 
-	return g_str_hash(viewer->screenname) +
-		g_str_hash(purple_account_get_username(viewer->account));
+	if (viewer->account) {
+		return g_str_hash(viewer->screenname) +
+			g_str_hash(purple_account_get_username(viewer->account));
+	}
+
+	return (guint)viewer;
 }
 
 static gboolean log_viewer_equal(gconstpointer y, gconstpointer z)
@@ -84,10 +88,14 @@
 			return FALSE;
 	}
 
-	normal = g_strdup(purple_normalize(a->account, a->screenname));
-	ret = (a->account == b->account) &&
-		!strcmp(normal, purple_normalize(b->account, b->screenname));
-	g_free(normal);
+	if (a->screenname && b->screenname) {
+		normal = g_strdup(purple_normalize(a->account, a->screenname));
+		ret = (a->account == b->account) &&
+			!strcmp(normal, purple_normalize(b->account, b->screenname));
+		g_free(normal);
+	} else {
+		ret = (a == b);
+	}
 
 	return ret;
 }
@@ -348,14 +356,28 @@
 	return lv;
 }
 
-void finch_log_show(PurpleLogType type, const char *screenname, PurpleAccount *account) {
+static void
+our_logging_blows(PurpleLogSet *set, PurpleLogSet *setagain, GList **list)
+{
+	/* The iteration happens on the first list. So we use the shorter list in front */
+	if (set->type != PURPLE_LOG_IM)
+		return;
+	*list = g_list_concat(purple_log_get_logs(PURPLE_LOG_IM, set->name, set->account), *list);
+}
+
+void finch_log_show(PurpleLogType type, const char *screenname, PurpleAccount *account)
+{
 	struct log_viewer_hash_t *ht;
 	FinchLogViewer *lv = NULL;
 	const char *name = screenname;
 	char *title;
+	GList *logs = NULL;
+	int size = 0;
 
-	g_return_if_fail(account != NULL);
-	g_return_if_fail(screenname != NULL);
+	if (type != PURPLE_LOG_IM) {
+		g_return_if_fail(account != NULL);
+		g_return_if_fail(screenname != NULL);
+	}
 
 	ht = g_new0(struct log_viewer_hash_t, 1);
 
@@ -383,20 +405,35 @@
 	} else {
 		PurpleBuddy *buddy;
 
-		buddy = purple_find_buddy(account, screenname);
-		if (buddy != NULL)
-			name = purple_buddy_get_contact_alias(buddy);
-
-		title = g_strdup_printf(_("Conversations with %s"), name);
+		if (screenname) {
+			buddy = purple_find_buddy(account, screenname);
+			if (buddy != NULL)
+				name = purple_buddy_get_contact_alias(buddy);
+			title = g_strdup_printf(_("Conversations with %s"), name);
+		} else {
+			title = g_strdup(_("All Conversations"));
+		}
 	}
 
-	display_log_viewer(ht, purple_log_get_logs(type, screenname, account),
-			title, purple_log_get_total_size(type, screenname, account));
+	if (screenname) {
+		logs = purple_log_get_logs(type, screenname, account);
+		size = purple_log_get_total_size(type, screenname, account);
+	} else {
+		/* This will happen only for IMs */
+		GHashTable *table = purple_log_get_log_sets();
+		g_hash_table_foreach(table, (GHFunc)our_logging_blows, &logs);
+		g_hash_table_destroy(table);
+		logs = g_list_sort(logs, purple_log_compare);
+		size = 0;
+	}
+
+	display_log_viewer(ht, logs, title, size);
 
 	g_free(title);
 }
 
-void finch_log_show_contact(PurpleContact *contact) {
+void finch_log_show_contact(PurpleContact *contact)
+{
 	struct log_viewer_hash_t *ht;
 	PurpleBlistNode *child;
 	FinchLogViewer *lv = NULL;