diff --git a/configuration/ui/settings_general.ui b/configuration/ui/settings_general.ui --- a/configuration/ui/settings_general.ui +++ b/configuration/ui/settings_general.ui @@ -44,6 +44,13 @@ + + + + Auto-expand folders containing unread articles + + + diff --git a/interfaces/akregator.kcfg b/interfaces/akregator.kcfg --- a/interfaces/akregator.kcfg +++ b/interfaces/akregator.kcfg @@ -10,6 +10,11 @@ Hides feeds with no unread articles false + + + Auto-expand folders containing unread articles + false + Show Quick Filter Bar diff --git a/src/actions/actionmanagerimpl.cpp b/src/actions/actionmanagerimpl.cpp --- a/src/actions/actionmanagerimpl.cpp +++ b/src/actions/actionmanagerimpl.cpp @@ -132,6 +132,13 @@ return; } a->setChecked(Settings::hideReadFeeds()); + + a = action(QStringLiteral("auto_expand_folders")); + if (!a) { + qCCritical(AKREGATOR_LOG) << "Action not found"; + return; + } + a->setChecked(Settings::autoExpandFolders()); } void ActionManagerImpl::slotNodeSelected(TreeNode *node) @@ -536,6 +543,12 @@ action->setText(i18n("Hide Read Feeds")); action->setChecked(Settings::hideReadFeeds()); connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotSetHideReadFeeds); + + action = coll->addAction(QStringLiteral("auto_expand_folders")); + action->setCheckable(true); + action->setText(i18n("Auto-expand folders with unread articles")); + action->setChecked(Settings::autoExpandFolders()); + connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotSetAutoExpandFolders); } void ActionManagerImpl::initTabWidget(TabWidget *tabWidget) diff --git a/src/data/akregator_part.rc b/src/data/akregator_part.rc --- a/src/data/akregator_part.rc +++ b/src/data/akregator_part.rc @@ -1,5 +1,5 @@ - + @@ -26,6 +26,7 @@ + diff --git a/src/selectioncontroller.h b/src/selectioncontroller.h --- a/src/selectioncontroller.h +++ b/src/selectioncontroller.h @@ -87,6 +87,7 @@ private Q_SLOTS: + void subscriptionDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); void selectedSubscriptionChanged(const QModelIndex &index); void articleSelectionChanged(); void articleIndexDoubleClicked(const QModelIndex &index); diff --git a/src/selectioncontroller.cpp b/src/selectioncontroller.cpp --- a/src/selectioncontroller.cpp +++ b/src/selectioncontroller.cpp @@ -37,6 +37,7 @@ #include #include +#include #include using namespace Akregator; @@ -89,6 +90,9 @@ { m_subscriptionModel->setDoFilter(Settings::hideReadFeeds()); m_subscriptionModel->setSourceModel(new SubscriptionListModel(QSharedPointer(), this)); + + connect(m_subscriptionModel, &FilterUnreadProxyModel::dataChanged, + this, &SelectionController::subscriptionDataChanged); } Akregator::SelectionController::~SelectionController() @@ -248,6 +252,38 @@ } } +void Akregator::SelectionController::subscriptionDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + if (!Settings::autoExpandFolders()) { + return; + } + + if (!m_subscriptionModel) { + qCCritical(AKREGATOR_LOG) << "m_subscriptionModel is NULL"; + return; + } + + //need access to setExpanded + QTreeView *tv = qobject_cast(m_feedSelector); + if (!tv) { + qCCritical(AKREGATOR_LOG) << "Unable to cast m_feedSelector to QTreeView"; + return; + } + + int startRow = topLeft.row(); + int endRow = bottomRight.row(); + QModelIndex parent = topLeft.parent(); + + for (int row = startRow; row <= endRow; ++row) { + QModelIndex idx = m_subscriptionModel->index(row, 0, parent); + QVariant v = m_subscriptionModel->data(idx, SubscriptionListModel::HasUnreadRole); + if (!v.toBool()) { + return; + } + tv->setExpanded(idx, true); + } +} + void Akregator::SelectionController::selectedSubscriptionChanged(const QModelIndex &index) { if (!index.isValid()) { diff --git a/src/subscription/subscriptionlistview.h b/src/subscription/subscriptionlistview.h --- a/src/subscription/subscriptionlistview.h +++ b/src/subscription/subscriptionlistview.h @@ -73,6 +73,7 @@ void slotItemDown(); void slotSetHideReadFeeds(bool setting); + void slotSetAutoExpandFolders(bool setting); Q_SIGNALS: void userActionTakingPlace(); diff --git a/src/subscription/subscriptionlistview.cpp b/src/subscription/subscriptionlistview.cpp --- a/src/subscription/subscriptionlistview.cpp +++ b/src/subscription/subscriptionlistview.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -405,6 +406,43 @@ filter->setDoFilter(setting); } +void Akregator::SubscriptionListView::slotSetAutoExpandFolders(bool setting) +{ + Settings::setAutoExpandFolders(setting); + if (!setting) { + return; + } + + //expand any current subscriptions with unread items + QQueue indexes; + //start at the root node + indexes.enqueue(QModelIndex()); + + QAbstractItemModel *m = model(); + if (!m) { + return; + } + + while (!indexes.isEmpty()) { + QModelIndex parent = indexes.dequeue(); + int rows = m->rowCount(parent); + + for (int row = 0; row < rows; ++row) { + QModelIndex current = m->index(row, 0, parent); + + if (m->hasChildren(current)) { + indexes.enqueue(current); + } + + if (!m->data(current, SubscriptionListModel::HasUnreadRole).toBool()) { + continue; + } + + setExpanded(current, true); + } + } +} + void Akregator::SubscriptionListView::ensureNodeVisible(Akregator::TreeNode *) { }