save
This commit is contained in:
parent
795e1b2f72
commit
9e7409e9d3
7 changed files with 107 additions and 28 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include "miscellaneous/textfactory.h"
|
#include "miscellaneous/textfactory.h"
|
||||||
#include "network-web/oauth2service.h"
|
#include "network-web/oauth2service.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
|
#include "services/feedly/definitions.h"
|
||||||
#include "services/gmail/definitions.h"
|
#include "services/gmail/definitions.h"
|
||||||
#include "services/gmail/gmailfeed.h"
|
#include "services/gmail/gmailfeed.h"
|
||||||
#include "services/gmail/gmailserviceroot.h"
|
#include "services/gmail/gmailserviceroot.h"
|
||||||
|
@ -1841,6 +1842,36 @@ bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QSt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DatabaseQueries::createFeedlyAccount(const QSqlDatabase& db, const QString& username,
|
||||||
|
const QString& developer_access_token, const QString& refresh_token,
|
||||||
|
int batch_size, int id_to_assign) {
|
||||||
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
q.prepare("INSERT INTO FeedlyAccounts (id, username, developer_access_token, refresh_token, msg_limit) "
|
||||||
|
"VALUES (:id, :service, :username, :developer_access_token, :refresh_token, :msg_limit);");
|
||||||
|
q.bindValue(QSL(":id"), id_to_assign);
|
||||||
|
q.bindValue(QSL(":username"), username);
|
||||||
|
q.bindValue(QSL(":developer_access_token"), developer_access_token);
|
||||||
|
q.bindValue(QSL(":refresh_token"), refresh_token);
|
||||||
|
q.bindValue(QSL(":msg_limit"), batch_size <= 0 ? FEEDLY_UNLIMITED_BATCH_SIZE : batch_size);
|
||||||
|
|
||||||
|
if (q.exec()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qWarningNN << LOGSEC_FEEDLY
|
||||||
|
<< "Inserting of new account failed:"
|
||||||
|
<< QUOTE_W_SPACE_DOT(q.lastError().text());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DatabaseQueries::overwriteFeedlyAccount(const QSqlDatabase& db, const QString& username,
|
||||||
|
const QString& developer_access_token, const QString& refresh_token,
|
||||||
|
int batch_size, int id_to_assign) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
bool DatabaseQueries::createGreaderAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
|
bool DatabaseQueries::createGreaderAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
|
||||||
const QString& password, GreaderServiceRoot::Service service,
|
const QString& password, GreaderServiceRoot::Service service,
|
||||||
const QString& url, int batch_size) {
|
const QString& url, int batch_size) {
|
||||||
|
|
|
@ -150,6 +150,20 @@ class DatabaseQueries {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void fillFeedData(T* feed, const QSqlRecord& sql_record);
|
static void fillFeedData(T* feed, const QSqlRecord& sql_record);
|
||||||
|
|
||||||
|
// Feedly account.
|
||||||
|
static bool createFeedlyAccount(const QSqlDatabase& db,
|
||||||
|
const QString& username,
|
||||||
|
const QString& developer_access_token,
|
||||||
|
const QString& refresh_token,
|
||||||
|
int batch_size,
|
||||||
|
int id_to_assign);
|
||||||
|
static bool overwriteFeedlyAccount(const QSqlDatabase& db,
|
||||||
|
const QString& username,
|
||||||
|
const QString& developer_access_token,
|
||||||
|
const QString& refresh_token,
|
||||||
|
int batch_size,
|
||||||
|
int id_to_assign);
|
||||||
|
|
||||||
// Greader account.
|
// Greader account.
|
||||||
static bool deleteGreaderAccount(const QSqlDatabase& db, int account_id);
|
static bool deleteGreaderAccount(const QSqlDatabase& db, int account_id);
|
||||||
static QList<ServiceRoot*> getGreaderAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
static QList<ServiceRoot*> getGreaderAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
||||||
|
|
|
@ -27,15 +27,15 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
|
||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
m_oauth(new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
|
m_oauth(new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
|
||||||
QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_TOKEN,
|
QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_TOKEN,
|
||||||
"dontknow",
|
FEEDLY_CLIENT_ID,
|
||||||
"dontknow",
|
FEEDLY_CLIENT_ID,
|
||||||
FEEDLY_API_SCOPE, this)),
|
FEEDLY_API_SCOPE, this)),
|
||||||
#endif
|
#endif
|
||||||
m_username(QString()),
|
m_username(QString()),
|
||||||
m_developerAccessToken(QString()), m_batchSize(FEEDLY_UNLIMITED_BATCH_SIZE) {
|
m_developerAccessToken(QString()), m_batchSize(FEEDLY_UNLIMITED_BATCH_SIZE) {
|
||||||
|
|
||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
//m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
|
m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
|
||||||
|
|
||||||
connect(m_oauth, &OAuth2Service::tokensRetrieveError, this, &FeedlyNetwork::onTokensError);
|
connect(m_oauth, &OAuth2Service::tokensRetrieveError, this, &FeedlyNetwork::onTokensError);
|
||||||
connect(m_oauth, &OAuth2Service::authFailed, this, &FeedlyNetwork::onAuthFailed);
|
connect(m_oauth, &OAuth2Service::authFailed, this, &FeedlyNetwork::onAuthFailed);
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
#include "services/feedly/feedlynetwork.h"
|
#include "services/feedly/feedlynetwork.h"
|
||||||
#include "services/feedly/gui/formeditfeedlyaccount.h"
|
#include "services/feedly/gui/formeditfeedlyaccount.h"
|
||||||
|
|
||||||
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
|
#include "network-web/oauth2service.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
FeedlyServiceRoot::FeedlyServiceRoot(RootItem* parent)
|
FeedlyServiceRoot::FeedlyServiceRoot(RootItem* parent)
|
||||||
: ServiceRoot(parent), m_network(new FeedlyNetwork(this)) {
|
: ServiceRoot(parent), m_network(new FeedlyNetwork(this)) {
|
||||||
setIcon(FeedlyEntryPoint().icon());
|
setIcon(FeedlyEntryPoint().icon());
|
||||||
|
@ -76,23 +80,35 @@ void FeedlyServiceRoot::updateTitle() {
|
||||||
void FeedlyServiceRoot::saveAccountDataToDatabase(bool creating_new) {
|
void FeedlyServiceRoot::saveAccountDataToDatabase(bool creating_new) {
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
||||||
|
|
||||||
/*
|
if (!creating_new) {
|
||||||
if (!creating_new) {
|
if (DatabaseQueries::overwriteFeedlyAccount(database,
|
||||||
if (DatabaseQueries::overwriteGreaderAccount(database, m_network->username(),
|
m_network->username(),
|
||||||
m_network->password(), m_network->service(),
|
m_network->developerAccessToken(),
|
||||||
m_network->baseUrl(), m_network->batchSize(),
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
accountId())) {
|
m_network->oauth()->refreshToken(),
|
||||||
|
#else
|
||||||
|
{},
|
||||||
|
#endif
|
||||||
|
m_network->batchSize(),
|
||||||
|
accountId())) {
|
||||||
updateTitle();
|
updateTitle();
|
||||||
itemChanged(QList<RootItem*>() << this);
|
itemChanged(QList<RootItem*>() << this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (DatabaseQueries::createGreaderAccount(database, accountId(), m_network->username(),
|
if (DatabaseQueries::createFeedlyAccount(database,
|
||||||
m_network->password(), m_network->service(),
|
m_network->username(),
|
||||||
m_network->baseUrl(), m_network->batchSize())) {
|
m_network->developerAccessToken(),
|
||||||
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
|
m_network->oauth()->refreshToken(),
|
||||||
|
#else
|
||||||
|
{},
|
||||||
|
#endif
|
||||||
|
m_network->batchSize(),
|
||||||
|
accountId())) {
|
||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RootItem* FeedlyServiceRoot::obtainNewTreeForSyncIn() const {
|
RootItem* FeedlyServiceRoot::obtainNewTreeForSyncIn() const {
|
||||||
|
|
|
@ -27,10 +27,15 @@ void FormEditFeedlyAccount::apply() {
|
||||||
bool editing_account = !applyInternal<FeedlyServiceRoot>();
|
bool editing_account = !applyInternal<FeedlyServiceRoot>();
|
||||||
|
|
||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
// We copy credentials from testing OAuth to live OAuth.
|
if (!editing_account) {
|
||||||
account<FeedlyServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
|
// We transfer refresh token to avoid the need to login once more,
|
||||||
account<FeedlyServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
|
// then we delete testing OAuth service.
|
||||||
account<FeedlyServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
|
account<FeedlyServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
|
||||||
|
account<FeedlyServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
|
||||||
|
account<FeedlyServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
|
||||||
|
m_details->m_oauth->logout();
|
||||||
|
m_details->m_oauth->deleteLater();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
account<FeedlyServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text());
|
account<FeedlyServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text());
|
||||||
|
@ -49,16 +54,20 @@ void FormEditFeedlyAccount::apply() {
|
||||||
void FormEditFeedlyAccount::setEditableAccount(ServiceRoot* editable_account) {
|
void FormEditFeedlyAccount::setEditableAccount(ServiceRoot* editable_account) {
|
||||||
FormAccountDetails::setEditableAccount(editable_account);
|
FormAccountDetails::setEditableAccount(editable_account);
|
||||||
|
|
||||||
FeedlyServiceRoot* existing_root = account<FeedlyServiceRoot>();
|
|
||||||
|
|
||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
|
if (m_details->m_oauth != nullptr) {
|
||||||
|
// We will use live OAuth service for testing.
|
||||||
|
m_details->m_oauth->logout();
|
||||||
|
m_details->m_oauth->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
m_details->m_oauth = account<FeedlyServiceRoot>()->network()->oauth();
|
m_details->m_oauth = account<FeedlyServiceRoot>()->network()->oauth();
|
||||||
m_details->hookNetwork();
|
m_details->hookNetwork();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_details->m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->username());
|
m_details->m_ui.m_txtUsername->lineEdit()->setText(account<FeedlyServiceRoot>()->network()->username());
|
||||||
m_details->m_ui.m_txtDeveloperAccessToken->lineEdit()->setText(existing_root->network()->developerAccessToken());
|
m_details->m_ui.m_txtDeveloperAccessToken->lineEdit()->setText(account<FeedlyServiceRoot>()->network()->developerAccessToken());
|
||||||
m_details->m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
|
m_details->m_ui.m_spinLimitMessages->setValue(account<FeedlyServiceRoot>()->network()->batchSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormEditFeedlyAccount::performTest() {
|
void FormEditFeedlyAccount::performTest() {
|
||||||
|
|
|
@ -31,6 +31,12 @@ class GmailAccountDetails : public QWidget {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::GmailAccountDetails m_ui;
|
Ui::GmailAccountDetails m_ui;
|
||||||
|
|
||||||
|
// Testing OAuth service. This object is not ever copied
|
||||||
|
// to new living account instance, instead only its properties
|
||||||
|
// like tokens are copied.
|
||||||
|
// If editing existing account, then the pointer points
|
||||||
|
// directly to existing OAuth from the account.
|
||||||
OAuth2Service* m_oauth;
|
OAuth2Service* m_oauth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,11 @@ class InoreaderAccountDetails : public QWidget {
|
||||||
private:
|
private:
|
||||||
Ui::InoreaderAccountDetails m_ui;
|
Ui::InoreaderAccountDetails m_ui;
|
||||||
|
|
||||||
// Testing OAuth service. Only for testing. Resulting tokens
|
// Testing OAuth service. This object is not ever copied
|
||||||
//
|
// to new living account instance, instead only its properties
|
||||||
|
// like tokens are copied.
|
||||||
|
// If editing existing account, then the pointer points
|
||||||
|
// directly to existing OAuth from the account.
|
||||||
OAuth2Service* m_oauth;
|
OAuth2Service* m_oauth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue