2013-03-11 16:53:15 -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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QDragEnterEvent>
# include <QMessageBox>
# include <QBuffer>
# include <QMenu>
# include <QDir>
2013-10-21 05:27:12 -04:00
# include <QMimeData>
2013-03-11 16:53:15 -04:00
# include <gui/RetroShareLink.h>
# include "CreateGxsChannelMsg.h"
# include "gui/feeds/SubFileItem.h"
# include "util/misc.h"
# include <retroshare/rsfiles.h>
# include <iostream>
2013-07-19 17:06:19 -04:00
//#define ENABLE_GENERATE
2013-07-19 05:48:51 -04:00
# define CREATEMSG_CHANNELINFO 0x002
2013-03-12 20:33:14 -04:00
2013-03-11 16:53:15 -04:00
/** Constructor */
2014-03-17 16:56:06 -04:00
CreateGxsChannelMsg : : CreateGxsChannelMsg ( const RsGxsGroupId & cId )
2013-07-19 05:48:51 -04:00
: QDialog ( NULL , Qt : : WindowSystemMenuHint | Qt : : WindowTitleHint | Qt : : WindowMinMaxButtonsHint | Qt : : WindowCloseButtonHint ) , mChannelId ( cId ) , mCheckAttachment ( true ) , mAutoMediaThumbNail ( false )
2013-03-11 16:53:15 -04:00
{
/* Invoke the Qt Designer generated object setup routine */
setupUi ( this ) ;
2013-03-12 20:33:14 -04:00
mChannelQueue = new TokenQueue ( rsGxsChannels - > getTokenService ( ) , this ) ;
2013-03-11 16:53:15 -04:00
headerFrame - > setHeaderImage ( QPixmap ( " :/images/channels.png " ) ) ;
2014-09-11 11:12:28 -04:00
headerFrame - > setHeaderText ( tr ( " New Channel Post " ) ) ;
2013-03-11 16:53:15 -04:00
setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
connect ( buttonBox , SIGNAL ( accepted ( ) ) , this , SLOT ( sendMsg ( ) ) ) ;
connect ( buttonBox , SIGNAL ( rejected ( ) ) , this , SLOT ( cancelMsg ( ) ) ) ;
connect ( addFileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
connect ( addfilepushButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
connect ( addThumbnailButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addThumbnail ( ) ) ) ;
connect ( thumbNailCb , SIGNAL ( toggled ( bool ) ) , this , SLOT ( allowAutoMediaThumbNail ( bool ) ) ) ;
connect ( tabWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
2013-07-19 17:06:19 -04:00
connect ( generateCheckBox , SIGNAL ( toggled ( bool ) ) , generateSpinBox , SLOT ( setEnabled ( bool ) ) ) ;
generateSpinBox - > setEnabled ( false ) ;
2013-03-11 16:53:15 -04:00
thumbNailCb - > setVisible ( false ) ;
thumbNailCb - > setEnabled ( false ) ;
# ifdef CHANNELS_FRAME_CATCHER
fCatcher = new framecatcher ( ) ;
thumbNailCb - > setVisible ( true ) ;
thumbNailCb - > setEnabled ( true ) ;
# endif
2013-07-19 05:48:51 -04:00
//buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
2013-03-11 16:53:15 -04:00
setAcceptDrops ( true ) ;
2013-07-19 05:48:51 -04:00
2013-03-11 16:53:15 -04:00
newChannelMsg ( ) ;
2013-07-19 17:06:19 -04:00
# ifndef ENABLE_GENERATE
generateCheckBox - > hide ( ) ;
generateSpinBox - > hide ( ) ;
# endif
2013-03-11 16:53:15 -04:00
}
2014-10-12 06:46:09 -04:00
CreateGxsChannelMsg : : ~ CreateGxsChannelMsg ( )
{
# ifdef CHANNELS_FRAME_CATCHER
delete fCatcher ;
# endif
delete ( mChannelQueue ) ;
}
2013-03-11 16:53:15 -04:00
void CreateGxsChannelMsg : : contextMenu ( QPoint /*point*/ )
{
QList < RetroShareLink > links ;
RSLinkClipboard : : pasteLinks ( links ) ;
int n_file = 0 ;
for ( QList < RetroShareLink > : : const_iterator it ( links . begin ( ) ) ; it ! = links . end ( ) ; + + it )
if ( ( * it ) . type ( ) = = RetroShareLink : : TYPE_FILE )
2014-10-21 18:33:02 -04:00
+ + n_file ;
2013-03-11 16:53:15 -04:00
2013-07-19 05:48:51 -04:00
QMenu contextMnu ( this ) ;
2013-03-11 16:53:15 -04:00
2013-07-19 05:48:51 -04:00
QAction * action ;
if ( n_file > 1 )
action = contextMnu . addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste RetroShare Links " ) , this , SLOT ( pasteLink ( ) ) ) ;
else
action = contextMnu . addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste RetroShare Link " ) , this , SLOT ( pasteLink ( ) ) ) ;
2013-03-11 16:53:15 -04:00
2013-07-19 05:48:51 -04:00
action - > setDisabled ( n_file < 1 ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
2013-03-11 16:53:15 -04:00
}
void CreateGxsChannelMsg : : pasteLink ( )
{
std : : cerr < < " Pasting links: " < < std : : endl ;
QList < RetroShareLink > links , not_have ;
RSLinkClipboard : : pasteLinks ( links ) ;
for ( QList < RetroShareLink > : : const_iterator it ( links . begin ( ) ) ; it ! = links . end ( ) ; + + it )
if ( ( * it ) . type ( ) = = RetroShareLink : : TYPE_FILE )
{
// 0 - check that we actually have the file!
//
std : : cerr < < " Pasting " < < ( * it ) . toString ( ) . toStdString ( ) < < std : : endl ;
2014-03-17 16:56:06 -04:00
FileInfo info ;
RsFileHash hash ( ( * it ) . hash ( ) . toStdString ( ) ) ;
if ( rsFiles - > alreadyHaveFile ( hash , info ) )
addAttachment ( hash , ( * it ) . name ( ) . toUtf8 ( ) . constData ( ) , ( * it ) . size ( ) , true , RsPeerId ( ) ) ;
2013-03-11 16:53:15 -04:00
else
not_have . push_back ( * it ) ;
}
if ( ! not_have . empty ( ) )
{
2015-03-18 10:12:31 -04:00
QString msg = tr ( " You are about to add files you're not actually sharing. Do you still want this to happen? " ) + " <br><br> " ;
2013-03-11 16:53:15 -04:00
2015-03-18 10:12:31 -04:00
for ( QList < RetroShareLink > : : const_iterator it ( not_have . begin ( ) ) ; it ! = not_have . end ( ) ; + + it )
msg + = ( * it ) . toString ( ) + " <br> " ;
2013-03-11 16:53:15 -04:00
2015-03-18 10:12:31 -04:00
if ( QMessageBox : : YesToAll = = QMessageBox : : question ( NULL , tr ( " About to post un-owned files to a channel. " ) , msg , QMessageBox : : YesToAll | QMessageBox : : No ) )
for ( QList < RetroShareLink > : : const_iterator it ( not_have . begin ( ) ) ; it ! = not_have . end ( ) ; + + it )
addAttachment ( RsFileHash ( ( * it ) . hash ( ) . toStdString ( ) ) , ( * it ) . name ( ) . toUtf8 ( ) . constData ( ) , ( * it ) . size ( ) , false , RsPeerId ( ) ) ;
2013-03-11 16:53:15 -04:00
}
}
/* Dropping */
void CreateGxsChannelMsg : : dragEnterEvent ( QDragEnterEvent * event )
{
/* print out mimeType */
std : : cerr < < " CreateGxsChannelMsg::dragEnterEvent() Formats " ;
std : : cerr < < std : : endl ;
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
2014-10-21 18:33:02 -04:00
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; + + it )
2013-03-11 16:53:15 -04:00
{
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasFormat ( " text/plain " ) )
{
std : : cerr < < " CreateGxsChannelMsg::dragEnterEvent() Accepting PlainText " ;
std : : cerr < < std : : endl ;
event - > acceptProposedAction ( ) ;
}
else if ( event - > mimeData ( ) - > hasUrls ( ) )
{
std : : cerr < < " CreateGxsChannelMsg::dragEnterEvent() Accepting Urls " ;
std : : cerr < < std : : endl ;
event - > acceptProposedAction ( ) ;
}
else if ( event - > mimeData ( ) - > hasFormat ( " application/x-rsfilelist " ) )
{
std : : cerr < < " CreateGxsChannelMsg::dragEnterEvent() accepting Application/x-qabs... " ;
std : : cerr < < std : : endl ;
event - > acceptProposedAction ( ) ;
}
else
{
std : : cerr < < " CreateGxsChannelMsg::dragEnterEvent() No PlainText/Urls " ;
std : : cerr < < std : : endl ;
}
}
void CreateGxsChannelMsg : : dropEvent ( QDropEvent * event )
{
if ( ! ( Qt : : CopyAction & event - > possibleActions ( ) ) )
{
std : : cerr < < " CreateGxsChannelMsg::dropEvent() Rejecting uncopyable DropAction " ;
std : : cerr < < std : : endl ;
/* can't do it */
return ;
}
std : : cerr < < " CreateGxsChannelMsg::dropEvent() Formats " < < std : : endl ;
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
2014-10-21 18:33:02 -04:00
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; + + it )
2013-03-11 16:53:15 -04:00
{
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasText ( ) )
{
std : : cerr < < " CreateGxsChannelMsg::dropEvent() Plain Text: " ;
std : : cerr < < std : : endl ;
std : : cerr < < event - > mimeData ( ) - > text ( ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasUrls ( ) )
{
std : : cerr < < " CreateGxsChannelMsg::dropEvent() Urls: " < < std : : endl ;
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
QList < QUrl > : : iterator uit ;
2014-10-21 18:33:02 -04:00
for ( uit = urls . begin ( ) ; uit ! = urls . end ( ) ; + + uit )
2013-03-11 16:53:15 -04:00
{
QString localpath = uit - > toLocalFile ( ) ;
std : : cerr < < " Whole URL: " < < uit - > toString ( ) . toStdString ( ) < < std : : endl ;
std : : cerr < < " or As Local File: " < < localpath . toStdString ( ) < < std : : endl ;
if ( localpath . isEmpty ( ) = = false )
{
// Check that the file does exist and is not a directory
QDir dir ( localpath ) ;
if ( dir . exists ( ) ) {
std : : cerr < < " CreateGxsChannelMsg::dropEvent() directory not accepted. " < < std : : endl ;
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " Directory can't be dropped, only files are accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 , this ) ;
mb . exec ( ) ;
} else if ( QFile : : exists ( localpath ) ) {
addAttachment ( localpath . toUtf8 ( ) . constData ( ) ) ;
} else {
std : : cerr < < " CreateGxsChannelMsg::dropEvent() file does not exists. " < < std : : endl ;
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " File not found or file name not accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 , this ) ;
mb . exec ( ) ;
}
}
}
}
else if ( event - > mimeData ( ) - > hasFormat ( " application/x-rsfilelist " ) )
{
std : : cerr < < " CreateGxsChannelMsg::dropEvent() Application/x-rsfilelist " ;
std : : cerr < < std : : endl ;
QByteArray data = event - > mimeData ( ) - > data ( " application/x-rsfilelist " ) ;
std : : cerr < < " Data Len: " < < data . length ( ) ;
std : : cerr < < std : : endl ;
std : : cerr < < " Data is: " < < data . data ( ) ;
std : : cerr < < std : : endl ;
std : : string newattachments ( data . data ( ) ) ;
parseRsFileListAttachments ( newattachments ) ;
}
event - > setDropAction ( Qt : : CopyAction ) ;
event - > accept ( ) ;
}
void CreateGxsChannelMsg : : parseRsFileListAttachments ( const std : : string & attachList )
{
/* split into lines */
QString input = QString : : fromStdString ( attachList ) ;
QStringList attachItems = input . split ( " \n " ) ;
QStringList : : iterator it ;
QStringList : : iterator it2 ;
2014-10-21 18:33:02 -04:00
for ( it = attachItems . begin ( ) ; it ! = attachItems . end ( ) ; + + it )
2013-03-11 16:53:15 -04:00
{
std : : cerr < < " CreateGxsChannelMsg::parseRsFileListAttachments() Entry: " ;
QStringList parts = ( * it ) . split ( " / " ) ;
bool ok = false ;
quint64 qsize = 0 ;
std : : string fname ;
2014-03-17 16:56:06 -04:00
RsFileHash hash ;
2013-03-11 16:53:15 -04:00
uint64_t size = 0 ;
2014-03-17 16:56:06 -04:00
RsPeerId source ;
2013-03-11 16:53:15 -04:00
int i = 0 ;
2014-10-21 18:33:02 -04:00
for ( it2 = parts . begin ( ) ; it2 ! = parts . end ( ) ; + + it2 , + + i )
2013-03-11 16:53:15 -04:00
{
std : : cerr < < " \" " < < it2 - > toStdString ( ) < < " \" " ;
switch ( i )
{
case 0 :
fname = it2 - > toStdString ( ) ;
break ;
case 1 :
2014-03-17 16:56:06 -04:00
hash = RsFileHash ( it2 - > toStdString ( ) ) ;
2013-03-11 16:53:15 -04:00
break ;
case 2 :
qsize = it2 - > toULongLong ( & ok , 10 ) ;
size = qsize ;
break ;
case 3 :
2014-03-17 16:56:06 -04:00
source = RsPeerId ( it2 - > toStdString ( ) ) ;
2013-03-11 16:53:15 -04:00
break ;
}
}
std : : cerr < < std : : endl ;
std : : cerr < < " \t fname: " < < fname < < std : : endl ;
std : : cerr < < " \t hash: " < < hash < < std : : endl ;
std : : cerr < < " \t size: " < < size < < std : : endl ;
std : : cerr < < " \t source: " < < source < < std : : endl ;
2014-03-17 16:56:06 -04:00
/* basic error checking */
if ( ok & & ! hash . isNull ( ) )
2013-03-11 16:53:15 -04:00
{
std : : cerr < < " Item Ok " < < std : : endl ;
2014-03-17 16:56:06 -04:00
addAttachment ( hash , fname , size , source . isNull ( ) , source ) ;
2013-03-11 16:53:15 -04:00
}
else
{
2014-03-17 16:56:06 -04:00
std : : cerr < < " Error Decode: Hash is not a hash: " < < hash < < std : : endl ;
2013-03-11 16:53:15 -04:00
}
}
}
2014-03-17 16:56:06 -04:00
void CreateGxsChannelMsg : : addAttachment ( const RsFileHash & hash , const std : : string & fname , uint64_t size , bool local , const RsPeerId & srcId )
2013-03-11 16:53:15 -04:00
{
/* add a SubFileItem to the attachment section */
std : : cerr < < " CreateGxsChannelMsg::addAttachment() " ;
std : : cerr < < std : : endl ;
/* add widget in for new destination */
uint32_t flags = SFI_TYPE_CHANNEL ;
if ( local )
{
flags | = SFI_STATE_LOCAL ;
}
else
{
flags | = SFI_STATE_REMOTE ;
}
SubFileItem * file = new SubFileItem ( hash , fname , " " , size , flags , srcId ) ; // destroyed when fileFrame (this subfileitem) is destroyed
mAttachments . push_back ( file ) ;
QLayout * layout = fileFrame - > layout ( ) ;
layout - > addWidget ( file ) ;
if ( mCheckAttachment )
{
checkAttachmentReady ( ) ;
}
return ;
}
void CreateGxsChannelMsg : : addExtraFile ( )
{
2013-07-19 05:48:51 -04:00
/* add a SubFileItem to the attachment section */
std : : cerr < < " CreateGxsChannelMsg::addExtraFile() opening file dialog " ;
std : : cerr < < std : : endl ;
QStringList files ;
if ( misc : : getOpenFileNames ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , files ) ) {
2014-10-21 18:33:02 -04:00
for ( QStringList : : iterator fileIt = files . begin ( ) ; fileIt ! = files . end ( ) ; + + fileIt ) {
2013-07-19 05:48:51 -04:00
addAttachment ( ( * fileIt ) . toUtf8 ( ) . constData ( ) ) ;
}
2013-03-12 20:33:14 -04:00
}
2013-03-11 16:53:15 -04:00
}
void CreateGxsChannelMsg : : addAttachment ( const std : : string & path )
{
/* add a SubFileItem to the attachment section */
std : : cerr < < " CreateGxsChannelMsg::addAttachment() " ;
std : : cerr < < std : : endl ;
if ( mAutoMediaThumbNail )
setThumbNail ( path , 2000 ) ;
/* add widget in for new destination */
uint32_t flags = SFI_TYPE_CHANNEL | SFI_STATE_EXTRA | SFI_FLAG_CREATE ;
// check attachment if hash exists already
std : : list < SubFileItem * > : : iterator it ;
2014-10-21 18:33:02 -04:00
for ( it = mAttachments . begin ( ) ; it ! = mAttachments . end ( ) ; + + it ) {
2013-03-11 16:53:15 -04:00
if ( ( * it ) - > FilePath ( ) = = path ) {
2013-07-19 05:48:51 -04:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " File already Added and Hashed " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2013-03-11 16:53:15 -04:00
return ;
}
}
FileInfo fInfo ;
2013-03-12 20:33:14 -04:00
std : : string filename ;
uint64_t size = 0 ;
2014-03-17 16:56:06 -04:00
RsFileHash hash ;
2013-03-12 20:33:14 -04:00
rsGxsChannels - > ExtraFileHash ( path , filename ) ;
2013-03-11 16:53:15 -04:00
2015-02-22 05:10:34 -05:00
// Only path and filename are valid.
// Destroyed when fileFrame (this subfileitem) is destroyed
// Hash will be retrieved later when the file is finished hashing.
//
2014-03-17 16:56:06 -04:00
//SubFileItem *file = new SubFileItem(hash, filename, path, size, flags, mChannelId);
SubFileItem * file = new SubFileItem ( hash , filename , path , size , flags , RsPeerId ( ) ) ;
2013-03-11 16:53:15 -04:00
mAttachments . push_back ( file ) ;
QLayout * layout = fileFrame - > layout ( ) ;
layout - > addWidget ( file ) ;
if ( mCheckAttachment )
{
checkAttachmentReady ( ) ;
}
return ;
}
bool CreateGxsChannelMsg : : setThumbNail ( const std : : string & path , int frame ) {
# ifdef CHANNELS_FRAME_CATCHER
unsigned char * imageBuffer = NULL ;
int width = 0 , height = 0 , errCode = 0 ;
int length ;
std : : string errString ;
if ( 1 ! = ( errCode = fCatcher - > open ( path ) ) ) {
fCatcher - > getError ( errCode , errString ) ;
std : : cerr < < errString < < std : : endl ;
return false ;
}
length = fCatcher - > getLength ( ) ;
// make sure frame chosen is at lease a quarter length of video length if not choose quarter length
if ( frame < ( int ) ( 0.25 * length ) )
frame = 0.25 * length ;
if ( 1 ! = ( errCode = fCatcher - > getRGBImage ( frame , imageBuffer , width , height ) ) ) {
fCatcher - > getError ( errCode , errString ) ;
std : : cerr < < errString < < std : : endl ;
return false ;
}
if ( imageBuffer = = NULL )
return false ;
QImage tNail ( imageBuffer , width , height , QImage : : Format_RGB32 ) ;
QByteArray ba ;
QBuffer buffer ( & ba ) ;
buffer . open ( QIODevice : : WriteOnly ) ;
tNail . save ( & buffer , " PNG " ) ;
QPixmap img ;
img . loadFromData ( ba , " PNG " ) ;
2014-09-28 16:19:52 -04:00
img = img . scaled ( thumbnail_label - > width ( ) , thumbnail_label - > height ( ) , Qt : : KeepAspectRatio , Qt : : SmoothTransformation ) ;
2013-03-11 16:53:15 -04:00
thumbnail_label - > setPixmap ( img ) ;
delete [ ] imageBuffer ;
# else
Q_UNUSED ( path ) ;
Q_UNUSED ( frame ) ;
# endif
return true ;
}
2013-07-19 05:48:51 -04:00
void CreateGxsChannelMsg : : allowAutoMediaThumbNail ( bool allowThumbNail )
{
2013-03-11 16:53:15 -04:00
mAutoMediaThumbNail = allowThumbNail ;
}
void CreateGxsChannelMsg : : checkAttachmentReady ( )
{
std : : list < SubFileItem * > : : iterator fit ;
mCheckAttachment = false ;
2014-10-21 18:33:02 -04:00
for ( fit = mAttachments . begin ( ) ; fit ! = mAttachments . end ( ) ; + + fit )
2013-03-11 16:53:15 -04:00
{
if ( ! ( * fit ) - > isHidden ( ) )
{
if ( ! ( * fit ) - > ready ( ) )
{
/* ensure file is hashed or file will be hashed, thus
* recognized by librs but not correctly by gui ( can ' t
* formally remove it )
*/
buttonBox - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( false ) ;
buttonBox - > button ( QDialogButtonBox : : Cancel ) - > setEnabled ( false ) ;
break ;
}
}
}
if ( fit = = mAttachments . end ( ) )
{
buttonBox - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( true ) ;
buttonBox - > button ( QDialogButtonBox : : Cancel ) - > setEnabled ( true ) ;
}
/* repeat... */
int msec_rate = 1000 ;
QTimer : : singleShot ( msec_rate , this , SLOT ( checkAttachmentReady ( void ) ) ) ;
}
void CreateGxsChannelMsg : : cancelMsg ( )
{
std : : cerr < < " CreateGxsChannelMsg::cancelMsg() : "
< < " Deleting EXTRA attachments " < < std : : endl ;
std : : cerr < < std : : endl ;
std : : list < SubFileItem * > : : const_iterator it ;
2014-10-21 18:33:02 -04:00
for ( it = mAttachments . begin ( ) ; it ! = mAttachments . end ( ) ; + + it )
2013-03-12 20:33:14 -04:00
rsGxsChannels - > ExtraFileRemove ( ( * it ) - > FileHash ( ) ) ;
2013-03-11 16:53:15 -04:00
2013-07-19 05:48:51 -04:00
reject ( ) ;
2013-03-11 16:53:15 -04:00
}
void CreateGxsChannelMsg : : newChannelMsg ( )
{
if ( ! rsGxsChannels )
return ;
2013-03-12 20:33:14 -04:00
mChannelMetaLoaded = false ;
/* request Data */
2013-03-11 16:53:15 -04:00
{
2013-03-12 20:33:14 -04:00
RsTokReqOptions opts ;
opts . mReqType = GXS_REQUEST_TYPE_GROUP_META ;
2013-03-11 16:53:15 -04:00
2014-03-17 16:56:06 -04:00
std : : list < RsGxsGroupId > groupIds ;
2013-03-12 20:33:14 -04:00
groupIds . push_back ( mChannelId ) ;
std : : cerr < < " CreateGxsChannelMsg::newChannelMsg() Req Group Summary( " < < mChannelId < < " ) " ;
std : : cerr < < std : : endl ;
uint32_t token ;
mChannelQueue - > requestGroupInfo ( token , RS_TOKREQ_ANSTYPE_SUMMARY , opts , groupIds , CREATEMSG_CHANNELINFO ) ;
2013-03-11 16:53:15 -04:00
}
2013-03-12 20:33:14 -04:00
}
2013-03-11 16:53:15 -04:00
2013-03-12 20:33:14 -04:00
void CreateGxsChannelMsg : : saveChannelInfo ( const RsGroupMetaData & meta )
{
mChannelMeta = meta ;
mChannelMetaLoaded = true ;
channelName - > setText ( QString : : fromUtf8 ( mChannelMeta . mGroupName . c_str ( ) ) ) ;
2013-03-11 16:53:15 -04:00
subjectEdit - > setFocus ( ) ;
}
void CreateGxsChannelMsg : : sendMsg ( )
{
std : : cerr < < " CreateGxsChannelMsg::sendMsg() " ;
std : : cerr < < std : : endl ;
/* construct message bits */
2013-03-12 20:33:14 -04:00
std : : string subject = std : : string ( misc : : removeNewLine ( subjectEdit - > text ( ) ) . toUtf8 ( ) ) ;
std : : string msg = std : : string ( msgEdit - > toPlainText ( ) . toUtf8 ( ) ) ;
2013-03-11 16:53:15 -04:00
2013-03-12 20:33:14 -04:00
std : : list < RsGxsFile > files ;
2013-03-11 16:53:15 -04:00
std : : list < SubFileItem * > : : iterator fit ;
2014-10-21 18:33:02 -04:00
for ( fit = mAttachments . begin ( ) ; fit ! = mAttachments . end ( ) ; + + fit )
2013-03-11 16:53:15 -04:00
{
if ( ! ( * fit ) - > isHidden ( ) )
{
2013-03-12 20:33:14 -04:00
RsGxsFile fi ;
fi . mHash = ( * fit ) - > FileHash ( ) ;
fi . mName = ( * fit ) - > FileName ( ) ;
fi . mSize = ( * fit ) - > FileSize ( ) ;
2013-03-11 16:53:15 -04:00
files . push_back ( fi ) ;
/* commence downloads - if we don't have the file */
if ( ! ( * fit ) - > done ( ) )
{
if ( ( * fit ) - > ready ( ) )
{
( * fit ) - > download ( ) ;
}
// Skips unhashed files.
}
}
}
sendMessage ( subject , msg , files ) ;
}
2013-03-12 20:33:14 -04:00
void CreateGxsChannelMsg : : sendMessage ( const std : : string & subject , const std : : string & msg , const std : : list < RsGxsFile > & files )
2013-03-11 16:53:15 -04:00
{
2013-03-12 20:33:14 -04:00
if ( subject . empty ( ) )
2013-03-11 16:53:15 -04:00
{ /* error message */
2013-07-19 05:48:51 -04:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Please add a Subject " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2013-03-11 16:53:15 -04:00
return ; //Don't add an empty Subject!!
}
else
/* rsGxsChannels */
if ( rsGxsChannels )
{
2013-03-12 20:33:14 -04:00
RsGxsChannelPost post ;
2013-07-19 05:48:51 -04:00
2013-03-12 20:33:14 -04:00
post . mMeta . mGroupId = mChannelId ;
2014-04-20 12:34:26 -04:00
post . mMeta . mParentId . clear ( ) ;
post . mMeta . mThreadId . clear ( ) ;
post . mMeta . mMsgId . clear ( ) ;
2013-07-19 05:48:51 -04:00
2013-03-12 20:33:14 -04:00
post . mMeta . mMsgName = subject ;
post . mMsg = msg ;
post . mFiles = files ;
2013-03-11 16:53:15 -04:00
QByteArray ba ;
QBuffer buffer ( & ba ) ;
2013-03-12 20:33:14 -04:00
if ( ! picture . isNull ( ) )
{
2013-03-11 16:53:15 -04:00
// send chan image
buffer . open ( QIODevice : : WriteOnly ) ;
picture . save ( & buffer , " PNG " ) ; // writes image into ba in PNG format
2013-03-12 20:33:14 -04:00
post . mThumbnail . copy ( ( uint8_t * ) ba . data ( ) , ba . size ( ) ) ;
2013-03-11 16:53:15 -04:00
}
2013-07-19 05:48:51 -04:00
2013-07-19 17:06:19 -04:00
int generateCount = 0 ;
# ifdef ENABLE_GENERATE
if ( generateCheckBox - > isChecked ( ) ) {
generateCount = 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 ;
}
}
# endif
2013-03-12 20:33:14 -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 ) {
RsGxsChannelPost generatePost = post ;
generatePost . mMeta . mMsgName = QString ( " %1 %2 " ) . arg ( QString : : fromUtf8 ( post . mMeta . mMsgName . c_str ( ) ) ) . arg ( count + 1 , 3 , 10 , QChar ( ' 0 ' ) ) . toUtf8 ( ) . constData ( ) ;
rsGxsChannels - > createPost ( token , generatePost ) ;
}
# endif
} else {
rsGxsChannels - > createPost ( token , post ) ;
}
2013-03-11 16:53:15 -04:00
}
2013-07-19 05:48:51 -04:00
accept ( ) ;
2013-03-11 16:53:15 -04:00
}
void CreateGxsChannelMsg : : addThumbnail ( )
{
QPixmap img = misc : : getOpenThumbnailedPicture ( this , tr ( " Load thumbnail picture " ) , 156 , 107 ) ;
if ( img . isNull ( ) )
return ;
picture = img ;
// to show the selected
thumbnail_label - > setPixmap ( picture ) ;
}
2013-03-12 20:33:14 -04:00
void CreateGxsChannelMsg : : loadChannelInfo ( const uint32_t & token )
{
std : : cerr < < " CreateGxsChannelMsg::loadChannelInfo() " ;
std : : cerr < < std : : endl ;
std : : list < RsGroupMetaData > groupInfo ;
rsGxsChannels - > getGroupSummary ( token , groupInfo ) ;
if ( groupInfo . size ( ) = = 1 )
{
RsGroupMetaData fi = groupInfo . front ( ) ;
saveChannelInfo ( fi ) ;
}
else
{
std : : cerr < < " CreateGxsChannelMsg::loadForumInfo() ERROR INVALID Number of Forums " ;
std : : cerr < < std : : endl ;
}
}
void CreateGxsChannelMsg : : loadRequest ( const TokenQueue * queue , const TokenRequest & req )
{
std : : cerr < < " CreateGxsChannelMsg::loadRequest() UserType: " < < req . mUserType ;
std : : cerr < < std : : endl ;
if ( queue = = mChannelQueue )
{
/* now switch on req */
switch ( req . mUserType )
{
case CREATEMSG_CHANNELINFO :
loadChannelInfo ( req . mToken ) ;
break ;
default :
std : : cerr < < " CreateGxsChannelMsg::loadRequest() UNKNOWN UserType " ;
std : : cerr < < std : : endl ;
}
}
}