Added posted comment creation

contextMnurequested does not seem to be working....may have to use an old fashioned non-derived treewidget.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5894 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-11-25 21:50:45 +00:00
parent 744a78b140
commit 8cef4da896
18 changed files with 357 additions and 202 deletions

View File

@ -68,6 +68,7 @@ class RsPostedVote;
typedef std::map<RsGxsGroupId, std::vector<RsPostedPost> > PostedPostResult;
typedef std::map<RsGxsGroupId, std::vector<RsPostedComment> > PostedCommentResult;
typedef std::map<RsGxsGroupId, std::vector<RsPostedVote> > PostedVoteResult;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedComment> > PostedRelatedCommentResult;
typedef std::pair<RsGxsGroupId, int32_t> GroupRank;
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
@ -93,6 +94,7 @@ virtual ~RsPosted() { return; }
virtual bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group) = 0;
virtual bool getPost(const uint32_t &token, PostedPostResult &post) = 0;
virtual bool getComment(const uint32_t &token, PostedCommentResult &comment) = 0;
virtual bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult& comments) = 0;
virtual bool getGroupRank(const uint32_t &token, GroupRank& grpRank) = 0;
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
@ -132,6 +134,7 @@ class RsPostedVote
RsMsgMetaData mMeta;
};
class RsGxsPostedCommentItem;
class RsPostedComment
{
@ -142,6 +145,7 @@ class RsPostedComment
return;
}
RsPostedComment(const RsGxsPostedCommentItem& );
std::string mComment;
RsMsgMetaData mMeta;
};

View File

@ -7,6 +7,12 @@ const uint32_t RsPosted::FLAG_MSGTYPE_VOTE = 0x0004;
RsPosted *rsPosted = NULL;
RsPostedComment::RsPostedComment(const RsGxsPostedCommentItem & item)
{
mComment = item.mComment.mComment;
mMeta = item.meta;
}
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV1_TYPE_POSTED), RsPosted(this)
{
@ -118,6 +124,11 @@ bool p3Posted::getComment(const uint32_t &token, PostedCommentResult &comments)
return ok;
}
bool p3Posted::getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments)
{
return RsGenExchange::getMsgRelatedDataT<RsGxsPostedCommentItem, RsPostedComment>(token, comments);
}
bool p3Posted::getGroupRank(const uint32_t &token, GroupRank &grpRank)
{

View File

@ -29,6 +29,7 @@ public:
bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group);
bool getPost(const uint32_t &token, PostedPostResult& posts) ;
bool getComment(const uint32_t &token, PostedCommentResult& comments) ;
bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments);
bool getGroupRank(const uint32_t& token, GroupRank& grpRank);
bool submitGroup(uint32_t &token, RsPostedGroup &group);

View File

@ -22,6 +22,7 @@
*/
#include "PostedComments.h"
#include "PostedCreateCommentDialog.h"
#include <retroshare/rsposted.h>
@ -30,10 +31,8 @@
#include <QTimer>
#include <QMessageBox>
#include <QDateTime>
/******
* #define PHOTO_DEBUG 1
*****/
/****************************************************************
@ -64,15 +63,51 @@ PostedComments::PostedComments(QWidget *parent)
ui.setupUi(this);
ui.postFrame->setVisible(false);
ui.treeWidget->setup(rsPosted->getTokenService());
connect(ui.treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(test(QPoint)));
}
void PostedComments::test(QPoint p)
{
int x = p.x();
int y = p.y();
int c= x+y;
}
void PostedComments::loadComments(const RsGxsMessageId& threadId )
void PostedComments::loadComments(const RsPostedPost& post)
{
std::cerr << "PostedComments::loadComments(" << threadId << ")";
std::cerr << "PostedComments::loadComments(" << post.mMeta.mOrigMsgId << ")";
std::cerr << std::endl;
mCurrentPost = post;
setUpPostFrame();
RsGxsGrpMsgIdPair threadId;
threadId.first = post.mMeta.mOrigMsgId;
threadId.second = post.mMeta.mGroupId;
ui.treeWidget->requestComments(threadId);
}
void PostedComments::setUpPostFrame()
{
ui.postFrame->setVisible(true);
QDateTime qtime;
qtime.setTime_t(mCurrentPost.mMeta.mPublishTs);
QString timestamp = qtime.toString("dd.MMMM yyyy hh:mm");
ui.dateLabel->setText(timestamp);
ui.fromLabel->setText(QString::fromUtf8(mCurrentPost.mMeta.mAuthorId.c_str()));
ui.titleLabel->setText("<a href=" + QString::fromStdString(mCurrentPost.mLink) +
"><span style=\" text-decoration: underline; color:#0000ff;\">" +
QString::fromStdString(mCurrentPost.mMeta.mMsgName) + "</span></a>");
ui.siteLabel->setText("<a href=" + QString::fromStdString(mCurrentPost.mLink) +
"><span style=\" text-decoration: underline; color:#0000ff;\">" +
QString::fromStdString(mCurrentPost.mLink) + "</span></a>");
ui.scoreLabel->setText(QString("1"));
}

View File

@ -42,12 +42,17 @@ public:
public slots:
void loadComments(const RsGxsMessageId& );
void loadComments(const RsPostedPost& );
private slots:
void test(QPoint p);
private:
void loadRequest(const TokenQueue *queue, const TokenRequest &req) { return; }
void setUpPostFrame();
TokenQueue *mPhotoQueue;
RsPostedPost mCurrentPost;
/* UI - from Designer */
Ui::PostedComments ui;

View File

@ -344,6 +344,43 @@ border-radius: 10px}</string>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="makeCommentButton">
<property name="text">
<string>Make Comment</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>

View File

@ -1,11 +1,27 @@
#include "PostedCreateCommentDialog.h"
#include "ui_PostedCreateCommentDialog.h"
PostedCreateCommentDialog::PostedCreateCommentDialog(QWidget *parent) :
PostedCreateCommentDialog::PostedCreateCommentDialog(TokenQueue *tokQ, const RsGxsGrpMsgIdPair &parentId, const RsGxsMessageId& threadId, QWidget *parent) :
QDialog(parent),
ui(new Ui::PostedCreateCommentDialog)
ui(new Ui::PostedCreateCommentDialog), mTokenQueue(tokQ), mParentId(parentId), mThreadId(threadId)
{
ui->setupUi(this);
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(createComment()));
}
void PostedCreateCommentDialog::createComment()
{
RsPostedComment comment;
comment.mComment = ui->commentTextEdit->document()->toPlainText().toStdString();
comment.mMeta.mParentId = mParentId.second;
comment.mMeta.mGroupId = mParentId.first;
comment.mMeta.mThreadId = mThreadId;
uint32_t token;
rsPosted->submitComment(token, comment);
mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, 0);
close();
}
PostedCreateCommentDialog::~PostedCreateCommentDialog()

View File

@ -2,6 +2,8 @@
#define POSTEDCREATECOMMENTDIALOG_H
#include <QDialog>
#include "retroshare/rsposted.h"
#include "util/TokenQueue.h"
namespace Ui {
class PostedCreateCommentDialog;
@ -12,11 +14,18 @@ class PostedCreateCommentDialog : public QDialog
Q_OBJECT
public:
explicit PostedCreateCommentDialog(QWidget *parent = 0);
explicit PostedCreateCommentDialog(TokenQueue* tokQ, const RsGxsGrpMsgIdPair& parentId, const RsGxsMessageId& threadId, QWidget *parent = 0);
~PostedCreateCommentDialog();
private slots:
void createComment();
private:
Ui::PostedCreateCommentDialog *ui;
TokenQueue* mTokenQueue;
RsGxsGrpMsgIdPair mParentId;
RsGxsMessageId mThreadId;
};
#endif // POSTEDCREATECOMMENTDIALOG_H

View File

@ -1,38 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>PostedCreateCommentDialog</class>
<widget class="QDialog" name="PostedCreateCommentDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>372</width>
<height>145</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Make Comment</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-weight:600;&quot;&gt;Comment&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="commentTextEdit"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<pixmapfunction/>
<resources/>
<connections>
<connection>

View File

