pidgin/gtkaccount.c

changeset 40691
c75a82bd0957
parent 40680
f9ea6d5e8992
child 40694
493d2a76c01b
equal deleted inserted replaced
40690:8aadc4b6a592 40691:c75a82bd0957
1581 {"text/uri-list", 0, 1}, 1581 {"text/uri-list", 0, 1},
1582 {"STRING", 0, 2} 1582 {"STRING", 0, 2}
1583 }; 1583 };
1584 1584
1585 static void 1585 static void
1586 pidgin_account_dialog_show_continue(GObject *obj, GAsyncResult *res, 1586 pidgin_account_dialog_show_continue(PidginAccountDialogType type,
1587 gpointer data) 1587 PurpleAccount *account,
1588 { 1588 const gchar *password)
1589 PurpleCredentialManager *manager = PURPLE_CREDENTIAL_MANAGER(obj); 1589 {
1590 PidginAccountDialogShowData *d = (PidginAccountDialogShowData *)data;
1591 PurpleAccount *account = NULL;
1592 PidginAccountDialogType type = 0;
1593 AccountPrefsDialog *dialog; 1590 AccountPrefsDialog *dialog;
1594 GtkWidget *win; 1591 GtkWidget *win;
1595 GtkWidget *main_vbox; 1592 GtkWidget *main_vbox;
1596 GtkWidget *vbox; 1593 GtkWidget *vbox;
1597 GtkWidget *dbox; 1594 GtkWidget *dbox;
1598 GtkWidget *notebook; 1595 GtkWidget *notebook;
1599 GtkWidget *button; 1596 GtkWidget *button;
1600 gchar *password = NULL;
1601
1602 /* we needed a struct to pass multiple pointers to here, but now that we
1603 * have them, we can free it.
1604 */
1605 account = d->account;
1606 type = d->type;
1607 g_free(d);
1608 1597
1609 if (accounts_window != NULL && account != NULL && 1598 if (accounts_window != NULL && account != NULL &&
1610 (dialog = g_hash_table_lookup(account_pref_wins, account)) != NULL) 1599 (dialog = g_hash_table_lookup(account_pref_wins, account)) != NULL)
1611 { 1600 {
1612 gtk_window_present(GTK_WINDOW(dialog->window)); 1601 gtk_window_present(GTK_WINDOW(dialog->window));
1613 return; 1602 return;
1614 } 1603 }
1615 1604
1616 dialog = g_new0(AccountPrefsDialog, 1); 1605 dialog = g_new0(AccountPrefsDialog, 1);
1617 1606
1618 if (account == NULL) { 1607 if(account == NULL) {
1619 /* Select the first protocol in the list*/ 1608 /* Select the first protocol in the list*/
1620 GList *protocol_list = purple_protocols_get_all(); 1609 GList *protocol_list = purple_protocols_get_all();
1621 if (protocol_list != NULL) { 1610 if (protocol_list != NULL) {
1622 dialog->protocol_id = g_strdup(purple_protocol_get_id(PURPLE_PROTOCOL(protocol_list->data))); 1611 dialog->protocol_id = g_strdup(purple_protocol_get_id(PURPLE_PROTOCOL(protocol_list->data)));
1623 g_list_free(protocol_list); 1612 g_list_free(protocol_list);
1624 } 1613 }
1625 } 1614 } else {
1626 else
1627 {
1628 dialog->protocol_id = 1615 dialog->protocol_id =
1629 g_strdup(purple_account_get_protocol_id(account)); 1616 g_strdup(purple_account_get_protocol_id(account));
1630 } 1617 }
1631 1618
1632 /* TODO if no protocols are loaded, this should inform the user that 1619 /* TODO if no protocols are loaded, this should inform the user that
1639 if (accounts_window != NULL && account != NULL) 1626 if (accounts_window != NULL && account != NULL)
1640 { 1627 {
1641 g_hash_table_insert(account_pref_wins, account, dialog); 1628 g_hash_table_insert(account_pref_wins, account, dialog);
1642 } 1629 }
1643 1630
1644 /* The dialog will take ownership of this pointer */
1645 password = purple_credential_manager_read_password_finish(manager, res,
1646 NULL);
1647
1648 dialog->account = account; 1631 dialog->account = account;
1649 dialog->password = password; 1632 dialog->password = g_strdup(password);
1650 dialog->type = type; 1633 dialog->type = type;
1651 dialog->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); 1634 dialog->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1652 dialog->protocol = purple_protocols_find(dialog->protocol_id); 1635 dialog->protocol = purple_protocols_find(dialog->protocol_id);
1653 1636
1654 dialog->window = win = pidgin_dialog_new((type == PIDGIN_ADD_ACCOUNT_DIALOG) ? _("Add Account") : _("Modify Account"), 1637 dialog->window = win = pidgin_dialog_new((type == PIDGIN_ADD_ACCOUNT_DIALOG) ? _("Add Account") : _("Modify Account"),
1728 gtk_widget_show(win); 1711 gtk_widget_show(win);
1729 if (!account) 1712 if (!account)
1730 gtk_widget_grab_focus(dialog->protocol_menu); 1713 gtk_widget_grab_focus(dialog->protocol_menu);
1731 } 1714 }
1732 1715
1716 static void
1717 pidgin_account_dialog_read_password_cb(GObject *obj, GAsyncResult *res,
1718 gpointer data)
1719 {
1720 PurpleCredentialManager *manager = PURPLE_CREDENTIAL_MANAGER(obj);
1721 PidginAccountDialogShowData *d = (PidginAccountDialogShowData *)data;
1722 gchar *password;
1723
1724 password = purple_credential_manager_read_password_finish(manager, res,
1725 NULL);
1726
1727 pidgin_account_dialog_show_continue(d->type, d->account, password);
1728
1729 g_free(password);
1730 g_free(d);
1731 }
1732
1733 void 1733 void
1734 pidgin_account_dialog_show(PidginAccountDialogType type, PurpleAccount *account) 1734 pidgin_account_dialog_show(PidginAccountDialogType type, PurpleAccount *account)
1735 { 1735 {
1736 PurpleCredentialManager *manager = NULL; 1736 PurpleCredentialManager *manager = NULL;
1737 PidginAccountDialogShowData *data = NULL; 1737 PidginAccountDialogShowData *data = NULL;
1743 data->account = account; 1743 data->account = account;
1744 data->type = type; 1744 data->type = type;
1745 1745
1746 manager = purple_credential_manager_get_default(); 1746 manager = purple_credential_manager_get_default();
1747 1747
1748 /* this is to make sure the password will be cached */ 1748 if(PURPLE_IS_ACCOUNT(account)) {
1749 purple_credential_manager_read_password_async(manager, account, NULL, 1749 purple_credential_manager_read_password_async(manager, account, NULL,
1750 pidgin_account_dialog_show_continue, 1750 pidgin_account_dialog_read_password_cb,
1751 data); 1751 data);
1752 } else {
1753 pidgin_account_dialog_show_continue(type, account, NULL);
1754 }
1752 } 1755 }
1753 1756
1754 /************************************************************************** 1757 /**************************************************************************
1755 * Accounts Dialog 1758 * Accounts Dialog
1756 **************************************************************************/ 1759 **************************************************************************/

mercurial