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