@ -49,7 +49,7 @@ PostedDialog::PostedDialog(QWidget *parent)
{
ui.setupUi(this);
mPostedList = new PostedListDialog(NULL);
mPostedList = new PostedListDialog(this, NULL);
mPostedComments = new PostedComments(NULL);
QString list("List");
@ -60,9 +60,10 @@ PostedDialog::PostedDialog(QWidget *parent)
connect(mPostedList, SIGNAL(loadComments( std::string ) ), mPostedComments, SLOT(loadComments( std::string ) ) );
}
void PostedDialog::commentLoad(const RsGxsMessageId &msgId)
void PostedDialog::commentLoad(const RsPostedPost &post)
{
mPostedComments->loadComments(msgId);
mPostedComments->loadComments(post);
ui.tabWidget->setCurrentWidget(mPostedComments);
}

View File

@ -39,7 +39,7 @@ public:
* This should be used for loading comments of a message on a main comment viewing page
* @param msgId the message id for which comments will be requested
*/
virtual void commentLoad(const RsGxsMessageId& msgId) = 0;
virtual void commentLoad(const RsPostedPost&) = 0;
};
class PostedListDialog;
@ -51,7 +51,7 @@ class PostedDialog : public MainPage, public CommentHolder
public:
PostedDialog(QWidget *parent = 0);
void commentLoad(const RsGxsMessageId &msgId);
void commentLoad(const RsPostedPost &);
private:

View File

@ -56,9 +56,10 @@ QString PostedGroupDialog::serviceHeader()
return tr("Create New Posted Topic");
}
QPixmap PostedGroupDialog::serviceImage()
{
return QPixmap(":/images/posted_add_64.png");
return QPixmap(":/images/posted_add_64.png");
}
bool PostedGroupDialog::service_CreateGroup(uint32_t &token, const RsGroupMetaData &meta)

View File

