- Switched from own token member to the new methods on TokenQueue.
- Reactivated thread from the old forum to fill the messages.
- Load all messages at once.
- Added processing of missing messages.
- Fixed new/read/unread status.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5952 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-12-09 02:32:47 +00:00
parent 6527aaf2d8
commit 4413536926
10 changed files with 781 additions and 661 deletions

View File

@ -34,6 +34,7 @@
#include "gxs/rsgxsifaceimpl.h"
#define IS_MSG_NEW(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
#define IS_MSG_UNREAD(status) (status & GXS_SERV::GXS_MSG_STATUS_UNREAD)
#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & (GXS_SERV::GROUP_SUBSCRIBE_ADMIN | GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED))

View File

@ -228,7 +228,7 @@ bool p3GxsForums::createMsg(uint32_t &token, RsGxsForumMsg &msg)
void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
{
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD;
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD | GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNREAD;
if (read)
{
@ -285,9 +285,9 @@ void p3GxsForums::dummy_tick()
if (mGenActive)
{
std::cerr << "p3Wiki::dummyTick() AboutActive";
std::cerr << "p3GxsForums::dummyTick() AboutActive";
std::cerr << std::endl;
uint32_t status = RsGenExchange::getTokenService()->requestStatus(mGenToken);
if (status != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
{
@ -406,6 +406,8 @@ bool p3GxsForums::generateMessage(uint32_t &token, const RsGxsGroupId &grpId, co
msg.mMeta.mThreadId = threadId;
msg.mMeta.mParentId = parentId;
msg.mMeta.mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_UNREAD;
/* chose a random Id to sign with */
std::list<RsGxsId> ownIds;
std::list<RsGxsId>::iterator it;

View File

@ -968,7 +968,8 @@ gxsforums {
HEADERS += gui/GxsForumsDialog.h \
gui/gxsforums/CreateGxsForumMsg.h \
gui/gxsforums/GxsForumThreadWidget.h
gui/gxsforums/GxsForumThreadWidget.h \
gui/gxsforums/GxsForumsFillThread.h
FORMS += gui/GxsForumsDialog.ui \
gui/gxsforums/CreateGxsForumMsg.ui \
@ -976,7 +977,8 @@ gxsforums {
SOURCES += gui/GxsForumsDialog.cpp \
gui/gxsforums/CreateGxsForumMsg.cpp \
gui/gxsforums/GxsForumThreadWidget.cpp
gui/gxsforums/GxsForumThreadWidget.cpp \
gui/gxsforums/GxsForumsFillThread.cpp
}

View File

@ -69,8 +69,6 @@ GxsForumsDialog::GxsForumsDialog(QWidget *parent)
/* Setup Queue */
mForumQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
mTokenGroupSummary = 0;
mRequestGroupSummary = false;
connect(ui.forumTreeWidget, SIGNAL(treeCustomContextMenuRequested(QPoint)), this, SLOT(forumListCustomPopupMenu(QPoint)));
connect(ui.newForumButton, SIGNAL(clicked()), this, SLOT(newforum()));
@ -172,10 +170,10 @@ void GxsForumsDialog::forumListCustomPopupMenu(QPoint /*point*/)
contextMnu.addSeparator();
action = contextMnu.addAction(QIcon(":/images/message-mail-read.png"), tr("Mark all as read"), this, SLOT(markMsgAsReadAll()));
action = contextMnu.addAction(QIcon(":/images/message-mail-read.png"), tr("Mark all as read"), this, SLOT(markMsgAsRead()));
action->setEnabled (!mForumId.empty () && IS_GROUP_SUBSCRIBED(subscribeFlags));
action = contextMnu.addAction(QIcon(":/images/message-mail.png"), tr("Mark all as unread"), this, SLOT(markMsgAsUnreadAll()));
action = contextMnu.addAction(QIcon(":/images/message-mail.png"), tr("Mark all as unread"), this, SLOT(markMsgAsUnread()));
action->setEnabled (!mForumId.empty () && IS_GROUP_SUBSCRIBED(subscribeFlags));
#ifdef DEBUG_FORUMS
@ -319,6 +317,20 @@ void GxsForumsDialog::insertForumsData(const std::list<RsGroupMetaData> &forumLi
updateMessageSummaryList("");
}
GxsForumThreadWidget *GxsForumsDialog::forumThreadWidget(const std::string &id)
{
int tabCount = ui.threadTabWidget->count();
for (int index = 0; index < tabCount; ++index) {
GxsForumThreadWidget *childWidget = dynamic_cast<GxsForumThreadWidget*>(ui.threadTabWidget->widget(index));
if (childWidget && childWidget->forumId() == id) {
return childWidget;
break;
}
}
return NULL;
}
void GxsForumsDialog::changedForum(const QString &id)
{
mForumId = id.toStdString();
@ -329,20 +341,12 @@ void GxsForumsDialog::changedForum(const QString &id)
// requestGroupSummary_CurrentForum(mForumId);
/* search exisiting tab */
GxsForumThreadWidget *threadWidget = NULL;
int tabCount = ui.threadTabWidget->count();
for (int index = 0; index < tabCount; ++index) {
GxsForumThreadWidget *childWidget = dynamic_cast<GxsForumThreadWidget*>(ui.threadTabWidget->widget(index));
if (childWidget && childWidget->forumId() == id.toStdString()) {
threadWidget = childWidget;
break;
}
}
GxsForumThreadWidget *threadWidget = forumThreadWidget(id.toStdString());
if (!threadWidget) {
/* create a thread widget */
threadWidget = new GxsForumThreadWidget(id.toStdString());
int index = ui.threadTabWidget->addTab(threadWidget, threadWidget->forumName());
int index = ui.threadTabWidget->addTab(threadWidget, threadWidget->forumName(true));
ui.threadTabWidget->setTabIcon(index, threadWidget->forumIcon());
connect(threadWidget, SIGNAL(forumChanged(QWidget*)), this, SLOT(threadTabChanged(QWidget*)));
}
@ -370,33 +374,10 @@ void GxsForumsDialog::threadTabChanged(QWidget *widget)
return;
}
ui.threadTabWidget->setTabText(index, threadWidget->forumName());
ui.threadTabWidget->setTabText(index, threadWidget->forumName(true));
ui.threadTabWidget->setTabIcon(index, threadWidget->forumIcon());
}
QString GxsForumsDialog::titleFromInfo(const RsMsgMetaData &meta)
{
// NOTE - NOTE SURE HOW THIS WILL WORK!
#ifdef TOGXS
if (meta.mMsgStatus & RS_DISTRIB_MISSING_MSG) {
return QApplication::translate("GxsForumsDialog", "[ ... Missing Message ... ]");
}
#endif
return QString::fromUtf8(meta.mMsgName.c_str());
}
QString GxsForumsDialog::messageFromInfo(const RsGxsForumMsg &msg)
{
#ifdef TOGXS
if (msg.mMeta.mMsgStatus & RS_DISTRIB_MISSING_MSG) {
return QApplication::translate("GxsForumsDialog", "Placeholder for missing Message");
}
#endif
return QString::fromUtf8(msg.mMsg.c_str());
}
void GxsForumsDialog::copyForumLink()
{
if (mForumId.empty()) {
@ -422,6 +403,22 @@ void GxsForumsDialog::copyForumLink()
QMessageBox::warning(this, "RetroShare", "ToDo");
}
void GxsForumsDialog::markMsgAsRead()
{
GxsForumThreadWidget *threadWidget = forumThreadWidget(mForumId);
if (threadWidget) {
threadWidget->setAllMsgReadStatus(true);
}
}
void GxsForumsDialog::markMsgAsUnread()
{
GxsForumThreadWidget *threadWidget = forumThreadWidget(mForumId);
if (threadWidget) {
threadWidget->setAllMsgReadStatus(false);
}
}
void GxsForumsDialog::newforum()
{
GxsForumGroupDialog cf(mForumQueue, this);
@ -597,8 +594,8 @@ void GxsForumsDialog::generateMassData()
/** Request / Response of Data ********************************/
/*********************** **** **** **** ***********************/
#define FORUMSV2DIALOG_LISTING 1
//#define FORUMSV2DIALOG_CURRENTFORUM 2
#define TOKEN_TYPE_LISTING 1
//#define TOKEN_TYPE_CURRENTFORUM 2
void GxsForumsDialog::insertForums()
{
@ -610,20 +607,23 @@ void GxsForumsDialog::requestGroupSummary()
std::cerr << "GxsForumsDialog::requestGroupSummary()";
std::cerr << std::endl;
if (mRequestGroupSummary) {
std::cerr << "GxsForumsDialog::requestGroupSummary() Canceling Request: " << mTokenGroupSummary;
std::cerr << std::endl;
std::list<uint32_t> tokens;
mForumQueue->activeRequestTokens(TOKEN_TYPE_LISTING, tokens);
if (!tokens.empty()) {
std::list<uint32_t>::iterator tokenIt;
for (tokenIt = tokens.begin(); tokenIt != tokens.end(); ++tokenIt) {
std::cerr << "GxsForumsDialog::requestGroupSummary() Canceling Request: " << *tokenIt;
std::cerr << std::endl;
mForumQueue->cancelRequest(mTokenGroupSummary);
mTokenGroupSummary = 0;
mRequestGroupSummary = false;
mForumQueue->cancelRequest(*tokenIt);
}
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
mForumQueue->requestGroupInfo(mTokenGroupSummary, RS_TOKREQ_ANSTYPE_SUMMARY, opts, FORUMSV2DIALOG_LISTING);
mRequestGroupSummary = true;
uint32_t token;
mForumQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_LISTING);
}
void GxsForumsDialog::loadGroupSummary(const uint32_t &token)
@ -631,18 +631,6 @@ void GxsForumsDialog::loadGroupSummary(const uint32_t &token)
std::cerr << "GxsForumsDialog::loadGroupSummary()";
std::cerr << std::endl;
if (!mRequestGroupSummary) {
std::cerr << "GxsForumsDialog::loadGroupSummary()) No waiting request got token: " << token;
std::cerr << std::endl;
return;
}
if (token != mTokenGroupSummary) {
std::cerr << "GxsForumsDialog::loadGroupSummary()) Wrong token - want: " << mTokenGroupSummary << " got: " << token;
std::cerr << std::endl;
return;
}
std::list<RsGroupMetaData> groupInfo;
rsGxsForums->getGroupSummary(token, groupInfo);
@ -655,8 +643,6 @@ void GxsForumsDialog::loadGroupSummary(const uint32_t &token)
std::cerr << "GxsForumsDialog::loadGroupSummary() ERROR No Groups...";
std::cerr << std::endl;
}
mTokenGroupSummary = 0;
mRequestGroupSummary = false;
}
/*********************** **** **** **** ***********************/
@ -674,7 +660,7 @@ void GxsForumsDialog::loadGroupSummary(const uint32_t &token)
// std::cerr << std::endl;
// uint32_t token;
// mForumQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, FORUMSV2DIALOG_CURRENTFORUM);
// mForumQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_CURRENTFORUM);
//}
//void GxsForumsDialog::loadGroupSummary_CurrentForum(const uint32_t &token)
@ -713,11 +699,11 @@ void GxsForumsDialog::loadRequest(const TokenQueue *queue, const TokenRequest &r
/* now switch on req */
switch(req.mUserType)
{
case FORUMSV2DIALOG_LISTING:
case TOKEN_TYPE_LISTING:
loadGroupSummary(req.mToken);
break;
// case FORUMSV2DIALOG_CURRENTFORUM:
// case TOKEN_TYPE_CURRENTFORUM:
// loadGroupSummary_CurrentForum(req.mToken);
// break;

View File

@ -36,6 +36,7 @@
class ForumInfo;
class RsGxsForumMsg;
class GxsForumThreadWidget;
class GxsForumsDialog : public RsAutoUpdatePage, public TokenResponse
{
@ -55,10 +56,6 @@ public:
// Callback for all Loads.
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
// Utility Fns.
static QString titleFromInfo(const RsMsgMetaData &meta);
static QString messageFromInfo(const RsGxsForumMsg &msg);
private slots:
void forceUpdateDisplay(); // TEMP HACK FN.
@ -80,6 +77,9 @@ private slots:
void showForumDetails();
void editForumDetails();
void markMsgAsRead();
void markMsgAsUnread();
void generateMassData();
void shareKey();
@ -101,13 +101,13 @@ private:
void requestGroupSummary();
void loadGroupSummary(const uint32_t &token);
GxsForumThreadWidget *forumThreadWidget(const std::string &id);
// void requestGroupSummary_CurrentForum(const std::string &forumId);
// void loadGroupSummary_CurrentForum(const uint32_t &token);
std::string mForumId;
TokenQueue *mForumQueue;
uint32_t mTokenGroupSummary;
bool mRequestGroupSummary;
QTreeWidgetItem *yourForums;
QTreeWidgetItem *subscribedForums;

File diff suppressed because it is too large Load Diff

View File

@ -6,38 +6,14 @@
#include "util/TokenQueue.h"
class QTreeWidgetItem;
class GxsIdTreeWidgetItem;
class RSTreeWidgetItemCompareRole;
class RsGxsForumMsg;
class GxsForumsFillThread;
namespace Ui {
class GxsForumThreadWidget;
}
/* These are all the parameters that are required for thread loading.
* They are kept static for the load duration.
*/
class GxsForumsThreadLoadParameters
{
public:
std::string ForumId;
std::string FocusMsgId;
uint32_t SubscribeFlags;
int ViewType;
uint32_t FilterColumn;
std::map<uint32_t, QTreeWidgetItem *> MsgTokens;
QList<QTreeWidgetItem*> Items;
QList<QTreeWidgetItem*> ItemToExpand;
bool FillComplete;
bool FlatView;
bool UseChildTS;
bool ExpandNewMessages;
};
class GxsForumThreadWidget : public QWidget, public TokenResponse
{
Q_OBJECT
@ -65,8 +41,15 @@ public:
void setTextColorMissing(QColor color) { mTextColorMissing = color; }
std::string forumId() { return mForumId; }
QString forumName();
QString forumName(bool withUnreadCount);
QIcon forumIcon();
unsigned int newCount() { return mNewCount; }
unsigned int unreadCount() { return mUnreadCount; }
QTreeWidgetItem *convertMsgToThreadWidget(const RsGxsForumMsg &msg, bool useChildTS, uint32_t filterColumn);
QTreeWidgetItem *generateMissingItem(const std::string &msgId);
void setAllMsgReadStatus(bool read);
// Callback for all Loads.
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
@ -98,9 +81,7 @@ private slots:
//void removemessage();
void markMsgAsRead();
void markMsgAsReadChildren();
void markMsgAsReadAll();
void markMsgAsUnread();
void markMsgAsUnreadAll();
void markMsgAsUnreadChildren();
void copyMessageLink();
@ -122,7 +103,8 @@ private slots:
void filterItems(const QString &text);
void fillThreadFinished();
// void fillThreadProgress(int current, int count);
void fillThreadProgress(int current, int count);
void fillThreadStatus(QString text);
private:
void insertForumThreads(const RsGroupMetaData &fi);
@ -141,6 +123,7 @@ private:
void markMsgAsReadUnread(bool read, bool children, bool forum);
void calculateIconsAndFonts(QTreeWidgetItem *item = NULL);
void calculateIconsAndFonts(QTreeWidgetItem *item, bool &hasReadChilddren, bool &hasUnreadChilddren);
void calculateUnreadCount();
void togglethreadview_internal();
@ -159,35 +142,19 @@ private:
int mLastViewType;
RSTreeWidgetItemCompareRole *mThreadCompareRole;
TokenQueue *mThreadQueue;
uint32_t mTokenGroupSummary;
uint32_t mTokenPost;
bool mRequestGroupSummary;
// QTimer *mTimer;
GxsForumsFillThread *mFillThread;
unsigned int mUnreadCount;
unsigned int mNewCount;
void requestGroupSummary_CurrentForum(const std::string &forumId);
void loadGroupSummary_CurrentForum(const uint32_t &token);
void loadCurrentForumThreads(const std::string &forumId);
void requestGroupThreadData_InsertThreads(const std::string &forumId);
void loadGroupThreadData_InsertThreads(const uint32_t &token);
void loadForumBaseThread(const RsGxsForumMsg &msg);
void requestChildData_InsertThreads(uint32_t &token, const RsGxsGrpMsgIdPair &parentId);
void loadChildData_InsertThreads(const uint32_t &token);
void loadForumChildMsg(const RsGxsForumMsg &msg, QTreeWidgetItem *parent);
void requestMsgData_InsertPost(const RsGxsGrpMsgIdPair &msgId);
void loadMsgData_InsertPost(const uint32_t &token);
void requestMsgData_ReplyMessage(const RsGxsGrpMsgIdPair &msgId);
void loadMsgData_ReplyMessage(const uint32_t &token);
bool convertMsgToThreadWidget(const RsGxsForumMsg &msgInfo, bool useChildTS, uint32_t filterColumn, GxsIdTreeWidgetItem *item);
// bool convertMsgToThreadWidget(const RsGxsForumMsg &msgInfo, std::string authorName, bool useChildTS, uint32_t filterColumn, QTreeWidgetItem *item);
// New Datatypes to replace the FillThread.
bool mThreadLoading;
GxsForumsThreadLoadParameters mThreadLoad;
/* Color definitions (for standard see qss.default) */
QColor mTextColorRead;
QColor mTextColorUnread;

View File

@ -193,12 +193,12 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="progressBarLayOut">
<layout class="QHBoxLayout" name="progressBarLayout">
<property name="leftMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="progLayOutTxt">
<widget class="QLabel" name="progressText">
<property name="font">
<font>
<pointsize>10</pointsize>

View File

@ -0,0 +1,260 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012, 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 <QApplication>
#include <QTreeWidgetItem>
#include "GxsForumsFillThread.h"
#include "GxsForumThreadWidget.h"
#include <retroshare/rsgxsforums.h>
#include <iostream>
#define DEBUG_FORUMS
GxsForumsFillThread::GxsForumsFillThread(GxsForumThreadWidget *parent)
: QThread(parent), mParent(parent)
{
mStopped = false;
mCompareRole = NULL;
mExpandNewMessages = true;
mFillComplete = false;
mFilterColumn = 0;
mSubscribeFlags = 0;
mViewType = 0;
mFlatView = false;
mUseChildTS = false;
}
GxsForumsFillThread::~GxsForumsFillThread()
{
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumsFillThread::~GxsForumsFillThread" << std::endl;
#endif
// remove all items (when items are available, the thread was terminated)
QList<QTreeWidgetItem *>::iterator item;
for (item = mItems.begin (); item != mItems.end (); item++) {
if (*item) {
delete (*item);
}
}
mItems.clear();
mItemToExpand.clear();
}
void GxsForumsFillThread::stop()
{
disconnect();
mStopped = true;
QApplication::processEvents();
wait();
}
void GxsForumsFillThread::run()
{
RsTokenService *service = rsGxsForums->getTokenService();
emit status(tr("Waiting"));
/* get all messages of the forum */
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
std::list<std::string> grpIds;
grpIds.push_back(mForumId);
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumsFillThread::run() forum id " << mForumId << std::endl;
#endif
uint32_t token;
service->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grpIds);
/* wait for the answer */
uint32_t requestStatus;
while (!wasStopped()) {
requestStatus = service->requestStatus(token);
if (requestStatus == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED ||
requestStatus == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE) {
break;
}
msleep(100);
}
if (wasStopped()) {
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumsFillThread::run() thread stopped, cancel request" << std::endl;
#endif
/* cancel request */
service->cancelRequest(token);
return;
}
if (requestStatus == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED) {
//#TODO
return;
}
//#TODO
// if (failed) {
// mService->cancelRequest(token);
// return;
// }
emit status(tr("Retrieving"));
/* get messages */
std::vector<RsGxsForumMsg> msgs;
if (!rsGxsForums->getMsgData(token, msgs)) {
return;
}
emit status(tr("Loading"));
int count = msgs.size();
int pos = 0;
QList<QPair<std::string, QTreeWidgetItem*> > threadList;
QPair<std::string, QTreeWidgetItem*> threadPair;
/* add all threads */
std::vector<RsGxsForumMsg>::iterator msgIt;
for (msgIt = msgs.begin(); msgIt != msgs.end(); ) {
if (wasStopped()) {
break;
}
const RsGxsForumMsg &msg = *msgIt;
if (!msg.mMeta.mParentId.empty()) {
++msgIt;
continue;
}
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumsFillThread::run() Adding TopLevel Thread: mId: " << msg.mMeta.mMsgId << std::endl;
#endif
QTreeWidgetItem *item = mParent->convertMsgToThreadWidget(msg, mUseChildTS, mFilterColumn);
threadList.push_back(QPair<std::string, QTreeWidgetItem*>(msg.mMeta.mMsgId, item));
mItems.append(item);
emit progress(++pos, count);
msgIt = msgs.erase(msgIt);
}
/* process messages */
while (msgs.size()) {
while (threadList.size() > 0) {
if (wasStopped()) {
break;
}
threadPair = threadList.front();
threadList.pop_front();
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumsFillThread::run() Getting Children of : " << threadPair.first << std::endl;
#endif
/* iterate through child */
for (msgIt = msgs.begin(); msgIt != msgs.end(); ) {
const RsGxsForumMsg &msg = *msgIt;
if (msg.mMeta.mParentId != threadPair.first) {
++msgIt;
continue;
}
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumsFillThread::run() adding " << msg.mMeta.mMsgId << std::endl;
#endif
QTreeWidgetItem *item = mParent->convertMsgToThreadWidget(msg, mUseChildTS, mFilterColumn);
if (mFlatView) {
mItems.append(item);
} else {
threadPair.second->addChild(item);
}
/* add item to process list */
threadList.push_back(QPair<std::string, QTreeWidgetItem*>(msg.mMeta.mMsgId, item));
emit progress(++pos, count);
msgIt = msgs.erase(msgIt);
}
}
if (wasStopped()) {
break;
}
/* process missing messages */
/* search for a message with missing parent */
for (msgIt = msgs.begin(); msgIt != msgs.end(); ++msgIt) {
const RsGxsForumMsg &msg = *msgIt;
/* search for parent */
std::vector<RsGxsForumMsg>::iterator msgIt1;
for (msgIt1 = msgs.begin(); msgIt1 != msgs.end(); ++msgIt1) {
if (wasStopped()) {
break;
}
const RsGxsForumMsg &msg1 = *msgIt1;
if (msg.mMeta.mParentId == msg1.mMeta.mMsgId) {
/* found parent */
break;
}
}
if (wasStopped()) {
break;
}
if (msgIt1 != msgs.end()) {
/* parant found */
continue;
}
/* add dummy item */
QTreeWidgetItem *item = mParent->generateMissingItem(msg.mMeta.mParentId);
threadList.push_back(QPair<std::string, QTreeWidgetItem*>(msg.mMeta.mParentId, item));
mItems.append(item);
break;
}
}
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumsFillThread::run() stopped: " << (wasStopped() ? "yes" : "no") << std::endl;
#endif
}

View File

@ -0,0 +1,46 @@
#ifndef GXSFORUMSFILLTHREAD_H
#define GXSFORUMSFILLTHREAD_H
#include <QThread>
class GxsForumThreadWidget;
class RSTreeWidgetItemCompareRole;
class QTreeWidgetItem;
class GxsForumsFillThread : public QThread
{
Q_OBJECT
public:
GxsForumsFillThread(GxsForumThreadWidget *parent);
~GxsForumsFillThread();
void run();
void stop();
bool wasStopped() { return mStopped; }
signals:
void progress(int current, int count);
void status(QString text);
public:
std::string mForumId;
int mFilterColumn;
int mSubscribeFlags;
bool mFillComplete;
int mViewType;
bool mFlatView;
bool mUseChildTS;
bool mExpandNewMessages;
std::string mFocusMsgId;
RSTreeWidgetItemCompareRole *mCompareRole;
QList<QTreeWidgetItem*> mItems;
QList<QTreeWidgetItem*> mItemToExpand;
private:
GxsForumThreadWidget *mParent;
volatile bool mStopped;
};
#endif // GXSFORUMSFILLTHREAD_H