Thu, 20 Sep 2007 17:30:59 +0000
purple_connection_error_reason-ify myspace
| 8113 | 1 | /** |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
2 | * @file gtkroomlist.c GTK+ Room List UI |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15931
diff
changeset
|
3 | * @ingroup pidgin |
|
20330
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* pidgin |
| 8113 | 7 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
8 | * Pidgin is the legal property of its developers, whose names are too numerous |
|
8146
4961c9c5fd61
[gaim-migrate @ 8854]
John Silvestri <john.silvestri@gmail.com>
parents:
8143
diff
changeset
|
9 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
4961c9c5fd61
[gaim-migrate @ 8854]
John Silvestri <john.silvestri@gmail.com>
parents:
8143
diff
changeset
|
10 | * source distribution. |
| 8113 | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2 of the License, or | |
| 15 | * (at your option) any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18122
diff
changeset
|
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8113 | 25 | */ |
| 26 | ||
| 9791 | 27 | #include "internal.h" |
| 15577 | 28 | #include "pidgin.h" |
| 8113 | 29 | #include "gtkutils.h" |
|
15883
969b74a3e27a
According to etags, pidgin/ should be completely clean of references to 'gaim' as a client
Sean Egan <seanegan@pidgin.im>
parents:
15882
diff
changeset
|
30 | #include "pidginstock.h" |
| 8113 | 31 | #include "debug.h" |
| 32 | #include "account.h" | |
| 33 | #include "connection.h" | |
| 34 | #include "notify.h" | |
| 35 | ||
| 36 | #include "gtkroomlist.h" | |
| 37 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
38 | typedef struct _PidginRoomlistDialog { |
| 8113 | 39 | GtkWidget *window; |
| 40 | GtkWidget *account_widget; | |
| 41 | GtkWidget *progress; | |
| 42 | GtkWidget *sw; | |
| 43 | ||
| 8199 | 44 | GtkWidget *stop_button; |
| 8113 | 45 | GtkWidget *list_button; |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
46 | GtkWidget *add_button; |
| 8199 | 47 | GtkWidget *join_button; |
| 8113 | 48 | GtkWidget *close_button; |
| 49 | ||
| 15884 | 50 | PurpleAccount *account; |
| 51 | PurpleRoomlist *roomlist; | |
| 8230 | 52 | |
| 53 | gboolean pg_needs_pulse; | |
| 54 | gboolean pg_to_active; | |
| 55 | guint pg_update_to; | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
56 | } PidginRoomlistDialog; |
| 14649 | 57 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
58 | typedef struct _PidginRoomlist { |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
59 | PidginRoomlistDialog *dialog; |
| 14649 | 60 | GtkTreeStore *model; |
| 61 | GtkWidget *tree; | |
| 62 | GHashTable *cats; /**< Meow. */ | |
| 63 | gint num_rooms, total_rooms; | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
64 | } PidginRoomlist; |
| 8113 | 65 | |
| 66 | enum { | |
| 67 | NAME_COLUMN = 0, | |
| 68 | ROOM_COLUMN, | |
| 69 | NUM_OF_COLUMNS, | |
| 70 | }; | |
| 71 | ||
| 72 | static GList *roomlists = NULL; | |
| 73 | ||
| 74 | static gint delete_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) | |
| 75 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
76 | PidginRoomlistDialog *dialog; |
| 8113 | 77 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
78 | dialog = (PidginRoomlistDialog *) d; |
| 8113 | 79 | |
| 15884 | 80 | if (dialog->roomlist && purple_roomlist_get_in_progress(dialog->roomlist)) |
| 81 | purple_roomlist_cancel_get_list(dialog->roomlist); | |
| 8199 | 82 | |
| 8230 | 83 | if (dialog->roomlist) { |
| 84 | if (dialog->pg_to_active) { | |
| 15884 | 85 | purple_timeout_remove(dialog->pg_update_to); |
| 8230 | 86 | dialog->pg_to_active = FALSE; |
| 87 | /* yes, that's right, unref it twice. */ | |
| 15884 | 88 | purple_roomlist_unref(dialog->roomlist); |
| 8230 | 89 | } |
| 90 | } | |
| 91 | ||
| 8113 | 92 | /* free stuff here */ |
| 93 | if (dialog->roomlist) | |
| 15884 | 94 | purple_roomlist_unref(dialog->roomlist); |
| 8113 | 95 | g_free(dialog); |
| 96 | ||
| 97 | return FALSE; | |
| 98 | } | |
| 99 | ||
| 15884 | 100 | static void dialog_select_account_cb(GObject *w, PurpleAccount *account, |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
101 | PidginRoomlistDialog *dialog) |
| 8113 | 102 | { |
| 103 | dialog->account = account; | |
| 104 | } | |
| 105 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
106 | static void list_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8113 | 107 | { |
| 15884 | 108 | PurpleConnection *gc; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
109 | PidginRoomlist *rl; |
| 8113 | 110 | |
| 15884 | 111 | gc = purple_account_get_connection(dialog->account); |
| 8113 | 112 | if (!gc) |
| 113 | return; | |
| 114 | ||
| 8199 | 115 | if (dialog->roomlist != NULL) { |
| 116 | rl = dialog->roomlist->ui_data; | |
| 117 | gtk_widget_destroy(rl->tree); | |
| 15884 | 118 | purple_roomlist_unref(dialog->roomlist); |
| 8199 | 119 | } |
| 120 | ||
| 15884 | 121 | dialog->roomlist = purple_roomlist_get_list(gc); |
| 9159 | 122 | if (!dialog->roomlist) |
| 123 | return; | |
| 15884 | 124 | purple_roomlist_ref(dialog->roomlist); |
| 8113 | 125 | rl = dialog->roomlist->ui_data; |
| 126 | rl->dialog = dialog; | |
| 8199 | 127 | |
| 8113 | 128 | if (dialog->account_widget) |
| 129 | gtk_widget_set_sensitive(dialog->account_widget, FALSE); | |
| 8199 | 130 | |
| 131 | gtk_container_add(GTK_CONTAINER(dialog->sw), rl->tree); | |
| 132 | ||
| 15884 | 133 | /* some protocols (not bundled with libpurple) finish getting their |
| 15350 | 134 | * room list immediately */ |
| 15884 | 135 | if(purple_roomlist_get_in_progress(dialog->roomlist)) { |
| 15350 | 136 | gtk_widget_set_sensitive(dialog->stop_button, TRUE); |
| 137 | gtk_widget_set_sensitive(dialog->list_button, FALSE); | |
| 138 | } else { | |
| 139 | gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
| 140 | gtk_widget_set_sensitive(dialog->list_button, TRUE); | |
| 141 | } | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
142 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 143 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
| 8113 | 144 | } |
| 145 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
146 | static void stop_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8113 | 147 | { |
| 15884 | 148 | purple_roomlist_cancel_get_list(dialog->roomlist); |
| 8199 | 149 | |
| 150 | if (dialog->account_widget) | |
| 151 | gtk_widget_set_sensitive(dialog->account_widget, TRUE); | |
| 152 | ||
| 153 | gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
| 154 | gtk_widget_set_sensitive(dialog->list_button, TRUE); | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
155 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 156 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
| 8113 | 157 | } |
| 158 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
159 | static void close_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8113 | 160 | { |
| 161 | GtkWidget *window = dialog->window; | |
| 162 | ||
| 163 | delete_win_cb(NULL, NULL, dialog); | |
| 164 | gtk_widget_destroy(window); | |
| 165 | } | |
| 166 | ||
| 167 | struct _menu_cb_info { | |
| 15884 | 168 | PurpleRoomlist *list; |
| 169 | PurpleRoomlistRoom *room; | |
| 8113 | 170 | }; |
| 171 | ||
| 8199 | 172 | static void |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
173 | selection_changed_cb(GtkTreeSelection *selection, PidginRoomlist *grl) { |
| 8199 | 174 | GtkTreeIter iter; |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
175 | GValue val; |
| 15884 | 176 | PurpleRoomlistRoom *room; |
| 8199 | 177 | static struct _menu_cb_info *info; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
178 | PidginRoomlistDialog *dialog; |
| 8199 | 179 | |
| 180 | dialog = grl->dialog; | |
| 181 | ||
| 182 | if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
183 | val.g_type = 0; |
| 8199 | 184 | gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); |
| 185 | room = g_value_get_pointer(&val); | |
| 15884 | 186 | if (!room || !(room->type & PURPLE_ROOMLIST_ROOMTYPE_ROOM)) { |
| 8199 | 187 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
188 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 189 | return; |
| 190 | } | |
| 191 | ||
| 192 | info = g_new0(struct _menu_cb_info, 1); | |
| 193 | info->list = dialog->roomlist; | |
| 194 | info->room = room; | |
| 195 | ||
| 8377 | 196 | g_object_set_data_full(G_OBJECT(dialog->join_button), "room-info", |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
197 | info, g_free); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
198 | g_object_set_data(G_OBJECT(dialog->add_button), "room-info", info); |
| 8199 | 199 | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
200 | gtk_widget_set_sensitive(dialog->add_button, TRUE); |
| 8199 | 201 | gtk_widget_set_sensitive(dialog->join_button, TRUE); |
| 202 | } else { | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
203 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
| 8199 | 204 | gtk_widget_set_sensitive(dialog->join_button, FALSE); |
| 205 | } | |
| 206 | } | |
| 207 | ||
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
208 | static void do_add_room_cb(GtkWidget *w, struct _menu_cb_info *info) |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
209 | { |
| 15185 | 210 | char *name; |
| 15884 | 211 | PurpleConnection *gc = purple_account_get_connection(info->list->account); |
| 212 | PurplePluginProtocolInfo *prpl_info = NULL; | |
| 15185 | 213 | |
| 214 | if(gc != NULL) | |
| 15884 | 215 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| 15185 | 216 | |
| 217 | if(prpl_info != NULL && prpl_info->roomlist_room_serialize) | |
| 218 | name = prpl_info->roomlist_room_serialize(info->room); | |
| 219 | else | |
| 220 | name = g_strdup(info->room->name); | |
| 221 | ||
| 15884 | 222 | purple_blist_request_add_chat(info->list->account, NULL, NULL, name); |
| 15185 | 223 | |
| 224 | g_free(name); | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
225 | } |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
226 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
227 | static void add_room_to_blist_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
228 | { |
| 15884 | 229 | PurpleRoomlist *rl = dialog->roomlist; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
230 | PidginRoomlist *grl = rl->ui_data; |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
231 | struct _menu_cb_info *info; |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
232 | |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
233 | info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
234 | |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
235 | if(info != NULL) |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
236 | do_add_room_cb(grl->tree, info); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
237 | } |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
238 | |
| 8113 | 239 | static void do_join_cb(GtkWidget *w, struct _menu_cb_info *info) |
| 240 | { | |
| 15884 | 241 | purple_roomlist_room_join(info->list, info->room); |
| 8199 | 242 | } |
| 8113 | 243 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
244 | static void join_button_cb(GtkButton *button, PidginRoomlistDialog *dialog) |
| 8199 | 245 | { |
| 15884 | 246 | PurpleRoomlist *rl = dialog->roomlist; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
247 | PidginRoomlist *grl = rl->ui_data; |
| 8199 | 248 | struct _menu_cb_info *info; |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
249 | |
| 8199 | 250 | info = (struct _menu_cb_info*)g_object_get_data(G_OBJECT(button), "room-info"); |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
251 | |
| 8377 | 252 | if(info != NULL) |
| 253 | do_join_cb(grl->tree, info); | |
| 8113 | 254 | } |
| 255 | ||
| 256 | static void row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *arg2, | |
| 15884 | 257 | PurpleRoomlist *list) |
| 8113 | 258 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
259 | PidginRoomlist *grl = list->ui_data; |
| 8113 | 260 | GtkTreeIter iter; |
| 15884 | 261 | PurpleRoomlistRoom *room; |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
262 | GValue val; |
| 8113 | 263 | struct _menu_cb_info info; |
| 264 | ||
| 265 | gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
266 | val.g_type = 0; |
| 8113 | 267 | gtk_tree_model_get_value(GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); |
| 268 | room = g_value_get_pointer(&val); | |
| 15884 | 269 | if (!room || !(room->type & PURPLE_ROOMLIST_ROOMTYPE_ROOM)) |
| 8113 | 270 | return; |
| 271 | ||
| 272 | info.list = list; | |
| 273 | info.room = room; | |
| 274 | ||
| 275 | do_join_cb(GTK_WIDGET(tv), &info); | |
| 276 | } | |
| 277 | ||
| 15884 | 278 | static gboolean room_click_cb(GtkWidget *tv, GdkEventButton *event, PurpleRoomlist *list) |
| 8113 | 279 | { |
| 280 | GtkTreePath *path; | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
281 | PidginRoomlist *grl = list->ui_data; |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
282 | GValue val; |
| 15884 | 283 | PurpleRoomlistRoom *room; |
| 8113 | 284 | GtkTreeIter iter; |
| 285 | GtkWidget *menu; | |
| 286 | static struct _menu_cb_info info; /* XXX? */ | |
| 287 | ||
| 288 | if (event->button != 3 || event->type != GDK_BUTTON_PRESS) | |
| 289 | return FALSE; | |
| 290 | ||
| 291 | /* Here we figure out which room was clicked */ | |
| 292 | if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
| 293 | return FALSE; | |
| 294 | gtk_tree_model_get_iter(GTK_TREE_MODEL(grl->model), &iter, path); | |
| 295 | gtk_tree_path_free(path); | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
296 | val.g_type = 0; |
| 8113 | 297 | gtk_tree_model_get_value (GTK_TREE_MODEL(grl->model), &iter, ROOM_COLUMN, &val); |
| 298 | room = g_value_get_pointer(&val); | |
| 299 | ||
| 15884 | 300 | if (!room || !(room->type & PURPLE_ROOMLIST_ROOMTYPE_ROOM)) |
| 8113 | 301 | return FALSE; |
| 302 | ||
| 303 | info.list = list; | |
| 304 | info.room = room; | |
| 305 | ||
| 306 | menu = gtk_menu_new(); | |
| 15570 | 307 | pidgin_new_item_from_stock(menu, _("_Join"), PIDGIN_STOCK_CHAT, |
| 8113 | 308 | G_CALLBACK(do_join_cb), &info, 0, 0, NULL); |
| 15568 | 309 | pidgin_new_item_from_stock(menu, _("_Add"), GTK_STOCK_ADD, |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
310 | G_CALLBACK(do_add_room_cb), &info, 0, 0, NULL); |
| 8113 | 311 | |
| 312 | gtk_widget_show_all(menu); | |
| 313 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
| 314 | ||
| 315 | return FALSE; | |
| 316 | } | |
| 317 | ||
| 318 | static void row_expanded_cb(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer user_data) | |
| 319 | { | |
| 15884 | 320 | PurpleRoomlist *list = user_data; |
| 321 | PurpleRoomlistRoom *category; | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
322 | GValue val; |
| 8113 | 323 | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12286
diff
changeset
|
324 | val.g_type = 0; |
| 8113 | 325 | gtk_tree_model_get_value(gtk_tree_view_get_model(treeview), arg1, ROOM_COLUMN, &val); |
| 8584 | 326 | category = g_value_get_pointer(&val); |
| 8113 | 327 | |
| 8584 | 328 | if (!category->expanded_once) { |
| 15884 | 329 | purple_roomlist_expand_category(list, category); |
| 8584 | 330 | category->expanded_once = TRUE; |
| 8113 | 331 | } |
| 332 | } | |
| 333 | ||
| 15884 | 334 | static gboolean account_filter_func(PurpleAccount *account) |
| 8113 | 335 | { |
| 15884 | 336 | PurpleConnection *gc = purple_account_get_connection(account); |
| 337 | PurplePluginProtocolInfo *prpl_info = NULL; | |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
338 | |
| 15884 | 339 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
340 | |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
341 | return (prpl_info->roomlist_get_list != NULL); |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
342 | } |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
343 | |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
344 | gboolean |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
345 | pidgin_roomlist_is_showable() |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
346 | { |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
347 | GList *c; |
| 15884 | 348 | PurpleConnection *gc; |
| 8113 | 349 | |
| 15884 | 350 | for (c = purple_connections_get_all(); c != NULL; c = c->next) { |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
351 | gc = c->data; |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
352 | |
| 15884 | 353 | if (account_filter_func(purple_connection_get_account(gc))) |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
354 | return TRUE; |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
355 | } |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
356 | |
|
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
357 | return FALSE; |
| 8113 | 358 | } |
| 359 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
360 | static PidginRoomlistDialog * |
| 15884 | 361 | pidgin_roomlist_dialog_new_with_account(PurpleAccount *account) |
| 8113 | 362 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
363 | PidginRoomlistDialog *dialog; |
| 8113 | 364 | GtkWidget *window; |
| 8199 | 365 | GtkWidget *vbox; |
| 366 | GtkWidget *vbox2; | |
| 8113 | 367 | GtkWidget *account_hbox; |
| 368 | GtkWidget *bbox; | |
| 369 | GtkWidget *label; | |
| 370 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
371 | dialog = g_new0(PidginRoomlistDialog, 1); |
|
8937
b436e9cbd701
[gaim-migrate @ 9707]
Mark Doliner <markdoliner@pidgin.im>
parents:
8584
diff
changeset
|
372 | dialog->account = account; |
| 8113 | 373 | |
| 374 | /* Create the window. */ | |
| 17213 | 375 | dialog->window = window = pidgin_create_window(_("Room List"), PIDGIN_HIG_BORDER, "room list", TRUE); |
| 8113 | 376 | |
| 377 | g_signal_connect(G_OBJECT(window), "delete_event", | |
| 378 | G_CALLBACK(delete_win_cb), dialog); | |
| 379 | ||
| 380 | /* Create the parent vbox for everything. */ | |
| 15882 | 381 | vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 8199 | 382 | gtk_container_add(GTK_CONTAINER(window), vbox); |
| 383 | gtk_widget_show(vbox); | |
| 8113 | 384 | |
| 15882 | 385 | vbox2 = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 8199 | 386 | gtk_container_add(GTK_CONTAINER(vbox), vbox2); |
| 8113 | 387 | gtk_widget_show(vbox2); |
| 388 | ||
| 8352 | 389 | /* accounts dropdown list */ |
| 15882 | 390 | account_hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); |
| 8352 | 391 | gtk_box_pack_start(GTK_BOX(vbox2), account_hbox, FALSE, FALSE, 0); |
| 392 | gtk_widget_show(account_hbox); | |
| 8113 | 393 | |
| 8352 | 394 | label = gtk_label_new(NULL); |
|
8425
ef1267a8ba9f
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
395 | gtk_box_pack_start(GTK_BOX(account_hbox), label, FALSE, FALSE, 0); |
| 8352 | 396 | gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Account:")); |
|
8425
ef1267a8ba9f
[gaim-migrate @ 9155]
Christian Hammond <chipx86@chipx86.com>
parents:
8377
diff
changeset
|
397 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
| 8352 | 398 | gtk_widget_show(label); |
| 8113 | 399 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
400 | dialog->account_widget = pidgin_account_option_menu_new(dialog->account, FALSE, |
|
8939
ec2ecc652447
[gaim-migrate @ 9709]
Mark Doliner <markdoliner@pidgin.im>
parents:
8937
diff
changeset
|
401 | G_CALLBACK(dialog_select_account_cb), account_filter_func, dialog); |
| 8199 | 402 | |
| 9067 | 403 | if (!dialog->account) /* this is normally null, and we normally don't care what the first selected item is */ |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
404 | dialog->account = pidgin_account_option_menu_get_selected(dialog->account_widget); |
| 9067 | 405 | |
| 8352 | 406 | gtk_box_pack_start(GTK_BOX(account_hbox), dialog->account_widget, TRUE, TRUE, 0); |
| 407 | gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(dialog->account_widget)); | |
| 408 | gtk_widget_show(dialog->account_widget); | |
| 8113 | 409 | |
| 8199 | 410 | /* scrolled window */ |
| 8113 | 411 | dialog->sw = gtk_scrolled_window_new(NULL, NULL); |
| 412 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->sw), | |
| 413 | GTK_SHADOW_IN); | |
| 414 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->sw), | |
| 415 | GTK_POLICY_AUTOMATIC, | |
| 416 | GTK_POLICY_AUTOMATIC); | |
| 8199 | 417 | gtk_box_pack_start(GTK_BOX(vbox2), dialog->sw, TRUE, TRUE, 0); |
| 418 | gtk_widget_set_size_request(dialog->sw, -1, 250); | |
| 8113 | 419 | gtk_widget_show(dialog->sw); |
| 420 | ||
| 8199 | 421 | /* progress bar */ |
| 422 | dialog->progress = gtk_progress_bar_new(); | |
| 423 | gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dialog->progress), 0.1); | |
| 424 | gtk_box_pack_start(GTK_BOX(vbox2), dialog->progress, FALSE, FALSE, 0); | |
| 425 | gtk_widget_show(dialog->progress); | |
| 426 | ||
| 427 | /* button box */ | |
| 428 | bbox = gtk_hbutton_box_new(); | |
| 15882 | 429 | gtk_box_set_spacing(GTK_BOX(bbox), PIDGIN_HIG_BOX_SPACE); |
| 8199 | 430 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
| 431 | gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
| 432 | gtk_widget_show(bbox); | |
| 433 | ||
| 434 | /* stop button */ | |
| 435 | dialog->stop_button = gtk_button_new_from_stock(GTK_STOCK_STOP); | |
| 436 | gtk_box_pack_start(GTK_BOX(bbox), dialog->stop_button, FALSE, FALSE, 0); | |
| 437 | g_signal_connect(G_OBJECT(dialog->stop_button), "clicked", | |
| 438 | G_CALLBACK(stop_button_cb), dialog); | |
| 439 | gtk_widget_set_sensitive(dialog->stop_button, FALSE); | |
| 440 | gtk_widget_show(dialog->stop_button); | |
| 441 | ||
| 442 | /* list button */ | |
| 15568 | 443 | dialog->list_button = pidgin_pixbuf_button_from_stock(_("_Get List"), GTK_STOCK_REFRESH, |
| 444 | PIDGIN_BUTTON_HORIZONTAL); | |
| 8199 | 445 | gtk_box_pack_start(GTK_BOX(bbox), dialog->list_button, FALSE, FALSE, 0); |
| 446 | g_signal_connect(G_OBJECT(dialog->list_button), "clicked", | |
| 447 | G_CALLBACK(list_button_cb), dialog); | |
| 448 | gtk_widget_show(dialog->list_button); | |
| 449 | ||
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
450 | /* add button */ |
| 15568 | 451 | dialog->add_button = pidgin_pixbuf_button_from_stock(_("_Add Chat"), GTK_STOCK_ADD, |
| 452 | PIDGIN_BUTTON_HORIZONTAL); | |
|
12896
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
453 | gtk_box_pack_start(GTK_BOX(bbox), dialog->add_button, FALSE, FALSE, 0); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
454 | g_signal_connect(G_OBJECT(dialog->add_button), "clicked", |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
455 | G_CALLBACK(add_room_to_blist_cb), dialog); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
456 | gtk_widget_set_sensitive(dialog->add_button, FALSE); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
457 | gtk_widget_show(dialog->add_button); |
|
d368037a2bb7
[gaim-migrate @ 15249]
Peter Lawler <pidgin@bleeter.id.au>
parents:
12600
diff
changeset
|
458 | |
| 8199 | 459 | /* join button */ |
| 15570 | 460 | dialog->join_button = pidgin_pixbuf_button_from_stock(_("_Join"), PIDGIN_STOCK_CHAT, |
| 15568 | 461 | PIDGIN_BUTTON_HORIZONTAL); |
| 8199 | 462 | gtk_box_pack_start(GTK_BOX(bbox), dialog->join_button, FALSE, FALSE, 0); |
| 463 | g_signal_connect(G_OBJECT(dialog->join_button), "clicked", | |
| 464 | G_CALLBACK(join_button_cb), dialog); | |
| 465 | gtk_widget_set_sensitive(dialog->join_button, FALSE); | |
| 466 | gtk_widget_show(dialog->join_button); | |
| 467 | ||
| 468 | /* close button */ | |
| 469 | dialog->close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 470 | gtk_box_pack_start(GTK_BOX(bbox), dialog->close_button, FALSE, FALSE, 0); | |
| 471 | g_signal_connect(G_OBJECT(dialog->close_button), "clicked", | |
| 472 | G_CALLBACK(close_button_cb), dialog); | |
| 473 | gtk_widget_show(dialog->close_button); | |
| 474 | ||
| 475 | /* show the dialog window and return the dialog */ | |
| 476 | gtk_widget_show(dialog->window); | |
| 477 | ||
| 8113 | 478 | return dialog; |
| 479 | } | |
| 480 | ||
| 15884 | 481 | void pidgin_roomlist_dialog_show_with_account(PurpleAccount *account) |
| 8352 | 482 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
483 | PidginRoomlistDialog *dialog; |
| 8352 | 484 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
485 | dialog = pidgin_roomlist_dialog_new_with_account(account); |
| 8352 | 486 | if (!dialog) |
| 487 | return; | |
| 488 | ||
| 489 | list_button_cb(GTK_BUTTON(dialog->list_button), dialog); | |
| 490 | } | |
| 491 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
492 | void pidgin_roomlist_dialog_show(void) |
| 8113 | 493 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
494 | pidgin_roomlist_dialog_new_with_account(NULL); |
| 8113 | 495 | } |
| 496 | ||
| 15884 | 497 | static void pidgin_roomlist_new(PurpleRoomlist *list) |
| 8113 | 498 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
499 | PidginRoomlist *rl; |
| 8113 | 500 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
501 | rl = g_new0(PidginRoomlist, 1); |
| 8113 | 502 | |
| 503 | list->ui_data = rl; | |
| 504 | ||
| 505 | rl->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free); | |
| 506 | ||
| 507 | roomlists = g_list_append(roomlists, list); | |
| 508 | } | |
| 509 | ||
| 510 | static void int_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, | |
| 511 | GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) | |
| 512 | { | |
| 513 | gchar buf[16]; | |
| 514 | int myint; | |
| 515 | ||
| 516 | gtk_tree_model_get(model, iter, GPOINTER_TO_INT(user_data), &myint, -1); | |
| 517 | ||
| 518 | if (myint) | |
| 519 | g_snprintf(buf, sizeof(buf), "%d", myint); | |
| 520 | else | |
| 521 | buf[0] = '\0'; | |
| 522 | ||
| 523 | g_object_set(renderer, "text", buf, NULL); | |
| 524 | } | |
| 525 | ||
| 526 | /* this sorts backwards on purpose, so that clicking name sorts a-z, while clicking users sorts | |
| 527 | infinity-0. you can still click again to reverse it on any of them. */ | |
| 528 | static gint int_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) | |
| 529 | { | |
| 530 | int c, d; | |
| 531 | ||
| 532 | c = d = 0; | |
| 533 | ||
| 534 | gtk_tree_model_get(model, a, GPOINTER_TO_INT(user_data), &c, -1); | |
| 535 | gtk_tree_model_get(model, b, GPOINTER_TO_INT(user_data), &d, -1); | |
| 536 | ||
| 537 | if (c == d) | |
| 538 | return 0; | |
| 539 | else if (c > d) | |
| 540 | return -1; | |
| 541 | else | |
| 542 | return 1; | |
| 543 | } | |
| 544 | ||
|
11490
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
545 | static gboolean |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
546 | _search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
547 | { |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
548 | gboolean result; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
549 | gchar *name, *fold, *fkey; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
550 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
551 | gtk_tree_model_get(model, iter, column, &name, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
552 | fold = g_utf8_casefold(name, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
553 | fkey = g_utf8_casefold(key, -1); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
554 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
555 | result = (g_strstr_len(fold, strlen(fold), fkey) == NULL); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
556 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
557 | g_free(fold); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
558 | g_free(fkey); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
559 | g_free(name); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
560 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
561 | return result; |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
562 | } |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
563 | |
| 15884 | 564 | static void pidgin_roomlist_set_fields(PurpleRoomlist *list, GList *fields) |
| 8113 | 565 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
566 | PidginRoomlist *grl = list->ui_data; |
| 8113 | 567 | gint columns = NUM_OF_COLUMNS; |
| 568 | int j; | |
| 569 | GtkTreeStore *model; | |
| 570 | GtkWidget *tree; | |
| 571 | GtkCellRenderer *renderer; | |
| 572 | GtkTreeViewColumn *column; | |
| 8199 | 573 | GtkTreeSelection *selection; |
| 8113 | 574 | GList *l; |
| 575 | GType *types; | |
| 576 | ||
| 577 | g_return_if_fail(grl != NULL); | |
| 578 | ||
| 579 | columns += g_list_length(fields); | |
| 580 | types = g_new(GType, columns); | |
| 581 | ||
| 582 | types[NAME_COLUMN] = G_TYPE_STRING; | |
| 583 | types[ROOM_COLUMN] = G_TYPE_POINTER; | |
| 584 | ||
| 585 | for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
| 15884 | 586 | PurpleRoomlistField *f = l->data; |
| 8113 | 587 | |
| 588 | switch (f->type) { | |
| 15884 | 589 | case PURPLE_ROOMLIST_FIELD_BOOL: |
| 8113 | 590 | types[j] = G_TYPE_BOOLEAN; |
| 591 | break; | |
| 15884 | 592 | case PURPLE_ROOMLIST_FIELD_INT: |
| 8113 | 593 | types[j] = G_TYPE_INT; |
| 594 | break; | |
| 15884 | 595 | case PURPLE_ROOMLIST_FIELD_STRING: |
| 8113 | 596 | types[j] = G_TYPE_STRING; |
| 597 | break; | |
| 598 | } | |
| 599 | } | |
| 600 | ||
| 601 | model = gtk_tree_store_newv(columns, types); | |
| 602 | g_free(types); | |
| 603 | ||
| 604 | tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
| 605 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); | |
| 606 | ||
| 8199 | 607 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
| 608 | g_signal_connect(G_OBJECT(selection), "changed", | |
| 609 | G_CALLBACK(selection_changed_cb), grl); | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13448
diff
changeset
|
610 | |
| 8113 | 611 | g_object_unref(model); |
| 612 | ||
| 613 | grl->model = model; | |
| 614 | grl->tree = tree; | |
| 615 | gtk_widget_show(grl->tree); | |
| 616 | ||
| 617 | renderer = gtk_cell_renderer_text_new(); | |
| 618 | column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, | |
| 619 | "text", NAME_COLUMN, NULL); | |
| 620 | gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
| 621 | GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 622 | gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 623 | gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), NAME_COLUMN); | |
| 624 | gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 625 | gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
| 626 | ||
| 627 | for (j = NUM_OF_COLUMNS, l = fields; l; l = l->next, j++) { | |
| 15884 | 628 | PurpleRoomlistField *f = l->data; |
| 8113 | 629 | |
| 630 | if (f->hidden) | |
| 631 | continue; | |
| 632 | ||
| 633 | renderer = gtk_cell_renderer_text_new(); | |
| 634 | column = gtk_tree_view_column_new_with_attributes(f->label, renderer, | |
| 635 | "text", j, NULL); | |
| 636 | gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column), | |
| 637 | GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 638 | gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 639 | gtk_tree_view_column_set_sort_column_id(GTK_TREE_VIEW_COLUMN(column), j); | |
| 640 | gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 15884 | 641 | if (f->type == PURPLE_ROOMLIST_FIELD_INT) { |
| 8113 | 642 | gtk_tree_view_column_set_cell_data_func(column, renderer, int_cell_data_func, |
| 643 | GINT_TO_POINTER(j), NULL); | |
| 644 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), j, int_sort_func, | |
| 645 | GINT_TO_POINTER(j), NULL); | |
| 646 | } | |
| 647 | gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); | |
| 648 | } | |
| 649 | ||
| 650 | g_signal_connect(G_OBJECT(tree), "button-press-event", G_CALLBACK(room_click_cb), list); | |
| 651 | g_signal_connect(G_OBJECT(tree), "row-expanded", G_CALLBACK(row_expanded_cb), list); | |
| 652 | g_signal_connect(G_OBJECT(tree), "row-activated", G_CALLBACK(row_activated_cb), list); | |
|
11490
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
653 | |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
654 | /* Enable CTRL+F searching */ |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
655 | gtk_tree_view_set_search_column(GTK_TREE_VIEW(tree), NAME_COLUMN); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
656 | gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree), _search_func, NULL, NULL); |
|
7a4f16625f66
[gaim-migrate @ 13733]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11243
diff
changeset
|
657 | |
| 8113 | 658 | } |
| 659 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
660 | static gboolean pidgin_progress_bar_pulse(gpointer data) |
| 8230 | 661 | { |
| 15884 | 662 | PurpleRoomlist *list = data; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
663 | PidginRoomlist *rl = list->ui_data; |
| 8230 | 664 | |
| 665 | if (!rl || !rl->dialog || !rl->dialog->pg_needs_pulse) { | |
|
13448
27832a91b988
[gaim-migrate @ 15822]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12896
diff
changeset
|
666 | if (rl && rl->dialog) |
|
27832a91b988
[gaim-migrate @ 15822]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12896
diff
changeset
|
667 | rl->dialog->pg_to_active = FALSE; |
| 15884 | 668 | purple_roomlist_unref(list); |
| 8230 | 669 | return FALSE; |
| 670 | } | |
| 671 | ||
| 672 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); | |
| 673 | rl->dialog->pg_needs_pulse = FALSE; | |
| 674 | return TRUE; | |
| 675 | } | |
| 676 | ||
| 15884 | 677 | static void pidgin_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
| 8113 | 678 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
679 | PidginRoomlist *rl = list->ui_data; |
| 8113 | 680 | GtkTreeRowReference *rr, *parentrr = NULL; |
| 681 | GtkTreePath *path; | |
| 682 | GtkTreeIter iter, parent, child; | |
| 683 | GList *l, *k; | |
| 684 | int j; | |
| 685 | gboolean append = TRUE; | |
| 686 | ||
| 687 | rl->total_rooms++; | |
| 15884 | 688 | if (room->type == PURPLE_ROOMLIST_ROOMTYPE_ROOM) |
| 8113 | 689 | rl->num_rooms++; |
| 690 | ||
| 691 | if (rl->dialog) { | |
| 8230 | 692 | if (!rl->dialog->pg_to_active) { |
| 693 | rl->dialog->pg_to_active = TRUE; | |
| 15884 | 694 | purple_roomlist_ref(list); |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
695 | rl->dialog->pg_update_to = g_timeout_add(100, pidgin_progress_bar_pulse, list); |
| 8230 | 696 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(rl->dialog->progress)); |
| 697 | } else { | |
| 698 | rl->dialog->pg_needs_pulse = TRUE; | |
| 699 | } | |
| 8113 | 700 | } |
| 701 | if (room->parent) { | |
| 702 | parentrr = g_hash_table_lookup(rl->cats, room->parent); | |
| 703 | path = gtk_tree_row_reference_get_path(parentrr); | |
| 704 | if (path) { | |
| 15884 | 705 | PurpleRoomlistRoom *tmproom = NULL; |
| 8113 | 706 | |
| 707 | gtk_tree_model_get_iter(GTK_TREE_MODEL(rl->model), &parent, path); | |
| 708 | gtk_tree_path_free(path); | |
| 709 | ||
| 710 | if (gtk_tree_model_iter_children(GTK_TREE_MODEL(rl->model), &child, &parent)) { | |
| 711 | gtk_tree_model_get(GTK_TREE_MODEL(rl->model), &child, ROOM_COLUMN, &tmproom, -1); | |
| 712 | if (!tmproom) | |
| 713 | append = FALSE; | |
| 714 | } | |
| 715 | } | |
| 716 | } | |
| 717 | ||
| 718 | if (append) | |
| 719 | gtk_tree_store_append(rl->model, &iter, (parentrr ? &parent : NULL)); | |
| 720 | else | |
| 721 | iter = child; | |
| 722 | ||
| 15884 | 723 | if (room->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) |
| 8113 | 724 | gtk_tree_store_append(rl->model, &child, &iter); |
| 725 | ||
| 726 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(rl->model), &iter); | |
| 727 | ||
| 15884 | 728 | if (room->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) { |
| 8113 | 729 | rr = gtk_tree_row_reference_new(GTK_TREE_MODEL(rl->model), path); |
| 730 | g_hash_table_insert(rl->cats, room, rr); | |
| 731 | } | |
| 732 | ||
| 733 | gtk_tree_path_free(path); | |
| 734 | ||
| 735 | gtk_tree_store_set(rl->model, &iter, NAME_COLUMN, room->name, -1); | |
| 736 | gtk_tree_store_set(rl->model, &iter, ROOM_COLUMN, room, -1); | |
| 737 | ||
| 738 | for (j = NUM_OF_COLUMNS, l = room->fields, k = list->fields; l && k; j++, l = l->next, k = k->next) { | |
| 15884 | 739 | PurpleRoomlistField *f = k->data; |
| 8113 | 740 | if (f->hidden) |
| 741 | continue; | |
| 742 | gtk_tree_store_set(rl->model, &iter, j, l->data, -1); | |
| 743 | } | |
| 744 | } | |
| 745 | ||
| 15884 | 746 | static void pidgin_roomlist_in_progress(PurpleRoomlist *list, gboolean flag) |
| 8113 | 747 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
748 | PidginRoomlist *rl = list->ui_data; |
| 8113 | 749 | |
| 750 | if (!rl || !rl->dialog) | |
| 751 | return; | |
| 752 | ||
| 753 | if (flag) { | |
| 8199 | 754 | if (rl->dialog->account_widget) |
| 755 | gtk_widget_set_sensitive(rl->dialog->account_widget, FALSE); | |
| 756 | gtk_widget_set_sensitive(rl->dialog->stop_button, TRUE); | |
| 757 | gtk_widget_set_sensitive(rl->dialog->list_button, FALSE); | |
| 8113 | 758 | } else { |
| 8230 | 759 | rl->dialog->pg_needs_pulse = FALSE; |
| 8113 | 760 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(rl->dialog->progress), 0.0); |
| 8199 | 761 | if (rl->dialog->account_widget) |
| 762 | gtk_widget_set_sensitive(rl->dialog->account_widget, TRUE); | |
| 763 | gtk_widget_set_sensitive(rl->dialog->stop_button, FALSE); | |
| 764 | gtk_widget_set_sensitive(rl->dialog->list_button, TRUE); | |
| 8113 | 765 | } |
| 766 | } | |
| 767 | ||
| 15884 | 768 | static void pidgin_roomlist_destroy(PurpleRoomlist *list) |
| 8113 | 769 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
770 | PidginRoomlist *rl; |
| 8113 | 771 | |
| 772 | roomlists = g_list_remove(roomlists, list); | |
| 773 | ||
| 774 | rl = list->ui_data; | |
| 775 | ||
| 776 | g_return_if_fail(rl != NULL); | |
| 777 | ||
| 778 | g_hash_table_destroy(rl->cats); | |
| 779 | g_free(rl); | |
| 780 | list->ui_data = NULL; | |
| 781 | } | |
| 782 | ||
| 15884 | 783 | static PurpleRoomlistUiOps ops = { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
784 | pidgin_roomlist_dialog_show_with_account, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
785 | pidgin_roomlist_new, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
786 | pidgin_roomlist_set_fields, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
787 | pidgin_roomlist_add_room, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
788 | pidgin_roomlist_in_progress, |
|
16752
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
789 | pidgin_roomlist_destroy, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
790 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
791 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
792 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
793 | NULL |
| 8113 | 794 | }; |
| 795 | ||
| 796 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
797 | void pidgin_roomlist_init(void) |
| 8113 | 798 | { |
| 15884 | 799 | purple_roomlist_set_ui_ops(&ops); |
| 8113 | 800 | } |