@ -38,7 +38,7 @@
/** Constructor */
PostedItem::PostedItem(PostedHolder *postHolder, const RsPostedPost &post)
:QWidget(NULL), mPostHolder(postHolder)
:QWidget(NULL), mPostHolder(postHolder), mPost(post)
{
setupUi(this);
setAttribute ( Qt::WA_DeleteOnClose, true );
@ -71,5 +71,5 @@ void PostedItem::loadComments()
{
std::cerr << "PostedItem::loadComments() Requesting for " << mThreadId;
std::cerr << std::endl;
mPostHolder->showComments(mPost.mMeta.mMsgId);
mPostHolder->showComments(mPost);
}

View File

@ -35,7 +35,7 @@ class PostedHolder
{
public:
virtual void showComments(const RsGxsMessageId& threadId) = 0;
virtual void showComments(const RsPostedPost& post) = 0;
};

View File

@ -106,9 +106,9 @@ void PostedListDialog::newPost()
cp.exec();
}
void PostedListDialog::showComments(const RsGxsMessageId &threadId)
void PostedListDialog::showComments(const RsPostedPost& post)
{
mCommentHolder->commentLoad(threadId);
mCommentHolder->commentLoad(post);
}
void PostedListDialog::updateDisplay()
@ -403,6 +403,7 @@ void PostedListDialog::loadRequest(const TokenQueue *queue, const TokenRequest &
break;
case RS_TOKREQ_ANSTYPE_SUMMARY:
loadGroupSummary(req.mToken);
break;
default:
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
break;

View File

@ -24,6 +24,7 @@
#ifndef MRK_POSTED_LIST_DIALOG_H
#define MRK_POSTED_LIST_DIALOG_H
#include "retroshare-gui/mainpage.h"
#include "ui_PostedListDialog.h"
@ -58,7 +59,7 @@ class PostedListDialog : public RsAutoUpdatePage, public PostedHolder, public To
public:
PostedListDialog(CommentHolder* commentHolder, QWidget *parent = 0);
void showComments(const RsGxsMessageId &threadId);
void showComments(const RsPostedPost& post);
private slots:

View File

@ -21,14 +21,16 @@
#include <QMimeData>
#include <QDateTime>
#include <QMenu>
#include "gui/gxs/GxsCommentTreeWidget.h"
#include "gui/Posted/PostedCreateCommentDialog.h"
#include <iostream>
#define PCITEM_COLUMN_DATE 0
#define PCITEM_COLUMN_COMMENT 1
#define PCITEM_COLUMN_AUTHOR 2
#define PCITEM_COLUMN_COMMENT 0
#define PCITEM_COLUMN_AUTHOR 1
#define PCITEM_COLUMN_DATE 2
#define PCITEM_COLUMN_SERVSTRING 3
#define PCITEM_COLUMN_MSGID 4
#define PCITEM_COLUMN_PARENTID 5
@ -38,54 +40,104 @@
// Temporarily make this specific.
#include "retroshare/rsposted.h"
/* Images for context menu icons */
#define IMAGE_MESSAGE ":/images/folder-draft.png"
GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent)
:QTreeWidget(parent), mRsService(NULL), mTokenQueue(NULL)
{
// QTreeWidget* widget = this;
// QFont font = QFont("ARIAL", 10);
// font.setBold(true);
// QString name("test");
// QTreeWidgetItem *item = new QTreeWidgetItem();
// item->setText(0, name);
// item->setFont(0, font);
// item->setSizeHint(0, QSize(18, 18));
// item->setForeground(0, QBrush(QColor(79, 79, 79)));
// addTopLevelItem(item);
// item->setExpanded(true);
return;
}
void GxsCommentTreeWidget::setCurrentMsgId(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous);
if(current)
{
mCurrentMsgId = current->text(PCITEM_COLUMN_MSGID).toStdString();
}else{
mCurrentMsgId = "";
}
}
void GxsCommentTreeWidget::customPopUpMenu(const QPoint& point)
{
QMenu contextMnu( this );
contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Comment"), this, SLOT(makeComment()));
contextMnu.exec(QCursor::pos());
}
void GxsCommentTreeWidget::makeComment()
{
if(mCurrentMsgId.empty())
{
PostedCreateCommentDialog pcc(mTokenQueue, mThreadId, mThreadId.second, this);
pcc.exec();
}
else
{
RsGxsGrpMsgIdPair msgId;
msgId.first = mThreadId.first;
msgId.second = mCurrentMsgId;
PostedCreateCommentDialog pcc(mTokenQueue, msgId, mThreadId.second, this);
pcc.exec();
}
}
void GxsCommentTreeWidget::setup(RsTokenService *service)
{
mRsService = service;
mTokenQueue = new TokenQueue(service, this);
mRsService = service;
mTokenQueue = new TokenQueue(service, this);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customPopUpMenu(QPoint)));
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(setCurrentMsgId(QTreeWidgetItem*, QTreeWidgetItem*)));
return;
return;
}
/* Load Comments */
void GxsCommentTreeWidget::requestComments(std::string threadId)
void GxsCommentTreeWidget::requestComments(const RsGxsGrpMsgIdPair& threadId)
{
/* request comments */
/* request comments */
service_requestComments(threadId);
mThreadId = threadId;
service_requestComments(threadId);
}
void GxsCommentTreeWidget::service_requestComments(std::string threadId)
void GxsCommentTreeWidget::service_requestComments(const RsGxsGrpMsgIdPair& threadId)
{
/* request comments */
//std::cerr << "GxsCommentTreeWidget::service_requestComments() ERROR must be overloaded!";
//std::cerr << std::endl;
std::cerr << "GxsCommentTreeWidget::service_requestComments(" << threadId << ")";
std::cerr << "GxsCommentTreeWidget::service_requestComments(" << threadId.second << ")";
std::cerr << std::endl;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST;
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST;
// opts.mFlagsFilter = RSPOSTED_MSGTYPE_COMMENT;
// opts.mFlagsMask = RSPOSTED_MSGTYPE_COMMENT;
std::list<std::string> msgIds;
std::vector<RsGxsGrpMsgIdPair> msgIds;
msgIds.push_back(threadId);
mThreadId = threadId;
uint32_t token;
// mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, GXSCOMMENTS_LOADTHREAD);
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, GXSCOMMENTS_LOADTHREAD);
}
@ -138,7 +190,7 @@ void GxsCommentTreeWidget::completeItems()
parent->addChild(pit->second);
}
else if (parentId == mThreadId)
else if (parentId == mThreadId.second)
{
std::cerr << "GxsCommentTreeWidget::completeItems() Added to topLevelItems";
std::cerr << std::endl;
@ -206,64 +258,75 @@ void GxsCommentTreeWidget::loadThread(const uint32_t &token)
completeItems();
}
void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token)
{
RsGxsGrpMsgIdPair msgId;
rsPosted->acknowledgeMsg(token, msgId);
// simply reload data
service_requestComments(mThreadId);
}
void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
{
std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!";
std::cerr << std::endl;
std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!";
std::cerr << std::endl;
// RsPostedComment comment;
// while(rsPosted->getComment(token, comment))
// {
// /* convert to a QTreeWidgetItem */
// std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment;
// std::cerr << std::endl;
// QTreeWidgetItem *item = new QTreeWidgetItem();
// QString text;
PostedRelatedCommentResult commentResult;
rsPosted->getRelatedComment(token, commentResult);
// {
// QDateTime qtime;
// qtime.setTime_t(comment.mMeta.mPublishTs);
// text = qtime.toString("yyyy-MM-dd hh:mm:ss");
// item->setText(PCITEM_COLUMN_DATE, text);
// }
// text = QString::fromUtf8(comment.mComment.c_str());
// item->setText(PCITEM_COLUMN_COMMENT, text);
// text = QString::fromUtf8(comment.mMeta.mAuthorId.c_str());
// if (text.isEmpty())
// {
// item->setText(PCITEM_COLUMN_AUTHOR, tr("Anonymous"));
// }
// else
// {
// item->setText(PCITEM_COLUMN_AUTHOR, text);
// }
std::vector<RsPostedComment>& commentV = commentResult[mThreadId];
std::vector<RsPostedComment>::iterator vit = commentV.begin();
for(; vit != commentV.end(); vit++)
{
RsPostedComment& comment = *vit;
/* convert to a QTreeWidgetItem */
std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId;
std::cerr << std::endl;
// text = QString::fromUtf8(comment.mMeta.mMsgId.c_str());
// item->setText(PCITEM_COLUMN_MSGID, text);
QTreeWidgetItem *item = new QTreeWidgetItem();
QString text;
// text = QString::fromUtf8(comment.mMeta.mParentId.c_str());
// item->setText(PCITEM_COLUMN_PARENTID, text);
{
QDateTime qtime;
qtime.setTime_t(comment.mMeta.mPublishTs);
// text = QString::fromUtf8(comment.mMeta.mServiceString.c_str());
// item->setText(PCITEM_COLUMN_SERVSTRING, text);
text = qtime.toString("yyyy-MM-dd hh:mm:ss");
item->setText(PCITEM_COLUMN_DATE, text);
}
// addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item);
// }
text = QString::fromUtf8(comment.mComment.c_str());
item->setText(PCITEM_COLUMN_COMMENT, text);
text = QString::fromUtf8(comment.mMeta.mAuthorId.c_str());
if (text.isEmpty())
{
item->setText(PCITEM_COLUMN_AUTHOR, tr("Anonymous"));
}
else
{
item->setText(PCITEM_COLUMN_AUTHOR, text);
}
text = QString::fromUtf8(comment.mMeta.mMsgId.c_str());
item->setText(PCITEM_COLUMN_MSGID, text);
text = QString::fromUtf8(comment.mMeta.mParentId.c_str());
item->setText(PCITEM_COLUMN_PARENTID, text);
text = QString::fromUtf8(comment.mMeta.mServiceString.c_str());
item->setText(PCITEM_COLUMN_SERVSTRING, text);
addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item);
}
return;
}
QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(std::string parent)
QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent)
{
//std::cerr << "GxsCommentTreeWidget::service_createMissingItem() ERROR must be overloaded!";
//std::cerr << std::endl;
std::cerr << "GxsCommentTreeWidget::service_createMissingItem()";
std::cerr << std::endl;
@ -280,13 +343,14 @@ QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(std::string par
item->setText(PCITEM_COLUMN_SERVSTRING, text);
text = QString::fromUtf8(parent.c_str());
text = QString::fromUtf8(parent.c_str());
item->setText(PCITEM_COLUMN_PARENTID, text);
return item;
}
void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
std::cerr << "GxsCommentTreeWidget::loadRequest() UserType: " << req.mUserType;
@ -300,74 +364,26 @@ void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenReque
}
/* now switch on req */
switch(req.mUserType)
switch(req.mType)
{
case GXSCOMMENTS_LOADTHREAD:
loadThread(req.mToken);
break;
default:
std::cerr << "GxsCommentTreeWidget::loadRequest() UNKNOWN UserType ";
std::cerr << std::endl;
break;
case TOKENREQ_MSGINFO:
{
switch(req.mAnsType)
{
case RS_TOKREQ_ANSTYPE_ACK:
acknowledgeComment(req.mToken);
break;
case RS_TOKREQ_ANSTYPE_DATA:
loadThread(req.mToken);
break;
}
}
break;
default:
std::cerr << "GxsCommentTreeWidget::loadRequest() UNKNOWN UserType ";
std::cerr << std::endl;
break;
}
}
#if 0
QMimeData * GxsCommentTreeWidget::mimeData ( const QList<QTreeWidgetItem *> items ) const
{
/* extract from each QTreeWidgetItem... all the member text */
QList<QTreeWidgetItem *>::const_iterator it;
QString text;
for(it = items.begin(); it != items.end(); it++)
{
QString line = QString("%1/%2/%3/").arg((*it)->text(SR_NAME_COL), (*it)->text(SR_HASH_COL), (*it)->text(SR_SIZE_COL));
bool isLocal = (*it)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool();
if (isLocal)
{
line += "Local";
}
else
{
line += "Remote";
}
line += "/\n";
text += line;
}
std::cerr << "Created MimeData:";
std::cerr << std::endl;
std::string str = text.toUtf8().constData();
std::cerr << str;
std::cerr << std::endl;
QMimeData *data = new QMimeData();
data->setData("application/x-rsfilelist", QByteArray(str.c_str()));
return data;
}
QStringList GxsCommentTreeWidget::mimeTypes () const
{
QStringList list;
list.push_back("application/x-rsfilelist");
return list;
}
Qt::DropActions GxsCommentTreeWidget::supportedDropActions () const
{
return Qt::CopyAction;
}
#endif

