comparison pidgin/gtkblist.c @ 29995:2292d8896b0b

merged with im.pidgin.pidgin
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 16 Mar 2010 12:07:06 +0900
parents 10c2702ecfff 41c53be0e8b5
children f988f25259c7
comparison
equal deleted inserted replaced
29919:10c2702ecfff 29995:2292d8896b0b
3387 { 3387 {
3388 purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/debug/enabled", 3388 purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/debug/enabled",
3389 !purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled")); 3389 !purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled"));
3390 } 3390 }
3391 3391
3392 static char *get_mood_icon_path(const char *mood)
3393 {
3394 char *path;
3395
3396 if (!strcmp(mood, "busy")) {
3397 path = g_build_filename(DATADIR, "pixmaps", "pidgin",
3398 "status", "16", "busy.png", NULL);
3399 } else if (!strcmp(mood, "hiptop")) {
3400 path = g_build_filename(DATADIR, "pixmaps", "pidgin",
3401 "emblems", "16", "hiptop.png", NULL);
3402 } else {
3403 char *filename = g_strdup_printf("%s.png", mood);
3404 path = g_build_filename(DATADIR, "pixmaps", "pidgin",
3405 "emotes", "small", filename, NULL);
3406 g_free(filename);
3407 }
3408 return path;
3409 }
3410
3411 static void
3412 update_status_with_mood(PurpleAccount *account, const gchar *mood,
3413 const gchar *text)
3414 {
3415 if (mood != NULL && !purple_strequal(mood, "")) {
3416 if (text) {
3417 purple_account_set_status(account, "mood", TRUE,
3418 PURPLE_MOOD_NAME, mood,
3419 PURPLE_MOOD_COMMENT, text,
3420 NULL);
3421 } else {
3422 purple_account_set_status(account, "mood", TRUE,
3423 PURPLE_MOOD_NAME, mood,
3424 NULL);
3425 }
3426 } else {
3427 purple_account_set_status(account, "mood", FALSE, NULL);
3428 }
3429 }
3430
3431 static void
3432 edit_mood_cb(PurpleConnection *gc, PurpleRequestFields *fields)
3433 {
3434 PurpleRequestField *mood_field, *text_field;
3435 GList *l;
3436
3437 mood_field = purple_request_fields_get_field(fields, "mood");
3438 text_field = purple_request_fields_get_field(fields, "text");
3439 l = purple_request_field_list_get_selected(mood_field);
3440
3441 if (l) {
3442 const char *mood = purple_request_field_list_get_data(mood_field, l->data);
3443 const char *text = purple_request_field_string_get_value(text_field);
3444
3445 if (gc) {
3446 PurpleAccount *account = purple_connection_get_account(gc);
3447
3448 update_status_with_mood(account, mood, text);
3449 } else {
3450 GList *accounts = purple_accounts_get_all_active();
3451
3452 for (; accounts ; accounts = g_list_delete_link(accounts, accounts)) {
3453 PurpleAccount *account = (PurpleAccount *) accounts->data;
3454 PurpleConnection *gc = purple_account_get_connection(account);
3455
3456 if (gc->flags && PURPLE_CONNECTION_SUPPORT_MOODS) {
3457 update_status_with_mood(account, mood, text);
3458 }
3459 }
3460 }
3461 }
3462 }
3463
3464 static void
3465 global_moods_for_each(gpointer key, gpointer value, gpointer user_data)
3466 {
3467 GList **out_moods = (GList **) user_data;
3468 PurpleMood *mood = (PurpleMood *) value;
3469
3470 *out_moods = g_list_append(*out_moods, mood);
3471 }
3472
3473 static PurpleMood *
3474 get_global_moods(void)
3475 {
3476 GHashTable *global_moods =
3477 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
3478 GHashTable *mood_counts =
3479 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
3480 GList *accounts = purple_accounts_get_all_active();
3481 PurpleMood *result = NULL;
3482 GList *out_moods = NULL;
3483 int i = 0;
3484 int num_accounts = 0;
3485
3486 for (; accounts ; accounts = g_list_delete_link(accounts, accounts)) {
3487 PurpleAccount *account = (PurpleAccount *) accounts->data;
3488 PurpleConnection *gc = purple_account_get_connection(account);
3489
3490 if (gc->flags & PURPLE_CONNECTION_SUPPORT_MOODS) {
3491 PurplePluginProtocolInfo *prpl_info =
3492 PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
3493 PurpleMood *mood = NULL;
3494
3495 for (mood = prpl_info->get_moods(account) ;
3496 mood->mood != NULL ; mood++) {
3497 int mood_count =
3498 GPOINTER_TO_INT(g_hash_table_lookup(mood_counts, mood->mood));
3499
3500 if (!g_hash_table_lookup(global_moods, mood->mood)) {
3501 g_hash_table_insert(global_moods, g_strdup(mood->mood), mood);
3502 }
3503 g_hash_table_insert(mood_counts, g_strdup(mood->mood),
3504 GINT_TO_POINTER(mood_count + 1));
3505 }
3506
3507 num_accounts++;
3508 }
3509 }
3510
3511 g_hash_table_foreach(global_moods, global_moods_for_each, &out_moods);
3512 result = g_new0(PurpleMood, g_hash_table_size(global_moods) + 1);
3513
3514 while (out_moods) {
3515 PurpleMood *mood = (PurpleMood *) out_moods->data;
3516 int in_num_accounts =
3517 GPOINTER_TO_INT(g_hash_table_lookup(mood_counts, mood->mood));
3518
3519 if (in_num_accounts == num_accounts) {
3520 /* mood is present in all accounts supporting moods */
3521 result[i].mood = mood->mood;
3522 result[i].description = mood->description;
3523 i++;
3524 }
3525 out_moods = g_list_delete_link(out_moods, out_moods);
3526 }
3527
3528 g_hash_table_destroy(global_moods);
3529 g_hash_table_destroy(mood_counts);
3530
3531 return result;
3532 }
3533
3534 /* get current set mood for all mood-supporting accounts, or NULL if not set
3535 or not set to the same on all */
3536 static const gchar *
3537 get_global_mood_status(void)
3538 {
3539 GList *accounts = purple_accounts_get_all_active();
3540 const gchar *found_mood = NULL;
3541
3542 for (; accounts ; accounts = g_list_delete_link(accounts, accounts)) {
3543 PurpleAccount *account = (PurpleAccount *) accounts->data;
3544
3545 if (purple_account_get_connection(account)->flags &
3546 PURPLE_CONNECTION_SUPPORT_MOODS) {
3547 PurplePresence *presence = purple_account_get_presence(account);
3548 PurpleStatus *status = purple_presence_get_status(presence, "mood");
3549 const gchar *curr_mood = purple_status_get_attr_string(status, PURPLE_MOOD_NAME);
3550
3551 if (found_mood != NULL && !purple_strequal(curr_mood, found_mood)) {
3552 /* found a different mood */
3553 found_mood = NULL;
3554 break;
3555 } else {
3556 found_mood = curr_mood;
3557 }
3558 }
3559 }
3560
3561 return found_mood;
3562 }
3563
3564 static void
3565 set_mood_cb(GtkWidget *widget, PurpleAccount *account)
3566 {
3567 const char *current_mood;
3568 PurpleRequestFields *fields;
3569 PurpleRequestFieldGroup *g;
3570 PurpleRequestField *f;
3571 PurpleConnection *gc = NULL;
3572 PurplePluginProtocolInfo *prpl_info = NULL;
3573 PurpleMood *mood;
3574 PurpleMood *global_moods = get_global_moods();
3575
3576 if (account) {
3577 PurplePresence *presence = purple_account_get_presence(account);
3578 PurpleStatus *status = purple_presence_get_status(presence, "mood");
3579 gc = purple_account_get_connection(account);
3580 g_return_if_fail(gc->prpl != NULL);
3581 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
3582 current_mood = purple_status_get_attr_string(status, PURPLE_MOOD_NAME);
3583 } else {
3584 current_mood = get_global_mood_status();
3585 }
3586
3587 fields = purple_request_fields_new();
3588 g = purple_request_field_group_new(NULL);
3589 f = purple_request_field_list_new("mood", _("Please select your mood from the list"));
3590
3591 purple_request_field_list_add(f, _("None"), "");
3592 if (current_mood == NULL)
3593 purple_request_field_list_add_selected(f, _("None"));
3594
3595 /* TODO: rlaager wants this sorted. */
3596 for (mood = account ? prpl_info->get_moods(account) : global_moods;
3597 mood->mood != NULL ; mood++) {
3598 char *path;
3599
3600 if (mood->mood == NULL || mood->description == NULL)
3601 continue;
3602
3603 path = get_mood_icon_path(mood->mood);
3604 purple_request_field_list_add_icon(f, _(mood->description),
3605 path, (gpointer)mood->mood);
3606 g_free(path);
3607
3608 if (current_mood && !strcmp(current_mood, mood->mood))
3609 purple_request_field_list_add_selected(f, _(mood->description));
3610 }
3611 purple_request_field_group_add_field(g, f);
3612
3613 purple_request_fields_add_group(fields, g);
3614
3615 /* if the connection allows setting a mood message */
3616 if (gc && (gc->flags & PURPLE_CONNECTION_SUPPORT_MOOD_MESSAGES)) {
3617 g = purple_request_field_group_new(NULL);
3618 f = purple_request_field_string_new("text",
3619 _("Message (optional)"), NULL, FALSE);
3620 purple_request_field_group_add_field(g, f);
3621 purple_request_fields_add_group(fields, g);
3622 }
3623
3624 purple_request_fields(gc, _("Edit User Mood"), _("Edit User Mood"),
3625 NULL, fields,
3626 _("OK"), G_CALLBACK(edit_mood_cb),
3627 _("Cancel"), NULL,
3628 gc ? purple_connection_get_account(gc) : NULL,
3629 NULL, NULL, gc);
3630
3631 g_free(global_moods);
3632 }
3633
3634 static void
3635 set_mood_show(void)
3636 {
3637 set_mood_cb(NULL, NULL);
3638 }
3392 3639
3393 /*************************************************** 3640 /***************************************************
3394 * Crap * 3641 * Crap *
3395 ***************************************************/ 3642 ***************************************************/
3396 static GtkItemFactoryEntry blist_menu[] = 3643 static GtkItemFactoryEntry blist_menu[] =
3426 { N_("/Tools/_Certificates"), NULL, pidgin_certmgr_show, 0, "<Item>", NULL }, 3673 { N_("/Tools/_Certificates"), NULL, pidgin_certmgr_show, 0, "<Item>", NULL },
3427 { N_("/Tools/Custom Smile_ys"), "<CTL>Y", pidgin_smiley_manager_show, 0, "<StockItem>", PIDGIN_STOCK_TOOLBAR_SMILEY }, 3674 { N_("/Tools/Custom Smile_ys"), "<CTL>Y", pidgin_smiley_manager_show, 0, "<StockItem>", PIDGIN_STOCK_TOOLBAR_SMILEY },
3428 { N_("/Tools/Plu_gins"), "<CTL>U", pidgin_plugin_dialog_show, 2, "<StockItem>", PIDGIN_STOCK_TOOLBAR_PLUGINS }, 3675 { N_("/Tools/Plu_gins"), "<CTL>U", pidgin_plugin_dialog_show, 2, "<StockItem>", PIDGIN_STOCK_TOOLBAR_PLUGINS },
3429 { N_("/Tools/Pr_eferences"), "<CTL>P", pidgin_prefs_show, 0, "<StockItem>", GTK_STOCK_PREFERENCES }, 3676 { N_("/Tools/Pr_eferences"), "<CTL>P", pidgin_prefs_show, 0, "<StockItem>", GTK_STOCK_PREFERENCES },
3430 { N_("/Tools/Pr_ivacy"), NULL, pidgin_privacy_dialog_show, 0, "<Item>", NULL }, 3677 { N_("/Tools/Pr_ivacy"), NULL, pidgin_privacy_dialog_show, 0, "<Item>", NULL },
3678 { N_("/Tools/Set _Mood"), "<CTL>M", set_mood_show, 0, "<Item>", NULL },
3431 { "/Tools/sep2", NULL, NULL, 0, "<Separator>", NULL }, 3679 { "/Tools/sep2", NULL, NULL, 0, "<Separator>", NULL },
3432 { N_("/Tools/_File Transfers"), "<CTL>T", pidgin_xfer_dialog_show, 0, "<StockItem>", PIDGIN_STOCK_TOOLBAR_TRANSFER }, 3680 { N_("/Tools/_File Transfers"), "<CTL>T", pidgin_xfer_dialog_show, 0, "<StockItem>", PIDGIN_STOCK_TOOLBAR_TRANSFER },
3433 { N_("/Tools/R_oom List"), NULL, pidgin_roomlist_dialog_show, 0, "<Item>", NULL }, 3681 { N_("/Tools/R_oom List"), NULL, pidgin_roomlist_dialog_show, 0, "<Item>", NULL },
3434 { N_("/Tools/System _Log"), NULL, gtk_blist_show_systemlog_cb, 3, "<Item>", NULL }, 3682 { N_("/Tools/System _Log"), NULL, gtk_blist_show_systemlog_cb, 3, "<Item>", NULL },
3435 { "/Tools/sep3", NULL, NULL, 0, "<Separator>", NULL }, 3683 { "/Tools/sep3", NULL, NULL, 0, "<Separator>", NULL },
3756 } else 4004 } else
3757 g_free(path); 4005 g_free(path);
3758 } 4006 }
3759 4007
3760 return pb; 4008 return pb;
3761 }
3762
3763 static char *get_mood_icon_path(const char *mood)
3764 {
3765 char *path;
3766
3767 if (!strcmp(mood, "busy")) {
3768 path = g_build_filename(DATADIR, "pixmaps", "pidgin",
3769 "status", "16", "busy.png", NULL);
3770 } else if (!strcmp(mood, "hiptop")) {
3771 path = g_build_filename(DATADIR, "pixmaps", "pidgin",
3772 "emblems", "16", "hiptop.png", NULL);
3773 } else {
3774 char *filename = g_strdup_printf("%s.png", mood);
3775 path = g_build_filename(DATADIR, "pixmaps", "pidgin",
3776 "emotes", "small", filename, NULL);
3777 g_free(filename);
3778 }
3779 return path;
3780 } 4009 }
3781 4010
3782 GdkPixbuf * 4011 GdkPixbuf *
3783 pidgin_blist_get_emblem(PurpleBlistNode *node) 4012 pidgin_blist_get_emblem(PurpleBlistNode *node)
3784 { 4013 {
7819 PurpleAccount *account = data; 8048 PurpleAccount *account = data;
7820 8049
7821 purple_account_set_enabled(account, PIDGIN_UI, FALSE); 8050 purple_account_set_enabled(account, PIDGIN_UI, FALSE);
7822 } 8051 }
7823 8052
7824 static void 8053
7825 edit_mood_cb(PurpleConnection *gc, PurpleRequestFields *fields)
7826 {
7827 PurpleRequestField *f;
7828 GList *l;
7829
7830 f = purple_request_fields_get_field(fields, "mood");
7831 l = purple_request_field_list_get_selected(f);
7832
7833 if (l) {
7834 const char *mood = purple_request_field_list_get_data(f, l->data);
7835 PurpleAccount *account = purple_connection_get_account(gc);
7836
7837 if (mood != NULL && !purple_strequal(mood, "")) {
7838 purple_account_set_status(account, "mood", TRUE,
7839 PURPLE_MOOD_NAME, mood,
7840 NULL);
7841 } else {
7842 purple_account_set_status(account, "mood", FALSE, NULL);
7843 }
7844 }
7845 }
7846
7847 static void
7848 set_mood_cb(GtkWidget *widget, PurpleAccount *account)
7849 {
7850 PurplePresence *presence = purple_account_get_presence(account);
7851 PurpleStatus *status = purple_presence_get_status(presence, "mood");
7852 const char *current_mood;
7853 PurpleRequestFields *fields;
7854 PurpleRequestFieldGroup *g;
7855 PurpleRequestField *f;
7856 PurpleConnection *gc = purple_account_get_connection(account);
7857 PurplePluginProtocolInfo *prpl_info;
7858 PurpleMood *mood;
7859
7860 g_return_if_fail(gc->prpl != NULL);
7861 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
7862
7863 current_mood = purple_status_get_attr_string(status, PURPLE_MOOD_NAME);
7864
7865 fields = purple_request_fields_new();
7866 g = purple_request_field_group_new(NULL);
7867 f = purple_request_field_list_new("mood", _("Please select your mood from the list"));
7868
7869 purple_request_field_list_add(f, _("None"), "");
7870 if (current_mood == NULL)
7871 purple_request_field_list_add_selected(f, _("None"));
7872
7873 /* TODO: rlaager wants this sorted. */
7874 for (mood = prpl_info->get_moods(account);
7875 mood->mood != NULL ; mood++) {
7876 char *path;
7877
7878 if (mood->mood == NULL || mood->description == NULL)
7879 continue;
7880
7881 path = get_mood_icon_path(mood->mood);
7882 purple_request_field_list_add_icon(f, _(mood->description),
7883 path, (gpointer)mood->mood);
7884 g_free(path);
7885
7886 if (current_mood && !strcmp(current_mood, mood->mood))
7887 purple_request_field_list_add_selected(f, _(mood->description));
7888 }
7889 purple_request_field_group_add_field(g, f);
7890
7891 purple_request_fields_add_group(fields, g);
7892
7893 purple_request_fields(gc, _("Edit User Mood"), _("Edit User Mood"),
7894 NULL, fields,
7895 _("OK"), G_CALLBACK(edit_mood_cb),
7896 _("Cancel"), NULL,
7897 purple_connection_get_account(gc),
7898 NULL, NULL, gc);
7899 }
7900 8054
7901 void 8055 void
7902 pidgin_blist_update_accounts_menu(void) 8056 pidgin_blist_update_accounts_menu(void)
7903 { 8057 {
7904 GtkWidget *menuitem = NULL, *submenu = NULL; 8058 GtkWidget *menuitem = NULL, *submenu = NULL;
8021 8175
8022 if (prpl_info && 8176 if (prpl_info &&
8023 (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) || 8177 (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) ||
8024 PURPLE_PLUGIN_HAS_ACTIONS(plugin))) { 8178 PURPLE_PLUGIN_HAS_ACTIONS(plugin))) {
8025 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) && 8179 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) &&
8026 prpl_info->get_moods(account) != NULL) { 8180 gc->flags & PURPLE_CONNECTION_SUPPORT_MOODS) {
8027 GList *types; 8181 GList *types;
8028 8182
8029 for (types = purple_account_get_status_types(account); 8183 for (types = purple_account_get_status_types(account);
8030 types != NULL ; types = types->next) { 8184 types != NULL ; types = types->next) {
8031 PurpleStatusType *type = types->data; 8185 PurpleStatusType *type = types->data;