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