Mercurial > pidgin.yaz
annotate src/gtkconn.c @ 8053:223f530321e2
[gaim-migrate @ 8738]
NEWS
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 10 Jan 2004 04:45:37 +0000 |
parents | fa6395637e2c |
children | 4c34db6996d1 |
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 { | |
8014 | 57 if(!meter->progress) |
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--; | |
8014 | 64 meter->progress = NULL; |
7912 | 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) { |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
82 destroy_all_dialogs(); |
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 gtk_widget_realize(meter_win->window); | |
206 | |
207 vbox = gtk_vbox_new (FALSE, 0); | |
208 gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
209 | |
210 meter_win->table = gtk_table_new(1, 4, FALSE); | |
211 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
212 FALSE, FALSE, 0); | |
213 gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
214 gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
215 gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
216 | |
217 cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
218 GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
219 g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
220 G_CALLBACK(cancel_all), NULL); | |
221 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
222 FALSE, FALSE, 0); | |
223 | |
224 g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
225 G_CALLBACK(meter_destroy), NULL); | |
226 } | |
227 | |
228 meter = find_signon_meter(gc); | |
229 if(!meter) { | |
230 meter = new_meter(gc, meter_win->window, meter_win->table, | |
231 &meter_win->rows); | |
232 | |
233 meter_win->meters = g_slist_append(meter_win->meters, meter); | |
234 } | |
235 | |
236 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
237 (float)step / (float)step_count); | |
238 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
239 } | |
240 | |
241 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
242 { | |
243 struct signon_meter *meter = find_signon_meter(gc); | |
244 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
245 gaim_setup(gc); |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
246 |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
247 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
248 gaim_gtk_blist_update_protocol_actions(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
249 |
7912 | 250 if (meter) |
5717 | 251 kill_meter(meter, _("Done.")); |
252 } | |
253 | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
254 static void gaim_gtk_connection_disconnected(GaimConnection *gc) |
5717 | 255 { |
256 struct signon_meter *meter = find_signon_meter(gc); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
257 |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
258 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
259 gaim_gtk_blist_update_protocol_actions(); |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
260 |
7912 | 261 if (meter) |
5717 | 262 kill_meter(meter, _("Done.")); |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
263 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
264 if (gaim_connections_get_all() != NULL) |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
265 return; |
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 destroy_all_dialogs(); |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
268 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
269 gaim_blist_destroy(); |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
270 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
271 show_login(); |
5717 | 272 } |
273 | |
274 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
275 const char *text) | |
276 { | |
277 } | |
278 | |
7912 | 279 /* |
280 * The next couple of functions deal with the disconnected dialog | |
281 */ | |
7399 | 282 struct disconnect_window { |
283 GtkWidget *window; | |
284 GtkWidget *treeview; | |
285 GtkWidget *sw; | |
286 GtkWidget *label; | |
7808 | 287 GtkWidget *reconnect_btn; |
7912 | 288 GtkWidget *reconnectall_btn; |
7399 | 289 }; |
290 struct disconnect_window *disconnect_window = NULL; | |
291 | |
7912 | 292 static void disconnect_connection_change_cb(GaimConnection *gc, void *data); |
293 | |
294 /* | |
295 * Destroy the dialog and remove the signals associated with it. | |
296 */ | |
7493 | 297 static void disconnect_window_hide() |
298 { | |
7912 | 299 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", |
300 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb)); | |
301 | |
302 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", | |
303 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb)); | |
304 | |
7493 | 305 gtk_widget_destroy(disconnect_window->window); |
306 g_free(disconnect_window); | |
307 disconnect_window = NULL; | |
308 } | |
309 | |
7912 | 310 /* |
311 * Make sure the Reconnect and Reconnect All buttons are correctly | |
312 * shown or hidden. Also make sure the label on the Reconnect | |
313 * button is correctly set to either Reconnect or Remove. If there | |
314 * is more than one account then make sure the GtkTreeView is shown. | |
315 * If there are no accounts disconnectd then hide the dialog. | |
316 */ | |
317 static void disconnect_window_update_buttons(GtkTreeModel *model) | |
318 { | |
319 GtkTreeIter iter; | |
320 GtkTreeSelection *sel; | |
321 const char *label_text; | |
322 GaimAccount *account = NULL; | |
323 | |
324 if ((disconnect_window == NULL) || (model == NULL)) | |
325 return; | |
326 | |
327 if (!gtk_tree_model_get_iter_first(model, &iter)) { | |
328 /* No more accounts being shown. Caloo calay! */ | |
329 disconnect_window_hide(); | |
330 return; | |
331 } | |
332 | |
333 /* | |
334 * If we have more than one disconnected account then show the | |
335 * GtkTreeView and the "Reconnect All" button | |
336 */ | |
337 if (gtk_tree_model_iter_next(model, &iter)) { | |
338 gtk_widget_show_all(disconnect_window->sw); | |
339 gtk_widget_show(disconnect_window->reconnectall_btn); | |
340 } else { | |
341 gtk_widget_hide_all(disconnect_window->sw); | |
342 gtk_widget_hide(disconnect_window->reconnectall_btn); | |
343 } | |
344 | |
345 /* | |
346 * Make sure one of the accounts is selected. | |
347 */ | |
348 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
349 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) { | |
350 gtk_tree_model_get_iter_first(model, &iter); | |
351 gtk_tree_selection_select_iter(sel, &iter); | |
352 } | |
353 | |
354 /* | |
355 * Update the Reconnect/Remove button appropriately and set the | |
356 * label in the dialog to what it should be. | |
357 */ | |
358 gtk_tree_model_get(model, &iter, 3, &label_text, 4, &account, -1); | |
359 gtk_button_set_label(GTK_BUTTON(disconnect_window->reconnect_btn), | |
360 gaim_account_is_connected(account) ? _("_Remove") : _("_Reconnect")); | |
361 gtk_label_set_markup(GTK_LABEL(disconnect_window->label), label_text); | |
362 gtk_dialog_set_response_sensitive(GTK_DIALOG(disconnect_window->window), GTK_RESPONSE_ACCEPT, TRUE); | |
363 } | |
364 | |
7399 | 365 static void disconnect_response_cb(GtkDialog *dialog, gint id, GtkWidget *widget) |
366 { | |
7483 | 367 GtkTreeIter iter; |
368 GtkTreeSelection *sel = NULL; | |
369 GtkTreeModel *model = NULL; | |
7431 | 370 GaimAccount *account = NULL; |
371 | |
7912 | 372 switch (id) { |
373 case GTK_RESPONSE_APPLY: /* Reconnect All */ | |
7808 | 374 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); |
375 if (gtk_tree_model_get_iter_first(model, &iter)) { | |
376 /* tree rows to be deleted */ | |
377 GList *l_del = NULL, *l_del_iter = NULL; | |
378 /* accounts to be connected */ | |
7912 | 379 GList *l_accts = NULL, *l_accts_iter = NULL; |
7808 | 380 do { |
381 GtkTreePath *path = gtk_tree_model_get_path(model, &iter); | |
382 GtkTreeRowReference* del_row = gtk_tree_row_reference_new(model, path); | |
383 l_del = g_list_append(l_del, del_row); | |
384 gtk_tree_path_free(path); | |
385 | |
386 gtk_tree_model_get(model, &iter, 4, &account, -1); | |
387 if (!gaim_account_is_connected(account) && g_list_find(l_accts, account) == NULL) | |
388 l_accts = g_list_append(l_accts, account); | |
389 } while (gtk_tree_model_iter_next(model, &iter)); | |
390 | |
391 /* remove all rows */ | |
7912 | 392 /* We could just do the following, but we only want to remove accounts |
393 * that are going to be reconnected, not accounts that have already | |
394 * been reconnected. | |
395 */ | |
396 /* gtk_list_store_clear(GTK_LIST_STORE(model)); */ | |
7808 | 397 l_del_iter = l_del; |
398 while (l_del_iter != NULL) { | |
399 GtkTreeRowReference* del_row = l_del_iter->data; | |
400 GtkTreePath *path = gtk_tree_row_reference_get_path(del_row); | |
401 if (gtk_tree_model_get_iter(model, &iter, path)) | |
402 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
403 gtk_tree_path_free(path); | |
404 gtk_tree_row_reference_free(del_row); | |
405 l_del_iter = l_del_iter->next; | |
406 } | |
407 g_list_free(l_del); | |
408 | |
409 /* reconnect disconnected accounts */ | |
410 l_accts_iter = l_accts; | |
411 while (l_accts_iter != NULL) { | |
412 account = l_accts_iter->data; | |
413 gaim_account_connect(account); | |
414 l_accts_iter = l_accts_iter->next; | |
415 } | |
416 g_list_free(l_accts); | |
417 | |
418 } | |
419 | |
7912 | 420 disconnect_window_update_buttons(model); |
421 | |
7808 | 422 break; |
7912 | 423 |
424 case GTK_RESPONSE_ACCEPT: /* Reconnect Selected */ | |
7483 | 425 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); |
7912 | 426 |
7483 | 427 /* |
428 * If we have more than one account disconnection displayed, then | |
429 * the scroll window is visible and we should use the selected | |
430 * account to reconnect. | |
431 */ | |
432 if (GTK_WIDGET_VISIBLE(disconnect_window->sw)) { | |
433 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
434 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) | |
435 return; | |
436 } else { | |
437 /* There is only one account disconnection, so reconnect to it. */ | |
438 if (!gtk_tree_model_get_iter_first(model, &iter)) | |
439 return; | |
440 } | |
7912 | 441 |
442 /* remove all disconnections of the account to be reconnected */ | |
7808 | 443 gtk_tree_model_get(model, &iter, 4, &account, -1); |
7637 | 444 if (gtk_tree_model_get_iter_first(model, &iter)) { |
7808 | 445 GList *l_del = NULL, *l_del_iter = NULL; |
7637 | 446 GaimAccount *account2 = NULL; |
447 do { | |
7808 | 448 gtk_tree_model_get(model, &iter, 4, &account2, -1); |
7637 | 449 if (account2 == account) { |
7643 | 450 GtkTreePath *path = gtk_tree_model_get_path(model, &iter); |
451 GtkTreeRowReference* del_row = gtk_tree_row_reference_new(model, path); | |
452 l_del = g_list_append(l_del, del_row); | |
7808 | 453 gtk_tree_path_free(path); |
7637 | 454 } |
7643 | 455 } while (gtk_tree_model_iter_next(model, &iter)); |
456 | |
7808 | 457 l_del_iter = l_del; |
458 while (l_del_iter != NULL) { | |
459 GtkTreeRowReference* del_row = l_del_iter->data; | |
7643 | 460 GtkTreePath *path = gtk_tree_row_reference_get_path(del_row); |
461 if (gtk_tree_model_get_iter(model, &iter, path)) | |
462 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
7808 | 463 gtk_tree_path_free(path); |
464 gtk_tree_row_reference_free(del_row); | |
465 l_del_iter = l_del_iter->next; | |
7643 | 466 } |
7808 | 467 g_list_free(l_del); |
7637 | 468 } |
469 | |
7643 | 470 gaim_account_connect(account); |
7912 | 471 disconnect_window_update_buttons(model); |
7643 | 472 |
7399 | 473 break; |
7912 | 474 |
475 case GTK_RESPONSE_DELETE_EVENT: | |
476 case GTK_RESPONSE_CLOSE: | |
477 disconnect_window_hide(); | |
478 break; | |
479 | |
7399 | 480 } |
481 } | |
482 | |
7912 | 483 /* |
484 * Called whenever a different account is selected in the GtkListWhatever. | |
485 */ | |
7399 | 486 static void disconnect_tree_cb(GtkTreeSelection *sel, GtkTreeModel *model) |
487 { | |
7912 | 488 disconnect_window_update_buttons(model); |
7399 | 489 } |
490 | |
7912 | 491 /* |
492 * Update the icon next to the account in the disconnect dialog, and | |
493 * gray the Reconnect All button if there is only 1 disconnected account. | |
494 */ | |
7808 | 495 static void disconnect_connection_change_cb(GaimConnection *gc, void *data) { |
7912 | 496 GaimAccount *account = gaim_connection_get_account(gc); |
497 GtkTreeIter iter; | |
498 GtkTreeModel *model; | |
499 GdkPixbuf *icon; | |
500 GdkPixbuf *scale; | |
501 GList *l_disc_accts = NULL; | |
502 | |
503 if (disconnect_window == NULL) | |
504 return; | |
505 | |
506 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); | |
507 icon = create_prpl_icon(account); | |
508 scale = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); | |
509 | |
510 /* Mark all disconnections w/ the account type disconnected /w grey icon */ | |
511 if (!gaim_account_is_connected(account)) | |
512 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); | |
513 | |
514 gtk_tree_model_get_iter_first(model, &iter); | |
515 do { | |
516 GaimAccount *account2 = NULL; | |
517 /* Gray out the icon if this row is for this account */ | |
518 gtk_tree_model_get(model, &iter, 4, &account2, -1); | |
519 if (account2 == account) | |
520 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, scale, -1); | |
521 | |
522 /* Add */ | |
523 if (!gaim_account_is_connected(account2) | |
7808 | 524 && g_list_find(l_disc_accts, account2) == NULL) |
7912 | 525 l_disc_accts = g_list_append(l_disc_accts, account2); |
526 } while (gtk_tree_model_iter_next(model, &iter)); | |
7808 | 527 |
7912 | 528 gtk_dialog_set_response_sensitive( |
529 GTK_DIALOG(disconnect_window->window), | |
530 GTK_RESPONSE_APPLY, | |
531 g_list_length(l_disc_accts) > 1); | |
532 g_list_free(l_disc_accts); | |
533 | |
534 if (icon != NULL) | |
535 g_object_unref(G_OBJECT(icon)); | |
536 if (scale != NULL) | |
537 g_object_unref(G_OBJECT(scale)); | |
538 | |
539 disconnect_window_update_buttons(model); | |
7625 | 540 } |
7399 | 541 |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
542 static void |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
543 gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
544 { |
7399 | 545 char *label_text = NULL; |
7912 | 546 GtkTreeIter new_iter; |
7506 | 547 GtkListStore *list_store; |
548 GtkTreeViewColumn *col; | |
549 GtkTreeSelection *sel = NULL; | |
7399 | 550 |
7648 | 551 label_text = g_strdup_printf(_("<span weight=\"bold\" size=\"larger\">%s has been disconnected.</span>\n\n%s\n%s"), |
7912 | 552 gaim_account_get_username(gaim_connection_get_account(gc)), gaim_date_full(), |
7399 | 553 text ? text : _("Reason Unknown.")); |
7496 | 554 |
7506 | 555 /* Build the window if it isn't there yet */ |
556 if (!disconnect_window) { | |
7399 | 557 GtkWidget *hbox, *vbox, *img; |
558 GtkCellRenderer *rend, *rend2; | |
7496 | 559 |
7407 | 560 disconnect_window = g_new0(struct disconnect_window, 1); |
7874 | 561 disconnect_window->window = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, NULL, GTK_DIALOG_NO_SEPARATOR, NULL); |
7399 | 562 g_signal_connect(G_OBJECT(disconnect_window->window), "response", G_CALLBACK(disconnect_response_cb), disconnect_window); |
563 | |
564 gtk_container_set_border_width(GTK_CONTAINER(disconnect_window->window), 6); | |
565 gtk_window_set_resizable(GTK_WINDOW(disconnect_window->window), FALSE); | |
566 gtk_dialog_set_has_separator(GTK_DIALOG(disconnect_window->window), FALSE); | |
567 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(disconnect_window->window)->vbox), 12); | |
568 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), 6); | |
569 | |
570 hbox = gtk_hbox_new(FALSE, 12); | |
571 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), hbox); | |
572 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); | |
573 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
574 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
7496 | 575 |
7399 | 576 vbox = gtk_vbox_new(FALSE, 12); |
577 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
578 | |
7506 | 579 disconnect_window->label = gtk_label_new(label_text); |
7496 | 580 |
7399 | 581 gtk_label_set_line_wrap(GTK_LABEL(disconnect_window->label), TRUE); |
582 gtk_misc_set_alignment(GTK_MISC(disconnect_window->label), 0, 0); | |
583 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->label, FALSE, FALSE, 0); | |
584 | |
7808 | 585 disconnect_window->reconnect_btn = gtk_dialog_add_button( |
586 GTK_DIALOG(disconnect_window->window), | |
587 _("_Reconnect"), | |
588 GTK_RESPONSE_ACCEPT); | |
589 | |
7912 | 590 disconnect_window->reconnectall_btn = gtk_dialog_add_button( |
7808 | 591 GTK_DIALOG(disconnect_window->window), |
592 _("Reconnect _All"), | |
593 GTK_RESPONSE_APPLY); | |
594 | |
7874 | 595 gtk_dialog_add_button( |
596 GTK_DIALOG(disconnect_window->window), | |
597 GTK_STOCK_CLOSE, | |
598 GTK_RESPONSE_CLOSE); | |
599 | |
7399 | 600 gtk_widget_show_all(disconnect_window->window); |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
601 |
7399 | 602 /* Tree View */ |
603 disconnect_window->sw = gtk_scrolled_window_new(NULL,NULL); | |
7912 | 604 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_SHADOW_IN); |
605 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
7399 | 606 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->sw, TRUE, TRUE, 0); |
7496 | 607 |
7912 | 608 list_store = gtk_list_store_new(5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); |
609 disconnect_window->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store)); | |
7496 | 610 |
7399 | 611 rend = gtk_cell_renderer_pixbuf_new(); |
612 rend2 = gtk_cell_renderer_text_new(); | |
613 col = gtk_tree_view_column_new(); | |
614 gtk_tree_view_column_set_title(col, _("Account")); | |
615 gtk_tree_view_column_pack_start(col, rend, FALSE); | |
616 gtk_tree_view_column_pack_start(col, rend2, FALSE); | |
617 gtk_tree_view_column_set_attributes(col, rend, "pixbuf", 0, NULL); | |
618 gtk_tree_view_column_set_attributes(col, rend2, "text", 1, NULL); | |
619 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
7496 | 620 |
7399 | 621 rend = gtk_cell_renderer_text_new(); |
622 col = gtk_tree_view_column_new_with_attributes (_("Time"), | |
623 rend, "text", 2, NULL); | |
624 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
7637 | 625 |
7399 | 626 g_object_unref(G_OBJECT(list_store)); |
627 gtk_container_add(GTK_CONTAINER(disconnect_window->sw), disconnect_window->treeview); | |
7496 | 628 |
7399 | 629 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
|
630 gtk_widget_set_size_request(disconnect_window->treeview, -1, 96); |
7399 | 631 g_signal_connect (G_OBJECT (sel), "changed", |
632 G_CALLBACK (disconnect_tree_cb), list_store); | |
7625 | 633 |
634 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
7808 | 635 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb), NULL); |
636 | |
637 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | |
638 disconnect_window, GAIM_CALLBACK(disconnect_connection_change_cb), NULL); | |
7506 | 639 } else |
640 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview))); | |
641 | |
642 /* Add this account to our list of disconnected accounts */ | |
7912 | 643 gtk_list_store_append(list_store, &new_iter); |
644 gtk_list_store_set(list_store, &new_iter, | |
7808 | 645 0, NULL, |
7506 | 646 1, gaim_account_get_username(gaim_connection_get_account(gc)), |
647 2, gaim_date_full(), | |
648 3, label_text, | |
649 4, gaim_connection_get_account(gc), -1); | |
650 | |
7912 | 651 /* Make sure the newly disconnected account is selected */ |
652 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
653 gtk_tree_selection_select_iter(sel, &new_iter); | |
654 | |
655 disconnect_window_update_buttons(GTK_TREE_MODEL(list_store)); | |
7496 | 656 |
7399 | 657 g_free(label_text); |
7493 | 658 gtk_window_present(GTK_WINDOW(disconnect_window->window)); |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
659 } |
7912 | 660 /* |
661 * End of disconnected dialog | |
662 */ | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
663 |
5717 | 664 static GaimConnectionUiOps conn_ui_ops = |
665 { | |
666 gaim_gtk_connection_connect_progress, | |
667 gaim_gtk_connection_connected, | |
668 gaim_gtk_connection_disconnected, | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
669 gaim_gtk_connection_notice, |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
670 gaim_gtk_connection_report_disconnect |
5717 | 671 }; |
672 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
673 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
674 gaim_gtk_connections_get_ui_ops(void) |
5717 | 675 { |
676 return &conn_ui_ops; | |
677 } | |
678 | |
7912 | 679 /* |
680 * This function needs to be moved out of here once away messages are | |
681 * core/UI split. | |
682 */ | |
6216 | 683 void away_on_login(const char *mesg) |
5717 | 684 { |
685 GSList *awy = away_messages; | |
686 struct away_message *a, *message = NULL; | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
687 GaimGtkBuddyList *gtkblist; |
5717 | 688 |
689 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
690 | |
691 if (!gtkblist->window) { | |
692 return; | |
693 } | |
694 | |
6216 | 695 if (mesg == NULL) |
696 mesg = gaim_prefs_get_string("/core/away/default_message"); | |
697 while (awy) { | |
698 a = (struct away_message *)awy->data; | |
699 if (strcmp(a->name, mesg) == 0) { | |
700 message = a; | |
701 break; | |
5717 | 702 } |
6216 | 703 awy = awy->next; |
5717 | 704 } |
6216 | 705 if (message == NULL) { |
706 if(!away_messages) | |
707 return; | |
708 message = away_messages->data; | |
709 } | |
710 do_away_message(NULL, message); | |
5717 | 711 } |