Added threaded loading of channel posts.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7480 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-08-01 18:54:55 +00:00
parent 2d2e3881cf
commit 7a65ad1a14
9 changed files with 277 additions and 63 deletions

View file

@ -52,7 +52,6 @@ QString GxsChannelDialog::text(TextType type)
return tr("Create Channel");
case TEXT_TODO:
return "<b>Open points:</b><ul>"
"<li>Threaded load of messages"
"<li>Share key"
"<li>Restore channel keys"
"<li>Navigate channel link"

View file

@ -57,10 +57,10 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
/* Setup UI helper */
// No progress yet
mStateHelper->addWidget(mTokenTypePosts, ui->loadingLabel, UISTATE_LOADING_VISIBLE);
// mStateHelper->addWidget(mTokenTypePosts, ui->progressBar, UISTATE_LOADING_VISIBLE);
// mStateHelper->addWidget(mTokenTypePosts, ui->progressLabel, UISTATE_LOADING_VISIBLE);
mStateHelper->addWidget(mTokenTypePosts, ui->progressBar, UISTATE_LOADING_VISIBLE);
mStateHelper->addWidget(mTokenTypePosts, ui->filterLineEdit);
mStateHelper->addWidget(mTokenTypeRelatedPosts, ui->loadingLabel, UISTATE_LOADING_VISIBLE);
mStateHelper->addLoadPlaceholder(mTokenTypeGroupData, ui->nameLabel);
@ -81,7 +81,6 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
/*************** Setup Left Hand Side (List of Channels) ****************/
ui->loadingLabel->hide();
ui->progressLabel->hide();
ui->progressBar->hide();
ui->nameLabel->setMinimumWidth(20);
@ -271,33 +270,69 @@ void GxsChannelPostsWidget::filterChanged(int filter)
return bVisible;
}
void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &posts, bool related)
void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost &post, bool related)
{
GxsChannelPostItem *item = NULL;
if (related) {
FeedItem *feedItem = ui->feedWidget->findGxsFeedItem(post.mMeta.mGroupId, post.mMeta.mMsgId);
item = dynamic_cast<GxsChannelPostItem*>(feedItem);
}
if (item) {
item->setContent(post);
ui->feedWidget->setSort(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs));
} else {
uint32_t subscribeFlags = 0xffffffff;
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post, subscribeFlags, true, false);
ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs));
}
}
void GxsChannelPostsWidget::fillThreadCreatePost(const QVariant &post, bool related, int current, int count)
{
/* show fill progress */
if (count) {
ui->progressBar->setValue(current * ui->progressBar->maximum() / count);
}
if (!post.canConvert<RsGxsChannelPost>()) {
return;
}
createPostItem(post.value<RsGxsChannelPost>(), related);
}
void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &posts, GxsMessageFramePostThread *thread, bool related)
{
if (related && thread) {
std::cerr << "GxsChannelPostsWidget::insertChannelPosts fill only related posts as thread is not possible" << std::endl;
return;
}
std::vector<RsGxsChannelPost>::const_iterator it;
uint32_t subscribeFlags = 0xffffffff;
int count = posts.size();
int pos = 0;
ui->feedWidget->setSortingEnabled(false);
if (!thread) {
ui->feedWidget->setSortingEnabled(false);
}
for (it = posts.begin(); it != posts.end(); it++)
{
const RsGxsChannelPost &msg = *it;
GxsChannelPostItem *item = NULL;
if (related) {
FeedItem *feedItem = ui->feedWidget->findGxsFeedItem(msg.mMeta.mGroupId, msg.mMeta.mMsgId);
item = dynamic_cast<GxsChannelPostItem*>(feedItem);
if (thread && thread->stopped()) {
break;
}
if (item) {
item->setContent(*it);
//TODO: Sort timestamp
if (thread) {
thread->emitAddPost(qVariantFromValue(*it), related, ++pos, count);
} else {
item = new GxsChannelPostItem(this, 0, *it, subscribeFlags, true, false);
ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(msg.mMeta.mPublishTs));
createPostItem(*it, related);
}
}
ui->feedWidget->setSortingEnabled(true);
if (!thread) {
ui->feedWidget->setSortingEnabled(true);
}
}
void GxsChannelPostsWidget::clearPosts()
@ -352,12 +387,12 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa
return false;
}
void GxsChannelPostsWidget::insertPosts(const uint32_t &token)
void GxsChannelPostsWidget::insertPosts(const uint32_t &token, GxsMessageFramePostThread *thread)
{
std::vector<RsGxsChannelPost> posts;
rsGxsChannels->getPostData(token, posts);
insertChannelPosts(posts, false);
insertChannelPosts(posts, thread, false);
}
void GxsChannelPostsWidget::insertRelatedPosts(const uint32_t &token)
@ -365,7 +400,7 @@ void GxsChannelPostsWidget::insertRelatedPosts(const uint32_t &token)
std::vector<RsGxsChannelPost> posts;
rsGxsChannels->getRelatedPosts(token, posts);
insertChannelPosts(posts, true);
insertChannelPosts(posts, NULL, true);
}
static void setAllMessagesReadCallback(FeedItem *feedItem, const QVariant &data)

View file

@ -60,9 +60,11 @@ protected:
/* GxsMessageFramePostWidget */
virtual void groupNameChanged(const QString &name);
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData);
virtual void insertPosts(const uint32_t &token);
virtual void insertPosts(const uint32_t &token, GxsMessageFramePostThread *thread);
virtual void insertRelatedPosts(const uint32_t &token);
virtual void clearPosts();
virtual bool useThread() { return true; }
virtual void fillThreadCreatePost(const QVariant &post, bool related, int current, int count);
private slots:
void createMsg();
@ -70,9 +72,6 @@ private slots:
void subscribeGroup(bool subscribe);
void filterChanged(int filter);
//void fillThreadFinished();
//void fillThreadAddMsg(const QString &channelId, const QString &channelMsgId, int current, int count);
private:
void processSettings(bool load);
@ -80,7 +79,9 @@ private:
static bool filterItem(FeedItem *feedItem, const QString &text, int filter);
void insertChannelDetails(const RsGxsChannelGroup &group);
void insertChannelPosts(std::vector<RsGxsChannelPost> &posts, bool related);
void insertChannelPosts(std::vector<RsGxsChannelPost> &posts, GxsMessageFramePostThread *thread, bool related);
void createPostItem(const RsGxsChannelPost &post, bool related);
private:
QAction *mAutoDownloadAction;

View file

@ -177,6 +177,22 @@
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>10</height>
</size>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="LineEditClear" name="filterLineEdit">
<property name="sizePolicy">
@ -208,27 +224,6 @@
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="progressLayout">
<item>
<widget class="QLabel" name="progressLabel">
<property name="text">
<string>Loading</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>24</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="RSFeedWidget" name="feedWidget" native="true">
<property name="sizePolicy">