2012-06-13 20:36:25 -04:00
/****************************************************************
* 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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-11-12 15:47:55 -05:00
# include "CreateGxsForumMsg.h"
2012-06-13 20:36:25 -04:00
# include <QMessageBox>
# include <QFile>
# include <QDesktopWidget>
# include <QDropEvent>
# include <QPushButton>
2012-11-12 15:47:55 -05:00
# include <retroshare/rsgxsforums.h>
2012-06-13 20:36:25 -04:00
# include "gui/settings/rsharesettings.h"
# include "gui/RetroShareLink.h"
# include "gui/common/Emoticons.h"
2013-07-12 13:24:11 -04:00
# include "gui/common/UIStateHelper.h"
2014-07-06 07:19:58 -04:00
# include "gui/Identity/IdDialog.h"
2012-06-13 20:36:25 -04:00
2012-11-19 16:35:48 -05:00
# include "util/HandleRichText.h"
2012-06-13 20:36:25 -04:00
# include "util/misc.h"
# include <sys/stat.h>
2012-07-28 17:09:53 -04:00
# include <iostream>
2012-11-12 15:47:55 -05:00
# define CREATEGXSFORUMMSG_FORUMINFO 1
# define CREATEGXSFORUMMSG_PARENTMSG 2
2012-06-13 20:36:25 -04:00
2013-07-19 17:06:19 -04:00
//#define ENABLE_GENERATE
2012-06-13 20:36:25 -04:00
/** Constructor */
2014-03-17 16:56:06 -04:00
CreateGxsForumMsg : : CreateGxsForumMsg ( const RsGxsGroupId & fId , const RsGxsMessageId & pId )
2012-11-21 13:55:52 -05:00
: QDialog ( NULL , Qt : : WindowSystemMenuHint | Qt : : WindowTitleHint | Qt : : WindowMinMaxButtonsHint | Qt : : WindowCloseButtonHint ) , mForumId ( fId ) , mParentId ( pId )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2013-07-12 13:24:11 -04:00
2013-01-07 17:11:16 -05:00
setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
2012-06-13 20:36:25 -04:00
2012-07-28 17:09:53 -04:00
/* Setup Queue */
2012-11-12 15:47:55 -05:00
mForumQueue = new TokenQueue ( rsGxsForums - > getTokenService ( ) , this ) ;
2013-07-12 13:24:11 -04:00
/* Setup UI helper */
mStateHelper = new UIStateHelper ( this ) ;
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_FORUMINFO , ui . buttonBox - > button ( QDialogButtonBox : : Ok ) ) ;
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_FORUMINFO , ui . innerFrame ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_FORUMINFO , ui . forumName ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_FORUMINFO , ui . forumSubject ) ;
mStateHelper - > addClear ( CREATEGXSFORUMMSG_FORUMINFO , ui . forumName ) ;
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_PARENTMSG , ui . buttonBox - > button ( QDialogButtonBox : : Ok ) ) ;
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_PARENTMSG , ui . innerFrame ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_PARENTMSG , ui . forumName ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_PARENTMSG , ui . forumSubject ) ;
mStateHelper - > addClear ( CREATEGXSFORUMMSG_PARENTMSG , ui . forumName ) ;
2014-03-17 16:56:06 -04:00
QString text = pId . isNull ( ) ? tr ( " Start New Thread " ) : tr ( " Post Forum Message " ) ;
2013-01-07 17:11:16 -05:00
setWindowTitle ( text ) ;
2012-11-21 13:55:52 -05:00
2013-01-07 17:11:16 -05:00
ui . headerFrame - > setHeaderImage ( QPixmap ( " :/images/konversation64.png " ) ) ;
ui . headerFrame - > setHeaderText ( text ) ;
2012-07-28 17:09:53 -04:00
2013-07-19 17:06:19 -04:00
ui . generateSpinBox - > setEnabled ( false ) ;
2013-01-07 17:11:16 -05:00
Settings - > loadWidgetInformation ( this ) ;
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
connect ( ui . hashBox , SIGNAL ( fileHashingFinished ( QList < HashedFile > ) ) , this , SLOT ( fileHashingFinished ( QList < HashedFile > ) ) ) ;
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
// connect up the buttons.
connect ( ui . buttonBox , SIGNAL ( accepted ( ) ) , this , SLOT ( createMsg ( ) ) ) ;
connect ( ui . buttonBox , SIGNAL ( rejected ( ) ) , this , SLOT ( close ( ) ) ) ;
connect ( ui . emoticonButton , SIGNAL ( clicked ( ) ) , this , SLOT ( smileyWidgetForums ( ) ) ) ;
connect ( ui . attachFileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addFile ( ) ) ) ;
2013-07-19 17:06:19 -04:00
connect ( ui . generateCheckBox , SIGNAL ( toggled ( bool ) ) , ui . generateSpinBox , SLOT ( setEnabled ( bool ) ) ) ;
2014-07-06 07:19:58 -04:00
connect ( ui . toolButton_NewId , SIGNAL ( clicked ( ) ) , this , SLOT ( createNewGxsId ( ) ) ) ;
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
setAcceptDrops ( true ) ;
ui . hashBox - > setDropWidget ( this ) ;
ui . hashBox - > setAutoHide ( false ) ;
2012-06-13 20:36:25 -04:00
2012-07-28 17:09:53 -04:00
mParentMsgLoaded = false ;
mForumMetaLoaded = false ;
2013-01-07 17:11:16 -05:00
newMsg ( ) ;
2013-07-19 17:06:19 -04:00
# ifndef ENABLE_GENERATE
ui . generateCheckBox - > hide ( ) ;
ui . generateSpinBox - > hide ( ) ;
# endif
2013-01-07 17:11:16 -05:00
}
CreateGxsForumMsg : : ~ CreateGxsForumMsg ( )
{
delete ( mForumQueue ) ;
2012-06-13 20:36:25 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : newMsg ( )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
/* clear all */
2012-07-28 17:09:53 -04:00
mParentMsgLoaded = false ;
mForumMetaLoaded = false ;
2012-11-19 17:14:45 -05:00
/* fill in the available OwnIds for signing */
2014-03-17 16:56:06 -04:00
ui . idChooser - > loadIds ( IDCHOOSER_ID_REQUIRED , RsGxsId ( ) ) ;
2012-11-19 17:14:45 -05:00
2014-03-17 16:56:06 -04:00
if ( mForumId . isNull ( ) ) {
2013-07-12 13:24:11 -04:00
mStateHelper - > setActive ( CREATEGXSFORUMMSG_FORUMINFO , false ) ;
mStateHelper - > setActive ( CREATEGXSFORUMMSG_PARENTMSG , false ) ;
mStateHelper - > clear ( CREATEGXSFORUMMSG_FORUMINFO ) ;
mStateHelper - > clear ( CREATEGXSFORUMMSG_PARENTMSG ) ;
2013-01-07 17:11:16 -05:00
ui . forumName - > setText ( tr ( " No Forum " ) ) ;
return ;
2014-07-06 07:19:58 -04:00
} //if ( mForumId.isNull())
2013-01-07 17:11:16 -05:00
2014-07-06 07:19:58 -04:00
{ /* request Data */
2013-07-12 13:24:11 -04:00
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_FORUMINFO , true ) ;
2012-07-28 17:09:53 -04:00
RsTokReqOptions opts ;
2013-01-07 17:11:16 -05:00
opts . mReqType = GXS_REQUEST_TYPE_GROUP_META ;
2014-03-17 16:56:06 -04:00
std : : list < RsGxsGroupId > groupIds ;
2012-07-28 17:09:53 -04:00
groupIds . push_back ( mForumId ) ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
std : : cerr < < " ForumsV2Dialog::newMsg() Requesting Group Summary( " < < mForumId < < " ) " ;
std : : cerr < < std : : endl ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
uint32_t token ;
2012-11-12 15:47:55 -05:00
mForumQueue - > requestGroupInfo ( token , RS_TOKREQ_ANSTYPE_SUMMARY , opts , groupIds , CREATEGXSFORUMMSG_FORUMINFO ) ;
2014-07-06 07:19:58 -04:00
} /* request Data */
2012-07-28 17:09:53 -04:00
2014-07-06 07:19:58 -04:00
if ( mParentId . isNull ( ) ) {
2013-07-12 13:24:11 -04:00
mStateHelper - > setActive ( CREATEGXSFORUMMSG_PARENTMSG , true ) ;
2013-01-07 17:11:16 -05:00
mParentMsgLoaded = true ;
2014-07-06 07:19:58 -04:00
} else {
2013-07-12 13:24:11 -04:00
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_PARENTMSG , true ) ;
2012-07-28 17:09:53 -04:00
RsTokReqOptions opts ;
2013-01-07 17:11:16 -05:00
opts . mReqType = GXS_REQUEST_TYPE_MSG_DATA ;
GxsMsgReq msgIds ;
std : : vector < RsGxsMessageId > & vect = msgIds [ mForumId ] ;
vect . push_back ( mParentId ) ;
2012-07-28 17:09:53 -04:00
std : : cerr < < " ForumsV2Dialog::newMsg() Requesting Parent Summary( " < < mParentId < < " ) " ;
std : : cerr < < std : : endl ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
uint32_t token ;
2013-01-07 17:11:16 -05:00
mForumQueue - > requestMsgInfo ( token , RS_TOKREQ_ANSTYPE_DATA , opts , msgIds , CREATEGXSFORUMMSG_PARENTMSG ) ;
2014-07-06 07:19:58 -04:00
} //if (mParentId.isNull())
2012-07-28 17:09:53 -04:00
}
2012-06-13 20:36:25 -04:00
2013-07-12 13:24:11 -04:00
void CreateGxsForumMsg : : loadFormInformation ( )
2012-07-28 17:09:53 -04:00
{
2014-03-17 16:56:06 -04:00
if ( ! mParentId . isNull ( ) ) {
2013-07-12 13:24:11 -04:00
if ( mParentMsgLoaded ) {
mStateHelper - > setActive ( CREATEGXSFORUMMSG_PARENTMSG , true ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_PARENTMSG , false ) ;
} else {
std : : cerr < < " CreateGxsForumMsg::loadMsgInformation() ParentMsg not Loaded Yet " ;
std : : cerr < < std : : endl ;
2013-01-07 17:11:16 -05:00
2013-07-12 13:24:11 -04:00
mStateHelper - > setActive ( CREATEGXSFORUMMSG_PARENTMSG , false ) ;
2012-06-13 20:36:25 -04:00
2013-07-12 13:24:11 -04:00
return ;
}
} else {
mStateHelper - > setActive ( CREATEGXSFORUMMSG_PARENTMSG , true ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_PARENTMSG , false ) ;
2012-07-28 17:09:53 -04:00
}
2013-01-07 17:11:16 -05:00
2013-07-12 13:24:11 -04:00
if ( mForumMetaLoaded ) {
mStateHelper - > setActive ( CREATEGXSFORUMMSG_FORUMINFO , true ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_FORUMINFO , false ) ;
} else {
2012-11-12 15:47:55 -05:00
std : : cerr < < " CreateGxsForumMsg::loadMsgInformation() ForumMeta not Loaded Yet " ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
2013-07-12 13:24:11 -04:00
mStateHelper - > setActive ( CREATEGXSFORUMMSG_FORUMINFO , false ) ;
2012-07-28 17:09:53 -04:00
return ;
}
2013-01-07 17:11:16 -05:00
2012-11-12 15:47:55 -05:00
std : : cerr < < " CreateGxsForumMsg::loadMsgInformation() Data Available! " ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
QString name = QString : : fromUtf8 ( mForumMeta . mGroupName . c_str ( ) ) ;
QString subj ;
2014-03-17 16:56:06 -04:00
if ( ! mParentId . isNull ( ) )
2012-07-28 17:09:53 -04:00
{
QString title = QString : : fromUtf8 ( mParentMsg . mMeta . mMsgName . c_str ( ) ) ;
name + = " " + tr ( " In Reply to " ) + " : " ;
name + = title ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
QString text = title ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
subj = title ;
}
else
{
subj = " Re: " + title ;
}
}
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
ui . forumName - > setText ( misc : : removeNewLine ( name ) ) ;
ui . forumSubject - > setText ( misc : : removeNewLine ( subj ) ) ;
2013-01-07 17:11:16 -05:00
if ( ui . forumSubject - > text ( ) . isEmpty ( ) )
2012-07-28 17:09:53 -04:00
{
2013-01-07 17:11:16 -05:00
ui . forumSubject - > setFocus ( ) ;
2012-07-28 17:09:53 -04:00
}
else
{
2013-01-07 17:11:16 -05:00
ui . forumMessage - > setFocus ( ) ;
2012-07-28 17:09:53 -04:00
}
2013-01-07 17:11:16 -05:00
2012-11-12 15:47:55 -05:00
# ifdef TOGXS
2012-07-28 17:09:53 -04:00
if ( mForumMeta . mGroupFlags & RS_DISTRIB_AUTHEN_REQ )
2012-11-12 15:47:55 -05:00
# else
if ( 1 )
# endif
2012-07-28 17:09:53 -04:00
{
ui . signBox - > setChecked ( true ) ;
ui . signBox - > setEnabled ( false ) ;
}
else
{
/* Uncheck sign box by default for anonymous forums */
ui . signBox - > setChecked ( false ) ;
ui . signBox - > setEnabled ( true ) ;
}
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
ui . forumMessage - > setText ( " " ) ;
2012-06-13 20:36:25 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : createMsg ( )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
QString name = misc : : removeNewLine ( ui . forumSubject - > text ( ) ) ;
QString desc ;
2012-06-13 20:36:25 -04:00
2012-11-19 16:35:48 -05:00
RsHtml : : optimizeHtml ( ui . forumMessage , desc ) ;
2012-06-13 20:36:25 -04:00
2014-07-06 07:19:58 -04:00
if ( name . isEmpty ( ) ) {
/* error message */
2013-07-19 17:06:19 -04:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Please set a Forum Subject and Forum Message " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
return ; //Don't add a empty Subject!!
2014-07-06 07:19:58 -04:00
} //if(name.isEmpty())
2012-06-13 20:36:25 -04:00
2012-11-12 15:47:55 -05:00
RsGxsForumMsg msg ;
2012-07-28 17:09:53 -04:00
msg . mMeta . mGroupId = mForumId ;
msg . mMeta . mParentId = mParentId ;
2014-04-20 12:34:26 -04:00
msg . mMeta . mMsgId . clear ( ) ;
2014-07-06 07:19:58 -04:00
if ( mParentMsgLoaded ) {
2012-07-28 17:09:53 -04:00
msg . mMeta . mThreadId = mParentMsg . mMeta . mThreadId ;
2014-07-06 07:19:58 -04:00
} //if (mParentMsgLoaded)
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
msg . mMeta . mMsgName = std : : string ( name . toUtf8 ( ) ) ;
msg . mMsg = std : : string ( desc . toUtf8 ( ) ) ;
2012-11-12 15:47:55 -05:00
# ifdef TOGXS
2012-07-28 17:09:53 -04:00
msg . mMeta . mMsgFlags = RS_DISTRIB_AUTHEN_REQ ;
2012-11-12 15:47:55 -05:00
# endif
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
if ( ( msg . mMsg = = " " ) & & ( msg . mMeta . mMsgName = = " " ) )
2013-01-07 17:11:16 -05:00
return ; /* do nothing */
2012-11-19 17:14:45 -05:00
2014-07-06 07:19:58 -04:00
if ( ui . signBox - > isChecked ( ) ) {
2012-11-19 17:14:45 -05:00
RsGxsId authorId ;
2014-07-06 07:19:58 -04:00
switch ( ui . idChooser - > getChosenId ( authorId ) ) {
case GxsIdChooser : : KnowId :
case GxsIdChooser : : UnKnowId :
2012-11-19 17:14:45 -05:00
msg . mMeta . mAuthorId = authorId ;
std : : cerr < < " CreateGxsForumMsg::createMsg() AuthorId: " < < authorId ;
std : : cerr < < std : : endl ;
2014-07-06 07:19:58 -04:00
break ;
case GxsIdChooser : : NoId :
case GxsIdChooser : : None :
default :
2012-11-19 17:14:45 -05:00
std : : cerr < < " CreateGxsForumMsg::createMsg() ERROR GETTING AuthorId! " ;
std : : cerr < < std : : endl ;
2013-07-19 17:06:19 -04:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Please choose Signing Id " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2013-03-15 17:02:43 -04:00
return ;
2014-07-06 07:19:58 -04:00
} //switch (ui.idChooser->getChosenId(authorId))
} else {
2012-11-19 17:14:45 -05:00
std : : cerr < < " CreateGxsForumMsg::createMsg() No Signature (for now :) " ;
std : : cerr < < std : : endl ;
2013-07-19 17:06:19 -04:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Please choose Signing Id, it is required " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2013-03-15 17:02:43 -04:00
return ;
2014-07-06 07:19:58 -04:00
} //if (ui.signBox->isChecked())
2012-11-19 17:14:45 -05:00
2013-07-19 17:06:19 -04:00
int generateCount = 0 ;
# ifdef ENABLE_GENERATE
if ( ui . generateCheckBox - > isChecked ( ) ) {
generateCount = ui . generateSpinBox - > value ( ) ;
if ( QMessageBox : : question ( this , " Generate mass data " , QString ( " Do you really want to generate %1 messages ? " ) . arg ( generateCount ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) = = QMessageBox : : No ) {
return ;
2014-07-06 07:19:58 -04:00
} //if (QMessageBox::question(this,
} //if (ui.generateCheckBox->isChecked())
2013-07-19 17:06:19 -04:00
# endif
2012-07-28 17:09:53 -04:00
uint32_t token ;
2013-07-19 17:06:19 -04:00
if ( generateCount ) {
# ifdef ENABLE_GENERATE
for ( int count = 0 ; count < generateCount ; + + count ) {
RsGxsForumMsg generateMsg = msg ;
generateMsg . mMeta . mMsgName = QString ( " %1 %2 " ) . arg ( QString : : fromUtf8 ( msg . mMeta . mMsgName . c_str ( ) ) ) . arg ( count + 1 , 3 , 10 , QChar ( ' 0 ' ) ) . toUtf8 ( ) . constData ( ) ;
rsGxsForums - > createMsg ( token , generateMsg ) ;
2014-07-06 07:19:58 -04:00
} //for (int count = 0
2013-07-19 17:06:19 -04:00
# endif
} else {
rsGxsForums - > createMsg ( token , msg ) ;
2014-07-06 07:19:58 -04:00
} //if (generateCount)
2013-07-19 17:06:19 -04:00
2012-07-28 17:09:53 -04:00
close ( ) ;
}
2012-06-13 20:36:25 -04:00
2014-07-06 07:19:58 -04:00
void CreateGxsForumMsg : : createNewGxsId ( )
{
IdEditDialog dlg ( this ) ;
dlg . setupNewId ( false ) ;
dlg . exec ( ) ;
ui . idChooser - > setDefaultId ( dlg . getLastIdName ( ) ) ;
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : closeEvent ( QCloseEvent * /*event*/ )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
Settings - > saveWidgetInformation ( this ) ;
2012-06-13 20:36:25 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : smileyWidgetForums ( )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
Emoticons : : showSmileyWidget ( this , ui . emoticonButton , SLOT ( addSmileys ( ) ) , false ) ;
2012-06-13 20:36:25 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : addSmileys ( )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
ui . forumMessage - > textCursor ( ) . insertText ( qobject_cast < QPushButton * > ( sender ( ) ) - > toolTip ( ) . split ( " | " ) . first ( ) ) ;
2012-06-13 20:36:25 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : addFile ( )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
QStringList files ;
if ( misc : : getOpenFileNames ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , files ) ) {
ui . hashBox - > addAttachments ( files , RS_FILE_REQ_ANONYMOUS_ROUTING ) ;
}
2012-06-13 20:36:25 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : fileHashingFinished ( QList < HashedFile > hashedFiles )
2012-06-13 20:36:25 -04:00
{
2013-01-07 17:11:16 -05:00
std : : cerr < < " CreateGxsForumMsg::fileHashingFinished() started. " < < std : : endl ;
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
QString mesgString ;
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
QList < HashedFile > : : iterator it ;
for ( it = hashedFiles . begin ( ) ; it ! = hashedFiles . end ( ) ; + + it ) {
HashedFile & hashedFile = * it ;
RetroShareLink link ;
2014-03-17 16:56:06 -04:00
if ( link . createFile ( hashedFile . filename , hashedFile . size ,
QString : : fromStdString ( hashedFile . hash . toStdString ( ) ) ) ) {
2013-01-07 17:11:16 -05:00
mesgString + = link . toHtmlSize ( ) + " <br> " ;
}
}
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
if ( ! mesgString . isEmpty ( ) ) {
ui . forumMessage - > textCursor ( ) . insertHtml ( mesgString ) ;
}
2012-06-13 20:36:25 -04:00
2013-01-07 17:11:16 -05:00
ui . forumMessage - > setFocus ( Qt : : OtherFocusReason ) ;
2012-06-13 20:36:25 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : loadForumInfo ( const uint32_t & token )
2012-07-28 17:09:53 -04:00
{
2012-11-12 15:47:55 -05:00
std : : cerr < < " CreateGxsForumMsg::loadForumInfo() " ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
std : : list < RsGroupMetaData > groupInfo ;
2012-11-12 15:47:55 -05:00
rsGxsForums - > getGroupSummary ( token , groupInfo ) ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
if ( groupInfo . size ( ) = = 1 )
{
RsGroupMetaData fi = groupInfo . front ( ) ;
2013-07-12 13:24:11 -04:00
mForumMeta = fi ;
mForumMetaLoaded = true ;
loadFormInformation ( ) ;
2012-07-28 17:09:53 -04:00
}
else
{
2012-11-12 15:47:55 -05:00
std : : cerr < < " CreateGxsForumMsg::loadForumInfo() ERROR INVALID Number of Forums " ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
2013-07-12 13:24:11 -04:00
mStateHelper - > setActive ( CREATEGXSFORUMMSG_FORUMINFO , false ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_FORUMINFO , false ) ;
2012-07-28 17:09:53 -04:00
}
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : loadParentMsg ( const uint32_t & token )
2012-07-28 17:09:53 -04:00
{
2012-11-12 15:47:55 -05:00
std : : cerr < < " CreateGxsForumMsg::loadParentMsg() " ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
// Only grab one.... ignore more (shouldn't be any).
2012-11-12 15:47:55 -05:00
std : : vector < RsGxsForumMsg > msgs ;
if ( rsGxsForums - > getMsgData ( token , msgs ) )
{
if ( msgs . size ( ) ! = 1 )
{
/* error */
std : : cerr < < " CreateGxsForumMsg::loadParentMsg() ERROR wrong number of msgs " ;
std : : cerr < < std : : endl ;
2013-07-12 13:24:11 -04:00
mStateHelper - > setActive ( CREATEGXSFORUMMSG_PARENTMSG , false ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_PARENTMSG , false ) ;
return ;
2013-01-07 17:11:16 -05:00
}
2013-07-12 13:24:11 -04:00
mParentMsg = msgs [ 0 ] ;
mParentMsgLoaded = true ;
loadFormInformation ( ) ;
2012-11-12 15:47:55 -05:00
}
2012-07-28 17:09:53 -04:00
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : loadRequest ( const TokenQueue * queue , const TokenRequest & req )
2012-07-28 17:09:53 -04:00
{
2012-11-12 15:47:55 -05:00
std : : cerr < < " CreateGxsForum::loadRequest() UserType: " < < req . mUserType ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
2013-01-07 17:11:16 -05:00
2012-07-28 17:09:53 -04:00
if ( queue = = mForumQueue )
{
/* now switch on req */
switch ( req . mUserType )
{
2012-11-12 15:47:55 -05:00
case CREATEGXSFORUMMSG_FORUMINFO :
2012-07-28 17:09:53 -04:00
loadForumInfo ( req . mToken ) ;
break ;
2012-11-12 15:47:55 -05:00
case CREATEGXSFORUMMSG_PARENTMSG :
2012-07-28 17:09:53 -04:00
loadParentMsg ( req . mToken ) ;
break ;
default :
2012-11-12 15:47:55 -05:00
std : : cerr < < " CreateGxsForum::loadRequest() UNKNOWN UserType " ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
}
}
}