Add new sql for gmail accs.

This commit is contained in:
Martin Rotter 2017-10-17 10:31:11 +02:00
parent 67254d209c
commit 93f4dae658
13 changed files with 138 additions and 40 deletions

View File

@ -4,26 +4,6 @@
<file>text/COPYING_BSD</file> <file>text/COPYING_BSD</file>
<file>text/COPYING_GNU_GPL</file> <file>text/COPYING_GNU_GPL</file>
<file>text/COPYING_GNU_GPL_HTML</file> <file>text/COPYING_GNU_GPL_HTML</file>
<file>sql/db_init_mysql.sql</file>
<file>sql/db_init_sqlite.sql</file>
<file>sql/db_update_mysql_1_2.sql</file>
<file>sql/db_update_mysql_2_3.sql</file>
<file>sql/db_update_mysql_3_4.sql</file>
<file>sql/db_update_mysql_4_5.sql</file>
<file>sql/db_update_mysql_5_6.sql</file>
<file>sql/db_update_mysql_6_7.sql</file>
<file>sql/db_update_mysql_7_8.sql</file>
<file>sql/db_update_mysql_8_9.sql</file>
<file>sql/db_update_mysql_9_10.sql</file>
<file>sql/db_update_sqlite_1_2.sql</file>
<file>sql/db_update_sqlite_2_3.sql</file>
<file>sql/db_update_sqlite_3_4.sql</file>
<file>sql/db_update_sqlite_4_5.sql</file>
<file>sql/db_update_sqlite_5_6.sql</file>
<file>sql/db_update_sqlite_6_7.sql</file>
<file>sql/db_update_sqlite_7_8.sql</file>
<file>sql/db_update_sqlite_8_9.sql</file>
<file>sql/db_update_sqlite_9_10.sql</file>
<file>graphics/rssguard.ico</file> <file>graphics/rssguard.ico</file>
<file>graphics/rssguard.png</file> <file>graphics/rssguard.png</file>
<file>graphics/rssguard_plain.png</file> <file>graphics/rssguard_plain.png</file>

View File

@ -28,9 +28,9 @@ set -- R*.AppImage
imagename="$1" imagename="$1"
if [ "$USE_WEBENGINE" = true ]; then if [ "$USE_WEBENGINE" = true ]; then
imagenamenospace="rssguard-$(git rev-parse --short HEAD)-linux.AppImage" imagenamenospace="rssguard-$(git rev-parse --short HEAD)-linux64.AppImage"
else else
imagenamenospace="rssguard-$(git rev-parse --short HEAD)-nowebengine-linux.AppImage" imagenamenospace="rssguard-$(git rev-parse --short HEAD)-nowebengine-linux64.AppImage"
fi fi
echo "File to upload: $imagename" echo "File to upload: $imagename"

26
resources/sql.qrc Executable file
View File

@ -0,0 +1,26 @@
<RCC>
<qresource prefix="/">
<file>sql/db_init_mysql.sql</file>
<file>sql/db_init_sqlite.sql</file>
<file>sql/db_update_mysql_1_2.sql</file>
<file>sql/db_update_mysql_2_3.sql</file>
<file>sql/db_update_mysql_3_4.sql</file>
<file>sql/db_update_mysql_4_5.sql</file>
<file>sql/db_update_mysql_5_6.sql</file>
<file>sql/db_update_mysql_6_7.sql</file>
<file>sql/db_update_mysql_7_8.sql</file>
<file>sql/db_update_mysql_8_9.sql</file>
<file>sql/db_update_mysql_9_10.sql</file>
<file>sql/db_update_mysql_10_11.sql</file>
<file>sql/db_update_sqlite_1_2.sql</file>
<file>sql/db_update_sqlite_2_3.sql</file>
<file>sql/db_update_sqlite_3_4.sql</file>
<file>sql/db_update_sqlite_4_5.sql</file>
<file>sql/db_update_sqlite_5_6.sql</file>
<file>sql/db_update_sqlite_6_7.sql</file>
<file>sql/db_update_sqlite_7_8.sql</file>
<file>sql/db_update_sqlite_8_9.sql</file>
<file>sql/db_update_sqlite_9_10.sql</file>
<file>sql/db_update_sqlite_10_11.sql</file>
</qresource>
</RCC>

View File

