changeset 28072:74ce58c7bc30

Further pounce dialog improvements. Refs #10037. Make the pounce dialog multi-selectable, add an "IM" button, and fix the activate-row callback to open a conversation with the right person. Quoting Masca (for using gtk_tree_selection_get_selected): "shame on me."
author Paul Aurich <paul@darkrain42.org>
date Sun, 23 Aug 2009 02:10:43 +0000
parents 1a9e56e2097a
children 208f4d20ac5d
files pidgin/gtknotify.c
diffstat 1 files changed, 67 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtknotify.c	Sat Aug 22 23:33:44 2009 +0000
+++ b/pidgin/gtknotify.c	Sun Aug 23 02:10:43 2009 +0000
@@ -60,6 +60,7 @@
 {
 	PurpleAccount *account;
 	PurplePounce *pounce;
+	char *pouncee;
 } PidginNotifyPounceData;
 
 
@@ -155,6 +156,7 @@
 				-1);
 		gtk_tree_store_remove(dialog->treemodel, &iter);
 
+		g_free(pounce_data->pouncee);
 		g_free(pounce_data);
 	}
 
@@ -173,8 +175,29 @@
 			PIDGIN_POUNCE_DATA, &pounce_data,
 			-1);
 
-	if (pounce_data != NULL)
+	if (pounce_data != NULL) {
+		g_free(pounce_data->pouncee);
 		g_free(pounce_data);
+	}
+}
+
+static void
+open_im_foreach(GtkTreeModel *model, GtkTreePath *path,
+		GtkTreeIter *iter, gpointer data)
+{
+	PidginNotifyPounceData *pounce_data;
+
+	gtk_tree_model_get(model, iter,
+			PIDGIN_POUNCE_DATA, &pounce_data,
+			-1);
+
+	if (pounce_data != NULL) {
+		PurpleConversation *conv;
+
+		conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
+				pounce_data->account, pounce_data->pouncee);
+		purple_conversation_present(conv);
+	}
 }
 
 static void
@@ -211,6 +234,17 @@
 }
 
 static void
+pounce_response_open_ims()
+{
+	GtkTreeSelection *selection;
+
+	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pounce_dialog->treeview));
+	gtk_tree_selection_selected_foreach(selection, open_im_foreach, pounce_dialog);
+	
+	pounce_response_dismiss();
+}
+
+static void
 pounce_response_edit_cb(GtkTreeModel *model, GtkTreePath *path,
 		GtkTreeIter *iter, gpointer data)
 {
@@ -246,6 +280,9 @@
 		case GTK_RESPONSE_DELETE_EVENT:
 			pounce_response_close(dialog);
 			break;
+		case GTK_RESPONSE_YES:
+			pounce_response_open_ims();
+			break;
 		case GTK_RESPONSE_NO:
 			pounce_response_dismiss();
 			break;
@@ -261,68 +298,53 @@
 pounce_row_selected_cb(GtkTreeView *tv, GtkTreePath *path,
 	GtkTreeViewColumn *col, gpointer data)
 {
-	GtkTreeIter iter;
 	GtkTreeSelection *selection;
-	gboolean selected;
-	GList *list;
+	int count;
 
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pounce_dialog->treeview));
 
-	selected = gtk_tree_selection_get_selected(selection,
-			NULL, &iter);
+	count = gtk_tree_selection_count_selected_rows(selection);
 
