diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index 2bf42de87..15b174acc 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -26,7 +26,8 @@ #include "ui_RSFeedWidget.h" #include "RSTreeWidgetItem.h" #include "gui/feeds/FeedItem.h" -#include "gui/gxs/GxsFeedItem.h" + +#include #define COLUMN_FEED 0 @@ -108,6 +109,7 @@ bool RSFeedWidget::eventFilter(QObject *object, QEvent *event) FeedItem *feedItem = feedItemFromTreeItem(treeItem); if (feedItem) { disconnectSignals(feedItem); + feedRemoved(feedItem); delete(feedItem); } delete(treeItem); @@ -127,6 +129,21 @@ bool RSFeedWidget::eventFilter(QObject *object, QEvent *event) return QWidget::eventFilter(object, event); } +void RSFeedWidget::feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem) +{ + mItems.insert(feedItem, treeItem); +} + +void RSFeedWidget::feedRemoved(FeedItem *feedItem) +{ + mItems.remove(feedItem); +} + +void RSFeedWidget::feedsCleared() +{ + mItems.clear(); +} + void RSFeedWidget::connectSignals(FeedItem *feedItem) { connect(feedItem, SIGNAL(feedItemDestroyed(FeedItem*)), this, SLOT(feedItemDestroyed(FeedItem*))); @@ -167,6 +184,8 @@ void RSFeedWidget::addFeedItem(FeedItem *feedItem, Qt::ItemDataRole sortRole, co ui->treeWidget->addTopLevelItem(treeItem); ui->treeWidget->setItemWidget(treeItem, 0, feedItem); + feedAdded(feedItem, treeItem); + connectSignals(feedItem); filterItem(treeItem, feedItem); @@ -192,6 +211,8 @@ void RSFeedWidget::addFeedItem(FeedItem *feedItem, const QMaptreeWidget->addTopLevelItem(treeItem); ui->treeWidget->setItemWidget(treeItem, 0, feedItem); + feedAdded(feedItem, treeItem); + connectSignals(feedItem); filterItem(treeItem, feedItem); @@ -246,6 +267,8 @@ void RSFeedWidget::clear() } } + feedsCleared(); + /* Clear items */ ui->treeWidget->clear(); @@ -369,6 +392,7 @@ void RSFeedWidget::removeFeedItem(FeedItem *feedItem) disconnectSignals(feedItem); QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem); + feedRemoved(feedItem); if (treeItem) { delete(treeItem); } @@ -396,6 +420,7 @@ void RSFeedWidget::feedItemDestroyed(FeedItem *feedItem) /* No need to disconnect when object will be destroyed */ QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem); + feedRemoved(feedItem); if (treeItem) { delete(treeItem); } @@ -407,16 +432,12 @@ void RSFeedWidget::feedItemDestroyed(FeedItem *feedItem) QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(FeedItem *feedItem) { - QTreeWidgetItemIterator it(ui->treeWidget); - QTreeWidgetItem *treeItem; - while ((treeItem = *it) != NULL) { - ++it; - if (feedItemFromTreeItem(treeItem) == feedItem) { - return treeItem; - } + QMap::iterator it = mItems.find(feedItem); + if (it == mItems.end()) { + return NULL; } - return NULL; + return it.value(); } bool RSFeedWidget::scrollTo(FeedItem *feedItem, bool focus) @@ -491,38 +512,3 @@ void RSFeedWidget::selectedFeedItems(QList &feedItems) feedItems.push_back(feedItem); } } - -struct FindGxsFeedItemData -{ - FindGxsFeedItemData(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId) : mGroupId(groupId), mMessageId(messageId) {} - - const RsGxsGroupId &mGroupId; - const RsGxsMessageId &mMessageId; -}; - -static bool findGxsFeedItemCallback(FeedItem *feedItem, void *data) -{ - FindGxsFeedItemData *findData = (FindGxsFeedItemData*) data; - if (!findData || findData->mGroupId.isNull() || findData->mMessageId.isNull()) { - return false; - } - - GxsFeedItem *item = dynamic_cast(feedItem); - if (!item) { - return false; - } - - if (item->groupId() != findData->mGroupId || - item->messageId() != findData->mMessageId) { - return false; - } - - return true; -} - -GxsFeedItem *RSFeedWidget::findGxsFeedItem(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId) -{ - FindGxsFeedItemData data(groupId, messageId); - FeedItem *feedItem = findFeedItem(findGxsFeedItemCallback, &data); - return dynamic_cast(feedItem); -} diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.h b/retroshare-gui/src/gui/common/RSFeedWidget.h index 205554bc0..66bd0351c 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.h +++ b/retroshare-gui/src/gui/common/RSFeedWidget.h @@ -26,14 +26,11 @@ #include #include -#include "retroshare/rsgxsifacetypes.h" - #define FEED_TREEWIDGET_SORTROLE Qt::UserRole class FeedItem; class QTreeWidgetItem; class RSTreeWidgetItemCompareRole; -class GxsFeedItem; namespace Ui { class RSFeedWidget; @@ -79,9 +76,6 @@ public: void selectedFeedItems(QList &feedItems); - /* Convenience functions */ - GxsFeedItem *findGxsFeedItem(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId); - signals: void feedCountChanged(); @@ -93,6 +87,9 @@ public slots: protected: bool eventFilter(QObject *object, QEvent *event); + virtual void feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem); + virtual void feedRemoved(FeedItem *feedItem); + virtual void feedsCleared(); private slots: void feedItemDestroyed(FeedItem *feedItem); @@ -121,6 +118,9 @@ private: /* Options */ int mCountChangedDisabled; + /* Items */ + QMap mItems; + Ui::RSFeedWidget *ui; }; diff --git a/retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp b/retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp new file mode 100644 index 000000000..29a4d5f83 --- /dev/null +++ b/retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp @@ -0,0 +1,75 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2015, RetroShare Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include "GxsFeedWidget.h" +#include "gui/gxs/GxsFeedItem.h" + +#define PAIR(groupId,messageId) QPair(groupId, messageId) + +GxsFeedWidget::GxsFeedWidget(QWidget *parent) + : RSFeedWidget(parent) +{ +} + +GxsFeedWidget::~GxsFeedWidget() +{ +} + +void GxsFeedWidget::feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem) +{ + RSFeedWidget::feedAdded(feedItem, treeItem); + + GxsFeedItem *gxsFeedItem = dynamic_cast(feedItem); + if (!gxsFeedItem) { + return; + } + + mGxsItems.insert(PAIR(gxsFeedItem->groupId(), gxsFeedItem->messageId()), feedItem); +} + +void GxsFeedWidget::feedRemoved(FeedItem *feedItem) +{ + RSFeedWidget::feedRemoved(feedItem); + + GxsFeedItem *gxsFeedItem = dynamic_cast(feedItem); + if (!gxsFeedItem) { + return; + } + + mGxsItems.remove(PAIR(gxsFeedItem->groupId(), gxsFeedItem->messageId())); +} + +void GxsFeedWidget::feedsCleared() +{ + RSFeedWidget::feedsCleared(); + + mGxsItems.clear(); +} + +GxsFeedItem *GxsFeedWidget::findGxsFeedItem(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId) +{ + QMap, FeedItem*>::iterator it = mGxsItems.find(PAIR(groupId, messageId)); + if (it == mGxsItems.end()) { + return NULL; + } + + return dynamic_cast(it.value()); +} diff --git a/retroshare-gui/src/gui/gxs/GxsFeedWidget.h b/retroshare-gui/src/gui/gxs/GxsFeedWidget.h new file mode 100644 index 000000000..983fa0587 --- /dev/null +++ b/retroshare-gui/src/gui/gxs/GxsFeedWidget.h @@ -0,0 +1,52 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2015, RetroShare Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef _GXSFEEDTREEWIDGET_H +#define _GXSFEEDTREEWIDGET_H + +#include "gui/common/RSFeedWidget.h" + +#include "retroshare/rsgxsifacetypes.h" + +class GxsFeedItem; + +class GxsFeedWidget : public RSFeedWidget +{ + Q_OBJECT + +public: + GxsFeedWidget(QWidget *parent = 0); + virtual ~GxsFeedWidget(); + + GxsFeedItem *findGxsFeedItem(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId); + +protected: + /* RSFeedWidget */ + virtual void feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem); + virtual void feedRemoved(FeedItem *feedItem); + virtual void feedsCleared(); + +private: + /* Items */ + QMap, FeedItem*> mGxsItems; +}; + +#endif diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui index 908c3b7f0..1e351d48e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui @@ -454,7 +454,7 @@ - + 0 @@ -497,9 +497,9 @@
gui/common/SubscribeToolButton.h
- RSFeedWidget + GxsFeedWidget QWidget -
gui/common/RSFeedWidget.h
+
gui/gxs/GxsFeedWidget.h
1
diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 680273a6d..764aa56dc 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -1297,6 +1297,7 @@ gxsgui { gui/gxs/RsGxsUpdateBroadcastPage.h \ gui/gxs/GxsGroupShareKey.h \ gui/gxs/GxsUserNotify.h \ + gui/gxs/GxsFeedWidget.h \ util/TokenQueue.h \ util/RsGxsUpdateBroadcast.h \ @@ -1333,6 +1334,7 @@ gxsgui { gui/gxs/RsGxsUpdateBroadcastWidget.cpp \ gui/gxs/RsGxsUpdateBroadcastPage.cpp \ gui/gxs/GxsUserNotify.cpp \ + gui/gxs/GxsFeedWidget.cpp \ util/TokenQueue.cpp \ util/RsGxsUpdateBroadcast.cpp \