static void remove_account_info(const gchar *accountid) { GHashTable *table = dt_pwstorage_get("facebook"); g_hash_table_remove(table, accountid); dt_pwstorage_set("facebook", table); g_hash_table_destroy(table); }
static void save_account_info(dt_storage_facebook_gui_data_t *ui, FBAccountInfo *accountinfo) { FBContext *ctx = ui->facebook_api; g_return_if_fail(ctx != NULL); ///serialize data; JsonBuilder *builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "username"); json_builder_add_string_value(builder, accountinfo->username); json_builder_set_member_name(builder, "token"); json_builder_add_string_value(builder, accountinfo->token); json_builder_end_object(builder); JsonNode *node = json_builder_get_root(builder); JsonGenerator *generator = json_generator_new(); json_generator_set_root(generator, node); #if JSON_CHECK_VERSION(0, 14, 0) json_generator_set_pretty(generator, FALSE); #endif gchar *data = json_generator_to_data(generator, NULL); json_node_free(node); g_object_unref(generator); g_object_unref(builder); GHashTable *table = dt_pwstorage_get("facebook"); g_hash_table_insert(table, accountinfo->id, data); dt_pwstorage_set("facebook", table); g_hash_table_destroy(table); }
static void remove_account_info(const gchar *accountid) { GHashTable *table = dt_pwstorage_get(GPHOTO_STORAGE); g_hash_table_remove(table, accountid); dt_pwstorage_set(GPHOTO_STORAGE, table); g_hash_table_destroy(table); }
static void _piwigo_set_account(dt_storage_piwigo_gui_data_t *ui) { /// serialize data; JsonBuilder *builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "server"); json_builder_add_string_value(builder, gtk_entry_get_text(ui->server_entry)); json_builder_set_member_name(builder, "username"); json_builder_add_string_value(builder, gtk_entry_get_text(ui->user_entry)); json_builder_set_member_name(builder, "password"); json_builder_add_string_value(builder, gtk_entry_get_text(ui->pwd_entry)); json_builder_end_object(builder); JsonNode *node = json_builder_get_root(builder); JsonGenerator *generator = json_generator_new(); json_generator_set_root(generator, node); #if JSON_CHECK_VERSION(0, 14, 0) json_generator_set_pretty(generator, FALSE); #endif gchar *data = json_generator_to_data(generator, NULL); json_node_free(node); g_object_unref(generator); g_object_unref(builder); GHashTable *table = dt_pwstorage_get("piwigo"); g_hash_table_insert(table, g_strdup(gtk_entry_get_text(ui->server_entry)), data); dt_pwstorage_set("piwigo", table); g_hash_table_destroy(table); }
_flickr_api_context_t static *_flickr_api_authenticate(dt_storage_flickr_gui_data_t *ui) { char *perms = NULL, *frob; gchar *token; char *flickr_user_token = NULL; gint result; _flickr_api_context_t *ctx = (_flickr_api_context_t *)g_malloc(sizeof(_flickr_api_context_t)); memset(ctx,0,sizeof(_flickr_api_context_t)); flickcurl_init (); ctx->fc = flickcurl_new (); flickcurl_set_api_key (ctx->fc, API_KEY); flickcurl_set_shared_secret (ctx->fc, SHARED_SECRET); flickcurl_set_error_handler(ctx->fc, _flickr_api_error_handler, ctx); if (!ui->user_token) { // Retrieve stored auth_key // TODO: We should be able to store token for different users GHashTable* table = dt_pwstorage_get("flickr"); gchar * _username = g_strdup( g_hash_table_lookup(table, "username")); gchar *_user_token = g_strdup( g_hash_table_lookup(table, "token")); g_hash_table_destroy(table); if (_username) { if (!strcmp(_username,gtk_entry_get_text(ui->entry1))) { flickr_user_token = g_strdup(_user_token); perms = flickcurl_auth_checkToken(ctx->fc, flickr_user_token); } g_free (_username); } if (_user_token) g_free (_user_token); } else { flickr_user_token = ui->user_token; perms = flickcurl_auth_checkToken(ctx->fc, ui->user_token); } if (perms) { ui->user_token = flickr_user_token; flickcurl_set_auth_token(ctx->fc, flickr_user_token); return ctx; } else if (!ctx->error_occured) { frob = flickcurl_auth_getFrob(ctx->fc); GError *error = NULL; char *sign = g_strdup_printf ("%sapi_key%sfrob%spermswrite", SHARED_SECRET, API_KEY, frob); char *sign_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, sign, strlen (sign)); gchar auth_url[250]; sprintf(auth_url,"http://flickr.com/services/auth/?api_key=%s&perms=write&frob=%s&api_sig=%s", API_KEY, frob, sign_md5); gtk_show_uri (gdk_screen_get_default(), auth_url, gtk_get_current_event_time (), &error); g_free(sign); g_free(sign_md5); // Hold here to let the user interact // Show a dialog. gchar *text1, *text2; text1 = g_strdup(_("step 1: a new window or tab of your browser should have been loaded. you have to login into your flickr account there and authorize darktable to upload photos before continuing.")); text2 = g_strdup(_("step 2: click the OK button once you are done.")); GtkWidget *window = dt_ui_main_window(darktable.gui->ui); GtkWidget *flickr_auth_dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK_CANCEL, _("flickr authentication")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (flickr_auth_dialog), "%s\n\n%s", text1, text2); result = gtk_dialog_run (GTK_DIALOG (flickr_auth_dialog)); gtk_widget_destroy(flickr_auth_dialog); g_free (text1); g_free (text2); switch (result) { case GTK_RESPONSE_OK: token = flickcurl_auth_getToken(ctx->fc, frob); g_free(frob); // TODO: Handle timeouts errors if (token) { flickr_user_token = g_strdup (token); } else { g_free(token); _flickr_api_free(ctx); return NULL; } ui->user_token = g_strdup(flickr_user_token); flickcurl_set_auth_token(ctx->fc, flickr_user_token); /* Add creds to pwstorage */ GHashTable *table = g_hash_table_new(g_str_hash, g_str_equal); gchar* username = g_strdup(gtk_entry_get_text(ui->entry1)); g_hash_table_insert(table, "username", username); g_hash_table_insert(table, "token", flickr_user_token); if( !dt_pwstorage_set("flickr", table) ) { dt_print(DT_DEBUG_PWSTORAGE,"[flickr] cannot store username/token\n"); } g_free(flickr_user_token); g_hash_table_destroy(table); return ctx; break; default: dt_print(DT_DEBUG_PWSTORAGE,"[flickr] user cancelled the login process\n"); return NULL; } } if (perms) free(perms); return NULL; }
/** Refresh albums */ static void refresh_albums(dt_storage_picasa_gui_data_t *ui) { gtk_widget_set_sensitive( GTK_WIDGET(ui->comboBox1), FALSE); if( ui->picasa_api == NULL || ui->picasa_api->needsReauthentication == TRUE ) { if( ui->picasa_api ) _picasa_api_free( ui->picasa_api); ui->picasa_api = _picasa_api_authenticate(gtk_entry_get_text(ui->entry1),gtk_entry_get_text(ui->entry2)); } // First clear the model of data except first item (Create new album) GtkTreeModel *model=gtk_combo_box_get_model(ui->comboBox1); gtk_list_store_clear (GTK_LIST_STORE(model)); if( ui->picasa_api ) { set_status(ui,_("authenticated"), "#7fe07f"); /* Add creds to pwstorage */ GHashTable *table = g_hash_table_new(g_str_hash, g_str_equal); gchar* username = g_strdup(gtk_entry_get_text(ui->entry1)); gchar* password = g_strdup(gtk_entry_get_text(ui->entry2)); g_hash_table_insert(table, "username", username); g_hash_table_insert(table, "password", password); if( !dt_pwstorage_set("picasa", table) ) { dt_print(DT_DEBUG_PWSTORAGE,"[picasa] cannot store username/password\n"); } g_free(username); g_free(password); g_hash_table_destroy(table); if( _picasa_api_get_feed(ui->picasa_api) == 200) { // Add standard action gtk_combo_box_append_text( ui->comboBox1, _("create new album") ); gtk_combo_box_append_text( ui->comboBox1, "" );// Separator // Then add albums from list... GList *album=g_list_first(ui->picasa_api->albums); if( album != NULL ) { for(int i=0; i<g_list_length(ui->picasa_api->albums); i++) { char data[512]= {0}; sprintf(data,"%s (%s)", ((_picasa_album_t*)g_list_nth_data(ui->picasa_api->albums,i))->title, ((_picasa_album_t*)g_list_nth_data(ui->picasa_api->albums,i))->photoCount ); gtk_combo_box_append_text( ui->comboBox1, g_strdup(data)); } gtk_combo_box_set_active( ui->comboBox1, 2); gtk_widget_hide( GTK_WIDGET(ui->hbox1) ); // Hide create album box... } else gtk_combo_box_set_active( ui->comboBox1, 0); } else { // Failed to parse feed of album... // Lets notify somehow... } gtk_widget_set_sensitive( GTK_WIDGET(ui->comboBox1), TRUE); } else { // Failed to authenticated, let's notify somehow... set_status(ui,_("authentication failed"),"#e07f7f"); gtk_widget_set_sensitive(GTK_WIDGET( ui->comboBox1 ) ,FALSE); } }