* Added first pass at Generic Comment Tree.

- Specific to Posted at the moment.
 * Modified Posted to load Comments when Post "comment" button is pressed.
 



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5366 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-08-01 01:47:53 +00:00
parent c3ea5cbab6
commit 48683a19d5
13 changed files with 576 additions and 112 deletions

View File

@ -973,19 +973,19 @@ gxsgui {
gui/gxs/ForumV2GroupDialog.h \
gui/gxs/WikiGroupDialog.h \
gui/gxs/PostedGroupDialog.h \
gui/gxs/GxsCommentTreeWidget.h \
# gui/gxs/GxsMsgDialog.h \
# gui/gxs/GxsCommentWidget.h \
FORMS += gui/gxs/GxsGroupDialog.ui \
# gui/gxs/GxsMsgDialog.ui \
# gui/gxs/GxsCommentWidget.ui \
# gui/gxs/GxsCommentTreeWidget.ui \
SOURCES += gui/gxs/GxsGroupDialog.cpp \
gui/gxs/ForumV2GroupDialog.cpp \
gui/gxs/WikiGroupDialog.cpp \
gui/gxs/PostedGroupDialog.cpp \
gui/gxs/GxsCommentTreeWidget.cpp \
# gui/gxs/GxsMsgDialog.cpp \
# gui/gxs/GxsCommentWidget.cpp \
}

View File

@ -83,8 +83,19 @@ PostedComments::PostedComments(QWidget *parent)
/* setup TokenQueue */
//mPhotoQueue = new TokenQueue(rsPhoto, this);
ui.treeWidget->setup(rsPosted);
}
void PostedComments::loadComments( std::string threadId )
{
std::cerr << "PostedComments::loadComments(" << threadId << ")";
std::cerr << std::endl;
ui.treeWidget->requestComments(threadId);
}
#if 0
void PhotoDialog::notifySelection(PhotoItem *item, int ptype)

View File

@ -43,6 +43,9 @@ class PostedComments: public QWidget, public TokenResponse
public:
PostedComments(QWidget *parent = 0);
public slots:
void loadComments( std::string );
private:
void loadRequest(const TokenQueue *queue, const TokenRequest &req) { return; }
@ -53,6 +56,8 @@ virtual void notifySelection(PhotoItem *item, int ptype);
void notifyAlbumSelection(PhotoItem *item);
void notifyPhotoSelection(PhotoItem *item);
private slots:
void checkUpdate();

View File

@ -13,8 +13,8 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_3">
@ -51,119 +51,67 @@
</spacer>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>Today</string>
</property>
</item>
<item>
<property name="text">
<string>Yesterday</string>
</property>
</item>
<item>
<property name="text">
<string>This Week</string>
</property>
</item>
<item>
<property name="text">
<string>This Month</string>
</property>
</item>
<item>
<property name="text">
<string>This Year</string>
</property>
</item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Showing 1-100</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_6">
<property name="text">
<string>Prev</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>382</width>
<height>302</height>
</rect>
</property>
</widget>
</widget>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QTreeWidget" name="treeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
<item row="1" column="0">
<widget class="GxsCommentTreeWidget" name="treeWidget">
<column>
<property name="text">
<string>Stuff</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>Yes More</string>
</property>
</column>
<column>
<property name="text">
<string>more, more, more</string>
</property>
</column>
<column>
<property name="text">
<string>More Stuff</string>
</property>
</column>
<column>
<property name="text">
<string>Less Stuff</string>
</property>
</column>
<column>
<property name="text">
<string>More</string>
</property>
</column>
<column>
<property name="text">
<string>asdf</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GxsCommentTreeWidget</class>
<extends>QTreeWidget</extends>
<header>gui/gxs/GxsCommentTreeWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -70,6 +70,7 @@ PostedDialog::PostedDialog(QWidget *parent)
QString comments("Comments");
ui.tabWidget->addTab(mPostedComments, comments);
connect(mPostedList, SIGNAL(loadComments( std::string ) ), mPostedComments, SLOT(loadComments( std::string ) ) );
}

View File

@ -72,10 +72,23 @@ PostedItem::PostedItem(PostedHolder *parent, const RsPostedPost &post)
ts.setTime_t(post.mMeta.mPublishTs);
dateLabel->setText(ts.toString(QString("yyyy/MM/dd hh:mm:ss")));
mThreadId = post.mMeta.mThreadId;
mParent = parent;
connect( commentButton, SIGNAL( clicked() ), this, SLOT( loadComments() ) );
return;
}
void PostedItem::loadComments()
{
std::cerr << "PostedItem::loadComments() Requesting for " << mThreadId;
std::cerr << std::endl;
mParent->requestComments(mThreadId);
}
#if 0
PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album)

