Browse Source

Prevent RSS folder from being moved into itself

PR #18619.
Closes #18446.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
8df68ac878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/base/rss/rss_session.cpp
  2. 10
      src/gui/rss/feedlistwidget.cpp

5
src/base/rss/rss_session.cpp

@ -185,8 +185,11 @@ nonstd::expected<void, QString> Session::moveItem(Item *item, const QString &des
if (!result) if (!result)
return result.get_unexpected(); return result.get_unexpected();
auto srcFolder = static_cast<Folder *>(m_itemsByPath.value(Item::parentPath(item->path())));
const auto destFolder = result.value(); const auto destFolder = result.value();
if (static_cast<Item *>(destFolder) == item)
return nonstd::make_unexpected(tr("Couldn't move folder into itself."));
auto srcFolder = static_cast<Folder *>(m_itemsByPath.value(Item::parentPath(item->path())));
if (srcFolder != destFolder) if (srcFolder != destFolder)
{ {
srcFolder->removeItem(item); srcFolder->removeItem(item);

10
src/gui/rss/feedlistwidget.cpp

@ -105,7 +105,8 @@ FeedListWidget::FeedListWidget(QWidget *parent)
m_rssToTreeItemMapping[RSS::Session::instance()->rootFolder()] = invisibleRootItem(); m_rssToTreeItemMapping[RSS::Session::instance()->rootFolder()] = invisibleRootItem();
m_unreadStickyItem = new FeedListItem(this); m_unreadStickyItem = new FeedListItem(this);
m_unreadStickyItem->setData(0, Qt::UserRole, QVariant::fromValue(RSS::Session::instance()->rootFolder())); m_unreadStickyItem->setData(0, Qt::UserRole, QVariant::fromValue(
reinterpret_cast<intptr_t>(RSS::Session::instance()->rootFolder())));
m_unreadStickyItem->setText(0, tr("Unread (%1)").arg(RSS::Session::instance()->rootFolder()->unreadCount())); m_unreadStickyItem->setText(0, tr("Unread (%1)").arg(RSS::Session::instance()->rootFolder()->unreadCount()));
m_unreadStickyItem->setData(0, Qt::DecorationRole, UIThemeManager::instance()->getIcon(u"mail-inbox"_qs)); m_unreadStickyItem->setData(0, Qt::DecorationRole, UIThemeManager::instance()->getIcon(u"mail-inbox"_qs));
m_unreadStickyItem->setData(0, StickyItemTagRole, true); m_unreadStickyItem->setData(0, StickyItemTagRole, true);
@ -211,9 +212,10 @@ QList<QTreeWidgetItem *> FeedListWidget::getAllOpenedFolders(QTreeWidgetItem *pa
RSS::Item *FeedListWidget::getRSSItem(QTreeWidgetItem *item) const RSS::Item *FeedListWidget::getRSSItem(QTreeWidgetItem *item) const
{ {
if (!item) return nullptr; if (!item)
return nullptr;
return item->data(0, Qt::UserRole).value<RSS::Item *>(); return reinterpret_cast<RSS::Item *>(item->data(0, Qt::UserRole).value<intptr_t>());
} }
QTreeWidgetItem *FeedListWidget::mapRSSItem(RSS::Item *rssItem) const QTreeWidgetItem *FeedListWidget::mapRSSItem(RSS::Item *rssItem) const
@ -275,7 +277,7 @@ QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem
{ {
auto *item = new FeedListItem; auto *item = new FeedListItem;
item->setData(0, Qt::DisplayRole, u"%1 (%2)"_qs.arg(rssItem->name(), QString::number(rssItem->unreadCount()))); item->setData(0, Qt::DisplayRole, u"%1 (%2)"_qs.arg(rssItem->name(), QString::number(rssItem->unreadCount())));
item->setData(0, Qt::UserRole, QVariant::fromValue(rssItem)); item->setData(0, Qt::UserRole, QVariant::fromValue(reinterpret_cast<intptr_t>(rssItem)));
m_rssToTreeItemMapping[rssItem] = item; m_rssToTreeItemMapping[rssItem] = item;
QIcon icon; QIcon icon;

Loading…
Cancel
Save