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

@ -726,7 +726,7 @@ void WikiEditDialog::loadBaseHistory(const uint32_t &token)
std::cerr << " ParentId: " << page.mMeta.mParentId;
std::cerr << std::endl;
GxsIdTreeWidgetItem *modItem = new GxsIdTreeWidgetItem(mThreadCompareRole);
GxsIdRSTreeWidgetItem *modItem = new GxsIdRSTreeWidgetItem(mThreadCompareRole);
modItem->setData(WET_DATA_COLUMN, WET_ROLE_ORIGPAGEID, QString::fromStdString(page.mMeta.mOrigMsgId));
modItem->setData(WET_DATA_COLUMN, WET_ROLE_PAGEID, QString::fromStdString(page.mMeta.mMsgId));
@ -841,7 +841,7 @@ void WikiEditDialog::loadEditTreeData(const uint32_t &token)
}
/* create an Entry */
GxsIdTreeWidgetItem *modItem = new GxsIdTreeWidgetItem(mThreadCompareRole);
GxsIdRSTreeWidgetItem *modItem = new GxsIdRSTreeWidgetItem(mThreadCompareRole);
modItem->setData(WET_DATA_COLUMN, WET_ROLE_ORIGPAGEID, QString::fromStdString(snapshot.mMeta.mOrigMsgId));
modItem->setData(WET_DATA_COLUMN, WET_ROLE_PAGEID, QString::fromStdString(snapshot.mMeta.mMsgId));
modItem->setData(WET_DATA_COLUMN, WET_ROLE_PARENTID, QString::fromStdString(snapshot.mMeta.mParentId));

View File

@ -93,9 +93,9 @@ void GxsChannelPostItem::setup()
connect(readAndClearButton, SIGNAL(clicked()), this, SLOT(readAndClearItem()));
connect( unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeChannel ( void ) ) );
//connect( downloadButton, SIGNAL( clicked( void ) ), this, SLOT( download ( void ) ) );
connect( downloadButton, SIGNAL( clicked( void ) ), this, SLOT( download ( void ) ) );
// HACK FOR NOW.
connect( downloadButton, SIGNAL( clicked( void ) ), this, SLOT( comments ( void ) ) );
connect( commentButton, SIGNAL( clicked( void ) ), this, SLOT( comments ( void ) ) );
connect( playButton, SIGNAL( clicked( void ) ), this, SLOT( play ( void ) ) );
connect( copyLinkButton, SIGNAL( clicked( void ) ), this, SLOT( copyLink ( void ) ) );
@ -124,6 +124,7 @@ void GxsChannelPostItem::setup()
void GxsChannelPostItem::updateItemStatic()
{
#if 0
/* fill in */
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelPostItem::updateItemStatic()";
@ -262,6 +263,8 @@ void GxsChannelPostItem::updateItemStatic()
}
m_inUpdateItemStatic = false;
#endif
}
@ -298,7 +301,7 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
unsubscribeButton->setEnabled(false);
}
readButton->hide();
newLabel->hide();
//newLabel->hide();
copyLinkButton->hide();
}
else
@ -338,13 +341,13 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
QColor color;
if (!IS_MSG_UNREAD(post.mMeta.mMsgStatus))
{
newLabel->setVisible(false);
//newLabel->setVisible(false);
newState = false;
color = COLOR_NORMAL;
}
else
{
newLabel->setVisible(true);
//newLabel->setVisible(true);
newState = true;
color = COLOR_NEW;
}
@ -362,7 +365,7 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
else
{
readButton->setVisible(false);
newLabel->setVisible(false);
//newLabel->setVisible(false);
}
}
@ -382,17 +385,17 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
mFileItems.clear();
}
#if 0
std::list<FileInfo>::iterator it;
for(it = cmi.files.begin(); it != cmi.files.end(); it++)
std::list<RsGxsFile>::const_iterator it;
for(it = post.mFiles.begin(); it != post.mFiles.end(); it++)
{
/* add file */
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->path, it->size,
std::string path;
SubFileItem *fi = new SubFileItem(it->mHash, it->mName, path, it->mSize,
SFI_STATE_REMOTE | SFI_TYPE_CHANNEL, "");
mFileItems.push_back(fi);
/* check if the file is a media file */
if (!misc::isPreviewable(QFileInfo(QString::fromUtf8(it->fname.c_str())).suffix()))
if (!misc::isPreviewable(QFileInfo(QString::fromUtf8(it->mName.c_str())).suffix()))
fi->mediatype();
@ -400,15 +403,12 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
layout->addWidget(fi);
}
if(cmi.thumbnail.image_thumbnail != NULL)
if(post.mThumbnail.mData != NULL)
{
QPixmap thumbnail;
thumbnail.loadFromData(cmi.thumbnail.image_thumbnail, cmi.thumbnail.im_thumbnail_size, "PNG");
thumbnail.loadFromData(post.mThumbnail.mData, post.mThumbnail.mSize, "PNG");
logoLabel->setPixmap(thumbnail);
}
#endif
}
void GxsChannelPostItem::setFileCleanUpWarning(uint32_t time_left)

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>629</width>
<height>172</height>
<height>177</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
@ -224,19 +224,6 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="newLabel">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>21</height>
</size>
</property>
<property name="text">
<string>New</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="downloadButton">
<property name="font">
@ -271,6 +258,13 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="commentButton">
<property name="text">
<string>Comments</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

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);

