8113
|
1 /**
|
|
2 * @file gtkroomlist.c Gtk Room List UI
|
|
3 * @ingroup gtkui
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
8146
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
8113
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25
|
|
26 #include "gtkinternal.h"
|
|
27 #include "gtkutils.h"
|
|
28 #include "stock.h"
|
|
29 #include "debug.h"
|
|
30 #include "account.h"
|
|
31 #include "connection.h"
|
|
32 #include "notify.h"
|
|
33
|
|
34 #include "gtkroomlist.h"
|
|
35
|
|
36 typedef struct _GaimGtkRoomlist {
|
|
37 GaimGtkRoomlistDialog *dialog;
|
|
38 GtkTreeStore *model;
|
|
39 GtkWidget *tree;
|
|
40 GHashTable *cats; /**< Meow. */
|
|
41 gint num_rooms, total_rooms;
|
|
42 } GaimGtkRoomlist;
|
|
43
|
|
44 struct _GaimGtkRoomlistDialog {
|
|
45 GtkWidget *window;
|
|
46 GtkWidget *account_widget;
|
|
47 GtkWidget *progress;
|
|
48 GtkWidget *sw;
|
|
49
|
8199
|
50 GtkWidget *stop_button;
|
8113
|
51 GtkWidget *list_button;
|
8199
|
52 GtkWidget *join_button;
|
8113
|
53 GtkWidget *close_button;
|
|
54
|
|
55 GaimAccount *account;
|
|
56 GaimRoomlist *roomlist;
|
|
57 };
|
|
58
|
|
59 enum {
|
|
60 NAME_COLUMN = 0,
|
|
61 ROOM_COLUMN,
|
|
62 NUM_OF_COLUMNS,
|
|
63 };
|
|
64
|
|
65 static GList *roomlists = NULL;
|
|
66
|
|
67 static gint delete_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d)
|
|
68 {
|
|
69 GaimGtkRoomlistDialog *dialog;
|
|
70
|
|
71 dialog = (GaimGtkRoomlistDialog *) d;
|
|
72
|
8199
|
73 if (dialog->roomlist && gaim_roomlist_get_in_progress(dialog->roomlist))
|
|
74 gaim_roomlist_cancel_get_list(dialog->roomlist);
|
|
75
|
8113
|
76 /* free stuff here */
|
|
77 if (dialog->roomlist)
|
|
78 gaim_roomlist_unref(dialog->roomlist);
|
|
79 g_free(dialog);
|
|
80
|
|
81 return FALSE;
|
|
82 }
|
|
83
|
|
84 static void dialog_select_account_cb(GObject *w, GaimAccount *account,
|
|
85 GaimGtkRoomlistDialog *dialog)
|
|
86 {
|
|
87 dialog->account = account;
|
|
88 }
|
|
89
|
|
90 static void list_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog)
|
|
91 {
|
|
92 GaimConnection *gc;
|
|
93 GaimGtkRoomlist *rl;
|
|
94
|
|
95 gc = gaim_account_get_connection(dialog->account);
|
|
96 if (!gc)
|
|
97 return;
|
|
98
|
8199
|
99 if (dialog->roomlist != NULL) {
|
|
100 rl = dialog->roomlist->ui_data;
|
|
101 gtk_widget_destroy(rl->tree);
|
|
102 gaim_roomlist_unref(dialog->roomlist);
|
|
103 }
|
|
104
|
8113
|
105 dialog->roomlist = gaim_roomlist_get_list(gc);
|
|
106 gaim_roomlist_ref(dialog->roomlist);
|
|
107 rl = dialog->roomlist->ui_data;
|
|
108 rl->dialog = dialog;
|
8199
|
109
|
8113
|
110 if (dialog->account_widget)
|
|
111 gtk_widget_set_sensitive(dialog->account_widget, FALSE);
|
8199
|
112
|
|
113 gtk_container_add(GTK_CONTAINER(dialog->sw), rl->tree);
|
|
114
|
|
115 gtk_widget_set_sensitive(dialog->stop_button, TRUE);
|
8113
|
116 gtk_widget_set_sensitive(dialog->list_button, FALSE);
|
8199
|
117 gtk_widget_set_sensitive(dialog->join_button, FALSE);
|
8113
|
118 }
|
|
119
|
|
120 static void stop_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog)
|
|
121 {
|
|
122 gaim_roomlist_cancel_get_list(dialog->roomlist);
|
8199
|
123
|
|
124 if (dialog->account_widget)
|
|
125 gtk_widget_set_sensitive(dialog->account_widget, TRUE);
|
|
126
|
|
127 gtk_widget_set_sensitive(dialog->stop_button, FALSE);
|
|
128 gtk_widget_set_sensitive(dialog->list_button, TRUE);
|
|
129 gtk_widget_set_sensitive(dialog->join_button, FALSE);
|
8113
|
130 }
|
|
131
|
|
132 static void close_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog)
|
|
133 {
|
|
134 GtkWidget *window = dialog->window;
|
|
135
|
|
136 delete_win_cb(NULL, NULL, dialog);
|
|
137 gtk_widget_destroy(window);
|
|
138 }
|
|
139
|
|
140 struct _menu_cb_info {
|
|
141 GaimRoomlist *list;
|
|
142 GaimRoomlistRoom *room;
|
|
143 };
|
|
144
|
8199
|
145 static void
|
|
146 selection_changed_cb(GtkTreeSelection *selection, GaimGtkRoomlist *grl) {
|
|
147 GtkTreeIter iter;
|
|
148 GValue val = { 0, };
|
|
149 GaimRoomlistRoom *room;
|
|
150 static struct _menu_cb_info *info;
|
|
151 GaimGtkRoomlistDialog *dialog;
|
|
152
|
|
153 dialog = grl->dialog;
|
|
154
|
|
155 if (gtk_tree_selection_get_selected(selection, NULL, &iter)) {
|
|
156 gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val);
|
|
157 room = g_value_get_pointer(&val);
|
|
158 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM)) {
|
|
159 gtk_widget_set_sensitive(dialog->join_button, FALSE);
|
|
160 return;
|
|
161 }
|
|
162
|
|
163 info = g_new0(struct _menu_cb_info, 1);
|
|
164 info->list = dialog->roomlist;
|
|
165 info->room = room;
|
|
166
|
|
167 g_object_set_data(G_OBJECT(dialog->join_button), "room-info", info);
|
|
168
|
|
169 gtk_widget_set_sensitive(dialog->join_button, TRUE);
|
|
170 } else {
|
|
171 gtk_widget_set_sensitive(dialog->join_button, FALSE);
|
|
172 }
|
|
173 }
|
|
174
|
8113
|
175 static void do_join_cb(GtkWidget *w, struct _menu_cb_info *info)
|
|
176 {
|
8199
|
177 gaim_roomlist_room_join(info->list, info->room);
|
|
178 }
|
8113
|
179
|
8199
|
180 static void join_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog)
|
|
181 {
|
|
182 GaimRoomlist *rl = dialog->roomlist;
|
|
183 GaimGtkRoomlist *grl = rl->ui_data;
|
|
184 struct _menu_cb_info *info;
|
|
185
|
|
186 info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info");
|
|
187
|
|
188 do_join_cb(grl->tree, info);
|
|
189 g_free(info);
|
8113
|
190 }
|
|
191
|
|
192 static void row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *arg2,
|
|
193 GaimRoomlist *list)
|
|
194 {
|
|
195 GaimGtkRoomlist *grl = list->ui_data;
|
|
196 GtkTreeIter iter;
|
|
197 GaimRoomlistRoom *room;
|
|
198 GValue val = { 0, };
|
|
199 struct _menu_cb_info info;
|
|
200
|
|
201 gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path);
|
|
202 gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val);
|
|
203 room = g_value_get_pointer(&val);
|
|
204 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM))
|
|
205 return;
|
|
206
|
|
207 info.list = list;
|
|
208 info.room = room;
|
|
209
|
|
210 do_join_cb(GTK_WIDGET(tv), &info);
|
|
211 }
|
|
212
|
|
213 static gboolean room_click_cb(GtkWidget *tv, GdkEventButton *event, GaimRoomlist *list)
|
|
214 {
|
|
215 GtkTreePath *path;
|
|
216 GaimGtkRoomlist *grl = list->ui_data;
|
|
217 GValue val = { 0, };
|
|
218 GaimRoomlistRoom *room;
|
|
219 GtkTreeIter iter;
|
|
220 GtkWidget *menu;
|
|
221 static struct _menu_cb_info info; /* XXX? */
|
|
222
|
|
223 if (event->button != 3 || event->type != GDK_BUTTON_PRESS)
|
|
224 return FALSE;
|
|
225
|
|
226 /* Here we figure out which room was clicked */
|
|
227 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL))
|
|
228 return FALSE;
|
|
229 gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path);
|
|
230 gtk_tree_path_free(path);
|
|
231 gtk_tree_model_get_value (GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val);
|
|
232 room = g_value_get_pointer(&val);
|
|
233
|
|
234 if (!room || !(room->type & GAIM_ROOMLIST_ROOMTYPE_ROOM))
|
|
235 return FALSE;
|
|
236
|
|
237 info.list = list;
|
|
238 info.room = room;
|
|
239
|
|
240
|
|
241 menu = gtk_menu_new();
|
|
242 gaim_new_item_from_stock(menu, _("_Join"), GAIM_STOCK_CHAT,
|
|
243 G_CALLBACK(do_join_cb), &info, 0, 0, NULL);
|
|
244
|
|
245
|
|
246 gtk_widget_show_all(menu);
|
|
247 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
|
|
248
|
|
249 return FALSE;
|
|
250 }
|
|
251
|
|
252 static void row_expanded_cb(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer user_data)
|
|
253 {
|
|
254 GaimRoomlist *list = user_data;
|
|
255 GaimRoomlistRoom *catagory;
|
|
256 GValue val = { 0, };
|
|
257
|
|
258 gtk_tree_model_get_value(gtk_tree_view_get_model(treeview), arg1, ROOM_COLUMN, &val);
|
|
259 catagory = g_value_get_pointer(&val);
|
|
260
|
|
261 if (!catagory->expanded_once) {
|
|
262 gaim_roomlist_expand_catagory(list, catagory);
|
|
263 catagory->expanded_once = TRUE;
|
|
264 }
|
|
265 }
|
|
266
|
|
267 static gboolean accounts_filter_func(GaimAccount *account)
|
|
268 {
|
|
269 GaimConnection *gc;
|
|
270
|
|
271 gc = gaim_account_get_connection(account);
|
|
272 if (!gc)
|
|
273 return FALSE;
|
|
274 return gaim_roomlist_is_possible(gc);
|
|
275 }
|
|
276
|
|
277 GaimGtkRoomlistDialog *gaim_gtk_roomlist_dialog_new_with_account(GaimAccount *account)
|
|
278 {
|
|
279 GaimGtkRoomlistDialog *dialog;
|
|
280 GtkWidget *window;
|
8199
|
281 GtkWidget *vbox;
|
|
282 GtkWidget *vbox2;
|
8113
|
283 GtkWidget *account_hbox;
|
|
284 GtkWidget *bbox;
|
|
285 GtkWidget *label;
|
|
286 GaimAccount *first_account = NULL;
|
|
287
|
|
288 if (!account) {
|
|
289 GList *c;
|
|
290 GaimConnection *gc;
|
|
291
|
|
292 for (c = gaim_connections_get_all(); c != NULL; c = c->next) {
|
|
293 gc = c->data;
|
|
294
|
|
295 if (gaim_roomlist_is_possible(gc)) {
|
|
296 first_account = gaim_connection_get_account(gc);
|
|
297 break;
|
|
298 }
|
|
299 }
|
|
300
|
|
301 if (first_account == NULL) {
|
|
302 gaim_notify_error(NULL, NULL,
|
|
303 _("You are not currently signed on with any "
|
|
304 "protocols that have the ability to list rooms."),
|
|
305 NULL);
|
|
306
|
|
307 return NULL;
|
|
308 }
|
|
309 }
|
|
310
|
|
311 dialog = g_new0(GaimGtkRoomlistDialog, 1);
|
|
312
|
|
313 /* Create the window. */
|
|
314 dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
315 gtk_window_set_role(GTK_WINDOW(window), "room list");
|
|
316 gtk_window_set_title(GTK_WINDOW(window), _("Room List"));
|
|
317
|
|
318 gtk_container_set_border_width(GTK_CONTAINER(window), 12);
|
|
319 gtk_widget_realize(window);
|
|
320
|
|
321 g_signal_connect(G_OBJECT(window), "delete_event",
|
|
322 G_CALLBACK(delete_win_cb), dialog);
|
|
323
|
|
324 /* Create the parent vbox for everything. */
|
8199
|
325 vbox = gtk_vbox_new(FALSE, 12);
|
|
326 gtk_container_add(GTK_CONTAINER(window), vbox);
|
|
327 gtk_widget_show(vbox);
|
8113
|
328
|
8199
|
329 vbox2 = gtk_vbox_new(FALSE, 12);
|
|
330 gtk_container_add(GTK_CONTAINER(vbox), vbox2);
|
8113
|
331 gtk_widget_show(vbox2);
|
|
332
|
|
333 /* accounts dropdown list */
|
|
334 if (!account) {
|
8199
|
335 account_hbox = gtk_hbox_new(FALSE, 0);
|
|
336 gtk_box_pack_start(GTK_BOX(vbox2), account_hbox, FALSE, FALSE, 0);
|
|
337 gtk_widget_show(account_hbox);
|
|
338
|
8113
|
339 dialog->account = first_account;
|
|
340 label = gtk_label_new(NULL);
|
|
341 gtk_box_pack_start(GTK_BOX(account_hbox), label, TRUE, TRUE, 0);
|
|
342 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:"));
|
|
343 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
|
8199
|
344 gtk_widget_show(label);
|
8113
|
345
|
|
346 dialog->account_widget = gaim_gtk_account_option_menu_new(first_account, FALSE,
|
|
347 G_CALLBACK(dialog_select_account_cb), accounts_filter_func, dialog);
|
|
348
|
|
349 gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0);
|
|
350 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget));
|
|
351 gtk_widget_show(dialog->account_widget);
|
8199
|
352
|
8113
|
353 } else {
|
|
354 dialog->account = account;
|
|
355 }
|
|
356
|
8199
|
357 /* scrolled window */
|
8113
|
358 dialog->sw = gtk_scrolled_window_new(NULL, NULL);
|
|
359 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->sw),
|
|
360 GTK_SHADOW_IN);
|
|
361 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->sw),
|
|
362 GTK_POLICY_AUTOMATIC,
|
|
363 GTK_POLICY_AUTOMATIC);
|
8199
|
364 gtk_box_pack_start(GTK_BOX(vbox2), dialog->sw, TRUE, TRUE, 0);
|
|
365 gtk_widget_set_size_request(dialog->sw, -1, 250);
|
8113
|
366 gtk_widget_show(dialog->sw);
|
|
367
|
8199
|
368 /* progress bar */
|
|
369 dialog->progress = gtk_progress_bar_new();
|
|
370 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dialog->progress), 0.1);
|
|
371 gtk_box_pack_start(GTK_BOX(vbox2), dialog->progress, FALSE, FALSE, 0);
|
|
372 gtk_widget_show(dialog->progress);
|
|
373
|
|
374
|
|
375 /* button box */
|
|
376 bbox = gtk_hbutton_box_new();
|
|
377 gtk_box_set_spacing(GTK_BOX(bbox), 6);
|
|
378 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
|
379 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
|
|
380 gtk_widget_show(bbox);
|
|
381
|
|
382 /* stop button */
|
|
383 dialog->stop_button = gtk_button_new_from_stock(GTK_STOCK_STOP);
|
|
384 gtk_box_pack_start(GTK_BOX(bbox), dialog->stop_button, FALSE, FALSE, 0);
|
|
385 g_signal_connect(G_OBJECT(dialog->stop_button), "clicked",
|
|
386 G_CALLBACK(stop_button_cb), dialog);
|
|
387 gtk_widget_set_sensitive(dialog->stop_button, FALSE);
|
|
388 gtk_widget_show(dialog->stop_button);
|
|
389
|
|
390 /* list button */
|
|
391 dialog->list_button = gtk_button_new_with_mnemonic(_("_Get List"));
|
|
392 gtk_box_pack_start(GTK_BOX(bbox), dialog->list_button, FALSE, FALSE, 0);
|
|
393 g_signal_connect(G_OBJECT(dialog->list_button), "clicked",
|
|
394 G_CALLBACK(list_button_cb), dialog);
|
|
395 gtk_widget_show(dialog->list_button);
|
|
396
|
|
397 /* join button */
|
|
398 dialog->join_button = gaim_pixbuf_button_from_stock(_("_Join"), GAIM_STOCK_CHAT,
|
|
399 GAIM_BUTTON_HORIZONTAL);
|
|
400 gtk_box_pack_start(GTK_BOX(bbox), dialog->join_button, FALSE, FALSE, 0);
|
|
401 g_signal_connect(G_OBJECT(dialog->join_button), "clicked",
|
|
402 G_CALLBACK(join_button_cb), dialog);
|
|
403 gtk_widget_set_sensitive(dialog->join_button, FALSE);
|
|
404 gtk_widget_show(dialog->join_button);
|
|
405
|
|
406 /* close button */
|
|
407 dialog->close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
|
|
408 gtk_box_pack_start(GTK_BOX(bbox), dialog->close_button, FALSE, FALSE, 0);
|
|
409 g_signal_connect(G_OBJECT(dialog->close_button), "clicked",
|
|
410 G_CALLBACK(close_button_cb), dialog);
|
|
411 gtk_widget_show(dialog->close_button);
|
|
412
|
|
413 /* show the dialog window and return the dialog */
|
|
414 gtk_widget_show(dialog->window);
|
|
415
|
8113
|
416 return dialog;
|
|
417 }
|
|
418
|
|
419 GaimGtkRoomlistDialog *gaim_gtk_roomlist_dialog_new(void)
|
|
420 {
|
|
421 return gaim_gtk_roomlist_dialog_new_with_account(NULL);
|
|
422 }
|
|
423
|
|
424 void gaim_gtk_roomlist_dialog_show(void)
|
|
425 {
|
|
426 gaim_gtk_roomlist_dialog_new();
|
|
427 }
|
|
428
|
|
429 static void gaim_gtk_roomlist_new(GaimRoomlist *list)
|
|
430 {
|
|
431 GaimGtkRoomlist *rl;
|
|
432
|
|
433 rl = g_new0(GaimGtkRoomlist, 1);
|
|
434
|
|
435 list->ui_data = rl;
|
|
436
|
|
437 rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free);
|
|
438
|
|
439 roomlists = g_list_append(roomlists, list);
|
|
440 }
|
|
441
|
|
442 static void int_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
|
|
443 GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
|
|
444 {
|
|
445 gchar buf[16];
|
|
446 int myint;
|
|
447
|
|
448 gtk_tree_model_get(model, iter, GPOINTER_TO_INT(user_data), &myint, -1);
|
|
449
|
|
450 if (myint)
|
|
451 g_snprintf(buf, sizeof(buf), "%d", myint);
|
|
452 else
|
|
453 buf[0] = '\0';
|
|
454
|
|
455 g_object_set(renderer, "text", buf, NULL);
|
|
456 }
|
|
457
|
|
458 /* this sorts backwards on purpose, so that clicking name sorts a-z, while clicking users sorts
|
|
459 infinity-0. you can still click again to reverse it on any of them. */
|
|
460 static gint int_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data)
|
|
461 {
|
|
462 int c, d;
|
|
463
|
|
464 c = d = 0;
|
|
465
|
|
466 gtk_tree_model_get(model, a, GPOINTER_TO_INT(user_data), &c, -1);
|
|
467 gtk_tree_model_get(model, b, GPOINTER_TO_INT(user_data), &d, -1);
|
|
468
|
|
469 if (c == d)
|
|
470 return 0;
|
|
471 else if (c > d)
|
|
472 return -1;
|
|
473 else
|
|
474 return 1;
|
|
475 }
|
|
476
|
|
477 static void gaim_gtk_roomlist_set_fields(GaimRoomlist *list, GList *fields)
|
|
478 {
|
|
479 GaimGtkRoomlist *grl = list->ui_data;
|
|
480 gint columns = NUM_OF_COLUMNS;
|
|
481 int j;
|
|
482 GtkTreeStore *model;
|
|
483 GtkWidget *tree;
|
|
484 GtkCellRenderer *renderer;
|
|
485 GtkTreeViewColumn *column;
|
8199
|
486 GtkTreeSelection *selection;
|
8113
|
487 GList *l;
|
|
488 GType *types;
|
|
489
|
|
490 g_return_if_fail(grl != NULL);
|
|
491
|
|
492 columns += g_list_length(fields);
|
|
493 types = g_new(GType, columns);
|
|
494
|
|
495 types[NAME_COLUMN] = G_TYPE_STRING;
|
|
496 types[ROOM_COLUMN] = G_TYPE_POINTER;
|
|
497
|
|
498 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) {
|
|
499 GaimRoomlistField *f = l->data;
|
|
500
|
|
501 switch (f->type) {
|
|
502 case GAIM_ROOMLIST_FIELD_BOOL:
|
|
503 types[j] = G_TYPE_BOOLEAN;
|
|
504 break;
|
|
505 case GAIM_ROOMLIST_FIELD_INT:
|
|
506 types[j] = G_TYPE_INT;
|
|
507 break;
|
|
508 case GAIM_ROOMLIST_FIELD_STRING:
|
|
509 types[j] = G_TYPE_STRING;
|
|
510 break;
|
|
511 }
|
|
512 }
|
|
513
|
|
514 model = gtk_tree_store_newv(columns, types);
|
|
515 g_free(types);
|
|
516
|
|
517 tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
|
|
518 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
|
|
519
|
8199
|
520 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
|
|
521 g_signal_connect(G_OBJECT(selection), "changed",
|
|
522 G_CALLBACK(selection_changed_cb), grl);
|
|
523
|
8113
|
524 g_object_unref(model);
|
|
525
|
|
526 grl->model = model;
|
|
527 grl->tree = tree;
|
|
528 gtk_widget_show(grl->tree);
|
|
529
|
|
530 renderer = gtk_cell_renderer_text_new();
|
|
531 column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer,
|
|
532 "text", NAME_COLUMN, NULL);
|
|
533 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column),
|
|
534 GTK_TREE_VIEW_COLUMN_GROW_ONLY);
|
|
535 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE);
|
|
536 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), NAME_COLUMN);
|
|
537 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE);
|
|
538 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
|
|
539
|
|
540 for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) {
|
|
541 GaimRoomlistField *f = l->data;
|
|
542
|
|
543 if (f->hidden)
|
|
544 continue;
|
|
545
|
|
546 renderer = gtk_cell_renderer_text_new();
|
|
547 column = gtk_tree_view_column_new_with_attributes(f->label, renderer,
|
|
548 "text", j, NULL);
|
|
549 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column),
|
|
550 GTK_TREE_VIEW_COLUMN_GROW_ONLY);
|
|
551 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE);
|
|
552 gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), j);
|
|
553 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE);
|
|
554 if (f->type == GAIM_ROOMLIST_FIELD_INT) {
|
|
555 gtk_tree_view_column_set_cell_data_func(column, renderer, int_cell_data_func,
|
|
556 GINT_TO_POINTER(j), NULL);
|
|
557 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), j, int_sort_func,
|
|
558 GINT_TO_POINTER(j), NULL);
|
|
559 }
|
|
560 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
|
|
561 }
|
|
562
|
|
563 g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(room_click_cb), list);
|
|
564 g_signal_connect(G_OBJECT(tree), "row-expanded", G_CALLBACK(row_expanded_cb), list);
|
|
565 g_signal_connect(G_OBJECT(tree), "row-activated", G_CALLBACK(row_activated_cb), list);
|
|
566 }
|
|
567
|
|
568 static void gaim_gtk_roomlist_add_room(GaimRoomlist *list, GaimRoomlistRoom *room)
|
|
569 {
|
|
570 GaimGtkRoomlist *rl= list->ui_data;
|
|
571 GtkTreeRowReference *rr, *parentrr = NULL;
|
|
572 GtkTreePath *path;
|
|
573 GtkTreeIter iter, parent, child;
|
|
574 GList *l, *k;
|
|
575 int j;
|
|
576 gboolean append = TRUE;
|
|
577
|
|
578 rl->total_rooms++;
|
|
579 if (room->type == GAIM_ROOMLIST_ROOMTYPE_ROOM)
|
|
580 rl->num_rooms++;
|
|
581
|
|
582 if (rl->dialog) {
|
|
583 if (rl->total_rooms > 100)
|
|
584 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(rl->dialog->progress),
|
|
585 0.01);
|
|
586 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress));
|
|
587 }
|
|
588 if (room->parent) {
|
|
589 parentrr = g_hash_table_lookup(rl->cats, room->parent);
|
|
590 path = gtk_tree_row_reference_get_path(parentrr);
|
|
591 if (path) {
|
|
592 GaimRoomlistRoom *tmproom = NULL;
|
|
593
|
|
594 gtk_tree_model_get_iter(GTK_TREE_MODEL(rl->model), &parent, path);
|
|
595 gtk_tree_path_free(path);
|
|
596
|
|
597 if (gtk_tree_model_iter_children(GTK_TREE_MODEL(rl->model), &child, &parent)) {
|
|
598 gtk_tree_model_get(GTK_TREE_MODEL(rl->model), &child, ROOM_COLUMN, &tmproom, -1);
|
|
599 if (!tmproom)
|
|
600 append = FALSE;
|
|
601 }
|
|
602 }
|
|
603 }
|
|
604
|
|
605 if (append)
|
|
606 gtk_tree_store_append(rl->model, &iter, (parentrr ? &parent : NULL));
|
|
607 else
|
|
608 iter = child;
|
|
609
|
|
610 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATAGORY)
|
|
611 gtk_tree_store_append(rl->model, &child, &iter);
|
|
612
|
|
613 path = gtk_tree_model_get_path(GTK_TREE_MODEL(rl->model), &iter);
|
|
614
|
|
615 if (room->type & GAIM_ROOMLIST_ROOMTYPE_CATAGORY) {
|
|
616 rr = gtk_tree_row_reference_new(GTK_TREE_MODEL(rl->model), path);
|
|
617 g_hash_table_insert(rl->cats, room, rr);
|
|
618 }
|
|
619
|
|
620 gtk_tree_path_free(path);
|
|
621
|
|
622 gtk_tree_store_set(rl->model, &iter, NAME_COLUMN, room->name, -1);
|
|
623 gtk_tree_store_set(rl->model, &iter, ROOM_COLUMN, room, -1);
|
|
624
|
|
625 for (j = NUM_OF_COLUMNS, l = room->fields, k = list->fields; l && k; j++, l = l->next, k = k->next) {
|
|
626 GaimRoomlistField *f = k->data;
|
|
627 if (f->hidden)
|
|
628 continue;
|
|
629 gtk_tree_store_set(rl->model, &iter, j, l->data, -1);
|
|
630 }
|
|
631 }
|
|
632
|
|
633 static void gaim_gtk_roomlist_in_progress(GaimRoomlist *list, gboolean flag)
|
|
634 {
|
|
635 GaimGtkRoomlist *rl = list->ui_data;
|
|
636
|
|
637 if (!rl || !rl->dialog)
|
|
638 return;
|
|
639
|
|
640 if (flag) {
|
8199
|
641 if (rl->dialog->account_widget)
|
|
642 gtk_widget_set_sensitive(rl->dialog->account_widget, FALSE);
|
|
643 gtk_widget_set_sensitive(rl->dialog->stop_button, TRUE);
|
|
644 gtk_widget_set_sensitive(rl->dialog->list_button, FALSE);
|
8113
|
645 } else {
|
|
646 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(rl->dialog->progress), 0.0);
|
8199
|
647 if (rl->dialog->account_widget)
|
|
648 gtk_widget_set_sensitive(rl->dialog->account_widget, TRUE);
|
|
649 gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE);
|
|
650 gtk_widget_set_sensitive(rl->dialog->list_button, TRUE);
|
8113
|
651 }
|
|
652 }
|
|
653
|
|
654 static void gaim_gtk_roomlist_destroy(GaimRoomlist *list)
|
|
655 {
|
|
656 GaimGtkRoomlist *rl;
|
|
657
|
|
658 roomlists = g_list_remove(roomlists, list);
|
|
659
|
|
660 rl = list->ui_data;
|
|
661
|
|
662 g_return_if_fail(rl != NULL);
|
|
663
|
|
664 g_hash_table_destroy(rl->cats);
|
|
665 g_free(rl);
|
|
666 list->ui_data = NULL;
|
|
667 }
|
|
668
|
|
669 static GaimRoomlistUiOps ops = {
|
|
670 gaim_gtk_roomlist_new,
|
|
671 gaim_gtk_roomlist_set_fields,
|
|
672 gaim_gtk_roomlist_add_room,
|
|
673 gaim_gtk_roomlist_in_progress,
|
|
674 gaim_gtk_roomlist_destroy
|
|
675 };
|
|
676
|
|
677
|
|
678 void gaim_gtk_roomlist_init(void)
|
|
679 {
|
|
680 gaim_roomlist_set_ui_ops(&ops);
|
|
681 }
|