Thu, 14 Aug 2008 19:47:00 +0000
Made more calls asynch, enhanced error checking and reporting.
| finch/gntaccount.c | file | annotate | diff | comparison | revisions | |
| finch/gntprefs.c | file | annotate | diff | comparison | revisions | |
| libpurple/keyring.c | file | annotate | diff | comparison | revisions | |
| libpurple/keyring.h | file | annotate | diff | comparison | revisions | |
| pidgin/gtkaccount.c | file | annotate | diff | comparison | revisions |
--- a/finch/gntaccount.c Wed Aug 13 21:48:58 2008 +0000 +++ b/finch/gntaccount.c Thu Aug 14 19:47:00 2008 +0000 @@ -58,6 +58,9 @@ static FinchAccountList accounts; +static void edit_account_continue(PurpleAccount * account, + const gchar * password, GError * error, gpointer user_data); + typedef struct { PurpleAccount *account; /* NULL for a new account */ @@ -173,9 +176,9 @@ gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->remember))); value = gnt_entry_get_text(GNT_ENTRY(dialog->password)); if (value && *value) - purple_account_set_password(account, value); + purple_account_set_password_async(account, g_strdup(value), g_free, NULL, NULL); else - purple_account_set_password(account, NULL); + purple_account_set_password_async(account, NULL, NULL, NULL, NULL); /* Mail notification */ purple_account_set_check_mail(account, @@ -484,11 +487,21 @@ static void edit_account(PurpleAccount *account) { + purple_account_get_password_async(account, edit_account_continue, account); +} + +static void +edit_account_continue(PurpleAccount * account, + const gchar * password, GError * error, gpointer user_data) +{ GntWidget *window, *hbox; GntWidget *combo, *button, *entry; GList *list, *iter; AccountEditDialog *dialog; + if (error) + g_error_free(error); + if (account) { GList *iter; @@ -563,7 +576,7 @@ gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Password:"))); gnt_box_add_widget(GNT_BOX(hbox), entry); if (account) - gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_password(account)); + gnt_entry_set_text(GNT_ENTRY(entry), password); hbox = gnt_hbox_new(TRUE); gnt_box_set_pad(GNT_BOX(hbox), 0);
--- a/finch/gntprefs.c Wed Aug 13 21:48:58 2008 +0000 +++ b/finch/gntprefs.c Thu Aug 14 19:47:00 2008 +0000 @@ -1,6 +1,7 @@ /** * @file gntprefs.c GNT Preferences API * @ingroup finch + * @todo : add support for master password changing. */ /* finch @@ -80,6 +81,13 @@ } Prefs; static GList * +get_keyring_options(void) +{ + return purple_keyring_get_options(); +} + + +static GList * get_log_options(void) { return purple_log_logger_get_options(); @@ -202,6 +210,11 @@ {PURPLE_PREF_NONE, NULL, NULL, NULL}, }; +static Prefs keyring[] = +{ + {PURPLE_PREF_STRING, "/purple/keyring/active", N_("Active keyring"), purple_keyring_get_options} +}; + static Prefs idle[] = { {PURPLE_PREF_STRING, "/purple/away/idle_reporting", N_("Report Idle time"), get_idle_options}, @@ -257,6 +270,7 @@ add_pref_group(fields, _("Buddy List"), blist); add_pref_group(fields, _("Conversations"), convs); + add_pref_group(fields, _("Keyring"), keyring); add_pref_group(fields, _("Logging"), logging); add_pref_group(fields, _("Idle"), idle);
--- a/libpurple/keyring.c Wed Aug 13 21:48:58 2008 +0000 +++ b/libpurple/keyring.c Thu Aug 14 19:47:00 2008 +0000 @@ -1,6 +1,8 @@ /** * @file keyring.c Keyring plugin API * @ingroup core + * @todo ? : add dummy callback to all calls to prevent poorly written + * plugins from segfaulting on NULL callback ? */ /* purple @@ -32,6 +34,7 @@ #include "core.h" #include "debug.h" +typedef struct _PurpleKeyringCbInfo PurpleKeyringCbInfo; typedef struct _PurpleKeyringChangeTracker PurpleKeyringChangeTracker; static void purple_keyring_pref_cb(const char *, PurplePrefType, gconstpointer, gpointer); @@ -76,6 +79,12 @@ gboolean force; }; +struct _PurpleKeyringCbInfo +{ + gpointer cb; + gpointer data; +}; + /* Constructor */ PurpleKeyring * purple_keyring_new() @@ -279,8 +288,6 @@ /***************************************/ /** @name Keyring API */ -/** @todo (maybe) */ -/** - rename as purple_keyrings */ /***************************************/ /*@{*/ @@ -375,7 +382,6 @@ /* fire and forget */ -/** @todo ? : add dummy callback ? */ static void purple_keyring_drop_passwords(const PurpleKeyring * keyring) { @@ -451,10 +457,7 @@ if (tracker->finished == TRUE && tracker->read_outstanding == 0) { if (tracker->abort == TRUE && tracker->force == FALSE) { - /** - * TODO : - * - create faulty keyring to test this code. - */ + if (tracker->cb != NULL) tracker->cb(tracker->old, FALSE, tracker->error, tracker->data); @@ -467,8 +470,8 @@ purple_debug_info("keyring", "Failed to change keyring, aborting"); - /* FIXME : this should maybe be in a callback - * cancel the prefs change + /** + * FIXME : call purple_notify() */ purple_prefs_disconnect_callback(purple_keyring_pref_cb_id); purple_prefs_set_string("/purple/keyring/active", @@ -664,7 +667,7 @@ new = purple_keyring_get_keyring_by_id(id); g_return_if_fail(new != NULL); - purple_keyring_set_inuse(new, FALSE, NULL, data); /* FIXME Maybe this should have a callback that can cancel the action */ + purple_keyring_set_inuse(new, FALSE, NULL, data); return; } @@ -733,7 +736,6 @@ purple_debug_info("keyring", "Keyring %s matches keyring to use, using it.\n", keyring->id); - /** @todo add callback to make sure all is ok */ purple_keyring_set_inuse(keyring, TRUE, NULL, NULL); } @@ -771,7 +773,6 @@ if (inuse == keyring) { if (inuse != fallback) { - /* TODO : check result ? */ purple_keyring_set_inuse(fallback, TRUE, NULL, NULL); } else { @@ -783,7 +784,7 @@ purple_keyring_keyrings = g_list_remove(purple_keyring_keyrings, keyring); - //purple_debug_info("keyring", "Keyring %s unregistered", keyring->id); + purple_debug_info("keyring", "Keyring %s unregistered", keyring->id); } @@ -971,6 +972,7 @@ GError * error = NULL; const PurpleKeyring * inuse; PurpleKeyringSave save; + PurpleKeyringCbInfo * cbinfo; if (account == NULL) { error = g_error_new(ERR_PIDGINKEYRING, ERR_INVALID, @@ -1006,7 +1008,10 @@ g_error_free(error); } else { - save(account, password, destroypassword, cb, data); + cbinfo->cb = cb; + cbinfo->data = data; + save(account, password, destroypassword, + purple_keyring_set_password_async, data); } } } @@ -1014,7 +1019,22 @@ return; } +void +purple_keyring_set_password_async_cb(PurpleAccount * account, + GError * error, + gpointer data) +{ + PurpleKeyringCbInfo * cbinfo = data; + PurpleKeyringSaveCallback cb = cbinfo->cb; + if (error != NULL) { + /* FIXME : purple_notify_warning() */ + } + + if (cb != NULL) + cb(account, error, cbinfo->data); + g_free(data); +} /** * This should be dropped at 3.0 (it's here for compatibility) */
--- a/libpurple/keyring.h Wed Aug 13 21:48:58 2008 +0000 +++ b/libpurple/keyring.h Thu Aug 14 19:47:00 2008 +0000 @@ -67,8 +67,8 @@ * @param error Error that could have occured. Must be freed by the calling function. * @param data Data passed to the callback. */ -typedef void (*PurpleKeyringReadCallback)(const PurpleAccount * account, - const gchar * password, +typedef void (*PurpleKeyringReadCallback)(PurpleAccount * account, + gchar * password, GError * error, gpointer data);
--- a/pidgin/gtkaccount.c Wed Aug 13 21:48:58 2008 +0000 +++ b/pidgin/gtkaccount.c Thu Aug 14 19:47:00 2008 +0000 @@ -144,6 +144,8 @@ static void add_account_to_liststore(PurpleAccount *account, gpointer user_data); static void set_account(GtkListStore *store, GtkTreeIter *iter, PurpleAccount *account, GdkPixbuf *global_buddyicon); +static void add_login_options_continue(PurpleAccount * account, + const gchar * password, GError * error, gpointer user_data); /************************************************************************** * Add/Modify Account dialog @@ -390,9 +392,33 @@ gtk_widget_set_sensitive((GtkWidget *)l->data, set); } +typedef struct _AddLoginOptionsCalbackData { + AccountPrefsDialog *dialog; + GtkWidget *parent; +} AddLoginOptionsCallbackData; + static void add_login_options(AccountPrefsDialog *dialog, GtkWidget *parent) { + + AddLoginOptionsCallbackData *data; + data = g_new(AddLoginOptionsCallbackData, 1); + + data->dialog = dialog; + data->parent = parent; + + purple_account_get_password_async(dialog->account, add_login_options_continue, data); +} + +static void +add_login_options_continue(PurpleAccount * account, + const gchar * password, + GError * error, + gpointer user_data) +{ + AddLoginOptionsCallbackData * data = user_data; + AccountPrefsDialog *dialog = data->dialog; + GtkWidget *parent = data->parent; GtkWidget *frame; GtkWidget *hbox; GtkWidget *vbox; @@ -402,7 +428,10 @@ GList *user_splits; GList *l, *l2; char *username = NULL; - char *password = NULL; + + /* XXX : report error ? */ + if (error) + g_error_free(error); if (dialog->protocol_menu != NULL) { @@ -562,7 +591,6 @@ /* Set the fields. */ if (dialog->account != NULL) { - password = purple_account_get_password(dialog->account); if (password) gtk_entry_set_text(GTK_ENTRY(dialog->password_entry), password);