diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 1f585fd94..a10de0fef 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -68,6 +68,7 @@ class RsPostedVote; typedef std::map > PostedPostResult; typedef std::map > PostedCommentResult; typedef std::map > PostedVoteResult; +typedef std::map > PostedRelatedCommentResult; typedef std::pair 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 &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; }; diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 350a559bc..d34e8f5ea 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -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(token, comments); +} + bool p3Posted::getGroupRank(const uint32_t &token, GroupRank &grpRank) { diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index 18be77e7b..78e6c9ea5 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -29,6 +29,7 @@ public: bool getGroup(const uint32_t &token, std::vector &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); diff --git a/retroshare-gui/src/gui/Posted/PostedComments.cpp b/retroshare-gui/src/gui/Posted/PostedComments.cpp index 12558668d..04c07e467 100644 --- a/retroshare-gui/src/gui/Posted/PostedComments.cpp +++ b/retroshare-gui/src/gui/Posted/PostedComments.cpp @@ -22,6 +22,7 @@ */ #include "PostedComments.h" +#include "PostedCreateCommentDialog.h" #include @@ -30,10 +31,8 @@ #include #include +#include -/****** - * #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("" + + QString::fromStdString(mCurrentPost.mMeta.mMsgName) + ""); + ui.siteLabel->setText("" + + QString::fromStdString(mCurrentPost.mLink) + ""); + + ui.scoreLabel->setText(QString("1")); + +} + diff --git a/retroshare-gui/src/gui/Posted/PostedComments.h b/retroshare-gui/src/gui/Posted/PostedComments.h index 5458fafc0..5bf557364 100644 --- a/retroshare-gui/src/gui/Posted/PostedComments.h +++ b/retroshare-gui/src/gui/Posted/PostedComments.h @@ -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; diff --git a/retroshare-gui/src/gui/Posted/PostedComments.ui b/retroshare-gui/src/gui/Posted/PostedComments.ui index 8347d0c5b..d06b8d0c1 100644 --- a/retroshare-gui/src/gui/Posted/PostedComments.ui +++ b/retroshare-gui/src/gui/Posted/PostedComments.ui @@ -344,6 +344,43 @@ border-radius: 10px} + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Make Comment + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.cpp b/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.cpp index e9a020f14..e5eaa27c6 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.cpp @@ -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() diff --git a/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.h b/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.h index 22ff82598..8edae3e1a 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.h +++ b/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.h @@ -2,6 +2,8 @@ #define POSTEDCREATECOMMENTDIALOG_H #include +#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 diff --git a/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.ui b/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.ui index c35128f27..ddecc9214 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.ui +++ b/retroshare-gui/src/gui/Posted/PostedCreateCommentDialog.ui @@ -1,38 +1,49 @@ + - - - PostedCreateCommentDialog 0 0 - 400 - 300 + 372 + 145 - Dialog + Make Comment - - - - 30 - 240 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">Comment</span></p></body></html> + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + - diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.cpp b/retroshare-gui/src/gui/Posted/PostedDialog.cpp index 283969441..ba0c55432 100644 --- a/retroshare-gui/src/gui/Posted/PostedDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedDialog.cpp @@ -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); } diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.h b/retroshare-gui/src/gui/Posted/PostedDialog.h index 82210b913..4b491770d 100644 --- a/retroshare-gui/src/gui/Posted/PostedDialog.h +++ b/retroshare-gui/src/gui/Posted/PostedDialog.h @@ -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: diff --git a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp index 6004975c7..080447989 100644 --- a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp @@ -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) diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index 3bfaceda3..449f54fc5 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -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); } diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 1c066f74d..6ed65ac9e 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -35,7 +35,7 @@ class PostedHolder { public: - virtual void showComments(const RsGxsMessageId& threadId) = 0; + virtual void showComments(const RsPostedPost& post) = 0; }; diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.cpp b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp index da542da71..059c356e6 100644 --- a/retroshare-gui/src/gui/Posted/PostedListDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp @@ -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; diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.h b/retroshare-gui/src/gui/Posted/PostedListDialog.h index d4dc5f9f0..0f61aefc1 100644 --- a/retroshare-gui/src/gui/Posted/PostedListDialog.h +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.h @@ -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: diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index ccd35b887..4f32e04e0 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -21,14 +21,16 @@ #include #include +#include #include "gui/gxs/GxsCommentTreeWidget.h" +#include "gui/Posted/PostedCreateCommentDialog.h" #include -#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 msgIds; + std::vector 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& commentV = commentResult[mThreadId]; + std::vector::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 items ) const -{ - /* extract from each QTreeWidgetItem... all the member text */ - QList::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 diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h index 87859d8ba..448c2e324 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h @@ -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 mLoadingMap; - std::multimap mPendingInsertMap; + /* Data */ + RsGxsGrpMsgIdPair mThreadId; + RsGxsMessageId mCurrentMsgId; - TokenQueue *mTokenQueue; - RsTokenService *mRsService; + std::map mLoadingMap; + std::multimap mPendingInsertMap; - protected: -//virtual QMimeData * mimeData ( const QList items ) const; -//virtual QStringList mimeTypes () const; -//virtual Qt::DropActions supportedDropActions () const; + TokenQueue *mTokenQueue; + RsTokenService *mRsService; };