コード例 #1
0
ファイル: flickr.c プロジェクト: drinkcat/darktable
void
free_params(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *params)
{
  dt_storage_flickr_params_t *d = (dt_storage_flickr_params_t *)params;

  _flickr_api_free(  d->flickr_api ); //TODO

  free(params);
}
コード例 #2
0
ファイル: flickr.c プロジェクト: drinkcat/darktable
/** Refresh albums */
void static refresh_albums(dt_storage_flickr_gui_data_t *ui)
{
  int i;
  gtk_widget_set_sensitive( GTK_WIDGET(ui->comboBox1), FALSE);

  if (ui->flickr_api == NULL || ui->flickr_api->needsReauthentication == TRUE)
  {
    if (ui->flickr_api != NULL) _flickr_api_free (ui->flickr_api);
    ui->flickr_api = _flickr_api_authenticate(ui);
    if (ui->flickr_api != NULL)
    {
      set_status(ui,_("authenticated"), "#7fe07f");
    }
    else
    {
      set_status(ui,_("not authenticated"), "#e07f7f");
      gtk_widget_set_sensitive(GTK_WIDGET( ui->comboBox1 ) ,FALSE);
      return;
    }
  }

  // First clear the model of data except first item (Create new album)
  GtkTreeModel *model=gtk_combo_box_get_model(GTK_COMBO_BOX(ui->comboBox1));
  gtk_list_store_clear (GTK_LIST_STORE(model));

  ui->albums = _flickr_api_photosets(ui->flickr_api, gtk_entry_get_text(ui->entry1));
  if( ui->albums )
  {

    // Add standard action
    gtk_combo_box_text_append_text(ui->comboBox1, _("without album") );
    gtk_combo_box_text_append_text(ui->comboBox1, _("create new album") );
    gtk_combo_box_text_append_text(ui->comboBox1, "" );// Separator

    // Then add albums from list...
    for(i=0; ui->albums[i]; i++)
    {
      char data[512]= {0};
      sprintf(data,"%s (%i)", ui->albums[i]->title, ui->albums[i]->photos_count);
      gtk_combo_box_text_append_text(ui->comboBox1, g_strdup(data));
    }
    gtk_combo_box_set_active(GTK_COMBO_BOX(ui->comboBox1), 3);
    gtk_widget_hide( GTK_WIDGET(ui->hbox1) ); // Hide create album box...
  }
  else
  {
    // Failed to parse feed of album...
    // Lets notify somehow...
    gtk_combo_box_set_active(GTK_COMBO_BOX(ui->comboBox1), 0);
  }
  gtk_widget_set_sensitive( GTK_WIDGET(ui->comboBox1), TRUE);

}
コード例 #3
0
ファイル: flickr.c プロジェクト: nlannuzel/darktable
/** Refresh albums */
static void refresh_albums(dt_storage_flickr_gui_data_t *ui)
{
    int i;
    gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), FALSE);

    if(ui->flickr_api == NULL || ui->flickr_api->needsReauthentication == TRUE)
    {
        if(ui->flickr_api != NULL) _flickr_api_free(ui->flickr_api);
        ui->flickr_api = _flickr_api_authenticate(ui);
        if(ui->flickr_api != NULL)
        {
            set_status(ui, _("authenticated"), "#7fe07f");
        }
        else
        {
            set_status(ui, _("not authenticated"), "#e07f7f");
            gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), FALSE);
            return;
        }
    }

    // First clear the cobobox except first 2 items (none / create new album)
    dt_bauhaus_combobox_clear(ui->album_list);

    ui->albums = _flickr_api_photosets(ui->flickr_api, gtk_entry_get_text(ui->user_entry));
    if(ui->albums)
    {

        // Add standard action
        dt_bauhaus_combobox_add(ui->album_list, _("without album"));
        dt_bauhaus_combobox_add(ui->album_list, _("create new album"));
//     dt_bauhaus_combobox_add(ui->album_list, ""); // Separator // FIXME: bauhaus doesn't support separators

        // Then add albums from list...
        for(i = 0; ui->albums[i]; i++)
        {
            char data[512] = { 0 };
            snprintf(data, sizeof(data), "%s (%i)", ui->albums[i]->title, ui->albums[i]->photos_count);
            dt_bauhaus_combobox_add(ui->album_list, data);
        }
        dt_bauhaus_combobox_set(ui->album_list, 2);
        gtk_widget_hide(GTK_WIDGET(ui->create_box)); // Hide create album box...
    }
    else
    {
        // Failed to parse feed of album...
        // Lets notify somehow...
        dt_bauhaus_combobox_set(ui->album_list, 0);
    }
    gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), TRUE);
}
コード例 #4
0
ファイル: flickr.c プロジェクト: drinkcat/darktable
_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;
}