Mercurial > pidgin.yaz
comparison pidgin/gtkdocklet.c @ 20351:d938cdb2339a
applied changes from a3511433f0830f88e2e470b22fd2c706e2aa7713
through cca81a1b623d3a31f3a7d03158eddb36ecf4bfbc
applied changes from cca81a1b623d3a31f3a7d03158eddb36ecf4bfbc
through f881ac75f7e0412344009a6cc0f00318fa750fa0
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 21 Oct 2007 04:51:10 +0000 |
parents | 946f14971f6a |
children | 89c7be36fd61 |
comparison
equal
deleted
inserted
replaced
20350:4d4eb6831722 | 20351:d938cdb2339a |
---|---|
36 #include "gtkconv.h" | 36 #include "gtkconv.h" |
37 #include "gtkplugin.h" | 37 #include "gtkplugin.h" |
38 #include "gtkprefs.h" | 38 #include "gtkprefs.h" |
39 #include "gtksavedstatuses.h" | 39 #include "gtksavedstatuses.h" |
40 #include "gtksound.h" | 40 #include "gtksound.h" |
41 #include "gtkstatusbox.h" | |
41 #include "gtkutils.h" | 42 #include "gtkutils.h" |
42 #include "pidginstock.h" | 43 #include "pidginstock.h" |
43 #include "gtkdocklet.h" | 44 #include "gtkdocklet.h" |
44 #include "gtkdialogs.h" | 45 #include "gtkdialogs.h" |
45 | 46 |
354 } | 355 } |
355 return FALSE; | 356 return FALSE; |
356 } | 357 } |
357 #endif | 358 #endif |
358 | 359 |
360 /* There is a lot of code here for handling the status submenu, much of | |
361 * which is duplicated from the gtkstatusbox. It'd be nice to add API | |
362 * somewhere to simplify this (either in the statusbox, or in libpurple). | |
363 */ | |
359 static void | 364 static void |
360 show_custom_status_editor_cb(GtkMenuItem *menuitem, gpointer user_data) | 365 show_custom_status_editor_cb(GtkMenuItem *menuitem, gpointer user_data) |
361 { | 366 { |
362 PurpleSavedStatus *saved_status; | 367 PurpleSavedStatus *saved_status; |
363 saved_status = purple_savedstatus_get_current(); | 368 saved_status = purple_savedstatus_get_current(); |
367 | 372 |
368 pidgin_status_editor_show(FALSE, | 373 pidgin_status_editor_show(FALSE, |
369 purple_savedstatus_is_transient(saved_status) ? saved_status : NULL); | 374 purple_savedstatus_is_transient(saved_status) ? saved_status : NULL); |
370 } | 375 } |
371 | 376 |
377 static PurpleSavedStatus * | |
378 create_transient_status(PurpleStatusPrimitive primitive, PurpleStatusType *status_type) | |
379 { | |
380 PurpleSavedStatus *saved_status = purple_savedstatus_new(NULL, primitive); | |
381 | |
382 if(status_type != NULL) { | |
383 GList *tmp, *active_accts = purple_accounts_get_all_active(); | |
384 for (tmp = active_accts; tmp != NULL; tmp = tmp->next) { | |
385 purple_savedstatus_set_substatus(saved_status, | |
386 (PurpleAccount*) tmp->data, status_type, NULL); | |
387 } | |
388 g_list_free(active_accts); | |
389 } | |
390 | |
391 return saved_status; | |
392 } | |
393 | |
394 static void | |
395 activate_status_account_cb(GtkMenuItem *menuitem, gpointer user_data) | |
396 { | |
397 PurpleStatusType *status_type; | |
398 PurpleStatusPrimitive primitive; | |
399 PurpleSavedStatus *saved_status = NULL; | |
400 GList *iter = purple_savedstatuses_get_all(); | |
401 GList *tmp, *active_accts = purple_accounts_get_all_active(); | |
402 | |
403 status_type = (PurpleStatusType *)user_data; | |
404 primitive = purple_status_type_get_primitive(status_type); | |
405 | |
406 for (; iter != NULL; iter = iter->next) { | |
407 PurpleSavedStatus *ss = iter->data; | |
408 if ((purple_savedstatus_get_type(ss) == primitive) && purple_savedstatus_is_transient(ss) && | |
409 purple_savedstatus_has_substatuses(ss)) | |
410 { | |
411 gboolean found = FALSE; | |
412 /* The currently enabled accounts must have substatuses for all the active accts */ | |
413 for(tmp = active_accts; tmp != NULL; tmp = tmp->next) { | |
414 PurpleAccount *acct = tmp->data; | |
415 PurpleSavedStatusSub *sub = purple_savedstatus_get_substatus(ss, acct); | |
416 if (sub) { | |
417 const PurpleStatusType *sub_type = purple_savedstatus_substatus_get_type(sub); | |
418 const char *subtype_status_id = purple_status_type_get_id(sub_type); | |
419 if (subtype_status_id && !strcmp(subtype_status_id, | |
420 purple_status_type_get_id(status_type))) | |
421 found = TRUE; | |
422 } | |
423 } | |
424 if (!found) | |
425 continue; | |
426 saved_status = ss; | |
427 break; | |
428 } | |
429 } | |
430 | |
431 g_list_free(active_accts); | |
432 | |
433 /* Create a new transient saved status if we weren't able to find one */ | |
434 if (saved_status == NULL) | |
435 saved_status = create_transient_status(primitive, status_type); | |
436 | |
437 /* Set the status for each account */ | |
438 purple_savedstatus_activate(saved_status); | |
439 } | |
440 | |
372 static void | 441 static void |
373 activate_status_primitive_cb(GtkMenuItem *menuitem, gpointer user_data) | 442 activate_status_primitive_cb(GtkMenuItem *menuitem, gpointer user_data) |
374 { | 443 { |
375 PurpleStatusPrimitive primitive; | 444 PurpleStatusPrimitive primitive; |
376 PurpleSavedStatus *saved_status; | 445 PurpleSavedStatus *saved_status; |
380 /* Try to lookup an already existing transient saved status */ | 449 /* Try to lookup an already existing transient saved status */ |
381 saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, NULL); | 450 saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, NULL); |
382 | 451 |
383 /* Create a new transient saved status if we weren't able to find one */ | 452 /* Create a new transient saved status if we weren't able to find one */ |
384 if (saved_status == NULL) | 453 if (saved_status == NULL) |
385 saved_status = purple_savedstatus_new(NULL, primitive); | 454 saved_status = create_transient_status(primitive, NULL); |
386 | 455 |
387 /* Set the status for each account */ | 456 /* Set the status for each account */ |
388 purple_savedstatus_activate(saved_status); | 457 purple_savedstatus_activate(saved_status); |
389 } | 458 } |
390 | 459 |
423 gtk_widget_show_all(menuitem); | 492 gtk_widget_show_all(menuitem); |
424 | 493 |
425 return menuitem; | 494 return menuitem; |
426 } | 495 } |
427 | 496 |
497 static void | |
498 add_account_statuses(GtkWidget *menu, PurpleAccount *account) | |
499 { | |
500 GList *l; | |
501 | |
502 for (l = purple_account_get_status_types(account); l != NULL; l = l->next) { | |
503 PurpleStatusType *status_type = (PurpleStatusType *)l->data; | |
504 PurpleStatusPrimitive prim; | |
505 | |
506 if (!purple_status_type_is_user_settable(status_type)) | |
507 continue; | |
508 | |
509 prim = purple_status_type_get_primitive(status_type); | |
510 | |
511 new_menu_item_with_status_icon(menu, | |
512 purple_status_type_get_name(status_type), | |
513 prim, G_CALLBACK(activate_status_account_cb), | |
514 status_type, 0, 0, NULL); | |
515 } | |
516 } | |
517 | |
428 static GtkWidget * | 518 static GtkWidget * |
429 docklet_status_submenu() | 519 docklet_status_submenu() |
430 { | 520 { |
431 GtkWidget *submenu, *menuitem; | 521 GtkWidget *submenu, *menuitem; |
432 GList *popular_statuses, *cur; | 522 GList *popular_statuses, *cur; |
523 PidginStatusBox *statusbox = NULL; | |
433 | 524 |
434 submenu = gtk_menu_new(); | 525 submenu = gtk_menu_new(); |
435 menuitem = gtk_menu_item_new_with_label(_("Change Status")); | 526 menuitem = gtk_menu_item_new_with_label(_("Change Status")); |
436 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | 527 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); |
437 | 528 |
438 new_menu_item_with_status_icon(submenu, _("Available"), | 529 if(pidgin_blist_get_default_gtk_blist() != NULL) { |
439 PURPLE_STATUS_AVAILABLE, G_CALLBACK(activate_status_primitive_cb), | 530 statusbox = PIDGIN_STATUS_BOX(pidgin_blist_get_default_gtk_blist()->statusbox); |
440 GINT_TO_POINTER(PURPLE_STATUS_AVAILABLE), 0, 0, NULL); | 531 } |
441 | 532 |
442 new_menu_item_with_status_icon(submenu, _("Away"), | 533 if(statusbox && statusbox->account != NULL) { |
443 PURPLE_STATUS_AWAY, G_CALLBACK(activate_status_primitive_cb), | 534 add_account_statuses(submenu, statusbox->account); |
444 GINT_TO_POINTER(PURPLE_STATUS_AWAY), 0, 0, NULL); | 535 } else if(statusbox && statusbox->token_status_account != NULL) { |
445 | 536 add_account_statuses(submenu, statusbox->token_status_account); |
446 new_menu_item_with_status_icon(submenu, _("Invisible"), | 537 } else { |
447 PURPLE_STATUS_INVISIBLE, G_CALLBACK(activate_status_primitive_cb), | 538 new_menu_item_with_status_icon(submenu, _("Available"), |
448 GINT_TO_POINTER(PURPLE_STATUS_INVISIBLE), 0, 0, NULL); | 539 PURPLE_STATUS_AVAILABLE, G_CALLBACK(activate_status_primitive_cb), |
449 | 540 GINT_TO_POINTER(PURPLE_STATUS_AVAILABLE), 0, 0, NULL); |
450 new_menu_item_with_status_icon(submenu, _("Offline"), | 541 |
451 PURPLE_STATUS_OFFLINE, G_CALLBACK(activate_status_primitive_cb), | 542 new_menu_item_with_status_icon(submenu, _("Away"), |
452 GINT_TO_POINTER(PURPLE_STATUS_OFFLINE), 0, 0, NULL); | 543 PURPLE_STATUS_AWAY, G_CALLBACK(activate_status_primitive_cb), |
544 GINT_TO_POINTER(PURPLE_STATUS_AWAY), 0, 0, NULL); | |
545 | |
546 new_menu_item_with_status_icon(submenu, _("Do not disturb"), | |
547 PURPLE_STATUS_UNAVAILABLE, G_CALLBACK(activate_status_primitive_cb), | |
548 GINT_TO_POINTER(PURPLE_STATUS_UNAVAILABLE), 0, 0, NULL); | |
549 | |
550 new_menu_item_with_status_icon(submenu, _("Invisible"), | |
551 PURPLE_STATUS_INVISIBLE, G_CALLBACK(activate_status_primitive_cb), | |
552 GINT_TO_POINTER(PURPLE_STATUS_INVISIBLE), 0, 0, NULL); | |
553 | |
554 new_menu_item_with_status_icon(submenu, _("Offline"), | |
555 PURPLE_STATUS_OFFLINE, G_CALLBACK(activate_status_primitive_cb), | |
556 GINT_TO_POINTER(PURPLE_STATUS_OFFLINE), 0, 0, NULL); | |
557 } | |
453 | 558 |
454 popular_statuses = purple_savedstatuses_get_popular(6); | 559 popular_statuses = purple_savedstatuses_get_popular(6); |
455 if (popular_statuses != NULL) | 560 if (popular_statuses != NULL) |
456 pidgin_separator(submenu); | 561 pidgin_separator(submenu); |
457 for (cur = popular_statuses; cur != NULL; cur = cur->next) | 562 for (cur = popular_statuses; cur != NULL; cur = cur->next) |