View File

@ -31,12 +31,16 @@
#include "CreateGxsChannelMsg.h"
#include "gui/feeds/SubFileItem.h"
#include "util/misc.h"
#include "util/TokenQueue.h"
#include <retroshare/rsgxschannels.h>
#include <retroshare/rsfiles.h>
#include <iostream>
#define CREATEMSG_CHANNELINFO 0x002
/** Constructor */
CreateGxsChannelMsg::CreateGxsChannelMsg(std::string cId)
: QDialog (NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), mChannelId(cId) ,mCheckAttachment(true), mAutoMediaThumbNail(false)
@ -44,6 +48,8 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(std::string cId)
/* Invoke the Qt Designer generated object setup routine */
setupUi(this);
mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this);
headerFrame->setHeaderImage(QPixmap(":/images/channels.png"));
headerFrame->setHeaderText(tr("New GxsChannel Post"));
@ -371,9 +377,9 @@ void CreateGxsChannelMsg::addExtraFile()
QStringList files;
if (misc::getOpenFileNames(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", files)) {
for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) {
addAttachment((*fileIt).toUtf8().constData());
}
for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) {
addAttachment((*fileIt).toUtf8().constData());
}
}
}
@ -397,24 +403,23 @@ void CreateGxsChannelMsg::addAttachment(const std::string &path)
if((*it)->FilePath() == path){
QMessageBox::warning(this, tr("RetroShare"),
tr("File already Added and Hashed"),
QMessageBox::Ok, QMessageBox::Ok);
tr("File already Added and Hashed"),
QMessageBox::Ok, QMessageBox::Ok);
return;
}
}
// channels creates copy of file into channels directory and shares this
FileInfo fInfo;
#if 0
rsGxsChannels->channelExtraFileHash(path, mChannelId, fInfo);
#endif
std::string filename;
uint64_t size = 0;
std::string hash = "";
rsGxsChannels->ExtraFileHash(path, filename);
// file is not innitial
SubFileItem *file = new SubFileItem(fInfo.hash, fInfo.fname, fInfo.path, fInfo.size,
flags, mChannelId); // destroyed when fileFrame (this subfileitem) is destroyed
// only path and filename are valid.
// destroyed when fileFrame (this subfileitem) is destroyed
SubFileItem *file = new SubFileItem(hash, filename, path, size, flags, mChannelId);
mAttachments.push_back(file);
QLayout *layout = fileFrame->layout();
@ -525,10 +530,8 @@ void CreateGxsChannelMsg::cancelMsg()
std::list<SubFileItem* >::const_iterator it;
#if 0
for(it = mAttachments.begin(); it != mAttachments.end(); it++)
rsGxsChannels->channelExtraFileRemove((*it)->FileHash(), mChannelId);
#endif
rsGxsChannels->ExtraFileRemove((*it)->FileHash());
close();
return;
@ -539,31 +542,45 @@ void CreateGxsChannelMsg::newChannelMsg()
if (!rsGxsChannels)
return;
#if 0
GxsChannelInfo ci;
if (!rsGxsChannels->getGxsChannelInfo(mChannelId, ci))
mChannelMetaLoaded = false;
/* request Data */
{
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
return;
std::list<std::string> groupIds;
groupIds.push_back(mChannelId);
std::cerr << "CreateGxsChannelMsg::newChannelMsg() Req Group Summary(" << mChannelId << ")";
std::cerr << std::endl;
uint32_t token;
mChannelQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, groupIds, CREATEMSG_CHANNELINFO);
}
}
channelName->setText(QString::fromStdWString(ci.channelName));
#endif
void CreateGxsChannelMsg::saveChannelInfo(const RsGroupMetaData &meta)
{
mChannelMeta = meta;
mChannelMetaLoaded = true;
channelName->setText(QString::fromUtf8(mChannelMeta.mGroupName.c_str()));
subjectEdit->setFocus();
}
void CreateGxsChannelMsg::sendMsg()
{
std::cerr << "CreateGxsChannelMsg::sendMsg()";
std::cerr << std::endl;
/* construct message bits */
std::wstring subject = misc::removeNewLine(subjectEdit->text()).toStdWString();
std::wstring msg = msgEdit->toPlainText().toStdWString();
std::string subject = std::string(misc::removeNewLine(subjectEdit->text()).toUtf8());
std::string msg = std::string(msgEdit->toPlainText().toUtf8());
std::list<FileInfo> files;
std::list<RsGxsFile> files;
std::list<SubFileItem *>::iterator fit;
@ -571,10 +588,10 @@ void CreateGxsChannelMsg::sendMsg()
{
if (!(*fit)->isHidden())
{
FileInfo fi;
fi.hash = (*fit)->FileHash();
fi.fname = (*fit)->FileName();
fi.size = (*fit)->FileSize();
RsGxsFile fi;
fi.mHash = (*fit)->FileHash();
fi.mName = (*fit)->FileName();
fi.mSize = (*fit)->FileSize();
files.push_back(fi);
@ -595,50 +612,49 @@ void CreateGxsChannelMsg::sendMsg()
}
void CreateGxsChannelMsg::sendMessage(std::wstring subject, std::wstring msg, std::list<FileInfo> &files)
void CreateGxsChannelMsg::sendMessage(const std::string &subject, const std::string &msg, const std::list<RsGxsFile> &files)
{
QString name = misc::removeNewLine(subjectEdit->text());
if(name.isEmpty())
if(subject.empty())
{ /* error message */
QMessageBox::warning(this, tr("RetroShare"),
tr("Please add a Subject"),
QMessageBox::Ok, QMessageBox::Ok);
tr("Please add a Subject"),
QMessageBox::Ok, QMessageBox::Ok);
return; //Don't add an empty Subject!!
}
else
/* rsGxsChannels */
if (rsGxsChannels)
{
#if 0
GxsChannelMsgInfo msgInfo;
RsGxsChannelPost post;
msgInfo.channelId = mChannelId;
msgInfo.msgId = "";
post.mMeta.mGroupId = mChannelId;
post.mMeta.mParentId = "";
post.mMeta.mThreadId = "";
post.mMeta.mMsgId = "";
msgInfo.subject = subject;
msgInfo.msg = msg;
msgInfo.files = files;
post.mMeta.mMsgName = subject;
post.mMsg = msg;
post.mFiles = files;
QByteArray ba;
QBuffer buffer(&ba);
if(!picture.isNull()){
if(!picture.isNull())
{
// send chan image
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
msgInfo.thumbnail.image_thumbnail = (unsigned char*) ba.data();
msgInfo.thumbnail.im_thumbnail_size = ba.size();
post.mThumbnail.copy((uint8_t *) ba.data(), ba.size());
}
rsGxsChannels->GxsChannelMessageSend(msgInfo);
#endif
uint32_t token;
rsGxsChannels->createPost(token, post);
}
close();
return;
return;
}
@ -654,3 +670,52 @@ void CreateGxsChannelMsg::addThumbnail()
// to show the selected
thumbnail_label->setPixmap(picture);
}
void CreateGxsChannelMsg::loadChannelInfo(const uint32_t &token)
{
std::cerr << "CreateGxsChannelMsg::loadChannelInfo()";
std::cerr << std::endl;
std::list<RsGroupMetaData> groupInfo;
rsGxsChannels->getGroupSummary(token, groupInfo);
if (groupInfo.size() == 1)
{
RsGroupMetaData fi = groupInfo.front();
saveChannelInfo(fi);
}
else
{
std::cerr << "CreateGxsChannelMsg::loadForumInfo() ERROR INVALID Number of Forums";
std::cerr << std::endl;
}
}
void CreateGxsChannelMsg::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
std::cerr << "CreateGxsChannelMsg::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
if (queue == mChannelQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case CREATEMSG_CHANNELINFO:
loadChannelInfo(req.mToken);
break;
default:
std::cerr << "CreateGxsChannelMsg::loadRequest() UNKNOWN UserType ";
std::cerr << std::endl;
}
}
}

View File

@ -24,15 +24,17 @@
#include "ui_CreateGxsChannelMsg.h"
#include <stdint.h>
#include "util/TokenQueue.h"
#include <retroshare/rsgxschannels.h>
#ifdef CHANNELS_FRAME_CATCHER
#include "util/framecatcher.h"
#endif
class SubFileItem;
class FileInfo;
class RsGxsFile;
class CreateGxsChannelMsg : public QDialog, private Ui::CreateGxsChannelMsg
class CreateGxsChannelMsg : public QDialog, public TokenResponse, private Ui::CreateGxsChannelMsg
{
Q_OBJECT
@ -51,6 +53,10 @@ public:
QPixmap picture;
// overload from TokenResponse
virtual void loadRequest(const TokenQueue*, const TokenRequest&);
protected:
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);
@ -69,17 +75,23 @@ private slots:
private:
void parseRsFileListAttachments(const std::string &attachList);
void sendMessage(std::wstring subject, std::wstring msg, std::list<FileInfo> &files);
bool setThumbNail(const std::string& path, int frame);
void loadChannelInfo(const uint32_t &token);
void saveChannelInfo(const RsGroupMetaData &group);
void parseRsFileListAttachments(const std::string &attachList);
void sendMessage(const std::string &subject, const std::string &msg, const std::list<RsGxsFile> &files);
bool setThumbNail(const std::string& path, int frame);
std::string mChannelId;
std::string mChannelId;
RsGroupMetaData mChannelMeta;
bool mChannelMetaLoaded;
std::list<SubFileItem *> mAttachments;
bool mCheckAttachment;
bool mAutoMediaThumbNail;
bool mAutoMediaThumbNail;
TokenQueue *mChannelQueue;
#ifdef CHANNELS_FRAME_CATCHER
framecatcher* fCatcher;