-	if (selected) {
-		PurplePounce *pounce;
+	if (count == 0) {
+		gtk_widget_set_sensitive(pounce_dialog->open_button, FALSE);
+		gtk_widget_set_sensitive(pounce_dialog->edit_button, FALSE);
+		gtk_widget_set_sensitive(pounce_dialog->dismiss_button, FALSE);
+	} else if (count == 1) {
+		GList *pounces;
+		GList *list;
 		PidginNotifyPounceData *pounce_data;
+		GtkTreeIter iter;
 
-		list = purple_pounces_get_all();
-
+		list = gtk_tree_selection_get_selected_rows(selection, NULL);
+		gtk_tree_model_get_iter(GTK_TREE_MODEL(pounce_dialog->treemodel),
+				&iter, list->data);
 		gtk_tree_model_get(GTK_TREE_MODEL(pounce_dialog->treemodel), &iter,
 				PIDGIN_POUNCE_DATA, &pounce_data,
 				-1);
-
-		gtk_widget_set_sensitive(pounce_dialog->edit_button, FALSE);
+		g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL);
+		g_list_free(list);
 
-		for (; list != NULL; list = list->next) {
-			pounce = list->data;
+		pounces = purple_pounces_get_all();
+		for (; pounces != NULL; pounces = pounces->next) {
+			PurplePounce *pounce = pounces->data;
 			if (pounce == pounce_data->pounce) {
 				gtk_widget_set_sensitive(pounce_dialog->edit_button, TRUE);
 				break;
 			}
 		}
 
+		gtk_widget_set_sensitive(pounce_dialog->open_button, TRUE);
 		gtk_widget_set_sensitive(pounce_dialog->dismiss_button, TRUE);
 	} else {
+		gtk_widget_set_sensitive(pounce_dialog->open_button, TRUE);
 		gtk_widget_set_sensitive(pounce_dialog->edit_button, FALSE);
-		gtk_widget_set_sensitive(pounce_dialog->dismiss_button, FALSE);
+		gtk_widget_set_sensitive(pounce_dialog->dismiss_button, TRUE);
 	}
 
 
 }
 
 static void
-pounce_row_activated_cb(GtkTreeView *tv, GtkTreePath *path,
-	GtkTreeViewColumn *col, gpointer data)
-{
-	PidginNotifyPounceData *pounce_data;
-	PurpleAccount *account;
-	GtkTreeIter iter;
-
-	if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(pounce_dialog->treemodel), &iter, path))
-		return;
-
-	gtk_tree_model_get(GTK_TREE_MODEL(pounce_dialog->treemodel), &iter,
-		PIDGIN_POUNCE_DATA, &pounce_data, -1);
-
-	account = pounce_data->account;
-
-	purple_conversation_new(PURPLE_CONV_TYPE_IM, account,
-		purple_account_get_username(account));
-
-	pounce_response_dismiss();
-}
-
-static void
 reset_mail_dialog(GtkDialog *unused)
 {
 	if (mail_dialog->in_use)
@@ -1388,6 +1410,7 @@
 
 	pounce_data->account = account;
 	pounce_data->pounce = pounce;
+	pounce_data->pouncee = g_strdup(purple_pounce_get_pouncee(pounce));
 
 	gtk_tree_store_append(pounce_dialog->treemodel, &iter, NULL);
 
@@ -1511,6 +1534,11 @@
 		gtk_window_set_title(GTK_WINDOW(dialog), _("New Pounces"));
 
 		button = gtk_dialog_add_button(GTK_DIALOG(dialog),
+						_("IM"), GTK_RESPONSE_YES);
+		gtk_widget_set_sensitive(button, FALSE);
+		spec_dialog->open_button = button;
+	
+		button = gtk_dialog_add_button(GTK_DIALOG(dialog),
 						_("Dismiss"), GTK_RESPONSE_NO);
 		gtk_widget_set_sensitive(button, FALSE);
 		spec_dialog->dismiss_button = button;
@@ -1563,11 +1591,11 @@
 		gtk_label_set_markup(GTK_LABEL(label), _("<span weight=\"bold\" size=\"larger\">You have pounced!</span>"));
 
 		sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(spec_dialog->treeview));
-		gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
+		gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE);
 		g_signal_connect(G_OBJECT(sel), "changed",
 			G_CALLBACK(pounce_row_selected_cb), NULL);
 		g_signal_connect(G_OBJECT(spec_dialog->treeview), "row-activated",
-			G_CALLBACK(pounce_row_activated_cb), NULL);
+			G_CALLBACK(pounce_response_open_ims), NULL);
 	}
 
 	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);