View File

@ -44,42 +44,48 @@ class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse
Q_OBJECT
public:
GxsCommentTreeWidget(QWidget *parent = 0);
void setup(RsTokenService *service);
GxsCommentTreeWidget(QWidget *parent = 0);
void setup(RsTokenService *service);
void requestComments(std::string threadId);
void requestComments(const RsGxsGrpMsgIdPair& threadId);
void getCurrentMsgId(RsGxsMessageId& parentId);
void setCurrentMsgId(QTreeWidgetItem* current, QTreeWidgetItem* previous);
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
protected:
/* to be overloaded */
virtual void service_requestComments(std::string threadId);
virtual void service_loadThread(const uint32_t &token);
virtual QTreeWidgetItem *service_createMissingItem(std::string parent);
/* to be overloaded */
virtual void service_requestComments(const RsGxsGrpMsgIdPair& threadId);
virtual void service_loadThread(const uint32_t &token);
virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent);
void clearItems();
void completeItems();
void clearItems();
void completeItems();
void loadThread(const uint32_t &token);
void addItem(std::string itemId, std::string parentId, QTreeWidgetItem *item);
void acknowledgeComment(const uint32_t& token);
void loadThread(const uint32_t &token);
void addItem(std::string itemId, std::string parentId, QTreeWidgetItem *item);
public slots:
void customPopUpMenu(const QPoint& point);
private slots:
void makeComment();
/* Data */
std::string mThreadId;
protected:
std::map<std::string, QTreeWidgetItem *> mLoadingMap;
std::multimap<std::string, QTreeWidgetItem *> mPendingInsertMap;
/* Data */
RsGxsGrpMsgIdPair mThreadId;
RsGxsMessageId mCurrentMsgId;
TokenQueue *mTokenQueue;
RsTokenService *mRsService;
std::map<std::string, QTreeWidgetItem *> mLoadingMap;
std::multimap<std::string, QTreeWidgetItem *> mPendingInsertMap;
protected:
//virtual QMimeData * mimeData ( const QList<QTreeWidgetItem *> items ) const;
//virtual QStringList mimeTypes () const;
//virtual Qt::DropActions supportedDropActions () const;
TokenQueue *mTokenQueue;
RsTokenService *mRsService;
};