View File

@ -1077,6 +1077,13 @@ void GxsChannelDialog::insertChannelPosts(const std::vector<RsGxsChannelPost> &p
// can we add that into the request?
//msgs.sort(sortChannelMsgSummary);
/* replace all the messages with new ones */
QList<GxsChannelPostItem *>::iterator mit;
for (mit = mChannelPostItems.begin(); mit != mChannelPostItems.end(); mit++) {
delete (*mit);
}
mChannelPostItems.clear();
uint32_t subscribeFlags = 0xffffffff;
for (it = posts.begin(); it != posts.end(); it++)

View File

@ -791,7 +791,7 @@ void GxsForumThreadWidget::forceUpdateDisplay()
QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForumMsg &msg, bool useChildTS, uint32_t filterColumn)
{
GxsIdTreeWidgetItem *item = new GxsIdTreeWidgetItem(mThreadCompareRole);
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole);
QString text;
item->setText(COLUMN_THREAD_TITLE, QString::fromUtf8(msg.mMeta.mMsgName.c_str()));
@ -871,7 +871,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
QTreeWidgetItem *GxsForumThreadWidget::generateMissingItem(const std::string &msgId)
{
GxsIdTreeWidgetItem *item = new GxsIdTreeWidgetItem(mThreadCompareRole);
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole);
item->setText(COLUMN_THREAD_TITLE, tr("[ ... Missing Message ... ]"));
item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_MSGID, QString::fromStdString(msgId));
item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_MISSING, true);