double fix selected items fetch and fix multiple popup questions when clearing multiple feeds

This commit is contained in:
Martin Rotter 2023-11-01 10:11:25 +01:00
parent 6eea00e628
commit 5b090c7030
6 changed files with 38 additions and 30 deletions

View file

@ -516,19 +516,8 @@ bool FeedsModel::markItemRead(RootItem* item, RootItem::ReadStatus read) {
return true; return true;
} }
bool FeedsModel::markItemCleared(RootItem* item, bool clean_read_only, bool ask) { bool FeedsModel::markItemCleared(RootItem* item, bool clean_read_only) {
if (item != nullptr) { if (item != nullptr) {
if (ask && MsgBox::show(nullptr,
QMessageBox::Icon::Question,
tr("Are you sure?"),
tr("Do you really want to clean all articles from selected item?"),
{},
{},
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No,
QMessageBox::StandardButton::No) != QMessageBox::StandardButton::Yes) {
return false;
}
return item->cleanMessages(clean_read_only); return item->cleanMessages(clean_read_only);
} }

View file

@ -114,7 +114,7 @@ class RSSGUARD_DLLSPEC FeedsModel : public QAbstractItemModel {
// Feeds operations. // Feeds operations.
bool markItemRead(RootItem* item, RootItem::ReadStatus read); bool markItemRead(RootItem* item, RootItem::ReadStatus read);
bool markItemCleared(RootItem* item, bool clean_read_only, bool ask); bool markItemCleared(RootItem* item, bool clean_read_only);
// Signals that properties (probably counts) // Signals that properties (probably counts)
// of ALL items have changed. // of ALL items have changed.

View file

@ -900,11 +900,11 @@ void FormMain::createConnections() {
connect(m_ui->m_actionClearSelectedItems, connect(m_ui->m_actionClearSelectedItems,
&QAction::triggered, &QAction::triggered,
tabWidget()->feedMessageViewer()->feedsView(), tabWidget()->feedMessageViewer()->feedsView(),
&FeedsView::clearSelectedFeeds); &FeedsView::clearSelectedItems);
connect(m_ui->m_actionClearAllItems, connect(m_ui->m_actionClearAllItems,
&QAction::triggered, &QAction::triggered,
tabWidget()->feedMessageViewer()->feedsView(), tabWidget()->feedMessageViewer()->feedsView(),
&FeedsView::clearAllFeeds); &FeedsView::clearAllItems);
connect(m_ui->m_actionUpdateSelectedItems, connect(m_ui->m_actionUpdateSelectedItems,
&QAction::triggered, &QAction::triggered,
tabWidget()->feedMessageViewer()->feedsView(), tabWidget()->feedMessageViewer()->feedsView(),

View file

@ -73,14 +73,13 @@ void FeedsView::setSortingEnabled(bool enable) {
QList<Feed*> FeedsView::selectedFeeds() const { QList<Feed*> FeedsView::selectedFeeds() const {
auto its = selectedItems(); auto its = selectedItems();
auto std_feeds = boolinq::from(its) QList<Feed*> feeds;
.select([](RootItem* it) {
return it->toFeed(); for (RootItem* it : its) {
}) feeds.append(it->getSubTreeFeeds());
.where([](Feed* fd) { }
return fd != nullptr;
}) auto std_feeds = boolinq::from(feeds).distinct().toStdList();
.toStdList();
return FROM_STD_LIST(QList<Feed*>, std_feeds); return FROM_STD_LIST(QList<Feed*>, std_feeds);
} }
@ -233,14 +232,34 @@ void FeedsView::updateSelectedItems() {
qApp->feedReader()->updateFeeds(selectedFeeds()); qApp->feedReader()->updateFeeds(selectedFeeds());
} }
void FeedsView::clearSelectedFeeds() { void FeedsView::clearSelectedItems() {
if (MsgBox::show(nullptr,
QMessageBox::Icon::Question,
tr("Are you sure?"),
tr("Do you really want to clean all articles from selected items?"),
{},
{},
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No,
QMessageBox::StandardButton::No) != QMessageBox::StandardButton::Yes) {
}
for (auto* it : selectedItems()) { for (auto* it : selectedItems()) {
m_sourceModel->markItemCleared(it, false, true); m_sourceModel->markItemCleared(it, false);
} }
} }
void FeedsView::clearAllFeeds() { void FeedsView::clearAllItems() {
m_sourceModel->markItemCleared(m_sourceModel->rootItem(), false, true); if (MsgBox::show(nullptr,
QMessageBox::Icon::Question,
tr("Are you sure?"),
tr("Do you really want to clean all articles from selected items?"),
{},
{},
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No,
QMessageBox::StandardButton::No) != QMessageBox::StandardButton::Yes) {
}
m_sourceModel->markItemCleared(m_sourceModel->rootItem(), false);
} }
void FeedsView::editItems(const QList<RootItem*>& items) { void FeedsView::editItems(const QList<RootItem*>& items) {

View file

@ -62,8 +62,8 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {
void openSelectedItemsInNewspaperMode(); void openSelectedItemsInNewspaperMode();
// Feed clearers. // Feed clearers.
void clearSelectedFeeds(); void clearSelectedItems();
void clearAllFeeds(); void clearAllItems();
// Base manipulators. // Base manipulators.
void editItems(const QList<RootItem*>& items); void editItems(const QList<RootItem*>& items);

View file

@ -398,7 +398,7 @@ void FeedReader::quit() {
} }
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool()) { if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool()) {
m_feedsModel->markItemCleared(m_feedsModel->rootItem(), true, false); m_feedsModel->markItemCleared(m_feedsModel->rootItem(), true);
} }
m_feedsModel->stopServiceAccounts(); m_feedsModel->stopServiceAccounts();