- Added update of changed posts to GxsChannelPostsWidget

- Added auto update to GxsFeedItem

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7342 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-05-06 20:19:04 +00:00
parent 2b36cefca2
commit 0abc2342fe
14 changed files with 99 additions and 42 deletions

View File

@ -32,14 +32,14 @@
/** Constructor */
PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome)
:GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsPosted, true)
PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome) :
GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsPosted, true, false)
{
setup();
}
PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome)
:GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, false),
PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome) :
GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, false, false),
mPost(post)
{
setup();

View File

@ -319,13 +319,13 @@ void PostedListDialog::updateDisplay(bool /*complete*/)
/* update List */
insertGroups();
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs = getMsgIds();
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs = getMsgIds();
if(!msgs.empty())
{
std::cerr << "rsPosted->msgsChanged():";
std::cerr << std::endl;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit;
mit = msgs.find(mCurrTopicId);
if(mit != msgs.end())
{

View File

@ -42,16 +42,14 @@
* #define DEBUG_ITEM 1
****/
#define DEBUG_ITEM 1
#define COLOR_NORMAL QColor(248, 248, 248)
#define COLOR_NEW QColor(220, 236, 253)
#define SELF_LOAD 1
#define DATA_PROVIDED 2
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome) :
GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsGxsChannels, true)
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) :
GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsGxsChannels, true, autoUpdate)
{
mMode = SELF_LOAD;
@ -59,8 +57,8 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, cons
}
/** Constructor */
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subFlags, bool isHome) :
GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, false)
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subFlags, bool isHome, bool autoUpdate) :
GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, false, autoUpdate)
{
std::cerr << "GxsChannelPostItem::GxsChannelPostItem() Direct Load";
std::cerr << std::endl;
@ -75,6 +73,19 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, cons
loadPost(post);
}
bool GxsChannelPostItem::setPost(const RsGxsChannelPost &post)
{
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
std::cerr << "GxsChannelPostItem::setPost() - Wrong id, cannot set post";
std::cerr << std::endl;
return false;
}
loadPost(post);
return true;
}
GxsChannelPostItem::~GxsChannelPostItem()
{
delete(ui);
@ -162,6 +173,7 @@ void GxsChannelPostItem::loadMessage(const uint32_t &token)
void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
{
/* fill in */
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelPostItem::loadPost()";
std::cerr << std::endl;

View File

@ -41,11 +41,12 @@ class GxsChannelPostItem : public GxsFeedItem
public:
/** Default Constructor */
GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome);
GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subscribeFlags, bool isHome);
GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate);
GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subscribeFlags, bool isHome, bool autoUpdate);
virtual ~GxsChannelPostItem();
void setFileCleanUpWarning(uint32_t time_left);
bool setPost(const RsGxsChannelPost &post);
protected:
virtual void loadMessage(const uint32_t &token);

View File

@ -23,6 +23,7 @@
#include "gui/gxs/GxsFeedItem.h"
#include "gui/feeds/FeedHolder.h"
#include "gui/gxs/RsGxsUpdateBroadcastBase.h"
#include <iostream>
@ -111,7 +112,7 @@ void GxsFeedItem::updateItem()
/***********************************************************/
GxsFeedItem::GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData) :
GxsFeedItem::GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData, bool autoUpdate) :
QWidget(NULL)
{
std::cerr << "GxsFeedItem::GxsFeedItem()";
@ -136,6 +137,14 @@ GxsFeedItem::GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId
{
mLoadQueue = NULL;
}
if (mGxsIface && autoUpdate) {
/* Connect to update broadcast */
mUpdateBroadcastBase = new RsGxsUpdateBroadcastBase(mGxsIface);
connect(mUpdateBroadcastBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool)));
} else {
mUpdateBroadcastBase = NULL;
}
}
GxsFeedItem::~GxsFeedItem()
@ -143,12 +152,33 @@ GxsFeedItem::~GxsFeedItem()
std::cerr << "GxsFeedItem::~GxsFeedItem()";
std::cerr << std::endl;
if (mUpdateBroadcastBase)
{
delete(mUpdateBroadcastBase);
}
if (mLoadQueue)
{
delete mLoadQueue;
}
}
void GxsFeedItem::fillDisplay(bool /*complete*/)
{
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs = mUpdateBroadcastBase->getMsgIds();
if (!msgs.empty())
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit = msgs.find(groupId());
if (mit != msgs.end())
{
const std::vector<RsGxsMessageId> &msgIds = mit->second;
if (std::find(msgIds.begin(), msgIds.end(), messageId()) != msgIds.end()) {
requestMessage();
}
}
}
}
void GxsFeedItem::requestGroupMeta()
{
std::cerr << "GxsFeedItem::requestGroup()";
@ -177,7 +207,12 @@ void GxsFeedItem::requestMessage()
if (!mLoadQueue)
{
return;
if (mGxsIface)
{
mLoadQueue = new TokenQueue(mGxsIface->getTokenService(), this);
} else {
return;
}
}
RsTokReqOptions opts;

View File

@ -29,6 +29,7 @@
#include <stdint.h>
class FeedHolder;
class RsGxsUpdateBroadcastBase;
class GxsFeedItem : public QWidget, public TokenResponse
{
@ -36,7 +37,7 @@ class GxsFeedItem : public QWidget, public TokenResponse
public:
/** Note parent can = NULL */
GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData);
GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData, bool autoUpdate);
virtual ~GxsFeedItem();
RsGxsGroupId groupId() { return mGroupId; }
@ -61,6 +62,10 @@ protected slots:
void unsubscribe();
void removeItem();
private slots:
/* RsGxsUpdateBroadcastBase */
void fillDisplay(bool complete);
protected:
FeedHolder *mParent;
uint32_t mFeedId;
@ -76,6 +81,7 @@ private:
RsGxsIfaceHelper *mGxsIface;
TokenQueue *mLoadQueue;
RsGxsUpdateBroadcastBase *mUpdateBroadcastBase;
};
#endif

