changeset 22840:04e0d8677b9a

Add a 'View log' option in the buddylist menu.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 04 May 2008 04:15:11 +0000
parents f67edee0224e
children b77d000b738b
files finch/gntblist.c
diffstat 1 files changed, 67 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntblist.c	Sun May 04 03:28:58 2008 +0000
+++ b/finch/gntblist.c	Sun May 04 04:15:11 2008 +0000
@@ -2779,6 +2779,68 @@
 }
 
 static void
+view_log_select_cb(gpointer data, PurpleRequestFields *fields)
+{
+	PurpleAccount *account;
+	const char *name;
+	PurpleBuddy *buddy;
+	PurpleContact *contact;
+
+	account = purple_request_fields_get_account(fields, "account");
+	name = purple_request_fields_get_string(fields,  "screenname");
+
+	buddy = purple_find_buddy(account, name);
+	if (buddy) {
+		contact = purple_buddy_get_contact(buddy);
+	} else {
+		contact = NULL;
+	}
+
+	if (contact) {
+		finch_log_show_contact(contact);
+	} else {
+		finch_log_show(PURPLE_LOG_IM, name, account);
+	}
+}
+
+static void
+view_log_cb(GntMenuItem *item, gpointer n)
+{
+	PurpleRequestFields *fields;
+	PurpleRequestFieldGroup *group;
+	PurpleRequestField *field;
+
+	fields = purple_request_fields_new();
+
+	group = purple_request_field_group_new(NULL);
+	purple_request_fields_add_group(fields, group);
+
+	field = purple_request_field_string_new("screenname", _("Name"), NULL, FALSE);
+	purple_request_field_set_type_hint(field, "screenname-all");
+	purple_request_field_set_required(field, TRUE);
+	purple_request_field_group_add_field(group, field);
+
+	field = purple_request_field_account_new("account", _("Account"), NULL);
+	purple_request_field_set_type_hint(field, "account");
+	purple_request_field_set_visible(field,
+		(purple_accounts_get_all() != NULL &&
+		 purple_accounts_get_all()->next != NULL));
+	purple_request_field_set_required(field, TRUE);
+	purple_request_field_group_add_field(group, field);
+	purple_request_field_account_set_show_all(field, TRUE);
+
+	purple_request_fields(purple_get_blist(), _("View Log"),
+						NULL,
+						_("Please enter the username or alias of the person "
+						  "whose log you would like to view."),
+						fields,
+						_("OK"), G_CALLBACK(view_log_select_cb),
+						_("Cancel"), NULL,
+						NULL, NULL, NULL,
+						NULL);
+}
+
+static void
 menu_add_buddy_cb(GntMenuItem *item, gpointer null)
 {
 	purple_blist_request_add_buddy(NULL, NULL, NULL, NULL);
@@ -2838,6 +2900,11 @@
 	gnt_menu_add_item(GNT_MENU(sub), item);
 	gnt_menuitem_set_callback(GNT_MENU_ITEM(item), join_chat_select, NULL);
 
+	item = gnt_menuitem_new(_("View Log..."));
+	gnt_menuitem_set_id(GNT_MENU_ITEM(item), "view-log");
+	gnt_menu_add_item(GNT_MENU(sub), item);
+	gnt_menuitem_set_callback(GNT_MENU_ITEM(item), view_log_cb, NULL);
+
 	item = gnt_menuitem_new(_("Show"));
 	gnt_menu_add_item(GNT_MENU(sub), item);
 	subsub = gnt_menu_new(GNT_MENU_POPUP);