RTL layout direction to feeds

I added a feature that lets change the feed's articles from right to left for languages such as Arabic, Urdu, Hebrew, Farsi...
To enable it :  **The desired feed -> Edit selected item -> Articles -> Right-to-left layout**.

![LTR](https://github.com/martinrotter/rssguard/assets/25085777/a555d38d-a066-44d2-b0d0-158daae4ac2b)
![RTL](https://github.com/martinrotter/rssguard/assets/25085777/81cde3e3-f645-4c2b-a46a-d60aa5f54bd7)
This commit is contained in:
رشيد 2023-07-22 16:00:18 +01:00
parent c76320fbcd
commit a5366e8a68
15 changed files with 239 additions and 16 deletions

View File

@ -43,6 +43,9 @@ CREATE TABLE Feeds (
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),
add_any_datetime_articles INTEGER NOT NULL DEFAULT 0 CHECK(add_any_datetime_articles >= 0 AND add_any_datetime_articles <= 1),
avoid_old_articles INTEGER NOT NULL DEFAULT 0 CHECK(avoid_old_articles >= 0 AND avoid_old_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. */
@ -97,4 +100,4 @@ CREATE TABLE Labels (
account_id INTEGER NOT NULL,
FOREIGN KEY (account_id) REFERENCES Accounts (id) ON DELETE CASCADE
);
);

View File

@ -13,6 +13,9 @@ CREATE TABLE Feeds (
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),
add_any_datetime_articles INTEGER NOT NULL DEFAULT 0 CHECK(add_any_datetime_articles >= 0 AND add_any_datetime_articles <= 1),
avoid_old_articles INTEGER NOT NULL DEFAULT 0 CHECK(avoid_old_articles >= 0 AND avoid_old_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. */
@ -26,4 +29,4 @@ INSERT INTO Feeds (id, ordr, title, description, date_created, icon, category, s
SELECT id, ordr, title, description, date_created, icon, category, source, update_type, update_interval, is_off, open_articles, account_id, custom_id, custom_data
FROM backup_Feeds;
-- !
DROP TABLE backup_Feeds;
DROP TABLE backup_Feeds;

View File

@ -2178,11 +2178,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, add_any_datetime_articles = :add_any_datetime_articles,"
" avoid_old_articles = :avoid_old_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 +2198,9 @@ 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(":add_any_datetime_articles"), feed->addAnyDatetimeArticles());
q.bindValue(QSL(":avoid_old_articles"), feed->avoidOldArticles());
q.bindValue(QSL(":datetime_to_avoid"), feed->datetimeToAvoid().toMSecsSinceEpoch());
auto custom_data = feed->customDatabaseData();
QString serialized_custom_data = serializeCustomData(custom_data);

View File

@ -353,6 +353,9 @@ 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->setAddAnyDatetimeArticles(query.value(FDS_DB_ADD_ANY_DATETIME_ARTICLES_INDEX).toBool());
feed->setAvoidOldArticles(query.value(FDS_DB_AVOID_OLD_ARTICLES_INDEX).toBool());
feed->setDatetimeToAvoid(query.value(FDS_DB_DATETIME_TO_AVOID_INDEX).toDateTime());
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

@ -295,10 +295,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_ADD_ANY_DATETIME_ARTICLES_INDEX 12
#define FDS_DB_AVOID_OLD_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

@ -197,6 +197,11 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
m_ui->m_spinFeedUpdateTimeout->setSuffix(QSL(" ") + m_ui->m_spinFeedUpdateTimeout->suffix());
}
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,8 @@ 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 +353,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

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

@ -21,6 +21,7 @@ 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_addAnyDatetimeArticles(false), m_avoidOldArticles(false), m_datetimeToAvoid(QDateTime::currentDateTime()),
m_openArticlesDirectly(false), m_messageFilters(QList<QPointer<MessageFilter>>()) {
setKind(RootItem::Kind::Feed);
}
@ -43,6 +44,10 @@ Feed::Feed(const Feed& other) : RootItem(other) {
setLastUpdated(other.lastUpdated());
setMessageFilters(other.messageFilters());
setOpenArticlesDirectly(other.openArticlesDirectly());
setAddAnyDatetimeArticles(other.addAnyDatetimeArticles());
setAvoidOldArticles(other.avoidOldArticles());
setAvoidOldArticlesEnabled(other.isAvoidOldArticlesEnabled());
setDatetimeToAvoid(other.datetimeToAvoid());
setIsSwitchedOff(other.isSwitchedOff());
setIsQuiet(other.isQuiet());
}
@ -189,6 +194,38 @@ void Feed::setOpenArticlesDirectly(bool opn) {
m_openArticlesDirectly = opn;
}
bool Feed::addAnyDatetimeArticles() const {
return m_addAnyDatetimeArticles;
}
void Feed::setAddAnyDatetimeArticles(bool addAnyDatetimeArticles) {
m_addAnyDatetimeArticles = addAnyDatetimeArticles;
}
bool Feed::avoidOldArticles() const {
return m_avoidOldArticles;
}
void Feed::setAvoidOldArticles(bool avoidDateArticles) {
m_avoidOldArticles = avoidDateArticles;
}
bool Feed::isAvoidOldArticlesEnabled() const {
return m_avoidOldArticlesEnabled;
}
void Feed::setAvoidOldArticlesEnabled(bool newAvoidOldArticlesEnabled) {
m_avoidOldArticlesEnabled = newAvoidOldArticlesEnabled;
}
QDateTime Feed::datetimeToAvoid() const {
return m_datetimeToAvoid;
}
void Feed::setDatetimeToAvoid(const QDateTime &dateTime) {
m_datetimeToAvoid = dateTime;
}
void Feed::appendMessageFilter(MessageFilter* filter) {
m_messageFilters.append(QPointer<MessageFilter>(filter));
}

View File

@ -82,6 +82,20 @@ class Feed : public RootItem {
QDateTime lastUpdated() const;
void setLastUpdated(const QDateTime& last_updated);
bool addAnyDatetimeArticles() const;
void setAddAnyDatetimeArticles(bool addAnyDatetimeArticles);
bool avoidOldArticles() const;
void setAvoidOldArticles(bool avoidDateArticles);
bool isAvoidOldArticlesEnabled() const;
void setAvoidOldArticlesEnabled(bool newAvoidOldArticlesEnabled);
QDateTime datetimeToAvoid() const;
void setDatetimeToAvoid(const QDateTime &dateTime);
public slots:
virtual void updateCounts(bool including_total_count);
@ -99,6 +113,10 @@ class Feed : public RootItem {
bool m_isSwitchedOff;
bool m_isQuiet;
bool m_openArticlesDirectly;
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,9 @@ void FormFeedDetails::apply() {
.toInt()));
m_feed->setAutoUpdateInterval(int(m_ui->m_spinAutoUpdateInterval->value()));
m_feed->setOpenArticlesDirectly(m_ui->m_cbOpenArticlesAutomatically->isChecked());
m_feed->setAddAnyDatetimeArticles(m_ui->m_cbAddAnyDateArticles->isChecked());
m_feed->setAvoidOldArticles(m_ui->m_gbAvoidOldArticles->isChecked());
m_feed->setDatetimeToAvoid(m_ui->m_dtDateTimeToAvoid->dateTime());
m_feed->setIsSwitchedOff(m_ui->m_cbDisableFeed->isChecked());
m_feed->setIsQuiet(m_ui->m_cbSuppressFeed->isChecked());
@ -81,6 +84,12 @@ 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);
m_feed->setAvoidOldArticlesEnabled(!checked);
});
}
void FormFeedDetails::loadFeedData() {
@ -97,6 +106,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_cbAddAnyDateArticles->setChecked(m_feed->addAnyDatetimeArticles());
m_ui->m_gbAvoidOldArticles->setChecked(m_feed->avoidOldArticles());
m_ui->m_gbAvoidOldArticles->setEnabled(!m_feed->addAnyDatetimeArticles());
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,64 @@
</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>
<property name="checked">
<bool>true</bool>
</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">

View File

@ -384,6 +384,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("add_any_datetime_articles"), feed->addAnyDatetimeArticles());
feed_custom_data.insert(QSL("avoid_old_articles"), feed->avoidOldArticles());
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
@ -433,6 +436,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->setAddAnyDatetimeArticles(feed_custom_data.value(QSL("add_any_datetime_articles")).toBool());
feed->setAvoidOldArticles(feed_custom_data.value(QSL("avoid_date_message")).toBool());
feed->setDatetimeToAvoid(feed_custom_data.value(QSL("avoid_message_datetime")).toDateTime());
}
}
}

View File

@ -256,6 +256,23 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
mess.m_feedId = feed->customId();
}
if (!feed->addAnyDatetimeArticles()) {
QDateTime datetimeToAvoid;
if (feed->isAvoidOldArticlesEnabled() && feed->avoidOldArticles())
datetimeToAvoid = feed->datetimeToAvoid();
else if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::AvoidOldArticles)).toBool())
datetimeToAvoid = qApp->settings()->value(GROUP(Messages), SETTING(Messages::DateTimeToAvoidArticle)).toDateTime();
else
return messages;
for (int i = 0; i < messages.size(); i++)
if (messages.at(i).m_created < datetimeToAvoid)
messages.removeAt(i--);
}
return messages;
}