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