im.pidgin.pidgin: 9a813713521f5b6a9a626e507938ea5b5232245e

wabz at pidgin.im wabz at pidgin.im
Fri Feb 1 22:55:53 EST 2008


-------------- next part --------------
============================================================
--- finch/gntlog.c	208a96bb627b879fcec3779c15e15862c4352e3c
+++ finch/gntlog.c	208a96bb627b879fcec3779c15e15862c4352e3c
@@ -0,0 +1,504 @@
+/**
+ * @file gntlog.c GNT Log viewer
+ * @ingroup finch
+ */
+
+/* finch
+ *
+ * Finch is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#include "internal.h"
+
+#include <gnt.h>
+#include <gntbox.h>
+#include <gntbutton.h>
+#include <gntentry.h>
+#include <gntlabel.h>
+#include <gnttextview.h>
+#include <gnttree.h>
+#include <gntwindow.h>
+
+#include "account.h"
+#include "debug.h"
+#include "log.h"
+#include "notify.h"
+#include "request.h"
+#include "util.h"
+
+#include "gntlog.h"
+
+static GHashTable *log_viewers = NULL;
+static void populate_log_tree(FinchLogViewer *lv);
+static FinchLogViewer *syslog_viewer = NULL;
+
+struct log_viewer_hash_t {
+	PurpleLogType type;
+	char *screenname;
+	PurpleAccount *account;
+	PurpleContact *contact;
+};
+
+static guint log_viewer_hash(gconstpointer data)
+{
+	const struct log_viewer_hash_t *viewer = data;
+
+	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));
+}
+
+static gboolean log_viewer_equal(gconstpointer y, gconstpointer z)
+{
+	const struct log_viewer_hash_t *a, *b;
+	int ret;
+	char *normal;
+
+	a = y;
+	b = z;
+
+	if (a->contact != NULL) {
+		if (b->contact != NULL)
+			return (a->contact == b->contact);
+		else
+			return FALSE;
+	} else {
+		if (b->contact != NULL)
+			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);
+
+	return ret;
+}
+
+static const char *log_get_date(PurpleLog *log)
+{
+	if (log->tm)
+		return purple_date_format_full(log->tm);
+	else
+		return purple_date_format_full(localtime(&log->time));
+}
+
+static void search_cb(GntWidget *button, FinchLogViewer *lv)
+{
+	const char *search_term = gnt_entry_get_text(GNT_ENTRY(lv->entry));
+	GList *logs;
+
+	if (!(*search_term)) {
+		/* reset the tree */
+		gnt_tree_remove_all(GNT_TREE(lv->tree));
+		g_free(lv->search);
+		lv->search = NULL;
+		populate_log_tree(lv);
+		return;
+	}
+
+	if (lv->search != NULL && !strcmp(lv->search, search_term)) {
+		return;
+	}
+
+	g_free(lv->search);
+	lv->search = g_strdup(search_term);
+
+	gnt_tree_remove_all(GNT_TREE(lv->tree));
+	gnt_text_view_clear(GNT_TEXT_VIEW(lv->text));
+
+	for (logs = lv->logs; logs != NULL; logs = logs->next) {
+		char *read = purple_log_read((PurpleLog*)logs->data, NULL);
+		if (read && *read && purple_strcasestr(read, search_term)) {
+			PurpleLog *log = logs->data;
+
+			gnt_tree_add_row_last(GNT_TREE(lv->tree),
+									log,
+									gnt_tree_create_row(GNT_TREE(lv->tree), log_get_date(log)),
+									NULL);
+		}
+		g_free(read);
+	}
+
+}
+
+static void destroy_cb(GntWidget *w, struct log_viewer_hash_t *ht) {
+	FinchLogViewer *lv = syslog_viewer;
+
+	if (ht != NULL) {
+		lv = g_hash_table_lookup(log_viewers, ht);
+		g_hash_table_remove(log_viewers, ht);
+
+		g_free(ht->screenname);
+		g_free(ht);
+	} else
+		syslog_viewer = NULL;
+
+	purple_request_close_with_handle(lv);
+
+	g_list_foreach(lv->logs, (GFunc)purple_log_free, NULL);
+	g_list_free(lv->logs);
+
+	g_free(lv->search);
+	g_free(lv);
+
+	gnt_widget_destroy(w);
+}
+
+static void log_select_cb(GntWidget *w, gpointer old, gpointer new, FinchLogViewer *viewer) {
+	GntTree *tree = GNT_TREE(w);
+	PurpleLog *log = NULL;
+	PurpleLogReadFlags flags;
+	char *read = NULL, *strip, *newline;
+	int h;
+
+	if (!viewer->search && !gnt_tree_get_parent_key(tree, new))
+		return;
+
+	log = (PurpleLog *)new;
+
+	if (log == NULL)
+		return;
+
+	if (log->type != PURPLE_LOG_SYSTEM) {
+		char *title;
+		if (log->type == PURPLE_LOG_CHAT)
+			title = g_strdup_printf(_("Conversation in %s on %s"),
+									log->name, log_get_date(log));
+		else
+			title = g_strdup_printf(_("Conversation with %s on %s"),
+									log->name, log_get_date(log));
+
+		gnt_label_set_text(GNT_LABEL(viewer->label), title);
+		g_free(title);
+	}
+
+	read = purple_log_read(log, &flags);
+	if (flags != PURPLE_LOG_READ_NO_NEWLINE) {
+		newline = purple_strdup_withhtml(read);
+		strip = purple_markup_strip_html(newline);
+		g_free(newline);
+	} else {
+		strip = purple_markup_strip_html(read);
+	}
+	viewer->flags = flags;
+
+	purple_signal_emit(finch_log_get_handle(), "log-displaying", viewer, log);
+
+	gnt_text_view_clear(GNT_TEXT_VIEW(viewer->text));
+	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(viewer->text), strip, GNT_TEXT_FLAG_NORMAL);
+	gnt_widget_get_size(viewer->text, NULL, &h);
+	gnt_text_view_scroll(GNT_TEXT_VIEW(viewer->text), h - 2);
+	g_free(read);
+	g_free(strip);
+}
+
+/* I want to make this smarter, but haven't come up with a cool algorithm to do so, yet.
+ * I want the tree to be divided into groups like "Today," "Yesterday," "Last week,"
+ * "August," "2002," etc. based on how many conversation took place in each subdivision.
+ *
+ * For now, I'll just make it a flat list.
+ */
+static void populate_log_tree(FinchLogViewer *lv)
+     /* Logs are made from trees in real life.
+        This is a tree made from logs */
+{
+	const char *pmonth;
+	char *month = NULL;
+	char prev_top_month[30] = "";
+	GList *logs = lv->logs;
+
+	while (logs != NULL) {
+		PurpleLog *log = logs->data;
+
+		pmonth = purple_utf8_strftime(_("%B %Y"),
+		                           log->tm ? log->tm : localtime(&log->time));
+
+		if (strcmp(pmonth, prev_top_month) != 0) {
+			month = g_strdup(pmonth);
+			/* top level */
+			gnt_tree_add_row_last(GNT_TREE(lv->tree),
+									month,
+									gnt_tree_create_row(GNT_TREE(lv->tree), month),
+									NULL);
+			gnt_tree_set_expanded(GNT_TREE(lv->tree), month, FALSE);
+
+			strncpy(prev_top_month, month, sizeof(prev_top_month));
+		}
+
+		/* sub */
+		gnt_tree_add_row_last(GNT_TREE(lv->tree),
+								log,
+								gnt_tree_create_row(GNT_TREE(lv->tree), log_get_date(log)),
+								month);
+
+		logs = logs->next;
+	}
+}
+
+static FinchLogViewer *display_log_viewer(struct log_viewer_hash_t *ht, GList *logs,
+						const char *title, int log_size)
+{
+	FinchLogViewer *lv;
+	char *text;
+	GntWidget *vbox, *hbox;
+	GntWidget *size_label;
+
+	if (logs == NULL)
+	{
+		/* No logs were found. */
+		const char *log_preferences = NULL;
+
+		if (ht == NULL) {
+			if (!purple_prefs_get_bool("/purple/logging/log_system"))
+				log_preferences = _("System events will only be logged if the \"Log all status changes to system log\" preference is enabled.");
+		} else {
+			if (ht->type == PURPLE_LOG_IM) {
+				if (!purple_prefs_get_bool("/purple/logging/log_ims"))
+					log_preferences = _("Instant messages will only be logged if the \"Log all instant messages\" preference is enabled.");
+			} else if (ht->type == PURPLE_LOG_CHAT) {
+				if (!purple_prefs_get_bool("/purple/logging/log_chats"))
+					log_preferences = _("Chats will only be logged if the \"Log all chats\" preference is enabled.");
+			}
+			g_free(ht->screenname);
+			g_free(ht);
+		}
+
+		purple_notify_info(NULL, title, _("No logs were found"), log_preferences);
+		return NULL;
+	}
+
+	lv = g_new0(FinchLogViewer, 1);
+	lv->logs = logs;
+
+	if (ht != NULL)
+		g_hash_table_insert(log_viewers, ht, lv);
+
+	/* Window ***********/
+	lv->window = gnt_vwindow_new(FALSE);
+	gnt_box_set_title(GNT_BOX(lv->window), title);
+	gnt_box_set_toplevel(GNT_BOX(lv->window), TRUE);
+	gnt_box_set_pad(GNT_BOX(lv->window), 0);
+	g_signal_connect(G_OBJECT(lv->window), "destroy", G_CALLBACK(destroy_cb), ht);
+
+	vbox = gnt_vbox_new(FALSE);
+	gnt_box_add_widget(GNT_BOX(lv->window), vbox);
+
+	/* Label ************/
+	text = g_strdup_printf("%s", title);
+	lv->label = gnt_label_new(text);
+	g_free(text);
+	gnt_box_add_widget(GNT_BOX(vbox), lv->label);
+
+	hbox = gnt_hbox_new(FALSE);
+	gnt_box_add_widget(GNT_BOX(vbox), hbox);
+	/* List *************/
+	lv->tree = gnt_tree_new();
+	gnt_widget_set_size(lv->tree, 30, 0);
+	populate_log_tree(lv);
+	g_signal_connect (G_OBJECT(lv->tree), "selection-changed",
+			G_CALLBACK (log_select_cb),
+			lv);
+	gnt_box_add_widget(GNT_BOX(hbox), lv->tree);
+
+	/* Viewer ************/
+	lv->text = gnt_text_view_new();
+	gnt_box_add_widget(GNT_BOX(hbox), lv->text);
+
+	hbox = gnt_hbox_new(FALSE);
+	gnt_box_add_widget(GNT_BOX(vbox), hbox);
+	/* Log size ************/
+	if (log_size) {
+		char *sz_txt = purple_str_size_to_units(log_size);
+		text = g_strdup_printf("%s %s", _("Total log size:"), sz_txt);
+		size_label = gnt_label_new(text);
+		gnt_box_add_widget(GNT_BOX(hbox), size_label);
+		g_free(sz_txt);
+		g_free(text);
+	}
+
+	/* Search box **********/
+	gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Scroll/Search: ")));
+	lv->entry = gnt_entry_new("");
+	gnt_box_add_widget(GNT_BOX(hbox), lv->entry);
+	g_signal_connect(GNT_ENTRY(lv->entry), "activate", G_CALLBACK(search_cb), lv);
+
+	gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(lv->text), lv->entry);
+	gnt_text_view_attach_pager_widget(GNT_TEXT_VIEW(lv->text), lv->entry);
+
+	gnt_widget_show(lv->window);
+
+	return lv;
+}
+
+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;
+
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(screenname != NULL);
+
+	ht = g_new0(struct log_viewer_hash_t, 1);
+
+	ht->type = type;
+	ht->screenname = g_strdup(screenname);
+	ht->account = account;
+
+	if (log_viewers == NULL) {
+		log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal);
+	} else if ((lv = g_hash_table_lookup(log_viewers, ht))) {
+		gnt_window_present(lv->window);
+		g_free(ht->screenname);
+		g_free(ht);
+		return;
+	}
+
+	if (type == PURPLE_LOG_CHAT) {
+		PurpleChat *chat;
+
+		chat = purple_blist_find_chat(account, screenname);
+		if (chat != NULL)
+			name = purple_chat_get_name(chat);
+
+		title = g_strdup_printf(_("Conversations in %s"), name);
+	} 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);
+	}
+
+	display_log_viewer(ht, purple_log_get_logs(type, screenname, account),
+			title, purple_log_get_total_size(type, screenname, account));
+
+	g_free(title);
+}
+
+void finch_log_show_contact(PurpleContact *contact) {
+	struct log_viewer_hash_t *ht;
+	PurpleBlistNode *child;
+	FinchLogViewer *lv = NULL;
+	GList *logs = NULL;
+	const char *name = NULL;
+	char *title;
+	int total_log_size = 0;
+
+	g_return_if_fail(contact != NULL);
+
+	ht = g_new0(struct log_viewer_hash_t, 1);
+	ht->type = PURPLE_LOG_IM;
+	ht->contact = contact;
+
+	if (log_viewers == NULL) {
+		log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal);
+	} else if ((lv = g_hash_table_lookup(log_viewers, ht))) {
+		gnt_window_present(lv->window);
+		g_free(ht);
+		return;
+	}
+
+	for (child = contact->node.child ; child ; child = child->next) {
+		if (!PURPLE_BLIST_NODE_IS_BUDDY(child))
+			continue;
+
+		logs = g_list_concat(purple_log_get_logs(PURPLE_LOG_IM, ((PurpleBuddy *)child)->name,
+						((PurpleBuddy *)child)->account), logs);
+		total_log_size += purple_log_get_total_size(PURPLE_LOG_IM, ((PurpleBuddy *)child)->name, ((PurpleBuddy *)child)->account);
+	}
+	logs = g_list_sort(logs, purple_log_compare);
+
+	if (contact->alias != NULL)
+		name = contact->alias;
+	else if (contact->priority != NULL)
+		name = purple_buddy_get_contact_alias(contact->priority);
+
+	/* This will happen if the contact doesn't have an alias,
+	 * and none of the contact's buddies are online.
+	 * There is probably a better way to deal with this. */
+	if (name == NULL) {
+		if (contact->node.child != NULL && PURPLE_BLIST_NODE_IS_BUDDY(contact->node.child))
+			name = purple_buddy_get_contact_alias((PurpleBuddy *) contact->node.child);
+		if (name == NULL)
+			name = "";
+	}
+
+	title = g_strdup_printf(_("Conversations with %s"), name);
+	display_log_viewer(ht, logs, title, total_log_size);
+	g_free(title);
+}
+
+void finch_syslog_show()
+{
+	GList *accounts = NULL;
+	GList *logs = NULL;
+
+	if (syslog_viewer != NULL) {
+		gnt_window_present(syslog_viewer->window);
+		return;
+	}
+
+	for(accounts = purple_accounts_get_all(); accounts != NULL; accounts = accounts->next) {
+
+		PurpleAccount *account = (PurpleAccount *)accounts->data;
+		if(purple_find_prpl(purple_account_get_protocol_id(account)) == NULL)
+			continue;
+
+		logs = g_list_concat(purple_log_get_system_logs(account), logs);
+	}
+	logs = g_list_sort(logs, purple_log_compare);
+
+	syslog_viewer = display_log_viewer(NULL, logs, _("System Log"), 0);
+}
+
+/****************************************************************************
+ * GNT LOG SUBSYSTEM *******************************************************
+ ****************************************************************************/
+
+void *
+finch_log_get_handle(void)
+{
+	static int handle;
+
+	return &handle;
+}
+
+void finch_log_init(void)
+{
+	void *handle = finch_log_get_handle();
+
+	purple_signal_register(handle, "log-displaying",
+	                     purple_marshal_VOID__POINTER_POINTER,
+	                     NULL, 2,
+	                     purple_value_new(PURPLE_TYPE_BOXED,
+	                                    "FinchLogViewer *"),
+	                     purple_value_new(PURPLE_TYPE_SUBTYPE,
+	                                    PURPLE_SUBTYPE_LOG));
+}
+
+void
+finch_log_uninit(void)
+{
+	purple_signals_unregister_by_instance(finch_log_get_handle());
+}
============================================================
--- finch/gntlog.h	563f8e5a1f11d7209cc6f9ab9172ddd2ec96d310
+++ finch/gntlog.h	563f8e5a1f11d7209cc6f9ab9172ddd2ec96d310
@@ -0,0 +1,83 @@
+/**
+ * @file gntlog.h GNT Log viewer
+ * @ingroup finch
+ * @see @ref gntlog-signals
+ */
+
+/* finch
+ *
+ * Finch is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#ifndef _FINCHLOG_H_
+#define _FINCHLOG_H_
+
+#include "log.h"
+#include "account.h"
+#include "gntwidget.h"
+
+typedef struct _FinchLogViewer FinchLogViewer;
+
+/**
+ * A GNT Log Viewer.  You can look at logs with it.
+ */
+struct _FinchLogViewer {
+	GList *logs;                 /**< The list of logs viewed in this viewer   */
+
+	GntWidget	*window;    /**< The viewer's window                      */
+	GntWidget	*tree;      /**< The tree representing said treestore */
+	GntWidget	*text;      /**< The text to display said logs          */
+	GntWidget	*entry;     /**< The search entry, in which search terms
+	                              *   are entered                              */
+	GntWidget	*label;
+	PurpleLogReadFlags flags;      /**< The most recently used log flags         */
+	char		*search;    /**< The string currently being searched for  */
+};
+
+
+
+void finch_log_show(PurpleLogType type, const char *screenname, PurpleAccount *account);
+void finch_log_show_contact(PurpleContact *contact);
+
+void finch_syslog_show(void);
+
+/**************************************************************************/
+/** @name GNT Log Subsystem                                              */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Initializes the GNT log subsystem.
+ */
+void finch_log_init(void);
+
+/**
+ * Returns the GNT log subsystem handle.
+ *
+ * @return The GNT log subsystem handle.
+ */
+void *finch_log_get_handle(void);
+
+/**
+ * Uninitializes the GNT log subsystem.
+ */
+void finch_log_uninit(void);
+
+/*@}*/
+
+#endif
============================================================
--- ChangeLog	6e6d3291bd75979ad8d669500cd5652e6655a6fc
+++ ChangeLog	055480014a418f2e63ea6bcba42c7500d13f7708
@@ -41,6 +41,7 @@ version 2.4.0 (??/??/????):
 	* The 'Grouping' plugin can be used for alternate grouping in the
 	  buddylist. The current options are 'Group Online/Offline' and 'No
 	  Group'.
