comparison pidgin/gtkroomlist.c @ 15500:d75099d2567e

gaim_gtk to pidgin. I hope
author Sean Egan <seanegan@gmail.com>
date Sat, 03 Feb 2007 07:23:11 +0000
parents 5fe8042783c1
children 311315e979f7
comparison
equal deleted inserted replaced
15499:45ecefd0ce3a 15500:d75099d2567e
32 #include "connection.h" 32 #include "connection.h"
33 #include "notify.h" 33 #include "notify.h"
34 34
35 #include "gtkroomlist.h" 35 #include "gtkroomlist.h"
36 36
37 typedef struct _GaimGtkRoomlistDialog { 37 typedef struct _PidginRoomlistDialog {
38 GtkWidget *window; 38 GtkWidget *window;
39 GtkWidget *account_widget; 39 GtkWidget *account_widget;
40 GtkWidget *progress; 40 GtkWidget *progress;
41 GtkWidget *sw; 41 GtkWidget *sw;
42 42
50 GaimRoomlist *roomlist; 50 GaimRoomlist *roomlist;
51 51
52 gboolean pg_needs_pulse; 52 gboolean pg_needs_pulse;
53 gboolean pg_to_active; 53 gboolean pg_to_active;
54 guint pg_update_to; 54 guint pg_update_to;
55 } GaimGtkRoomlistDialog; 55 } PidginRoomlistDialog;
56 56
57 typedef struct _GaimGtkRoomlist { 57 typedef struct _PidginRoomlist {
58 GaimGtkRoomlistDialog *dialog; 58 PidginRoomlistDialog *dialog;
59 GtkTreeStore *model; 59 GtkTreeStore *model;
60 GtkWidget *tree; 60 GtkWidget *tree;
61 GHashTable *cats; /**< Meow. */ 61 GHashTable *cats; /**< Meow. */
62 gint num_rooms, total_rooms; 62 gint num_rooms, total_rooms;
63 } GaimGtkRoomlist; 63 } PidginRoomlist;
64 64
65 enum { 65 enum {
66 NAME_COLUMN = 0, 66 NAME_COLUMN = 0,
67 ROOM_COLUMN, 67 ROOM_COLUMN,
68 NUM_OF_COLUMNS, 68 NUM_OF_COLUMNS,
70 70
71 static GList *roomlists = NULL; 71 static GList *roomlists = NULL;
72 72
73 static gint delete_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) 73 static gint delete_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d)
74 { 74 {
75 GaimGtkRoomlistDialog *dialog; 75 PidginRoomlistDialog *dialog;
76 76
77 dialog = (GaimGtkRoomlistDialog *) d; 77 dialog = (PidginRoomlistDialog *) d;
78 78
79 if (dialog->roomlist && gaim_roomlist_get_in_progress(dialog->roomlist)) 79 if (dialog->roomlist && gaim_roomlist_get_in_progress(dialog->roomlist))
80 gaim_roomlist_cancel_get_list(dialog->roomlist); 80 gaim_roomlist_cancel_get_list(dialog->roomlist);
81 81
82 if (dialog->roomlist) { 82 if (dialog->roomlist) {
95 95
96 return FALSE; 96 return FALSE;
97 } 97 }
98 98
99 static void dialog_select_account_cb(GObject *w, GaimAccount *account, 99 static void dialog_select_account_cb(GObject *w, GaimAccount *account,
100 GaimGtkRoomlistDialog *dialog) 100 PidginRoomlistDialog *dialog)
101 { 101 {
102 dialog->account = account; 102 dialog->account = account;
103 } 103 }
104 104
105 static void list_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) 105 static void list_button_cb(GtkButton *button, PidginRoomlistDialog *dialog)
106 { 106 {
107 GaimConnection *gc; 107 GaimConnection *gc;
108 GaimGtkRoomlist *rl; 108 PidginRoomlist *rl;
109 109
110 gc = gaim_account_get_connection(dialog->account); 110 gc = gaim_account_get_connection(dialog->account);
111 if (!gc) 111 if (!gc)
112 return; 112 return;
113 113
140 } 140 }
141 gtk_widget_set_sensitive(dialog->add_button, FALSE); 141 gtk_widget_set_sensitive(dialog->add_button, FALSE);
142 gtk_widget_set_sensitive(dialog->join_button, FALSE); 142 gtk_widget_set_sensitive(dialog->join_button, FALSE);
143 } 143 }
144 144
145 static void stop_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) 145 static void stop_button_cb(GtkButton *button, PidginRoomlistDialog *dialog)
146 { 146 {
147 gaim_roomlist_cancel_get_list(dialog->roomlist); 147 gaim_roomlist_cancel_get_list(dialog->roomlist);
148 148
149 if (dialog->account_widget) 149 if (dialog->account_widget)
150 gtk_widget_set_sensitive(dialog->account_widget, TRUE); 150 gtk_widget_set_sensitive(dialog->account_widget, TRUE);
153 gtk_widget_set_sensitive(dialog->list_button, TRUE); 153 gtk_widget_set_sensitive(dialog->list_button, TRUE);
154 gtk_widget_set_sensitive(dialog->add_button, FALSE); 154 gtk_widget_set_sensitive(dialog->add_button, FALSE);
155 gtk_widget_set_sensitive(dialog->join_button, FALSE); 155 gtk_widget_set_sensitive(dialog->join_button, FALSE);
156 } 156 }
157 157
158 static void close_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) 158 static void close_button_cb(GtkButton *button, PidginRoomlistDialog *dialog)
159 { 159 {
160 GtkWidget *window = dialog->window; 160 GtkWidget *window = dialog->window;
161 161
162 delete_win_cb(NULL, NULL, dialog); 162 delete_win_cb(NULL, NULL, dialog);
163 gtk_widget_destroy(window); 163 gtk_widget_destroy(window);
167 GaimRoomlist *list; 167 GaimRoomlist *list;
168 GaimRoomlistRoom *room; 168 GaimRoomlistRoom *room;
169 }; 169 };
170 170
171 static void 171 static void
172 selection_changed_cb(GtkTreeSelection *selection, GaimGtkRoomlist *grl) { 172 selection_changed_cb(GtkTreeSelection *selection, PidginRoomlist *grl) {
173 GtkTreeIter iter; 173 GtkTreeIter iter;
174 GValue val; 174 GValue val;
175 GaimRoomlistRoom *room; 175 GaimRoomlistRoom *room;
176 static struct _menu_cb_info *info; 176 static struct _menu_cb_info *info;
177 GaimGtkRoomlistDialog *dialog; 177 PidginRoomlistDialog *dialog;
178 178
179 dialog = grl->dialog; 179 dialog = grl->dialog;
180 180
181 if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { 181 if (gtk_tree_selection_get_selected(selection, NULL, &iter)) {
182 val.g_type = 0; 182 val.g_type = 0;
221 gaim_blist_request_add_chat(info->list->account, NULL, NULL, name); 221 gaim_blist_request_add_chat(info->list->account, NULL, NULL, name);
222 222
223 g_free(name); 223 g_free(name);
224 } 224 }
225 225
226 static void add_room_to_blist_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) 226 static void add_room_to_blist_cb(GtkButton *button, PidginRoomlistDialog *dialog)
227 { 227 {
228 GaimRoomlist *rl = dialog->roomlist; 228 GaimRoomlist *rl = dialog->roomlist;
229 GaimGtkRoomlist *grl = rl->ui_data; 229 PidginRoomlist *grl = rl->ui_data;
230 struct _menu_cb_info *info; 230 struct _menu_cb_info *info;
231 231
232 info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); 232 info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info");
233 233
234 if(info != NULL) 234 if(info != NULL)
238 static void do_join_cb(GtkWidget *w, struct _menu_cb_info *info) 238 static void do_join_cb(GtkWidget *w, struct _menu_cb_info *info)
239 { 239 {
240 gaim_roomlist_room_join(info->list, info->room); 240 gaim_roomlist_room_join(info->list, info->room);
241 } 241 }
242 242
243 static void join_button_cb(GtkButton *button, GaimGtkRoomlistDialog *dialog) 243 static void join_button_cb(GtkButton *button, PidginRoomlistDialog *dialog)
244 { 244 {
245 GaimRoomlist *rl = dialog->roomlist; 245 GaimRoomlist *rl = dialog->roomlist;
246 GaimGtkRoomlist *grl = rl->ui_data; 246 PidginRoomlist *grl = rl->ui_data;
247 struct _menu_cb_info *info; 247 struct _menu_cb_info *info;
248 248
249 info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); 249 info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info");
250 250
251 if(info != NULL) 251 if(info != NULL)
253 } 253 }
254 254
255 static void row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *arg2, 255 static void row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *arg2,
256 GaimRoomlist *list) 256 GaimRoomlist *list)
257 { 257 {
258 GaimGtkRoomlist *grl = list->ui_data; 258 PidginRoomlist *grl = list->ui_data;
259 GtkTreeIter iter; 259 GtkTreeIter iter;
260 GaimRoomlistRoom *room; 260 GaimRoomlistRoom *room;
261 GValue val; 261 GValue val;
262 struct _menu_cb_info info; 262 struct _menu_cb_info info;
263 263
275 } 275 }
276 276
277 static gboolean room_click_cb(GtkWidget *tv, GdkEventButton *event, GaimRoomlist *list) 277 static gboolean room_click_cb(GtkWidget *tv, GdkEventButton *event, GaimRoomlist *list)
278 { 278 {
279 GtkTreePath *path; 279 GtkTreePath *path;
280 GaimGtkRoomlist *grl = list->ui_data; 280 PidginRoomlist *grl = list->ui_data;
281 GValue val; 281 GValue val;
282 GaimRoomlistRoom *room; 282 GaimRoomlistRoom *room;
283 GtkTreeIter iter; 283 GtkTreeIter iter;
284 GtkWidget *menu; 284 GtkWidget *menu;
285 static struct _menu_cb_info info; /* XXX? */ 285 static struct _menu_cb_info info; /* XXX? */
339 339
340 return (prpl_info->roomlist_get_list != NULL); 340 return (prpl_info->roomlist_get_list != NULL);
341 } 341 }
342 342
343 gboolean 343 gboolean
344 gaim_gtk_roomlist_is_showable() 344 pidgin_roomlist_is_showable()
345 { 345 {
346 GList *c; 346 GList *c;
347 GaimConnection *gc; 347 GaimConnection *gc;
348 348
349 for (c = gaim_connections_get_all(); c != NULL; c = c->next) { 349 for (c = gaim_connections_get_all(); c != NULL; c = c->next) {
354 } 354 }
355 355
356 return FALSE; 356 return FALSE;
357 } 357 }
358 358
359 static GaimGtkRoomlistDialog * 359 static PidginRoomlistDialog *
360 gaim_gtk_roomlist_dialog_new_with_account(GaimAccount *account) 360 pidgin_roomlist_dialog_new_with_account(GaimAccount *account)
361 { 361 {
362 GaimGtkRoomlistDialog *dialog; 362 PidginRoomlistDialog *dialog;
363 GtkWidget *window; 363 GtkWidget *window;
364 GtkWidget *vbox; 364 GtkWidget *vbox;
365 GtkWidget *vbox2; 365 GtkWidget *vbox2;
366 GtkWidget *account_hbox; 366 GtkWidget *account_hbox;
367 GtkWidget *bbox; 367 GtkWidget *bbox;
368 GtkWidget *label; 368 GtkWidget *label;
369 369
370 dialog = g_new0(GaimGtkRoomlistDialog, 1); 370 dialog = g_new0(PidginRoomlistDialog, 1);
371 dialog->account = account; 371 dialog->account = account;
372 372
373 /* Create the window. */ 373 /* Create the window. */
374 dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 374 dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
375 gtk_window_set_role(GTK_WINDOW(window), "room list"); 375 gtk_window_set_role(GTK_WINDOW(window), "room list");
398 gtk_box_pack_start(GTK_BOX(account_hbox), label, FALSE, FALSE, 0); 398 gtk_box_pack_start(GTK_BOX(account_hbox), label, FALSE, FALSE, 0);
399 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); 399 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:"));
400 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); 400 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
401 gtk_widget_show(label); 401 gtk_widget_show(label);
402 402
403 dialog->account_widget = gaim_gtk_account_option_menu_new(dialog->account, FALSE, 403 dialog->account_widget = pidgin_account_option_menu_new(dialog->account, FALSE,
404 G_CALLBACK(dialog_select_account_cb), account_filter_func, dialog); 404 G_CALLBACK(dialog_select_account_cb), account_filter_func, dialog);
405 405
406 if (!dialog->account) /* this is normally null, and we normally don't care what the first selected item is */ 406 if (!dialog->account) /* this is normally null, and we normally don't care what the first selected item is */
407 dialog->account = gaim_gtk_account_option_menu_get_selected(dialog->account_widget); 407 dialog->account = pidgin_account_option_menu_get_selected(dialog->account_widget);
408 408
409 gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0); 409 gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0);
410 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget)); 410 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget));
411 gtk_widget_show(dialog->account_widget); 411 gtk_widget_show(dialog->account_widget);
412 412
479 gtk_widget_show(dialog->window); 479 gtk_widget_show(dialog->window);
480 480
481 return dialog; 481 return dialog;
482 } 482 }
483 483
484 void gaim_gtk_roomlist_dialog_show_with_account(GaimAccount *account) 484 void pidgin_roomlist_dialog_show_with_account(GaimAccount *account)
485 { 485 {
486 GaimGtkRoomlistDialog *dialog; 486 PidginRoomlistDialog *dialog;
487 487
488 dialog = gaim_gtk_roomlist_dialog_new_with_account(account); 488 dialog = pidgin_roomlist_dialog_new_with_account(account);
489 if (!dialog) 489 if (!dialog)
490 return; 490 return;
491 491
492 list_button_cb(GTK_BUTTON(dialog->list_button), dialog); 492 list_button_cb(GTK_BUTTON(dialog->list_button), dialog);
493 } 493 }
494 494
495 void gaim_gtk_roomlist_dialog_show(void) 495 void pidgin_roomlist_dialog_show(void)
496 { 496 {
497 gaim_gtk_roomlist_dialog_new_with_account(NULL); 497 pidgin_roomlist_dialog_new_with_account(NULL);
498 } 498 }
499 499
500 static void gaim_gtk_roomlist_new(GaimRoomlist *list) 500 static void pidgin_roomlist_new(GaimRoomlist *list)
501 { 501 {
502 GaimGtkRoomlist *rl; 502 PidginRoomlist *rl;
503 503
504 rl = g_new0(GaimGtkRoomlist, 1); 504 rl = g_new0(PidginRoomlist, 1);
505 505
506 list->ui_data = rl; 506 list->ui_data = rl;
507 507
508 rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free); 508 rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free);
509 509
562 g_free(name); 562 g_free(name);
563 563
564 return result; 564 return result;
565 } 565 }
566 566
567 static void gaim_gtk_roomlist_set_fields(GaimRoomlist *list, GList *fields) 567 static void pidgin_roomlist_set_fields(GaimRoomlist *list, GList *fields)
568 { 568 {
569 GaimGtkRoomlist *grl = list->ui_data; 569 PidginRoomlist *grl = list->ui_data;
570 gint columns = NUM_OF_COLUMNS; 570 gint columns = NUM_OF_COLUMNS;
571 int j; 571 int j;
572 GtkTreeStore *model; 572 GtkTreeStore *model;
573 GtkWidget *tree; 573 GtkWidget *tree;
574 GtkCellRenderer *renderer; 574 GtkCellRenderer *renderer;
658 gtk_tree_view_set_search_column(GTK_TREE_VIEW(tree), NAME_COLUMN); 658 gtk_tree_view_set_search_column(GTK_TREE_VIEW(tree), NAME_COLUMN);
659 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree), _search_func, NULL, NULL); 659 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree), _search_func, NULL, NULL);
660 660
661 } 661 }
662 662
663 static gboolean gaim_gtk_progress_bar_pulse(gpointer data) 663 static gboolean pidgin_progress_bar_pulse(gpointer data)
664 { 664 {
665 GaimRoomlist *list = data; 665 GaimRoomlist *list = data;
666 GaimGtkRoomlist *rl = list->ui_data; 666 PidginRoomlist *rl = list->ui_data;
667 667
668 if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) { 668 if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) {
669 if (rl && rl->dialog) 669 if (rl && rl->dialog)
670 rl->dialog->pg_to_active = FALSE; 670 rl->dialog->pg_to_active = FALSE;
671 gaim_roomlist_unref(list); 671 gaim_roomlist_unref(list);
675 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); 675 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress));
676 rl->dialog->pg_needs_pulse = FALSE; 676 rl->dialog->pg_needs_pulse = FALSE;
677 return TRUE; 677 return TRUE;
678 } 678 }
679 679
680 static void gaim_gtk_roomlist_add_room(GaimRoomlist *list, GaimRoomlistRoom *room) 680 static void pidgin_roomlist_add_room(GaimRoomlist *list, GaimRoomlistRoom *room)
681 { 681 {
682 GaimGtkRoomlist *rl = list->ui_data; 682 PidginRoomlist *rl = list->ui_data;
683 GtkTreeRowReference *rr, *parentrr = NULL; 683 GtkTreeRowReference *rr, *parentrr = NULL;
684 GtkTreePath *path; 684 GtkTreePath *path;
685 GtkTreeIter iter, parent, child; 685 GtkTreeIter iter, parent, child;
686 GList *l, *k; 686 GList *l, *k;
687 int j; 687 int j;
693 693
694 if (rl->dialog) { 694 if (rl->dialog) {
695 if (!rl->dialog->pg_to_active) { 695 if (!rl->dialog->pg_to_active) {
696 rl->dialog->pg_to_active = TRUE; 696 rl->dialog->pg_to_active = TRUE;
697 gaim_roomlist_ref(list); 697 gaim_roomlist_ref(list);
698 rl->dialog->pg_update_to = g_timeout_add(100, gaim_gtk_progress_bar_pulse, list); 698 rl->dialog->pg_update_to = g_timeout_add(100, pidgin_progress_bar_pulse, list);
699 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); 699 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress));
700 } else { 700 } else {
701 rl->dialog->pg_needs_pulse = TRUE; 701 rl->dialog->pg_needs_pulse = TRUE;
702 } 702 }
703 } 703 }
744 continue; 744 continue;
745 gtk_tree_store_set(rl->model, &iter, j, l->data, -1); 745 gtk_tree_store_set(rl->model, &iter, j, l->data, -1);
746 } 746 }
747 } 747 }
748 748
749 static void gaim_gtk_roomlist_in_progress(GaimRoomlist *list, gboolean flag) 749 static void pidgin_roomlist_in_progress(GaimRoomlist *list, gboolean flag)
750 { 750 {
751 GaimGtkRoomlist *rl = list->ui_data; 751 PidginRoomlist *rl = list->ui_data;
752 752
753 if (!rl || !rl->dialog) 753 if (!rl || !rl->dialog)
754 return; 754 return;
755 755
756 if (flag) { 756 if (flag) {
766 gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE); 766 gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE);
767 gtk_widget_set_sensitive(rl->dialog->list_button, TRUE); 767 gtk_widget_set_sensitive(rl->dialog->list_button, TRUE);
768 } 768 }
769 } 769 }
770 770
771 static void gaim_gtk_roomlist_destroy(GaimRoomlist *list) 771 static void pidgin_roomlist_destroy(GaimRoomlist *list)
772 { 772 {
773 GaimGtkRoomlist *rl; 773 PidginRoomlist *rl;
774 774
775 roomlists = g_list_remove(roomlists, list); 775 roomlists = g_list_remove(roomlists, list);
776 776
777 rl = list->ui_data; 777 rl = list->ui_data;
778 778
782 g_free(rl); 782 g_free(rl);
783 list->ui_data = NULL; 783 list->ui_data = NULL;
784 } 784 }
785 785
786 static GaimRoomlistUiOps ops = { 786 static GaimRoomlistUiOps ops = {
787 gaim_gtk_roomlist_dialog_show_with_account, 787 pidgin_roomlist_dialog_show_with_account,
788 gaim_gtk_roomlist_new, 788 pidgin_roomlist_new,
789 gaim_gtk_roomlist_set_fields, 789 pidgin_roomlist_set_fields,
790 gaim_gtk_roomlist_add_room, 790 pidgin_roomlist_add_room,
791 gaim_gtk_roomlist_in_progress, 791 pidgin_roomlist_in_progress,
792 gaim_gtk_roomlist_destroy 792 pidgin_roomlist_destroy
793 }; 793 };
794 794
795 795
796 void gaim_gtk_roomlist_init(void) 796 void pidgin_roomlist_init(void)
797 { 797 {
798 gaim_roomlist_set_ui_ops(&ops); 798 gaim_roomlist_set_ui_ops(&ops);
799 } 799 }