Mercurial > pidgin.yaz
annotate src/gtkstatusselector.c @ 10437:446f5f28e8d0
[gaim-migrate @ 11694]
sf patch #1090744, from Balwinder Singh Dheeman
Adds back a thingy to the perl API
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 27 Dec 2004 20:48:41 +0000 |
parents | ce098e226486 |
children | 6feef0a9098a |
rev | line source |
---|---|
10178 | 1 /** |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10249
diff
changeset
|
2 * @file gtkstatusselector.c GTK+ Status selector widget |
10178 | 3 * @ingroup gtkui |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include "internal.h" | |
26 #include "gtkgaim.h" | |
27 #include "gtkimhtml.h" | |
28 #include "gtkstatusselector.h" | |
29 #include "gtkutils.h" | |
30 | |
31 #include "account.h" | |
32 #include "debug.h" | |
33 #include "prefs.h" | |
34 | |
35 struct _GaimGtkStatusSelectorPrivate | |
36 { | |
37 GtkWidget *combo; | |
38 GtkWidget *entry; | |
10191 | 39 GtkWidget *frame; |
10178 | 40 |
10347 | 41 GtkWidget *optmenu; |
42 GtkWidget *menu; | |
43 GtkSizeGroup *sg; | |
44 | |
10178 | 45 GtkListStore *model; |
10199 | 46 |
47 guint entry_timer; | |
10178 | 48 }; |
49 | |
50 enum | |
51 { | |
52 COLUMN_STATUS_TYPE_ID, | |
53 COLUMN_ICON, | |
54 COLUMN_NAME, | |
55 NUM_COLUMNS | |
56 }; | |
57 | |
10347 | 58 #define GAIM_SELECTOR_TEXT "gaim-text" |
59 #define GAIM_SELECTOR_STATUS_TYPE_ID "gaim-status-type-id" | |
60 | |
10178 | 61 static void gaim_gtk_status_selector_class_init(GaimGtkStatusSelectorClass *klass); |
62 static void gaim_gtk_status_selector_init(GaimGtkStatusSelector *selector); | |
63 static void gaim_gtk_status_selector_finalize(GObject *obj); | |
64 static void gaim_gtk_status_selector_destroy(GtkObject *obj); | |
65 static void status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector); | |
10199 | 66 static gboolean key_press_cb(GtkWidget *entry, GdkEventKey *event, gpointer user_data); |
10178 | 67 static void signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector); |
68 static void rebuild_list(GaimGtkStatusSelector *selector); | |
69 | |
70 static GtkVBox *parent_class = NULL; | |
71 | |
72 GType | |
73 gaim_gtk_status_selector_get_type(void) | |
74 { | |
75 static GType type = 0; | |
76 | |
77 if (!type) | |
78 { | |
79 static const GTypeInfo info = | |
80 { | |
81 sizeof(GaimGtkStatusSelectorClass), | |
82 NULL, | |
83 NULL, | |
84 (GClassInitFunc)gaim_gtk_status_selector_class_init, | |
85 NULL, | |
86 NULL, | |
87 sizeof(GaimGtkStatusSelector), | |
88 0, | |
89 (GInstanceInitFunc)gaim_gtk_status_selector_init | |
90 }; | |
91 | |
92 type = g_type_register_static(GTK_TYPE_VBOX, | |
93 "GaimGtkStatusSelector", &info, 0); | |
94 } | |
95 | |
96 return type; | |
97 } | |
98 | |
99 static void | |
100 gaim_gtk_status_selector_class_init(GaimGtkStatusSelectorClass *klass) | |
101 { | |
102 GObjectClass *gobject_class; | |
103 GtkObjectClass *object_class; | |
104 | |
105 parent_class = g_type_class_peek_parent(klass); | |
106 | |
107 gobject_class = G_OBJECT_CLASS(klass); | |
108 object_class = GTK_OBJECT_CLASS(klass); | |
109 | |
110 gobject_class->finalize = gaim_gtk_status_selector_finalize; | |
111 | |
112 object_class->destroy = gaim_gtk_status_selector_destroy; | |
113 } | |
114 | |
115 static void | |
116 gaim_gtk_status_selector_init(GaimGtkStatusSelector *selector) | |
117 { | |
10225 | 118 #if GTK_CHECK_VERSION(2,4,0) |
10178 | 119 GtkWidget *combo; |
10347 | 120 GtkCellRenderer *renderer; |
121 #else | |
122 GtkWidget *optmenu; | |
123 #endif | |
10178 | 124 GtkWidget *entry; |
10191 | 125 GtkWidget *toolbar; |
126 GtkWidget *frame; | |
10178 | 127 |
128 selector->priv = g_new0(GaimGtkStatusSelectorPrivate, 1); | |
129 | |
130 #if GTK_CHECK_VERSION(2,4,0) | |
131 selector->priv->model = gtk_list_store_new(NUM_COLUMNS, G_TYPE_POINTER, | |
10347 | 132 GDK_TYPE_PIXBUF, G_TYPE_STRING); |
10178 | 133 |
134 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(selector->priv->model)); | |
135 selector->priv->combo = combo; | |
136 | |
137 g_object_unref(G_OBJECT(selector->priv->model)); | |
138 | |
139 renderer = gtk_cell_renderer_pixbuf_new(); | |
140 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, FALSE); | |
141 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, | |
142 "pixbuf", COLUMN_ICON, | |
143 NULL); | |
144 | |
145 renderer = gtk_cell_renderer_text_new(); | |
146 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE); | |
147 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, | |
148 "text", COLUMN_NAME, | |
149 NULL); | |
150 | |
151 g_signal_connect(G_OBJECT(combo), "changed", | |
152 G_CALLBACK(status_switched_cb), selector); | |
153 | |
154 /* TODO */ | |
155 | |
156 | |
157 gtk_widget_show(combo); | |
158 gtk_box_pack_start(GTK_BOX(selector), combo, FALSE, FALSE, 0); | |
159 | |
10347 | 160 |
161 #else /* GTK < 2.4.0 */ | |
162 selector->priv->optmenu = optmenu = gtk_option_menu_new(); | |
163 gtk_widget_show(optmenu); | |
164 | |
165 selector->priv->menu = gtk_menu_new(); | |
166 gtk_widget_show(selector->priv->menu); | |
167 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), selector->priv->menu); | |
168 | |
169 selector->priv->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
170 | |
171 g_signal_connect(G_OBJECT(optmenu), "changed", | |
172 G_CALLBACK(status_switched_cb), selector); | |
173 | |
174 gtk_box_pack_start(GTK_BOX(selector), optmenu, FALSE, FALSE, 0); | |
175 #endif | |
176 | |
10191 | 177 frame = gaim_gtk_create_imhtml(TRUE, &entry, &toolbar); |
178 selector->priv->entry = entry; | |
179 selector->priv->frame = frame; | |
180 gtk_widget_set_name(entry, "gaim_gtkstatusselector_imhtml"); | |
181 gtk_box_pack_start(GTK_BOX(selector), frame, TRUE, TRUE, 0); | |
182 gtk_widget_hide(toolbar); | |
10178 | 183 |
10199 | 184 g_signal_connect(G_OBJECT(entry), "key_press_event", |
10347 | 185 G_CALLBACK(key_press_cb), selector); |
10178 | 186 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
10347 | 187 selector, GAIM_CALLBACK(signed_on_off_cb), |
188 selector); | |
10178 | 189 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", |
10347 | 190 selector, GAIM_CALLBACK(signed_on_off_cb), |
191 selector); | |
10404 | 192 |
10178 | 193 rebuild_list(selector); |
194 } | |
195 | |
196 static void | |
197 gaim_gtk_status_selector_finalize(GObject *obj) | |
198 { | |
199 GaimGtkStatusSelector *selector; | |
200 | |
201 g_return_if_fail(obj != NULL); | |
202 g_return_if_fail(GAIM_GTK_IS_STATUS_SELECTOR(obj)); | |
203 | |
204 selector = GAIM_GTK_STATUS_SELECTOR(obj); | |
205 | |
10347 | 206 if (selector->priv->sg) { |
207 g_object_unref(selector->priv->sg); | |
208 selector->priv->sg = NULL; | |
209 } | |
210 | |
10178 | 211 g_free(selector->priv); |
212 | |
213 if (G_OBJECT_CLASS(parent_class)->finalize) | |
214 G_OBJECT_CLASS(parent_class)->finalize(obj); | |
215 } | |
216 | |
217 static void | |
218 gaim_gtk_status_selector_destroy(GtkObject *obj) | |
219 { | |
220 GaimGtkStatusSelector *selector; | |
221 | |
222 g_return_if_fail(obj != NULL); | |
223 g_return_if_fail(GAIM_GTK_IS_STATUS_SELECTOR(obj)); | |
224 | |
225 selector = GAIM_GTK_STATUS_SELECTOR(obj); | |
226 | |
10187 | 227 gaim_signals_disconnect_by_handle(selector); |
10249 | 228 if (selector->priv->entry_timer != 0) |
229 gaim_timeout_remove(selector->priv->entry_timer); | |
10187 | 230 |
10178 | 231 if (GTK_OBJECT_CLASS(parent_class)->destroy) |
232 GTK_OBJECT_CLASS(parent_class)->destroy(obj); | |
233 } | |
234 | |
10347 | 235 static gboolean |
236 get_selected_data(GaimGtkStatusSelector *selector, const char **text, const char **status_type_id) | |
237 { | |
10225 | 238 #if GTK_CHECK_VERSION(2,4,0) |
10347 | 239 GtkTreeIter iter; |
240 | |
241 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(selector->priv->combo), | |
242 &iter)) | |
243 return FALSE; | |
244 | |
245 gtk_tree_model_get(GTK_TREE_MODEL(selector->priv->model), &iter, | |
246 COLUMN_NAME, text, | |
247 COLUMN_STATUS_TYPE_ID, status_type_id, | |
248 -1); | |
249 return TRUE; | |
250 #else | |
251 GtkWidget *item; | |
252 int i; | |
253 GList *l; | |
254 | |
255 i = gtk_option_menu_get_history(GTK_OPTION_MENU(selector->priv->optmenu)); | |
256 l = GTK_MENU_SHELL(selector->priv->menu)->children; | |
257 item = g_list_nth_data(l, i); | |
258 *text = g_object_get_data(G_OBJECT(item), GAIM_SELECTOR_TEXT); | |
259 *status_type_id = g_object_get_data(G_OBJECT(item), GAIM_SELECTOR_STATUS_TYPE_ID); | |
260 return TRUE; | |
261 #endif | |
262 return FALSE; | |
263 } | |
264 | |
10178 | 265 static void |
266 status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector) | |
267 { | |
10347 | 268 const char *status_type_id = NULL; |
269 const char *text = NULL; | |
10178 | 270 |
10347 | 271 if (!get_selected_data(selector, &text, &status_type_id)) |
10188 | 272 return; |
10178 | 273 |
10191 | 274 if (status_type_id == NULL) |
275 { | |
276 if (!strcmp(text, _("New Status"))) | |
277 { | |
278 /* TODO */ | |
279 } | |
280 } | |
10197 | 281 else |
10188 | 282 { |
10199 | 283 /* |
284 * If the chosen status does not require a message, then set the | |
285 * status immediately. Otherwise just register a timeout and the | |
286 * status will be set whenever the user stops typing the message. | |
287 */ | |
288 GList *l; | |
10188 | 289 GtkTextBuffer *buffer; |
290 gboolean allow_message = FALSE; | |
10178 | 291 |
10188 | 292 buffer = |
293 gtk_text_view_get_buffer(GTK_TEXT_VIEW(selector->priv->entry)); | |
294 | |
10199 | 295 gtk_text_buffer_set_text(buffer, text, -1); |
296 | |
10400 | 297 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) |
10199 | 298 { |
10400 | 299 GaimAccount *account = (GaimAccount*)l->data; |
10199 | 300 GaimStatusType *status_type; |
10404 | 301 |
10400 | 302 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) |
303 continue; | |
10199 | 304 |
305 status_type = gaim_account_get_status_type(account, | |
10400 | 306 status_type_id); |
10199 | 307 |
308 if (status_type == NULL) | |
309 continue; | |
310 | |
311 if (gaim_status_type_get_attr(status_type, "message") != NULL) | |
312 { | |
313 allow_message = TRUE; | |
314 } | |
315 else | |
316 { | |
317 gaim_account_set_status(account, | |
10400 | 318 status_type_id, TRUE, |
319 NULL); | |
10199 | 320 } |
321 } | |
322 | |
323 if (allow_message) | |
324 { | |
325 gtk_widget_show(selector->priv->frame); | |
326 key_press_cb(NULL, NULL, selector); | |
327 } | |
328 else | |
329 gtk_widget_hide(selector->priv->frame); | |
330 } | |
331 } | |
332 | |
333 static gboolean | |
334 insert_text_timeout_cb(gpointer data) | |
335 { | |
336 GaimGtkStatusSelector *selector = (GaimGtkStatusSelector *)data; | |
337 const char *status_type_id; | |
338 const char *text; | |
339 | |
10347 | 340 if (!get_selected_data(selector, &text, &status_type_id)) |
10199 | 341 return FALSE; |
342 | |
343 if (status_type_id == NULL) | |
344 { | |
345 if (!strcmp(text, _("New Status"))) | |
346 { | |
347 /* TODO */ | |
348 } | |
349 } | |
350 else | |
351 { | |
352 gchar *message; | |
353 GList *l; | |
354 | |
355 message = gtk_imhtml_get_markup(GTK_IMHTML(selector->priv->entry)); | |
10188 | 356 |
10400 | 357 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) |
10178 | 358 { |
10400 | 359 GaimAccount *account = (GaimAccount*)l->data; |
10188 | 360 GaimStatusType *status_type; |
10404 | 361 |
10400 | 362 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) |
363 continue; | |
10178 | 364 |
10188 | 365 status_type = gaim_account_get_status_type(account, |
10347 | 366 status_type_id); |
10178 | 367 |
10188 | 368 if (status_type == NULL) |
369 continue; | |
10178 | 370 |
10188 | 371 if (gaim_status_type_get_attr(status_type, "message") != NULL) |
10178 | 372 { |
10188 | 373 gaim_account_set_status(account, |
10347 | 374 status_type_id, TRUE, |
375 "message", message, | |
376 NULL); | |
10188 | 377 } |
378 } | |
10199 | 379 } |
10178 | 380 |
10199 | 381 return FALSE; |
382 } | |
383 | |
384 /** | |
385 * The user typed in the IMHTML entry widget. If the user is finished | |
386 * typing then we want to set the appropriate status message. So let's | |
387 * wait 3 seconds, and if they haven't typed anything else then set the | |
388 * status message. | |
389 */ | |
390 static gboolean | |
391 key_press_cb(GtkWidget *entry, GdkEventKey *event, gpointer user_data) | |
392 { | |
393 GaimGtkStatusSelector *selector = (GaimGtkStatusSelector *)user_data; | |
394 | |
395 if (selector->priv->entry_timer != 0) { | |
396 gaim_timeout_remove(selector->priv->entry_timer); | |
10178 | 397 } |
10199 | 398 |
399 selector->priv->entry_timer = gaim_timeout_add(3000, insert_text_timeout_cb, | |
400 selector); | |
401 | |
402 return FALSE; | |
10178 | 403 } |
404 | |
405 static void | |
406 signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector) | |
407 { | |
408 rebuild_list(selector); | |
409 } | |
410 | |
411 static GdkPixbuf * | |
412 load_icon(const char *basename) | |
413 { | |
414 char *filename; | |
415 GdkPixbuf *pixbuf, *scale = NULL; | |
416 | |
417 if (!strcmp(basename, "available.png")) | |
418 basename = "online.png"; | |
419 else if (!strcmp(basename, "hidden.png")) | |
420 basename = "invisible.png"; | |
421 | |
422 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", | |
423 basename, NULL); | |
424 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
425 g_free(filename); | |
426 | |
427 if (pixbuf != NULL) | |
428 { | |
429 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
430 GDK_INTERP_BILINEAR); | |
431 | |
432 g_object_unref(G_OBJECT(pixbuf)); | |
433 } | |
434 else | |
435 { | |
436 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
437 "default", basename, NULL); | |
438 scale = gdk_pixbuf_new_from_file(filename, NULL); | |
439 g_free(filename); | |
440 } | |
441 | |
442 return scale; | |
443 } | |
444 | |
445 static void | |
446 add_item(GaimGtkStatusSelector *selector, const char *status_type_id, | |
447 const char *text, GdkPixbuf *pixbuf) | |
448 { | |
10347 | 449 #if GTK_CHECK_VERSION(2,4,0) |
10178 | 450 GtkTreeIter iter; |
451 | |
452 gtk_list_store_append(selector->priv->model, &iter); | |
453 gtk_list_store_set(selector->priv->model, &iter, | |
454 COLUMN_STATUS_TYPE_ID, status_type_id, | |
455 COLUMN_ICON, pixbuf, | |
456 COLUMN_NAME, text, | |
457 -1); | |
10347 | 458 #else |
459 GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); | |
460 GtkWidget *item, *hbox, *label; | |
461 | |
462 /* Create the item. */ | |
463 item = gtk_menu_item_new(); | |
464 | |
465 /* Create the hbox. */ | |
466 hbox = gtk_hbox_new(FALSE, 4); | |
467 gtk_container_add(GTK_CONTAINER(item), hbox); | |
468 gtk_widget_show(hbox); | |
469 | |
470 gtk_size_group_add_widget(selector->priv->sg, image); | |
471 | |
472 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | |
473 gtk_widget_show(image); | |
474 | |
475 /* Create the label. */ | |
476 label = gtk_label_new(text); | |
477 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
478 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
479 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | |
480 gtk_widget_show(label); | |
481 | |
482 g_object_set_data_full(G_OBJECT(item), GAIM_SELECTOR_TEXT, g_strdup(text), g_free); | |
483 g_object_set_data_full(G_OBJECT(item), GAIM_SELECTOR_STATUS_TYPE_ID, g_strdup(status_type_id), g_free); | |
484 | |
485 gtk_menu_shell_append(GTK_MENU_SHELL(selector->priv->menu), item); | |
486 gtk_widget_show(item); | |
487 gaim_set_accessible_label(item, label); | |
488 #endif | |
10178 | 489 |
490 if (pixbuf != NULL) | |
491 g_object_unref(G_OBJECT(pixbuf)); | |
492 } | |
493 | |
10347 | 494 |
10178 | 495 static void |
496 rebuild_list(GaimGtkStatusSelector *selector) | |
497 { | |
498 gboolean single_prpl = TRUE; | |
10400 | 499 GList *accounts; |
500 gboolean enabled = FALSE; | |
10178 | 501 GaimAccount *first_account = NULL; |
502 const char *first_prpl_type = NULL; | |
503 GList *l; | |
504 | |
505 g_return_if_fail(selector != NULL); | |
506 g_return_if_fail(GAIM_GTK_IS_STATUS_SELECTOR(selector)); | |
507 | |
10347 | 508 #if GTK_CHECK_VERSION(2,4,0) |
10178 | 509 gtk_list_store_clear(selector->priv->model); |
10347 | 510 #else |
511 gtk_option_menu_remove_menu(GTK_OPTION_MENU(selector->priv->optmenu)); | |
512 /* XXX this automaticly destroys the menu, right? */ | |
513 selector->priv->menu = gtk_menu_new(); | |
514 gtk_widget_show(selector->priv->menu); | |
515 #endif | |
10178 | 516 |
517 /* | |
10400 | 518 * If no accounts are enabled then gray ourself out and get |
10352 | 519 * outta hee. |
520 */ | |
10400 | 521 for(accounts = gaim_accounts_get_all(); accounts; accounts = accounts->next) { |
522 GaimAccount *a = accounts->data; | |
523 if (gaim_account_get_enabled(a, GAIM_GTK_UI)) { | |
524 enabled = TRUE; | |
525 break; | |
526 } | |
527 } | |
528 | |
529 if (enabled == FALSE) | |
10352 | 530 { |
531 gtk_widget_set_sensitive(GTK_WIDGET(selector), FALSE); | |
532 return; | |
533 } | |
534 gtk_widget_set_sensitive(GTK_WIDGET(selector), TRUE); | |
535 | |
536 /* | |
10178 | 537 * If the user only has one IM account or one type of IM account |
538 * connected, they'll see all their statuses. This is ideal for those | |
539 * who use only one account, or one single protocol. Everyone else | |
540 * gets Available and Away and a list of saved statuses. | |
541 */ | |
10400 | 542 for (l = gaim_accounts_get_all(); l != NULL && single_prpl; l = l->next) |
10178 | 543 { |
10400 | 544 GaimAccount *account = l->data; |
10178 | 545 GaimPluginProtocolInfo *prpl_info; |
10400 | 546 GaimPlugin *plugin; |
10178 | 547 const char *basename; |
548 | |
10400 | 549 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) |
550 continue; | |
551 | |
552 plugin = gaim_find_prpl(account->protocol_id); | |
553 if (!plugin) | |
554 continue; | |
555 | |
556 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
10178 | 557 basename = prpl_info->list_icon(account, NULL); |
558 | |
559 if (first_prpl_type == NULL) | |
560 { | |
561 first_prpl_type = basename; | |
562 first_account = account; | |
563 } | |
10179
97ee3bf7bcf7
[gaim-migrate @ 11294]
Christian Hammond <chipx86@chipx86.com>
parents:
10178
diff
changeset
|
564 else if (strcmp(first_prpl_type, basename)) |
10178 | 565 single_prpl = FALSE; |
566 } | |
567 | |
568 if (single_prpl) | |
569 { | |
570 const GList *l; | |
571 | |
572 for (l = gaim_account_get_status_types(first_account); | |
573 l != NULL; | |
574 l = l->next) | |
575 { | |
576 GaimStatusType *status_type = (GaimStatusType *)l->data; | |
577 char filename[BUFSIZ]; | |
578 | |
579 if (!gaim_status_type_is_user_settable(status_type)) | |
580 continue; | |
581 | |
10207 | 582 /* |
583 * TODO Find a way to fallback to the GaimStatusPrimitive | |
584 * if an icon for this id does not exist. | |
585 */ | |
10178 | 586 g_snprintf(filename, sizeof(filename), "%s.png", |
587 gaim_status_type_get_id(status_type)); | |
588 | |
589 add_item(selector, | |
590 gaim_status_type_get_id(status_type), | |
591 gaim_status_type_get_name(status_type), | |
592 load_icon(filename)); | |
593 } | |
594 } | |
595 else | |
596 { | |
597 add_item(selector, "available", _("Available"), | |
598 load_icon("online.png")); | |
599 add_item(selector, "away", _("Away"), load_icon("away.png")); | |
600 } | |
601 | |
10191 | 602 /* TODO: Add saved statuses here? */ |
603 | |
10178 | 604 add_item(selector, NULL, _("New Status"), |
10347 | 605 gtk_widget_render_icon(GTK_WIDGET(selector), GTK_STOCK_NEW, |
606 GTK_ICON_SIZE_MENU, NULL)); | |
607 #if !GTK_CHECK_VERSION(2,4,0) | |
608 gtk_option_menu_set_menu(GTK_OPTION_MENU(selector->priv->optmenu), selector->priv->menu); | |
609 #endif | |
10178 | 610 } |
611 | |
612 GtkWidget * | |
613 gaim_gtk_status_selector_new(void) | |
614 { | |
615 GaimGtkStatusSelector *selector; | |
616 | |
617 selector = g_object_new(GAIM_GTK_TYPE_STATUS_SELECTOR, NULL); | |
618 | |
619 return GTK_WIDGET(selector); | |
620 } |