Exemple #1
0
static void ui_login_clicked(GtkButton *button, gpointer data)
{
  dt_storage_facebook_gui_data_t *ui=(dt_storage_facebook_gui_data_t*)data;
  gtk_widget_set_sensitive(GTK_WIDGET(ui->comboBox_album), FALSE);
  if (ui->connected == FALSE)
  {
    if (ui_authenticate(ui))
    {
      ui_refresh_albums(ui);
      ui->connected = TRUE;
      gtk_button_set_label(ui->button_login, _("logout"));
    }
    else
    {
      gtk_button_set_label(ui->button_login, _("login"));
    }
  }
  else //disconnect user
  {
    if (ui->connected == TRUE && ui->facebook_api->token != NULL)
    {
      GtkTreeModel *model = gtk_combo_box_get_model(ui->comboBox_username);
      GtkTreeIter iter;
      gtk_combo_box_get_active_iter(ui->comboBox_username, &iter);
      gchar *userid;
      gtk_tree_model_get(model, &iter, COMBO_USER_MODEL_ID_COL, &userid, -1);
      remove_account_info(userid);
      gtk_button_set_label(ui->button_login, _("login"));
      ui_refresh_users(ui);
      ui->connected = FALSE;
    }
  }
  gtk_widget_set_sensitive(GTK_WIDGET(ui->comboBox_album), TRUE);
}
Exemple #2
0
static void ui_combo_username_changed(GtkComboBox *combo, struct dt_storage_gphoto_gui_data_t *ui)
{
  GtkTreeIter iter;
  gchar *token = NULL;
  gchar *refresh_token = NULL;
  gchar *userid = NULL;
  if(!gtk_combo_box_get_active_iter(combo, &iter)) return; // ie: list is empty while clearing the combo
  GtkTreeModel *model = gtk_combo_box_get_model(combo);
  gtk_tree_model_get(model, &iter, COMBO_USER_MODEL_TOKEN_COL, &token, -1); // get the selected token
  gtk_tree_model_get(model, &iter, COMBO_USER_MODEL_REFRESH_TOKEN_COL, &refresh_token, -1);
  gtk_tree_model_get(model, &iter, COMBO_USER_MODEL_ID_COL, &userid, -1);

  ui->gphoto_api->token = g_strdup(token);
  ui->gphoto_api->refresh_token = g_strdup(refresh_token);
  g_snprintf(ui->gphoto_api->userid, sizeof(ui->gphoto_api->userid), "%s", userid);

  if(ui->gphoto_api->token != NULL && gphoto_test_auth_token(ui->gphoto_api))
  {
    ui->connected = TRUE;
    gtk_button_set_label(ui->button_login, _("logout"));
    ui_refresh_albums(ui);
    gtk_widget_set_sensitive(GTK_WIDGET(ui->combo_album), TRUE);
  }
  else
  {
    gtk_button_set_label(ui->button_login, _("login"));
    g_free(ui->gphoto_api->token);
    g_free(ui->gphoto_api->refresh_token);
    ui->gphoto_api->token = ui->gphoto_api->refresh_token = NULL;
    gtk_widget_set_sensitive(GTK_WIDGET(ui->combo_album), FALSE);
    GtkListStore *model_album = GTK_LIST_STORE(gtk_combo_box_get_model(ui->combo_album));
    gtk_list_store_clear(model_album);
  }
}
Exemple #3
0
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);
}
Exemple #4
0
void finalize_store(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data)
{
  gdk_threads_enter();
  dt_storage_facebook_gui_data_t *ui = (dt_storage_facebook_gui_data_t*)self->gui_data;
  ui_reset_albums_creation(ui);
  ui_refresh_albums(ui);
  gdk_threads_leave();
}
Exemple #5
0
static gboolean _finalize_store(gpointer user_data)
{
  dt_storage_facebook_gui_data_t *ui = (dt_storage_facebook_gui_data_t *)user_data;
  ui_reset_albums_creation(ui);
  ui_refresh_albums(ui);

  return FALSE;
}