From b4982e56661d1717f0b2f0490884db08540302d2 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 18 Dec 2015 10:31:14 +0100 Subject: [PATCH] Added ability to change auto-update strategy for individual TT-RSS feeds. --- CMakeLists.txt | 3 + src/services/abstract/feed.cpp | 27 ++ src/services/abstract/feed.h | 30 +- .../gui/formstandardcategorydetails.cpp | 7 +- .../gui/formstandardcategorydetails.h | 3 +- .../standard/gui/formstandardfeeddetails.cpp | 24 +- .../standard/gui/formstandardfeeddetails.h | 5 +- src/services/tt-rss/gui/formeditaccount.ui | 328 +++++++++--------- src/services/tt-rss/ttrssfeed.cpp | 82 +++++ src/services/tt-rss/ttrssfeed.h | 7 + 10 files changed, 311 insertions(+), 205 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe55b1e33..85f24324c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -444,6 +444,7 @@ set(APP_SOURCES src/services/tt-rss/ttrsscategory.cpp src/services/tt-rss/ttrssrecyclebin.cpp src/services/tt-rss/gui/formeditaccount.cpp + src/services/tt-rss/gui/formeditfeed.cpp src/services/tt-rss/network/ttrssnetworkfactory.cpp # NETWORK-WEB sources. @@ -566,6 +567,7 @@ set(APP_HEADERS src/services/tt-rss/ttrssfeed.h src/services/tt-rss/ttrsscategory.h src/services/tt-rss/gui/formeditaccount.h + src/services/tt-rss/gui/formeditfeed.h # NETWORK-WEB headers. src/network-web/webpage.h @@ -608,6 +610,7 @@ set(APP_FORMS # TT-RSS service forms. src/services/tt-rss/gui/formeditaccount.ui + src/services/tt-rss/gui/formeditfeed.ui # NETWORK forms. src/network-web/downloadmanager.ui diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index b838c33fb..277a19962 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -50,3 +50,30 @@ QVariant Feed::data(int column, int role) const { return RootItem::data(column, role); } } + +int Feed::autoUpdateInitialInterval() const { + return m_autoUpdateInitialInterval; +} + +void Feed::setAutoUpdateInitialInterval(int auto_update_interval) { + // If new initial auto-update interval is set, then + // we should reset time that remains to the next auto-update. + m_autoUpdateInitialInterval = auto_update_interval; + m_autoUpdateRemainingInterval = auto_update_interval; +} + +Feed::AutoUpdateType Feed::autoUpdateType() const { + return m_autoUpdateType; +} + +void Feed::setAutoUpdateType(Feed::AutoUpdateType auto_update_type) { + m_autoUpdateType = auto_update_type; +} + +int Feed::autoUpdateRemainingInterval() const { + return m_autoUpdateRemainingInterval; +} + +void Feed::setAutoUpdateRemainingInterval(int auto_update_remaining_interval) { + m_autoUpdateRemainingInterval = auto_update_remaining_interval; +} diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index 4b9b9a550..df47f1e2f 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -69,32 +69,14 @@ class Feed : public RootItem { // Members to override. */ ///////////////////////////////////////// - inline int autoUpdateInitialInterval() const { - return m_autoUpdateInitialInterval; - } + int autoUpdateInitialInterval() const; + void setAutoUpdateInitialInterval(int auto_update_interval); - inline void setAutoUpdateInitialInterval(int auto_update_interval) { - // If new initial auto-update interval is set, then - // we should reset time that remains to the next auto-update. - m_autoUpdateInitialInterval = auto_update_interval; - m_autoUpdateRemainingInterval = auto_update_interval; - } + AutoUpdateType autoUpdateType() const; + void setAutoUpdateType(AutoUpdateType auto_update_type); - inline AutoUpdateType autoUpdateType() const { - return m_autoUpdateType; - } - - inline void setAutoUpdateType(const AutoUpdateType &autoUpdateType) { - m_autoUpdateType = autoUpdateType; - } - - inline int autoUpdateRemainingInterval() const { - return m_autoUpdateRemainingInterval; - } - - inline void setAutoUpdateRemainingInterval(int autoUpdateRemainingInterval) { - m_autoUpdateRemainingInterval = autoUpdateRemainingInterval; - } + int autoUpdateRemainingInterval() const; + void setAutoUpdateRemainingInterval(int auto_update_remaining_interval); inline Status status() const { return m_status; diff --git a/src/services/standard/gui/formstandardcategorydetails.cpp b/src/services/standard/gui/formstandardcategorydetails.cpp index 00e0664d6..484634cd4 100755 --- a/src/services/standard/gui/formstandardcategorydetails.cpp +++ b/src/services/standard/gui/formstandardcategorydetails.cpp @@ -26,6 +26,7 @@ #include "gui/messagebox.h" #include "gui/systemtrayicon.h" #include "gui/dialogs/formmain.h" +#include "services/abstract/category.h" #include "services/standard/standardcategory.h" #include "services/standard/standardserviceroot.h" @@ -76,7 +77,7 @@ void FormStandardCategoryDetails::setEditableCategory(StandardCategory *editable int FormStandardCategoryDetails::exec(StandardCategory *input_category, RootItem *parent_to_select) { // Load categories. - loadCategories(m_serviceRoot->allCategories(), m_serviceRoot, input_category); + loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot, input_category); if (input_category == NULL) { // User is adding new category. @@ -246,14 +247,14 @@ void FormStandardCategoryDetails::initialize() { m_ui->m_txtTitle->lineEdit()->setFocus(Qt::TabFocusReason); } -void FormStandardCategoryDetails::loadCategories(const QList categories, +void FormStandardCategoryDetails::loadCategories(const QList categories, RootItem *root_item, StandardCategory *input_category) { m_ui->m_cmbParentCategory->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*) root_item)); - foreach (StandardCategory *category, categories) { + foreach (Category *category, categories) { if (input_category != NULL && (category == input_category || category->isChildOf(input_category))) { // This category cannot be selected as the new // parent for currently edited category, so diff --git a/src/services/standard/gui/formstandardcategorydetails.h b/src/services/standard/gui/formstandardcategorydetails.h index 3717b3251..8ee09b891 100755 --- a/src/services/standard/gui/formstandardcategorydetails.h +++ b/src/services/standard/gui/formstandardcategorydetails.h @@ -27,6 +27,7 @@ namespace Ui { class FormStandardCategoryDetails; } +class Category; class StandardCategory; class StandardServiceRoot; class FeedsModel; @@ -72,7 +73,7 @@ class FormStandardCategoryDetails : public QDialog { // Loads categories into the dialog + give root "category" // and make sure that no childs of input category (including) // input category are loaded. - void loadCategories(const QList categories, RootItem *root_item, StandardCategory *input_category); + void loadCategories(const QList categories, RootItem *root_item, StandardCategory *input_category); private: Ui::FormStandardCategoryDetails *m_ui; diff --git a/src/services/standard/gui/formstandardfeeddetails.cpp b/src/services/standard/gui/formstandardfeeddetails.cpp index 84ac02b9a..88c3656a7 100755 --- a/src/services/standard/gui/formstandardfeeddetails.cpp +++ b/src/services/standard/gui/formstandardfeeddetails.cpp @@ -20,8 +20,8 @@ #include "definitions/definitions.h" #include "core/feedsmodel.h" #include "services/abstract/rootitem.h" +#include "services/abstract/category.h" #include "services/standard/standardserviceroot.h" -#include "services/standard/standardcategory.h" #include "services/standard/standardfeed.h" #include "miscellaneous/textfactory.h" #include "miscellaneous/iconfactory.h" @@ -61,7 +61,7 @@ FormStandardFeedDetails::~FormStandardFeedDetails() { int FormStandardFeedDetails::exec(StandardFeed *input_feed, RootItem *parent_to_select) { // Load categories. - loadCategories(m_serviceRoot->allCategories(), m_serviceRoot); + loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot); if (input_feed == NULL) { // User is adding new category. @@ -169,15 +169,15 @@ void FormStandardFeedDetails::onAuthenticationSwitched() { } void FormStandardFeedDetails::onAutoUpdateTypeChanged(int new_index) { - StandardFeed::AutoUpdateType auto_update_type = static_cast(m_ui->m_cmbAutoUpdateType->itemData(new_index).toInt()); + Feed::AutoUpdateType auto_update_type = static_cast(m_ui->m_cmbAutoUpdateType->itemData(new_index).toInt()); switch (auto_update_type) { - case StandardFeed::DontAutoUpdate: - case StandardFeed::DefaultAutoUpdate: + case Feed::DontAutoUpdate: + case Feed::DefaultAutoUpdate: m_ui->m_spinAutoUpdateInterval->setEnabled(false); break; - case StandardFeed::SpecificAutoUpdate: + case Feed::SpecificAutoUpdate: default: m_ui->m_spinAutoUpdateInterval->setEnabled(true); } @@ -235,7 +235,7 @@ void FormStandardFeedDetails::apply() { new_feed->setPasswordProtected(m_ui->m_gbAuthentication->isChecked()); new_feed->setUsername(m_ui->m_txtUsername->lineEdit()->text()); new_feed->setPassword(m_ui->m_txtPassword->lineEdit()->text()); - new_feed->setAutoUpdateType(static_cast(m_ui->m_cmbAutoUpdateType->itemData(m_ui->m_cmbAutoUpdateType->currentIndex()).toInt())); + new_feed->setAutoUpdateType(static_cast(m_ui->m_cmbAutoUpdateType->itemData(m_ui->m_cmbAutoUpdateType->currentIndex()).toInt())); new_feed->setAutoUpdateInitialInterval(m_ui->m_spinAutoUpdateInterval->value()); if (m_editableFeed == NULL) { @@ -458,9 +458,9 @@ void FormStandardFeedDetails::initialize() { // Setup auto-update options. m_ui->m_spinAutoUpdateInterval->setValue(DEFAULT_AUTO_UPDATE_INTERVAL); - m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update using global interval"), QVariant::fromValue((int) StandardFeed::DefaultAutoUpdate)); - m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update every"), QVariant::fromValue((int) StandardFeed::SpecificAutoUpdate)); - m_ui->m_cmbAutoUpdateType->addItem(tr("Do not auto-update at all"), QVariant::fromValue((int) StandardFeed::DontAutoUpdate)); + m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update using global interval"), QVariant::fromValue((int) Feed::DefaultAutoUpdate)); + m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update every"), QVariant::fromValue((int) Feed::SpecificAutoUpdate)); + m_ui->m_cmbAutoUpdateType->addItem(tr("Do not auto-update at all"), QVariant::fromValue((int) Feed::DontAutoUpdate)); // Set tab order. setTabOrder(m_ui->m_cmbParentCategory, m_ui->m_cmbType); @@ -484,13 +484,13 @@ void FormStandardFeedDetails::initialize() { m_ui->m_txtUrl->lineEdit()->setFocus(Qt::TabFocusReason); } -void FormStandardFeedDetails::loadCategories(const QList categories, +void FormStandardFeedDetails::loadCategories(const QList categories, RootItem *root_item) { m_ui->m_cmbParentCategory->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*) root_item)); - foreach (StandardCategory *category, categories) { + foreach (Category *category, categories) { m_ui->m_cmbParentCategory->addItem(category->icon(), category->title(), QVariant::fromValue((void*) category)); diff --git a/src/services/standard/gui/formstandardfeeddetails.h b/src/services/standard/gui/formstandardfeeddetails.h index d3651f969..c5817a399 100755 --- a/src/services/standard/gui/formstandardfeeddetails.h +++ b/src/services/standard/gui/formstandardfeeddetails.h @@ -29,7 +29,7 @@ namespace Ui { class StandardServiceRoot; class StandardFeed; -class StandardCategory; +class Category; class RootItem; class FormStandardFeedDetails : public QDialog { @@ -78,8 +78,7 @@ class FormStandardFeedDetails : public QDialog { void initialize(); // Loads categories into the dialog from the model. - void loadCategories(const QList categories, - RootItem *root_item); + void loadCategories(const QList categories, RootItem *root_item); private: Ui::FormStandardFeedDetails *m_ui; diff --git a/src/services/tt-rss/gui/formeditaccount.ui b/src/services/tt-rss/gui/formeditaccount.ui index 6f655e1e4..c8338dad6 100755 --- a/src/services/tt-rss/gui/formeditaccount.ui +++ b/src/services/tt-rss/gui/formeditaccount.ui @@ -7,132 +7,177 @@ 0 0 541 - 339 + 377 - Dialog + Dialog - - - - - Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported. - - - Authentication - - - false - - - false - - - - - - Username - - - m_txtUsername - - - - - - - Password - - - m_txtPassword - - - - - - - - - - - - - Show password - - - - - + + + + + + + + + URL + + + m_txtUrl + + + + + + + + + + + + Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported. + + + Authentication + + + false + + + false + + + + + + Username + + + m_txtUsername + + + + + + + Password + + + m_txtPassword + + + + + + + + + + + + + Show password + + + + + + + + + + Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported. + + + Requires HTTP authentication + + + false + + + true + + + false + + + + + + Username + + + m_txtUsername + + + + + + + + + + Password + + + m_txtPassword + + + + + + + + + + Show password + + + + + + + + + + &Test setup + + + + + + + + 0 + 0 + + + + Qt::RightToLeft + + + + + + + Force execution of server-side update when updating feeds from RSS Guard + + + true + + + + + + + + + + + - - - - Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported. - - - Requires HTTP authentication - - - false - - - true - - - false - - - - - - Username - - - m_txtUsername - - - - - - - - - - Password - - - m_txtPassword - - - - - - - - - - Show password - - - - - - - - - - - 0 - 0 - - - - Qt::RightToLeft - - - - + Qt::Horizontal @@ -142,47 +187,6 @@ - - - - - - URL - - - m_txtUrl - - - - - - - - - - - - &Test setup - - - - - - - Force execution of server-side update when updating feeds from RSS Guard - - - true - - - - - - - - - - diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index 2796008a1..19df0f74d 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -22,12 +22,15 @@ #include "miscellaneous/databasefactory.h" #include "miscellaneous/iconfactory.h" #include "miscellaneous/textfactory.h" +#include "gui/dialogs/formmain.h" #include "services/tt-rss/definitions.h" #include "services/tt-rss/ttrssserviceroot.h" +#include "services/tt-rss/gui/formeditfeed.h" #include "services/tt-rss/network/ttrssnetworkfactory.h" #include #include +#include TtRssFeed::TtRssFeed(RootItem *parent) @@ -50,6 +53,49 @@ TtRssServiceRoot *TtRssFeed::serviceRoot() { return qobject_cast(getParentServiceRoot()); } +QVariant TtRssFeed::data(int column, int role) const { + switch (role) { + case Qt::ToolTipRole: + if (column == FDS_MODEL_TITLE_INDEX) { + QString auto_update_string; + + switch (autoUpdateType()) { + case DontAutoUpdate: + //: Describes feed auto-update status. + auto_update_string = tr("does not use auto-update"); + break; + + case DefaultAutoUpdate: + //: Describes feed auto-update status. + auto_update_string = tr("uses global settings"); + break; + + case SpecificAutoUpdate: + default: + //: Describes feed auto-update status. + auto_update_string = tr("uses specific settings " + "(%n minute(s) to next auto-update)", + 0, + autoUpdateRemainingInterval()); + break; + } + + //: Tooltip for feed. + return tr("%1" + "%2\n\n" + "Auto-update status: %3").arg(title(), + description().isEmpty() ? QString() : QString('\n') + description(), + auto_update_string); + } + else { + return Feed::data(column, role); + } + + default: + return Feed::data(column, role); + } +} + void TtRssFeed::updateCounts(bool including_total_count) { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlQuery query_all(database); @@ -76,6 +122,18 @@ void TtRssFeed::updateCounts(bool including_total_count) { } } +bool TtRssFeed::canBeEdited() { + return true; +} + +bool TtRssFeed::editViaGui() { + QPointer form_pointer = new FormEditFeed(serviceRoot(), qApp->mainForm()); + + form_pointer.data()->execForEdit(this); + delete form_pointer.data(); + return false; +} + int TtRssFeed::countOfAllMessages() const { return m_totalCount; } @@ -171,6 +229,30 @@ void TtRssFeed::setCustomId(int custom_id) { m_customId = custom_id; } +bool TtRssFeed::editItself(TtRssFeed *new_feed_data) { + QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings); + QSqlQuery query_update(database); + + query_update.setForwardOnly(true); + query_update.prepare("UPDATE Feeds " + "SET update_type = :update_type, update_interval = :update_interval " + "WHERE id = :id;"); + + query_update.bindValue(QSL(":update_type"), (int) new_feed_data->autoUpdateType()); + query_update.bindValue(QSL(":update_interval"), new_feed_data->autoUpdateInitialInterval()); + query_update.bindValue(QSL(":id"), id()); + + if (query_update.exec()) { + setAutoUpdateType(new_feed_data->autoUpdateType()); + setAutoUpdateInitialInterval(new_feed_data->autoUpdateInitialInterval()); + + return true; + } + else { + return false; + } +} + int TtRssFeed::updateMessages(const QList &messages) { if (messages.isEmpty()) { return 0; diff --git a/src/services/tt-rss/ttrssfeed.h b/src/services/tt-rss/ttrssfeed.h index 66c6838a6..83a16eeb5 100755 --- a/src/services/tt-rss/ttrssfeed.h +++ b/src/services/tt-rss/ttrssfeed.h @@ -35,8 +35,13 @@ class TtRssFeed : public Feed { TtRssServiceRoot *serviceRoot(); + QVariant data(int column, int role) const; + void updateCounts(bool including_total_count); + bool canBeEdited(); + bool editViaGui(); + int countOfAllMessages() const; int countOfUnreadMessages() const; @@ -49,6 +54,8 @@ class TtRssFeed : public Feed { int customId() const; void setCustomId(int custom_id); + bool editItself(TtRssFeed *new_feed_data); + private: int updateMessages(const QList &messages);