Mercurial > pidgin.yaz
annotate src/gtkconn.c @ 5996:7711ef5338a0
[gaim-migrate @ 6444]
Two aborts() in a row is a bit pointless, isn't it? Thanks faceprint.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 02 Jul 2003 21:37:12 +0000 |
parents | 5d5bad909bc4 |
children | d2d5d1984b09 |
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 * | |
20 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
21 #include "internal.h" |
5717 | 22 |
23 #include "account.h" | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
24 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
25 #include "notify.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
26 #include "util.h" |
5717 | 27 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
28 #include "gtkblist.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
29 #include "gtkutils.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
30 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
31 #include "ui.h" |
5717 | 32 |
33 struct signon_meter { | |
34 GaimAccount *account; | |
35 GtkWidget *button; | |
36 GtkWidget *progress; | |
37 GtkWidget *status; | |
38 }; | |
39 | |
40 struct meter_window { | |
41 GtkWidget *window; | |
42 GtkWidget *table; | |
43 gint rows; | |
44 gint active_count; | |
45 GSList *meters; | |
46 } *meter_win = NULL; | |
47 | |
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
48 static void kill_meter(struct signon_meter *meter, const char *text); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
49 |
5717 | 50 static void cancel_signon(GtkWidget *button, struct signon_meter *meter) |
51 { | |
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
52 if (meter->account->gc != NULL) { |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
53 meter->account->gc->wants_to_die = TRUE; |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
54 gaim_connection_destroy(meter->account->gc); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
55 } |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
56 else { |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
57 kill_meter(meter, _("Done.")); |
5987
6e19ad2ef712
[gaim-migrate @ 6435]
Christian Hammond <chipx86@chipx86.com>
parents:
5936
diff
changeset
|
58 |
5991
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
59 if (gaim_connections_get_all() == NULL) { |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
60 destroy_all_dialogs(); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
61 |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
62 gaim_blist_destroy(); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
63 |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
64 show_login(); |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
65 } |
5d5bad909bc4
[gaim-migrate @ 6439]
Christian Hammond <chipx86@chipx86.com>
parents:
5989
diff
changeset
|
66 } |
5717 | 67 } |
68 | |
69 static void cancel_all () { | |
70 GSList *m = meter_win ? meter_win->meters : NULL; | |
71 | |
72 while (m) { | |
73 cancel_signon(NULL, m->data); | |
74 m = meter_win ? meter_win->meters : NULL; | |
75 } | |
76 } | |
77 | |
78 static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) | |
79 { | |
80 return TRUE; | |
81 } | |
82 | |
83 static struct signon_meter *find_signon_meter(GaimConnection *gc) | |
84 { | |
85 GSList *m = meter_win ? meter_win->meters : NULL; | |
86 | |
87 while (m) { | |
88 if (((struct signon_meter *)m->data)->account == gc->account) | |
89 return m->data; | |
90 m = m->next; | |
91 } | |
92 | |
93 return NULL; | |
94 } | |
95 | |
96 static GtkWidget* create_meter_pixmap (GaimConnection *gc) | |
97 { | |
98 GdkPixbuf *pb = create_prpl_icon(gc->account); | |
99 GdkPixbuf *scale = gdk_pixbuf_scale_simple(pb, 30,30,GDK_INTERP_BILINEAR); | |
100 GtkWidget *image = | |
101 gtk_image_new_from_pixbuf(scale); | |
102 g_object_unref(G_OBJECT(pb)); | |
103 g_object_unref(G_OBJECT(scale)); | |
104 return image; | |
105 } | |
106 | |
107 | |
108 | |
109 static struct signon_meter * | |
110 new_meter(GaimConnection *gc, GtkWidget *widget, | |
111 GtkWidget *table, gint *rows) | |
112 { | |
113 GtkWidget *graphic; | |
114 GtkWidget *label; | |
115 GtkWidget *nest_vbox; | |
116 GString *name_to_print; | |
117 struct signon_meter *meter; | |
118 | |
119 | |
120 meter = g_new0(struct signon_meter, 1); | |
121 | |
122 meter->account = gaim_connection_get_account(gc); | |
123 name_to_print = g_string_new(gaim_account_get_username(meter->account)); | |
124 | |
125 (*rows)++; | |
126 gtk_table_resize (GTK_TABLE(table), *rows, 4); | |
127 | |
128 graphic = create_meter_pixmap(gc); | |
129 | |
130 nest_vbox = gtk_vbox_new (FALSE, 0); | |
131 | |
132 g_string_prepend(name_to_print, _("Signon: ")); | |
133 label = gtk_label_new (name_to_print->str); | |
134 g_string_free(name_to_print, TRUE); | |
135 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); | |
136 | |
137 meter->status = gtk_label_new(""); | |
138 gtk_misc_set_alignment(GTK_MISC(meter->status), 0, 0.5); | |
139 gtk_widget_set_size_request(meter->status, 250, -1); | |
140 | |
141 meter->progress = gtk_progress_bar_new (); | |
142 | |
143 meter->button = gaim_pixbuf_button_from_stock (_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
144 g_signal_connect(G_OBJECT (meter->button), "clicked", | |
145 G_CALLBACK (cancel_signon), meter); | |
146 | |
147 gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
148 gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
149 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0); | |
150 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0); | |
151 gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
152 gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
153 | |
154 gtk_widget_show_all (GTK_WIDGET (meter_win->window)); | |
155 | |
156 meter_win->active_count++; | |
157 | |
158 return meter; | |
159 } | |
160 | |
161 static void kill_meter(struct signon_meter *meter, const char *text) { | |
162 gtk_widget_set_sensitive (meter->button, FALSE); | |
163 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), 1); | |
164 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
165 meter_win->active_count--; | |
166 if (meter_win->active_count == 0) { | |
167 gtk_widget_destroy(meter_win->window); | |
168 g_free (meter_win); | |
169 meter_win = NULL; | |
170 } | |
171 } | |
172 | |
173 static void gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
174 const char *text, size_t step, size_t step_count) | |
175 { | |
176 struct signon_meter *meter; | |
177 | |
178 if(!meter_win) { | |
179 GtkWidget *vbox; | |
180 GtkWidget *cancel_button; | |
181 | |
182 if(mainwindow) | |
183 gtk_widget_hide(mainwindow); | |
184 | |
185 meter_win = g_new0(struct meter_window, 1); | |
186 meter_win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
187 gtk_window_set_resizable(GTK_WINDOW(meter_win->window), FALSE); | |
188 gtk_window_set_role(GTK_WINDOW(meter_win->window), "signon"); | |
189 gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5); | |
190 gtk_window_set_title(GTK_WINDOW(meter_win->window), _("Signon")); | |
191 gtk_widget_realize(meter_win->window); | |
192 | |
193 vbox = gtk_vbox_new (FALSE, 0); | |
194 gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
195 | |
196 meter_win->table = gtk_table_new(1, 4, FALSE); | |
197 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
198 FALSE, FALSE, 0); | |
199 gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
200 gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
201 gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
202 | |
203 cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
204 GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
205 g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
206 G_CALLBACK(cancel_all), NULL); | |
207 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
208 FALSE, FALSE, 0); | |
209 | |
210 g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
211 G_CALLBACK(meter_destroy), NULL); | |
212 } | |
213 | |
214 meter = find_signon_meter(gc); | |
215 if(!meter) { | |
216 meter = new_meter(gc, meter_win->window, meter_win->table, | |
217 &meter_win->rows); | |
218 | |
219 meter_win->meters = g_slist_append(meter_win->meters, meter); | |
220 } | |
221 | |
222 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
223 (float)step / (float)step_count); | |
224 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
225 } | |
226 | |
227 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
228 { | |
229 struct signon_meter *meter = find_signon_meter(gc); | |
230 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
231 gaim_setup(gc); |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
232 |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
233 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
234 gaim_gtk_blist_update_protocol_actions(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
235 |
5717 | 236 if(meter) |
237 kill_meter(meter, _("Done.")); | |
238 } | |
239 | |
240 static void gaim_gtk_connection_request_pass(GaimConnection *gc) | |
241 { | |
242 } | |
243 | |
244 static void gaim_gtk_connection_disconnected(GaimConnection *gc, | |
245 const char *reason) | |
246 { | |
247 struct signon_meter *meter = find_signon_meter(gc); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
248 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
249 update_privacy_connections(); |
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 | |
271 static GaimConnectionUiOps conn_ui_ops = | |
272 { | |
273 gaim_gtk_connection_connect_progress, | |
274 gaim_gtk_connection_connected, | |
275 gaim_gtk_connection_request_pass, | |
276 gaim_gtk_connection_disconnected, | |
277 gaim_gtk_connection_notice | |
278 }; | |
279 | |
280 GaimConnectionUiOps *gaim_get_gtk_connection_ui_ops(void) | |
281 { | |
282 return &conn_ui_ops; | |
283 } | |
284 | |
285 | |
5746
2c04c55222b7
[gaim-migrate @ 6171]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5717
diff
changeset
|
286 void away_on_login(char *mesg) |
5717 | 287 { |
288 GSList *awy = away_messages; | |
289 struct away_message *a, *message = NULL; | |
290 struct gaim_gtk_buddy_list *gtkblist; | |
291 | |
292 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
293 | |
294 if (!gtkblist->window) { | |
295 return; | |
296 } | |
297 | |
298 if (mesg == NULL) { | |
299 /* Use default message */ | |
300 do_away_message(NULL, default_away); | |
301 } else { | |
302 /* Use argument */ | |
303 while (awy) { | |
304 a = (struct away_message *)awy->data; | |
305 if (strcmp(a->name, mesg) == 0) { | |
306 message = a; | |
307 break; | |
308 } | |
309 awy = awy->next; | |
310 } | |
311 if (message == NULL) | |
312 message = default_away; | |
313 do_away_message(NULL, message); | |
314 } | |
315 return; | |
316 } | |
317 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
318 #if 0 |
5717 | 319 struct kick_dlg { |
320 GaimAccount *account; | |
321 GtkWidget *dlg; | |
322 }; | |
323 static GSList *kicks = NULL; | |
324 | |
325 static struct kick_dlg *find_kick_dlg(GaimAccount *account) | |
326 { | |
327 GSList *k = kicks; | |
328 while (k) { | |
329 struct kick_dlg *d = k->data; | |
330 if (d->account == account) | |
331 return d; | |
332 k = k->next; | |
333 } | |
334 return NULL; | |
335 } | |
336 | |
337 static void set_kick_null(struct kick_dlg *k) | |
338 { | |
339 kicks = g_slist_remove(kicks, k); | |
340 g_free(k); | |
341 } | |
342 | |
343 /* | |
344 * Common code for hide_login_progress(), and hide_login_progress_info() | |
345 */ | |
346 static void hide_login_progress_common(GaimConnection *gc, | |
347 char *details, | |
348 char *title, | |
349 char *prologue) | |
350 { | |
351 gchar *buf; | |
352 struct kick_dlg *k = find_kick_dlg(gc->account); | |
353 struct signon_meter *meter = find_signon_meter(gc); | |
354 buf = g_strdup_printf(_("%s\n%s: %s"), full_date(), prologue, details); | |
355 if (k) | |
356 gtk_widget_destroy(k->dlg); | |
357 k = g_new0(struct kick_dlg, 1); | |
358 k->account = gc->account; | |
359 k->dlg = gaim_notify_message(NULL, GAIM_NOTIFY_MSG_ERROR, NULL, | |
360 title, buf, G_CALLBACK(set_kick_null), k); | |
361 kicks = g_slist_append(kicks, k); | |
362 if (meter) { | |
363 kill_meter(meter, _("Done.")); | |
364 meter_win->meters = g_slist_remove(meter_win->meters, meter); | |
365 g_free(meter); | |
366 } | |
367 g_free(buf); | |
368 } | |
369 | |
370 static void hide_login_progress(GaimConnection *gc, char *why) | |
371 { | |
372 GaimAccount *account = gaim_connection_get_account(gc); | |
373 gchar *buf; | |
374 | |
375 gaim_event_broadcast(event_error, gc, why); | |
376 buf = g_strdup_printf(_("%s was unable to sign on"), | |
377 gaim_account_get_username(account)); | |
378 hide_login_progress_common(gc, why, _("Signon Error"), buf); | |
379 g_free(buf); | |
380 } | |
381 | |
382 /* | |
383 * Like hide_login_progress(), but for informational, not error/warning, | |
384 * messages. | |
385 * | |
386 */ | |
387 static void hide_login_progress_notice(GaimConnection *gc, char *why) | |
388 { | |
389 GaimAccount *account = gaim_connection_get_account(gc); | |
390 | |
391 hide_login_progress_common(gc, why, _("Notice"), | |
392 (char *)gaim_account_get_username(account)); | |
393 } | |
394 | |
395 /* | |
396 * Like hide_login_progress(), but for non-signon error messages. | |
397 * | |
398 */ | |
399 static void hide_login_progress_error(GaimConnection *gc, char *why) | |
400 { | |
401 char buf[2048]; | |
402 GaimAccount *account = gaim_connection_get_account(gc); | |
403 | |
404 gaim_event_broadcast(event_error, gc, why); | |
405 g_snprintf(buf, sizeof(buf), _("%s has been signed off"), | |
406 gaim_account_get_username(account)); | |
407 hide_login_progress_common(gc, why, _("Connection Error"), buf); | |
408 } | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5746
diff
changeset
|
409 #endif |