comparison src/away.c @ 4167:7002b6f16bdf

[gaim-migrate @ 4396] (00:14:20) Robot101: if anyone with CVS would like to choose between the docklet eating messages if you ask it to queue them, or an occasional crash when returning from away with queued messages, I have a patch to revert ari's 'fix' at http://people.debian.org/~robot101/silly-ari.diff (00:15:05) Robot101: Sean and I agreed that keeping the queued messages in a GSList is better, so if ari could seperate the gtk2ification and the fixing of the crash, without breaking the generic queueing stuff, that'd be peachy (00:15:22) Robot101: in the meantime, the docklet saying it has queued messages, and not letting you read them, is pretty damn obnoxious. (00:16:30) LSchiere: i'll do it committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Thu, 02 Jan 2003 05:18:16 +0000
parents d3c8d2b40494
children 906f61f27479
comparison
equal deleted inserted replaced
4166:481c51159627 4167:7002b6f16bdf
34 #include "pixmaps/join.xpm" 34 #include "pixmaps/join.xpm"
35 35
36 GtkWidget *imaway = NULL; 36 GtkWidget *imaway = NULL;
37 37
38 GtkWidget *awaymenu = NULL; 38 GtkWidget *awaymenu = NULL;
39 GtkWidget *awayqueue = NULL; 39 GtkWidget *clistqueue = NULL;
40 GtkListStore *awayqueuestore; 40 GtkWidget *clistqueuesw;
41 GtkWidget *awayqueuesw;
42 41
43 struct away_message *awaymessage = NULL; 42 struct away_message *awaymessage = NULL;
44 struct away_message *default_away; 43 struct away_message *default_away;
45 int auto_away; 44 int auto_away;
46 45
47 static void destroy_im_away() 46 static void destroy_im_away()
48 { 47 {
49 if (imaway) 48 if (imaway)
50 gtk_widget_destroy(imaway); 49 gtk_widget_destroy(imaway);
51 50
52 awayqueue = NULL; 51 clistqueue = NULL;
53 awayqueuestore = NULL; 52 clistqueuesw = NULL;
54 awayqueuesw = NULL;
55 imaway = NULL; 53 imaway = NULL;
56 } 54 }
57 55
58 void dequeue_message(GtkTreeIter *iter) 56 void purge_away_queue(GSList *queue)
59 { 57 {
60 gchar *name; 58 struct conversation *cnv;
59
60 gtk_clist_freeze(GTK_CLIST(clistqueue));
61 gtk_clist_clear(GTK_CLIST(clistqueue));
62
63 while (queue) {
64 struct queued_message *qm = queue->data;
65
66 cnv = find_conversation(qm->name);
67 if (!cnv)
68 cnv = new_conversation(qm->name);
69 if (g_slist_index(connections, qm->gc) >= 0)
70 set_convo_gc(cnv, qm->gc);
71 write_to_conv(cnv, qm->message, qm->flags, NULL, qm->tm, qm->len);
72
73 queue = g_slist_remove(queue, qm);
74
75 g_free(qm->message);
76 g_free(qm);
77 }
78
79 gtk_clist_thaw(GTK_CLIST(clistqueue));
80 }
81
82 void dequeue_by_buddy(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data) {
83 char *temp;
84 char *name;
61 GSList *templist; 85 GSList *templist;
62 struct conversation *cnv; 86 struct conversation *cnv;
63
64 gtk_tree_model_get(GTK_TREE_MODEL(awayqueuestore), iter, 0, &name, -1);
65 87
88 if(!(event->type == GDK_2BUTTON_PRESS && event->button == 1))
89 return; /* Double clicking on the clist will unqueue that users messages. */
90
91 gtk_clist_get_text(GTK_CLIST(clist), row, 0, &temp);
92 name = g_strdup(temp);
93
94 if (!name)
95 return;
66 debug_printf("Unqueueing messages from %s.\n", name); 96 debug_printf("Unqueueing messages from %s.\n", name);
67
68 templist = message_queue; 97 templist = message_queue;
69
70 while (templist) { 98 while (templist) {
71 struct queued_message *qm = templist->data; 99 struct queued_message *qm = templist->data;
72 if (templist->data) { 100 if (templist->data) {
73 if (!g_strcasecmp(qm->name, name)) { 101 if (!g_strcasecmp(qm->name, name)) {
74 cnv = find_conversation(name); 102 cnv = find_conversation(name);
85 } else { 113 } else {
86 templist = templist->next; 114 templist = templist->next;
87 } 115 }
88 } 116 }
89 } 117 }
118 g_free(name);
119 gtk_clist_remove(GTK_CLIST(clist), row);
120
121 }
90 122
91 g_free(name);
92 /* In GTK 2.2, _store_remove actually returns whether iter is valid or not
93 * after the remove, but in GTK 2.0 it is a void function. */
94 gtk_list_store_remove(awayqueuestore, iter);
95 }
96
97 void purge_away_queue(GSList *queue)
98 {
99 gboolean valid;
100 GtkTreeIter iter;
101
102 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(awayqueuestore), &iter);
103 while(valid) {
104 dequeue_message(&iter);
105 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(awayqueuestore),
106 &iter);
107 }
108 123
109 g_object_unref(G_OBJECT(awayqueuestore));
110 }
111
112 gint dequeue_cb(GtkWidget *treeview, GdkEventButton *event, gpointer data) {
113 GtkTreeIter iter;
114 GtkTreeSelection *select;
115
116 if(!(event->type == GDK_2BUTTON_PRESS && event->button == 1))
117 return FALSE; /* Double clicking on the list will unqueue that user's messages. */
118
119 select = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
120 if(gtk_tree_selection_get_selected(select, NULL, &iter))
121 dequeue_message(&iter);
122
123 return FALSE;
124 }
125
126 124
127 125
128 void toggle_away_queue() 126 void toggle_away_queue()
129 { 127 {
130 if (!awayqueue || !awayqueuesw) 128 if (!clistqueue || !clistqueuesw)
131 return; 129 return;
132 130
133 if (away_options & OPT_AWAY_QUEUE) { 131 if (away_options & OPT_AWAY_QUEUE) {
134 gtk_widget_show(awayqueue); 132 gtk_widget_show(clistqueue);
135 gtk_widget_show(awayqueuesw); 133 gtk_widget_show(clistqueuesw);
136 } else { 134 } else {
137 gtk_widget_hide(awayqueue); 135 gtk_widget_hide(clistqueue);
138 gtk_widget_hide(awayqueuesw); 136 gtk_widget_hide(clistqueuesw);
139 purge_away_queue(message_queue); 137 purge_away_queue(message_queue);
140 } 138 }
141 } 139 }
142 140
143 void do_im_back(GtkWidget *w, GtkWidget *x) 141 void do_im_back(GtkWidget *w, GtkWidget *x)
158 away_time_queue = g_slist_remove(away_time_queue, qar); 156 away_time_queue = g_slist_remove(away_time_queue, qar);
159 g_free(qar); 157 g_free(qar);
160 } 158 }
161 159
162 awaymessage = NULL; 160 awaymessage = NULL;
163 awayqueue = NULL; 161 clistqueue = NULL;
164 awayqueuesw = NULL; 162 clistqueuesw = NULL;
165 serv_set_away_all(NULL); 163 serv_set_away_all(NULL);
166 } 164 }
167 165
168 166
169 void do_away_message(GtkWidget *w, struct away_message *a) 167 void do_away_message(GtkWidget *w, struct away_message *a)
170 { 168 {
171 GtkWidget *back; 169 GtkWidget *back;
172 GtkWidget *awaytext; 170 GtkWidget *awaytext;
173 GtkWidget *sw; 171 GtkWidget *sw;
174 GtkWidget *vbox; 172 GtkWidget *vbox;
175 GtkTreeViewColumn *column;
176 GtkCellRenderer *renderer;
177 char *buf2; 173 char *buf2;
178 char *buf; 174 char *buf;
179 175
180 if (!blist) 176 if (!blist)
181 return; 177 return;
216 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_SCROLL); 212 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_SCROLL);
217 g_free(buf); 213 g_free(buf);
218 gtk_imhtml_append_text(GTK_IMHTML(awaytext), "<BR>", -1, GTK_IMHTML_NO_TITLE | 214 gtk_imhtml_append_text(GTK_IMHTML(awaytext), "<BR>", -1, GTK_IMHTML_NO_TITLE |
219 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_SCROLL); 215 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_SCROLL);
220 216
221 awayqueuesw = gtk_scrolled_window_new(NULL, NULL); 217 clistqueuesw = gtk_scrolled_window_new(NULL, NULL);
222 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(awayqueuesw), GTK_POLICY_NEVER, 218 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clistqueuesw), GTK_POLICY_NEVER,
223 GTK_POLICY_AUTOMATIC); 219 GTK_POLICY_AUTOMATIC);
224 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(awayqueuesw), 220 gtk_box_pack_start(GTK_BOX(vbox), clistqueuesw, TRUE, TRUE, 0);
225 GTK_SHADOW_IN); 221
226 gtk_box_pack_start(GTK_BOX(vbox), awayqueuesw, TRUE, TRUE, 0); 222 clistqueue = gtk_clist_new(2);
227 223 gtk_clist_set_column_width(GTK_CLIST(clistqueue), 0, 100);
228 awayqueuestore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); 224 gtk_widget_set_usize(GTK_WIDGET(clistqueue), -1, 50);
229 awayqueue = gtk_tree_view_new_with_model(GTK_TREE_MODEL(awayqueuestore)); 225 gtk_container_add(GTK_CONTAINER(clistqueuesw), clistqueue);
230 renderer = gtk_cell_renderer_text_new(); 226 gtk_signal_connect(GTK_OBJECT(clistqueue), "select_row", GTK_SIGNAL_FUNC(dequeue_by_buddy), NULL);
231 227
232 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(awayqueue), FALSE);
233 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
234 "text", 0,
235 NULL);
236 gtk_tree_view_append_column(GTK_TREE_VIEW(awayqueue), column);
237 column = gtk_tree_view_column_new_with_attributes(NULL, renderer,
238 "text", 1,
239 NULL);
240 gtk_tree_view_append_column(GTK_TREE_VIEW(awayqueue), column);
241
242 gtk_container_add(GTK_CONTAINER(awayqueuesw), awayqueue);
243
244 g_signal_connect(G_OBJECT(awayqueue), "button_press_event", G_CALLBACK(dequeue_cb), NULL);
245 228
246 229
247 if (away_options & OPT_AWAY_QUEUE) { 230 if (away_options & OPT_AWAY_QUEUE) {
248 gtk_widget_show(awayqueuesw); 231 gtk_widget_show(clistqueuesw);
249 gtk_widget_show(awayqueue); 232 gtk_widget_show(clistqueue);
250 } 233 }
251 234
252 back = picture_button(imaway, _("I'm Back!"), join_xpm); 235 back = picture_button(imaway, _("I'm Back!"), join_xpm);
253 gtk_box_pack_start(GTK_BOX(vbox), back, FALSE, FALSE, 0); 236 gtk_box_pack_start(GTK_BOX(vbox), back, FALSE, FALSE, 0);
254 g_signal_connect(GTK_OBJECT(back), "clicked", G_CALLBACK(do_im_back), imaway); 237 g_signal_connect(GTK_OBJECT(back), "clicked", G_CALLBACK(do_im_back), imaway);