Mercurial > pidgin
annotate src/gtkconn.c @ 7693:1d0314b99747
[gaim-migrate @ 8338]
this doesn't seem to crash, so I figured I'd put it in
get rid of the gaim_{buddy,chat,group}_{get,set}_setting() functions and
replace them with gaim_blist_node_{get,set}_{bool,int,string} so we can have
types, and clean up the code, all at the same time.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 02 Dec 2003 07:08:02 +0000 |
parents | cf6a7939af78 |
children | 4707d8436806 |
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; |
76 cancel_signon(NULL, meter); | |
77 m = m->next; | |
5717 | 78 } |
79 } | |
80 | |
81 static gint meter_destroy(GtkWidget *window, GdkEvent *evt, struct signon_meter *meter) | |
82 { | |
83 return TRUE; | |
84 } | |
85 | |
86 static struct signon_meter *find_signon_meter(GaimConnection *gc) | |
87 { | |
88 GSList *m = meter_win ? meter_win->meters : NULL; | |
6114 | 89 struct signon_meter *meter; |
5717 | 90 |
91 while (m) { | |
6114 | 92 meter = m->data; |
93 if (meter->account == gaim_connection_get_account(gc)) | |
5717 | 94 return m->data; |
95 m = m->next; | |
96 } | |
97 | |
98 return NULL; | |
99 } | |
100 | |
101 static GtkWidget* create_meter_pixmap (GaimConnection *gc) | |
102 { | |
103 GdkPixbuf *pb = create_prpl_icon(gc->account); | |
104 GdkPixbuf *scale = gdk_pixbuf_scale_simple(pb, 30,30,GDK_INTERP_BILINEAR); | |
105 GtkWidget *image = | |
106 gtk_image_new_from_pixbuf(scale); | |
107 g_object_unref(G_OBJECT(pb)); | |
108 g_object_unref(G_OBJECT(scale)); | |
109 return image; | |
110 } | |
111 | |
112 | |
113 | |
114 static struct signon_meter * | |
115 new_meter(GaimConnection *gc, GtkWidget *widget, | |
116 GtkWidget *table, gint *rows) | |
117 { | |
118 GtkWidget *graphic; | |
119 GtkWidget *label; | |
120 GtkWidget *nest_vbox; | |
121 GString *name_to_print; | |
122 struct signon_meter *meter; | |
123 | |
124 | |
125 meter = g_new0(struct signon_meter, 1); | |
126 | |
127 meter->account = gaim_connection_get_account(gc); | |
128 name_to_print = g_string_new(gaim_account_get_username(meter->account)); | |
129 | |
130 (*rows)++; | |
131 gtk_table_resize (GTK_TABLE(table), *rows, 4); | |
132 | |
133 graphic = create_meter_pixmap(gc); | |
134 | |
135 nest_vbox = gtk_vbox_new (FALSE, 0); | |
136 | |
137 g_string_prepend(name_to_print, _("Signon: ")); | |
138 label = gtk_label_new (name_to_print->str); | |
139 g_string_free(name_to_print, TRUE); | |
140 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); | |
141 | |
142 meter->status = gtk_label_new(""); | |
143 gtk_misc_set_alignment(GTK_MISC(meter->status), 0, 0.5); | |
144 gtk_widget_set_size_request(meter->status, 250, -1); | |
145 | |
146 meter->progress = gtk_progress_bar_new (); | |
147 | |
148 meter->button = gaim_pixbuf_button_from_stock (_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
149 g_signal_connect(G_OBJECT (meter->button), "clicked", | |
150 G_CALLBACK (cancel_signon), meter); | |
151 | |
152 gtk_table_attach (GTK_TABLE (table), graphic, 0, 1, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
153 gtk_table_attach (GTK_TABLE (table), nest_vbox, 1, 2, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
154 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (label), FALSE, FALSE, 0); | |
155 gtk_box_pack_start (GTK_BOX (nest_vbox), GTK_WIDGET (meter->status), FALSE, FALSE, 0); | |
156 gtk_table_attach (GTK_TABLE (table), meter->progress, 2, 3, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
157 gtk_table_attach (GTK_TABLE (table), meter->button, 3, 4, *rows, *rows+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); | |
158 | |
159 gtk_widget_show_all (GTK_WIDGET (meter_win->window)); | |
160 | |
161 meter_win->active_count++; | |
162 | |
163 return meter; | |
164 } | |
165 | |
166 static void kill_meter(struct signon_meter *meter, const char *text) { | |
167 gtk_widget_set_sensitive (meter->button, FALSE); | |
168 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), 1); | |
169 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
170 meter_win->active_count--; | |
171 if (meter_win->active_count == 0) { | |
172 gtk_widget_destroy(meter_win->window); | |
173 g_free (meter_win); | |
174 meter_win = NULL; | |
175 } | |
176 } | |
177 | |
178 static void gaim_gtk_connection_connect_progress(GaimConnection *gc, | |
179 const char *text, size_t step, size_t step_count) | |
180 { | |
181 struct signon_meter *meter; | |
182 | |
183 if(!meter_win) { | |
184 GtkWidget *vbox; | |
185 GtkWidget *cancel_button; | |
186 | |
187 if(mainwindow) | |
188 gtk_widget_hide(mainwindow); | |
189 | |
190 meter_win = g_new0(struct meter_window, 1); | |
191 meter_win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
192 gtk_window_set_resizable(GTK_WINDOW(meter_win->window), FALSE); | |
193 gtk_window_set_role(GTK_WINDOW(meter_win->window), "signon"); | |
194 gtk_container_set_border_width(GTK_CONTAINER(meter_win->window), 5); | |
195 gtk_window_set_title(GTK_WINDOW(meter_win->window), _("Signon")); | |
196 gtk_widget_realize(meter_win->window); | |
197 | |
198 vbox = gtk_vbox_new (FALSE, 0); | |
199 gtk_container_add(GTK_CONTAINER(meter_win->window), vbox); | |
200 | |
201 meter_win->table = gtk_table_new(1, 4, FALSE); | |
202 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(meter_win->table), | |
203 FALSE, FALSE, 0); | |
204 gtk_container_set_border_width(GTK_CONTAINER(meter_win->table), 5); | |
205 gtk_table_set_row_spacings(GTK_TABLE(meter_win->table), 5); | |
206 gtk_table_set_col_spacings(GTK_TABLE(meter_win->table), 10); | |
207 | |
208 cancel_button = gaim_pixbuf_button_from_stock(_("Cancel All"), | |
209 GTK_STOCK_QUIT, GAIM_BUTTON_HORIZONTAL); | |
210 g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", | |
211 G_CALLBACK(cancel_all), NULL); | |
212 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(cancel_button), | |
213 FALSE, FALSE, 0); | |
214 | |
215 g_signal_connect(G_OBJECT(meter_win->window), "delete_event", | |
216 G_CALLBACK(meter_destroy), NULL); | |
217 } | |
218 | |
219 meter = find_signon_meter(gc); | |
220 if(!meter) { | |
221 meter = new_meter(gc, meter_win->window, meter_win->table, | |
222 &meter_win->rows); | |
223 | |
224 meter_win->meters = g_slist_append(meter_win->meters, meter); | |
225 } | |
226 | |
227 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(meter->progress), | |
228 (float)step / (float)step_count); | |
229 gtk_label_set_text(GTK_LABEL(meter->status), text); | |
230 } | |
231 | |
232 static void gaim_gtk_connection_connected(GaimConnection *gc) | |
233 { | |
234 struct signon_meter *meter = find_signon_meter(gc); | |
235 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
236 gaim_setup(gc); |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
237 |
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 | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
245 static void gaim_gtk_connection_disconnected(GaimConnection *gc) |
5717 | 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 |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
249 do_away_menu(); |
5936
1b56a833d665
[gaim-migrate @ 6376]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
250 gaim_gtk_blist_update_protocol_actions(); |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
251 |
5717 | 252 if(meter) |
253 kill_meter(meter, _("Done.")); | |
5883
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
254 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
255 if (gaim_connections_get_all() != NULL) |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
256 return; |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
257 |
f5b0c6073264
[gaim-migrate @ 6315]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
258 destroy_all_dialogs(); |
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 gaim_blist_destroy(); |
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 show_login(); |
5717 | 263 } |
264 | |
265 static void gaim_gtk_connection_notice(GaimConnection *gc, | |
266 const char *text) | |
267 { | |
268 } | |
269 | |
7399 | 270 struct disconnect_window { |
271 GtkWidget *window; | |
272 GtkWidget *treeview; | |
273 GtkWidget *sw; | |
274 GtkWidget *label; | |
275 }; | |
276 struct disconnect_window *disconnect_window = NULL; | |
277 | |
7493 | 278 static void disconnect_window_hide() |
279 { | |
280 gtk_widget_destroy(disconnect_window->window); | |
281 g_free(disconnect_window); | |
282 disconnect_window = NULL; | |
283 } | |
284 | |
7399 | 285 static void disconnect_response_cb(GtkDialog *dialog, gint id, GtkWidget *widget) |
286 { | |
7483 | 287 GtkTreeIter iter; |
288 GValue val = { 0, }; | |
289 GtkTreeSelection *sel = NULL; | |
290 GtkTreeModel *model = NULL; | |
7431 | 291 GaimAccount *account = NULL; |
292 | |
7399 | 293 switch(id) { |
7506 | 294 case GTK_RESPONSE_DELETE_EVENT: |
7399 | 295 case GTK_RESPONSE_CLOSE: |
7493 | 296 disconnect_window_hide(); |
7399 | 297 break; |
298 case GTK_RESPONSE_ACCEPT: | |
7483 | 299 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); |
300 /* | |
301 * If we have more than one account disconnection displayed, then | |
302 * the scroll window is visible and we should use the selected | |
303 * account to reconnect. | |
304 */ | |
305 if (GTK_WIDGET_VISIBLE(disconnect_window->sw)) { | |
306 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
307 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) | |
308 return; | |
309 } else { | |
310 /* There is only one account disconnection, so reconnect to it. */ | |
311 if (!gtk_tree_model_get_iter_first(model, &iter)) | |
312 return; | |
313 } | |
7493 | 314 gtk_tree_model_get_value(model, &iter, 4, &val); |
7483 | 315 account = g_value_get_pointer(&val); |
316 g_value_unset(&val); | |
7643 | 317 /* remove all disconnections of the account to be reconnected */ |
7637 | 318 if (gtk_tree_model_get_iter_first(model, &iter)) { |
7643 | 319 GList *l_del = NULL; |
7637 | 320 GaimAccount *account2 = NULL; |
321 do { | |
322 gtk_tree_model_get_value(model, &iter, 4, &val); | |
323 account2 = g_value_get_pointer(&val); | |
324 g_value_unset(&val); | |
325 if (account2 == account) { | |
7643 | 326 GtkTreePath *path = gtk_tree_model_get_path(model, &iter); |
327 GtkTreeRowReference* del_row = gtk_tree_row_reference_new(model, path); | |
328 l_del = g_list_append(l_del, del_row); | |
7637 | 329 } |
330 g_value_unset(&val); | |
7643 | 331 } while (gtk_tree_model_iter_next(model, &iter)); |
332 | |
333 while (l_del != NULL) { | |
334 GtkTreeRowReference* del_row = l_del->data; | |
335 GtkTreePath *path = gtk_tree_row_reference_get_path(del_row); | |
336 if (gtk_tree_model_get_iter(model, &iter, path)) | |
337 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
338 l_del = l_del->next; | |
339 } | |
7637 | 340 } |
341 | |
7643 | 342 gaim_account_connect(account); |
343 | |
7552 | 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); | |
7493 | 350 } |
7399 | 351 break; |
352 } | |
353 } | |
354 | |
355 static void disconnect_tree_cb(GtkTreeSelection *sel, GtkTreeModel *model) | |
356 { | |
357 GtkTreeIter iter; | |
358 GValue val = { 0, }; | |
359 const char *label_text; | |
360 | |
7637 | 361 if (! gtk_tree_selection_get_selected (sel, &model, &iter)) { |
362 gtk_dialog_set_response_sensitive(GTK_DIALOG(disconnect_window->window), GTK_RESPONSE_ACCEPT, FALSE); | |
7399 | 363 return; |
7637 | 364 } else |
365 gtk_dialog_set_response_sensitive(GTK_DIALOG(disconnect_window->window), GTK_RESPONSE_ACCEPT, TRUE); | |
7399 | 366 gtk_tree_model_get_value (model, &iter, 3, &val); |
367 label_text = g_value_get_string(&val); | |
368 gtk_label_set_markup(GTK_LABEL(disconnect_window->label), label_text); | |
369 g_value_unset(&val); | |
370 } | |
371 | |
7625 | 372 static void disconnect_signed_on_cb(GaimConnection *gc, void *data) |
373 { | |
374 if (disconnect_window) { | |
375 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); | |
7637 | 376 GaimAccount *account = gaim_connection_get_account(gc); |
377 GdkPixbuf *icon = create_prpl_icon(account); | |
378 GdkPixbuf *scale = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); | |
7625 | 379 GtkTreeIter iter; |
380 if (gtk_tree_model_get_iter_first(model, &iter)) { | |
7637 | 381 GaimAccount *account2 = NULL; |
7625 | 382 do { |
383 GValue val = { 0, }; | |
384 gtk_tree_model_get_value(model, &iter, 4, &val); | |
7637 | 385 account2 = g_value_get_pointer(&val); |
7625 | 386 g_value_unset(&val); |
7637 | 387 if (account2 == account) { |
388 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, scale, -1); | |
7625 | 389 } |
390 } while (gtk_tree_model_iter_next(model, &iter)); | |
391 } | |
7637 | 392 if (icon != NULL) g_object_unref(G_OBJECT(icon)); |
393 if (scale != NULL) g_object_unref(G_OBJECT(scale)); | |
7625 | 394 } |
395 } | |
7399 | 396 |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
397 static void |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
398 gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
399 { |
7399 | 400 char *label_text = NULL; |
401 GdkPixbuf *scale, *icon; | |
7506 | 402 GtkTreeIter new_row_iter, iter; |
7483 | 403 GValue val = { 0, }; |
404 GaimAccount *account = NULL; | |
7506 | 405 GtkListStore *list_store; |
406 GtkTreeViewColumn *col; | |
407 GtkTreeSelection *sel = NULL; | |
7399 | 408 |
7648 | 409 label_text = g_strdup_printf(_("<span weight=\"bold\" size=\"larger\">%s has been disconnected.</span>\n\n%s\n%s"), |
7399 | 410 gaim_account_get_username(gaim_connection_get_account(gc)), gaim_date_full(), |
411 text ? text : _("Reason Unknown.")); | |
7496 | 412 |
7506 | 413 /* Build the window if it isn't there yet */ |
414 if (!disconnect_window) { | |
7399 | 415 GtkWidget *hbox, *vbox, *img; |
416 GtkCellRenderer *rend, *rend2; | |
7496 | 417 |
7407 | 418 disconnect_window = g_new0(struct disconnect_window, 1); |
7678 | 419 disconnect_window->window = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, NULL, GTK_DIALOG_NO_SEPARATOR, |
7399 | 420 _("Reconnect"), GTK_RESPONSE_ACCEPT, |
421 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); | |
422 g_signal_connect(G_OBJECT(disconnect_window->window), "response", G_CALLBACK(disconnect_response_cb), disconnect_window); | |
423 | |
424 gtk_container_set_border_width(GTK_CONTAINER(disconnect_window->window), 6); | |
425 gtk_window_set_resizable(GTK_WINDOW(disconnect_window->window), FALSE); | |
426 gtk_dialog_set_has_separator(GTK_DIALOG(disconnect_window->window), FALSE); | |
427 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(disconnect_window->window)->vbox), 12); | |
428 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), 6); | |
429 | |
430 hbox = gtk_hbox_new(FALSE, 12); | |
431 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), hbox); | |
432 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); | |
433 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
434 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
7496 | 435 |
7399 | 436 vbox = gtk_vbox_new(FALSE, 12); |
437 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
438 | |
7506 | 439 disconnect_window->label = gtk_label_new(label_text); |
7496 | 440 |
7399 | 441 gtk_label_set_line_wrap(GTK_LABEL(disconnect_window->label), TRUE); |
442 gtk_misc_set_alignment(GTK_MISC(disconnect_window->label), 0, 0); | |
443 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->label, FALSE, FALSE, 0); | |
444 | |
445 gtk_widget_show_all(disconnect_window->window); | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
446 |
7399 | 447 /* Tree View */ |
448 disconnect_window->sw = gtk_scrolled_window_new(NULL,NULL); | |
449 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_SHADOW_IN); | |
450 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
451 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->sw, TRUE, TRUE, 0); | |
7496 | 452 |
7506 | 453 list_store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); |
7399 | 454 disconnect_window->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL(list_store)); |
7496 | 455 |
7399 | 456 rend = gtk_cell_renderer_pixbuf_new(); |
457 rend2 = gtk_cell_renderer_text_new(); | |
458 col = gtk_tree_view_column_new(); | |
459 gtk_tree_view_column_set_title(col, _("Account")); | |
460 gtk_tree_view_column_pack_start(col, rend, FALSE); | |
461 gtk_tree_view_column_pack_start(col, rend2, FALSE); | |
462 gtk_tree_view_column_set_attributes(col, rend, "pixbuf", 0, NULL); | |
463 gtk_tree_view_column_set_attributes(col, rend2, "text", 1, NULL); | |
464 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
7496 | 465 |
7399 | 466 rend = gtk_cell_renderer_text_new(); |
467 col = gtk_tree_view_column_new_with_attributes (_("Time"), | |
468 rend, "text", 2, NULL); | |
469 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
7637 | 470 |
7399 | 471 g_object_unref(G_OBJECT(list_store)); |
472 gtk_container_add(GTK_CONTAINER(disconnect_window->sw), disconnect_window->treeview); | |
7496 | 473 |
7399 | 474 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
|
475 gtk_widget_set_size_request(disconnect_window->treeview, -1, 96); |
7399 | 476 g_signal_connect (G_OBJECT (sel), "changed", |
477 G_CALLBACK (disconnect_tree_cb), list_store); | |
7625 | 478 |
479 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
480 disconnect_window, GAIM_CALLBACK(disconnect_signed_on_cb), NULL); | |
481 | |
7506 | 482 } else |
483 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview))); | |
7637 | 484 /* mark all disconnections w/ the account type disconnected /w grey icon */ |
485 icon = create_prpl_icon(gaim_connection_get_account(gc)); | |
486 scale = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); | |
487 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); | |
7506 | 488 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)) { |
489 do { | |
490 gtk_tree_model_get_value(GTK_TREE_MODEL(list_store), &iter, 4, &val); | |
491 account = g_value_get_pointer(&val); | |
492 g_value_unset(&val); | |
493 if (account == gaim_connection_get_account(gc)) { | |
7637 | 494 gtk_list_store_set(list_store, &iter, 0, scale, -1); |
7506 | 495 } |
496 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)); | |
497 } | |
498 | |
499 /* Add this account to our list of disconnected accounts */ | |
500 gtk_list_store_append(list_store, &new_row_iter); | |
501 gtk_list_store_set(list_store, &new_row_iter, | |
502 0, scale, | |
503 1, gaim_account_get_username(gaim_connection_get_account(gc)), | |
504 2, gaim_date_full(), | |
505 3, label_text, | |
506 4, gaim_connection_get_account(gc), -1); | |
507 g_object_unref(G_OBJECT(icon)); | |
508 g_object_unref(G_OBJECT(scale)); | |
509 | |
510 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)) | |
511 { | |
512 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
513 gtk_tree_selection_select_iter(sel, &new_row_iter); | |
514 /* if we have more than one disconnected acct, display the treeview */ | |
515 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)) | |
516 gtk_widget_show_all(disconnect_window->sw); | |
7399 | 517 } |
7496 | 518 |
7399 | 519 g_free(label_text); |
7493 | 520 gtk_window_present(GTK_WINDOW(disconnect_window->window)); |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
521 } |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
522 |
5717 | 523 static GaimConnectionUiOps conn_ui_ops = |
524 { | |
525 gaim_gtk_connection_connect_progress, | |
526 gaim_gtk_connection_connected, | |
527 gaim_gtk_connection_disconnected, | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
528 gaim_gtk_connection_notice, |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
529 gaim_gtk_connection_report_disconnect |
5717 | 530 }; |
531 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
532 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6460
diff
changeset
|
533 gaim_gtk_connections_get_ui_ops(void) |
5717 | 534 { |
535 return &conn_ui_ops; | |
536 } | |
537 | |
6216 | 538 void away_on_login(const char *mesg) |
5717 | 539 { |
540 GSList *awy = away_messages; | |
541 struct away_message *a, *message = NULL; | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
542 GaimGtkBuddyList *gtkblist; |
5717 | 543 |
544 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
545 | |
546 if (!gtkblist->window) { | |
547 return; | |
548 } | |
549 | |
6216 | 550 if (mesg == NULL) |
551 mesg = gaim_prefs_get_string("/core/away/default_message"); | |
552 while (awy) { | |
553 a = (struct away_message *)awy->data; | |
554 if (strcmp(a->name, mesg) == 0) { | |
555 message = a; | |
556 break; | |
5717 | 557 } |
6216 | 558 awy = awy->next; |
5717 | 559 } |
6216 | 560 if (message == NULL) { |
561 if(!away_messages) | |
562 return; | |
563 message = away_messages->data; | |
564 } | |
565 do_away_message(NULL, message); | |
5717 | 566 } |