- 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

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