Added ability to change auto-update strategy for individual TT-RSS feeds.

This commit is contained in:
Martin Rotter 2015-12-18 10:31:14 +01:00
parent 2324544aaf
commit b4982e5666
10 changed files with 311 additions and 205 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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;

View file

@ -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<StandardCategory*> categories,
void FormStandardCategoryDetails::loadCategories(const QList<Category*> 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

View file

@ -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<StandardCategory*> categories, RootItem *root_item, StandardCategory *input_category);
void loadCategories(const QList<Category *> categories, RootItem *root_item, StandardCategory *input_category);
private:
Ui::FormStandardCategoryDetails *m_ui;

View file

@ -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<StandardFeed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(new_index).toInt());
Feed::AutoUpdateType auto_update_type = static_cast<Feed::AutoUpdateType>(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<StandardFeed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
new_feed->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(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<StandardCategory*> categories,
void FormStandardFeedDetails::loadCategories(const QList<Category*> 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));

View file

@ -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<StandardCategory*> categories,
RootItem *root_item);
void loadCategories(const QList<Category*> categories, RootItem *root_item);
private:
Ui::FormStandardFeedDetails *m_ui;

View file

@ -7,132 +7,177 @@
<x>0</x>
<y>0</y>
<width>541</width>
<height>339</height>
<height>377</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string notr="true">Dialog</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="3" 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>
</property>
<property name="title">
<string>Authentication</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>m_txtUsername</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>m_txtPassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtPassword" native="true"/>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="m_checkShowPassword">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="m_lblTitle">
<property name="text">
<string>URL</string>
</property>
<property name="buddy">
<cstring>m_txtUrl</cstring>
</property>
</widget>
</item>
<item>
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
</item>
</layout>
</item>
<item row="3" 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>
</property>
<property name="title">
<string>Authentication</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>m_txtUsername</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>m_txtPassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtPassword" native="true"/>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="m_checkShowPassword">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="m_gbHttpAuthentication">
<property name="toolTip">
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>
</property>
<property name="title">
<string>Requires HTTP authentication</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>m_txtUsername</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtHttpUsername" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>m_txtPassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtHttpPassword" native="true"/>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="m_checkShowHttpPassword">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="m_btnTestSetup">
<property name="text">
<string>&amp;Test setup</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
<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>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="m_lblDescription">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="m_gbHttpAuthentication">
<property name="toolTip">
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>
</property>
<property name="title">
<string>Requires HTTP authentication</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>m_txtUsername</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtHttpUsername" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>m_txtPassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtHttpPassword" native="true"/>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="m_checkShowHttpPassword">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="1">
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item>
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -142,47 +187,6 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="m_lblTitle">
<property name="text">
<string>URL</string>
</property>
<property name="buddy">
<cstring>m_txtUrl</cstring>
</property>
</widget>
</item>
<item>
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="m_btnTestSetup">
<property name="text">
<string>&amp;Test setup</string>
</property>
</widget>
</item>
<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>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="m_lblDescription">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>

View file

@ -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 <QSqlQuery>
#include <QSqlError>
#include <QPointer>
TtRssFeed::TtRssFeed(RootItem *parent)
@ -50,6 +53,49 @@ TtRssServiceRoot *TtRssFeed::serviceRoot() {
return qobject_cast<TtRssServiceRoot*>(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<FormEditFeed> 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<Message> &messages) {
if (messages.isEmpty()) {
return 0;

View file

@ -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<Message> &messages);