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