Major improvements to Comments GUI for channels and posted.

- Split GxsIdWidgetTreeItem into two types.
 - Added Voter Id into Comment Dialog.
 - Expanded Comment display to show Votes and Score.
 - Expanded Comment Context Menu to include Voting and Reputation Options.
 - Fixed up CreateComment Dialog to include AuthorId, and enabled.
 - Completed Basic Comment Voting.
 - Made Comment Windows Closable.
 - Cleanup up Channel Posts before loading new ones.
 - Fixed up Channel Post Attachments, and Thumbnails.
 - Added View Comments button to Channel Posts
 - Misc other Bugs.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6219 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2013-03-13 00:33:14 +00:00
parent b9f2708927
commit 5ba4c8f7ff
19 changed files with 829 additions and 389 deletions

View file

@ -44,6 +44,9 @@ GxsCommentContainer::GxsCommentContainer(QWidget *parent)
: MainPage(parent)
{
ui.setupUi(this);
connect(ui.tabWidget, SIGNAL(tabCloseRequested( int )), this, SLOT(tabCloseRequested( int )));
}
@ -74,6 +77,20 @@ void GxsCommentContainer::commentLoad(const RsGxsGroupId &grpId, const RsGxsMess
void GxsCommentContainer::tabCloseRequested(int index)
{
std::cerr << "GxsCommentContainer::tabCloseRequested(" << index << ")";
if (index != 0)
{
QWidget *comments = ui.tabWidget->widget(index);
ui.tabWidget->removeTab(index);
delete comments;
}
std::cerr << "GxsCommentContainer::tabCloseRequested() Not closing First Tab";
}

View file

@ -62,6 +62,9 @@ public:
virtual RsGxsCommentService *getCommentService() = 0;
virtual GxsCommentHeader *createHeaderWidget() = 0;
private slots:
void tabCloseRequested(int index);
private:
GxsServiceDialog *mServiceDialog;

View file

@ -77,6 +77,9 @@
<property name="currentIndex">
<number>-1</number>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>

View file

@ -40,50 +40,89 @@
GxsCommentDialog::GxsCommentDialog(QWidget *parent, RsTokenService *token_service, RsGxsCommentService *comment_service)
:QWidget(parent)
{
ui.setupUi(this);
//ui.postFrame->setVisible(false);
ui.setupUi(this);
//ui.postFrame->setVisible(false);
ui.treeWidget->setup(token_service, comment_service);
ui.treeWidget->setup(token_service, comment_service);
/* fill in the available OwnIds for signing */
ui.idChooser->loadIds(IDCHOOSER_ID_REQUIRED, "");
connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));
connect(ui.idChooser, SIGNAL(currentIndexChanged( int )), this, SLOT(voterSelectionChanged( int )));
/* force voterId through - first time */
voterSelectionChanged( 0 );
}
void GxsCommentDialog::commentLoad(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId)
{
std::cerr << "GxsCommentDialog::commentLoad(" << grpId << ", " << msgId << ")";
std::cerr << "GxsCommentDialog::commentLoad(" << grpId << ", " << msgId << ")";
std::cerr << std::endl;
mGrpId = grpId;
mMsgId = msgId;
RsGxsGrpMsgIdPair threadId;
RsGxsGrpMsgIdPair threadId;
threadId.first = grpId;
threadId.second = msgId;
threadId.first = grpId;
threadId.second = msgId;
ui.treeWidget->requestComments(threadId);
}
void GxsCommentDialog::refresh()
{
std::cerr << "GxsCommentDialog::refresh()";
std::cerr << std::endl;
commentLoad(mGrpId, mMsgId);
}
void GxsCommentDialog::voterSelectionChanged( int index )
{
std::cerr << "GxsCommentDialog::voterSelectionChanged(" << index << ")";
std::cerr << std::endl;
RsGxsId voterId;
if (ui.idChooser->getChosenId(voterId))
{
std::cerr << "GxsCommentDialog::voterSelectionChanged() => " << voterId;
std::cerr << std::endl;
ui.treeWidget->setVoteId(voterId);
}
else
{
std::cerr << "GxsCommentDialog::voterSelectionChanged() ERROR nothing selected";
std::cerr << std::endl;
}
}
void GxsCommentDialog::setCommentHeader(GxsCommentHeader *header)
{
#if 0
ui.postFrame->setVisible(true);
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>");
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("0"));
ui.scoreLabel->setText(QString("0"));
ui.notesBrowser->setPlainText(QString::fromStdString(mCurrentPost.mNotes));
ui.notesBrowser->setPlainText(QString::fromStdString(mCurrentPost.mNotes));
#endif
}

