Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a719e6e9 authored by Kevin Tardif's avatar Kevin Tardif Committed by Daniel Vrátil

Added Auto-Expand Folder On Unread option

Summary:
This patch adds a new option, to auto-expand folders whenever any of its
children have unread content. This makes it quicker to navigate to new
content when using folders.

akregator_part.rc:
    - added an action to <Menu name="view"> with name=auto_expand_folders
    - bumped version

settings_general.ui:
    - added kcfg_AutoExpandFolders field under General->Global

subscriptionlistview:
    - added slotSetAutoExpandFolders to expand any unread folders when
      enabling the auto_expand_folders setting

actionmanagerimpl:
    - added code to slotSettingsChanged, to update the auto_expand_folders action state
    - added a KAction to ActionManagerImpl:initSubscriptionListView,
      connected to SubscriptionListView::slotSetAutoExpandFolders

selectioncontroller:
    - added subscriptionDataChanged to update folder expand state for
      newly updated items
    - connect m_subscriptionModel's dataChanged signal to
      subscriptionDataChanged

Reviewers: dvratil

Reviewed By: dvratil

Subscribers: dvratil, #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D8165
parent 115172ab
......@@ -44,6 +44,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_AutoExpandFolders">
<property name="text">
<string>Auto-expand folders containing unread articles</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_UseNotifications">
<property name="toolTip">
......
......@@ -10,6 +10,11 @@
<whatsthis>Hides feeds with no unread articles</whatsthis>
<default>false</default>
</entry>
<entry key="Auto Expand Folders" type="Bool">
<label>Auto-Expand folders with unread articles</label>
<whatsthis>Auto-expand folders containing unread articles</whatsthis>
<default>false</default>
</entry>
<entry key="Show Quick Filter" type="Bool" >
<label>Show Quick Filter</label>
<whatsthis>Show Quick Filter Bar</whatsthis>
......
......@@ -132,6 +132,13 @@ void ActionManagerImpl::slotSettingsChanged()
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 @@ void ActionManagerImpl::initSubscriptionListView(SubscriptionListView *subscript
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)
......
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="akregator_part" version="426" translationDomain="akregator">
<gui name="akregator_part" version="427" translationDomain="akregator">
<MenuBar>
<Menu name="file">
<Action name="file_import"/>
......@@ -26,6 +26,7 @@
<Action name="zoom_menu"/>
<Separator/>
<Action name="feed_hide_read"/>
<Action name="auto_expand_folders"/>
</Menu>
<Menu name="go">
......
......@@ -37,6 +37,7 @@
#include <QAbstractItemView>
#include <QMenu>
#include <QTreeView>
#include <memory>
using namespace Akregator;
......@@ -89,6 +90,9 @@ Akregator::SelectionController::SelectionController(QObject *parent)
{
m_subscriptionModel->setDoFilter(Settings::hideReadFeeds());
m_subscriptionModel->setSourceModel(new SubscriptionListModel(QSharedPointer<FeedList>(), this));
connect(m_subscriptionModel, &FilterUnreadProxyModel::dataChanged,
this, &SelectionController::subscriptionDataChanged);
}
Akregator::SelectionController::~SelectionController()
......@@ -248,6 +252,38 @@ void Akregator::SelectionController::articleHeadersAvailable(KJob *job)
}
}
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<QTreeView*>(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()) {
......
......@@ -87,6 +87,7 @@ public Q_SLOTS:
private Q_SLOTS:
void subscriptionDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void selectedSubscriptionChanged(const QModelIndex &index);
void articleSelectionChanged();
void articleIndexDoubleClicked(const QModelIndex &index);
......
......@@ -31,6 +31,7 @@
#include <QHeaderView>
#include <QStack>
#include <QPointer>
#include <QQueue>
#include <QMenu>
#include <KLocalizedString>
......@@ -405,6 +406,43 @@ void SubscriptionListView::slotSetHideReadFeeds(bool setting)
filter->setDoFilter(setting);
}
void Akregator::SubscriptionListView::slotSetAutoExpandFolders(bool setting)
{
Settings::setAutoExpandFolders(setting);
if (!setting) {
return;
}
//expand any current subscriptions with unread items
QQueue<QModelIndex> 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 *)
{
}
......
......@@ -73,6 +73,7 @@ public Q_SLOTS:
void slotItemDown();
void slotSetHideReadFeeds(bool setting);
void slotSetAutoExpandFolders(bool setting);
Q_SIGNALS:
void userActionTakingPlace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment