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