changeset 4124:19ee0409a3d7

[gaim-migrate @ 4341] fix segfault on returning from away with messages queued from ari. also gets rid of some gtk1.2 code in favor of gtk2 code. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 23 Dec 2002 23:08:14 +0000
parents 1e87350cb57c
children 6ba49fc29d67
files src/away.c src/server.c src/ui.h
diffstat 3 files changed, 107 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/src/away.c	Mon Dec 23 22:04:40 2002 +0000
+++ b/src/away.c	Mon Dec 23 23:08:14 2002 +0000
@@ -36,8 +36,9 @@
 GtkWidget *imaway = NULL;
 
 GtkWidget *awaymenu = NULL;
-GtkWidget *clistqueue = NULL;
-GtkWidget *clistqueuesw;
+GtkWidget *awayqueue = NULL;
+GtkListStore *awayqueuestore;
+GtkWidget *awayqueuesw;
 
 struct away_message *awaymessage = NULL;
 struct away_message *default_away;
@@ -48,53 +49,24 @@
 	if (imaway)
 		gtk_widget_destroy(imaway);
 
-	clistqueue = NULL;
-	clistqueuesw = NULL;
+	awayqueue = NULL;
+	awayqueuestore = NULL;
+	awayqueuesw = NULL;
 	imaway = NULL;
 }
 
-void purge_away_queue(GSList *queue)
+void dequeue_message(GtkTreeIter *iter)
 {
+	gchar *name;
+	GSList *templist;
 	struct conversation *cnv;
 
-	gtk_clist_freeze(GTK_CLIST(clistqueue));
-	gtk_clist_clear(GTK_CLIST(clistqueue));
-
-	while (queue) {
-		struct queued_message *qm = queue->data;
-
-		cnv = find_conversation(qm->name);
-		if (!cnv)
-			cnv = new_conversation(qm->name);
-		if (g_slist_index(connections, qm->gc) >= 0)
-			set_convo_gc(cnv, qm->gc);
-		write_to_conv(cnv, qm->message, qm->flags, NULL, qm->tm, qm->len);
-
-		queue = g_slist_remove(queue, qm);
-
-		g_free(qm->message);
-		g_free(qm);
-	}
-
-	gtk_clist_thaw(GTK_CLIST(clistqueue));
-}
-
-void dequeue_by_buddy(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data) {
-	char *temp;
-	char *name;
-	GSList *templist;
-	struct conversation *cnv;
+	gtk_tree_model_get(GTK_TREE_MODEL(awayqueuestore), iter, 0, &name, -1);
 	
-	if(!(event->type == GDK_2BUTTON_PRESS && event->button == 1))
-		return; /* Double clicking on the clist will unqueue that users messages. */
+	debug_printf("Unqueueing messages from %s.\n", name);
 	
-	gtk_clist_get_text(GTK_CLIST(clist), row, 0, &temp);
-	name = g_strdup(temp);
-
-	if (!name)
-		return;
-	debug_printf("Unqueueing messages from %s.\n", name);
 	templist = message_queue;
+	
 	while (templist) {
 		struct queued_message *qm = templist->data;
 		if (templist->data) {
@@ -115,25 +87,55 @@
 			}
 		}
 	}
+	
 	g_free(name);
-	gtk_clist_remove(GTK_CLIST(clist), row);
+	/* In GTK 2.2, _store_remove actually returns whether iter is valid or not
+	 * after the remove, but in GTK 2.0 it is a void function. */
+	gtk_list_store_remove(awayqueuestore, iter);
+}
+
+void purge_away_queue(GSList *queue)
+{
+	gboolean valid;
+	GtkTreeIter iter;
 
+	valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(awayqueuestore), &iter);
+	while(valid) {
+		dequeue_message(&iter);
+		valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(awayqueuestore),
+				&iter);
+	}	
+	
+	g_object_unref(G_OBJECT(awayqueuestore));
 }