+	* Added a log viewer
 
 version 2.3.1 (12/7/2007):
 	http://developer.pidgin.im/query?status=closed&milestone=2.3.1
============================================================
--- ChangeLog.API	648c910eb3e52630af53d71372117ce76d0b7fe4
+++ ChangeLog.API	1dc8f076568168e6c6d0ffbcbf924d4578002392
@@ -75,6 +75,8 @@ version 2.4.0 (??/??/????):
 		  util functions finch_blist_install_manager,
 		  finch_blist_uninstall_manager, finch_blist_manager_find and
 		  finch_blist_manager_add_node.
+		* Added finch_log_show, finch_log_show_contact, finch_syslog_show,
+		  finch_log_init, finch_log_get_handle, finch_log_uninit
 
 		libgnt:
 		* Added gnt_tree_set_row_color to set the color for a row in a tree.
============================================================
--- finch/Makefile.am	076949a89a5b4446a3c86f0eb99dec6ccf5e422b
+++ finch/Makefile.am	1cb229ff0117f297a41e8a7fdeb2e1f5b0b07bc6
@@ -25,6 +25,7 @@ finch_SOURCES = \
 	gntft.c \
 	finch.c \
 	gntidle.c \
+	gntlog.c \
 	gntnotify.c \
 	gntplugin.c \
 	gntpounce.c \
