FeedReader: The feed can be moved with drag and drop to a folder

This commit is contained in:
thunder2 2023-04-13 15:53:14 +02:00
parent 571f709b50
commit 186976e209
10 changed files with 285 additions and 8 deletions

View File

@ -44,6 +44,7 @@ SOURCES = FeedReaderPlugin.cpp \
gui/FeedReaderFeedNotify.cpp \ gui/FeedReaderFeedNotify.cpp \
gui/FeedReaderUserNotify.cpp \ gui/FeedReaderUserNotify.cpp \
gui/FeedReaderFeedItem.cpp \ gui/FeedReaderFeedItem.cpp \
gui/FeedTreeWidget.cpp \
util/CURLWrapper.cpp \ util/CURLWrapper.cpp \
util/XMLWrapper.cpp \ util/XMLWrapper.cpp \
util/HTMLWrapper.cpp \ util/HTMLWrapper.cpp \
@ -64,6 +65,7 @@ HEADERS = FeedReaderPlugin.h \
gui/FeedReaderFeedNotify.h \ gui/FeedReaderFeedNotify.h \
gui/FeedReaderUserNotify.h \ gui/FeedReaderUserNotify.h \
gui/FeedReaderFeedItem.h \ gui/FeedReaderFeedItem.h \
gui/FeedTreeWidget.h \
util/CURLWrapper.h \ util/CURLWrapper.h \
util/XMLWrapper.h \ util/XMLWrapper.h \
util/HTMLWrapper.h \ util/HTMLWrapper.h \

View File

@ -84,9 +84,16 @@ FeedReaderDialog::FeedReaderDialog(RsFeedReader *feedReader, FeedReaderNotify *n
connect(ui->feedAddButton, SIGNAL(clicked()), this, SLOT(newFeed())); connect(ui->feedAddButton, SIGNAL(clicked()), this, SLOT(newFeed()));
connect(ui->feedProcessButton, SIGNAL(clicked()), this, SLOT(processFeed())); connect(ui->feedProcessButton, SIGNAL(clicked()), this, SLOT(processFeed()));
connect(ui->feedTreeWidget, SIGNAL(feedReparent(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(feedTreeReparent(QTreeWidgetItem*,QTreeWidgetItem*)));
mFeedCompareRole = new RSTreeWidgetItemCompareRole; mFeedCompareRole = new RSTreeWidgetItemCompareRole;
mFeedCompareRole->setRole(COLUMN_FEED_NAME, ROLE_FEED_SORT); mFeedCompareRole->setRole(COLUMN_FEED_NAME, ROLE_FEED_SORT);
/* enable drag and drop */
ui->feedTreeWidget->setAcceptDrops(true);
ui->feedTreeWidget->setDragEnabled(true);
ui->feedTreeWidget->setDragDropMode(QAbstractItemView::InternalMove);
/* initialize root item */ /* initialize root item */
mRootItem = new QTreeWidgetItem(ui->feedTreeWidget); mRootItem = new QTreeWidgetItem(ui->feedTreeWidget);
QString name = tr("Message Folders"); QString name = tr("Message Folders");
@ -395,6 +402,9 @@ void FeedReaderDialog::updateFeeds(uint32_t parentId, QTreeWidgetItem *parentIte
mOpenFeedIds->removeAt(index); mOpenFeedIds->removeAt(index);
} }
} }
} else {
/* disable drop */
item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
} }
} }
@ -832,3 +842,30 @@ void FeedReaderDialog::processFeed()
mFeedReader->processFeed(feedId); mFeedReader->processFeed(feedId);
} }
void FeedReaderDialog::feedTreeReparent(QTreeWidgetItem *item, QTreeWidgetItem *newParent)
{
if (!item || ! newParent) {
return;
}
uint32_t feedId = item->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toUInt();
uint32_t parentId = newParent->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toUInt();
if (feedId == 0) {
return;
}
RsFeedAddResult result = mFeedReader->setParent(feedId, parentId);
if (FeedReaderStringDefs::showError(this, result, tr("Move feed"), tr("Cannot move feed."))) {
return;
}
bool expanded = item->isExpanded();
item->parent()->removeChild(item);
newParent->addChild(item);
item->setExpanded(expanded);
newParent->setExpanded(true);
calculateFeedItems();
}

View File

@ -61,6 +61,7 @@ private slots:
void editFeed(); void editFeed();
void activateFeed(); void activateFeed();
void processFeed(); void processFeed();
void feedTreeReparent(QTreeWidgetItem *item, QTreeWidgetItem *newParent);
void messageTabCloseRequested(int index); void messageTabCloseRequested(int index);
void messageTabChanged(int index); void messageTabChanged(int index);

View File

@ -150,7 +150,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="RSTreeWidget" name="feedTreeWidget"> <widget class="FeedTreeWidget" name="feedTreeWidget">
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
</property> </property>
@ -186,9 +186,9 @@
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>RSTreeWidget</class> <class>FeedTreeWidget</class>
<extends>QTreeWidget</extends> <extends>QTreeWidget</extends>
<header>gui/common/RSTreeWidget.h</header> <header>gui/FeedTreeWidget.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>RSTabWidget</class> <class>RSTabWidget</class>

View File

@ -0,0 +1,119 @@
/*******************************************************************************
* plugins/FeedReader/gui/FeedTreeWidget.cpp *
* *
* Copyright (C) 2012 RetroShare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include <QDropEvent>
#include "FeedTreeWidget.h"
FeedTreeWidget::FeedTreeWidget(QWidget *parent) : RSTreeWidget(parent)
{
mDraggedItem = NULL;
}
void FeedTreeWidget::dragEnterEvent(QDragEnterEvent *event)
{
mDraggedItem = currentItem();
RSTreeWidget::dragEnterEvent(event);
}
void FeedTreeWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
RSTreeWidget::dragLeaveEvent(event);
mDraggedItem = NULL;
}
bool FeedTreeWidget::canDrop(QDropEvent *event, QTreeWidgetItem **dropItem)
{
if (dropItem) {
*dropItem = NULL;
}
if (!mDraggedItem) {
/* no drag item */
return false;
}
QModelIndex droppedIndex = indexAt(event->pos());
if (!droppedIndex.isValid()) {
/* no drop target */
return false;
}
QTreeWidgetItem *dropItemIntern = itemFromIndex(droppedIndex);
if (!dropItemIntern) {
/* no drop item */
return false;
}
if ((dropItemIntern->flags() & Qt::ItemIsDropEnabled) == 0) {
/* drop is disabled */
return false;
}
if (dropItemIntern == mDraggedItem->parent()) {
/* drag item parent */
return false;
}
if (dropItem) {
*dropItem = dropItemIntern;
}
return true;
}
void FeedTreeWidget::dragMoveEvent(QDragMoveEvent *event)
{
if (!canDrop(event)) {
event->ignore();
return;
}
RSTreeWidget::dragMoveEvent(event);
}
void FeedTreeWidget::dropEvent(QDropEvent *event)
{
QTreeWidgetItem *dropItem;
if (!canDrop(event, &dropItem)) {
event->ignore();
return;
}
if (!mDraggedItem) {
/* no drag item */
event->ignore();
return;
}
QTreeWidgetItem *draggedParent = mDraggedItem->parent();
if (!draggedParent) {
/* no drag item parent */
event->ignore();
return;
}
if (!dropItem) {
/* no drop item */
event->ignore();
return;
}
emit feedReparent(mDraggedItem, dropItem);
}

View File

@ -0,0 +1,50 @@
/*******************************************************************************
* plugins/FeedReader/gui/FeedTreeWidget.h *
* *
* Copyright (C) 2012 by Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef _FEEDTREEWIDGET_H
#define _FEEDTREEWIDGET_H
#include "gui/common/RSTreeWidget.h"
/* Subclassing RSTreeWidget */
class FeedTreeWidget : public RSTreeWidget
{
Q_OBJECT
public:
FeedTreeWidget(QWidget *parent = 0);
Q_SIGNALS:
void feedReparent(QTreeWidgetItem *item, QTreeWidgetItem *newParent);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
private:
bool canDrop(QDropEvent *event, QTreeWidgetItem **dropItem = NULL);
private:
QTreeWidgetItem *mDraggedItem;
};
#endif

View File

@ -216,6 +216,7 @@ public:
virtual RsFeedAddResult setFolder(uint32_t feedId, const std::string &name) = 0; virtual RsFeedAddResult setFolder(uint32_t feedId, const std::string &name) = 0;
virtual RsFeedAddResult addFeed(const FeedInfo &feedInfo, uint32_t &feedId) = 0; virtual RsFeedAddResult addFeed(const FeedInfo &feedInfo, uint32_t &feedId) = 0;
virtual RsFeedAddResult setFeed(uint32_t feedId, const FeedInfo &feedInfo) = 0; virtual RsFeedAddResult setFeed(uint32_t feedId, const FeedInfo &feedInfo) = 0;
virtual RsFeedAddResult setParent(uint32_t feedId, uint32_t parentId) = 0;
virtual bool removeFeed(uint32_t feedId) = 0; virtual bool removeFeed(uint32_t feedId) = 0;
virtual bool addPreviewFeed(const FeedInfo &feedInfo, uint32_t &feedId) = 0; virtual bool addPreviewFeed(const FeedInfo &feedInfo, uint32_t &feedId) = 0;
virtual void getFeedList(uint32_t parentId, std::list<FeedInfo> &feedInfos) = 0; virtual void getFeedList(uint32_t parentId, std::list<FeedInfo> &feedInfos) = 0;

