2018-11-15 15:49:12 -05:00
/*******************************************************************************
* retroshare - gui / src / gui / gxsforums / CreateGxsForumMsg . cpp *
* *
* Copyright 2013 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-06-13 20:36:25 -04:00
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>
2016-03-24 00:05:54 -04:00
# include <retroshare/rsgxscircles.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"
2015-06-01 04:55:30 -04:00
# include "gui/Identity/IdEditDialog.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
2016-03-24 00:05:54 -04:00
# define CREATEGXSFORUMMSG_CIRCLENFO 3
2017-02-09 15:49:24 -05:00
# define CREATEGXSFORUMMSG_ORIGMSG 4
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 */
2018-09-02 11:07:40 -04:00
CreateGxsForumMsg : : CreateGxsForumMsg ( const RsGxsGroupId & fId , const RsGxsMessageId & pId , const RsGxsMessageId & mOId , const RsGxsId & posterId , bool isModerating )
: QDialog ( NULL , Qt : : WindowSystemMenuHint | Qt : : WindowTitleHint | Qt : : WindowMinMaxButtonsHint | Qt : : WindowCloseButtonHint ) ,
mForumId ( fId ) , mParentId ( pId ) , mOrigMsgId ( mOId ) , mPosterId ( posterId ) , mIsModerating ( isModerating )
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 ) ;
2016-03-24 00:05:54 -04:00
mCirclesQueue = new TokenQueue ( rsGxsCircles - > getTokenService ( ) , this ) ;
2012-11-12 15:47:55 -05:00
2013-07-12 13:24:11 -04:00
/* Setup UI helper */
mStateHelper = new UIStateHelper ( this ) ;
2015-01-31 07:23:56 -05:00
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_FORUMINFO , ui . buttonBox - > button ( QDialogButtonBox : : Ok ) ) ;
2013-07-12 13:24:11 -04:00
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_FORUMINFO , ui . innerFrame ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_FORUMINFO , ui . forumName ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_FORUMINFO , ui . forumSubject ) ;
mStateHelper - > addClear ( CREATEGXSFORUMMSG_FORUMINFO , ui . forumName ) ;
2015-01-31 07:23:56 -05:00
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_PARENTMSG , ui . buttonBox - > button ( QDialogButtonBox : : Ok ) ) ;
2013-07-12 13:24:11 -04:00
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_PARENTMSG , ui . innerFrame ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_PARENTMSG , ui . forumName ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_PARENTMSG , ui . forumSubject ) ;
mStateHelper - > addClear ( CREATEGXSFORUMMSG_PARENTMSG , ui . forumName ) ;
2017-02-09 15:49:24 -05:00
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_ORIGMSG , ui . buttonBox - > button ( QDialogButtonBox : : Ok ) ) ;
mStateHelper - > addWidget ( CREATEGXSFORUMMSG_ORIGMSG , ui . innerFrame ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_ORIGMSG , ui . forumName ) ;
mStateHelper - > addLoadPlaceholder ( CREATEGXSFORUMMSG_ORIGMSG , ui . forumSubject ) ;
mStateHelper - > addClear ( CREATEGXSFORUMMSG_ORIGMSG , ui . forumName ) ;
2017-02-03 06:48:51 -05:00
QString text = mOId . isNull ( ) ? ( pId . isNull ( ) ? tr ( " Start New Thread " ) : tr ( " Post Forum Message " ) ) : tr ( " Edit Message " ) ;
2013-01-07 17:11:16 -05:00
setWindowTitle ( text ) ;
2012-11-21 13:55:52 -05: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
2015-01-31 07:23:56 -05:00
/* Rename Ok button */
ui . buttonBox - > button ( QDialogButtonBox : : Ok ) - > setText ( tr ( " Send " ) ) ;
2013-01-07 17:11:16 -05:00
// connect up the buttons.
2015-01-31 07:23:56 -05:00
connect ( ui . buttonBox , SIGNAL ( accepted ( ) ) , this , SLOT ( createMsg ( ) ) ) ;
2014-12-13 07:36:43 -05:00
connect ( ui . buttonBox , SIGNAL ( rejected ( ) ) , this , SLOT ( reject ( ) ) ) ;
2013-01-07 17:11:16 -05:00
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 ) ) ) ;
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 ;
2017-02-03 06:48:51 -05:00
mForumCircleLoaded = false ;
2012-07-28 17:09:53 -04:00
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 ) ;
2016-03-24 00:05:54 -04:00
delete ( mCirclesQueue ) ;
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 */
2016-03-24 19:46:08 -04:00
//std::cerr << "Initing ID chooser. Sign flags = " << std::hex << mForumMeta.mSignFlags << std::dec << std::endl;
2015-10-24 12:48:17 -04:00
2017-02-09 15:49:24 -05:00
if ( ! mPosterId . isNull ( ) )
{
std : : set < RsGxsId > id_set ;
id_set . insert ( mPosterId ) ;
ui . idChooser - > loadIds ( IDCHOOSER_ID_REQUIRED | IDCHOOSER_NO_CREATE , mPosterId ) ;
ui . idChooser - > setIdConstraintSet ( id_set ) ;
}
else
ui . idChooser - > loadIds ( IDCHOOSER_ID_REQUIRED , mPosterId ) ;
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 ) ;
2017-02-09 15:49:24 -05:00
mStateHelper - > setActive ( CREATEGXSFORUMMSG_ORIGMSG , false ) ;
2017-10-29 15:33:56 -04:00
2013-07-12 13:24:11 -04:00
mStateHelper - > clear ( CREATEGXSFORUMMSG_FORUMINFO ) ;
mStateHelper - > clear ( CREATEGXSFORUMMSG_PARENTMSG ) ;
2017-02-09 15:49:24 -05:00
mStateHelper - > clear ( CREATEGXSFORUMMSG_ORIGMSG ) ;
2013-01-07 17:11:16 -05:00
ui . forumName - > setText ( tr ( " No Forum " ) ) ;
return ;
2017-10-29 15:33:56 -04:00
}
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
2016-03-24 19:46:08 -04:00
//std::cerr << "ForumsV2Dialog::newMsg() Requesting Group Summary(" << mForumId << ")"<< 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 ;
2018-06-21 09:46:59 -04:00
std : : set < RsGxsMessageId > & vect = msgIds [ mForumId ] ;
vect . insert ( mParentId ) ;
2013-01-07 17:11:16 -05:00
2016-03-24 19:46:08 -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 ) ;
2017-10-29 15:33:56 -04:00
}
2017-02-09 15:49:24 -05:00
if ( mOrigMsgId . isNull ( ) ) {
mStateHelper - > setActive ( CREATEGXSFORUMMSG_ORIGMSG , true ) ;
mOrigMsgLoaded = true ;
} else {
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_ORIGMSG , true ) ;
RsTokReqOptions opts ;
opts . mReqType = GXS_REQUEST_TYPE_MSG_DATA ;
GxsMsgReq msgIds ;
2018-06-21 09:46:59 -04:00
std : : set < RsGxsMessageId > & vect = msgIds [ mForumId ] ;
vect . insert ( mOrigMsgId ) ;
2017-02-09 15:49:24 -05:00
//std::cerr << "ForumsV2Dialog::newMsg() Requesting Parent Summary(" << mParentId << ")";
//std::cerr << std::endl;
uint32_t token ;
mForumQueue - > requestMsgInfo ( token , RS_TOKREQ_ANSTYPE_DATA , opts , msgIds , CREATEGXSFORUMMSG_ORIGMSG ) ;
2017-10-29 15:33:56 -04:00
}
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
{
2017-02-09 15:49:24 -05:00
if ( ! mOrigMsgId . isNull ( ) )
{
if ( mOrigMsgLoaded ) {
mStateHelper - > setActive ( CREATEGXSFORUMMSG_ORIGMSG , true ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_ORIGMSG , false ) ;
} else {
//std::cerr << "CreateGxsForumMsg::loadMsgInformation() ParentMsg not Loaded Yet";
//std::cerr << std::endl;
mStateHelper - > setActive ( CREATEGXSFORUMMSG_ORIGMSG , false ) ;
return ;
}
}
else
{
mStateHelper - > setActive ( CREATEGXSFORUMMSG_ORIGMSG , true ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_ORIGMSG , false ) ;
}
if ( ! mParentId . isNull ( ) )
{
2013-07-12 13:24:11 -04:00
if ( mParentMsgLoaded ) {
mStateHelper - > setActive ( CREATEGXSFORUMMSG_PARENTMSG , true ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_PARENTMSG , false ) ;
} else {
2016-03-24 19:46:08 -04:00
//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 ;
}
2017-02-09 15:49:24 -05:00
}
else
{
2013-07-12 13:24:11 -04:00
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 {
2016-03-24 19:46:08 -04:00
//std::cerr << "CreateGxsForumMsg::loadMsgInformation() ForumMeta not Loaded Yet";
//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
2016-03-24 19:46:08 -04:00
//std::cerr << "CreateGxsForumMsg::loadMsgInformation() Data Available!";
//std::cerr << std::endl;
2013-01-07 17:11:16 -05:00
2016-03-24 19:46:08 -04:00
//std::cerr << "CreateGxsForumMsg::loadMsgInformation() using signFlags=" << std::hex << mForumMeta.mSignFlags << std::dec << std::endl;
2015-10-24 12:48:17 -04:00
2017-02-09 15:49:24 -05:00
uint32_t fl = IDCHOOSER_ID_REQUIRED ;
2017-02-03 07:02:53 -05:00
if ( ( mForumMeta . mSignFlags & GXS_SERV : : FLAG_AUTHOR_AUTHENTICATION_GPG ) | | ( mForumMeta . mSignFlags & GXS_SERV : : FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN ) )
2017-05-08 06:26:37 -04:00
fl | = IDCHOOSER_NON_ANONYMOUS ;
2017-02-09 15:49:24 -05:00
2017-05-08 06:26:37 -04:00
if ( ! mPosterId . isNull ( ) )
fl | = IDCHOOSER_NO_CREATE ;
2017-02-09 15:49:24 -05:00
ui . idChooser - > setFlags ( fl ) ;
2012-07-28 17:09:53 -04:00
QString name = QString : : fromUtf8 ( mForumMeta . mGroupName . c_str ( ) ) ;
QString subj ;
2017-02-03 07:02:53 -05:00
if ( ! mOrigMsgId . isNull ( ) )
{
2017-02-09 15:49:24 -05:00
subj = QString : : fromUtf8 ( mOrigMsg . mMeta . mMsgName . c_str ( ) ) ;
2017-02-03 07:02:53 -05:00
}
else 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 ) ) ;
2017-10-29 15:33:56 -04:00
if ( ! subj . isNull ( ) )
ui . forumSubject - > setText ( misc : : removeNewLine ( subj ) ) ;
2013-01-07 17:11:16 -05:00
if ( ui . forumSubject - > text ( ) . isEmpty ( ) )
ui . forumSubject - > setFocus ( ) ;
2012-07-28 17:09:53 -04:00
else
2013-01-07 17:11:16 -05:00
ui . forumMessage - > setFocus ( ) ;
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 ) ;
2017-03-03 08:59:18 -05:00
ui . signBox - > hide ( ) ;
2012-07-28 17:09:53 -04:00
}
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
2015-11-19 06:05:52 -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-12-13 07:36:43 -05:00
if ( name . isEmpty ( ) | desc . isEmpty ( ) ) {
2014-07-06 07:19:58 -04:00
/* 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 ;
2017-02-03 06:48:51 -05:00
msg . mMeta . mOrigMsgId = mOrigMsgId ;
2018-09-02 11:07:40 -04:00
msg . mMeta . mMsgFlags = mIsModerating ? RS_GXS_FORUM_MSG_FLAGS_MODERATED : 0 ;
2014-04-20 12:34:26 -04:00
msg . mMeta . mMsgId . clear ( ) ;
2018-09-02 11:07:40 -04:00
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 ) ) {
2016-03-24 00:05:54 -04:00
case GxsIdChooser : : KnowId :
case GxsIdChooser : : UnKnowId :
2012-11-19 17:14:45 -05:00
msg . mMeta . mAuthorId = authorId ;
2016-03-24 19:46:08 -04:00
//std::cerr << "CreateGxsForumMsg::createMsg() AuthorId: " << authorId;
//std::cerr << std::endl;
2014-07-06 07:19:58 -04:00
break ;
2016-03-24 00:05:54 -04:00
case GxsIdChooser : : None :
{
// This is ONLY for the case where no id exists yet
// If an id exists, the chooser would not return None
IdEditDialog dlg ( this ) ;
dlg . setupNewId ( false ) ;
dlg . exec ( ) ;
// fetch new id, we will then see if the identity creation was successful
std : : list < RsGxsId > own_ids ;
if ( ! rsIdentity - > getOwnIds ( own_ids ) | | own_ids . size ( ) ! = 1 )
return ;
// we have only a single id, so we can use the first one
authorId = own_ids . front ( ) ;
break ;
}
case GxsIdChooser : : NoId :
default :
2012-11-19 17:14:45 -05:00
std : : cerr < < " CreateGxsForumMsg::createMsg() ERROR GETTING AuthorId! " ;
std : : cerr < < std : : endl ;
2016-03-24 00:05:54 -04:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Congrats, you found a bug! " ) + " " + QString ( __FILE__ ) + " : " + QString ( __LINE__ ) , 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 {
2016-03-24 19:46:08 -04: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 ( ) ;
2014-07-10 14:37:21 -04:00
if ( QMessageBox : : question ( this , tr ( " Generate mass data " ) , tr ( " Do you really want to generate %1 messages ? " ) . arg ( generateCount ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) = = QMessageBox : : No ) {
2013-07-19 17:06:19 -04:00
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
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
}
2014-12-13 07:36:43 -05:00
void CreateGxsForumMsg : : reject ( )
{
if ( ui . forumMessage - > document ( ) - > isModified ( ) ) {
QMessageBox : : StandardButton ret ;
2017-02-03 06:48:51 -05:00
ret = QMessageBox : : warning ( this , tr ( " Cancel Forum Message " ) ,
tr ( " Forum Message has not been sent yet! \n "
2017-02-09 15:49:24 -05:00
" Do you want to discard this message? " ) ,
2014-12-13 07:36:43 -05:00
QMessageBox : : Yes | QMessageBox : : No ) ;
switch ( ret ) {
case QMessageBox : : Yes :
break ;
case QMessageBox : : No :
return ; // don't close
default :
break ;
}
}
QDialog : : reject ( ) ;
}
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
{
2017-01-21 16:53:56 -05:00
QString smiley = qobject_cast < QPushButton * > ( sender ( ) ) - > toolTip ( ) . split ( " | " ) . first ( ) ;
// add trailing space
smiley + = QString ( " " ) ;
// add preceding space when needed (not at start of text or preceding space already exists)
if ( ! ui . forumMessage - > textCursor ( ) . atStart ( ) & & ui . forumMessage - > toPlainText ( ) [ ui . forumMessage - > textCursor ( ) . position ( ) - 1 ] ! = QChar ( ' ' ) )
smiley = QString ( " " ) + smiley ;
ui . forumMessage - > textCursor ( ) . insertText ( smiley ) ;
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
{
2016-03-24 19:46:08 -04: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 ;
2017-07-16 07:11:47 -04:00
RetroShareLink link = RetroShareLink : : createFile ( hashedFile . filename , hashedFile . size ,
QString : : fromStdString ( hashedFile . hash . toStdString ( ) ) ) ;
if ( link . valid ( ) ) {
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
{
2016-03-24 19:46:08 -04:00
//std::cerr << "CreateGxsForumMsg::loadForumInfo()";
//std::cerr << std::endl;
2013-01-07 17:11:16 -05:00
2016-03-24 00:05:54 -04:00
std : : list < RsGroupMetaData > groupInfo ;
rsGxsForums - > getGroupSummary ( token , groupInfo ) ;
2013-01-07 17:11:16 -05:00
2016-03-24 00:05:54 -04:00
if ( groupInfo . size ( ) = = 1 )
{
RsGroupMetaData fi = groupInfo . front ( ) ;
2013-07-12 13:24:11 -04:00
2016-03-24 00:05:54 -04:00
mForumMeta = fi ;
mForumMetaLoaded = true ;
2013-07-12 13:24:11 -04:00
2016-03-24 00:05:54 -04:00
if ( ! fi . mCircleId . isNull ( ) )
{
2016-03-24 19:46:08 -04:00
//std::cerr << "Circle ID is not null: " << fi.mCircleId << ": loading circle info to add constraint to the GXS ID chooser." << std::endl;
2013-07-12 13:24:11 -04:00
2016-03-24 00:05:54 -04:00
RsTokReqOptions opts ;
opts . mReqType = GXS_REQUEST_TYPE_GROUP_DATA ;
std : : list < RsGxsGroupId > groupIds ;
groupIds . push_back ( RsGxsGroupId ( fi . mCircleId ) ) ;
uint32_t _token ;
mCirclesQueue - > requestGroupInfo ( _token , RS_TOKREQ_ANSTYPE_DATA , opts , groupIds , CREATEGXSFORUMMSG_CIRCLENFO ) ;
}
loadFormInformation ( ) ;
}
else
{
std : : cerr < < " CreateGxsForumMsg::loadForumInfo() ERROR INVALID Number of Forums " ;
std : : cerr < < std : : endl ;
mStateHelper - > setActive ( CREATEGXSFORUMMSG_FORUMINFO , false ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_FORUMINFO , false ) ;
}
}
void CreateGxsForumMsg : : loadForumCircleInfo ( const uint32_t & token )
{
2016-03-24 19:46:08 -04:00
//std::cerr << "Loading forum circle info" << std::endl;
2016-03-24 00:05:54 -04:00
std : : vector < RsGxsCircleGroup > circle_grp_v ;
rsGxsCircles - > getGroupData ( token , circle_grp_v ) ;
if ( circle_grp_v . empty ( ) )
{
std : : cerr < < " (EE) unexpected empty result from getGroupData. Cannot process circle now! " < < std : : endl ;
return ;
}
if ( circle_grp_v . size ( ) ! = 1 )
{
std : : cerr < < " (EE) very weird result from getGroupData. Should get exactly one circle " < < std : : endl ;
return ;
}
RsGxsCircleGroup cg = circle_grp_v . front ( ) ;
mForumCircleData = cg ;
mForumCircleLoaded = true ;
2016-03-24 19:46:08 -04:00
//std::cerr << "Loaded content of circle " << cg.mMeta.mGroupId << std::endl;
2016-03-24 00:05:54 -04:00
2016-03-24 19:46:08 -04:00
//for(std::set<RsGxsId>::const_iterator it(cg.mInvitedMembers.begin());it!=cg.mInvitedMembers.end();++it)
// std::cerr << " added constraint to circle element " << *it << std::endl;
2016-03-24 00:05:54 -04:00
ui . idChooser - > setIdConstraintSet ( cg . mInvitedMembers ) ;
ui . idChooser - > setFlags ( IDCHOOSER_NO_CREATE | ui . idChooser - > flags ( ) ) ; // since there's a circle involved, no ID creation can be needed
RsGxsId tmpid ;
2016-03-24 19:23:34 -04:00
if ( ui . idChooser - > countEnabledEntries ( ) = = 0 )
2016-03-24 00:05:54 -04:00
{
2016-03-24 19:46:08 -04:00
QMessageBox : : information ( NULL , tr ( " No compatible ID for this forum " ) , tr ( " None of your identities is allowed to post in this forum. This could be due to the forum being limited to a circle that contains none of your identities, or forum flags requiring a PGP-signed identity. " ) ) ;
2016-03-24 00:05:54 -04:00
close ( ) ;
}
2012-07-28 17:09:53 -04:00
}
2017-02-09 15:49:24 -05:00
void CreateGxsForumMsg : : loadOrigMsg ( const uint32_t & token )
{
//std::cerr << "CreateGxsForumMsg::loadParentMsg()";
//std::cerr << std::endl;
// Only grab one.... ignore more (shouldn't be any).
std : : vector < RsGxsForumMsg > msgs ;
if ( rsGxsForums - > getMsgData ( token , msgs ) )
{
if ( msgs . size ( ) ! = 1 )
{
/* error */
std : : cerr < < " CreateGxsForumMsg::loadOrigMsg() ERROR wrong number of msgs " ;
std : : cerr < < std : : endl ;
mStateHelper - > setActive ( CREATEGXSFORUMMSG_ORIGMSG , false ) ;
mStateHelper - > setLoading ( CREATEGXSFORUMMSG_ORIGMSG , false ) ;
return ;
}
mOrigMsg = msgs [ 0 ] ;
mOrigMsgLoaded = true ;
loadFormInformation ( ) ;
}
}
2012-11-12 15:47:55 -05:00
void CreateGxsForumMsg : : loadParentMsg ( const uint32_t & token )
2012-07-28 17:09:53 -04:00
{
2016-03-24 19:46:08 -04:00
//std::cerr << "CreateGxsForumMsg::loadParentMsg()";
//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
{
2016-03-24 19:46:08 -04:00
//std::cerr << "CreateGxsForum::loadRequest() UserType: " << req.mUserType;
//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 ;
2017-02-09 15:49:24 -05:00
case CREATEGXSFORUMMSG_ORIGMSG :
loadOrigMsg ( 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 :
2016-03-24 00:05:54 -04:00
std : : cerr < < " CreateGxsForumMsg::loadRequest() UNKNOWN UserType " < < req . mUserType < < " for token request in mForumQueue " ;
2012-07-28 17:09:53 -04:00
std : : cerr < < std : : endl ;
}
}
2016-03-24 00:05:54 -04:00
if ( queue = = mCirclesQueue )
{
switch ( req . mUserType )
{
case CREATEGXSFORUMMSG_CIRCLENFO :
loadForumCircleInfo ( req . mToken ) ;
break ;
default :
std : : cerr < < " CreateGxsForumMsg::loadRequest() UNKNOWN UserType " < < req . mUserType < < " for token request in mCirclesQueue " ;
std : : cerr < < std : : endl ;
}
}
2012-07-28 17:09:53 -04:00
}
2017-10-29 15:33:56 -04:00
void CreateGxsForumMsg : : setSubject ( const QString & msg )
{
ui . forumSubject - > setText ( msg ) ;
}
2015-11-19 06:05:52 -05:00
2017-10-29 15:33:56 -04:00
void CreateGxsForumMsg : : insertPastedText ( const QString & msg )
2015-11-19 06:05:52 -05:00
{
ui . forumMessage - > append ( msg ) ;
}