2018-11-14 21:14:40 +01:00
/*******************************************************************************
* retroshare - gui / src / gui / gxs / GxsCommentTreeWidget . cpp *
* *
* Copyright 2012 - 2013 by Robert Fernie < retroshare . project @ gmail . com > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 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 Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-08-01 01:47:53 +00:00
2020-06-01 13:44:43 +02:00
# include "GxsCommentTreeWidget.h"
# include "gui/common/FilesDefs.h"
# include "gui/common/RSElidedItemDelegate.h"
# include "gui/common/RSTreeWidgetItem.h"
# include "gui/gxs/GxsCreateCommentDialog.h"
# include "gui/gxs/GxsIdTreeWidgetItem.h"
2017-05-16 10:24:23 +02:00
# include <QAbstractTextDocumentLayout>
# include <QApplication>
2020-10-30 23:22:52 +01:00
# include <QTextEdit>
2020-11-01 20:28:57 +01:00
# include <QHeaderView>
2017-11-18 19:48:38 +01:00
# include <QClipboard>
2012-08-01 01:47:53 +00:00
# include <QDateTime>
2012-11-25 21:50:45 +00:00
# include <QMenu>
2017-11-18 19:48:38 +01:00
# include <QMimeData>
2017-05-16 10:24:23 +02:00
# include <QPainter>
2020-06-01 13:44:43 +02:00
# include <QPainterPath>
2017-11-18 19:48:38 +01:00
# include <QTextDocument>
2012-08-01 01:47:53 +00:00
# include <iostream>
2012-11-25 21:50:45 +00:00
# define PCITEM_COLUMN_COMMENT 0
# define PCITEM_COLUMN_AUTHOR 1
# define PCITEM_COLUMN_DATE 2
2013-03-13 00:33:14 +00:00
# define PCITEM_COLUMN_SCORE 3
# define PCITEM_COLUMN_UPVOTES 4
# define PCITEM_COLUMN_DOWNVOTES 5
2013-03-15 21:02:43 +00:00
# define PCITEM_COLUMN_OWNVOTE 6
# define PCITEM_COLUMN_MSGID 7
# define PCITEM_COLUMN_PARENTID 8
2019-01-10 00:12:38 +01:00
# define PCITEM_COLUMN_AUTHORID 9
2019-03-26 18:35:10 +01:00
# define ROLE_SORT Qt::UserRole + 1
2012-08-01 01:47:53 +00:00
# define GXSCOMMENTS_LOADTHREAD 1
2013-03-15 21:02:43 +00:00
# define COMMENT_VOTE_ACK 0x001234
2017-05-18 22:31:52 +02:00
# define POST_CELL_SIZE_ROLE (Qt::UserRole+1)
# define POST_COLOR_ROLE (Qt::UserRole+2)
2012-08-01 01:47:53 +00:00
2012-11-25 21:50:45 +00:00
/* Images for context menu icons */
2020-10-15 20:12:00 +02:00
# define IMAGE_MESSAGE ": / icons / mail / compose.png"
# define IMAGE_REPLY ": / icons / mail / reply.png"
2017-11-18 19:48:38 +01:00
# define IMAGE_COPY ": / images / copy.png"
2017-05-18 22:31:52 +02:00
# define IMAGE_VOTEUP ": / images / vote_up.png"
# define IMAGE_VOTEDOWN ": / images / vote_down.png"
2012-08-01 01:47:53 +00:00
2020-09-18 23:12:48 +02:00
std : : map < RsGxsMessageId , std : : vector < RsGxsComment > > GxsCommentTreeWidget : : mCommentsCache ;
QMutex GxsCommentTreeWidget : : mCacheMutex ;
2020-11-01 20:28:57 +01:00
//#define USE_NEW_DELEGATE 1
2017-05-16 10:24:23 +02:00
// This class allows to draw the item using an appropriate size
class MultiLinesCommentDelegate : public QStyledItemDelegate
{
public :
MultiLinesCommentDelegate ( QFontMetricsF f ) : qf ( f ) { }
2017-07-05 19:30:31 +02:00
QSize sizeHint ( const QStyleOptionViewItem & /*option*/ , const QModelIndex & index ) const
2017-05-16 10:24:23 +02:00
{
2020-11-01 20:28:57 +01:00
std : : cerr < < " SizeHint called with size= " < < index . data ( POST_CELL_SIZE_ROLE ) . toSize ( ) . width ( ) < < " x " < < index . data ( POST_CELL_SIZE_ROLE ) . toSize ( ) . height ( ) < < std : : endl ;
2017-05-18 22:31:52 +02:00
return index . data ( POST_CELL_SIZE_ROLE ) . toSize ( ) ;
2017-05-16 10:24:23 +02:00
}
virtual void paint ( QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const
{
Q_ASSERT ( index . isValid ( ) ) ;
2020-10-30 23:22:52 +01:00
QStyleOptionViewItem opt = option ;
2017-05-16 10:24:23 +02:00
initStyleOption ( & opt , index ) ;
// disable default icon
opt . icon = QIcon ( ) ;
opt . text = QString ( ) ;
2017-07-05 19:30:31 +02:00
// draw default item background
if ( option . state & QStyle : : State_Selected ) {
painter - > fillRect ( option . rect , option . palette . highlight ( ) ) ;
} else {
const QWidget * widget = opt . widget ;
QStyle * style = widget ? widget - > style ( ) : QApplication : : style ( ) ;
style - > drawPrimitive ( QStyle : : PE_PanelItemViewItem , & opt , painter , widget ) ;
}
const QRect r = option . rect . adjusted ( 0 , 0 , - option . decorationSize . width ( ) , 0 ) ;
2017-05-16 10:24:23 +02:00
QTextDocument td ;
td . setHtml ( " <html> " + index . data ( Qt : : DisplayRole ) . toString ( ) + " </html> " ) ;
2017-07-05 19:30:31 +02:00
td . setTextWidth ( r . width ( ) ) ;
QSizeF s = td . documentLayout ( ) - > documentSize ( ) ;
2017-05-16 10:24:23 +02:00
int m = QFontMetricsF ( QFont ( ) ) . height ( ) ;
QSize full_area ( std : : min ( r . width ( ) , ( int ) s . width ( ) ) + m , std : : min ( r . height ( ) , ( int ) s . height ( ) ) + m ) ;
QPixmap px ( full_area . width ( ) , full_area . height ( ) ) ;
2017-07-05 19:30:31 +02:00
px . fill ( QColor ( 0 , 0 , 0 , 0 ) ) ; //Transparent background as item background is already paint.
2017-05-16 10:24:23 +02:00
QPainter p ( & px ) ;
p . setRenderHint ( QPainter : : Antialiasing ) ;
2020-11-01 20:28:57 +01:00
{
QPainterPath path ;
path . addRoundedRect ( QRectF ( m / 4.0 , m / 4.0 , s . width ( ) + m / 2.0 , s . height ( ) + m / 2.0 ) , m , m ) ;
QPen pen ( Qt : : gray , m / 7.0f ) ;
p . setPen ( pen ) ;
p . fillPath ( path , QColor : : fromHsv ( index . data ( POST_COLOR_ROLE ) . toInt ( ) / 255.0 * 360 , 40 , 220 ) ) ; // varies the color according to the post author
p . drawPath ( path ) ;
QAbstractTextDocumentLayout : : PaintContext ctx ;
ctx . clip = QRectF ( 0 , 0 , s . width ( ) , s . height ( ) ) ;
p . translate ( QPointF ( m / 2.0 , m / 2.0 ) ) ;
td . documentLayout ( ) - > draw ( & p , ctx ) ;
}
2017-05-16 10:24:23 +02:00
painter - > drawPixmap ( r . topLeft ( ) , px ) ;
2017-05-18 22:31:52 +02:00
const_cast < QAbstractItemModel * > ( index . model ( ) ) - > setData ( index , px . size ( ) , POST_CELL_SIZE_ROLE ) ;
2017-05-16 10:24:23 +02:00
}
private :
QFontMetricsF qf ;
} ;
2020-11-01 20:28:57 +01:00
class NoEditDelegate : public QStyledItemDelegate
{
public :
NoEditDelegate ( QObject * parent = 0 ) : QStyledItemDelegate ( parent ) { }
virtual QWidget * createEditor ( QWidget * parent , const QStyleOptionViewItem & option , const QModelIndex & index ) const
{
return nullptr ;
}
} ;
2020-10-30 23:22:52 +01:00
class GxsCommentDelegate : public QStyledItemDelegate
2012-08-01 01:47:53 +00:00
{
2020-10-30 23:22:52 +01:00
public :
GxsCommentDelegate ( QFontMetricsF f ) : qf ( f ) { }
2020-11-01 20:28:57 +01:00
QSize sizeHint ( const QStyleOptionViewItem & option , const QModelIndex & index ) const override
2020-10-30 23:22:52 +01:00
{
2020-11-01 20:28:57 +01:00
QSize s = QStyledItemDelegate : : sizeHint ( option , index ) ;
std : : cerr < < " SizeHint called with size= " < < index . data ( POST_CELL_SIZE_ROLE ) . toSize ( ) . width ( ) < < " x " < < index . data ( POST_CELL_SIZE_ROLE ) . toSize ( ) . height ( ) < < std : : endl ;
2020-10-30 23:22:52 +01:00
return index . data ( POST_CELL_SIZE_ROLE ) . toSize ( ) ;
}
2020-11-01 20:28:57 +01:00
void updateEditorGeometry ( QWidget * editor , const QStyleOptionViewItem & option , const QModelIndex & index ) const override
2020-10-30 23:22:52 +01:00
{
2020-11-01 20:28:57 +01:00
if ( index . column ( ) = = PCITEM_COLUMN_COMMENT )
editor - > setGeometry ( option . rect ) ;
2020-10-30 23:22:52 +01:00
}
QWidget * createEditor ( QWidget * parent , const QStyleOptionViewItem & option , const QModelIndex & index ) const override
{
if ( index . column ( ) = = PCITEM_COLUMN_COMMENT )
{
QTextEdit * b = new QTextEdit ( parent ) ;
2020-11-01 20:28:57 +01:00
b - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
2020-10-30 23:22:52 +01:00
b - > setFixedSize ( option . rect . size ( ) ) ;
b - > setAcceptRichText ( true ) ;
b - > setTextInteractionFlags ( Qt : : TextSelectableByMouse | Qt : : LinksAccessibleByMouse ) ;
b - > document ( ) - > setHtml ( " <html> " + index . data ( Qt : : DisplayRole ) . toString ( ) + " </html> " ) ;
2020-11-01 20:28:57 +01:00
b - > adjustSize ( ) ;
2020-10-30 23:22:52 +01:00
return b ;
}
else
return nullptr ;
}
virtual void paint ( QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const override
{
if ( ( option . state & QStyle : : State_Selected ) ) // Avoids double display. The selected widget is never exactly the size of the rendered one,
return ; // so when selected, we only draw the selected one.
Q_ASSERT ( index . isValid ( ) ) ;
QStyleOptionViewItem opt = option ;
initStyleOption ( & opt , index ) ;
// disable default icon
opt . icon = QIcon ( ) ;
opt . text = QString ( ) ;
const QRect r = option . rect . adjusted ( 0 , 0 , - option . decorationSize . width ( ) , 0 ) ;
QTextDocument td ;
td . setHtml ( " <html> " + index . data ( Qt : : DisplayRole ) . toString ( ) + " </html> " ) ;
td . setTextWidth ( r . width ( ) ) ;
QSizeF s = td . documentLayout ( ) - > documentSize ( ) ;
2012-08-01 01:47:53 +00:00
2020-11-01 20:28:57 +01:00
int m = QFontMetricsF ( QFont ( ) ) . height ( ) ;
//int m = 2;
2020-10-30 23:22:52 +01:00
QSize full_area ( std : : min ( r . width ( ) , ( int ) s . width ( ) ) + m , std : : min ( r . height ( ) , ( int ) s . height ( ) ) + m ) ;
QPixmap px ( full_area . width ( ) , full_area . height ( ) ) ;
px . fill ( QColor ( 0 , 0 , 0 , 0 ) ) ; //Transparent background as item background is already paint.
QPainter p ( & px ) ;
p . setRenderHint ( QPainter : : Antialiasing ) ;
2020-11-01 20:28:57 +01:00
{
QTextEdit b ;
b . setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
b . setFixedSize ( full_area ) ;
b . setAcceptRichText ( true ) ;
b . setTextInteractionFlags ( Qt : : TextSelectableByMouse | Qt : : LinksAccessibleByMouse ) ;
b . document ( ) - > setHtml ( " <html> " + index . data ( Qt : : DisplayRole ) . toString ( ) + " </html> " ) ;
b . adjustSize ( ) ;
b . render ( & p , QPoint ( ) , QRegion ( ) , QWidget : : DrawChildren ) ; // draw the widgets, not the background
}
2020-10-30 23:22:52 +01:00
2020-11-01 20:28:57 +01:00
painter - > drawPixmap ( opt . rect . topLeft ( ) , px ) ;
2020-10-30 23:22:52 +01:00
const_cast < QAbstractItemModel * > ( index . model ( ) ) - > setData ( index , px . size ( ) , POST_CELL_SIZE_ROLE ) ;
}
private :
QFontMetricsF qf ;
} ;
void GxsCommentTreeWidget : : mouseMoveEvent ( QMouseEvent * e )
{
QModelIndex idx = indexAt ( e - > pos ( ) ) ;
if ( idx ! = selectionModel ( ) - > currentIndex ( ) )
selectionModel ( ) - > setCurrentIndex ( idx , QItemSelectionModel : : ClearAndSelect | QItemSelectionModel : : Rows ) ;
QTreeView : : mouseMoveEvent ( e ) ;
}
GxsCommentTreeWidget : : GxsCommentTreeWidget ( QWidget * parent )
: QTreeWidget ( parent ) , mTokenQueue ( NULL ) , mRsTokenService ( NULL ) , mCommentService ( NULL )
{
2020-10-26 18:49:38 +01:00
setVerticalScrollMode ( ScrollPerPixel ) ;
2013-03-13 00:33:14 +00:00
setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2017-04-08 14:06:47 +02:00
RSElidedItemDelegate * itemDelegate = new RSElidedItemDelegate ( this ) ;
itemDelegate - > setSpacing ( QSize ( 0 , 2 ) ) ;
setItemDelegate ( itemDelegate ) ;
setWordWrap ( true ) ;
2017-05-16 10:24:23 +02:00
2020-10-30 23:22:52 +01:00
setMouseTracking ( true ) ; // for auto selection
setSelectionBehavior ( QAbstractItemView : : SelectRows ) ;
2020-11-01 20:28:57 +01:00
# ifdef USE_NEW_DELEGATE
2020-10-30 23:22:52 +01:00
setItemDelegateForColumn ( PCITEM_COLUMN_COMMENT , new GxsCommentDelegate ( QFontMetricsF ( font ( ) ) ) ) ;
2020-11-01 20:28:57 +01:00
// Apparently the following below is needed, since there is no way to set item flags for a single column
// so after setting flags Qt will believe that all columns are editable.
setItemDelegateForColumn ( PCITEM_COLUMN_AUTHOR , new NoEditDelegate ( this ) ) ;
setItemDelegateForColumn ( PCITEM_COLUMN_DATE , new NoEditDelegate ( this ) ) ;
setItemDelegateForColumn ( PCITEM_COLUMN_SCORE , new NoEditDelegate ( this ) ) ;
setItemDelegateForColumn ( PCITEM_COLUMN_UPVOTES , new NoEditDelegate ( this ) ) ;
setItemDelegateForColumn ( PCITEM_COLUMN_DOWNVOTES , new NoEditDelegate ( this ) ) ;
setItemDelegateForColumn ( PCITEM_COLUMN_OWNVOTE , new NoEditDelegate ( this ) ) ;
# else
setItemDelegateForColumn ( PCITEM_COLUMN_COMMENT , new MultiLinesCommentDelegate ( QFontMetricsF ( font ( ) ) ) ) ;
# endif
2019-03-26 18:35:10 +01:00
commentsRole = new RSTreeWidgetItemCompareRole ;
commentsRole - > setRole ( PCITEM_COLUMN_DATE , ROLE_SORT ) ;
2017-05-16 10:24:23 +02:00
2020-10-30 23:22:52 +01:00
setEditTriggers ( QAbstractItemView : : CurrentChanged | QAbstractItemView : : SelectedClicked ) ;
2020-09-18 23:12:48 +02:00
mUseCache = false ;
2020-11-01 20:28:57 +01:00
QObject : : connect ( header ( ) , SIGNAL ( geometriesChanged ( ) ) , this , SLOT ( updateContent ( ) ) ) ;
QObject : : connect ( header ( ) , SIGNAL ( sectionResized ( int , int , int ) ) , this , SLOT ( updateContent ( ) ) ) ;
2012-11-25 21:50:45 +00:00
2020-11-01 20:28:57 +01:00
//header()->setSectionResizeMode(PCITEM_COLUMN_COMMENT,QHeaderView::ResizeToContents);
return ;
}
2012-11-25 21:50:45 +00:00
2020-11-01 20:28:57 +01:00
void GxsCommentTreeWidget : : updateContent ( )
{
model ( ) - > dataChanged ( QModelIndex ( ) , QModelIndex ( ) ) ;
2012-11-25 21:50:45 +00:00
2020-11-01 20:28:57 +01:00
std : : cerr < < " Updating content " < < std : : endl ;
2012-08-01 01:47:53 +00:00
}
2014-10-12 10:46:09 +00:00
GxsCommentTreeWidget : : ~ GxsCommentTreeWidget ( )
{
if ( mTokenQueue ) {
delete ( mTokenQueue ) ;
}
}
2017-05-18 22:31:52 +02:00
void GxsCommentTreeWidget : : setCurrentCommentMsgId ( QTreeWidgetItem * current , QTreeWidgetItem * previous )
2012-11-25 21:50:45 +00:00
{
2013-03-13 00:33:14 +00:00
Q_UNUSED ( previous ) ;
2012-11-25 21:50:45 +00:00
2013-03-13 00:33:14 +00:00
if ( current )
{
2017-05-18 22:31:52 +02:00
mCurrentCommentMsgId = RsGxsMessageId ( current - > text ( PCITEM_COLUMN_MSGID ) . toStdString ( ) ) ;
2017-11-18 19:48:38 +01:00
mCurrentCommentText = current - > text ( PCITEM_COLUMN_COMMENT ) ;
2019-01-10 00:12:38 +01:00
mCurrentCommentAuthor = current - > text ( PCITEM_COLUMN_AUTHOR ) ;
mCurrentCommentAuthorId = RsGxsId ( current - > text ( PCITEM_COLUMN_AUTHORID ) . toStdString ( ) ) ;
2013-03-13 00:33:14 +00:00
}
2012-11-25 21:50:45 +00:00
}
2014-10-12 10:46:09 +00:00
void GxsCommentTreeWidget : : customPopUpMenu ( const QPoint & /*point*/ )
2012-11-25 21:50:45 +00:00
{
2013-03-13 00:33:14 +00:00
QMenu contextMnu ( this ) ;
2020-10-15 20:12:00 +02:00
QAction * action = contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_REPLY ) , tr ( " Reply to Comment " ) , this , SLOT ( replyToComment ( ) ) ) ;
2017-05-18 22:31:52 +02:00
action - > setDisabled ( mCurrentCommentMsgId . isNull ( ) ) ;
2020-04-19 17:41:13 +02:00
action = contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_MESSAGE ) , tr ( " Submit Comment " ) , this , SLOT ( makeComment ( ) ) ) ;
2017-05-18 22:31:52 +02:00
action - > setDisabled ( mMsgVersions . empty ( ) ) ;
2020-04-19 17:41:13 +02:00
action = contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_COPY ) , tr ( " Copy Comment " ) , this , SLOT ( copyComment ( ) ) ) ;
2017-11-18 19:48:38 +01:00
action - > setDisabled ( mCurrentCommentMsgId . isNull ( ) ) ;
2013-03-13 00:33:14 +00:00
contextMnu . addSeparator ( ) ;
2020-04-19 17:41:13 +02:00
action = contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_VOTEUP ) , tr ( " Vote Up " ) , this , SLOT ( voteUp ( ) ) ) ;
2014-03-17 20:56:06 +00:00
action - > setDisabled ( mVoterId . isNull ( ) ) ;
2020-04-19 17:41:13 +02:00
action = contextMnu . addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_VOTEDOWN ) , tr ( " Vote Down " ) , this , SLOT ( voteDown ( ) ) ) ;
2014-03-17 20:56:06 +00:00
action - > setDisabled ( mVoterId . isNull ( ) ) ;
2013-03-13 00:33:14 +00:00
2017-05-18 22:31:52 +02:00
if ( ! mCurrentCommentMsgId . isNull ( ) )
2013-03-13 00:33:14 +00:00
{
2015-05-08 18:08:27 +00:00
// not implemented yet
/*
2013-03-13 00:33:14 +00:00
contextMnu . addSeparator ( ) ;
QMenu * rep_menu = contextMnu . addMenu ( tr ( " Reputation " ) ) ;
2020-08-15 22:17:52 +02:00
action = rep_menu - > addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_MESSAGE ) , tr ( " Show Reputation " ) , this , SLOT ( showReputation ( ) ) ) ;
2013-03-13 00:33:14 +00:00
contextMnu . addSeparator ( ) ;
2020-08-15 22:17:52 +02:00
action = rep_menu - > addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_MESSAGE ) , tr ( " Interesting User " ) , this , SLOT ( markInteresting ( ) ) ) ;
2013-03-13 00:33:14 +00:00
contextMnu . addSeparator ( ) ;
2020-08-15 22:17:52 +02:00
action = rep_menu - > addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_MESSAGE ) , tr ( " Mark Spammy " ) , this , SLOT ( markSpammer ( ) ) ) ;
action = rep_menu - > addAction ( FilesDefs : : getIconFromQtResourcePath ( IMAGE_MESSAGE ) , tr ( " Ban User " ) , this , SLOT ( banUser ( ) ) ) ;
2015-05-08 18:08:27 +00:00
*/
2013-03-13 00:33:14 +00:00
}
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
void GxsCommentTreeWidget : : voteUp ( )
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::voteUp() " ;
2013-03-13 00:33:14 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2017-05-18 22:31:52 +02:00
vote ( mGroupId , mLatestMsgId , mCurrentCommentMsgId , mVoterId , true ) ;
2013-03-13 00:33:14 +00:00
}
void GxsCommentTreeWidget : : voteDown ( )
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::voteDown() " ;
2013-03-13 00:33:14 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2017-05-18 22:31:52 +02:00
vote ( mGroupId , mLatestMsgId , mCurrentCommentMsgId , mVoterId , false ) ;
2013-03-13 00:33:14 +00:00
}
void GxsCommentTreeWidget : : setVoteId ( const RsGxsId & voterId )
{
mVoterId = voterId ;
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::setVoterId( " < < mVoterId < < " ) " ;
2013-03-13 00:33:14 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2013-03-13 00:33:14 +00:00
}
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 ;
}
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
2013-03-13 00:33:14 +00:00
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 ;
2020-09-10 20:16:10 +02:00
# endif
2013-03-13 00:33:14 +00:00
uint32_t token ;
2019-02-14 21:58:33 +01:00
mCommentService - > createNewVote ( token , vote ) ;
2013-03-15 21:02:43 +00:00
mTokenQueue - > queueRequest ( token , TOKENREQ_MSGINFO , RS_TOKREQ_ANSTYPE_ACK , COMMENT_VOTE_ACK ) ;
2013-03-13 00:33:14 +00:00
}
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 ;
2012-11-25 21:50:45 +00:00
}
void GxsCommentTreeWidget : : makeComment ( )
{
2020-10-01 21:25:32 +02:00
GxsCreateCommentDialog pcc ( mCommentService , std : : make_pair ( mGroupId , mLatestMsgId ) , mLatestMsgId , mVoterId , this ) ;
2013-03-13 00:33:14 +00:00
pcc . exec ( ) ;
2012-11-30 18:54:25 +00:00
}
2012-11-25 21:50:45 +00:00
2012-11-30 18:54:25 +00:00
void GxsCommentTreeWidget : : replyToComment ( )
{
2013-03-13 00:33:14 +00:00
RsGxsGrpMsgIdPair msgId ;
2017-05-18 22:31:52 +02:00
msgId . first = mGroupId ;
msgId . second = mCurrentCommentMsgId ;
2020-10-01 21:25:32 +02:00
GxsCreateCommentDialog pcc ( mCommentService , msgId , mLatestMsgId , mVoterId , this ) ;
2019-01-10 00:12:38 +01:00
pcc . loadComment ( mCurrentCommentText , mCurrentCommentAuthor , mCurrentCommentAuthorId ) ;
2013-03-13 00:33:14 +00:00
pcc . exec ( ) ;
2012-11-25 21:50:45 +00:00
}
2017-11-18 19:48:38 +01:00
void GxsCommentTreeWidget : : copyComment ( )
{
QMimeData * mimeData = new QMimeData ( ) ;
mimeData - > setHtml ( " <html> " + mCurrentCommentText + " </html> " ) ;
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setMimeData ( mimeData , QClipboard : : Clipboard ) ;
}
2013-03-11 20:53:15 +00:00
void GxsCommentTreeWidget : : setup ( RsTokenService * token_service , RsGxsCommentService * comment_service )
2012-08-01 01:47:53 +00:00
{
2013-03-13 00:33:14 +00:00
mRsTokenService = token_service ;
mCommentService = comment_service ;
mTokenQueue = new TokenQueue ( token_service , this ) ;
connect ( this , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( customPopUpMenu ( QPoint ) ) ) ;
2017-05-20 17:53:25 +02:00
connect ( this , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( setCurrentCommentMsgId ( QTreeWidgetItem * , QTreeWidgetItem * ) ) ) ;
2012-08-01 01:47:53 +00:00
2013-03-13 00:33:14 +00:00
return ;
2012-08-01 01:47:53 +00:00
}
/* Load Comments */
2017-05-18 22:31:52 +02:00
void GxsCommentTreeWidget : : requestComments ( const RsGxsGroupId & group , const std : : set < RsGxsMessageId > & message_versions , const RsGxsMessageId & most_recent_message )
2012-08-01 01:47:53 +00:00
{
2013-03-13 00:33:14 +00:00
/* request comments */
2012-08-01 01:47:53 +00:00
2017-05-18 22:31:52 +02:00
mGroupId = group ;
mMsgVersions = message_versions ;
mLatestMsgId = most_recent_message ;
2020-09-18 23:12:48 +02:00
if ( mUseCache )
{
QMutexLocker lock ( & mCacheMutex ) ;
auto it = mCommentsCache . find ( most_recent_message ) ;
if ( it ! = mCommentsCache . end ( ) )
{
std : : cerr < < " Got " < < it - > second . size ( ) < < " comments from cache. " < < std : : endl ;
insertComments ( it - > second ) ;
completeItems ( ) ;
}
}
2017-05-18 22:31:52 +02:00
service_requestComments ( group , message_versions ) ;
2012-08-01 01:47:53 +00:00
}
2020-04-03 10:54:06 +02:00
2017-05-18 22:31:52 +02:00
void GxsCommentTreeWidget : : service_requestComments ( const RsGxsGroupId & group_id , const std : : set < RsGxsMessageId > & msgIds )
2012-08-01 01:47:53 +00:00
{
2013-03-13 00:33:14 +00:00
/* request comments */
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::service_requestComments for group " < < group_id < < std : : endl ;
# endif
2017-05-18 22:31:52 +02:00
std : : vector < RsGxsGrpMsgIdPair > ids_to_ask ;
for ( std : : set < RsGxsMessageId > : : const_iterator it ( msgIds . begin ( ) ) ; it ! = msgIds . end ( ) ; + + it )
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " asking for msg " < < * it < < std : : endl ;
# endif
2017-05-18 22:31:52 +02:00
ids_to_ask . push_back ( std : : make_pair ( group_id , * it ) ) ;
}
2012-11-30 18:54:25 +00:00
2013-03-13 00:33:14 +00:00
RsTokReqOptions opts ;
opts . mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA ;
opts . mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST ;
2012-11-30 18:54:25 +00:00
2013-03-13 00:33:14 +00:00
uint32_t token ;
2017-05-18 22:31:52 +02:00
mTokenQueue - > requestMsgRelatedInfo ( token , RS_TOKREQ_ANSTYPE_DATA , opts , ids_to_ask , GXSCOMMENTS_LOADTHREAD ) ;
2012-08-01 01:47:53 +00:00
}
/* Generic Handling */
void GxsCommentTreeWidget : : clearItems ( )
{
2013-03-13 00:33:14 +00:00
mPendingInsertMap . clear ( ) ;
mLoadingMap . clear ( ) ;
2012-08-01 01:47:53 +00:00
}
void GxsCommentTreeWidget : : completeItems ( )
{
2013-03-13 00:33:14 +00:00
/* handle pending items */
2014-03-17 20:56:06 +00:00
RsGxsMessageId parentId ;
2013-03-13 00:33:14 +00:00
QTreeWidgetItem * parent = NULL ;
QList < QTreeWidgetItem * > topLevelItems ;
2014-03-17 20:56:06 +00:00
std : : map < RsGxsMessageId , QTreeWidgetItem * > : : iterator lit ;
std : : multimap < RsGxsMessageId , QTreeWidgetItem * > : : iterator pit ;
2012-08-01 01:47:53 +00:00
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::completeItems() " < < mPendingInsertMap . size ( ) ;
2013-03-13 00:33:14 +00:00
std : : cerr < < " PendingItems " ;
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2012-08-01 01:47:53 +00:00
2014-10-21 22:33:02 +00:00
for ( pit = mPendingInsertMap . begin ( ) ; pit ! = mPendingInsertMap . end ( ) ; + + pit )
2013-03-13 00:33:14 +00:00
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::completeItems() item->parent: " < < pit - > first ;
2013-03-13 00:33:14 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2012-08-01 01:47:53 +00:00
2013-03-13 00:33:14 +00:00
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 )
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::completeItems() Added to Parent " ;
2013-03-13 00:33:14 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2013-03-13 00:33:14 +00:00
parent - > addChild ( pit - > second ) ;
}
2017-05-18 22:31:52 +02:00
else if ( mMsgVersions . find ( parentId ) ! = mMsgVersions . end ( ) )
2013-03-13 00:33:14 +00:00
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::completeItems() Added to topLevelItems " ;
2013-03-13 00:33:14 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2013-03-13 00:33:14 +00:00
topLevelItems . append ( pit - > second ) ;
}
else
{
/* missing parent -> insert At Top Level */
QTreeWidgetItem * missingItem = service_createMissingItem ( pit - > first ) ;
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::completeItems() Added MissingItem " ;
2013-03-13 00:33:14 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2013-03-13 00:33:14 +00:00
parent = missingItem ;
parent - > addChild ( pit - > second ) ;
topLevelItems . append ( parent ) ;
}
}
2012-08-01 01:47:53 +00:00
2013-03-13 00:33:14 +00:00
/* now push final tree into Tree */
clear ( ) ;
insertTopLevelItems ( 0 , topLevelItems ) ;
/* cleanup temp stuff */
mLoadingMap . clear ( ) ;
mPendingInsertMap . clear ( ) ;
2012-08-01 01:47:53 +00:00
}
2014-03-17 20:56:06 +00:00
void GxsCommentTreeWidget : : addItem ( RsGxsMessageId itemId , RsGxsMessageId parentId , QTreeWidgetItem * item )
2012-08-01 01:47:53 +00:00
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::addItem() Id: " < < itemId ;
2012-08-01 01:47:53 +00:00
std : : cerr < < " ParentId: " < < parentId ;
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2012-08-01 01:47:53 +00:00
/* store in map -> for children */
mLoadingMap [ itemId ] = item ;
2014-03-17 20:56:06 +00:00
std : : map < RsGxsMessageId , QTreeWidgetItem * > : : iterator it ;
2012-08-01 01:47:53 +00:00
it = mLoadingMap . find ( parentId ) ;
if ( it ! = mLoadingMap . end ( ) )
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::addItem() Added to Parent " ;
2012-08-01 01:47:53 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2012-08-01 01:47:53 +00:00
it - > second - > addChild ( item ) ;
}
else
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std : : cerr < < " GxsCommentTreeWidget::addItem() Added to Pending List " ;
2012-08-01 01:47:53 +00:00
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2012-08-01 01:47:53 +00:00
mPendingInsertMap . insert ( std : : make_pair ( parentId , item ) ) ;
}
}
2020-09-09 23:14:20 +02:00
int treeCount ( QTreeWidget * tree , QTreeWidgetItem * parent = 0 )
{
int count = 0 ;
if ( parent = = 0 ) {
int topCount = tree - > topLevelItemCount ( ) ;
for ( int i = 0 ; i < topCount ; i + + ) {
QTreeWidgetItem * item = tree - > topLevelItem ( i ) ;
if ( item - > isExpanded ( ) ) {
count + = treeCount ( tree , item ) ;
}
}
count + = topCount ;
} else {
int childCount = parent - > childCount ( ) ;
for ( int i = 0 ; i < childCount ; i + + ) {
QTreeWidgetItem * item = parent - > child ( i ) ;
if ( item - > isExpanded ( ) ) {
count + = treeCount ( tree , item ) ;
}
}
count + = childCount ;
}
return count ;
}
2012-08-01 01:47:53 +00:00
void GxsCommentTreeWidget : : loadThread ( const uint32_t & token )
{
clearItems ( ) ;
service_loadThread ( token ) ;
completeItems ( ) ;
2020-09-09 23:14:20 +02:00
emit commentsLoaded ( treeCount ( this ) ) ;
2012-08-01 01:47:53 +00:00
}
2012-11-25 21:50:45 +00:00
void GxsCommentTreeWidget : : acknowledgeComment ( const uint32_t & token )
{
2013-03-13 00:33:14 +00:00
RsGxsGrpMsgIdPair msgId ;
mCommentService - > acknowledgeComment ( token , msgId ) ;
2012-11-25 21:50:45 +00:00
2013-03-13 00:33:14 +00:00
// simply reload data
2017-05-18 22:31:52 +02:00
service_requestComments ( mGroupId , mMsgVersions ) ;
2012-11-25 21:50:45 +00:00
}
2012-08-01 01:47:53 +00:00
2013-03-15 21:02:43 +00:00
void GxsCommentTreeWidget : : acknowledgeVote ( const uint32_t & token )
{
RsGxsGrpMsgIdPair msgId ;
if ( mCommentService - > acknowledgeVote ( token , msgId ) )
{
// reload data if vote was added.
2017-05-18 22:31:52 +02:00
service_requestComments ( mGroupId , mMsgVersions ) ;
2013-03-15 21:02:43 +00:00
}
}
2012-08-01 01:47:53 +00:00
void GxsCommentTreeWidget : : service_loadThread ( const uint32_t & token )
{
2013-03-13 00:33:14 +00:00
std : : cerr < < " GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded! " ;
std : : cerr < < std : : endl ;
2012-08-01 01:47:53 +00:00
2013-03-13 00:33:14 +00:00
std : : vector < RsGxsComment > comments ;
mCommentService - > getRelatedComments ( token , comments ) ;
2012-08-01 01:47:53 +00:00
2020-09-18 23:12:48 +02:00
// This is inconsistent since we cannot know here that all comments are for the same thread. However they are only
// requested in requestComments() where a single MsgId is used.
if ( mUseCache )
{
QMutexLocker lock ( & mCacheMutex ) ;
2012-11-25 21:50:45 +00:00
2020-09-18 23:12:48 +02:00
if ( ! comments . empty ( ) )
{
std : : cerr < < " Updating cache with " < < comments . size ( ) < < " for thread " < < comments [ 0 ] . mMeta . mThreadId < < std : : endl ;
mCommentsCache [ comments [ 0 ] . mMeta . mThreadId ] = comments ;
}
}
insertComments ( comments ) ;
}
void GxsCommentTreeWidget : : insertComments ( const std : : vector < RsGxsComment > & comments )
{
for ( auto vit = comments . begin ( ) ; vit ! = comments . end ( ) ; + + vit )
2013-03-13 00:33:14 +00:00
{
2020-09-18 23:12:48 +02:00
const RsGxsComment & comment = * vit ;
2013-03-13 00:33:14 +00:00
/* convert to a QTreeWidgetItem */
std : : cerr < < " GxsCommentTreeWidget::service_loadThread() Got Comment: " < < comment . mMeta . mMsgId ;
std : : cerr < < std : : endl ;
2012-11-25 21:50:45 +00:00
2019-01-10 00:12:38 +01:00
GxsIdRSTreeWidgetItem * item = new GxsIdRSTreeWidgetItem ( NULL , GxsIdDetails : : ICON_TYPE_AVATAR ) ;
2013-03-13 00:33:14 +00:00
QString text ;
2012-08-01 01:47:53 +00:00
2013-03-13 00:33:14 +00:00
{
2016-10-22 16:15:29 +02:00
QDateTime qtime ;
qtime . setTime_t ( comment . mMeta . mPublishTs ) ;
2012-08-01 01:47:53 +00:00
2016-10-22 16:15:29 +02:00
text = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
item - > setText ( PCITEM_COLUMN_DATE , text ) ;
item - > setToolTip ( PCITEM_COLUMN_DATE , text ) ;
2019-03-29 02:00:13 +01:00
item - > setData ( PCITEM_COLUMN_DATE , ROLE_SORT , QVariant ( qlonglong ( comment . mMeta . mPublishTs ) ) ) ;
2019-03-26 18:35:10 +01:00
2013-03-13 00:33:14 +00:00
}
2012-08-01 01:47:53 +00:00
2013-03-13 00:33:14 +00:00
text = QString : : fromUtf8 ( comment . mComment . c_str ( ) ) ;
2020-10-30 23:22:52 +01:00
item - > setText ( PCITEM_COLUMN_COMMENT , text ) ;
item - > setToolTip ( PCITEM_COLUMN_COMMENT , text ) ;
2012-08-01 01:47:53 +00:00
2020-10-30 23:22:52 +01:00
RsGxsId authorId = comment . mMeta . mAuthorId ;
2015-03-09 20:41:14 +00:00
item - > setId ( authorId , PCITEM_COLUMN_AUTHOR , false ) ;
2017-05-18 22:31:52 +02:00
item - > setData ( PCITEM_COLUMN_COMMENT , POST_COLOR_ROLE , QVariant ( authorId . toByteArray ( ) [ 1 ] ) ) ;
2012-08-01 01:47:53 +00:00
2020-10-30 23:22:52 +01:00
text = QString : : number ( comment . mScore ) ;
2013-03-13 00:33:14 +00:00
item - > setText ( PCITEM_COLUMN_SCORE , text ) ;
2012-11-25 21:50:45 +00:00
2013-03-13 00:33:14 +00:00
text = QString : : number ( comment . mUpVotes ) ;
item - > setText ( PCITEM_COLUMN_UPVOTES , text ) ;
2012-11-25 21:50:45 +00:00
2013-03-13 00:33:14 +00:00
text = QString : : number ( comment . mDownVotes ) ;
item - > setText ( PCITEM_COLUMN_DOWNVOTES , text ) ;
2012-11-25 21:50:45 +00:00
2013-03-15 21:02:43 +00:00
text = QString : : number ( comment . mOwnVote ) ;
item - > setText ( PCITEM_COLUMN_OWNVOTE , text ) ;
2014-03-17 20:56:06 +00:00
text = QString : : fromUtf8 ( comment . mMeta . mMsgId . toStdString ( ) . c_str ( ) ) ;
2013-03-13 00:33:14 +00:00
item - > setText ( PCITEM_COLUMN_MSGID , text ) ;
2014-03-17 20:56:06 +00:00
text = QString : : fromUtf8 ( comment . mMeta . mParentId . toStdString ( ) . c_str ( ) ) ;
2013-03-13 00:33:14 +00:00
item - > setText ( PCITEM_COLUMN_PARENTID , text ) ;
2019-01-10 00:12:38 +01:00
text = QString : : fromUtf8 ( comment . mMeta . mAuthorId . toStdString ( ) . c_str ( ) ) ;
item - > setText ( PCITEM_COLUMN_AUTHORID , text ) ;
2013-03-13 00:33:14 +00:00
2020-11-01 20:28:57 +01:00
# ifdef USE_NEW_DELEGATE
// Allows to call createEditor() in the delegate. Without this, createEditor() is never called in
// the styled item delegate.
item - > setFlags ( Qt : : ItemIsEditable | item - > flags ( ) ) ;
# endif
2013-03-13 00:33:14 +00:00
addItem ( comment . mMeta . mMsgId , comment . mMeta . mParentId , item ) ;
}
2012-08-01 01:47:53 +00:00
}
2012-11-25 21:50:45 +00:00
QTreeWidgetItem * GxsCommentTreeWidget : : service_createMissingItem ( const RsGxsMessageId & parent )
2012-08-01 01:47:53 +00:00
{
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 ) ;
2019-01-10 00:12:38 +01:00
item - > setText ( PCITEM_COLUMN_AUTHORID , text ) ;
2012-08-01 01:47:53 +00:00
2014-03-17 20:56:06 +00:00
text = QString : : fromUtf8 ( parent . toStdString ( ) . c_str ( ) ) ;
2012-08-01 01:47:53 +00:00
item - > setText ( PCITEM_COLUMN_PARENTID , text ) ;
return item ;
}
2012-11-25 21:50:45 +00:00
2012-10-21 19:45:35 +00:00
void GxsCommentTreeWidget : : loadRequest ( const TokenQueue * queue , const TokenRequest & req )
2012-08-01 01:47:53 +00:00
{
2020-09-10 20:16:10 +02:00
# ifdef DEBUG_GXSCOMMENT_TREEWIDGET
2012-08-01 01:47:53 +00:00
std : : cerr < < " GxsCommentTreeWidget::loadRequest() UserType: " < < req . mUserType ;
std : : cerr < < std : : endl ;
2020-09-10 20:16:10 +02:00
# endif
2012-08-01 01:47:53 +00:00
if ( queue ! = mTokenQueue )
{
std : : cerr < < " GxsCommentTreeWidget::loadRequest() Queue ERROR " ;
std : : cerr < < std : : endl ;
return ;
}
/* now switch on req */
2013-03-13 00:33:14 +00:00
switch ( req . mType )
2012-08-01 01:47:53 +00:00
{
2013-03-13 00:33:14 +00:00
case TOKENREQ_MSGINFO :
{
switch ( req . mAnsType )
{
case RS_TOKREQ_ANSTYPE_ACK :
2013-03-15 21:02:43 +00:00
if ( req . mUserType = = COMMENT_VOTE_ACK )
{
acknowledgeVote ( req . mToken ) ;
}
else
{
acknowledgeComment ( req . mToken ) ;
}
2013-03-13 00:33:14 +00:00
break ;
case RS_TOKREQ_ANSTYPE_DATA :
loadThread ( req . mToken ) ;
break ;
}
}
break ;
default :
std : : cerr < < " GxsCommentTreeWidget::loadRequest() UNKNOWN UserType " ;
std : : cerr < < std : : endl ;
break ;
2012-08-01 01:47:53 +00:00
}
}