From 7bef56be53481897f2dc86b484b98f90fd8b35b6 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 2 Feb 2021 11:40:27 +0100 Subject: [PATCH] Add sql for #265. --- .../desktop/com.github.rssguard.appdata.xml | 2 +- resources/sql.qrc | 2 ++ resources/sql/db_init_mysql.sql | 4 ++- resources/sql/db_init_sqlite.sql | 4 ++- resources/sql/db_update_mysql_19_20.sql | 33 +++++++++++++++++++ resources/sql/db_update_sqlite_19_20.sql | 33 +++++++++++++++++++ src/librssguard/definitions/definitions.h | 22 +++++++------ .../services/gmail/gui/formaddeditemail.cpp | 2 +- .../services/greader/greadernetwork.cpp | 4 +-- .../services/standard/standardfeed.cpp | 14 +++++++- .../services/standard/standardfeed.h | 10 ++++++ 11 files changed, 113 insertions(+), 17 deletions(-) create mode 100755 resources/sql/db_update_mysql_19_20.sql create mode 100755 resources/sql/db_update_sqlite_19_20.sql diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index 3d892d5ba..d9c8533db 100644 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -30,7 +30,7 @@ https://martinrotter.github.io/donate/ - + none diff --git a/resources/sql.qrc b/resources/sql.qrc index 959541956..80c16307b 100755 --- a/resources/sql.qrc +++ b/resources/sql.qrc @@ -19,6 +19,7 @@ sql/db_update_mysql_16_17.sql sql/db_update_mysql_17_18.sql sql/db_update_mysql_18_19.sql + sql/db_update_mysql_19_20.sql sql/db_init_sqlite.sql sql/db_update_sqlite_1_2.sql @@ -39,5 +40,6 @@ sql/db_update_sqlite_16_17.sql sql/db_update_sqlite_17_18.sql sql/db_update_sqlite_18_19.sql + sql/db_update_sqlite_19_20.sql \ No newline at end of file diff --git a/resources/sql/db_init_mysql.sql b/resources/sql/db_init_mysql.sql index 2413eb309..0858d7f3d 100644 --- a/resources/sql/db_init_mysql.sql +++ b/resources/sql/db_init_mysql.sql @@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS Information ( inf_value TEXT NOT NULL ); -- ! -INSERT INTO Information VALUES (1, 'schema_version', '19'); +INSERT INTO Information VALUES (1, 'schema_version', '20'); -- ! CREATE TABLE IF NOT EXISTS Accounts ( id INTEGER AUTO_INCREMENT PRIMARY KEY, @@ -110,7 +110,9 @@ CREATE TABLE IF NOT EXISTS Feeds ( icon BLOB, category INTEGER NOT NULL CHECK (category >= -1), encoding TEXT, + source_type INTEGER, url VARCHAR(1000), + post_process TEXT, protected INTEGER(1) NOT NULL CHECK (protected >= 0 AND protected <= 1), username TEXT, password TEXT, diff --git a/resources/sql/db_init_sqlite.sql b/resources/sql/db_init_sqlite.sql index a024aba25..770f75e37 100644 --- a/resources/sql/db_init_sqlite.sql +++ b/resources/sql/db_init_sqlite.sql @@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS Information ( inf_value TEXT NOT NULL ); -- ! -INSERT INTO Information VALUES (1, 'schema_version', '19'); +INSERT INTO Information VALUES (1, 'schema_version', '20'); -- ! CREATE TABLE IF NOT EXISTS Accounts ( id INTEGER PRIMARY KEY, @@ -104,7 +104,9 @@ CREATE TABLE IF NOT EXISTS Feeds ( icon BLOB, category INTEGER NOT NULL CHECK (category >= -1), encoding TEXT, + source_type INTEGER, url TEXT, + post_process TEXT, protected INTEGER(1) NOT NULL CHECK (protected >= 0 AND protected <= 1), username TEXT, password TEXT, diff --git a/resources/sql/db_update_mysql_19_20.sql b/resources/sql/db_update_mysql_19_20.sql new file mode 100755 index 000000000..f4063dd8a --- /dev/null +++ b/resources/sql/db_update_mysql_19_20.sql @@ -0,0 +1,33 @@ +CREATE TABLE backup_feeds AS SELECT * FROM Feeds; +-- ! +DROP TABLE Feeds; +-- ! +CREATE TABLE IF NOT EXISTS Feeds ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + title TEXT NOT NULL CHECK (title != ''), + description TEXT, + date_created BIGINT, + icon BLOB, + category INTEGER NOT NULL CHECK (category >= -1), + encoding TEXT, + source_type INTEGER, + url VARCHAR(1000), + post_process TEXT, + protected INTEGER(1) NOT NULL CHECK (protected >= 0 AND protected <= 1), + username TEXT, + password TEXT, + update_type INTEGER(1) NOT NULL CHECK (update_type >= 0), + update_interval INTEGER NOT NULL DEFAULT 15 CHECK (update_interval >= 3), + type INTEGER, + account_id INTEGER NOT NULL, + custom_id TEXT, + + FOREIGN KEY (account_id) REFERENCES Accounts (id) +); +-- ! +INSERT INTO Feeds (id, title, description, date_created, icon, category, encoding, url, protected, username, password, update_type, update_interval, type, account_id, custom_id) +SELECT id, title, description, date_created, icon, category, encoding, url, protected, username, password, update_type, update_interval, type, account_id, custom_id FROM backup_feeds; +-- ! +DROP TABLE backup_feeds; +-- ! +UPDATE Information SET inf_value = '20' WHERE inf_key = 'schema_version'; \ No newline at end of file diff --git a/resources/sql/db_update_sqlite_19_20.sql b/resources/sql/db_update_sqlite_19_20.sql new file mode 100755 index 000000000..ee0a9a25b --- /dev/null +++ b/resources/sql/db_update_sqlite_19_20.sql @@ -0,0 +1,33 @@ +CREATE TABLE backup_feeds AS SELECT * FROM Feeds; +-- ! +DROP TABLE Feeds; +-- ! +CREATE TABLE IF NOT EXISTS Feeds ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL CHECK (title != ''), + description TEXT, + date_created INTEGER, + icon BLOB, + category INTEGER NOT NULL CHECK (category >= -1), + encoding TEXT, + source_type INTEGER, + url TEXT, + post_process TEXT, + protected INTEGER(1) NOT NULL CHECK (protected >= 0 AND protected <= 1), + username TEXT, + password TEXT, + update_type INTEGER(1) NOT NULL CHECK (update_type >= 0), + update_interval INTEGER NOT NULL CHECK (update_interval >= 3) DEFAULT 15, + type INTEGER, + account_id INTEGER NOT NULL, + custom_id TEXT, + + FOREIGN KEY (account_id) REFERENCES Accounts (id) +); +-- ! +INSERT INTO Feeds (id, title, description, date_created, icon, category, encoding, url, protected, username, password, update_type, update_interval, type, account_id, custom_id) +SELECT id, title, description, date_created, icon, category, encoding, url, protected, username, password, update_type, update_interval, type, account_id, custom_id FROM backup_feeds; +-- ! +DROP TABLE backup_feeds; +-- ! +UPDATE Information SET inf_value = '20' WHERE inf_key = 'schema_version'; \ No newline at end of file diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index a9d2241b9..11fca67ec 100755 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -146,7 +146,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 "19" +#define APP_DB_SCHEMA_VERSION "20" #define APP_DB_UPDATE_FILE_PATTERN "db_update_%1_%2_%3.sql" #define APP_DB_COMMENT_SPLIT "-- !\n" #define APP_DB_NAME_PLACEHOLDER "##" @@ -207,15 +207,17 @@ #define FDS_DB_ICON_INDEX 4 #define FDS_DB_CATEGORY_INDEX 5 #define FDS_DB_ENCODING_INDEX 6 -#define FDS_DB_URL_INDEX 7 -#define FDS_DB_PROTECTED_INDEX 8 -#define FDS_DB_USERNAME_INDEX 9 -#define FDS_DB_PASSWORD_INDEX 10 -#define FDS_DB_UPDATE_TYPE_INDEX 11 -#define FDS_DB_UPDATE_INTERVAL_INDEX 12 -#define FDS_DB_TYPE_INDEX 13 -#define FDS_DB_ACCOUNT_ID_INDEX 14 -#define FDS_DB_CUSTOM_ID_INDEX 15 +#define FDS_DB_SOURCE_TYPE_INDEX 7 +#define FDS_DB_URL_INDEX 8 +#define FDS_DB_POST_PROCESS 9 +#define FDS_DB_PROTECTED_INDEX 10 +#define FDS_DB_USERNAME_INDEX 11 +#define FDS_DB_PASSWORD_INDEX 12 +#define FDS_DB_UPDATE_TYPE_INDEX 13 +#define FDS_DB_UPDATE_INTERVAL_INDEX 14 +#define FDS_DB_TYPE_INDEX 15 +#define FDS_DB_ACCOUNT_ID_INDEX 16 +#define FDS_DB_CUSTOM_ID_INDEX 17 // Indexes of columns for feed models. #define FDS_MODEL_TITLE_INDEX 0 diff --git a/src/librssguard/services/gmail/gui/formaddeditemail.cpp b/src/librssguard/services/gmail/gui/formaddeditemail.cpp index cba5c9fb1..63ca70816 100644 --- a/src/librssguard/services/gmail/gui/formaddeditemail.cpp +++ b/src/librssguard/services/gmail/gui/formaddeditemail.cpp @@ -123,7 +123,7 @@ void FormAddEditEmail::onOkClicked() { .arg(QString(m_ui.m_txtSubject->text().toUtf8().toBase64(QByteArray::Base64Option::Base64UrlEncoding))) .toStdString(); msg.set_plain(m_ui.m_txtMessage->toPlainText().toStdString()); - msg.set_header("Content-Type", "text/plain; charset=utf-8"); + msg.set_header(HTTP_HEADERS_CONTENT_TYPE, "text/plain; charset=utf-8"); try { m_root->network()->sendEmail(msg, m_root->networkProxy(), m_originalMessage); diff --git a/src/librssguard/services/greader/greadernetwork.cpp b/src/librssguard/services/greader/greadernetwork.cpp index ef6aa25ac..2c36cdf92 100755 --- a/src/librssguard/services/greader/greadernetwork.cpp +++ b/src/librssguard/services/greader/greadernetwork.cpp @@ -70,7 +70,7 @@ QNetworkReply::NetworkError GreaderNetwork::editLabels(const QString& state, output, QNetworkAccessManager::Operation::PostOperation, { authHeader(), - { QSL("Content-Type").toLocal8Bit(), + { QSL(HTTP_HEADERS_CONTENT_TYPE).toLocal8Bit(), QSL("application/x-www-form-urlencoded").toLocal8Bit() } }, false, {}, @@ -425,7 +425,7 @@ QString GreaderNetwork::serviceToString(GreaderServiceRoot::Service service) { } QPair GreaderNetwork::authHeader() const { - return { QSL("Authorization").toLocal8Bit(), QSL("GoogleLogin auth=%1").arg(m_authAuth).toLocal8Bit() }; + return { QSL(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), QSL("GoogleLogin auth=%1").arg(m_authAuth).toLocal8Bit() }; } bool GreaderNetwork::ensureLogin(const QNetworkProxy& proxy, QNetworkReply::NetworkError* output) { diff --git a/src/librssguard/services/standard/standardfeed.cpp b/src/librssguard/services/standard/standardfeed.cpp index 695d5eb83..f79ed3ee7 100644 --- a/src/librssguard/services/standard/standardfeed.cpp +++ b/src/librssguard/services/standard/standardfeed.cpp @@ -34,6 +34,7 @@ StandardFeed::StandardFeed(RootItem* parent_item) : Feed(parent_item) { m_networkError = QNetworkReply::NetworkError::NoError; m_type = Type::Rss0X; + m_sourceType = SourceType::Url; m_encoding = QString(); } @@ -41,6 +42,7 @@ StandardFeed::StandardFeed(const StandardFeed& other) : Feed(other) { m_networkError = other.networkError(); m_type = other.type(); + m_sourceType = other.sourceType(); m_encoding = other.encoding(); } @@ -139,6 +141,14 @@ void StandardFeed::fetchMetadataForItself() { } } +StandardFeed::SourceType StandardFeed::sourceType() const { + return m_sourceType; +} + +void StandardFeed::setSourceType(const SourceType& source_type) { + m_sourceType = source_type; +} + QPair StandardFeed::guessFeed(const QString& url, const QString& username, const QString& password, @@ -406,6 +416,7 @@ bool StandardFeed::editItself(StandardFeed* new_feed_data) { original_feed->setAutoUpdateType(new_feed_data->autoUpdateType()); original_feed->setAutoUpdateInitialInterval(new_feed_data->autoUpdateInitialInterval()); original_feed->setType(new_feed_data->type()); + original_feed->setSourceType(new_feed_data->sourceType()); // Editing is done. return true; @@ -506,6 +517,7 @@ QNetworkReply::NetworkError StandardFeed::networkError() const { StandardFeed::StandardFeed(const QSqlRecord& record) : Feed(record) { setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString()); + setSourceType(SourceType(record.value(FDS_DB_SOURCE_TYPE_INDEX).toInt())); StandardFeed::Type type = static_cast(record.value(FDS_DB_TYPE_INDEX).toInt()); @@ -520,5 +532,5 @@ StandardFeed::StandardFeed(const QSqlRecord& record) : Feed(record) { } } - m_networkError = QNetworkReply::NoError; + m_networkError = QNetworkReply::NetworkError::NoError; } diff --git a/src/librssguard/services/standard/standardfeed.h b/src/librssguard/services/standard/standardfeed.h index aaa2157ba..e3578aee8 100644 --- a/src/librssguard/services/standard/standardfeed.h +++ b/src/librssguard/services/standard/standardfeed.h @@ -21,6 +21,12 @@ class StandardFeed : public Feed { Q_OBJECT public: + enum class SourceType { + Url = 0, + Script = 1, + LocalFile = 2 + }; + enum class Type { Rss0X = 0, Rss2X = 1, @@ -59,6 +65,9 @@ class StandardFeed : public Feed { Type type() const; void setType(Type type); + SourceType sourceType() const; + void setSourceType(const SourceType& source_type); + QString encoding() const; void setEncoding(const QString& encoding); @@ -83,6 +92,7 @@ class StandardFeed : public Feed { void fetchMetadataForItself(); private: + SourceType m_sourceType; Type m_type; QNetworkReply::NetworkError m_networkError;