Added persistent saving of inoreader accounts.
This commit is contained in:
parent
de548750e2
commit
6dde6928f6
resources/sql
src
definitions
miscellaneous
services/inoreader
@ -42,6 +42,16 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts (
|
||||
|
||||
FOREIGN KEY (id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
CREATE TABLE IF NOT EXISTS InoreaderAccounts (
|
||||
id INTEGER,
|
||||
username TEXT NOT NULL,
|
||||
access_token TEXT,
|
||||
refresh_token TEXT,
|
||||
msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1),
|
||||
|
||||
FOREIGN KEY (id) REFERENCES Accounts (id)
|
||||
);
|
||||
DROP TABLE IF EXISTS Categories;
|
||||
-- !
|
||||
CREATE TABLE IF NOT EXISTS Categories (
|
||||
|
@ -37,6 +37,16 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts (
|
||||
FOREIGN KEY (id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
CREATE TABLE IF NOT EXISTS InoreaderAccounts (
|
||||
id INTEGER,
|
||||
username TEXT NOT NULL,
|
||||
access_token TEXT,
|
||||
refresh_token TEXT,
|
||||
msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1),
|
||||
|
||||
FOREIGN KEY (id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
DROP TABLE IF EXISTS Categories;
|
||||
-- !
|
||||
CREATE TABLE IF NOT EXISTS Categories (
|
||||
|
11
resources/sql/db_update_mysql_9_10.sql
Executable file
11
resources/sql/db_update_mysql_9_10.sql
Executable file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS InoreaderAccounts (
|
||||
id INTEGER,
|
||||
username TEXT NOT NULL,
|
||||
access_token TEXT,
|
||||
refresh_token TEXT,
|
||||
msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1),
|
||||
|
||||
FOREIGN KEY (id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
UPDATE Information SET inf_value = '10' WHERE inf_key = 'schema_version';
|
11
resources/sql/db_update_sqlite_9_10.sql
Executable file
11
resources/sql/db_update_sqlite_9_10.sql
Executable file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS InoreaderAccounts (
|
||||
id INTEGER,
|
||||
username TEXT NOT NULL,
|
||||
access_token TEXT,
|
||||
refresh_token TEXT,
|
||||
msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1),
|
||||
|
||||
FOREIGN KEY (id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
UPDATE Information SET inf_value = '10' WHERE inf_key = 'schema_version';
|
@ -124,7 +124,7 @@
|
||||
#define APP_DB_SQLITE_FILE "database.db"
|
||||
|
||||
// Keep this in sync with schema versions declared in SQL initialization code.
|
||||
#define APP_DB_SCHEMA_VERSION "9"
|
||||
#define APP_DB_SCHEMA_VERSION "10"
|
||||
#define APP_DB_UPDATE_FILE_PATTERN "db_update_%1_%2_%3.sql"
|
||||
#define APP_DB_COMMENT_SPLIT "-- !\n"
|
||||
#define APP_DB_NAME_PLACEHOLDER "##"
|
||||
|
@ -1491,7 +1491,7 @@ bool DatabaseQueries::overwriteInoreaderAccount(QSqlDatabase db, const QString&
|
||||
query.bindValue(QSL(":access_token"), access_token);
|
||||
query.bindValue(QSL(":refresh_token"), refresh_token);
|
||||
query.bindValue(QSL(":id"), account_id);
|
||||
query.bindValue(QSL(":msg_limit"), batch_size);
|
||||
query.bindValue(QSL(":msg_limit"), batch_size <= 0 ? UNLIMITED_BATCH_SIZE : batch_size);
|
||||
|
||||
if (query.exec()) {
|
||||
return true;
|
||||
@ -1512,7 +1512,7 @@ bool DatabaseQueries::createInoreaderAccount(QSqlDatabase db, int id_to_assign,
|
||||
q.bindValue(QSL(":username"), username);
|
||||
q.bindValue(QSL(":access_token"), access_token);
|
||||
q.bindValue(QSL(":refresh_token"), refresh_token);
|
||||
q.bindValue(QSL(":msg_limit"), batch_size);
|
||||
q.bindValue(QSL(":msg_limit"), batch_size <= 0 ? UNLIMITED_BATCH_SIZE : batch_size);
|
||||
|
||||
if (q.exec()) {
|
||||
return true;
|
||||
|
@ -19,15 +19,15 @@
|
||||
#ifndef INOREADER_DEFINITIONS_H
|
||||
#define INOREADER_DEFINITIONS_H
|
||||
|
||||
#define INOREADER_OAUTH_PORT 12885
|
||||
#define INOREADER_OAUTH_SCOPE "read write"
|
||||
#define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token"
|
||||
#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth"
|
||||
#define INOREADER_OAUTH_CLI_ID "1000000604"
|
||||
#define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK"
|
||||
#define INOREADER_REFRESH_TOKEN_KEY "refresh_token"
|
||||
#define INOREADER_ACCESS_TOKEN_KEY "access_token"
|
||||
#define INOREADER_DEFAULT_BATCH_SIZE 900
|
||||
#define INOREADER_MAX_BATCH_SIZE 999
|
||||
#define INOREADER_OAUTH_PORT 12885
|
||||
#define INOREADER_OAUTH_SCOPE "read write"
|
||||
#define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token"
|
||||
#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth"
|
||||
#define INOREADER_OAUTH_CLI_ID "1000000604"
|
||||
#define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK"
|
||||
#define INOREADER_REFRESH_TOKEN_KEY "refresh_token"
|
||||
#define INOREADER_ACCESS_TOKEN_KEY "access_token"
|
||||
#define INOREADER_DEFAULT_BATCH_SIZE -1
|
||||
#define INOREADER_UNLIMITED_BATCH_SIZE -1
|
||||
|
||||
#endif // INOREADER_DEFINITIONS_H
|
||||
|
@ -32,9 +32,18 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
|
||||
tr("Not tested yet."),
|
||||
tr("Not tested yet."));
|
||||
m_ui.m_lblTestResult->label()->setWordWrap(true);
|
||||
|
||||
connect(m_ui.m_spinLimitMessages, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int value) {
|
||||
if (value <= 0) {
|
||||
m_ui.m_spinLimitMessages->setSuffix(QSL(" ") + tr("= unlimited"));
|
||||
}
|
||||
else {
|
||||
m_ui.m_spinLimitMessages->setSuffix(QSL(" ") + tr("messages"));
|
||||
}
|
||||
});
|
||||
|
||||
m_ui.m_spinLimitMessages->setValue(INOREADER_DEFAULT_BATCH_SIZE);
|
||||
m_ui.m_spinLimitMessages->setMinimum(1);
|
||||
m_ui.m_spinLimitMessages->setMaximum(INOREADER_MAX_BATCH_SIZE);
|
||||
m_ui.m_spinLimitMessages->setMinimum(INOREADER_UNLIMITED_BATCH_SIZE);
|
||||
|
||||
connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup);
|
||||
connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditInoreaderAccount::onClickedOk);
|
||||
@ -78,7 +87,7 @@ void FormEditInoreaderAccount::onClickedOk() {
|
||||
if (m_editableRoot == nullptr) {
|
||||
// We want to confirm newly created account.
|
||||
// So save new account into DB, setup its properties.
|
||||
m_editableRoot = new InoreaderServiceRoot();
|
||||
m_editableRoot = new InoreaderServiceRoot(m_network);
|
||||
editing_account = false;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,9 @@
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string> = unlimited</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
|
@ -24,7 +24,15 @@
|
||||
#include "services/inoreader/inoreaderentrypoint.h"
|
||||
#include "services/inoreader/network/inoreadernetworkfactory.h"
|
||||
|
||||
InoreaderServiceRoot::InoreaderServiceRoot(RootItem* parent) : ServiceRoot(parent) {}
|
||||
InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent) : ServiceRoot(parent),
|
||||
m_network(network) {
|
||||
if (m_network == nullptr) {
|
||||
m_network = new InoreaderNetworkFactory(this);
|
||||
}
|
||||
else {
|
||||
m_network->setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
InoreaderServiceRoot::~InoreaderServiceRoot() {}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class InoreaderServiceRoot : public ServiceRoot {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InoreaderServiceRoot(RootItem* parent = nullptr);
|
||||
explicit InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent = nullptr);
|
||||
virtual ~InoreaderServiceRoot();
|
||||
|
||||
void saveAccountDataToDatabase();
|
||||
|
@ -122,6 +122,14 @@ void InoreaderNetworkFactory::initializeOauth() {
|
||||
});
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::setRefreshToken(const QString& refreshToken) {
|
||||
m_refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::setAccessToken(const QString& accessToken) {
|
||||
m_accessToken = accessToken;
|
||||
}
|
||||
|
||||
QString InoreaderNetworkFactory::refreshToken() const {
|
||||
return m_refreshToken;
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ class InoreaderNetworkFactory : public QObject {
|
||||
|
||||
QString accessToken() const;
|
||||
QString refreshToken() const;
|
||||
void setAccessToken(const QString& accessToken);
|
||||
void setRefreshToken(const QString& refreshToken);
|
||||
|
||||
public slots:
|
||||
void logIn();
|
||||
|
Loading…
x
Reference in New Issue
Block a user