@@ -45,6 +46,7 @@ finch_headers = \
 	gntft.h \
 	finch.h \
 	gntidle.h \
+	gntlog.h \
 	gntnotify.h \
 	gntplugin.h \
 	gntpounce.h \
============================================================
--- finch/gntblist.c	2f8d823aa635f8b087af35de47c4270f9b1d6434
+++ finch/gntblist.c	6d9cd9d556993bb3dae2f6f20cca0a1061c01056
@@ -27,6 +27,7 @@
 
 #include <account.h>
 #include <blist.h>
+#include <log.h>
 #include <notify.h>
 #include <request.h>
 #include <savedstatuses.h>
@@ -43,6 +44,7 @@
 #include "gntft.h"
 #include "gntlabel.h"
 #include "gntline.h"
+#include "gntlog.h"
 #include "gntmenu.h"
 #include "gntmenuitem.h"
 #include "gntmenuitemcheck.h"
@@ -1282,6 +1284,43 @@ finch_blist_rename_node_cb(PurpleBlistNo
 	g_free(prompt);
 }
 
+
+static void showlog_cb(PurpleBlistNode *node)
+{
+	PurpleLogType type;
+	PurpleAccount *account;
+	char *name = NULL;
+
+	if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
+		PurpleBuddy *b = (PurpleBuddy*) node;
+		type = PURPLE_LOG_IM;
+		name = g_strdup(b->name);
+		account = b->account;
+	} else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
+		PurpleChat *c = (PurpleChat*) node;
+		PurplePluginProtocolInfo *prpl_info = NULL;
+		type = PURPLE_LOG_CHAT;
+		account = c->account;
+		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(account)));
+		if (prpl_info && prpl_info->get_chat_name) {
+			name = prpl_info->get_chat_name(c->components);
+		}
+	} else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
+		finch_log_show_contact((PurpleContact *)node);
+		return;
+	} else {
+		/* This callback should not have been registered for a node
+		 * that doesn't match the type of one of the blocks above. */
+		g_return_if_reached();
+	}
+
+	if (name && account) {
+		finch_log_show(type, name, account);
+		g_free(name);
+	}
+}
+
+
 /* Xeroxed from gtkdialogs.c:purple_gtkdialogs_remove_group_cb*/
 static void
 remove_group(PurpleGroup *group)
@@ -1540,6 +1579,10 @@ draw_context_menu(FinchBlist *ggblist)
 			add_custom_action(GNT_MENU(context), _("Toggle Tag"),
 					PURPLE_CALLBACK(finch_blist_toggle_tag_buddy), node);
 		}
+		if (!PURPLE_BLIST_NODE_IS_GROUP(node)) {
+			add_custom_action(GNT_MENU(context), _("View Log"),
+					PURPLE_CALLBACK(showlog_cb), node);
+		}
 	}
 
 	/* Set the position for the popup */
============================================================
--- finch/gntconv.c	085a571773e53f46d226b3ea62ba57c3e93eafba
+++ finch/gntconv.c	dde9aa0c7e3b2f386a3695584514ef5eb6cd3a8f
@@ -36,6 +36,7 @@
 #include "gntblist.h"
 #include "gntconv.h"
 #include "gntdebug.h"
+#include "gntlog.h"
 #include "gntplugin.h"
 #include "gntprefs.h"
 #include "gntsound.h"
@@ -468,6 +469,44 @@ static void
 }
 
 static void
+view_log_cb(GntMenuItem *n, gpointer ggc)
+{
+	FinchConv *fc;
+	PurpleConversation *conv;
+	PurpleLogType type;
+	const char *name;
+	PurpleAccount *account;
+	GSList *buddies;
+	GSList *cur;
+
+	fc = ggc;
+	conv = fc->active_conv;
+
+	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
+		type = PURPLE_LOG_IM;
+	else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT)
+		type = PURPLE_LOG_CHAT;
+	else
+		return;
+
+	name = purple_conversation_get_name(conv);
+	account = purple_conversation_get_account(conv);
+
+	buddies = purple_find_buddies(account, name);
+	for (cur = buddies; cur != NULL; cur = cur->next) {
+		PurpleBlistNode *node = cur->data;
+		if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL))) {
+			finch_log_show_contact((PurpleContact *)node->parent);
+			g_slist_free(buddies);
+			return;
+		}
+	}
+	g_slist_free(buddies);
+
+	finch_log_show(type, name, account);
+}
+
+static void
 generate_send_to_menu(FinchConv *ggc)
 {
 	GntWidget *sub, *menu = ggc->menu;
@@ -569,6 +608,10 @@ gg_create_menu(FinchConv *ggc)
 		generate_send_to_menu(ggc);
 	}
 