View File

@ -36,6 +36,8 @@ class PostedHolder
public:
virtual void deletePostedItem(PostedItem *, uint32_t ptype) = 0;
virtual void notifySelection(PostedItem *item, int ptype) = 0;
virtual void requestComments(std::string threadId) = 0;
};
class PostedItem : public QWidget, private Ui::PostedItem
@ -55,9 +57,16 @@ public:
protected:
//void mousePressEvent(QMouseEvent *event);
private slots:
void loadComments();
private:
uint32_t mType;
bool mSelected;
std::string mThreadId;
PostedHolder *mParent;
};

View File

@ -265,7 +265,7 @@ border-radius: 10px}</string>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="commentButton">
<property name="text">
<string>View Comments</string>
</property>

View File

@ -185,6 +185,17 @@ void PostedListDialog::updateDisplay()
}
void PostedListDialog::requestComments(std::string threadId)
{
/* call a signal */
std::cerr << "PostedListDialog::requestComments(" << threadId << ")";
std::cerr << std::endl;
loadComments(threadId);
}
void PostedListDialog::changedTopic(const QString &id)
{
mCurrTopicId = id.toStdString();

View File

@ -47,7 +47,10 @@ public:
virtual void deletePostedItem(PostedItem *, uint32_t ptype) { return; }
virtual void notifySelection(PostedItem *item, int ptype) { return; }
virtual void requestComments(std::string threadId);
signals:
void loadComments( std::string );
private slots:

View File

@ -18,6 +18,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QGroupBox" name="sortGroup">
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>-1</number>

View File

@ -0,0 +1,372 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2008 Robert Fernie
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMimeData>
#include <QDateTime>
#include "gui/gxs/GxsCommentTreeWidget.h"
#include <iostream>
#define PCITEM_COLUMN_DATE 0
#define PCITEM_COLUMN_COMMENT 1
#define PCITEM_COLUMN_AUTHOR 2
#define PCITEM_COLUMN_SERVSTRING 3
#define PCITEM_COLUMN_MSGID 4
#define PCITEM_COLUMN_PARENTID 5
#define GXSCOMMENTS_LOADTHREAD 1
// Temporarily make this specific.
#include "retroshare/rsposted.h"
GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent)
:QTreeWidget(parent), mRsService(NULL), mTokenQueue(NULL)
{
return;
}
void GxsCommentTreeWidget::setup(RsTokenService *service)
{
mRsService = service;
mTokenQueue = new TokenQueue(service, this);
return;
}
/* Load Comments */
void GxsCommentTreeWidget::requestComments(std::string threadId)
{
/* request comments */
service_requestComments(threadId);
}
void GxsCommentTreeWidget::service_requestComments(std::string threadId)
{
/* request comments */
//std::cerr << "GxsCommentTreeWidget::service_requestComments() ERROR must be overloaded!";
//std::cerr << std::endl;
std::cerr << "GxsCommentTreeWidget::service_requestComments(" << threadId << ")";
std::cerr << std::endl;
RsTokReqOptions opts;
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST;
opts.mFlagsFilter = RSPOSTED_MSGTYPE_COMMENT;
opts.mFlagsMask = RSPOSTED_MSGTYPE_COMMENT;
std::list<std::string> msgIds;
msgIds.push_back(threadId);
mThreadId = threadId;
uint32_t token;
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, GXSCOMMENTS_LOADTHREAD);
}
/* Generic Handling */
void GxsCommentTreeWidget::clearItems()
{
mPendingInsertMap.clear();
mLoadingMap.clear();
}
void GxsCommentTreeWidget::completeItems()
{
/* 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::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;
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;
parent->addChild(pit->second);
}
else if (parentId == mThreadId)
{
std::cerr << "GxsCommentTreeWidget::completeItems() Added to topLevelItems";
std::cerr << std::endl;
topLevelItems.append(pit->second);
}
else
{
/* missing parent -> insert At Top Level */
QTreeWidgetItem *missingItem = service_createMissingItem(pit->first);
std::cerr << "GxsCommentTreeWidget::completeItems() Added MissingItem";
std::cerr << std::endl;
parent = missingItem;
parent->addChild(pit->second);
topLevelItems.append(parent);
}
}
/* now push final tree into Tree */
clear();
insertTopLevelItems(0, topLevelItems);
/* cleanup temp stuff */
mLoadingMap.clear();
mPendingInsertMap.clear();
}
void GxsCommentTreeWidget::addItem(std::string itemId, std::string parentId, QTreeWidgetItem *item)
{
std::cerr << "GxsCommentTreeWidget::addItem() Id: " << itemId;
std::cerr << " ParentId: " << parentId;
std::cerr << std::endl;
/* store in map -> for children */
mLoadingMap[itemId] = item;
std::map<std::string, QTreeWidgetItem *>::iterator it;
it = mLoadingMap.find(parentId);
if (it != mLoadingMap.end())
{
std::cerr << "GxsCommentTreeWidget::addItem() Added to Parent";
std::cerr << std::endl;
it->second->addChild(item);
}
else
{
std::cerr << "GxsCommentTreeWidget::addItem() Added to Pending List";
std::cerr << std::endl;
mPendingInsertMap.insert(std::make_pair(parentId, item));
}
}
void GxsCommentTreeWidget::loadThread(const uint32_t &token)
{
clearItems();
service_loadThread(token);
completeItems();
}
void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
{
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;
{
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);
}
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)
{
//std::cerr << "GxsCommentTreeWidget::service_createMissingItem() ERROR must be overloaded!";
//std::cerr << std::endl;
std::cerr << "GxsCommentTreeWidget::service_createMissingItem()";
std::cerr << std::endl;
QTreeWidgetItem *item = new QTreeWidgetItem();
QString text("Unknown");
item->setText(PCITEM_COLUMN_DATE, text);
item->setText(PCITEM_COLUMN_COMMENT, text);
item->setText(PCITEM_COLUMN_AUTHOR, text);
item->setText(PCITEM_COLUMN_MSGID, text);
item->setText(PCITEM_COLUMN_SERVSTRING, text);
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;
std::cerr << std::endl;
if (queue != mTokenQueue)
{
std::cerr << "GxsCommentTreeWidget::loadRequest() Queue ERROR";
std::cerr << std::endl;
return;
}
/* now switch on req */
switch(req.mUserType)
{
case GXSCOMMENTS_LOADTHREAD:
loadThread(req.mToken);
break;
default:
std::cerr << "GxsCommentTreeWidget::loadRequest() UNKNOWN UserType ";
std::cerr << std::endl;
break;
}
}
#if 0
QMimeData * GxsCommentTreeWidget::mimeData ( const QList<QTreeWidgetItem *> items ) const
{
/* extract from each QTreeWidgetItem... all the member text */
QList<QTreeWidgetItem *>::const_iterator it;
QString text;
for(it = items.begin(); it != items.end(); it++)
{
QString line = QString("%1/%2/%3/").arg((*it)->text(SR_NAME_COL), (*it)->text(SR_HASH_COL), (*it)->text(SR_SIZE_COL));
bool isLocal = (*it)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool();
if (isLocal)
{
line += "Local";
}
else
{
line += "Remote";
}
line += "/\n";
text += line;
}
std::cerr << "Created MimeData:";
std::cerr << std::endl;
std::string str = text.toUtf8().constData();
std::cerr << str;
std::cerr << std::endl;
QMimeData *data = new QMimeData();
data->setData("application/x-rsfilelist", QByteArray(str.c_str()));
return data;
}
QStringList GxsCommentTreeWidget::mimeTypes () const
{
QStringList list;
list.push_back("application/x-rsfilelist");
return list;
}
Qt::DropActions GxsCommentTreeWidget::supportedDropActions () const
{
return Qt::CopyAction;
}
#endif