View file

@ -38,6 +38,10 @@ public:
void setCommentHeader(GxsCommentHeader *header);
void commentLoad(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId);
private slots:
void refresh();
void voterSelectionChanged( int index );
private:
RsGxsGroupId mGrpId;

View file

@ -241,13 +241,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="notesBrowser">
<property name="styleSheet">
<string notr="true">background-color: rgb(203, 203, 203);</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -321,7 +314,17 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Voter ID:</string>
</property>
</widget>
</item>
<item>
<widget class="GxsIdChooser" name="idChooser"/>
</item>
<item>
<widget class="QPushButton" name="refreshButton">
<property name="text">
<string>Refresh</string>
</property>
@ -348,7 +351,17 @@
</column>
<column>
<property name="text">
<string>Points</string>
<string>Score</string>
</property>
</column>
<column>
<property name="text">
<string>UpVotes</string>
</property>
</column>
<column>
<property name="text">
<string>DownVotes</string>
</property>
</column>
</widget>
@ -356,6 +369,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GxsIdChooser</class>
<extends>QComboBox</extends>
<header>gui/gxs/GxsIdChooser.h</header>
</customwidget>
<customwidget>
<class>GxsCommentTreeWidget</class>
<extends>QTreeWidget</extends>

View file

@ -25,197 +25,305 @@
#include "gui/gxs/GxsCommentTreeWidget.h"
#include "gui/gxs/GxsCreateCommentDialog.h"
#include "gui/gxs/GxsIdTreeWidgetItem.h"
#include <iostream>
#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
#define PCITEM_COLUMN_SCORE 3
#define PCITEM_COLUMN_UPVOTES 4
#define PCITEM_COLUMN_DOWNVOTES 5
#define PCITEM_COLUMN_MSGID 6
#define PCITEM_COLUMN_PARENTID 7
#define GXSCOMMENTS_LOADTHREAD 1
/* Images for context menu icons */
#define IMAGE_MESSAGE ":/images/folder-draft.png"
#define IMAGE_MESSAGE ":/images/folder-draft.png"
GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent)
:QTreeWidget(parent), mRsTokenService(NULL), mCommentService(NULL), mTokenQueue(NULL)
:QTreeWidget(parent), mRsTokenService(NULL), mCommentService(NULL), mTokenQueue(NULL)
{
// QTreeWidget* widget = this;
// QTreeWidget* widget = this;
setContextMenuPolicy(Qt::CustomContextMenu);
// QFont font = QFont("ARIAL", 10);
// font.setBold(true);
setContextMenuPolicy(Qt::CustomContextMenu);
// 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)));
// 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);
// addTopLevelItem(item);
// item->setExpanded(true);
return;
return;
}
void GxsCommentTreeWidget::setCurrentMsgId(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous);
Q_UNUSED(previous);
if(current)
{
mCurrentMsgId = current->text(PCITEM_COLUMN_MSGID).toStdString();
}
if(current)
{
mCurrentMsgId = current->text(PCITEM_COLUMN_MSGID).toStdString();
}
}
void GxsCommentTreeWidget::customPopUpMenu(const QPoint& point)
{
QMenu contextMnu( this );
QAction* action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Reply to Comment"), this, SLOT(replyToComment()));
action->setDisabled(mCurrentMsgId.empty());
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Comment"), this, SLOT(makeComment()));
action->setDisabled(mThreadId.first.empty());
contextMnu.exec(QCursor::pos());
QMenu contextMnu( this );
QAction* action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Reply to Comment"), this, SLOT(replyToComment()));
action->setDisabled(mCurrentMsgId.empty());
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Comment"), this, SLOT(makeComment()));
action->setDisabled(mThreadId.first.empty());
contextMnu.addSeparator();
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Vote Up"), this, SLOT(voteUp()));
action->setDisabled(mVoterId.empty());
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Vote Down"), this, SLOT(voteDown()));
action->setDisabled(mVoterId.empty());
if (!mCurrentMsgId.empty())
{
contextMnu.addSeparator();
QMenu *rep_menu = contextMnu.addMenu(tr("Reputation"));
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Show Reputation"), this, SLOT(showReputation()));
contextMnu.addSeparator();
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Interesting User"), this, SLOT(markInteresting()));
contextMnu.addSeparator();
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Mark Spammy"), this, SLOT(markSpammer()));
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Ban User"), this, SLOT(banUser()));
}
contextMnu.exec(QCursor::pos());
}
void GxsCommentTreeWidget::voteUp()
{
std::cerr << "GxsCommentTreeWidget::voteUp()";
std::cerr << std::endl;
vote(mThreadId.first, mThreadId.second, mCurrentMsgId, mVoterId, true);
}
void GxsCommentTreeWidget::voteDown()
{
std::cerr << "GxsCommentTreeWidget::voteDown()";
std::cerr << std::endl;
vote(mThreadId.first, mThreadId.second, mCurrentMsgId, mVoterId, false);
}
void GxsCommentTreeWidget::setVoteId(const RsGxsId &voterId)
{
mVoterId = voterId;
std::cerr << "GxsCommentTreeWidget::setVoterId(" << mVoterId << ")";
std::cerr << std::endl;
}
void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageId &threadId,
const RsGxsMessageId &parentId, const RsGxsId &authorId, bool up)
{
RsGxsVote vote;
vote.mMeta.mGroupId = groupId;
vote.mMeta.mThreadId = threadId;
vote.mMeta.mParentId = parentId;
vote.mMeta.mAuthorId = authorId;
if (up)
{
vote.mVoteType = GXS_VOTE_UP;
}
else
{
vote.mVoteType = GXS_VOTE_DOWN;
}
std::cerr << "GxsCommentTreeWidget::vote()";
std::cerr << std::endl;
std::cerr << "GroupId : " << vote.mMeta.mGroupId << std::endl;
std::cerr << "ThreadId : " << vote.mMeta.mThreadId << std::endl;
std::cerr << "ParentId : " << vote.mMeta.mParentId << std::endl;
std::cerr << "AuthorId : " << vote.mMeta.mAuthorId << std::endl;
uint32_t token;
mCommentService->createVote(token, vote);
mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, 0);
}
void GxsCommentTreeWidget::showReputation()
{
std::cerr << "GxsCommentTreeWidget::showReputation() TODO";
std::cerr << std::endl;
}
void GxsCommentTreeWidget::markInteresting()
{
std::cerr << "GxsCommentTreeWidget::markInteresting() TODO";
std::cerr << std::endl;
}
void GxsCommentTreeWidget::markSpammer()
{
std::cerr << "GxsCommentTreeWidget::markSpammer() TODO";
std::cerr << std::endl;
}
void GxsCommentTreeWidget::banUser()
{
std::cerr << "GxsCommentTreeWidget::banUser() TODO";
std::cerr << std::endl;
}
void GxsCommentTreeWidget::makeComment()
{
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, mThreadId, mThreadId.second, this);
pcc.exec();
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, mThreadId, mThreadId.second, this);
pcc.exec();
}
void GxsCommentTreeWidget::replyToComment()
{
RsGxsGrpMsgIdPair msgId;
msgId.first = mThreadId.first;
msgId.second = mCurrentMsgId;
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, msgId, mThreadId.second, this);
pcc.exec();
RsGxsGrpMsgIdPair msgId;
msgId.first = mThreadId.first;
msgId.second = mCurrentMsgId;
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, msgId, mThreadId.second, this);
pcc.exec();
}
void GxsCommentTreeWidget::setup(RsTokenService *token_service, RsGxsCommentService *comment_service)
{
mRsTokenService = token_service;
mCommentService = comment_service;
mTokenQueue = new TokenQueue(token_service, this);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customPopUpMenu(QPoint)));
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(setCurrentMsgId(QTreeWidgetItem*, QTreeWidgetItem*)));
mRsTokenService = token_service;
mCommentService = comment_service;
mTokenQueue = new TokenQueue(token_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(const RsGxsGrpMsgIdPair& threadId)
{
/* request comments */
/* request comments */
mThreadId = threadId;
service_requestComments(threadId);
mThreadId = threadId;
service_requestComments(threadId);
}
void GxsCommentTreeWidget::service_requestComments(const RsGxsGrpMsgIdPair& threadId)
{
/* request comments */
std::cerr << "GxsCommentTreeWidget::service_requestComments(" << threadId.second << ")";
std::cerr << std::endl;
/* request comments */
std::cerr << "GxsCommentTreeWidget::service_requestComments(" << threadId.second << ")";
std::cerr << std::endl;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST;
std::vector<RsGxsGrpMsgIdPair> msgIds;
msgIds.push_back(threadId);
std::vector<RsGxsGrpMsgIdPair> msgIds;
msgIds.push_back(threadId);
uint32_t token;
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, GXSCOMMENTS_LOADTHREAD);
uint32_t token;
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, GXSCOMMENTS_LOADTHREAD);
}
/* Generic Handling */
void GxsCommentTreeWidget::clearItems()
{
mPendingInsertMap.clear();
mLoadingMap.clear();
mPendingInsertMap.clear();
mLoadingMap.clear();
}
void GxsCommentTreeWidget::completeItems()
{
/* handle pending items */
std::string parentId;
QTreeWidgetItem *parent = NULL;
QList<QTreeWidgetItem *> topLevelItems;
/* handle pending items */
std::string parentId;
QTreeWidgetItem *parent = NULL;
QList<QTreeWidgetItem *> topLevelItems;
std::map<std::string, QTreeWidgetItem *>::iterator lit;
std::multimap<std::string, QTreeWidgetItem *>::iterator pit;
std::map<std::string, QTreeWidgetItem *>::iterator lit;
std::multimap<std::string, QTreeWidgetItem *>::iterator pit;
std::cerr << "GxsCommentTreeWidget::completeItems() " << mPendingInsertMap.size();
std::cerr << " PendingItems";
std::cerr << std::endl;
std::cerr << "GxsCommentTreeWidget::completeItems() " << mPendingInsertMap.size();
std::cerr << " PendingItems";
std::cerr << std::endl;
for(pit = mPendingInsertMap.begin(); pit != mPendingInsertMap.end(); pit++)
{
std::cerr << "GxsCommentTreeWidget::completeItems() item->parent: " << pit->first;
std::cerr << std::endl;
for(pit = mPendingInsertMap.begin(); pit != mPendingInsertMap.end(); pit++)
{
std::cerr << "GxsCommentTreeWidget::completeItems() item->parent: " << pit->first;
std::cerr << std::endl;
if (pit->first != parentId)
{
/* find parent */
parentId = pit->first;
lit = mLoadingMap.find(pit->first);
if (lit != mLoadingMap.end())
{
parent = lit->second;
}
else
{
parent = NULL;
}
}
if (pit->first != parentId)
{
/* find parent */
parentId = pit->first;
lit = mLoadingMap.find(pit->first);
if (lit != mLoadingMap.end())
{
parent = lit->second;
}
else
{
parent = NULL;
}
}
if (parent)
{
std::cerr << "GxsCommentTreeWidget::completeItems() Added to Parent";
std::cerr << std::endl;
if (parent)
{
std::cerr << "GxsCommentTreeWidget::completeItems() Added to Parent";
std::cerr << std::endl;
parent->addChild(pit->second);
}
else if (parentId == mThreadId.second)
{
std::cerr << "GxsCommentTreeWidget::completeItems() Added to topLevelItems";
std::cerr << std::endl;
parent->addChild(pit->second);
}
else if (parentId == mThreadId.second)
{
std::cerr << "GxsCommentTreeWidget::completeItems() Added to topLevelItems";
std::cerr << std::endl;
topLevelItems.append(pit->second);
}
else
{
topLevelItems.append(pit->second);
}
else
{
/* missing parent -> insert At Top Level */
QTreeWidgetItem *missingItem = service_createMissingItem(pit->first);
/* missing parent -> insert At Top Level */
QTreeWidgetItem *missingItem = service_createMissingItem(pit->first);
std::cerr << "GxsCommentTreeWidget::completeItems() Added MissingItem";
std::cerr << std::endl;
std::cerr << "GxsCommentTreeWidget::completeItems() Added MissingItem";
std::cerr << std::endl;
parent = missingItem;
parent->addChild(pit->second);
topLevelItems.append(parent);
}
}
parent = missingItem;
parent->addChild(pit->second);
topLevelItems.append(parent);
}
}
/* now push final tree into Tree */
clear();
insertTopLevelItems(0, topLevelItems);
/* now push final tree into Tree */
clear();
insertTopLevelItems(0, topLevelItems);
/* cleanup temp stuff */
mLoadingMap.clear();
mPendingInsertMap.clear();
/* cleanup temp stuff */
mLoadingMap.clear();
mPendingInsertMap.clear();
}
@ -257,67 +365,66 @@ void GxsCommentTreeWidget::loadThread(const uint32_t &token)
void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token)
{
RsGxsGrpMsgIdPair msgId;
mCommentService->acknowledgeComment(token, msgId);
RsGxsGrpMsgIdPair msgId;
mCommentService->acknowledgeComment(token, msgId);
// simply reload data
service_requestComments(mThreadId);
// 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;
std::vector<RsGxsComment> comments;
mCommentService->getRelatedComments(token, comments);
std::vector<RsGxsComment> comments;
mCommentService->getRelatedComments(token, comments);
std::vector<RsGxsComment>::iterator vit;
std::vector<RsGxsComment>::iterator vit;
for(vit = comments.begin(); vit != comments.end(); vit++)
{
RsGxsComment &comment = *vit;
/* convert to a QTreeWidgetItem */
std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId;
std::cerr << std::endl;
for(vit = comments.begin(); vit != comments.end(); vit++)
{
RsGxsComment &comment = *vit;
/* convert to a QTreeWidgetItem */
std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId;
std::cerr << std::endl;
QTreeWidgetItem *item = new QTreeWidgetItem();
QString text;
GxsIdTreeWidgetItem *item = new GxsIdTreeWidgetItem();
QString text;
{
QDateTime qtime;
qtime.setTime_t(comment.mMeta.mPublishTs);
{
QDateTime qtime;
qtime.setTime_t(comment.mMeta.mPublishTs);
text = qtime.toString("yyyy-MM-dd hh:mm:ss");
item->setText(PCITEM_COLUMN_DATE, text);
}
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.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);
}
RsGxsId authorId = comment.mMeta.mAuthorId;
item->setId(authorId, PCITEM_COLUMN_AUTHOR);
text = QString::fromUtf8(comment.mMeta.mMsgId.c_str());
item->setText(PCITEM_COLUMN_MSGID, text);
text = QString::number(comment.mScore);
item->setText(PCITEM_COLUMN_SCORE, text);
text = QString::fromUtf8(comment.mMeta.mParentId.c_str());
item->setText(PCITEM_COLUMN_PARENTID, text);
text = QString::number(comment.mUpVotes);
item->setText(PCITEM_COLUMN_UPVOTES, text);
text = QString::fromUtf8("0");
//text = QString::fromUtf8(comment.mMeta.mServiceString.c_str());
item->setText(PCITEM_COLUMN_SERVSTRING, text);
text = QString::number(comment.mDownVotes);
item->setText(PCITEM_COLUMN_DOWNVOTES, text);
addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item);
}
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);
addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item);
}
return;
}
@ -338,9 +445,8 @@ QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMess
item->setText(PCITEM_COLUMN_MSGID, text);
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;
@ -361,26 +467,26 @@ void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenReque
}
/* now switch on req */
switch(req.mType)
switch(req.mType)
{
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;
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;
}
}

