static void ui_authenticate_finish(dt_storage_facebook_gui_data_t *ui, gboolean mustsaveaccount) { FBContext *ctx = ui->facebook_api; if(ctx->token == NULL) goto error; if(mustsaveaccount) { FBAccountInfo *accountinfo = fb_get_account_info(ui->facebook_api); if(accountinfo == NULL) goto error; save_account_info(ui, accountinfo); // add account to user list and select it GtkListStore *model = GTK_LIST_STORE(gtk_combo_box_get_model(ui->comboBox_username)); GtkTreeIter iter; gboolean r; gchar *uid; gboolean updated = FALSE; for(r = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter); r == TRUE; r = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter)) { gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, COMBO_USER_MODEL_ID_COL, &uid, -1); if(g_strcmp0(uid, accountinfo->id) == 0) { gtk_list_store_set(model, &iter, COMBO_USER_MODEL_NAME_COL, accountinfo->readablename, COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, -1); updated = TRUE; break; } } if(!updated) { gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, COMBO_USER_MODEL_NAME_COL, accountinfo->readablename, COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, COMBO_USER_MODEL_ID_COL, accountinfo->id, -1); } gtk_combo_box_set_active_iter(ui->comboBox_username, &iter); // we have to re-set the current token here since ui_combo_username_changed is called // on gtk_combo_box_set_active_iter (and thus is resetting the active token) ctx->token = g_strdup(accountinfo->token); fb_account_info_destroy(accountinfo); } ui_refresh_albums(ui); ui->connected = TRUE; gtk_button_set_label(ui->button_login, _("logout")); gtk_widget_set_sensitive(GTK_WIDGET(ui->comboBox_album), TRUE); return; error: gtk_button_set_label(ui->button_login, _("login")); gtk_widget_set_sensitive(GTK_WIDGET(ui->comboBox_album), FALSE); }
static gboolean ui_authenticate(dt_storage_facebook_gui_data_t *ui) { if (ui->facebook_api == NULL) { ui->facebook_api = fb_api_init(); } FBContext *ctx = ui->facebook_api; gboolean mustsaveaccount = FALSE; gchar *uiselectedaccounttoken = NULL; GtkTreeIter iter; gtk_combo_box_get_active_iter(ui->comboBox_username, &iter); GtkTreeModel *accountModel = gtk_combo_box_get_model(ui->comboBox_username); gtk_tree_model_get(accountModel, &iter, 1, &uiselectedaccounttoken, -1); if (ctx->token != NULL) { g_free(ctx->token); ctx->token = NULL; } if (uiselectedaccounttoken != NULL) { ctx->token = g_strdup(uiselectedaccounttoken); } //check selected token if we already have one if (ctx->token != NULL && !fb_test_auth_token(ctx)) { g_free(ctx->token); ctx->token = NULL; } if(ctx->token == NULL) { mustsaveaccount = TRUE; ctx->token = facebook_get_user_auth_token(ui);//ask user to log in } if (ctx->token == NULL) { return FALSE; } else { if (mustsaveaccount) { FBAccountInfo *accountinfo = fb_get_account_info(ui->facebook_api); g_return_val_if_fail(accountinfo != NULL, FALSE); save_account_info(ui, accountinfo); //add account to user list and select it GtkListStore *model = GTK_LIST_STORE(gtk_combo_box_get_model(ui->comboBox_username)); GtkTreeIter iter; gboolean r; gchar *uid; gboolean updated = FALSE; for (r = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(model), &iter); r == TRUE; r = gtk_tree_model_iter_next (GTK_TREE_MODEL(model), &iter)) { gtk_tree_model_get (GTK_TREE_MODEL(model), &iter, COMBO_USER_MODEL_ID_COL, &uid, -1); if (g_strcmp0(uid, accountinfo->id) == 0) { gtk_list_store_set(model, &iter, COMBO_USER_MODEL_NAME_COL, accountinfo->username, COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, -1); updated = TRUE; break; } } if (!updated) { gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, COMBO_USER_MODEL_NAME_COL, accountinfo->username, COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, COMBO_USER_MODEL_ID_COL, accountinfo->id, -1); } gtk_combo_box_set_active_iter(ui->comboBox_username, &iter); //we have to re-set the current token here since ui_combo_username_changed is called //on gtk_combo_box_set_active_iter (and thus is resetting the active token) ctx->token = g_strdup(accountinfo->token); fb_account_info_destroy(accountinfo); } return TRUE; } }