changeset 30806:4e804413b12b

Added a way to view the Visible/Invisible lists. The UI is kind of crippled, but that seems to be the best we can do with the notify API.
author ivan.komarov@soc.pidgin.im
date Tue, 29 Jun 2010 21:17:02 +0000
parents 5bfef3338383
children 48fe4720d795
files libpurple/protocols/oscar/oscar.c libpurple/protocols/oscar/oscar.h libpurple/protocols/oscar/util.c libpurple/protocols/oscar/visibility.c libpurple/protocols/oscar/visibility.h
diffstat 5 files changed, 99 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/oscar.c	Mon Jun 28 20:02:12 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Tue Jun 29 21:17:02 2010 +0000
@@ -5774,41 +5774,29 @@
 {
 	PurpleConnection *gc = (PurpleConnection *) action->context;
 	OscarData *od = purple_connection_get_protocol_data(gc);
-	gchar *text, *tmp;
-	GSList *buddies;
-	PurpleAccount *account;
-	int num=0;
-
-	text = g_strdup("");
-	account = purple_connection_get_account(gc);
+	PurpleAccount *account = purple_connection_get_account(gc);
+	GSList *buddies, *filtered_buddies, *cur;
+	gchar *text;
 
 	buddies = purple_find_buddies(account, NULL);
-	while (buddies) {
+	filtered_buddies = NULL;
+	for (cur = buddies; cur != NULL; cur = cur->next) {
 		PurpleBuddy *buddy;
 		const gchar *bname, *gname;
 
-		buddy = buddies->data;
+		buddy = cur->data;
 		bname = purple_buddy_get_name(buddy);
 		gname = purple_group_get_name(purple_buddy_get_group(buddy));
 		if (aim_ssi_waitingforauth(od->ssi.local, gname, bname)) {
-			const gchar *alias = purple_buddy_get_alias_only(buddy);
-			if (alias)
-				tmp = g_strdup_printf("%s %s (%s)<br>", text, bname, alias);
-			else
-				tmp = g_strdup_printf("%s %s<br>", text, bname);
-			g_free(text);
-			text = tmp;
-
-			num++;
+			filtered_buddies = g_slist_prepend(filtered_buddies, buddy);
 		}
-
-		buddies = g_slist_delete_link(buddies, buddies);
-	}
-
-	if (!num) {
-		g_free(text);
-		text = g_strdup(_("<i>you are not waiting for authorization</i>"));
-	}
+	}
+
+	g_slist_free(buddies);
+
+	filtered_buddies = g_slist_reverse(filtered_buddies);
+	text = oscar_format_buddies(filtered_buddies, _("you are not waiting for authorization"));
+	g_slist_free(filtered_buddies);
 
 	purple_notify_formatted(gc, NULL, _("You are awaiting authorization from "
 						  "the following buddies"),	_("You can re-request "
@@ -6023,6 +6011,12 @@
 		act = purple_plugin_action_new(_("Set Privacy Options..."),
 				oscar_show_icq_privacy_opts);
 		menu = g_list_prepend(menu, act);
+
+		act = purple_plugin_action_new("Show Visible List", oscar_show_visible_list);
+		menu = g_list_prepend(menu, act);
+
+		act = purple_plugin_action_new("Show Invisible List", oscar_show_invisible_list);
+		menu = g_list_prepend(menu, act);
 	}
 	else
 	{
--- a/libpurple/protocols/oscar/oscar.h	Mon Jun 28 20:02:12 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.h	Tue Jun 29 21:17:02 2010 +0000
@@ -1572,8 +1572,7 @@
 gboolean oscar_util_valid_name_sms(const char *bn);
 int oscar_util_name_compare(const char *bn1, const char *bn2);
 gchar *oscar_util_format_string(const char *str, const char *name);
-
-
+gchar *oscar_format_buddies(GSList *buddies, const gchar *no_buddies_message);
 
 typedef struct {
 	guint16 family;
--- a/libpurple/protocols/oscar/util.c	Mon Jun 28 20:02:12 2010 +0000
+++ b/libpurple/protocols/oscar/util.c	Tue Jun 29 21:17:02 2010 +0000
@@ -387,3 +387,27 @@
 
 	return g_string_free(cpy, FALSE);
 }
+
+gchar *
+oscar_format_buddies(GSList *buddies, const gchar *no_buddies_message)
+{
+	GSList *cur;
+	gchar *result, *tmp;
+	if (!buddies) {
+		return g_strdup_printf("<i>%s</i>", no_buddies_message);
+	}
+	result = g_strdup("");
+	for (cur = buddies; cur != NULL; cur = cur->next) {
+		PurpleBuddy *buddy = cur->data;
+		const gchar *bname = purple_buddy_get_name(buddy);
+		const gchar *alias = purple_buddy_get_alias_only(buddy);
+		if (alias) {
+			tmp = g_strdup_printf("%s%s (%s)<br>", result, bname, alias);
+		} else {
+			tmp = g_strdup_printf("%s%s<br>", result, bname);
+		}
+		g_free(result);
+		result = tmp;
+	}
+	return result;
+}
\ No newline at end of file
--- a/libpurple/protocols/oscar/visibility.c	Mon Jun 28 20:02:12 2010 +0000
+++ b/libpurple/protocols/oscar/visibility.c	Tue Jun 29 21:17:02 2010 +0000
@@ -57,8 +57,58 @@
 	data->list_type = list_type;
 	data->add_to_list = !on_list;
 
-	label = g_strdup_printf("%s %s", on_list ? "Don't appear" : "Appear", invisible ? "online" : "offline");
+	label = g_strdup_printf("%s %s", on_list ? "Don't appear" : "Appear", invisible ? "Online" : "Offline");
 	result = purple_menu_action_new(label, PURPLE_CALLBACK(visibility_cb), data, NULL);
 	g_free(label);
 	return result;
 }
+
+static void
+show_private_list(PurplePluginAction *action, guint16 list_type, const gchar *list_description, const gchar *menu_action_name)
+{
+	PurpleConnection *gc = (PurpleConnection *) action->context;
+	OscarData *od = purple_connection_get_protocol_data(gc);
+	PurpleAccount *account = purple_connection_get_account(gc);
+	GSList *buddies, *filtered_buddies, *cur;
+	gchar *text, *secondary;
+
+	buddies = purple_find_buddies(account, NULL);
+	filtered_buddies = NULL;
+	for (cur = buddies; cur != NULL; cur = cur->next) {
+		PurpleBuddy *buddy;
+		const gchar *bname;
+
+		buddy = cur->data;
+		bname = purple_buddy_get_name(buddy);
+		if (aim_ssi_itemlist_finditem(od->ssi.local, NULL, bname, list_type)) {
+			filtered_buddies = g_slist_prepend(filtered_buddies, buddy);
+		}
+	}
+
+	g_slist_free(buddies);
+
+	filtered_buddies = g_slist_reverse(filtered_buddies);
+	text = oscar_format_buddies(filtered_buddies, "you have no buddies on this list");
+	g_slist_free(filtered_buddies);
+
+	secondary = g_strdup_printf("You can add a buddy to this list "
+					"by right-clicking on them and "
+					"selecting \"%s\"", menu_action_name);
+	purple_notify_formatted(gc, NULL, list_description, secondary, text, NULL, NULL);
+	g_free(secondary);
+	g_free(text);
+}
+
+void
+oscar_show_visible_list(PurplePluginAction *action)
+{
+	show_private_list(action, AIM_SSI_TYPE_PERMIT, "These buddies will always see "
+							"your status, even when you switch "
+							"to \"Invisible\"", "Appear Online");
+}
+
+void
+oscar_show_invisible_list(PurplePluginAction *action)
+{
+	show_private_list(action, AIM_SSI_TYPE_DENY, "These buddies will always see you as offline", "Appear Offline");
+}
\ No newline at end of file
--- a/libpurple/protocols/oscar/visibility.h	Mon Jun 28 20:02:12 2010 +0000
+++ b/libpurple/protocols/oscar/visibility.h	Tue Jun 29 21:17:02 2010 +0000
@@ -22,8 +22,11 @@
 #define _VISIBILITY_H_
 
 #include "oscar.h"
+#include "plugin.h"
 #include "util.h"
 
 PurpleMenuAction * create_visibility_menu_item(OscarData *od, const char *bname);
+void oscar_show_visible_list(PurplePluginAction *action);
+void oscar_show_invisible_list(PurplePluginAction *action);
 
 #endif
\ No newline at end of file