Nextcloud News now can also download unread only messages if user wants to.

This commit is contained in:
Martin Rotter 2020-06-15 08:43:22 +02:00
parent ca1bf27629
commit 40c084c59a
8 changed files with 109 additions and 65 deletions

View File

@ -1036,6 +1036,8 @@ QList<ServiceRoot*> DatabaseQueries::getOwnCloudAccounts(const QSqlDatabase& db,
root->network()->setUrl(query.value(3).toString());
root->network()->setForceServerSideUpdate(query.value(4).toBool());
root->network()->setBatchSize(query.value(5).toInt());
root->network()->setDownloadOnlyUnreadMessages(query.value(6).toBool());
root->updateTitle();
roots.append(root);
}
@ -1073,6 +1075,7 @@ QList<ServiceRoot*> DatabaseQueries::getTtRssAccounts(const QSqlDatabase& db, bo
root->network()->setUrl(query.value(6).toString());
root->network()->setForceServerSideUpdate(query.value(7).toBool());
root->network()->setDownloadOnlyUnreadMessages(query.value(8).toBool());
root->updateTitle();
roots.append(root);
}
@ -1102,11 +1105,13 @@ bool DatabaseQueries::deleteOwnCloudAccount(const QSqlDatabase& db, int account_
}
bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QString& username, const QString& password,
const QString& url, bool force_server_side_feed_update, int batch_size, int account_id) {
const QString& url, bool force_server_side_feed_update, int batch_size,
bool download_only_unread_messages, int account_id) {
QSqlQuery query(db);
query.prepare("UPDATE OwnCloudAccounts "
"SET username = :username, password = :password, url = :url, force_update = :force_update, msg_limit = :msg_limit "
"SET username = :username, password = :password, url = :url, force_update = :force_update, "
"msg_limit = :msg_limit, update_only_unread = :update_only_unread "
"WHERE id = :id;");
query.bindValue(QSL(":username"), username);
query.bindValue(QSL(":password"), TextFactory::encrypt(password));
@ -1114,6 +1119,7 @@ bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QSt
query.bindValue(QSL(":force_update"), force_server_side_feed_update ? 1 : 0);
query.bindValue(QSL(":id"), account_id);
query.bindValue(QSL(":msg_limit"), batch_size <= 0 ? OWNCLOUD_UNLIMITED_BATCH_SIZE : batch_size);
query.bindValue(QSL(":update_only_unread"), download_only_unread_messages ? 1 : 0);
if (query.exec()) {
return true;
@ -1126,17 +1132,19 @@ bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QSt
bool DatabaseQueries::createOwnCloudAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
const QString& password, const QString& url,
bool force_server_side_feed_update, int batch_size) {
bool force_server_side_feed_update,
bool download_only_unread_messages, int batch_size) {
QSqlQuery q(db);
q.prepare("INSERT INTO OwnCloudAccounts (id, username, password, url, force_update, msg_limit) "
"VALUES (:id, :username, :password, :url, :force_update, :msg_limit);");
q.prepare("INSERT INTO OwnCloudAccounts (id, username, password, url, force_update, msg_limit, update_only_unread) "
"VALUES (:id, :username, :password, :url, :force_update, :msg_limit, :update_only_unread);");
q.bindValue(QSL(":id"), id_to_assign);
q.bindValue(QSL(":username"), username);
q.bindValue(QSL(":password"), TextFactory::encrypt(password));
q.bindValue(QSL(":url"), url);
q.bindValue(QSL(":force_update"), force_server_side_feed_update ? 1 : 0);
q.bindValue(QSL(":msg_limit"), batch_size <= 0 ? OWNCLOUD_UNLIMITED_BATCH_SIZE : batch_size);
q.bindValue(QSL(":update_only_unread"), download_only_unread_messages ? 1 : 0);
if (q.exec()) {
return true;

View File

@ -63,7 +63,8 @@ class DatabaseQueries {
static QStringList customIdsOfMessagesFromFeed(const QSqlDatabase& db, const QString& feed_custom_id, int account_id,
bool* ok = nullptr);
// Common accounts methods.
// Common account methods.
static int createAccount(const QSqlDatabase& db, const QString& code, bool* ok = nullptr);
static int updateMessages(QSqlDatabase db, const QList<Message>& messages, const QString& feed_custom_id,
int account_id, const QString& url, bool* any_message_changed, bool* ok = nullptr);
static bool deleteAccount(const QSqlDatabase& db, int account_id);
@ -75,6 +76,52 @@ class DatabaseQueries {
int auto_update_interval);
static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
// Standard account.
static bool deleteFeed(const QSqlDatabase& db, int feed_custom_id, int account_id);
static bool deleteCategory(const QSqlDatabase& db, int id);
static int addCategory(const QSqlDatabase& db, int parent_id, int account_id, const QString& title,
const QString& description, const QDateTime& creation_date, const QIcon& icon, bool* ok = nullptr);
static bool editCategory(const QSqlDatabase& db, int parent_id, int category_id,
const QString& title, const QString& description, const QIcon& icon);
static int addFeed(const QSqlDatabase& db, int parent_id, int account_id, const QString& title,
const QString& description, const QDateTime& creation_date, const QIcon& icon,
const QString& encoding, const QString& url, bool is_protected,
const QString& username, const QString& password,
Feed::AutoUpdateType auto_update_type,
int auto_update_interval, StandardFeed::Type feed_format, bool* ok = nullptr);
static bool editFeed(const QSqlDatabase& db, int parent_id, int feed_id, const QString& title,
const QString& description, const QIcon& icon,
const QString& encoding, const QString& url, bool is_protected,
const QString& username, const QString& password, Feed::AutoUpdateType auto_update_type,
int auto_update_interval, StandardFeed::Type feed_format);
static QList<ServiceRoot*> getAccounts(const QSqlDatabase& db, bool* ok = nullptr);
static Assignment getStandardCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static Assignment getStandardFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
// Nextcloud account.
static QList<ServiceRoot*> getOwnCloudAccounts(const QSqlDatabase& db, bool* ok = nullptr);
static bool deleteOwnCloudAccount(const QSqlDatabase& db, int account_id);
static bool overwriteOwnCloudAccount(const QSqlDatabase& db, const QString& username, const QString& password,
const QString& url, bool force_server_side_feed_update, int batch_size,
bool download_only_unread_messages, int account_id);
static bool createOwnCloudAccount(const QSqlDatabase& db, int id_to_assign, const QString& username, const QString& password,
const QString& url, bool force_server_side_feed_update,
bool download_only_unread_messages, int batch_size);
static Assignment getOwnCloudFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
// TT-RSS acccount.
static QList<ServiceRoot*> getTtRssAccounts(const QSqlDatabase& db, bool* ok = nullptr);
static bool deleteTtRssAccount(const QSqlDatabase& db, int account_id);
static bool overwriteTtRssAccount(const QSqlDatabase& db, const QString& username, const QString& password,
bool auth_protected, const QString& auth_username, const QString& auth_password,
const QString& url, bool force_server_side_feed_update,
bool download_only_unread_messages, int account_id);
static bool createTtRssAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
const QString& password, bool auth_protected, const QString& auth_username,
const QString& auth_password, const QString& url,
bool force_server_side_feed_update, bool download_only_unread_messages);
static Assignment getTtRssFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
// Gmail account.
static Assignment getGmailFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static bool deleteGmailAccount(const QSqlDatabase& db, int account_id);
@ -98,51 +145,6 @@ class DatabaseQueries {
const QString& app_id, const QString& app_key, const QString& redirect_url,
const QString& refresh_token, int batch_size);
// Nextcloud account.
static QList<ServiceRoot*> getOwnCloudAccounts(const QSqlDatabase& db, bool* ok = nullptr);
static bool deleteOwnCloudAccount(const QSqlDatabase& db, int account_id);
static bool overwriteOwnCloudAccount(const QSqlDatabase& db, const QString& username, const QString& password,
const QString& url, bool force_server_side_feed_update, int batch_size, int account_id);
static bool createOwnCloudAccount(const QSqlDatabase& db, int id_to_assign, const QString& username, const QString& password,
const QString& url, bool force_server_side_feed_update, int batch_size);
static int createAccount(const QSqlDatabase& db, const QString& code, bool* ok = nullptr);
static Assignment getOwnCloudFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
// Standard account.
static bool deleteFeed(const QSqlDatabase& db, int feed_custom_id, int account_id);
static bool deleteCategory(const QSqlDatabase& db, int id);
static int addCategory(const QSqlDatabase& db, int parent_id, int account_id, const QString& title,
const QString& description, const QDateTime& creation_date, const QIcon& icon, bool* ok = nullptr);
static bool editCategory(const QSqlDatabase& db, int parent_id, int category_id,
const QString& title, const QString& description, const QIcon& icon);
static int addFeed(const QSqlDatabase& db, int parent_id, int account_id, const QString& title,
const QString& description, const QDateTime& creation_date, const QIcon& icon,
const QString& encoding, const QString& url, bool is_protected,
const QString& username, const QString& password,
Feed::AutoUpdateType auto_update_type,
int auto_update_interval, StandardFeed::Type feed_format, bool* ok = nullptr);
static bool editFeed(const QSqlDatabase& db, int parent_id, int feed_id, const QString& title,
const QString& description, const QIcon& icon,
const QString& encoding, const QString& url, bool is_protected,
const QString& username, const QString& password, Feed::AutoUpdateType auto_update_type,
int auto_update_interval, StandardFeed::Type feed_format);
static QList<ServiceRoot*> getAccounts(const QSqlDatabase& db, bool* ok = nullptr);
static Assignment getStandardCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static Assignment getStandardFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
// TT-RSS acccount.
static QList<ServiceRoot*> getTtRssAccounts(const QSqlDatabase& db, bool* ok = nullptr);
static bool deleteTtRssAccount(const QSqlDatabase& db, int account_id);
static bool overwriteTtRssAccount(const QSqlDatabase& db, const QString& username, const QString& password,
bool auth_protected, const QString& auth_username, const QString& auth_password,
const QString& url, bool force_server_side_feed_update,
bool download_only_unread_messages, int account_id);
static bool createTtRssAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
const QString& password, bool auth_protected, const QString& auth_username,
const QString& auth_password, const QString& url,
bool force_server_side_feed_update, bool download_only_unread_messages);
static Assignment getTtRssFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
private:
static QString unnulifyString(const QString& str);

View File

@ -82,6 +82,7 @@ void FormEditOwnCloudAccount::execForEdit(OwnCloudServiceRoot* existing_root) {
m_ui->m_txtUsername->lineEdit()->setText(existing_root->network()->authUsername());
m_ui->m_txtPassword->lineEdit()->setText(existing_root->network()->authPassword());
m_ui->m_txtUrl->lineEdit()->setText(existing_root->network()->url());
m_ui->m_checkDownloadOnlyUnreadMessages->setChecked(existing_root->network()->downloadOnlyUnreadMessages());
m_ui->m_checkServerSideUpdate->setChecked(existing_root->network()->forceServerSideUpdate());
m_ui->m_spinLimitMessages->setValue(existing_root->network()->batchSize());
@ -147,6 +148,8 @@ void FormEditOwnCloudAccount::onClickedOk() {
m_editableRoot->network()->setAuthPassword(m_ui->m_txtPassword->lineEdit()->text());
m_editableRoot->network()->setForceServerSideUpdate(m_ui->m_checkServerSideUpdate->isChecked());
m_editableRoot->network()->setBatchSize(m_ui->m_spinLimitMessages->value());
m_editableRoot->network()->setDownloadOnlyUnreadMessages(m_ui->m_checkDownloadOnlyUnreadMessages->isChecked());
m_editableRoot->saveAccountDataToDatabase();
accept();

View File

@ -33,14 +33,14 @@
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkServerSideUpdate">
<property name="text">
<string>Force execution of server-side update when updating feeds from RSS Guard</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="m_lblServerSideUpdateInformation">
<property name="text">
<string/>
@ -50,14 +50,17 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Limit number of downloaded messages per feed</string>
</property>
<property name="buddy">
<cstring>m_spinLimitMessages</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QSpinBox" name="m_spinLimitMessages">
<property name="maximumSize">
<size>
@ -79,7 +82,7 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="m_lblLimitMessages">
<property name="text">
<string/>
@ -89,7 +92,7 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QGroupBox" name="m_gbAuthentication">
<property name="toolTip">
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>
@ -140,7 +143,7 @@
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="m_btnTestSetup">
@ -164,7 +167,7 @@
</item>
</layout>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -177,6 +180,13 @@
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="m_checkDownloadOnlyUnreadMessages">
<property name="text">
<string>Download only unread messages</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -205,6 +215,13 @@
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_checkDownloadOnlyUnreadMessages</tabstop>
<tabstop>m_checkServerSideUpdate</tabstop>
<tabstop>m_spinLimitMessages</tabstop>
<tabstop>m_checkShowPassword</tabstop>
<tabstop>m_btnTestSetup</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -18,7 +18,7 @@
#include <utility>
OwnCloudNetworkFactory::OwnCloudNetworkFactory()
: m_url(QString()), m_fixedUrl(QString()), m_forceServerSideUpdate(false),
: m_url(QString()), m_fixedUrl(QString()), m_downloadOnlyUnreadMessages(false), m_forceServerSideUpdate(false),
m_authUsername(QString()), m_authPassword(QString()), m_batchSize(OWNCLOUD_UNLIMITED_BATCH_SIZE), m_urlUser(QString()), m_urlStatus(
QString()),
m_urlFolders(QString()), m_urlFeeds(QString()), m_urlMessages(QString()), m_urlFeedsUpdate(QString()),
@ -45,7 +45,7 @@ void OwnCloudNetworkFactory::setUrl(const QString& url) {
m_urlStatus = m_fixedUrl + OWNCLOUD_API_PATH + "status";
m_urlFolders = m_fixedUrl + OWNCLOUD_API_PATH + "folders";
m_urlFeeds = m_fixedUrl + OWNCLOUD_API_PATH + "feeds";
m_urlMessages = m_fixedUrl + OWNCLOUD_API_PATH + "items?id=%1&batchSize=%2&type=%3";
m_urlMessages = m_fixedUrl + OWNCLOUD_API_PATH + "items?id=%1&batchSize=%2&type=%3&getRead=%4";
m_urlFeedsUpdate = m_fixedUrl + OWNCLOUD_API_PATH + "feeds/update?userId=%1&feedId=%2";
m_urlDeleteFeed = m_fixedUrl + OWNCLOUD_API_PATH + "feeds/%1";
m_urlRenameFeed = m_fixedUrl + OWNCLOUD_API_PATH + "feeds/%1/rename";
@ -264,7 +264,8 @@ OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
QString final_url = m_urlMessages.arg(QString::number(feed_id),
QString::number(batchSize() <= 0 ? -1 : batchSize()),
QString::number(0));
QString::number(0),
m_downloadOnlyUnreadMessages ? QSL("false") : QSL("true"));
QByteArray result_raw;
QList<QPair<QByteArray, QByteArray>> headers;
@ -425,6 +426,14 @@ void OwnCloudNetworkFactory::setBatchSize(int batch_size) {
m_batchSize = batch_size;
}
bool OwnCloudNetworkFactory::downloadOnlyUnreadMessages() const {
return m_downloadOnlyUnreadMessages;
}
void OwnCloudNetworkFactory::setDownloadOnlyUnreadMessages(bool dowload_only_unread_messages) {
m_downloadOnlyUnreadMessages = dowload_only_unread_messages;
}
QString OwnCloudNetworkFactory::userId() const {
return m_userId;
}

View File

@ -57,7 +57,7 @@ class RootItem;
class OwnCloudGetFeedsCategoriesResponse {
public:
explicit OwnCloudGetFeedsCategoriesResponse(QString raw_categories = QString(), QString raw_feeds = QString());
explicit OwnCloudGetFeedsCategoriesResponse(QString raw_categories = QString(), QString raw_feeds = QString());
virtual ~OwnCloudGetFeedsCategoriesResponse();
// Returns tree of feeds/categories.
@ -121,9 +121,13 @@ class OwnCloudNetworkFactory {
int batchSize() const;
void setBatchSize(int batch_size);
bool downloadOnlyUnreadMessages() const;
void setDownloadOnlyUnreadMessages(bool dowload_only_unread_messages);
private:
QString m_url;
QString m_fixedUrl;
bool m_downloadOnlyUnreadMessages;
bool m_forceServerSideUpdate;
QString m_authUsername;
QString m_authPassword;

View File

@ -138,7 +138,7 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase() {
if (DatabaseQueries::overwriteOwnCloudAccount(database, m_network->authUsername(),
m_network->authPassword(), m_network->url(),
m_network->forceServerSideUpdate(), m_network->batchSize(),
accountId())) {
m_network->downloadOnlyUnreadMessages(), accountId())) {
updateTitle();
itemChanged(QList<RootItem*>() << this);
}
@ -151,6 +151,7 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase() {
if (DatabaseQueries::createOwnCloudAccount(database, id_to_assign, m_network->authUsername(),
m_network->authPassword(), m_network->url(),
m_network->forceServerSideUpdate(),
m_network->downloadOnlyUnreadMessages(),
m_network->batchSize())) {
setId(id_to_assign);
setAccountId(id_to_assign);

View File

@ -175,7 +175,7 @@
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkDownloadOnlyUnreadMessages">
<property name="text">
<string>Download only unread messages.</string>
<string>Download only unread messages</string>
</property>
</widget>
</item>