View File

@ -194,7 +194,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location line="+186"/> <location line="+192"/>
<location line="+148"/> <location line="+148"/>
<location line="+15"/> <location line="+15"/>
<source>Edit feed</source> <source>Edit feed</source>
@ -312,7 +312,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui/FeedReaderDialog.cpp" line="+92"/> <location filename="../gui/FeedReaderDialog.cpp" line="+99"/>
<source>Message Folders</source> <source>Message Folders</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -362,7 +362,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location line="+195"/> <location line="+198"/>
<source>No name</source> <source>No name</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -418,6 +418,16 @@
<source>Please enter a new name for the folder</source> <source>Please enter a new name for the folder</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<location line="+61"/>
<source>Move feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+0"/>
<source>Cannot move feed.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>FeedReaderFeedItem</name> <name>FeedReaderFeedItem</name>
@ -520,7 +530,7 @@
</message> </message>
<message> <message>
<location line="+26"/> <location line="+26"/>
<location filename="../gui/FeedReaderMessageWidget.cpp" line="+113"/> <location filename="../gui/FeedReaderMessageWidget.cpp" line="+115"/>
<source>Title</source> <source>Title</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -612,7 +622,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location line="+374"/> <location line="+385"/>
<source>Hide</source> <source>Hide</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -598,6 +598,62 @@ RsFeedAddResult p3FeedReader::setFeed(uint32_t feedId, const FeedInfo &feedInfo)
return RS_FEED_ADD_RESULT_SUCCESS; return RS_FEED_ADD_RESULT_SUCCESS;
} }
RsFeedAddResult p3FeedReader::setParent(uint32_t feedId, uint32_t parentId)
{
bool changed = false;
{
RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setParent - set parent " << parentId << std::endl;
#endif
std::map<uint32_t, RsFeedReaderFeed*>::iterator feedIt = mFeeds.find(feedId);
if (feedIt == mFeeds.end()) {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setParent - feed id " << feedId << " not found" << std::endl;
#endif
return RS_FEED_ADD_RESULT_FEED_NOT_FOUND;
}
if (parentId) {
/* check parent id */
std::map<uint32_t, RsFeedReaderFeed*>::iterator parentIt = mFeeds.find(parentId);
if (parentIt == mFeeds.end()) {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setParent - parent id " << parentId << " not found" << std::endl;
#endif
return RS_FEED_ADD_RESULT_PARENT_NOT_FOUND;
}
if ((parentIt->second->flag & RS_FEED_FLAG_FOLDER) == 0) {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setParent - parent " << parentIt->second->name << " is no folder" << std::endl;
#endif
return RS_FEED_ADD_RESULT_PARENT_IS_NO_FOLDER;
}
}
RsFeedReaderFeed *fi = feedIt->second;
if (fi->parentId != parentId) {
fi->parentId = parentId;
changed = true;
}
}
if (changed) {
IndicateConfigChanged();
if (mNotify) {
mNotify->notifyFeedChanged(feedId, NOTIFY_TYPE_MOD);
}
}
return RS_FEED_ADD_RESULT_SUCCESS;
}
void p3FeedReader::deleteAllMsgs_locked(RsFeedReaderFeed *fi) void p3FeedReader::deleteAllMsgs_locked(RsFeedReaderFeed *fi)
{ {
if (!fi) { if (!fi) {

View File

@ -59,6 +59,7 @@ public:
virtual RsFeedAddResult setFolder(uint32_t feedId, const std::string &name); virtual RsFeedAddResult setFolder(uint32_t feedId, const std::string &name);
virtual RsFeedAddResult addFeed(const FeedInfo &feedInfo, uint32_t &feedId); virtual RsFeedAddResult addFeed(const FeedInfo &feedInfo, uint32_t &feedId);
virtual RsFeedAddResult setFeed(uint32_t feedId, const FeedInfo &feedInfo); virtual RsFeedAddResult setFeed(uint32_t feedId, const FeedInfo &feedInfo);
virtual RsFeedAddResult setParent(uint32_t feedId, uint32_t parentId);
virtual bool removeFeed(uint32_t feedId); virtual bool removeFeed(uint32_t feedId);
virtual bool addPreviewFeed(const FeedInfo &feedInfo, uint32_t &feedId); virtual bool addPreviewFeed(const FeedInfo &feedInfo, uint32_t &feedId);
virtual void getFeedList(uint32_t parentId, std::list<FeedInfo> &feedInfos); virtual void getFeedList(uint32_t parentId, std::list<FeedInfo> &feedInfos);