Skip to content

Commit

Permalink
fix feed batch edit behavior for some corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Nov 2, 2023
1 parent 79d7147 commit 4c412ac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
38 changes: 22 additions & 16 deletions src/librssguard/gui/feedsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ void FeedsView::setSortingEnabled(bool enable) {
connect(header(), &QHeaderView::sortIndicatorChanged, this, &FeedsView::saveSortState);
}

QList<Feed*> FeedsView::selectedFeeds() const {
QList<Feed*> FeedsView::selectedFeeds(bool recursive) const {
auto its = selectedItems();
QList<Feed*> feeds;

for (RootItem* it : its) {
feeds.append(it->getSubTreeFeeds());
feeds.append(it->getSubTreeFeeds(recursive));
}

auto std_feeds = boolinq::from(feeds).distinct().toStdList();
Expand Down Expand Up @@ -128,7 +128,7 @@ QList<RootItem*> FeedsView::selectedItems() const {
}

void FeedsView::copyUrlOfSelectedFeeds() const {
auto feeds = selectedFeeds();
auto feeds = selectedFeeds(true);
QStringList urls;

for (const auto* feed : feeds) {
Expand Down Expand Up @@ -229,7 +229,7 @@ void FeedsView::expandCollapseCurrentItem(bool recursive) {
}

void FeedsView::updateSelectedItems() {
qApp->feedReader()->updateFeeds(selectedFeeds());
qApp->feedReader()->updateFeeds(selectedFeeds(true));
}

void FeedsView::clearSelectedItems() {
Expand Down Expand Up @@ -285,6 +285,7 @@ void FeedsView::editItems(const QList<RootItem*>& items) {
.where([](RootItem* it) {
return it->canBeEdited();
})
.distinct()
.toStdList();

if (std_editable_items.empty()) {
Expand Down Expand Up @@ -357,25 +358,30 @@ void FeedsView::editItems(const QList<RootItem*>& items) {
}

void FeedsView::editChildFeeds() {
auto* item = selectedItem();
auto items = selectedFeeds(false);

if (item != nullptr) {
auto children = item->childItems();
auto std_feeds = boolinq::from(children)
.where([](RootItem* ch) {
return ch->kind() == RootItem::Kind::Feed;
})
.toStdList();
if (!items.isEmpty()) {
auto root_items = boolinq::from(items)
.select([](Feed* fd) {
return fd;
})
.toStdList();

editItems(FROM_STD_LIST(QList<RootItem*>, std_feeds));
editItems(FROM_STD_LIST(QList<RootItem*>, root_items));
}
}

void FeedsView::editRecursiveFeeds() {
auto* item = selectedItem();
auto items = selectedFeeds(true);

if (item != nullptr) {
editItems(item->getSubTree(RootItem::Kind::Feed));
if (!items.isEmpty()) {
auto root_items = boolinq::from(items)
.select([](Feed* fd) {
return fd;
})
.toStdList();

editItems(FROM_STD_LIST(QList<RootItem*>, root_items));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librssguard/gui/feedsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {

// Returns list of selected/all feeds.
// NOTE: This is recursive method which returns all descendants.
QList<Feed*> selectedFeeds() const;
QList<Feed*> selectedFeeds(bool recursive) const;

// Returns selected item. If multiple items are selected, returns
// the one of them which is also "current". If none of them is
Expand Down
8 changes: 6 additions & 2 deletions src/librssguard/services/abstract/rootitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,10 @@ QHash<QString, Feed*> RootItem::getHashedSubTreeFeeds() const {
return children;
}

QList<Feed*> RootItem::getSubTreeFeeds() const {
QList<Feed*> RootItem::getSubTreeFeeds(bool recursive) const {
QList<Feed*> children;
QList<RootItem*> traversable_items;
bool traversed = false;

traversable_items.append(const_cast<RootItem* const>(this));

Expand All @@ -411,7 +412,10 @@ QList<Feed*> RootItem::getSubTreeFeeds() const {
children.append(active_item->toFeed());
}

traversable_items.append(active_item->childItems());
if (recursive || !traversed) {
traversed = true;
traversable_items.append(active_item->childItems());
}
}

return children;
Expand Down
2 changes: 1 addition & 1 deletion src/librssguard/services/abstract/rootitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class RSSGUARD_DLLSPEC RootItem : public QObject {
// Returns list of feeds complemented by their own string CUSTOM ID.
QHash<QString, Feed*> getHashedSubTreeFeeds() const;

QList<Feed*> getSubTreeFeeds() const;
QList<Feed*> getSubTreeFeeds(bool recursive = true) const;
QList<Feed*> getSubTreeAutoFetchingWithManualIntervalsFeeds() const;
QList<Feed*> getSubAutoFetchingEnabledFeeds() const;

Expand Down

0 comments on commit 4c412ac

Please sign in to comment.