View File

@ -0,0 +1,88 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2008 Robert Fernie
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _GXS_COMMENT_TREE_WIDGET_H
#define _GXS_COMMENT_TREE_WIDGET_H
#include <QTreeWidget>
#include "util/TokenQueue.h"
/* indicies for search results item columns SR_ = Search Result */
#define SR_NAME_COL 0
#define SR_SIZE_COL 1
#define SR_ID_COL 2
#define SR_TYPE_COL 3
#define SR_AGE_COL 4
#define SR_HASH_COL 5
#define SR_SEARCH_ID_COL 6
#define SR_UID_COL 7
#define SR_DATA_COL SR_NAME_COL
#define SR_ROLE_LOCAL Qt::UserRole
class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse
{
Q_OBJECT
public:
GxsCommentTreeWidget(QWidget *parent = 0);
void setup(RsTokenService *service);
void requestComments(std::string threadId);
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);
void clearItems();
void completeItems();
void loadThread(const uint32_t &token);
void addItem(std::string itemId, std::string parentId, QTreeWidgetItem *item);
/* Data */
std::string mThreadId;
std::map<std::string, QTreeWidgetItem *> mLoadingMap;
std::multimap<std::string, QTreeWidgetItem *> mPendingInsertMap;
TokenQueue *mTokenQueue;
RsTokenService *mRsService;
protected:
//virtual QMimeData * mimeData ( const QList<QTreeWidgetItem *> items ) const;
//virtual QStringList mimeTypes () const;
//virtual Qt::DropActions supportedDropActions () const;
};
#endif