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