Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new setting for disabled feeds: Hide #1650

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions src/librssguard/core/feedsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,27 @@ QModelIndex FeedsModel::index(int row, int column, const QModelIndex& parent) co
}

RootItem* parent_item = itemForIndex(parent);
RootItem* child_item = parent_item->child(row);
int adjusted_row = -1;

if (child_item != nullptr) {
return createIndex(row, column, child_item);
}
else {
return QModelIndex();
// Check if hiding disabled feeds is enabled.
bool hide_disabled = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::HideDisabledFeeds)).toBool();

// Iterate through children and find the row that corresponds to the adjusted index.
for (int i = 0; i < parent_item->childCount(); ++i) {
RootItem* child = parent_item->child(i);

if (hide_disabled && child->kind() == RootItem::Kind::Feed && qobject_cast<Feed*>(child)->isSwitchedOff()) {
continue; // Skip disabled feeds if hiding is enabled.
}

adjusted_row++;

if (adjusted_row == row) {
return createIndex(row, column, child);
}
}

return QModelIndex();
}

QModelIndex FeedsModel::parent(const QModelIndex& child) const {
Expand All @@ -153,9 +166,25 @@ int FeedsModel::rowCount(const QModelIndex& parent) const {
if (parent.column() > 0) {
return 0;
}
else {
return itemForIndex(parent)->childCount();

RootItem* parent_item = itemForIndex(parent);
int count = 0;

// Check if hiding disabled feeds is enabled.
bool hide_disabled = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::HideDisabledFeeds)).toBool();

// Iterate through children and count rows based on the setting.
for (int i = 0; i < parent_item->childCount(); ++i) {
RootItem* child = parent_item->child(i);

if (hide_disabled && child->kind() == RootItem::Kind::Feed && qobject_cast<Feed*>(child)->isSwitchedOff()) {
continue; // Skip disabled feeds if hiding is enabled.
}

count++;
}

return count;
}

int FeedsModel::countOfAllMessages() const {
Expand Down Expand Up @@ -550,6 +579,17 @@ bool FeedsModel::purgeArticles(const QList<Feed*>& feeds) {
}

QVariant FeedsModel::data(const QModelIndex& index, int role) const {

bool hide_disabled = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::HideDisabledFeeds)).toBool();

if (hide_disabled) {
RootItem* it = itemForIndex(index);

if (it->kind() == RootItem::Kind::Feed && qobject_cast<Feed*>(it)->isSwitchedOff()) {
return QVariant();
}
}

switch (role) {
case Qt::ItemDataRole::FontRole: {
RootItem* it = itemForIndex(index);
Expand Down
4 changes: 4 additions & 0 deletions src/librssguard/gui/settings/settingsfeedsmessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
this,
&SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_checkShowTooltips, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_cbHideDisabledFeeds, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_cbStrikethroughDisabledFeeds, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_checkMultilineArticleList, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
connect(m_ui->m_checkMultilineArticleList, &QCheckBox::toggled, this, &SettingsFeedsMessages::requireRestart);
Expand Down Expand Up @@ -353,6 +354,8 @@ void SettingsFeedsMessages::loadSettings() {
m_ui->m_cmbCountsFeedList->setEditText(settings()->value(GROUP(Feeds), SETTING(Feeds::CountFormat)).toString());
m_ui->m_checkShowTooltips
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::EnableTooltipsFeedsMessages)).toBool());
m_ui->m_cbHideDisabledFeeds
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::HideDisabledFeeds)).toBool());
m_ui->m_cbStrikethroughDisabledFeeds
->setChecked(settings()->value(GROUP(Feeds), SETTING(Feeds::StrikethroughDisabledFeeds)).toBool());
m_ui->m_cmbIgnoreContentsChanges
Expand Down Expand Up @@ -492,6 +495,7 @@ void SettingsFeedsMessages::saveSettings() {
settings()->setValue(GROUP(Feeds), Feeds::FeedsUpdateStartupDelay, m_ui->m_spinStartupUpdateDelay->value());
settings()->setValue(GROUP(Feeds), Feeds::CountFormat, m_ui->m_cmbCountsFeedList->currentText());
settings()->setValue(GROUP(Feeds), Feeds::EnableTooltipsFeedsMessages, m_ui->m_checkShowTooltips->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::HideDisabledFeeds, m_ui->m_cbHideDisabledFeeds->isChecked());
settings()->setValue(GROUP(Feeds), Feeds::StrikethroughDisabledFeeds, m_ui->m_cbStrikethroughDisabledFeeds->isChecked());
settings()->setValue(GROUP(Messages), Messages::IgnoreContentsChanges, m_ui->m_cmbIgnoreContentsChanges->isChecked());
settings()->setValue(GROUP(Messages), Messages::MultilineArticleList, m_ui->m_checkMultilineArticleList->isChecked());
Expand Down
5 changes: 5 additions & 0 deletions src/librssguard/gui/settings/settingsfeedsmessages.ui
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbHideDisabledFeeds">
<property name="text">
<string>Hide disabled feeds</string>
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbStrikethroughDisabledFeeds">
<property name="text">
Expand Down Expand Up @@ -734,6 +738,7 @@
<tabstop>m_cbUpdateFeedListDuringFetching</tabstop>
<tabstop>m_cbListsRestrictedShortcuts</tabstop>
<tabstop>m_checkShowTooltips</tabstop>
<tabstop>m_cbHideDisabledFeeds</tabstop>
<tabstop>m_cbStrikethroughDisabledFeeds</tabstop>
<tabstop>m_checkRemoveReadMessagesOnExit</tabstop>
<tabstop>m_cbArticleViewerAlwaysVisible</tabstop>
Expand Down
3 changes: 3 additions & 0 deletions src/librssguard/miscellaneous/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ DVALUE(char*) Feeds::CountFormatDef = "(%unread)";
DKEY Feeds::EnableTooltipsFeedsMessages = "show_tooltips";
DVALUE(bool) Feeds::EnableTooltipsFeedsMessagesDef = true;

DKEY Feeds::HideDisabledFeeds = "hide_disabled_feeds";
DVALUE(bool) Feeds::HideDisabledFeedsDef = false;

DKEY Feeds::StrikethroughDisabledFeeds = "strikethrough_disabled_feeds";
DVALUE(bool) Feeds::StrikethroughDisabledFeedsDef = true;

Expand Down
3 changes: 3 additions & 0 deletions src/librssguard/miscellaneous/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ namespace Feeds {
KEY EnableTooltipsFeedsMessages;
VALUE(bool) EnableTooltipsFeedsMessagesDef;

KEY HideDisabledFeeds;
VALUE(bool) HideDisabledFeedsDef;

KEY StrikethroughDisabledFeeds;
VALUE(bool) StrikethroughDisabledFeedsDef;

Expand Down