コード例 #1
0
ファイル: facebook.c プロジェクト: rgo/darktable
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);
}
コード例 #2
0
ファイル: edit_local_accounts.c プロジェクト: ayttm/ayttm
static gboolean save_accounts(GtkTreeModel *model, GtkTreePath *path,
	GtkTreeIter *iter, gpointer data)
{
	FILE *fp = data;

	int tmp_connect = 0;
	char *service, *user, *pass;
	int id;

	gtk_tree_model_get(GTK_TREE_MODEL(account_list_store), iter,
		CONNECT, &tmp_connect,
		SERVICE_TYPE, &service, USER_NAME, &user, PASSWORD, &pass, -1);

	id = get_service_id(service);
	if (accounts && (ela = find_local_account_by_handle(user, id))) {
		LList *config = NULL;
		config = eb_services[id].sc->write_local_config(ela);
		config = value_pair_remove(config, "SCREEN_NAME");
		config = value_pair_add(config, "SCREEN_NAME", user);
		config = value_pair_remove(config, "PASSWORD");
		config = value_pair_add(config, "PASSWORD", pass);
		config = value_pair_remove(config, "CONNECT");
		config = value_pair_add(config, "CONNECT",
			tmp_connect ? "1" : "0");
		fprintf(fp, "<ACCOUNT %s>\n", service);
		value_pair_print_values(config, fp, 1);
		fprintf(fp, "</ACCOUNT>\n");
		existing_accounts = l_list_append(existing_accounts, ela);
	} else {
		LList *config = NULL;
		eb_debug(DBG_CORE,
			"Adding new account %s service %s\n", user, service);
		pairs = value_pair_add(NULL, "SCREEN_NAME", user);
		pairs = value_pair_add(pairs, "PASSWORD", pass);
		save_account_info(service, pairs);
		ela = eb_services[id].sc->read_local_account_config(pairs);

		if (ela != NULL) {
			/* Is this an account for which a module is not loaded? */
			if (ela->service_id == -1)
				ela->service_id = id;
			new_accounts = l_list_append(new_accounts, ela);
			config = eb_services[id].sc->write_local_config(ela);
			config = value_pair_remove(config, "CONNECT");
			config = value_pair_add(config, "CONNECT",
				tmp_connect ? "1" : "0");

			fprintf(fp, "<ACCOUNT %s>\n", service);
			value_pair_print_values(config, fp, 1);
			fprintf(fp, "</ACCOUNT>\n");
		} else
			ay_do_error(_("Invalid Service"),
				_("Can't add account : unknown service"));
	}

	return FALSE;
}
コード例 #3
0
ファイル: facebook.c プロジェクト: angryziber/darktable
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;
  }
}
コード例 #4
0
ファイル: googlephoto.c プロジェクト: TurboGit/darktable
static gboolean ui_authenticate(dt_storage_gphoto_gui_data_t *ui)
{
  if(ui->gphoto_api == NULL)
  {
    ui->gphoto_api = gphoto_api_init();
  }

  dt_gphoto_context_t *ctx = ui->gphoto_api;
  gboolean mustsaveaccount = FALSE;

  gchar *uiselectedaccounttoken = NULL;
  gchar *uiselectedaccountrefreshtoken = NULL;
  gchar *uiselecteduserid = NULL;
  GtkTreeIter iter;
  gtk_combo_box_get_active_iter(ui->combo_username, &iter);
  GtkTreeModel *accountModel = gtk_combo_box_get_model(ui->combo_username);
  gtk_tree_model_get(accountModel, &iter, COMBO_USER_MODEL_TOKEN_COL, &uiselectedaccounttoken, -1);
  gtk_tree_model_get(accountModel, &iter, COMBO_USER_MODEL_REFRESH_TOKEN_COL, &uiselectedaccountrefreshtoken,
                     -1);
  gtk_tree_model_get(accountModel, &iter, COMBO_USER_MODEL_ID_COL, &uiselecteduserid, -1);

  if(ctx->token != NULL)
  {
    g_free(ctx->token);
    g_free(ctx->refresh_token);
    ctx->userid[0] = 0;
    ctx->token = ctx->refresh_token = NULL;
  }

  if(uiselectedaccounttoken != NULL)
  {
    ctx->token = g_strdup(uiselectedaccounttoken);
    ctx->refresh_token = g_strdup(uiselectedaccountrefreshtoken);
    g_snprintf(ctx->userid, sizeof(ctx->userid), "%s", uiselecteduserid);
  }
  // check selected token if we already have one
  if(ctx->token != NULL && !gphoto_test_auth_token(ctx))
  {
    g_free(ctx->token);
    g_free(ctx->refresh_token);
    ctx->userid[0] = 0;
    ctx->token = ctx->refresh_token = NULL;
  }

  int ret = 0;
  if(ctx->token == NULL)
  {
    mustsaveaccount = TRUE;
    ret = gphoto_get_user_auth_token(ui); // ask user to log in
  }

  if(ctx->token == NULL || ctx->refresh_token == NULL || ret != 0)
  {
    return FALSE;
  }
  else
  {
    if(mustsaveaccount)
    {
      // Get first the refresh token
      dt_gphoto_account_info_t *accountinfo = gphoto_get_account_info(ui->gphoto_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->combo_username));
      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,
                             COMBO_USER_MODEL_REFRESH_TOKEN_COL, accountinfo->refresh_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_REFRESH_TOKEN_COL,
                           accountinfo->refresh_token, COMBO_USER_MODEL_ID_COL, accountinfo->id, -1);
      }
      g_signal_handlers_block_matched(ui->combo_username, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
                                      ui_combo_username_changed, NULL);
      gtk_combo_box_set_active_iter(ui->combo_username, &iter);
      g_signal_handlers_unblock_matched(ui->combo_username, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
                                        ui_combo_username_changed, NULL);

      gphoto_account_info_destroy(accountinfo);
    }
    return TRUE;
  }
}