Mercurial > pidgin
annotate src/gtkconn.c @ 7931:2a781d4178ba
[gaim-migrate @ 8602]
Make the prefs away message tree view thing actually scroll when you use
the arrow keys to scroll through your away messages. Same for the
privacy lists and for list of users in a chat. Although, the last one
you can't use the keyboard because input is stolen by the text input
box.
Make the menu item for blocking users gray out if the protocol doesn't
support it.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 26 Dec 2003 20:34:58 +0000 |
parents | 4d4438f6ddce |
children | c052eccc10ee |
rev | line source |
---|---|
5717 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6216
diff
changeset
|
20 #include "gtkinternal.h" |
5717 | 21 |
22 #include "account.h" | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
23 #include "debug.h" |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
24 #include "notify.h" |
6216 | 25 #include "prefs.h" |
7399 | 26 #include "stock.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
27 #include "util.h" |
5717 | 28 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
29 #include "gtkblist.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
30 #include "gtkutils.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
31 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
32 #include "ui.h" |
5717 | 33 |
7912 | 34 /* |
35 * The next couple of functions deal with the connection dialog | |
36 */ | |
5717 | 37 struct signon_meter { |
38 GaimAccount *account; | |
39 GtkWidget *button; | |
40 GtkWidget *progress; | |
41 GtkWidget *status; | |
42 }; | |
43 | |
44 struct meter_window { | |
45 GtkWidget *window; | |
46 GtkWidget *table; | |
47 gint rows; | |
48 gint active_count; | |
49 GSList *meters; | |
7912 | 50 }; |
51 struct meter_window *meter_win = NULL; | |
5717 | 52 |
7912 | 53 static void kill_meter(struct signon_meter *meter, const char *text) |
54 { | |
55 gtk_widget_set_sensitive(meter->button, FALSE); | |
56 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), 1); | |
57 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
58 meter_win->active_count--; | |
59 | |
60 if (meter_win->active_count == 0) { | |
61 gtk_widget_destroy(meter_win->window); | |
62 g_free(meter_win); | |
63 meter_win = NULL; | |
64 } | |
65 } | |
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
66 |
5717 | 67 static void cancel_signon(GtkWidget *button, struct signon_meter *meter) |
68 { | |
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
69 if (meter->account->gc != NULL) { |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
70 meter->account->gc->wants_to_die = TRUE; |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
71 gaim_connection_destroy(meter->account->gc); |
7912 | 72 } else { |
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
73 kill_meter(meter, _("Done.")); |
5987
6e19ad2ef712
[gaim-migrate @ 6435]
Christian Hammond <chipx86@chipx86.com>
parents:
5936
diff
changeset
|
74 |
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
75 if (gaim_connections_get_all() == NULL) { |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
76 destroy_all_dialogs(); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
77 |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
78 gaim_blist_destroy(); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
79 |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
80 show_login(); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
81 } |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
82 } |
5717 | 83 } |
84 | |
7912 | 85 static void cancel_all () |
86 { | |
5717 | 87 GSList *m = meter_win ? meter_win->meters : NULL; |
6114 | 88 struct signon_meter *meter; |
5717 | 89 |
90 while (m) { | |
6114 | 91 meter = m->data; |
7890 | 92 if (gaim_connection_get_state(meter->account->gc) != GAIM_CONNECTED) |
93 cancel_signon(NULL, meter); | |
6114 | 94 m = m->next; |
5717 | 95 } |
96 } | |
97 | |
98 static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) | |
99 { | |
100 return TRUE; | |
101 } | |
102 | |
103 static struct signon_meter *find_signon_meter(GaimConnection *gc) | |
104 { | |
105 GSList *m = meter_win ? meter_win->meters : NULL; | |
6114 | 106 struct signon_meter *meter; |
5717 | 107 |
108 while (m) { | |
6114 | 109 meter = m->data; |
110 if (meter->account == gaim_connection_get_account(gc)) | |
5717 | 111 return m->data; |
112 m = m->next; | |
113 } | |
114 | |
115 return NULL; | |
116 } | |
117 | |
118 static GtkWidget* create_meter_pixmap (GaimConnection *gc) | |
119 { | |
120 GdkPixbuf *pb = create_prpl_icon(gc->account); | |
121 GdkPixbuf *scale = gdk_pixbuf_scale_simple(pb, 30,30,GDK_INTERP_BILINEAR); | |
122 GtkWidget *image = | |
123 gtk_image_new_from_pixbuf(scale); | |
124 g_object_unref(G_OBJECT(pb)); | |
125 g_object_unref(G_OBJECT(scale)); | |
126 return image; | |
127 } | |
128 | |
129 static struct signon_meter * | |
130 new_meter(GaimConnection *gc, GtkWidget *widget, | |
131 GtkWidget *table, gint *rows) | |
132 { | |
133 GtkWidget *graphic; | |
134 GtkWidget *label; | |
135 GtkWidget *nest_vbox; | |
136 GString *name_to_print; | |
137 struct signon_meter *meter; | |
138 | |
139 | |
140 meter = g_new0(struct signon_meter, 1); | |
141 | |
142 meter->account = gaim_connection_get_account(gc); | |
143 name_to_print = g_string_new(gaim_account_get_username(meter->account)); | |
144 | |
145 (*rows)++; | |
146 gtk_table_resize (GTK_TABLE(table), *rows, 4); | |
147 | |
148 graphic = create_meter_pixmap(gc); | |
149 | |
150 nest_vbox = gtk_vbox_new (FALSE, 0); | |
151 | |
152 g_string_prepend(name_to_print, _("Signon: ")); | |
153 label = gtk_label_new (name_to_print->str); | |
154 g_string_free(name_to_print, TRUE); | |
155 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); | |
156 | |
157 meter->status = gtk_label_new(""); | |
158 gtk_misc_set_alignment(GTK_MISC(meter->status), 0, 0.5); | |
159 gtk_widget_set_size_request(meter->status, 250, -1); | |
160 | |
161 meter->progress = gtk_progress_bar_new (); | |
162 | |
163 meter->button = gaim_pixbuf_button_from_stock (_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
164 g_signal_connect(G_OBJECT (meter->button), "clicked", | |
165 G_CALLBACK (cancel_signon), meter); | |
166 | |
167 gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
168 gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
169 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0); | |
170 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0); | |
171 gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
172 gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
173 | |
174 gtk_widget_show_all (GTK_WIDGET (meter_win->window)); | |
175 | |
176 meter_win->active_count++; | |
177 | |
178 return meter; | |
179 } | |
180 | |
181 static void gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
182 const char *text, size_t step, size_t step_count) | |
183 { | |
184 struct signon_meter *meter; | |
185 | |
186 if(!meter_win) { | |
187 GtkWidget *vbox; | |
188 GtkWidget *cancel_button; | |
189 | |
190 if(mainwindow) | |
191 gtk_widget_hide(mainwindow); | |
192 | |
193 meter_win = g_new0(struct meter_window, 1); | |
194 meter_win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
195 gtk_window_set_resizable(GTK_WINDOW(meter_win->window), FALSE); | |
196 gtk_window_set_role(GTK_WINDOW(meter_win->window), "signon"); | |
197 gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5); | |
198 gtk_window_set_title(GTK_WINDOW(meter_win->window), _("Signon")); | |
199 gtk_widget_realize(meter_win->window); | |
200 | |
201 vbox = gtk_vbox_new (FALSE, 0); | |
202 gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
203 | |
204 meter_win->table = gtk_table_new(1, 4, FALSE); | |
205 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
206 FALSE, FALSE, 0); | |
207 gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
208 gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
209 gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
210 | |
211 cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
212 GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
213 g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
214 G_CALLBACK(cancel_all), NULL); | |
215 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
216 FALSE, FALSE, 0); | |
217 | |
218 g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
219 G_CALLBACK(meter_destroy), NULL); | |
220 } | |
221 | |
222 meter = find_signon_meter(gc); | |
223 if(!meter) { | |
224 meter = new_meter(gc, meter_win->window, meter_win->table, | |
225 &meter_win->rows); | |
226 | |
227 meter_win->meters = g_slist_append(meter_win->meters, meter); | |
228 } | |
229 | |
230 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
231 (float)step / (float)step_count); | |
232 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
233 } | |
234 | |
235 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
236 { | |
237 struct signon_meter *meter = find_signon_meter(gc); | |
238 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
239 gaim_setup(gc); |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
240 |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
241 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
242 gaim_gtk_blist_update_protocol_actions(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
243 |
7912 | 244 if (meter) |
5717 | 245 kill_meter(meter, _("Done.")); |
246 } | |
247 | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
248 static void gaim_gtk_connection_disconnected(GaimConnection *gc) |
5717 | 249 { |
250 struct signon_meter *meter = find_signon_meter(gc); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
251 |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
252 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
253 gaim_gtk_blist_update_protocol_actions(); |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
254 |
7912 | 255 if (meter) |
5717 | 256 kill_meter(meter, _("Done.")); |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
257 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
258 if (gaim_connections_get_all() != NULL) |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
259 return; |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
260 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
261 destroy_all_dialogs(); |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
262 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
263 gaim_blist_destroy(); |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
264 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
265 show_login(); |
5717 | 266 } |
267 | |
268 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
269 const char *text) | |
270 { | |
271 } | |
272 | |
7912 | 273 /* |
274 * The next couple of functions deal with the disconnected dialog | |
275 */ | |
7399 | 276 struct disconnect_window { |
277 GtkWidget *window; | |
278 GtkWidget *treeview; | |
279 GtkWidget *sw; | |
280 GtkWidget *label; | |
7808 | 281 GtkWidget *reconnect_btn; |
7912 | 282 GtkWidget *reconnectall_btn; |
7399 | 283 }; |
284 struct disconnect_window *disconnect_window = NULL; | |
285 | |
7912 | 286 static void disconnect_connection_change_cb(GaimConnection *gc, void *data); |
287 | |
288 /* | |
289 * Destroy the dialog and remove the signals associated with it. | |
290 */ | |
7493 | 291 static void disconnect_window_hide() |
292 { | |
7912 | 293 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", |
294 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb)); | |
295 | |
296 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", | |
297 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb)); | |
298 | |
7493 | 299 gtk_widget_destroy(disconnect_window->window); |
300 g_free(disconnect_window); | |
301 disconnect_window = NULL; | |
302 } | |
303 | |
7912 | 304 /* |
305 * Make sure the Reconnect and Reconnect All buttons are correctly | |
306 * shown or hidden. Also make sure the label on the Reconnect | |
307 * button is correctly set to either Reconnect or Remove. If there | |
308 * is more than one account then make sure the GtkTreeView is shown. | |
309 * If there are no accounts disconnectd then hide the dialog. | |
310 */ | |
311 static void disconnect_window_update_buttons(GtkTreeModel *model) | |
312 { | |
313 GtkTreeIter iter; | |
314 GtkTreeSelection *sel; | |
315 const char *label_text; | |
316 GaimAccount *account = NULL; | |
317 | |
318 if ((disconnect_window == NULL) || (model == NULL)) | |
319 return; | |
320 | |
321 if (!gtk_tree_model_get_iter_first(model, &iter)) { | |
322 /* No more accounts being shown. Caloo calay! */ | |
323 disconnect_window_hide(); | |
324 return; | |
325 } | |
326 | |
327 /* | |
328 * If we have more than one disconnected account then show the | |
329 * GtkTreeView and the "Reconnect All" button | |
330 */ | |
331 if (gtk_tree_model_iter_next(model, &iter)) { | |
332 gtk_widget_show_all(disconnect_window->sw); | |
333 gtk_widget_show(disconnect_window->reconnectall_btn); | |
334 } else { | |
335 gtk_widget_hide_all(disconnect_window->sw); | |
336 gtk_widget_hide(disconnect_window->reconnectall_btn); | |
337 } | |
338 | |
339 /* | |
340 * Make sure one of the accounts is selected. | |
341 */ | |
342 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
343 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) { | |
344 gtk_tree_model_get_iter_first(model, &iter); | |
345 gtk_tree_selection_select_iter(sel, &iter); | |
346 } | |
347 | |
348 /* | |
349 * Update the Reconnect/Remove button appropriately and set the | |
350 * label in the dialog to what it should be. | |
351 */ | |
352 gtk_tree_model_get(model, &iter, 3, &label_text, 4, &account, -1); | |
353 gtk_button_set_label(GTK_BUTTON(disconnect_window->reconnect_btn), | |
354 gaim_account_is_connected(account) ? _("_Remove") : _("_Reconnect")); | |
355 gtk_label_set_markup(GTK_LABEL(disconnect_window->label), label_text); | |
356 gtk_dialog_set_response_sensitive(GTK_DIALOG(disconnect_window->window), GTK_RESPONSE_ACCEPT, TRUE); | |
357 } | |
358 | |
7399 | 359 static void disconnect_response_cb(GtkDialog *dialog, gint id, GtkWidget *widget) |
360 { | |
7483 | 361 GtkTreeIter iter; |
362 GtkTreeSelection *sel = NULL; | |
363 GtkTreeModel *model = NULL; | |
7431 | 364 GaimAccount *account = NULL; |
365 | |
7912 | 366 switch (id) { |
367 case GTK_RESPONSE_APPLY: /* Reconnect All */ | |
7808 | 368 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); |
369 if (gtk_tree_model_get_iter_first(model, &iter)) { | |
370 /* tree rows to be deleted */ | |
371 GList *l_del = NULL, *l_del_iter = NULL; | |
372 /* accounts to be connected */ | |
7912 | 373 GList *l_accts = NULL, *l_accts_iter = NULL; |
7808 | 374 do { |
375 GtkTreePath *path = gtk_tree_model_get_path(model, &iter); | |
376 GtkTreeRowReference* del_row = gtk_tree_row_reference_new(model, path); | |
377 l_del = g_list_append(l_del, del_row); | |
378 gtk_tree_path_free(path); | |
379 | |
380 gtk_tree_model_get(model, &iter, 4, &account, -1); | |
381 if (!gaim_account_is_connected(account) && g_list_find(l_accts, account) == NULL) | |
382 l_accts = g_list_append(l_accts, account); | |
383 } while (gtk_tree_model_iter_next(model, &iter)); | |
384 | |
385 /* remove all rows */ | |
7912 | 386 /* We could just do the following, but we only want to remove accounts |
387 * that are going to be reconnected, not accounts that have already | |
388 * been reconnected. | |
389 */ | |
390 /* gtk_list_store_clear(GTK_LIST_STORE(model)); */ | |
7808 | 391 l_del_iter = l_del; |
392 while (l_del_iter != NULL) { | |
393 GtkTreeRowReference* del_row = l_del_iter->data; | |
394 GtkTreePath *path = gtk_tree_row_reference_get_path(del_row); | |
395 if (gtk_tree_model_get_iter(model, &iter, path)) | |
396 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
397 gtk_tree_path_free(path); | |
398 gtk_tree_row_reference_free(del_row); | |
399 l_del_iter = l_del_iter->next; | |
400 } | |
401 g_list_free(l_del); | |
402 | |
403 /* reconnect disconnected accounts */ | |
404 l_accts_iter = l_accts; | |
405 while (l_accts_iter != NULL) { | |
406 account = l_accts_iter->data; | |
407 gaim_account_connect(account); | |
408 l_accts_iter = l_accts_iter->next; | |
409 } | |
410 g_list_free(l_accts); | |
411 | |
412 } | |
413 | |
7912 | 414 disconnect_window_update_buttons(model); |
415 | |
7808 | 416 break; |
7912 | 417 |
418 case GTK_RESPONSE_ACCEPT: /* Reconnect Selected */ | |
7483 | 419 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); |
7912 | 420 |
7483 | 421 /* |
422 * If we have more than one account disconnection displayed, then | |
423 * the scroll window is visible and we should use the selected | |
424 * account to reconnect. | |
425 */ | |
426 if (GTK_WIDGET_VISIBLE(disconnect_window->sw)) { | |
427 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
428 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) | |
429 return; | |
430 } else { | |
431 /* There is only one account disconnection, so reconnect to it. */ | |
432 if (!gtk_tree_model_get_iter_first(model, &iter)) | |
433 return; | |
434 } | |
7912 | 435 |
436 /* remove all disconnections of the account to be reconnected */ | |
7808 | 437 gtk_tree_model_get(model, &iter, 4, &account, -1); |
7637 | 438 if (gtk_tree_model_get_iter_first(model, &iter)) { |
7808 | 439 GList *l_del = NULL, *l_del_iter = NULL; |
7637 | 440 GaimAccount *account2 = NULL; |
441 do { | |
7808 | 442 gtk_tree_model_get(model, &iter, 4, &account2, -1); |
7637 | 443 if (account2 == account) { |
7643 | 444 GtkTreePath *path = gtk_tree_model_get_path(model, &iter); |
445 GtkTreeRowReference* del_row = gtk_tree_row_reference_new(model, path); | |
446 l_del = g_list_append(l_del, del_row); | |
7808 | 447 gtk_tree_path_free(path); |
7637 | 448 } |
7643 | 449 } while (gtk_tree_model_iter_next(model, &iter)); |
450 | |
7808 | 451 l_del_iter = l_del; |
452 while (l_del_iter != NULL) { | |
453 GtkTreeRowReference* del_row = l_del_iter->data; | |
7643 | 454 GtkTreePath *path = gtk_tree_row_reference_get_path(del_row); |
455 if (gtk_tree_model_get_iter(model, &iter, path)) | |
456 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
7808 | 457 gtk_tree_path_free(path); |
458 gtk_tree_row_reference_free(del_row); | |
459 l_del_iter = l_del_iter->next; | |
7643 | 460 } |
7808 | 461 g_list_free(l_del); |
7637 | 462 } |
463 | |
7643 | 464 gaim_account_connect(account); |
7912 | 465 disconnect_window_update_buttons(model); |
7643 | 466 |
7399 | 467 break; |
7912 | 468 |
469 case GTK_RESPONSE_DELETE_EVENT: | |
470 case GTK_RESPONSE_CLOSE: | |
471 disconnect_window_hide(); | |
472 break; | |
473 | |
7399 | 474 } |
475 } | |
476 | |
7912 | 477 /* |
478 * Called whenever a different account is selected in the GtkListWhatever. | |
479 */ | |
7399 | 480 static void disconnect_tree_cb(GtkTreeSelection *sel, GtkTreeModel *model) |
481 { | |
7912 | 482 disconnect_window_update_buttons(model); |
7399 | 483 } |
484 | |
7912 | 485 /* |
486 * Update the icon next to the account in the disconnect dialog, and | |
487 * gray the Reconnect All button if there is only 1 disconnected account. | |
488 */ | |
7808 | 489 static void disconnect_connection_change_cb(GaimConnection *gc, void *data) { |
7912 | 490 GaimAccount *account = gaim_connection_get_account(gc); |
491 GtkTreeIter iter; | |
492 GtkTreeModel *model; | |
493 GdkPixbuf *icon; | |
494 GdkPixbuf *scale; | |
495 GList *l_disc_accts = NULL; | |
496 | |
497 if (disconnect_window == NULL) | |
498 return; | |
499 | |
500 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); | |
501 icon = create_prpl_icon(account); | |
502 scale = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); | |
503 | |
504 /* Mark all disconnections w/ the account type disconnected /w grey icon */ | |
505 if (!gaim_account_is_connected(account)) | |
506 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); | |
507 | |
508 gtk_tree_model_get_iter_first(model, &iter); | |
509 do { | |
510 GaimAccount *account2 = NULL; | |
511 /* Gray out the icon if this row is for this account */ | |
512 gtk_tree_model_get(model, &iter, 4, &account2, -1); | |
513 if (account2 == account) | |
514 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, scale, -1); | |
515 | |
516 /* Add */ | |
517 if (!gaim_account_is_connected(account2) | |
7808 | 518 && g_list_find(l_disc_accts, account2) == NULL) |
7912 | 519 l_disc_accts = g_list_append(l_disc_accts, account2); |
520 } while (gtk_tree_model_iter_next(model, &iter)); | |
7808 | 521 |
7912 | 522 gtk_dialog_set_response_sensitive( |
523 GTK_DIALOG(disconnect_window->window), | |
524 GTK_RESPONSE_APPLY, | |
525 g_list_length(l_disc_accts) > 1); | |
526 g_list_free(l_disc_accts); | |
527 | |
528 if (icon != NULL) | |
529 g_object_unref(G_OBJECT(icon)); | |
530 if (scale != NULL) | |
531 g_object_unref(G_OBJECT(scale)); | |
532 | |
533 disconnect_window_update_buttons(model); | |
7625 | 534 } |
7399 | 535 |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
536 static void |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
537 gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
538 { |
7399 | 539 char *label_text = NULL; |
7912 | 540 GtkTreeIter new_iter; |
7506 | 541 GtkListStore *list_store; |
542 GtkTreeViewColumn *col; | |
543 GtkTreeSelection *sel = NULL; | |
7399 | 544 |
7648 | 545 label_text = g_strdup_printf(_("<span weight=\"bold\" size=\"larger\">%s has been disconnected.</span>\n\n%s\n%s"), |
7912 | 546 gaim_account_get_username(gaim_connection_get_account(gc)), gaim_date_full(), |
7399 | 547 text ? text : _("Reason Unknown.")); |
7496 | 548 |
7506 | 549 /* Build the window if it isn't there yet */ |
550 if (!disconnect_window) { | |
7399 | 551 GtkWidget *hbox, *vbox, *img; |
552 GtkCellRenderer *rend, *rend2; | |
7496 | 553 |
7407 | 554 disconnect_window = g_new0(struct disconnect_window, 1); |
7874 | 555 disconnect_window->window = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, NULL, GTK_DIALOG_NO_SEPARATOR, NULL); |
7399 | 556 g_signal_connect(G_OBJECT(disconnect_window->window), "response", G_CALLBACK(disconnect_response_cb), disconnect_window); |
557 | |
558 gtk_container_set_border_width(GTK_CONTAINER(disconnect_window->window), 6); | |
559 gtk_window_set_resizable(GTK_WINDOW(disconnect_window->window), FALSE); | |
560 gtk_dialog_set_has_separator(GTK_DIALOG(disconnect_window->window), FALSE); | |
561 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(disconnect_window->window)->vbox), 12); | |
562 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), 6); | |
563 | |
564 hbox = gtk_hbox_new(FALSE, 12); | |
565 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), hbox); | |
566 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); | |
567 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
568 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
7496 | 569 |
7399 | 570 vbox = gtk_vbox_new(FALSE, 12); |
571 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
572 | |
7506 | 573 disconnect_window->label = gtk_label_new(label_text); |
7496 | 574 |
7399 | 575 gtk_label_set_line_wrap(GTK_LABEL(disconnect_window->label), TRUE); |
576 gtk_misc_set_alignment(GTK_MISC(disconnect_window->label), 0, 0); | |
577 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->label, FALSE, FALSE, 0); | |
578 | |
7808 | 579 disconnect_window->reconnect_btn = gtk_dialog_add_button( |
580 GTK_DIALOG(disconnect_window->window), | |
581 _("_Reconnect"), | |
582 GTK_RESPONSE_ACCEPT); | |
583 | |
7912 | 584 disconnect_window->reconnectall_btn = gtk_dialog_add_button( |
7808 | 585 GTK_DIALOG(disconnect_window->window), |
586 _("Reconnect _All"), | |
587 GTK_RESPONSE_APPLY); | |
588 | |
7874 | 589 gtk_dialog_add_button( |
590 GTK_DIALOG(disconnect_window->window), | |
591 GTK_STOCK_CLOSE, | |
592 GTK_RESPONSE_CLOSE); | |
593 | |
7399 | 594 gtk_widget_show_all(disconnect_window->window); |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
595 |
7399 | 596 /* Tree View */ |
597 disconnect_window->sw = gtk_scrolled_window_new(NULL,NULL); | |
7912 | 598 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_SHADOW_IN); |
599 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
7399 | 600 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->sw, TRUE, TRUE, 0); |
7496 | 601 |
7912 | 602 list_store = gtk_list_store_new(5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); |
603 disconnect_window->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store)); | |
7496 | 604 |
7399 | 605 rend = gtk_cell_renderer_pixbuf_new(); |
606 rend2 = gtk_cell_renderer_text_new(); | |
607 col = gtk_tree_view_column_new(); | |
608 gtk_tree_view_column_set_title(col, _("Account")); | |
609 gtk_tree_view_column_pack_start(col, rend, FALSE); | |
610 gtk_tree_view_column_pack_start(col, rend2, FALSE); | |
611 gtk_tree_view_column_set_attributes(col, rend, "pixbuf", 0, NULL); | |
612 gtk_tree_view_column_set_attributes(col, rend2, "text", 1, NULL); | |
613 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
7496 | 614 |
7399 | 615 rend = gtk_cell_renderer_text_new(); |
616 col = gtk_tree_view_column_new_with_attributes (_("Time"), | |
617 rend, "text", 2, NULL); | |
618 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
7637 | 619 |
7399 | 620 g_object_unref(G_OBJECT(list_store)); |
621 gtk_container_add(GTK_CONTAINER(disconnect_window->sw), disconnect_window->treeview); | |
7496 | 622 |
7399 | 623 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (disconnect_window->treeview)); |
7409
2ea9bf5686ad
[gaim-migrate @ 8009]
Christian Hammond <chipx86@chipx86.com>
parents:
7407
diff
changeset
|
624 gtk_widget_set_size_request(disconnect_window->treeview, -1, 96); |
7399 | 625 g_signal_connect (G_OBJECT (sel), "changed", |
626 G_CALLBACK (disconnect_tree_cb), list_store); | |
7625 | 627 |
628 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
7808 | 629 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb), NULL); |
630 | |
631 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | |
632 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb), NULL); | |
7506 | 633 } else |
634 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview))); | |
635 | |
636 /* Add this account to our list of disconnected accounts */ | |
7912 | 637 gtk_list_store_append(list_store, &new_iter); |
638 gtk_list_store_set(list_store, &new_iter, | |
7808 | 639 0, NULL, |
7506 | 640 1, gaim_account_get_username(gaim_connection_get_account(gc)), |
641 2, gaim_date_full(), | |
642 3, label_text, | |
643 4, gaim_connection_get_account(gc), -1); | |
644 | |
7912 | 645 /* Make sure the newly disconnected account is selected */ |
646 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
647 gtk_tree_selection_select_iter(sel, &new_iter); | |
648 | |
649 disconnect_window_update_buttons(GTK_TREE_MODEL(list_store)); | |
7496 | 650 |
7399 | 651 g_free(label_text); |
7493 | 652 gtk_window_present(GTK_WINDOW(disconnect_window->window)); |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
653 } |
7912 | 654 /* |
655 * End of disconnected dialog | |
656 */ | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
657 |
5717 | 658 static GaimConnectionUiOps conn_ui_ops = |
659 { | |
660 gaim_gtk_connection_connect_progress, | |
661 gaim_gtk_connection_connected, | |
662 gaim_gtk_connection_disconnected, | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
663 gaim_gtk_connection_notice, |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
664 gaim_gtk_connection_report_disconnect |
5717 | 665 }; |
666 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
667 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
668 gaim_gtk_connections_get_ui_ops(void) |
5717 | 669 { |
670 return &conn_ui_ops; | |
671 } | |
672 | |
7912 | 673 /* |
674 * This function needs to be moved out of here once away messages are | |
675 * core/UI split. | |
676 */ | |
6216 | 677 void away_on_login(const char *mesg) |
5717 | 678 { |
679 GSList *awy = away_messages; | |
680 struct away_message *a, *message = NULL; | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
681 GaimGtkBuddyList *gtkblist; |
5717 | 682 |
683 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
684 | |
685 if (!gtkblist->window) { | |
686 return; | |
687 } | |
688 | |
6216 | 689 if (mesg == NULL) |
690 mesg = gaim_prefs_get_string("/core/away/default_message"); | |
691 while (awy) { | |
692 a = (struct away_message *)awy->data; | |
693 if (strcmp(a->name, mesg) == 0) { | |
694 message = a; | |
695 break; | |
5717 | 696 } |
6216 | 697 awy = awy->next; |
5717 | 698 } |
6216 | 699 if (message == NULL) { |
700 if(!away_messages) | |
701 return; | |
702 message = away_messages->data; | |
703 } | |
704 do_away_message(NULL, message); | |
5717 | 705 } |