@ -55,6 +55,18 @@ CREATE TABLE IF NOT EXISTS InoreaderAccounts (
FOREIGN KEY (id) REFERENCES Accounts (id) FOREIGN KEY (id) REFERENCES Accounts (id)
); );
-- ! -- !
CREATE TABLE IF NOT EXISTS GmailAccounts (
id INTEGER,
username TEXT NOT NULL,
app_id TEXT,
app_key TEXT,
redirect_url 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; DROP TABLE IF EXISTS Categories;
-- ! -- !
CREATE TABLE IF NOT EXISTS Categories ( CREATE TABLE IF NOT EXISTS Categories (

View File

@ -49,6 +49,18 @@ CREATE TABLE IF NOT EXISTS InoreaderAccounts (
FOREIGN KEY (id) REFERENCES Accounts (id) FOREIGN KEY (id) REFERENCES Accounts (id)
); );
-- ! -- !
CREATE TABLE IF NOT EXISTS GmailAccounts (
id INTEGER,
username TEXT NOT NULL,
app_id TEXT,
app_key TEXT,
redirect_url 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; DROP TABLE IF EXISTS Categories;
-- ! -- !
CREATE TABLE IF NOT EXISTS Categories ( CREATE TABLE IF NOT EXISTS Categories (

View File

@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS GmailAccounts (
id INTEGER,
username TEXT NOT NULL,
app_id TEXT,
app_key TEXT,
redirect_url 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 = '11' WHERE inf_key = 'schema_version';

View File

@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS GmailAccounts (
id INTEGER,
username TEXT NOT NULL,
app_id TEXT,
app_key TEXT,
redirect_url 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 = '11' WHERE inf_key = 'schema_version';

View File

@ -208,7 +208,9 @@ win32 {
QMAKE_TARGET_PRODUCT = $$APP_NAME QMAKE_TARGET_PRODUCT = $$APP_NAME
} }
RESOURCES += resources/rssguard.qrc CONFIG *= resources_big
RESOURCES += resources/sql.qrc \
resources/rssguard.qrc
HEADERS += src/core/feeddownloader.h \ HEADERS += src/core/feeddownloader.h \
src/core/feedsmodel.h \ src/core/feedsmodel.h \

View File

@ -128,7 +128,7 @@
#define APP_DB_SQLITE_FILE "database.db" #define APP_DB_SQLITE_FILE "database.db"
// Keep this in sync with schema versions declared in SQL initialization code. // Keep this in sync with schema versions declared in SQL initialization code.
#define APP_DB_SCHEMA_VERSION "10" #define APP_DB_SCHEMA_VERSION "11"
#define APP_DB_UPDATE_FILE_PATTERN "db_update_%1_%2_%3.sql" #define APP_DB_UPDATE_FILE_PATTERN "db_update_%1_%2_%3.sql"
#define APP_DB_COMMENT_SPLIT "-- !\n" #define APP_DB_COMMENT_SPLIT "-- !\n"
#define APP_DB_NAME_PLACEHOLDER "##" #define APP_DB_NAME_PLACEHOLDER "##"

View File

@ -175,22 +175,21 @@ int main(int argc, char* argv[]) {
qApp->showPolls(); qApp->showPolls();
qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->loadAllExpandStates(); qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->loadAllExpandStates();
/* OAuth2Service* srv = new OAuth2Service(
OAuth2Service* srv = new OAuth2Service(
"https://accounts.google.com/o/oauth2/auth", "https://accounts.google.com/o/oauth2/auth",
"https://accounts.google.com/o/oauth2/token", "https://accounts.google.com/o/oauth2/token",
"369069180494-j66bgeciouinec1eem7fhvj6qm0as7q3.apps.googleusercontent.com", "369069180494-j66bgeciouinec1eem7fhvj6qm0as7q3.apps.googleusercontent.com",
"vppQtxrEeBkImiXcjGYl9NxZ", "vppQtxrEeBkImiXcjGYl9NxZ",
"https://mail.google.com/"); "https://mail.google.com/");
srv->setRefreshToken("1/RKE3oohSoTHE54L0IPflvndK-DcI7l0of3lVdLa1Q9Q"); srv->setRefreshToken("1/RKE3oohSoTHE54L0IPflvndK-DcI7l0of3lVdLa1Q9Q");
QObject::connect(srv, &OAuth2Service::authCodeObtained, [](QString auth_code) { QObject::connect(srv, &OAuth2Service::authCodeObtained, [](QString auth_code) {
int a = 5; int a = 5;
}); });
QObject::connect(srv, &OAuth2Service::authFailed, []() { QObject::connect(srv, &OAuth2Service::authFailed, []() {
int a = 5; int a = 5;
}); });
QObject::connect(srv, &OAuth2Service::tokensReceived, [srv](QString acc, QString ref, int exp) { QObject::connect(srv, &OAuth2Service::tokensReceived, [srv](QString acc, QString ref, int exp) {
QHttpMultiPart* multi = new QHttpMultiPart(srv); QHttpMultiPart* multi = new QHttpMultiPart(srv);
QHttpPart p1; QHttpPart p1;
@ -222,11 +221,11 @@ int main(int argc, char* argv[]) {
}); });
int a = 5; int a = 5;
}); });
QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) { QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) {
int a = 5; int a = 5;
}); });
srv->login();*/ srv->login();
// Enter global event loop. // Enter global event loop.
return Application::exec(); return Application::exec();

View File

@ -476,7 +476,8 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
// The two message are the "same" if: // The two message are the "same" if:
// 1) they belong to the same feed AND, // 1) they belong to the same feed AND,
// 2) they have same URL AND, // 2) they have same URL AND,
// 3) they have same AUTHOR. // 3) they have same AUTHOR AND,
// 4) they have same title.
query_select_with_url.setForwardOnly(true); query_select_with_url.setForwardOnly(true);
query_select_with_url.prepare("SELECT id, date_created, is_read, is_important, contents FROM Messages " query_select_with_url.prepare("SELECT id, date_created, is_read, is_important, contents FROM Messages "
"WHERE feed = :feed AND title = :title AND url = :url AND author = :author AND account_id = :account_id;"); "WHERE feed = :feed AND title = :title AND url = :url AND author = :author AND account_id = :account_id;");
@ -527,7 +528,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
QString contents_existing_message; QString contents_existing_message;
if (message.m_customId.isEmpty()) { if (message.m_customId.isEmpty()) {
// We need to recognize existing messages according URL & AUTHOR. // We need to recognize existing messages according URL & AUTHOR & TITLE.
// NOTE: This particularly concerns messages from standard account. // NOTE: This particularly concerns messages from standard account.
query_select_with_url.bindValue(QSL(":feed"), feed_custom_id); query_select_with_url.bindValue(QSL(":feed"), feed_custom_id);
query_select_with_url.bindValue(QSL(":title"), message.m_title); query_select_with_url.bindValue(QSL(":title"), message.m_title);
@ -1491,6 +1492,42 @@ Assignment DatabaseQueries::getCategories(QSqlDatabase db, int account_id, bool*
} }
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
QList<ServiceRoot*> DatabaseQueries::getGmailAccounts(QSqlDatabase db, bool* ok) {
QSqlQuery query(db);
QList<ServiceRoot*> roots;
if (query.exec("SELECT * FROM GmailAccounts;")) {
while (query.next()) {
/*GmailServiceRoot* root = new GmailServiceRoot(nullptr);
root->setId(query.value(0).toInt());
root->setAccountId(query.value(0).toInt());
root->network()->setUsername(query.value(1).toString());
root->network()->oauth()->setClientId(query.value(2).toString());
root->network()->oauth()->setClientSecret(query.value(3).toString());
root->network()->oauth()->setRedirectUrl(query.value(4).toString());
root->network()->oauth()->setRefreshToken(query.value(5).toString());
root->network()->setBatchSize(query.value(6).toInt());
root->updateTitle();
roots.append(root);*/
}
if (ok != nullptr) {
*ok = true;
}
}
else {
qWarning("Gmail: Getting list of activated accounts failed: '%s'.", qPrintable(query.lastError().text()));
if (ok != nullptr) {
*ok = false;
}
}
return roots;
}
bool DatabaseQueries::deleteInoreaderAccount(QSqlDatabase db, int account_id) { bool DatabaseQueries::deleteInoreaderAccount(QSqlDatabase db, int account_id) {
QSqlQuery q(db); QSqlQuery q(db);

View File

@ -78,8 +78,12 @@ class DatabaseQueries {
int auto_update_interval); int auto_update_interval);
static Assignment getCategories(QSqlDatabase db, int account_id, bool* ok = nullptr); static Assignment getCategories(QSqlDatabase db, int account_id, bool* ok = nullptr);
// Inoreader account.
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
// Gmail account.
static QList<ServiceRoot*> getGmailAccounts(QSqlDatabase db, bool* ok = nullptr);
// Inoreader account.
static bool deleteInoreaderAccount(QSqlDatabase db, int account_id); static bool deleteInoreaderAccount(QSqlDatabase db, int account_id);
static Assignment getInoreaderFeeds(QSqlDatabase db, int account_id, bool* ok = nullptr); static Assignment getInoreaderFeeds(QSqlDatabase db, int account_id, bool* ok = nullptr);
static bool storeNewInoreaderTokens(QSqlDatabase db, const QString& refresh_token, int account_id); static bool storeNewInoreaderTokens(QSqlDatabase db, const QString& refresh_token, int account_id);

View File

@ -33,7 +33,7 @@ QList<ServiceRoot*> GmailEntryPoint::initializeSubtree() const {
return QList<ServiceRoot*>(); return QList<ServiceRoot*>();
//return DatabaseQueries::getInoreaderAccounts(database); return DatabaseQueries::getGmailAccounts(database);
} }
bool GmailEntryPoint::isSingleInstanceService() const { bool GmailEntryPoint::isSingleInstanceService() const {