Mercurial > pidgin
changeset 4412:8067614e49e4
[gaim-migrate @ 4685]
Gtk2ification. Thanks, Ari.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 25 Jan 2003 23:00:32 +0000 |
parents | 2ad81729c049 |
children | a00bfe984e7e |
files | src/away.c src/buddy.c src/server.c src/ui.h |
diffstat | 4 files changed, 124 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
--- a/src/away.c Sat Jan 25 21:23:02 2003 +0000 +++ b/src/away.c Sat Jan 25 23:00:32 2003 +0000 @@ -36,8 +36,9 @@ GtkWidget *imaway = NULL; GtkWidget *awaymenu = NULL; -GtkWidget *clistqueue = NULL; -GtkWidget *clistqueuesw; +GtkWidget *awayqueue = NULL; +GtkListStore *awayqueuestore = NULL; +GtkWidget *awayqueuesw; struct away_message *awaymessage = NULL; struct away_message *default_away; @@ -48,11 +49,55 @@ if (imaway) gtk_widget_destroy(imaway); - clistqueue = NULL; - clistqueuesw = NULL; + awayqueue = NULL; + g_object_unref(G_OBJECT(awayqueuestore)); + awayqueuestore = NULL; + awayqueuesw = NULL; imaway = NULL; } +static void dequeue_message(GtkTreeIter *iter) +{ + gchar *name; + GSList *templist; + struct gaim_conversation *cnv; + + gtk_tree_model_get(GTK_TREE_MODEL(awayqueuestore), iter, 0, &name, -1); + + debug_printf("Unqueueing messages from %s.\n", name); + + templist = message_queue; + + while (templist) { + struct queued_message *qm = templist->data; + if (templist->data) { + if (!g_strcasecmp(qm->name, name)) { + cnv = gaim_find_conversation(name); + + if (!cnv) + cnv = gaim_conversation_new(GAIM_CONV_IM, qm->name); + + if (g_slist_index(connections, qm->gc) >= 0) + gaim_conversation_set_user(cnv, qm->gc->user); + + gaim_im_write(GAIM_IM(cnv), NULL, qm->message, qm->len, + qm->flags, qm->tm); + g_free(qm->message); + g_free(qm); + templist = message_queue = g_slist_remove(message_queue, qm); + + } else { + templist = templist->next; + } + } + } + + g_free(name); + /* 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) { GSList *q = *queue; @@ -83,65 +128,33 @@ *queue = NULL; } -void dequeue_by_buddy(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data) { - char *temp; - char *name; - GSList *templist; - struct gaim_conversation *cnv; +gint dequeue_cb(GtkWidget *treeview, GdkEventButton *event, gpointer data) { + GtkTreeIter iter; + GtkTreeSelection *select; if(!(event->type == GDK_2BUTTON_PRESS && event->button == 1)) - return; /* Double clicking on the clist will unqueue that users messages. */ + return FALSE; /* Double clicking on the list will unqueue that user's messages. */ - 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) { - if (!g_strcasecmp(qm->name, name)) { - cnv = gaim_find_conversation(name); - - if (!cnv) - cnv = gaim_conversation_new(GAIM_CONV_IM, qm->name); + select = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + if(gtk_tree_selection_get_selected(select, NULL, &iter)) + dequeue_message(&iter); - if (g_slist_index(connections, qm->gc) >= 0) - gaim_conversation_set_user(cnv, qm->gc->user); - - gaim_conversation_write(cnv, NULL, qm->message, qm->len, - qm->flags, qm->tm); - g_free(qm->message); - g_free(qm); - templist = message_queue = g_slist_remove(message_queue, qm); - - } else { - templist = templist->next; - } - } - } - g_free(name); - gtk_clist_remove(GTK_CLIST(clist), row); - + 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_clist_clear(GTK_CLIST(clistqueue)); + gtk_widget_hide(awayqueue); + gtk_widget_hide(awayqueuesw); purge_away_queue(&message_queue); } } @@ -151,13 +164,8 @@ if (imaway) { GtkWidget *tmp = imaway; - gtk_clist_freeze(GTK_CLIST(clistqueue)); - gtk_clist_clear(GTK_CLIST(clistqueue)); - purge_away_queue(&message_queue); - gtk_clist_thaw(GTK_CLIST(clistqueue)); - imaway = NULL; gtk_widget_destroy(tmp); if (w != tmp) @@ -171,8 +179,10 @@ } awaymessage = NULL; - clistqueue = NULL; - clistqueuesw = NULL; + awayqueue = NULL; + awayqueuesw = NULL; + g_object_unref(G_OBJECT(awayqueuestore)); + awayqueuestore = NULL; serv_set_away_all(NULL); } @@ -183,6 +193,8 @@ GtkWidget *awaytext; GtkWidget *sw; GtkWidget *vbox; + GtkTreeViewColumn *column; + GtkCellRenderer *renderer; char *buf2; char *buf; @@ -227,22 +239,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); @@ -605,5 +630,4 @@ default_away_menu_init(GTK_WIDGET(prefs_away_menu)); gtk_widget_show(prefs_away_menu); } - }
--- a/src/buddy.c Sat Jan 25 21:23:02 2003 +0000 +++ b/src/buddy.c Sat Jan 25 23:00:32 2003 +0000 @@ -2225,7 +2225,7 @@ get_buddy_alias(b)); gaim_conversation_write(c, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL)); - } else if (clistqueue && find_queue_total_by_name(b->name)) { + } else if (awayqueue && find_queue_total_by_name(b->name)) { struct queued_message *qm = g_new0(struct queued_message, 1); g_snprintf(qm->name, sizeof(qm->name), "%s", b->name); qm->message = g_strdup_printf(_("%s logged in."), @@ -2287,7 +2287,7 @@ get_buddy_alias(b)); gaim_conversation_write(c, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL)); - } else if (clistqueue && find_queue_total_by_name(b->name)) { + } else if (awayqueue && find_queue_total_by_name(b->name)) { struct queued_message *qm = g_new0(struct queued_message, 1); g_snprintf(qm->name, sizeof(qm->name), "%s", get_buddy_alias(b));
--- a/src/server.c Sat Jan 25 21:23:02 2003 +0000 +++ b/src/server.c Sat Jan 25 23:00:32 2003 +0000 @@ -492,17 +492,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; @@ -667,7 +670,7 @@ * 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 @@ -675,6 +678,8 @@ * that we've queued something. */ struct queued_message *qm; + GtkTreeIter iter; + gchar path[10]; qm = g_new0(struct queued_message, 1); g_snprintf(qm->name, sizeof(qm->name), "%s", name); @@ -686,20 +691,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 { /* @@ -775,7 +785,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 Sat Jan 25 21:23:02 2003 +0000 +++ b/src/ui.h Sat Jan 25 23:00:32 2003 +0000 @@ -297,7 +297,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;