Merge pull request #1019 from RachidTagzen/master

New Features: Avoid Downloading Old Articles to Preserve a Small Database & Supporting RTL
This commit is contained in:
martinrotter 2023-07-31 09:50:47 +02:00 committed by GitHub
commit cd8ba3da17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 407 additions and 70 deletions

View File

@ -1,4 +1,4 @@
<div class="rssguard-mwrapper" dir="auto" id="%8">
<div class="rssguard-mwrapper" dir="%9" id="%8">
<section class="rssguard-mhead">
<div style="float: right; margin: 10px;"><!-- Should it remain here??? -->%7</div>

View File

@ -5,11 +5,13 @@
<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_init_sqlite.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>
</qresource>
</RCC>

View File

@ -31,21 +31,24 @@ CREATE TABLE Categories (
);
-- !
CREATE TABLE Feeds (
id $$,
ordr INTEGER NOT NULL CHECK (ordr >= 0),
title TEXT NOT NULL CHECK (title != ''),
description TEXT,
date_created BIGINT,
icon ^^,
category INTEGER NOT NULL CHECK (category >= -1), /* Physical category ID, also root feeds contain -1 here. */
source TEXT,
update_type INTEGER NOT NULL CHECK (update_type >= 0),
update_interval INTEGER NOT NULL DEFAULT 900 CHECK (update_interval >= 1),
is_off INTEGER NOT NULL DEFAULT 0 CHECK (is_off >= 0 AND is_off <= 1),
is_quiet INTEGER NOT NULL DEFAULT 0 CHECK (is_quiet >= 0 AND is_quiet <= 1),
open_articles INTEGER NOT NULL DEFAULT 0 CHECK (open_articles >= 0 AND open_articles <= 1),
account_id INTEGER NOT NULL,
custom_id TEXT NOT NULL CHECK (custom_id != ''), /* Custom ID cannot be empty, it must contain either service-specific ID, or Feeds/id. */
id $$,
ordr INTEGER NOT NULL CHECK (ordr >= 0),
title TEXT NOT NULL CHECK (title != ''),
description TEXT,
date_created BIGINT,
icon ^^,
category INTEGER NOT NULL CHECK (category >= -1), /* Physical category ID, also root feeds contain -1 here. */
source TEXT,
update_type INTEGER NOT NULL CHECK (update_type >= 0),
update_interval INTEGER NOT NULL DEFAULT 900 CHECK (update_interval >= 1),
is_off INTEGER NOT NULL DEFAULT 0 CHECK (is_off >= 0 AND is_off <= 1),
is_quiet INTEGER NOT NULL DEFAULT 0 CHECK (is_quiet >= 0 AND is_quiet <= 1),
is_rtl INTEGER NOT NULL DEFAULT 0 CHECK (is_rtl >= 0 AND is_rtl <= 1),
add_any_datetime_articles INTEGER NOT NULL DEFAULT 1 CHECK (add_any_datetime_articles >= 0 AND add_any_datetime_articles <= 1),
datetime_to_avoid BIGINT NOT NULL DEFAULT 0 CHECK (datetime_to_avoid >= 0),
open_articles INTEGER NOT NULL DEFAULT 0 CHECK (open_articles >= 0 AND open_articles <= 1),
account_id INTEGER NOT NULL,
custom_id TEXT NOT NULL CHECK (custom_id != ''), /* Custom ID cannot be empty, it must contain either service-specific ID, or Feeds/id. */
/* Custom column for (serialized) custom account-specific data. */
custom_data TEXT,
@ -97,4 +100,4 @@ CREATE TABLE Labels (
account_id INTEGER NOT NULL,
FOREIGN KEY (account_id) REFERENCES Accounts (id) ON DELETE CASCADE
);
);

View File

@ -0,0 +1,8 @@
USE ##;
-- !
SET FOREIGN_KEY_CHECKS = 0;
-- !
!! db_update_sqlite_5_6.sql
-- !
SET FOREIGN_KEY_CHECKS = 1;
-- !

View File

@ -0,0 +1,32 @@
ALTER TABLE Feeds RENAME TO backup_Feeds;
-- !
CREATE TABLE Feeds (
id $$,
ordr INTEGER NOT NULL CHECK (ordr >= 0),
title TEXT NOT NULL CHECK (title != ''),
description TEXT,
date_created BIGINT,
icon ^^,
category INTEGER NOT NULL CHECK (category >= -1), /* Physical category ID, also root feeds contain -1 here. */
source TEXT,
update_type INTEGER NOT NULL CHECK (update_type >= 0),
update_interval INTEGER NOT NULL DEFAULT 900 CHECK (update_interval >= 1),
is_off INTEGER NOT NULL DEFAULT 0 CHECK (is_off >= 0 AND is_off <= 1),
is_quiet INTEGER NOT NULL DEFAULT 0 CHECK (is_quiet >= 0 AND is_quiet <= 1),
is_rtl INTEGER NOT NULL DEFAULT 0 CHECK (is_rtl >= 0 AND is_rtl <= 1),
add_any_datetime_articles INTEGER NOT NULL DEFAULT 1 CHECK (add_any_datetime_articles >= 0 AND add_any_datetime_articles <= 1),
datetime_to_avoid BIGINT NOT NULL DEFAULT 0 CHECK (datetime_to_avoid >= 0),
open_articles INTEGER NOT NULL DEFAULT 0 CHECK (open_articles >= 0 AND open_articles <= 1),
account_id INTEGER NOT NULL,
custom_id TEXT NOT NULL CHECK (custom_id != ''), /* Custom ID cannot be empty, it must contain either service-specific ID, or Feeds/id. */
/* Custom column for (serialized) custom account-specific data. */
custom_data TEXT,
FOREIGN KEY (account_id) REFERENCES Accounts (id) ON DELETE CASCADE
);
-- !
INSERT INTO Feeds (id, ordr, title, description, date_created, icon, category, source, update_type, update_interval, is_off, is_quiet, open_articles, account_id, custom_id, custom_data)
SELECT id, ordr, title, description, date_created, icon, category, source, update_type, update_interval, is_off, is_quiet, open_articles, account_id, custom_id, custom_data
FROM backup_Feeds;
-- !
DROP TABLE backup_Feeds;

