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