View file

@ -26,6 +26,7 @@
#include "util/TokenQueue.h"
#include <retroshare/rsgxscommon.h>
#include <retroshare/rsidentity.h>
class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse
{
@ -40,6 +41,7 @@ public:
void applyRankings(std::map<RsGxsMessageId, uint32_t>& positions);
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
void setVoteId(const RsGxsId &voterId);
protected:
@ -64,11 +66,23 @@ public slots:
void makeComment();
void replyToComment();
void voteUp();
void voteDown();
void showReputation();
void markInteresting();
void markSpammer();
void banUser();
protected:
void vote(const RsGxsGroupId &groupId, const RsGxsMessageId &threadId,
const RsGxsMessageId &parentId, const RsGxsId &authorId, bool up);
/* Data */
RsGxsGrpMsgIdPair mThreadId;
RsGxsMessageId mCurrentMsgId;
RsGxsId mVoterId;
std::map<std::string, QTreeWidgetItem *> mLoadingMap;
std::multimap<std::string, QTreeWidgetItem *> mPendingInsertMap;

View file

@ -2,6 +2,9 @@
#include "GxsCreateCommentDialog.h"
#include "ui_GxsCreateCommentDialog.h"
#include <QMessageBox>
#include <iostream>
GxsCreateCommentDialog::GxsCreateCommentDialog(TokenQueue *tokQ, RsGxsCommentService *service,
const RsGxsGrpMsgIdPair &parentId, const RsGxsMessageId& threadId, QWidget *parent) :
QDialog(parent),
@ -9,17 +12,47 @@ GxsCreateCommentDialog::GxsCreateCommentDialog(TokenQueue *tokQ, RsGxsCommentSer
{
ui->setupUi(this);
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(createComment()));
/* fill in the available OwnIds for signing */
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, "");
}
void GxsCreateCommentDialog::createComment()
{
RsGxsComment comment;
comment.mComment = ui->commentTextEdit->document()->toPlainText().toStdString();
comment.mComment = std::string(ui->commentTextEdit->document()->toPlainText().toUtf8());
comment.mMeta.mParentId = mParentId.second;
comment.mMeta.mGroupId = mParentId.first;
comment.mMeta.mThreadId = mThreadId;
std::cerr << "GxsCreateCommentDialog::createComment()";
std::cerr << std::endl;
std::cerr << "GroupId : " << comment.mMeta.mGroupId << std::endl;
std::cerr << "ThreadId : " << comment.mMeta.mThreadId << std::endl;
std::cerr << "ParentId : " << comment.mMeta.mParentId << std::endl;
RsGxsId authorId;
if (ui->idChooser->getChosenId(authorId))
{
comment.mMeta.mAuthorId = authorId;
std::cerr << "AuthorId : " << comment.mMeta.mAuthorId << std::endl;
std::cerr << std::endl;
}
else
{
std::cerr << "GxsCreateCommentDialog::createComment() ERROR GETTING AuthorId!";
std::cerr << std::endl;
int ret = QMessageBox::information(this, tr("Comment Signing Error"),
tr("You need to create an Identity\n"
"before you can comment"),
QMessageBox::Ok);
return;
}
uint32_t token;
mCommentService->createComment(token, comment);
mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, 0);