+
+gint dequeue_cb(GtkWidget *treeview, GdkEventButton *event, gpointer data) {
+	GtkTreeIter iter;
+	GtkTreeSelection *select;
 	
+	if(!(event->type == GDK_2BUTTON_PRESS && event->button == 1))
+		return FALSE; /* Double clicking on the list will unqueue that user's messages. */
+	
+	select = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
+	if(gtk_tree_selection_get_selected(select, NULL, &iter))
+			dequeue_message(&iter);
+
+	return FALSE;
+}
 	
 
 
 void toggle_away_queue()
 {
-	if (!clistqueue || !clistqueuesw)
+	if (!awayqueue || !awayqueuesw)
 		return;
 
 	if (away_options & OPT_AWAY_QUEUE) {
-		gtk_widget_show(clistqueue);
-		gtk_widget_show(clistqueuesw);
+		gtk_widget_show(awayqueue);
+		gtk_widget_show(awayqueuesw);
 	} else {
-		gtk_widget_hide(clistqueue);
-		gtk_widget_hide(clistqueuesw);
+		gtk_widget_hide(awayqueue);
+		gtk_widget_hide(awayqueuesw);
 		purge_away_queue(message_queue);
 	}
 }
@@ -158,8 +160,8 @@
 	}
 
 	awaymessage = NULL;
-	clistqueue = NULL;
-	clistqueuesw = NULL;
+	awayqueue = NULL;
+	awayqueuesw = NULL;
 	serv_set_away_all(NULL);
 }
 
@@ -170,6 +172,8 @@
 	GtkWidget *awaytext;
 	GtkWidget *sw;
 	GtkWidget *vbox;
+	GtkTreeViewColumn *column;
+	GtkCellRenderer *renderer;
 	char *buf2;
 	char *buf;
 
@@ -213,22 +217,35 @@
 		gtk_imhtml_append_text(GTK_IMHTML(awaytext), "<BR>", -1, GTK_IMHTML_NO_TITLE |
 				       GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_SCROLL);
 
-		clistqueuesw = gtk_scrolled_window_new(NULL, NULL);
-		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clistqueuesw), GTK_POLICY_NEVER,
+		awayqueuesw = gtk_scrolled_window_new(NULL, NULL);
+		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(awayqueuesw), GTK_POLICY_NEVER,
 					       GTK_POLICY_AUTOMATIC);
-		gtk_box_pack_start(GTK_BOX(vbox), clistqueuesw, TRUE, TRUE, 0);
+		gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(awayqueuesw),
+							GTK_SHADOW_IN);
+		gtk_box_pack_start(GTK_BOX(vbox), awayqueuesw, TRUE, TRUE, 0);
 
-		clistqueue = gtk_clist_new(2);
-		gtk_clist_set_column_width(GTK_CLIST(clistqueue), 0, 100);
-		gtk_widget_set_usize(GTK_WIDGET(clistqueue), -1, 50);
-		gtk_container_add(GTK_CONTAINER(clistqueuesw), clistqueue);
-		gtk_signal_connect(GTK_OBJECT(clistqueue), "select_row", GTK_SIGNAL_FUNC(dequeue_by_buddy), NULL);
-
+		awayqueuestore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+		awayqueue = gtk_tree_view_new_with_model(GTK_TREE_MODEL(awayqueuestore));
+		renderer = gtk_cell_renderer_text_new();
+		
+		gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(awayqueue), FALSE);
+		column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
+										"text", 0,
+										NULL);
+		gtk_tree_view_append_column(GTK_TREE_VIEW(awayqueue), column);
+		column = gtk_tree_view_column_new_with_attributes(NULL, renderer,
+										"text", 1, 
+										NULL);
+		gtk_tree_view_append_column(GTK_TREE_VIEW(awayqueue), column);
+			
+		gtk_container_add(GTK_CONTAINER(awayqueuesw), awayqueue);
+		
+		g_signal_connect(G_OBJECT(awayqueue), "button_press_event", G_CALLBACK(dequeue_cb), NULL);
 
 
 		if (away_options & OPT_AWAY_QUEUE) {
-			gtk_widget_show(clistqueuesw);
-			gtk_widget_show(clistqueue);
+			gtk_widget_show(awayqueuesw);
+			gtk_widget_show(awayqueue);
 		}
 
 		back = picture_button(imaway, _("I'm Back!"), join_xpm);
