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