View File

@ -14,16 +14,17 @@ class RsGxsUpdateBroadcastBase : public QObject
Q_OBJECT
protected:
public:
RsGxsUpdateBroadcastBase(RsGxsIfaceHelper* ifaceImpl, QWidget *parent = NULL);
virtual ~RsGxsUpdateBroadcastBase();
const std::list<RsGxsGroupId> &getGrpIds() { return mGrpIds; }
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds() { return mMsgIds; }
protected:
void fillComplete();
void setUpdateWhenInvisible(bool update) { mUpdateWhenInvisible = update; }
std::list<RsGxsGroupId> &getGrpIds() { return mGrpIds; }
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds() { return mMsgIds; }
void showEvent(QShowEvent *e);
signals:

View File

@ -22,12 +22,12 @@ void RsGxsUpdateBroadcastPage::setUpdateWhenInvisible(bool update)
mBase->setUpdateWhenInvisible(update);
}
std::list<RsGxsGroupId> &RsGxsUpdateBroadcastPage::getGrpIds()
const std::list<RsGxsGroupId> &RsGxsUpdateBroadcastPage::getGrpIds()
{
return mBase->getGrpIds();
}
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &RsGxsUpdateBroadcastPage::getMsgIds()
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &RsGxsUpdateBroadcastPage::getMsgIds()
{
return mBase->getMsgIds();
}

View File

@ -24,8 +24,8 @@ public:
void fillComplete();
void setUpdateWhenInvisible(bool update);
std::list<RsGxsGroupId> &getGrpIds();
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds();
const std::list<RsGxsGroupId> &getGrpIds();
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds();
protected:
virtual void showEvent(QShowEvent *event);

View File

@ -22,12 +22,12 @@ void RsGxsUpdateBroadcastWidget::setUpdateWhenInvisible(bool update)
mBase->setUpdateWhenInvisible(update);
}
std::list<RsGxsGroupId> &RsGxsUpdateBroadcastWidget::getGrpIds()
const std::list<RsGxsGroupId> &RsGxsUpdateBroadcastWidget::getGrpIds()
{
return mBase->getGrpIds();
}
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &RsGxsUpdateBroadcastWidget::getMsgIds()
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &RsGxsUpdateBroadcastWidget::getMsgIds()
{
return mBase->getMsgIds();
}

View File

@ -24,8 +24,8 @@ public:
void fillComplete();
void setUpdateWhenInvisible(bool update);
std::list<RsGxsGroupId> &getGrpIds();
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds();
const std::list<RsGxsGroupId> &getGrpIds();
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds();
protected:
virtual void showEvent(QShowEvent *event);

View File

@ -60,7 +60,7 @@ public:
virtual QWidget *createHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId)
{
return new GxsChannelPostItem(NULL, 0, grpId, msgId, true);
return new GxsChannelPostItem(NULL, 0, grpId, msgId, true, true);
}
virtual QPixmap getServicePixmap()

View File

@ -43,8 +43,8 @@
#define TOKEN_TYPE_RELATEDPOSTS 8
/** Constructor */
GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent)
: GxsMessageFrameWidget(rsGxsChannels, parent),
GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent) :
GxsMessageFrameWidget(rsGxsChannels, parent),
ui(new Ui::GxsChannelPostsWidget)
{
/* Invoke the Qt Designer generated object setup routine */
@ -96,16 +96,16 @@ void GxsChannelPostsWidget::updateDisplay(bool complete)
return;
}
std::list<RsGxsGroupId> &grpIds = getGrpIds();
const std::list<RsGxsGroupId> &grpIds = getGrpIds();
if (!mChannelId.isNull() && std::find(grpIds.begin(), grpIds.end(), mChannelId) != grpIds.end()) {
requestGroupData(mChannelId);
/* Do we need to fill all posts? */
requestPosts(mChannelId);
} else {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs = getMsgIds();
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs = getMsgIds();
if (!msgs.empty())
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit = msgs.find(mChannelId);
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit = msgs.find(mChannelId);
if(mit != msgs.end())
{
requestRelatedPosts(mChannelId, mit->second);
@ -279,9 +279,10 @@ void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &po
}
}
if (item) {
//TODO: Update item
item->setPost(*it);
//TODO: Sort timestamp
} else {
item = new GxsChannelPostItem(this, 0, *it, subscribeFlags, true);
item = new GxsChannelPostItem(this, 0, *it, subscribeFlags, true, false);
mChannelPostItems.push_back(item);
if (related) {
ui->verticalLayout->insertWidget(0, item);
@ -626,10 +627,11 @@ void GxsChannelPostsWidget::requestRelatedPosts(const RsGxsGroupId &grpId, const
return;
}
mStateHelper->setLoading(TOKEN_TYPE_POSTS, true);
if (msgIds.empty()) {
return;
}
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(grpId);
mStateHelper->setLoading(TOKEN_TYPE_POSTS, true);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;

View File

@ -318,12 +318,12 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
return;
}
std::list<RsGxsGroupId> &grpIds = getGrpIds();
const std::list<RsGxsGroupId> &grpIds = getGrpIds();
if (std::find(grpIds.begin(), grpIds.end(), mForumId) != grpIds.end()) {
/* Update threads */
insertThreads();
} else {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgIds = getMsgIds();
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgIds = getMsgIds();
if (msgIds.find(mForumId) != msgIds.end()) {
/* Update threads */
insertThreads();