View File

@ -238,6 +238,28 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
msg.sanitize(feed, fix_future_datetimes);
}
if (!feed->addAnyDatetimeArticles()) {
QDateTime dt_to_avoid;
if (feed->datetimeToAvoid().isValid()) {
dt_to_avoid = feed->datetimeToAvoid();
}
else if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::AvoidOldArticles)).toBool()) {
dt_to_avoid = qApp->settings()->value(GROUP(Messages), SETTING(Messages::DateTimeToAvoidArticle)).toDateTime();
}
if (dt_to_avoid.isValid()) {
for (int i = 0; i < msgs.size(); i++) {
const auto& mss = msgs.at(i);
if (mss.m_createdFromFeed && mss.m_created < dt_to_avoid) {
qDebugNN << LOGSEC_CORE << "Removing message" << QUOTE_W_SPACE(mss.m_title) << "for being too old.";
msgs.removeAt(i--);
}
}
}
}
if (!feed->messageFilters().isEmpty()) {
tmr.restart();

View File

@ -322,9 +322,11 @@ bool FeedsProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right
bool FeedsProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const {
bool should_show = filterAcceptsRowInternal(source_row, source_parent);
/*
qDebugNN << LOGSEC_CORE << "Filter accepts row"
<< QUOTE_W_SPACE(m_sourceModel->itemForIndex(m_sourceModel->index(source_row, 0, source_parent))->title())
<< "and filter result is:" << QUOTE_W_SPACE_DOT(should_show);
*/
/*
if (should_show && (!filterRegularExpression().pattern().isEmpty() ||

View File

@ -68,7 +68,7 @@ Message::Message() {
m_categories = QList<MessageCategory>();
m_accountId = m_id = 0;
m_score = 0.0;
m_isRead = m_isImportant = m_isDeleted = false;
m_isRead = m_isImportant = m_isDeleted = m_isRtl = false;
m_assignedLabels = QList<Label*>();
m_assignedLabelsByFilter = QList<Label*>();
m_deassignedLabelsByFilter = QList<Label*>();
@ -140,6 +140,7 @@ Message Message::fromSqlRecord(const QSqlRecord& record, bool* result) {
message.m_contents = record.value(MSG_DB_CONTENTS_INDEX).toString();
message.m_enclosures = Enclosures::decodeEnclosuresFromString(record.value(MSG_DB_ENCLOSURES_INDEX).toString());
message.m_score = record.value(MSG_DB_SCORE_INDEX).toDouble();
message.m_isRtl = record.value(MSG_DB_FEED_IS_RTL_INDEX).toBool();
message.m_accountId = record.value(MSG_DB_ACCOUNT_ID_INDEX).toInt();
message.m_customId = record.value(MSG_DB_CUSTOM_ID_INDEX).toString();
message.m_customHash = record.value(MSG_DB_CUSTOM_HASH_INDEX).toString();
@ -179,7 +180,7 @@ QString Message::generateRawAtomContents(const Message& msg) {
QDataStream& operator<<(QDataStream& out, const Message& my_obj) {
out << my_obj.m_accountId << my_obj.m_customHash << my_obj.m_customId << my_obj.m_feedId << my_obj.m_id
<< my_obj.m_isImportant << my_obj.m_isRead << my_obj.m_isDeleted << my_obj.m_score;
<< my_obj.m_isImportant << my_obj.m_isRead << my_obj.m_isDeleted << my_obj.m_score << my_obj.m_isRtl;
return out;
}
@ -193,9 +194,11 @@ QDataStream& operator>>(QDataStream& in, Message& my_obj) {
bool is_important;
bool is_read;
bool is_deleted;
bool is_rtl;
double score;
in >> account_id >> custom_hash >> custom_id >> feed_id >> id >> is_important >> is_read >> is_deleted >> score;
in >> account_id >> custom_hash >> custom_id >> feed_id >> id >> is_important >> is_read >> is_deleted >> score >>
is_rtl;
my_obj.m_accountId = account_id;
my_obj.m_customHash = custom_hash;
@ -206,6 +209,7 @@ QDataStream& operator>>(QDataStream& in, Message& my_obj) {
my_obj.m_isRead = is_read;
my_obj.m_isDeleted = is_deleted;
my_obj.m_score = score;
my_obj.m_isRtl = is_rtl;
return in;
}

View File

@ -80,6 +80,7 @@ class RSSGUARD_DLLSPEC Message {
bool m_isImportant;
bool m_isDeleted;
double m_score;
bool m_isRtl;
QList<Enclosure> m_enclosures;
// List of assigned labels.

View File

@ -294,6 +294,7 @@ void MessagesModel::setupHeaderData() {
/*: Tooltip for custom ID of message.*/ tr("Custom ID") <<
/*: Tooltip for custom hash string of message.*/ tr("Custom hash") <<
/*: Tooltip for name of feed for message.*/ tr("Feed") <<
/*: Tooltip for indication whether article is RTL or not.*/ tr("RTL") <<
/*: Tooltip for indication of presence of enclosures.*/ tr("Has enclosures") <<
/*: Tooltip for indication of labels of message.*/ tr("Assigned labels") <<
/*: Tooltip for indication of label IDs of message.*/ tr("Assigned label IDs");
@ -305,8 +306,8 @@ void MessagesModel::setupHeaderData() {
<< tr("Contents of the article.") << tr("List of attachments.") << tr("Score of the article.")
<< tr("Account ID of the article.") << tr("Custom ID of the article.")
<< tr("Custom hash of the article.") << tr("Name of feed of the article.")
<< tr("Indication of enclosures presence within the article.") << tr("Labels assigned to the article.")
<< tr("Label IDs assigned to the article.");
<< tr("Layout direction of the article") << tr("Indication of enclosures presence within the article.")
<< tr("Labels assigned to the article.") << tr("Label IDs assigned to the article.");
}
Qt::ItemFlags MessagesModel::flags(const QModelIndex& index) const {
@ -409,6 +410,23 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
}
}
case TEXT_DIRECTION_ROLE: {
int index_column = idx.column();
if (index_column != MSG_DB_TITLE_INDEX && index_column != MSG_DB_FEED_TITLE_INDEX &&
index_column != MSG_DB_AUTHOR_INDEX) {
return Qt::LayoutDirection::LayoutDirectionAuto;
}
else {
return (m_cache->containsData(idx.row())
? m_cache->data(index(idx.row(), MSG_DB_FEED_IS_RTL_INDEX))
: QSqlQueryModel::data(index(idx.row(), MSG_DB_FEED_IS_RTL_INDEX), Qt::ItemDataRole::EditRole))
.toInt() == 0
? Qt::LayoutDirection::LayoutDirectionAuto
: Qt::LayoutDirection::RightToLeft;
}
}
case LOWER_TITLE_ROLE:
return m_cache->containsData(idx.row())
? m_cache->data(idx).toString().toLower()

View File

@ -32,12 +32,14 @@ MessagesModelSqlLayer::MessagesModelSqlLayer()
m_orderByNames[MSG_DB_CUSTOM_ID_INDEX] = QSL("Messages.custom_id");
m_orderByNames[MSG_DB_CUSTOM_HASH_INDEX] = QSL("Messages.custom_hash");
m_orderByNames[MSG_DB_FEED_TITLE_INDEX] = QSL("Feeds.title");
m_orderByNames[MSG_DB_FEED_IS_RTL_INDEX] = QSL("Feeds.is_rtl");
m_orderByNames[MSG_DB_HAS_ENCLOSURES] = QSL("has_enclosures");
m_orderByNames[MSG_DB_LABELS] = QSL("msg_labels");
m_orderByNames[MSG_DB_LABELS_IDS] = QSL("Messages.labels");
m_numericColumns << MSG_DB_ID_INDEX << MSG_DB_READ_INDEX << MSG_DB_DELETED_INDEX << MSG_DB_PDELETED_INDEX
<< MSG_DB_IMPORTANT_INDEX << MSG_DB_ACCOUNT_ID_INDEX << MSG_DB_DCREATED_INDEX << MSG_DB_SCORE_INDEX;
<< MSG_DB_IMPORTANT_INDEX << MSG_DB_ACCOUNT_ID_INDEX << MSG_DB_DCREATED_INDEX << MSG_DB_SCORE_INDEX
<< MSG_DB_FEED_IS_RTL_INDEX;
}
void MessagesModelSqlLayer::addSortState(int column, Qt::SortOrder order, bool ignore_multicolumn_sorting) {

View File

@ -33,7 +33,8 @@ QMap<int, QString> DatabaseQueries::messageTableAttributes(bool only_msg_table,
field_names[MSG_DB_CUSTOM_ID_INDEX] = QSL("Messages.custom_id");
field_names[MSG_DB_CUSTOM_HASH_INDEX] = QSL("Messages.custom_hash");
field_names[MSG_DB_FEED_TITLE_INDEX] = only_msg_table ? QSL("Messages.feed") : QSL("Feeds.title");
field_names[MSG_DB_HAS_ENCLOSURES] = QSL("CASE WHEN length(Messages.enclosures) > 10 "
field_names[MSG_DB_FEED_IS_RTL_INDEX] = QSL("Feeds.is_rtl");
field_names[MSG_DB_HAS_ENCLOSURES] = QSL("CASE WHEN LENGTH(Messages.enclosures) > 10 "
"THEN 'true' "
"ELSE 'false' "
"END AS has_enclosures");
@ -2178,11 +2179,11 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
q.prepare("UPDATE Feeds "
"SET title = :title, ordr = :ordr, description = :description, date_created = :date_created, "
" icon = :icon, category = :category, source = :source, update_type = :update_type, "
" update_interval = :update_interval, is_off = :is_off, is_quiet = :is_quiet, open_articles = "
":open_articles, "
" account_id = :account_id, custom_id = :custom_id, custom_data = :custom_data "
"WHERE id = :id;");
" icon = :icon, category = :category, source = :source, update_type = :update_type,"
" update_interval = :update_interval, is_off = :is_off, is_quiet = :is_quiet, open_articles ="
" :open_articles, is_rtl = :is_rtl, add_any_datetime_articles = :add_any_datetime_articles,"
" datetime_to_avoid = :datetime_to_avoid, account_id"
" = :account_id, custom_id = :custom_id, custom_data = :custom_data WHERE id = :id;");
q.bindValue(QSL(":title"), feed->title());
q.bindValue(QSL(":description"), feed->description());
q.bindValue(QSL(":date_created"), feed->creationDate().toMSecsSinceEpoch());
@ -2198,6 +2199,10 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
q.bindValue(QSL(":is_off"), feed->isSwitchedOff());
q.bindValue(QSL(":is_quiet"), feed->isQuiet());
q.bindValue(QSL(":open_articles"), feed->openArticlesDirectly());
q.bindValue(QSL(":is_rtl"), feed->isRtl());
q.bindValue(QSL(":add_any_datetime_articles"), feed->addAnyDatetimeArticles());
q.bindValue(QSL(":datetime_to_avoid"),
feed->datetimeToAvoid().isValid() ? feed->datetimeToAvoid().toMSecsSinceEpoch() : 0);
auto custom_data = feed->customDatabaseData();
QString serialized_custom_data = serializeCustomData(custom_data);

View File

@ -353,6 +353,13 @@ Assignment DatabaseQueries::getFeeds(const QSqlDatabase& db,
feed->setAutoUpdateInterval(query.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
feed->setIsSwitchedOff(query.value(FDS_DB_IS_OFF_INDEX).toBool());
feed->setIsQuiet(query.value(FDS_DB_IS_QUIET_INDEX).toBool());
feed->setIsRtl(query.value(FDS_DB_IS_RTL_INDEX).toBool());
feed->setAddAnyDatetimeArticles(query.value(FDS_DB_ADD_ANY_DATETIME_ARTICLES_INDEX).toBool());
auto dt_avoid = query.value(FDS_DB_DATETIME_TO_AVOID_INDEX).value<qint64>();
feed->setDatetimeToAvoid(dt_avoid > 0 ? TextFactory::parseDateTime(dt_avoid) : QDateTime());
feed->setOpenArticlesDirectly(query.value(FDS_DB_OPEN_ARTICLES_INDEX).toBool());
qDebugNN << LOGSEC_CORE << "Custom ID of feed when loading from DB is" << QUOTE_W_SPACE_DOT(feed->customId());

View File

@ -50,7 +50,8 @@
#define MSG_SCORE_MIN 0.0
#define LOWER_TITLE_ROLE 64
#define HIGHLIGHTED_FOREGROUND_TITLE_ROLE 128
#define HIGHLIGHTED_FOREGROUND_TITLE_ROLE 65
#define TEXT_DIRECTION_ROLE 66
#define SOUNDS_BUILTIN_DIRECTORY ":/sounds"
#define ARGUMENTS_LIST_SEPARATOR "\n"
@ -214,7 +215,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 "5"
#define APP_DB_SCHEMA_VERSION "6"
#define APP_DB_UPDATE_FILE_PATTERN "db_update_%1_%2_%3.sql"
#define APP_DB_COMMENT_SPLIT "-- !\n"
#define APP_DB_INCLUDE_PLACEHOLDER "!!"
@ -267,9 +268,10 @@
#define MSG_DB_CUSTOM_ID_INDEX 14
#define MSG_DB_CUSTOM_HASH_INDEX 15
#define MSG_DB_FEED_TITLE_INDEX 16
#define MSG_DB_HAS_ENCLOSURES 17
#define MSG_DB_LABELS 18
#define MSG_DB_LABELS_IDS 19
#define MSG_DB_FEED_IS_RTL_INDEX 17
#define MSG_DB_HAS_ENCLOSURES 18
#define MSG_DB_LABELS 19
#define MSG_DB_LABELS_IDS 20
// Indexes of columns as they are DEFINED IN THE TABLE for CATEGORIES.
#define CAT_DB_ID_INDEX 0
@ -295,10 +297,13 @@
#define FDS_DB_UPDATE_INTERVAL_INDEX 9
#define FDS_DB_IS_OFF_INDEX 10
#define FDS_DB_IS_QUIET_INDEX 11
#define FDS_DB_OPEN_ARTICLES_INDEX 12
#define FDS_DB_ACCOUNT_ID_INDEX 13
#define FDS_DB_CUSTOM_ID_INDEX 14
#define FDS_DB_CUSTOM_DATA_INDEX 15
#define FDS_DB_IS_RTL_INDEX 12
#define FDS_DB_ADD_ANY_DATETIME_ARTICLES_INDEX 13
#define FDS_DB_DATETIME_TO_AVOID_INDEX 14
#define FDS_DB_OPEN_ARTICLES_INDEX 15
#define FDS_DB_ACCOUNT_ID_INDEX 16
#define FDS_DB_CUSTOM_ID_INDEX 17
#define FDS_DB_CUSTOM_DATA_INDEX 18
// Indexes of columns for feed models.
#define FDS_MODEL_TITLE_INDEX 0

View File

@ -233,6 +233,10 @@ void FeedsView::editSelectedItem() {
// Changes are done, unlock the update master lock.
qApp->feedUpdateLock()->unlock();
// TODO: NOTE: Make sure to refresh article list if RTL is changed?
// RootItem* selected_item = selectedItem();
// emit itemSelected(selected_item);
}
void FeedsView::deleteSelectedItem() {

View File

@ -175,7 +175,6 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
}
else {
ensureDefaultBrowserVisible();
m_msgBrowser->loadMessages({message}, m_root);
}
}

View File

@ -516,6 +516,20 @@ void MessagesView::loadItem(RootItem* item) {
sort(col, ord, false, true, false, true);
m_sourceModel->loadMessages(item);
/*
if (item->kind() == RootItem::Kind::Feed) {
if (item->toFeed()->isRtl()) {
setLayoutDirection(Qt::LayoutDirection::RightToLeft);
}
else {
setLayoutDirection(Qt::LayoutDirection::LeftToRight);
}
}
else {
setLayoutDirection(Qt::LayoutDirection::LeftToRight);
}
*/
// Messages are loaded, make sure that previously
// active message is not shown in browser.
emit currentMessageRemoved(m_sourceModel->loadedItem());
@ -826,6 +840,7 @@ void MessagesView::adjustColumns() {
hideColumn(MSG_DB_CUSTOM_HASH_INDEX);
hideColumn(MSG_DB_FEED_CUSTOM_ID_INDEX);
hideColumn(MSG_DB_FEED_TITLE_INDEX);
hideColumn(MSG_DB_FEED_IS_RTL_INDEX);
hideColumn(MSG_DB_HAS_ENCLOSURES);
hideColumn(MSG_DB_LABELS);

View File

@ -16,6 +16,12 @@ void StyledItemDelegateWithoutFocus::paint(QPainter* painter,
item_option.state = item_option.state ^ QStyle::StateFlag::State_HasFocus;
}
bool rtl = index.data(TEXT_DIRECTION_ROLE).value<Qt::LayoutDirection>() == Qt::LayoutDirection::RightToLeft;
if (rtl) {
item_option.direction = Qt::LayoutDirection::RightToLeft;
}
if ((item_option.state & QStyle::StateFlag::State_Selected) == QStyle::StateFlag::State_Selected &&
index.data(Qt::ItemDataRole::ForegroundRole).isValid()) {
item_option.palette.setColor(QPalette::ColorRole::HighlightedText,

View File

@ -197,6 +197,11 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
m_ui->m_spinFeedUpdateTimeout->setSuffix(QSL(" ") + m_ui->m_spinFeedUpdateTimeout->suffix());
}
m_ui->m_dtDateTimeToAvoid->setDisplayFormat(qApp->localization()->loadedLocale().dateFormat());
connect(m_ui->m_gbAvoidOldArticles, &QGroupBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_dtDateTimeToAvoid, &QDateTimeEdit::dateTimeChanged, this, &SettingsFeedsMessages::dirtifySettings);
m_ui->m_spinRelativeArticleTime->setValue(-1);
}
@ -260,6 +265,10 @@ void SettingsFeedsMessages::loadSettings() {
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::AutoUpdateOnlyUnfocused)).toBool());
m_ui->m_spinAutoUpdateInterval->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::AutoUpdateInterval)).toInt());
m_ui->m_spinFeedUpdateTimeout->setValue(settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt());
m_ui->m_gbAvoidOldArticles
->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::AvoidOldArticles)).toBool());
m_ui->m_dtDateTimeToAvoid
->setDateTime(settings()->value(GROUP(Messages), SETTING(Messages::DateTimeToAvoidArticle)).toDateTime());
m_ui->m_cmbFastAutoUpdate->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::FastAutoUpdate)).toBool());
m_ui->m_checkUpdateAllFeedsOnStartup
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateOnStartup)).toBool());
@ -346,6 +355,8 @@ void SettingsFeedsMessages::saveSettings() {
settings()->setValue(GROUP(Feeds), Feeds::AutoUpdateOnlyUnfocused, m_ui->m_checkAutoUpdateOnlyUnfocused->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::AutoUpdateInterval, m_ui->m_spinAutoUpdateInterval->value());
settings()->setValue(GROUP(Feeds), Feeds::UpdateTimeout, m_ui->m_spinFeedUpdateTimeout->value());
settings()->setValue(GROUP(Messages), Messages::AvoidOldArticles, m_ui->m_gbAvoidOldArticles->isChecked());
settings()->setValue(GROUP(Messages), Messages::DateTimeToAvoidArticle, m_ui->m_dtDateTimeToAvoid->dateTime());
settings()->setValue(GROUP(Feeds), Feeds::FastAutoUpdate, m_ui->m_cmbFastAutoUpdate->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::FeedsUpdateOnStartup, m_ui->m_checkUpdateAllFeedsOnStartup->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::FeedsUpdateStartupDelay, m_ui->m_spinStartupUpdateDelay->value());

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>558</width>
<width>570</width>
<height>531</height>
</rect>
</property>
@ -80,6 +80,13 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="m_cmbFastAutoUpdate">
<property name="text">
<string>Support very fast auto-fetching intervals (under 10 seconds)</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
@ -115,11 +122,42 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="m_cmbFastAutoUpdate">
<property name="text">
<string>Support very fast auto-fetching intervals (under 10 seconds)</string>
<item row="5" column="0" colspan="2">
<widget class="QGroupBox" name="m_gbAvoidOldArticles">
<property name="title">
<string>Avoid adding articles before this date into the database</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QDateTimeEdit" name="m_dtDateTimeToAvoid">
<property name="displayFormat">
<string>dd/MM/yyyy HH:mm</string>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>

View File

@ -302,6 +302,22 @@ void TextBrowserViewer::loadMessages(const QList<Message>& messages, RootItem* r
// auto html_messages = qApp->skins()->generateHtmlOfArticles(messages, root);
setHtml(html_messages.m_html, html_messages.m_baseUrl);
/*
auto* feed = root != nullptr
? root->getParentServiceRoot()
->getItemFromSubTree([messages](const RootItem* it) {
return it->kind() == RootItem::Kind::Feed && it->customId() == messages.at(0).m_feedId;
})
->toFeed()
: nullptr;
bool is_rtl_feed = feed != nullptr && feed->isRtl();
*/
QTextOption op;
op.setTextDirection(messages.at(0).m_isRtl ? Qt::LayoutDirection::RightToLeft : Qt::LayoutDirection::LeftToRight);
document()->setDefaultTextOption(op);
emit loadingFinished(true);
}
@ -544,16 +560,6 @@ void TextBrowserViewer::setHtml(const QString& html, const QUrl& base_url) {
}
setVerticalScrollBarPosition(0.0);
// TODO: implement RTL for viewers somehow?
/*
auto to = document()->defaultTextOption();
to.setTextDirection(Qt::LayoutDirection::RightToLeft);
to.setAlignment(Qt::AlignmentFlag::AlignRight);
document()->setDefaultTextOption(to);
*/
}
void TextBrowserViewer::setReadabledHtml(const QString& html, const QUrl& base_url) {

View File

@ -130,6 +130,12 @@ DVALUE(int) Messages::MessageHeadImageHeightDef = 36;
DKEY Messages::DisplayEnclosuresInMessage = "show_enclosures_in_message";
DVALUE(bool) Messages::DisplayEnclosuresInMessageDef = false;
DKEY Messages::AvoidOldArticles = "avoid_old_articles";
DVALUE(bool) Messages::AvoidOldArticlesDef = false;
DKEY Messages::DateTimeToAvoidArticle = "datetime_to_avoid_article";
DVALUE(QDateTime) Messages::DateTimeToAvoidArticleDef = QDateTime::currentDateTime();
DKEY Messages::AlwaysDisplayItemPreview = "always_display_preview";
DVALUE(bool) Messages::AlwaysDisplayItemPreviewDef = true;

View File

@ -129,6 +129,12 @@ namespace Messages {
KEY DisplayEnclosuresInMessage;
VALUE(bool) DisplayEnclosuresInMessageDef;
KEY AvoidOldArticles;
VALUE(bool) AvoidOldArticlesDef;
KEY DateTimeToAvoidArticle;
VALUE(QDateTime) DateTimeToAvoidArticleDef;
KEY AlwaysDisplayItemPreview;
VALUE(bool) AlwaysDisplayItemPreviewDef;

View File

@ -235,6 +235,17 @@ PreparedHtml SkinFactory::generateHtmlOfArticles(const QList<Message>& messages,
const auto forced_img_size =
qApp->settings()->value(GROUP(Messages), SETTING(Messages::MessageHeadImageHeight)).toInt();
auto* feed = root != nullptr
? root->getParentServiceRoot()
->getItemFromSubTree([messages](const RootItem* it) {
return it->kind() == RootItem::Kind::Feed && it->customId() == messages.at(0).m_feedId;
})
->toFeed()
: nullptr;
/*
bool is_rtl_feed = feed != nullptr && feed->isRtl();
*/
for (const Message& message : messages) {
QString enclosures;
QString enclosure_images;
@ -278,17 +289,13 @@ PreparedHtml SkinFactory::generateHtmlOfArticles(const QList<Message>& messages,
msg_date,
enclosures,
enclosure_images,
QString::number(message.m_id)));
QString::number(message.m_id),
message.m_isRtl ? QSL("rtl") : QSL("ltr")));
}
QString msg_contents =
skin.m_layoutMarkupWrapper.arg(messages.size() == 1 ? messages.at(0).m_title : tr("Newspaper view"),
messages_layout);
auto* feed = root->getParentServiceRoot()
->getItemFromSubTree([messages](const RootItem* it) {
return it->kind() == RootItem::Kind::Feed && it->customId() == messages.at(0).m_feedId;
})
->toFeed();
QString base_url;
if (feed != nullptr) {

View File

@ -20,8 +20,9 @@
Feed::Feed(RootItem* parent)
: RootItem(parent), m_source(QString()), m_status(Status::Normal), m_statusString(QString()),
m_autoUpdateType(AutoUpdateType::DefaultAutoUpdate), m_autoUpdateInterval(DEFAULT_AUTO_UPDATE_INTERVAL),
m_lastUpdated(QDateTime::currentDateTimeUtc()), m_isSwitchedOff(false), m_isQuiet(false),
m_openArticlesDirectly(false), m_messageFilters(QList<QPointer<MessageFilter>>()) {
m_lastUpdated(QDateTime::currentDateTimeUtc()), m_isSwitchedOff(false), m_isQuiet(false), m_isRtl(false),
m_addAnyDatetimeArticles(false), m_avoidOldArticles(false), m_openArticlesDirectly(false),
m_datetimeToAvoid(QDateTime::currentDateTime()), m_messageFilters(QList<QPointer<MessageFilter>>()) {
setKind(RootItem::Kind::Feed);
}
@ -43,6 +44,9 @@ Feed::Feed(const Feed& other) : RootItem(other) {
setLastUpdated(other.lastUpdated());
setMessageFilters(other.messageFilters());
setOpenArticlesDirectly(other.openArticlesDirectly());
setAddAnyDatetimeArticles(other.addAnyDatetimeArticles());
setDatetimeToAvoid(other.datetimeToAvoid());
setIsRtl(other.isRtl());
setIsSwitchedOff(other.isSwitchedOff());
setIsQuiet(other.isQuiet());
}
@ -78,6 +82,9 @@ QVariant Feed::data(int column, int role) const {
return QVariant();
}
case TEXT_DIRECTION_ROLE:
return isRtl() ? Qt::LayoutDirection::RightToLeft : Qt::LayoutDirection::LayoutDirectionAuto;
case Qt::ItemDataRole::ForegroundRole:
switch (status()) {
case Status::NewMessages:
@ -189,6 +196,30 @@ void Feed::setOpenArticlesDirectly(bool opn) {
m_openArticlesDirectly = opn;
}
bool Feed::isRtl() const {
return m_isRtl;
}
void Feed::setIsRtl(bool rtl) {
m_isRtl = rtl;
}
bool Feed::addAnyDatetimeArticles() const {
return m_addAnyDatetimeArticles;
}
void Feed::setAddAnyDatetimeArticles(bool add_any_articles) {
m_addAnyDatetimeArticles = add_any_articles;
}
QDateTime Feed::datetimeToAvoid() const {
return m_datetimeToAvoid;
}
void Feed::setDatetimeToAvoid(const QDateTime& dt) {
m_datetimeToAvoid = dt;
}
void Feed::appendMessageFilter(MessageFilter* filter) {
m_messageFilters.append(QPointer<MessageFilter>(filter));
}

View File

@ -82,6 +82,16 @@ class Feed : public RootItem {
QDateTime lastUpdated() const;
void setLastUpdated(const QDateTime& last_updated);
bool isRtl() const;
void setIsRtl(bool rtl);
bool addAnyDatetimeArticles() const;
void setAddAnyDatetimeArticles(bool add_any_articles);
QDateTime datetimeToAvoid() const;
void setDatetimeToAvoid(const QDateTime& dt);
public slots:
virtual void updateCounts(bool including_total_count);
@ -99,6 +109,11 @@ class Feed : public RootItem {
bool m_isSwitchedOff;
bool m_isQuiet;
bool m_openArticlesDirectly;
bool m_isRtl;
bool m_addAnyDatetimeArticles;
bool m_avoidOldArticles;
bool m_avoidOldArticlesEnabled;
QDateTime m_datetimeToAvoid;
int m_totalCount{};
int m_unreadCount{};
QList<QPointer<MessageFilter>> m_messageFilters;

View File

@ -49,6 +49,10 @@ void FormFeedDetails::apply() {
.toInt()));
m_feed->setAutoUpdateInterval(int(m_ui->m_spinAutoUpdateInterval->value()));
m_feed->setOpenArticlesDirectly(m_ui->m_cbOpenArticlesAutomatically->isChecked());
m_feed->setIsRtl(m_ui->m_cbFeedRTL->isChecked());
m_feed->setAddAnyDatetimeArticles(m_ui->m_cbAddAnyDateArticles->isChecked());
m_feed->setDatetimeToAvoid(m_ui->m_gbAvoidOldArticles->isChecked() ? m_ui->m_dtDateTimeToAvoid->dateTime()
: QDateTime());
m_feed->setIsSwitchedOff(m_ui->m_cbDisableFeed->isChecked());
m_feed->setIsQuiet(m_ui->m_cbSuppressFeed->isChecked());
@ -81,6 +85,10 @@ void FormFeedDetails::createConnections() {
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this,
&FormFeedDetails::onAutoUpdateTypeChanged);
connect(m_ui->m_cbAddAnyDateArticles, &QCheckBox::toggled, this, [this](bool checked) {
m_ui->m_gbAvoidOldArticles->setEnabled(!checked);
});
}
void FormFeedDetails::loadFeedData() {
@ -97,6 +105,10 @@ void FormFeedDetails::loadFeedData() {
->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue(int(m_feed->autoUpdateType()))));
m_ui->m_spinAutoUpdateInterval->setValue(m_feed->autoUpdateInterval());
m_ui->m_cbOpenArticlesAutomatically->setChecked(m_feed->openArticlesDirectly());
m_ui->m_cbFeedRTL->setChecked(m_feed->isRtl());
m_ui->m_cbAddAnyDateArticles->setChecked(m_feed->addAnyDatetimeArticles());
m_ui->m_gbAvoidOldArticles->setChecked(m_feed->datetimeToAvoid().isValid());
m_ui->m_dtDateTimeToAvoid->setDateTime(m_feed->datetimeToAvoid());
m_ui->m_cbDisableFeed->setChecked(m_feed->isSwitchedOff());
m_ui->m_cbSuppressFeed->setChecked(m_feed->isQuiet());
}

View File

@ -59,6 +59,61 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbAddAnyDateArticles">
<property name="text">
<string>Add articles with any date into the database</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="m_gbAvoidOldArticles">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Avoid adding articles before this date into the database :</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QDateTimeEdit" name="m_dtDateTimeToAvoid">
<property name="displayFormat">
<string>dd/MM/yyyy HH:mm</string>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabMisc">
@ -66,17 +121,24 @@
<string>Miscellaneous</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="0" colspan="2">
<item row="0" column="0">
<widget class="QCheckBox" name="m_cbSuppressFeed">
<property name="text">
<string>Ignore notifications for this feed</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="m_cbDisableFeed">
<property name="text">
<string>Disable this feed</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbSuppressFeed">
<item row="2" column="0">
<widget class="QCheckBox" name="m_cbFeedRTL">
<property name="text">
<string>Ignore notifications for this feed</string>
<string>Right-to-left layout</string>
</property>
</widget>
</item>
@ -111,8 +173,12 @@
<tabstop>m_cmbAutoUpdateType</tabstop>
<tabstop>m_spinAutoUpdateInterval</tabstop>
<tabstop>m_cbOpenArticlesAutomatically</tabstop>
<tabstop>m_cbAddAnyDateArticles</tabstop>
<tabstop>m_gbAvoidOldArticles</tabstop>
<tabstop>m_dtDateTimeToAvoid</tabstop>
<tabstop>m_cbSuppressFeed</tabstop>
<tabstop>m_cbDisableFeed</tabstop>
<tabstop>m_cbFeedRTL</tabstop>
</tabstops>
<resources/>
<connections>
@ -123,8 +189,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>331</x>
<y>556</y>
<x>340</x>
<y>580</y>
</hint>
<hint type="destinationlabel">
<x>286</x>

View File

@ -385,6 +385,9 @@ QMap<QString, QVariantMap> ServiceRoot::storeCustomFeedsData() {
feed_custom_data.insert(QSL("is_off"), feed->isSwitchedOff());
feed_custom_data.insert(QSL("is_quiet"), feed->isQuiet());
feed_custom_data.insert(QSL("open_articles_directly"), feed->openArticlesDirectly());
feed_custom_data.insert(QSL("is_rtl"), feed->isRtl());
feed_custom_data.insert(QSL("add_any_datetime_articles"), feed->addAnyDatetimeArticles());
feed_custom_data.insert(QSL("datetime_to_avoid"), feed->datetimeToAvoid().toMSecsSinceEpoch());
// NOTE: This is here specifically to be able to restore custom sort order.
// Otherwise the information is lost when list of feeds/folders is refreshed from remote
@ -434,6 +437,9 @@ void ServiceRoot::restoreCustomFeedsData(const QMap<QString, QVariantMap>& data,
feed->setIsSwitchedOff(feed_custom_data.value(QSL("is_off")).toBool());
feed->setIsQuiet(feed_custom_data.value(QSL("is_quiet")).toBool());
feed->setOpenArticlesDirectly(feed_custom_data.value(QSL("open_articles_directly")).toBool());
feed->setIsRtl(feed_custom_data.value(QSL("is_rtl")).toBool());
feed->setAddAnyDatetimeArticles(feed_custom_data.value(QSL("add_any_datetime_articles")).toBool());
feed->setDatetimeToAvoid(feed_custom_data.value(QSL("datetime_to_avoid")).toDateTime());
}
}
}

View File

@ -49,8 +49,6 @@ void EmailPreviewer::clear() {
}
void EmailPreviewer::loadMessage(const Message& msg, RootItem* selected_item) {
Q_UNUSED(selected_item)
m_message = msg;
m_webView->loadMessages({msg}, selected_item);