Mercurial > pidgin
annotate src/gtkconn.c @ 6304:2567032a7430
[gaim-migrate @ 6803]
*twitch*
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 25 Jul 2003 14:23:08 +0000 |
parents | dc42b27101c0 |
children | 8f94cce8faa5 |
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" |
6216 | 25 #include "prefs.h" |
5872
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; | |
6114 | 71 struct signon_meter *meter; |
5717 | 72 |
73 while (m) { | |
6114 | 74 meter = m->data; |
75 cancel_signon(NULL, meter); | |
76 m = m->next; | |
5717 | 77 } |
78 } | |
79 | |
80 static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) | |
81 { | |
82 return TRUE; | |
83 } | |
84 | |
85 static struct signon_meter *find_signon_meter(GaimConnection *gc) | |
86 { | |
87 GSList *m = meter_win ? meter_win->meters : NULL; | |
6114 | 88 struct signon_meter *meter; |
5717 | 89 |
90 while (m) { | |
6114 | 91 meter = m->data; |
92 if (meter->account == gaim_connection_get_account(gc)) | |
5717 | 93 return m->data; |
94 m = m->next; | |
95 } | |
96 | |
97 return NULL; | |
98 } | |
99 | |
100 static GtkWidget* create_meter_pixmap (GaimConnection *gc) | |
101 { | |
102 GdkPixbuf *pb = create_prpl_icon(gc->account); | |
103 GdkPixbuf *scale = gdk_pixbuf_scale_simple(pb, 30,30,GDK_INTERP_BILINEAR); | |
104 GtkWidget *image = | |
105 gtk_image_new_from_pixbuf(scale); | |
106 g_object_unref(G_OBJECT(pb)); | |
107 g_object_unref(G_OBJECT(scale)); | |
108 return image; | |
109 } | |
110 | |
111 | |
112 | |
113 static struct signon_meter * | |
114 new_meter(GaimConnection *gc, GtkWidget *widget, | |
115 GtkWidget *table, gint *rows) | |
116 { | |
117 GtkWidget *graphic; | |
118 GtkWidget *label; | |
119 GtkWidget *nest_vbox; | |
120 GString *name_to_print; | |
121 struct signon_meter *meter; | |
122 | |
123 | |
124 meter = g_new0(struct signon_meter, 1); | |
125 | |
126 meter->account = gaim_connection_get_account(gc); | |
127 name_to_print = g_string_new(gaim_account_get_username(meter->account)); | |
128 | |
129 (*rows)++; | |
130 gtk_table_resize (GTK_TABLE(table), *rows, 4); | |
131 | |
132 graphic = create_meter_pixmap(gc); | |
133 | |
134 nest_vbox = gtk_vbox_new (FALSE, 0); | |
135 | |
136 g_string_prepend(name_to_print, _("Signon: ")); | |
137 label = gtk_label_new (name_to_print->str); | |
138 g_string_free(name_to_print, TRUE); | |
139 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); | |
140 | |
141 meter->status = gtk_label_new(""); | |
142 gtk_misc_set_alignment(GTK_MISC(meter->status), 0, 0.5); | |
143 gtk_widget_set_size_request(meter->status, 250, -1); | |
144 | |
145 meter->progress = gtk_progress_bar_new (); | |
146 | |
147 meter->button = gaim_pixbuf_button_from_stock (_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
148 g_signal_connect(G_OBJECT (meter->button), "clicked", | |
149 G_CALLBACK (cancel_signon), meter); | |
150 | |
151 gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
152 gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
153 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0); | |
154 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0); | |
155 gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
156 gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
157 | |
158 gtk_widget_show_all (GTK_WIDGET (meter_win->window)); | |
159 | |
160 meter_win->active_count++; | |
161 | |
162 return meter; | |
163 } | |
164 | |
165 static void kill_meter(struct signon_meter *meter, const char *text) { | |
166 gtk_widget_set_sensitive (meter->button, FALSE); | |
167 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), 1); | |
168 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
169 meter_win->active_count--; | |
170 if (meter_win->active_count == 0) { | |
171 gtk_widget_destroy(meter_win->window); | |
172 g_free (meter_win); | |
173 meter_win = NULL; | |
174 } | |
175 } | |
176 | |
177 static void gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
178 const char *text, size_t step, size_t step_count) | |
179 { | |
180 struct signon_meter *meter; | |
181 | |
182 if(!meter_win) { | |
183 GtkWidget *vbox; | |
184 GtkWidget *cancel_button; | |
185 | |
186 if(mainwindow) | |
187 gtk_widget_hide(mainwindow); | |
188 | |
189 meter_win = g_new0(struct meter_window, 1); | |
190 meter_win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
191 gtk_window_set_resizable(GTK_WINDOW(meter_win->window), FALSE); | |
192 gtk_window_set_role(GTK_WINDOW(meter_win->window), "signon"); | |
193 gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5); | |
194 gtk_window_set_title(GTK_WINDOW(meter_win->window), _("Signon")); | |
195 gtk_widget_realize(meter_win->window); | |
196 | |
197 vbox = gtk_vbox_new (FALSE, 0); | |
198 gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
199 | |
200 meter_win->table = gtk_table_new(1, 4, FALSE); | |
201 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
202 FALSE, FALSE, 0); | |
203 gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
204 gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
205 gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
206 | |
207 cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
208 GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
209 g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
210 G_CALLBACK(cancel_all), NULL); | |
211 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
212 FALSE, FALSE, 0); | |
213 | |
214 g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
215 G_CALLBACK(meter_destroy), NULL); | |
216 } | |
217 | |
218 meter = find_signon_meter(gc); | |
219 if(!meter) { | |
220 meter = new_meter(gc, meter_win->window, meter_win->table, | |
221 &meter_win->rows); | |
222 | |
223 meter_win->meters = g_slist_append(meter_win->meters, meter); | |
224 } | |
225 | |
226 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
227 (float)step / (float)step_count); | |
228 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
229 } | |
230 | |
231 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
232 { | |
233 struct signon_meter *meter = find_signon_meter(gc); | |
234 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
235 gaim_setup(gc); |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
236 |
6021 | 237 update_privacy_connections(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
238 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
239 gaim_gtk_blist_update_protocol_actions(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
240 |
5717 | 241 if(meter) |
242 kill_meter(meter, _("Done.")); | |
243 } | |
244 | |
245 static void gaim_gtk_connection_disconnected(GaimConnection *gc, | |
246 const char *reason) | |
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 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
250 update_privacy_connections(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
251 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
252 gaim_gtk_blist_update_protocol_actions(); |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
253 |
5717 | 254 if(meter) |
255 kill_meter(meter, _("Done.")); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
256 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
257 if (gaim_connections_get_all() != NULL) |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
258 return; |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
259 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
260 destroy_all_dialogs(); |
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 gaim_blist_destroy(); |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
263 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
264 show_login(); |
5717 | 265 } |
266 | |
267 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
268 const char *text) | |
269 { | |
270 } | |
271 | |
272 static GaimConnectionUiOps conn_ui_ops = | |
273 { | |
274 gaim_gtk_connection_connect_progress, | |
275 gaim_gtk_connection_connected, | |
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 | |
6216 | 286 void away_on_login(const 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 | |
6216 | 298 if (mesg == NULL) |
299 mesg = gaim_prefs_get_string("/core/away/default_message"); | |
300 while (awy) { | |
301 a = (struct away_message *)awy->data; | |
302 if (strcmp(a->name, mesg) == 0) { | |
303 message = a; | |
304 break; | |
5717 | 305 } |
6216 | 306 awy = awy->next; |
5717 | 307 } |
6216 | 308 if (message == NULL) { |
309 if(!away_messages) | |
310 return; | |
311 message = away_messages->data; | |
312 } | |
313 do_away_message(NULL, message); | |
5717 | 314 } |