View file

@ -6,30 +6,53 @@
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>145</height>
<width>404</width>
<height>336</height>
</rect>
</property>
<property name="windowTitle">
<string>Make Comment</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout">
<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;
<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>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="3">
<widget class="GxsIdChooser" name="idChooser"/>
</item>
<item row="1" column="0" colspan="4">
<widget class="QTextEdit" name="commentTextEdit"/>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<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 row="0" column="2">
<widget class="QLabel" name="subjectLabel">
<property name="text">
<string>Signed by</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="commentTextEdit"/>
</item>
</layout>
</item>
<item>
@ -44,39 +67,13 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GxsIdChooser</class>
<extends>QComboBox</extends>
<header>gui/gxs/GxsIdChooser.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PostedCreateCommentDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PostedCreateCommentDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

View file

@ -25,19 +25,146 @@
#include <iostream>
static bool MakeIdDesc(const RsGxsId &id, QString &str)
{
RsIdentityDetails details;
if (!rsIdentity->getIdDetails(id, details))
{
std::cerr << "GxsIdRSTreeWidgetItem::MakeIdDesc() FAILED TO GET ID";
std::cerr << std::endl;
str = "Loading... " + QString::fromStdString(id.substr(0,5));
return false;
}
str = QString::fromUtf8(details.mNickname.c_str());
bool addCode = true;
if (details.mPgpLinked)
{
str += " (PGP) [";
if (details.mPgpKnown)
{
/* look up real name */
std::string authorName = rsPeers->getPeerName(details.mPgpId);
str += QString::fromUtf8(authorName.c_str());
str += "]";
addCode = false;
}
}
else
{
str += " (Anon) [";
}
if (addCode)
{
str += QString::fromStdString(id.substr(0,5));
str += "...]";
}
std::cerr << "GxsIdRSTreeWidgetItem::MakeIdDesc() ID Ok";
std::cerr << std::endl;
return true;
}
/** Constructor */
GxsIdTreeWidgetItem::GxsIdTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent)
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent)
:RSTreeWidgetItem(compareRole, parent), QObject(NULL), mTimer(NULL), mCount(0), mColumn(0)
{
init();
}
GxsIdTreeWidgetItem::GxsIdTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent)
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent)
:RSTreeWidgetItem(compareRole, parent), QObject(NULL), mTimer(NULL), mCount(0), mColumn(0)
{
init();
}
void GxsIdRSTreeWidgetItem::init()
{
mTimer = new QTimer(this);
mTimer->setSingleShot(true);
connect(mTimer, SIGNAL(timeout()), this, SLOT(loadId()));
}
void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column)
{
std::cerr << " GxsIdRSTreeWidgetItem::setId(" << id << "," << column << ")";
std::cerr << std::endl;
mId = id;
mColumn = column;
if (mId == "")
{
setText(mColumn, "No Signature");
}
else
{
loadId();
}
}
bool GxsIdRSTreeWidgetItem::getId(RsGxsId &id)
{
id = mId;
return true;
}
#define MAX_ATTEMPTS 5
void GxsIdRSTreeWidgetItem::loadId()
{
std::cerr << " GxsIdRSTreeWidgetItem::loadId() Id: " << mId << ", mCount: " << mCount;
std::cerr << std::endl;
mCount++;
/* try and get details - if not there ... set callback */
QString desc;
bool loaded = MakeIdDesc(mId, desc);
setText(mColumn, desc);
if (loaded)
{
std::cerr << " GxsIdRSTreeWidgetItem::loadId() Loaded Okay";
std::cerr << std::endl;
return;
}
if (mCount < MAX_ATTEMPTS)
{
std::cerr << " GxsIdRSTreeWidgetItem::loadId() Starting Timer for re-try";
std::cerr << std::endl;
/* timer event to try again */
mTimer->setInterval(mCount * 1000);
mTimer->start();
}
}
/** Constructor */
GxsIdTreeWidgetItem::GxsIdTreeWidgetItem(QTreeWidget *parent)
:QTreeWidgetItem(parent), QObject(NULL), mTimer(NULL), mCount(0), mColumn(0)
{
init();
}
GxsIdTreeWidgetItem::GxsIdTreeWidgetItem(QTreeWidgetItem *parent)
:QTreeWidgetItem(parent), QObject(NULL), mTimer(NULL), mCount(0), mColumn(0)
{
init();
}
void GxsIdTreeWidgetItem::init()
{
mTimer = new QTimer(this);
@ -68,47 +195,6 @@ bool GxsIdTreeWidgetItem::getId(RsGxsId &id)
return true;
}
static bool MakeIdDesc(const RsGxsId &id, QString &str)
{
RsIdentityDetails details;
if (!rsIdentity->getIdDetails(id, details))
{
str = "Loading... " + QString::fromStdString(id.substr(0,5));
return false;
}
str = QString::fromUtf8(details.mNickname.c_str());
bool addCode = true;
if (details.mPgpLinked)
{
str += " (PGP) [";
if (details.mPgpKnown)
{
/* look up real name */
std::string authorName = rsPeers->getPeerName(details.mPgpId);
str += QString::fromUtf8(authorName.c_str());
str += "]";
addCode = false;
}
}
else
{
str += " (Anon) [";
}
if (addCode)
{
str += QString::fromStdString(id.substr(0,5));
str += "...]";
}
return true;
}
#define MAX_ATTEMPTS 5
void GxsIdTreeWidgetItem::loadId()
{
@ -125,11 +211,16 @@ void GxsIdTreeWidgetItem::loadId()
if (loaded)
{
std::cerr << " GxsIdTreeWidgetItem::loadId() Loaded Okay";
std::cerr << std::endl;
return;
}
if (mCount < MAX_ATTEMPTS)
{
std::cerr << " GxsIdTreeWidgetItem::loadId() Starting Timer for re-try";
std::cerr << std::endl;
/* timer event to try again */
mTimer->setInterval(mCount * 1000);
mTimer->start();

View file

@ -28,13 +28,50 @@
#include "gui/common/RSTreeWidgetItem.h"
class GxsIdTreeWidgetItem : public QObject, public RSTreeWidgetItem
/*****
* NOTE: I have investigated why the Timer doesn't work in GxsForums.
* It appears that the Timer events occur in the Thread they were created in.
* GxsForums uses a short term thread to fill the ForumThread - this finishes,
* and so the Timer Events don't happen.
*
* The Timer events work fine in Wiki and Comments Dialog.
* because they don't use an additional thread.
*
***/
class GxsIdRSTreeWidgetItem : public QObject, public RSTreeWidgetItem
{
Q_OBJECT
public:
GxsIdTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent = NULL);
GxsIdTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent);
GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent = NULL);
GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent);
void setId(const RsGxsId &id, int column);
bool getId(RsGxsId &id);
private slots:
void loadId();
private:
void init();
QTimer *mTimer;
RsGxsId mId;
int mCount;
int mColumn;
};
class GxsIdTreeWidgetItem : public QObject, public QTreeWidgetItem
{
Q_OBJECT
public:
GxsIdTreeWidgetItem(QTreeWidget *parent = NULL);
GxsIdTreeWidgetItem(QTreeWidgetItem *parent);
void setId(const RsGxsId &id, int column);
bool getId(RsGxsId &id);