+	item = gnt_menuitem_new(_("View Log..."));
+	gnt_menu_add_item(GNT_MENU(sub), item);
+	gnt_menuitem_set_callback(item, view_log_cb, ggc);
+
 	item = gnt_menuitem_check_new(_("Enable Logging"));
 	gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item),
 			purple_conversation_is_logging(ggc->active_conv));
============================================================
--- finch/gntui.c	87e1ec531596308befb3899fb7d3c7532761ea8a
+++ finch/gntui.c	0a3dd5b122adf23040adadd21949a5ea7e51683d
@@ -30,6 +30,7 @@
 #include "gntconv.h"
 #include "gntdebug.h"
 #include "gntft.h"
+#include "gntlog.h"
 #include "gntnotify.h"
 #include "gntplugin.h"
 #include "gntpounce.h"
@@ -79,6 +80,9 @@ void gnt_ui_init()
 	/* Pounce */
 	finch_pounces_init();
 
+	/* Log */
+	finch_log_init();
+
 	/* File transfer */
 	finch_xfers_init();
 	purple_xfers_set_ui_ops(finch_xfers_get_ui_ops());
@@ -124,6 +128,8 @@ void gnt_ui_uninit()
 
 	finch_pounces_uninit();
 
+	finch_log_uninit();
+
 	finch_xfers_uninit();
 	purple_xfers_set_ui_ops(NULL);
 


More information about the Commits mailing list