--- a/src/server.c	Mon Dec 23 22:04:40 2002 +0000
+++ b/src/server.c	Mon Dec 23 23:08:14 2002 +0000
@@ -473,17 +473,20 @@
 
 int find_queue_row_by_name(char *name)
 {
-	GSList *templist;
-	char *temp;
-	int i;
-
-	templist = message_queue;
+	gchar *temp;
+	gint i = 0;
+	gboolean valid;
+	GtkTreeIter iter;
 
-	for (i = 0; i < GTK_CLIST(clistqueue)->rows; i++) {
-		gtk_clist_get_text(GTK_CLIST(clistqueue), i, 0, &temp);
-
-		if (!strcmp(name, temp))
+	valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(awayqueuestore), &iter);
+	while(valid) {
+		gtk_tree_model_get(GTK_TREE_MODEL(awayqueuestore), &iter, 0, &temp, -1);
+		if(!strcmp(name, temp))
 			return i;
+		g_free(temp);
+		
+		i++;
+		valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(awayqueuestore), &iter);
 	}
 
 	return -1;
@@ -623,13 +626,14 @@
 		 * imaway dialog being shown. in fact, it's possible for *all* the accounts to be
 		 * away without the imaway dialog being shown. so in order for this to be queued
 		 * properly, we have to make sure that the imaway dialog actually exists, first. */
-		if (!cnv && clistqueue && (away_options & OPT_AWAY_QUEUE)) {
+		if (!cnv && awayqueue && (away_options & OPT_AWAY_QUEUE)) {
 			/* alright, so we're going to queue it. neat, eh? :) so first we create
 			 * something to store the message, and add it to our queue. Then we update
 			 * the away dialog to indicate that we've queued something. */
 			struct queued_message *qm;
-			struct buddy *b;
-
+			GtkTreeIter iter;
+			gchar path[10];
+			
 			qm = g_new0(struct queued_message, 1);
 				g_snprintf(qm->name, sizeof(qm->name), "%s", name);
 			qm->message = g_memdup(message, len == -1 ? strlen(message) + 1 : len);
@@ -640,20 +644,25 @@
 			message_queue = g_slist_append(message_queue, qm);
 
 			row = find_queue_row_by_name(qm->name);
-
 			if (row >= 0) {
 				char number[32];
 				int qtotal;
 
 				qtotal = find_queue_total_by_name(qm->name);
 				g_snprintf(number, 32, _("(%d messages)"), qtotal);
-				gtk_clist_set_text(GTK_CLIST(clistqueue), row, 1, number);
+				g_snprintf(path, 10, "%d", row);
+				gtk_tree_model_get_iter_from_string(
+								GTK_TREE_MODEL(awayqueuestore), &iter, path);
+				gtk_list_store_set(awayqueuestore, &iter,
+								1, number, -1);
 			} else {
-				gchar *heh[2];
-
-				heh[0] = qm->name;
-				heh[1] = _("(1 message)");
-				gtk_clist_append(GTK_CLIST(clistqueue), heh);
+				gtk_tree_model_get_iter_first(GTK_TREE_MODEL(awayqueuestore), 
+								&iter);
+				gtk_list_store_append(awayqueuestore, &iter);
+				gtk_list_store_set(awayqueuestore, &iter,
+								0, qm->name,
+								1, _("(1 message)"),
+								-1);
 			}
 		} else {
 			/* ok, so we're not queuing it. well then, we'll try to handle it normally.
@@ -717,7 +726,7 @@
 		/* apply default fonts and colors */
 		tmpmsg = stylize(gc->away, MSG_LEN);
 		serv_send_im(gc, name, away_subs(tmpmsg, alias), -1, IM_FLAG_AWAY);
-		if (!cnv && clistqueue && (away_options & OPT_AWAY_QUEUE)) {
+		if (!cnv && awayqueue && (away_options & OPT_AWAY_QUEUE)) {
 			struct queued_message *qm;
 			qm = g_new0(struct queued_message, 1);
 			g_snprintf(qm->name, sizeof(qm->name), "%s", name);
--- a/src/ui.h	Mon Dec 23 22:04:40 2002 +0000
+++ b/src/ui.h	Mon Dec 23 23:08:14 2002 +0000
@@ -280,7 +280,8 @@
 extern struct away_message *default_away;
 extern int auto_away;
 extern GtkWidget *awaymenu;
-extern GtkWidget *clistqueue; 
+extern GtkWidget *awayqueue;
+extern GtkListStore *awayqueuestore;
 
 /* Globals in buddy.c */
 extern GtkWidget *buddies;