soc.2010.icq-tlc: eca3adf7: Applied and slightly modified Sadrul's p...

ivan.komarov at soc.pidgin.im ivan.komarov at soc.pidgin.im
Thu Jul 8 13:56:17 EDT 2010


----------------------------------------------------------------------
Revision: eca3adf7cdd9217fcf670611fb705385fcfaa48d
Parent:   7f7c58ec53c2d4419f78f66bf32c3c444987b621
Author:   ivan.komarov at soc.pidgin.im
Date:     07/08/10 10:58:55
Branch:   im.pidgin.soc.2010.icq-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/eca3adf7cdd9217fcf670611fb705385fcfaa48d

Changelog: 

Applied and slightly modified Sadrul's patch (http://pidgin.im/~sadrul/pp/icq-list.patch.txt)
for making the Visible/Invisible list editors support in-place editing.

The end result looks like this: http://pidgin.im/~sadrul/ss/icq-list.png

This dialog has some rough edges, so I commit it as a separate revision
and return to it later.

Changes against parent 7f7c58ec53c2d4419f78f66bf32c3c444987b621

  patched  libpurple/protocols/oscar/visibility.c

-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/visibility.c	2fa0497ed474a598202098dd2bce22ec32b02942
+++ libpurple/protocols/oscar/visibility.c	082c782bfb6f2f33b29ca349b521c0432fb5bbd8
@@ -16,9 +16,10 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
-*/
+ */
 
 #include "visibility.h"
+#include "request.h"
 
 /* 4 separate strings are needed in order to ease translators' job */
 #define APPEAR_ONLINE		N_("Appear Online")
@@ -70,17 +71,77 @@ create_visibility_menu_item(OscarData *o
 	return purple_menu_action_new(label, PURPLE_CALLBACK(visibility_cb), NULL, NULL);
 }
 
+typedef void (*ShowDialog)(PurplePluginAction *);
+
+struct list_remove_data
+{
+	PurplePluginAction *action;
+	ShowDialog show_dialog_again;
+	OscarData *od;
+	guint16 list_type;
+	const gchar *list_name;
+};
+
 static void
-show_private_list(PurplePluginAction *action, guint16 list_type, const gchar *title, const gchar *list_description, const gchar *menu_action_name)
+list_remove_cb(struct list_remove_data *data, PurpleRequestFields *fields)
 {
+	ShowDialog show_dialog_again = data->show_dialog_again;
+	PurplePluginAction *action = data->action;
+	PurpleRequestField *field = purple_request_fields_get_field(fields, "list-items");
+	GList *sels = purple_request_field_list_get_selected(field);
+	for (; sels; sels = sels->next) {
+		const gchar *name = sels->data;
+		const gchar *bname = purple_request_field_list_get_data(field, name);
+
+		purple_debug_info("oscar", "Removing %s from %s\n", bname, data->list_name);
+
+		aim_ssi_del_from_private_list(data->od, bname, data->list_type);
+	}
+
+	g_free(data);
+	show_dialog_again(action);
+}
+
+static void
+list_close_cb(struct list_remove_data *data, gpointer ignored)
+{
+	g_free(data);
+}
+
+static void
+show_private_list(PurplePluginAction *action,
+		  guint16 list_type,
+		  const gchar *list_name,
+		  const gchar *list_description,
+		  const gchar *menu_action_name,
+		  ShowDialog caller)
+{
 	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;
+	GSList *buddies, *cur;
+	gchar *desc;
+	struct list_remove_data *data;
 
+	PurpleRequestField *field;
+	PurpleRequestFields *fields = purple_request_fields_new();
+	PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL);
+
+	purple_request_fields_add_group(fields, group);
+
+	desc = g_strdup_printf(_("You can add a buddy to this list "
+				 "by right-clicking on them and "
+				 "selecting \"%s\""), menu_action_name);
+
+	field = purple_request_field_list_new("list-items", desc);
+	g_free(desc);
+
+	purple_request_field_group_add_field(group, field);
+
+	purple_request_field_list_set_multi_select(field, TRUE);
+	purple_request_field_set_required(field, TRUE);
+
 	buddies = purple_find_buddies(account, NULL);
-	filtered_buddies = NULL;
 	for (cur = buddies; cur != NULL; cur = cur->next) {
 		PurpleBuddy *buddy;
 		const gchar *bname;
@@ -88,38 +149,51 @@ show_private_list(PurplePluginAction *ac
 		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);
+			const gchar *alias = purple_buddy_get_alias_only(buddy);
+			char *dname = alias ? g_strdup_printf("%s (%s)", bname, alias) : NULL;
+			purple_request_field_list_add(field, dname ? dname : bname, (void *)bname);
+			g_free(dname);
 		}
 	}
 
 	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);
+	data = g_new0(struct list_remove_data, 1);
+	data->action = action;
+	data->show_dialog_again = caller;
+	data->od = od;
+	data->list_type = list_type;
+	data->list_name = list_name;
 
-	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, title, list_description, secondary, text, NULL, NULL);
-	g_free(secondary);
-	g_free(text);
+	purple_request_fields(gc, list_name, list_description, NULL,
+			      fields,
+			      _("Close"), G_CALLBACK(list_close_cb),
+			      _("Remove"), G_CALLBACK(list_remove_cb),
+			      account, NULL, NULL,
+			      data);
 }
 
 void
 oscar_show_visible_list(PurplePluginAction *action)
 {
-	show_private_list(action, AIM_SSI_TYPE_PERMIT, _("Visible List"),
-							_("These buddies will see "
-							"your status when you switch "
-							"to \"Invisible\""),
-							_(APPEAR_ONLINE));
+	show_private_list(action,
+			  AIM_SSI_TYPE_PERMIT,
+			  _("Visible List"),
+			  _("These buddies will see "
+			    "your status when you switch "
+			    "to \"Invisible\""),
+			  _(APPEAR_ONLINE),
+			  oscar_show_visible_list);
 }
 
 void
 oscar_show_invisible_list(PurplePluginAction *action)
 {
-	show_private_list(action, AIM_SSI_TYPE_DENY, _("Invisible List"),
-							_("These buddies will always see you as offline"),
-							_(APPEAR_OFFLINE));
-}
\ No newline at end of file
+	show_private_list(action,
+			  AIM_SSI_TYPE_DENY,
+			  _("Invisible List"),
+			  _("These buddies will always see you as offline"),
+			  _(APPEAR_OFFLINE),
+			  oscar_show_invisible_list);
+}
+


More information about the Commits mailing list