2010-01-18 21:02:16 +00: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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-23 18:52:58 +00:00
# include <QDragEnterEvent>
# include <QUrl>
# include <QTimer>
# include <QMessageBox>
# include <QBuffer>
2011-09-18 19:43:38 +00:00
# include <QMenu>
2011-05-13 20:06:16 +00:00
# include <QDir>
2010-01-18 21:02:16 +00:00
2011-09-18 19:43:38 +00:00
# include <gui/RetroShareLink.h>
2010-07-23 18:52:58 +00:00
# include "CreateChannelMsg.h"
2010-01-18 21:02:16 +00:00
# include "gui/feeds/SubFileItem.h"
2010-11-09 19:57:05 +00:00
# include "util/misc.h"
2010-01-18 21:02:16 +00:00
2010-08-06 09:40:23 +00:00
# include <retroshare/rschannels.h>
# include <retroshare/rsfiles.h>
2010-01-18 21:02:16 +00:00
# include <iostream>
/** Constructor */
CreateChannelMsg : : CreateChannelMsg ( std : : string cId )
2010-11-19 00:47:18 +00:00
: QDialog ( NULL ) , mChannelId ( cId ) , mCheckAttachment ( true ) , mAutoMediaThumbNail ( false )
2010-01-18 21:02:16 +00:00
{
/* Invoke the Qt Designer generated object setup routine */
setupUi ( this ) ;
2010-05-05 00:05:36 +00:00
setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
2010-01-18 21:02:16 +00:00
connect ( buttonBox , SIGNAL ( accepted ( ) ) , this , SLOT ( sendMsg ( ) ) ) ;
2011-09-18 19:43:38 +00:00
connect ( buttonBox , SIGNAL ( rejected ( ) ) , this , SLOT ( cancelMsg ( ) ) ) ;
2010-01-18 21:02:16 +00:00
connect ( addFileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
2010-01-18 22:30:21 +00:00
connect ( addfilepushButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
connect ( addThumbnailButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addThumbnail ( ) ) ) ;
2010-11-19 00:47:18 +00:00
connect ( thumbNailCb , SIGNAL ( toggled ( bool ) ) , this , SLOT ( allowAutoMediaThumbNail ( bool ) ) ) ;
2011-09-18 19:43:38 +00:00
connect ( tabWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
2011-02-11 00:06:00 +00:00
thumbNailCb - > setVisible ( false ) ;
thumbNailCb - > setEnabled ( false ) ;
2010-11-19 00:47:18 +00:00
# ifdef CHANNELS_FRAME_CATCHER
fCatcher = new framecatcher ( ) ;
2011-02-11 00:06:00 +00:00
thumbNailCb - > setVisible ( true ) ;
thumbNailCb - > setEnabled ( true ) ;
2010-11-19 00:47:18 +00:00
# endif
2010-10-04 18:43:13 +00:00
//buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
2010-01-18 21:02:16 +00:00
setAcceptDrops ( true ) ;
newChannelMsg ( ) ;
}
2011-09-18 19:43:38 +00:00
void CreateChannelMsg : : 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 )
n_file + + ;
QMenu contextMnu ( this ) ;
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 ( ) ) ) ;
action - > setDisabled ( n_file < 1 ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
void CreateChannelMsg : : 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 ;
FileInfo info ;
if ( rsFiles - > alreadyHaveFile ( ( * it ) . hash ( ) . toStdString ( ) , info ) )
2012-03-30 19:43:39 +00:00
addAttachment ( ( * it ) . hash ( ) . toStdString ( ) , ( * it ) . name ( ) . toUtf8 ( ) . constData ( ) , ( * it ) . size ( ) , true , " " ) ;
2011-09-18 19:43:38 +00:00
else
not_have . push_back ( * it ) ;
}
if ( ! not_have . empty ( ) )
{
2011-10-05 16:57:33 +00:00
QString msg = tr ( " Channel security policy prevents you from posting files that you don't have. If you have these files, you need to share them before, or attach them explicitly: " ) + " <br><br> " ;
2011-09-18 19:43:38 +00:00
for ( QList < RetroShareLink > : : const_iterator it ( not_have . begin ( ) ) ; it ! = not_have . end ( ) ; + + it )
2011-10-05 16:57:33 +00:00
msg + = ( * it ) . toString ( ) + " <br> " ;
2011-09-18 19:43:38 +00:00
QMessageBox : : warning ( NULL , tr ( " You can only post files that you do have " ) , msg ) ;
}
}
2010-11-19 00:47:18 +00:00
CreateChannelMsg : : ~ CreateChannelMsg ( ) {
# ifdef CHANNELS_FRAME_CATCHER
delete fCatcher ;
# endif
}
2010-01-18 21:02:16 +00:00
/* Dropping */
void CreateChannelMsg : : dragEnterEvent ( QDragEnterEvent * event )
{
/* print out mimeType */
std : : cerr < < " CreateChannelMsg::dragEnterEvent() Formats " ;
std : : cerr < < std : : endl ;
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; it + + )
{
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasFormat ( " text/plain " ) )
{
std : : cerr < < " CreateChannelMsg::dragEnterEvent() Accepting PlainText " ;
std : : cerr < < std : : endl ;
event - > acceptProposedAction ( ) ;
}
else if ( event - > mimeData ( ) - > hasUrls ( ) )
{
std : : cerr < < " CreateChannelMsg::dragEnterEvent() Accepting Urls " ;
std : : cerr < < std : : endl ;
event - > acceptProposedAction ( ) ;
}
else if ( event - > mimeData ( ) - > hasFormat ( " application/x-rsfilelist " ) )
{
std : : cerr < < " CreateChannelMsg::dragEnterEvent() accepting Application/x-qabs... " ;
std : : cerr < < std : : endl ;
event - > acceptProposedAction ( ) ;
}
else
{
std : : cerr < < " CreateChannelMsg::dragEnterEvent() No PlainText/Urls " ;
std : : cerr < < std : : endl ;
}
}
void CreateChannelMsg : : dropEvent ( QDropEvent * event )
{
if ( ! ( Qt : : CopyAction & event - > possibleActions ( ) ) )
{
std : : cerr < < " CreateChannelMsg::dropEvent() Rejecting uncopyable DropAction " ;
std : : cerr < < std : : endl ;
/* can't do it */
return ;
}
2011-05-13 20:06:16 +00:00
std : : cerr < < " CreateChannelMsg::dropEvent() Formats " < < std : : endl ;
2010-01-18 21:02:16 +00:00
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; it + + )
{
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasText ( ) )
{
std : : cerr < < " CreateChannelMsg::dropEvent() Plain Text: " ;
std : : cerr < < std : : endl ;
std : : cerr < < event - > mimeData ( ) - > text ( ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasUrls ( ) )
{
2011-05-13 20:06:16 +00:00
std : : cerr < < " CreateChannelMsg::dropEvent() Urls: " < < std : : endl ;
2010-01-18 21:02:16 +00:00
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
QList < QUrl > : : iterator uit ;
for ( uit = urls . begin ( ) ; uit ! = urls . end ( ) ; uit + + )
{
2011-05-13 20:06:16 +00:00
QString localpath = uit - > toLocalFile ( ) ;
std : : cerr < < " Whole URL: " < < uit - > toString ( ) . toStdString ( ) < < std : : endl ;
std : : cerr < < " or As Local File: " < < localpath . toStdString ( ) < < std : : endl ;
2010-01-18 21:02:16 +00:00
2011-05-13 20:06:16 +00:00
if ( localpath . isEmpty ( ) = = false )
2010-01-18 21:02:16 +00:00
{
2011-05-13 20:06:16 +00:00
// Check that the file does exist and is not a directory
QDir dir ( localpath ) ;
if ( dir . exists ( ) ) {
std : : cerr < < " CreateChannelMsg::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 < < " CreateChannelMsg::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 ( ) ;
}
2010-01-18 21:02:16 +00:00
}
}
}
else if ( event - > mimeData ( ) - > hasFormat ( " application/x-rsfilelist " ) )
{
std : : cerr < < " CreateChannelMsg::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 ( ) ;
}
2010-10-06 00:08:20 +00:00
void CreateChannelMsg : : parseRsFileListAttachments ( const std : : string & attachList )
2010-01-18 21:02:16 +00:00
{
/* split into lines */
QString input = QString : : fromStdString ( attachList ) ;
QStringList attachItems = input . split ( " \n " ) ;
QStringList : : iterator it ;
QStringList : : iterator it2 ;
for ( it = attachItems . begin ( ) ; it ! = attachItems . end ( ) ; it + + )
{
std : : cerr < < " CreateChannelMsg::parseRsFileListAttachments() Entry: " ;
QStringList parts = ( * it ) . split ( " / " ) ;
bool ok = false ;
quint64 qsize = 0 ;
std : : string fname ;
std : : string hash ;
uint64_t size = 0 ;
std : : string source ;
int i = 0 ;
for ( it2 = parts . begin ( ) ; it2 ! = parts . end ( ) ; it2 + + , i + + )
{
std : : cerr < < " \" " < < it2 - > toStdString ( ) < < " \" " ;
switch ( i )
{
case 0 :
fname = it2 - > toStdString ( ) ;
break ;
case 1 :
hash = it2 - > toStdString ( ) ;
break ;
case 2 :
qsize = it2 - > toULongLong ( & ok , 10 ) ;
size = qsize ;
break ;
case 3 :
source = it2 - > toStdString ( ) ;
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 ;
/* basic error checking */
if ( ( ok ) & & ( hash . size ( ) = = 40 ) )
{
std : : cerr < < " Item Ok " < < std : : endl ;
if ( source = = " Local " )
{
addAttachment ( hash , fname , size , true , " " ) ;
}
else
{
// TEMP NOT ALLOWED UNTIL FT WORKING.
addAttachment ( hash , fname , size , false , source ) ;
}
}
else
{
std : : cerr < < " Error Decode: Hash size: " < < hash . size ( ) < < std : : endl ;
}
}
}
2010-10-06 00:08:20 +00:00
void CreateChannelMsg : : addAttachment ( const std : : string & hash , const std : : string & fname , uint64_t size , bool local , const std : : string & srcId )
2010-01-18 21:02:16 +00:00
{
/* add a SubFileItem to the attachment section */
std : : cerr < < " CreateChannelMsg::addAttachment() " ;
std : : cerr < < std : : endl ;
/* add widget in for new destination */
2010-05-08 16:21:57 +00:00
uint32_t flags = SFI_TYPE_CHANNEL ;
2010-01-18 21:02:16 +00:00
if ( local )
{
flags | = SFI_STATE_LOCAL ;
}
else
{
flags | = SFI_STATE_REMOTE ;
}
2010-05-08 16:21:57 +00:00
SubFileItem * file = new SubFileItem ( hash , fname , " " , size , flags , srcId ) ; // destroyed when fileFrame (this subfileitem) is destroyed
2010-01-18 21:02:16 +00:00
mAttachments . push_back ( file ) ;
QLayout * layout = fileFrame - > layout ( ) ;
layout - > addWidget ( file ) ;
if ( mCheckAttachment )
{
checkAttachmentReady ( ) ;
}
return ;
}
void CreateChannelMsg : : addExtraFile ( )
{
2010-12-03 00:54:40 +00:00
/* add a SubFileItem to the attachment section */
std : : cerr < < " CreateChannelMsg::addExtraFile() opening file dialog " ;
std : : cerr < < std : : endl ;
QStringList files ;
if ( misc : : getOpenFileNames ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , files ) ) {
for ( QStringList : : iterator fileIt = files . begin ( ) ; fileIt ! = files . end ( ) ; fileIt + + ) {
addAttachment ( ( * fileIt ) . toUtf8 ( ) . constData ( ) ) ;
}
2010-11-29 15:21:00 +00:00
}
2010-01-18 21:02:16 +00:00
}
2010-10-06 00:08:20 +00:00
void CreateChannelMsg : : addAttachment ( const std : : string & path )
2010-01-18 21:02:16 +00:00
{
/* add a SubFileItem to the attachment section */
std : : cerr < < " CreateChannelMsg::addAttachment() " ;
std : : cerr < < std : : endl ;
2010-11-19 00:47:18 +00:00
if ( mAutoMediaThumbNail )
setThumbNail ( path , 2000 ) ;
2010-01-18 21:02:16 +00:00
/* add widget in for new destination */
2011-07-06 23:46:16 +00:00
uint32_t flags = SFI_TYPE_CHANNEL | SFI_STATE_EXTRA | SFI_FLAG_CREATE ;
2010-10-26 22:41:47 +00:00
// check attachment if hash exists already
std : : list < SubFileItem * > : : iterator it ;
for ( it = mAttachments . begin ( ) ; it ! = mAttachments . end ( ) ; it + + ) {
if ( ( * it ) - > FilePath ( ) = = path ) {
QMessageBox : : warning ( this , tr ( " RetroShare " ) ,
tr ( " File already Added and Hashed " ) ,
QMessageBox : : Ok , QMessageBox : : Ok ) ;
return ;
}
}
2010-05-08 16:21:57 +00:00
// channels creates copy of file into channels directory and shares this
FileInfo fInfo ;
rsChannels - > channelExtraFileHash ( path , mChannelId , fInfo ) ;
// file is not innitial
SubFileItem * file = new SubFileItem ( fInfo . hash , fInfo . fname , fInfo . path , fInfo . size ,
flags , mChannelId ) ; // destroyed when fileFrame (this subfileitem) is destroyed
2010-01-18 21:02:16 +00:00
mAttachments . push_back ( file ) ;
QLayout * layout = fileFrame - > layout ( ) ;
layout - > addWidget ( file ) ;
if ( mCheckAttachment )
{
checkAttachmentReady ( ) ;
}
return ;
}
2010-11-19 00:47:18 +00:00
bool CreateChannelMsg : : 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 " ) ;
img = img . scaled ( thumbnail_label - > width ( ) , thumbnail_label - > height ( ) , Qt : : KeepAspectRatio ) ;
thumbnail_label - > setPixmap ( img ) ;
delete [ ] imageBuffer ;
2011-08-12 14:06:29 +00:00
# else
Q_UNUSED ( path ) ;
Q_UNUSED ( frame ) ;
2010-11-19 00:47:18 +00:00
# endif
return true ;
}
void CreateChannelMsg : : allowAutoMediaThumbNail ( bool allowThumbNail ) {
mAutoMediaThumbNail = allowThumbNail ;
}
2010-01-18 21:02:16 +00:00
void CreateChannelMsg : : checkAttachmentReady ( )
{
std : : list < SubFileItem * > : : iterator fit ;
mCheckAttachment = false ;
for ( fit = mAttachments . begin ( ) ; fit ! = mAttachments . end ( ) ; fit + + )
{
if ( ! ( * fit ) - > isHidden ( ) )
{
if ( ! ( * fit ) - > ready ( ) )
{
2010-05-08 16:21:57 +00:00
/* ensure file is hashed or file will be hashed, thus
* recognized by librs but not correctly by gui ( can ' t
* formally remove it )
2010-01-18 21:02:16 +00:00
*/
buttonBox - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( false ) ;
2010-05-08 16:21:57 +00:00
buttonBox - > button ( QDialogButtonBox : : Cancel ) - > setEnabled ( false ) ;
2010-01-18 21:02:16 +00:00
break ;
}
}
}
if ( fit = = mAttachments . end ( ) )
{
buttonBox - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( true ) ;
2010-05-08 16:21:57 +00:00
buttonBox - > button ( QDialogButtonBox : : Cancel ) - > setEnabled ( true ) ;
2010-01-18 21:02:16 +00:00
}
/* repeat... */
int msec_rate = 1000 ;
QTimer : : singleShot ( msec_rate , this , SLOT ( checkAttachmentReady ( void ) ) ) ;
}
void CreateChannelMsg : : cancelMsg ( )
{
2010-05-08 16:21:57 +00:00
std : : cerr < < " CreateChannelMsg::cancelMsg() : "
< < " Deleting EXTRA attachments " < < std : : endl ;
2010-01-18 21:02:16 +00:00
std : : cerr < < std : : endl ;
2010-05-08 16:21:57 +00:00
std : : list < SubFileItem * > : : const_iterator it ;
for ( it = mAttachments . begin ( ) ; it ! = mAttachments . end ( ) ; it + + )
rsChannels - > channelExtraFileRemove ( ( * it ) - > FileHash ( ) , mChannelId ) ;
2010-01-18 21:02:16 +00:00
close ( ) ;
return ;
}
void CreateChannelMsg : : newChannelMsg ( )
{
if ( ! rsChannels )
return ;
ChannelInfo ci ;
if ( ! rsChannels - > getChannelInfo ( mChannelId , ci ) )
{
return ;
}
channelName - > setText ( QString : : fromStdWString ( ci . channelName ) ) ;
2012-02-05 14:56:27 +00:00
subjectEdit - > setFocus ( ) ;
2010-01-18 21:02:16 +00:00
}
void CreateChannelMsg : : sendMsg ( )
{
std : : cerr < < " CreateChannelMsg::sendMsg() " ;
std : : cerr < < std : : endl ;
/* construct message bits */
2010-11-09 19:57:05 +00:00
std : : wstring subject = misc : : removeNewLine ( subjectEdit - > text ( ) ) . toStdWString ( ) ;
2010-01-18 21:02:16 +00:00
std : : wstring msg = msgEdit - > toPlainText ( ) . toStdWString ( ) ;
std : : list < FileInfo > files ;
std : : list < SubFileItem * > : : iterator fit ;
for ( fit = mAttachments . begin ( ) ; fit ! = mAttachments . end ( ) ; fit + + )
{
if ( ! ( * fit ) - > isHidden ( ) )
{
FileInfo fi ;
fi . hash = ( * fit ) - > FileHash ( ) ;
fi . fname = ( * fit ) - > FileName ( ) ;
fi . size = ( * fit ) - > FileSize ( ) ;
files . push_back ( fi ) ;
/* commence downloads - if we don't have the file */
2010-05-08 16:21:57 +00:00
2010-01-18 21:02:16 +00:00
if ( ! ( * fit ) - > done ( ) )
{
if ( ( * fit ) - > ready ( ) )
{
( * fit ) - > download ( ) ;
}
2010-05-08 16:21:57 +00:00
// Skips unhashed files.
2010-01-18 21:02:16 +00:00
}
}
}
sendMessage ( subject , msg , files ) ;
}
void CreateChannelMsg : : sendMessage ( std : : wstring subject , std : : wstring msg , std : : list < FileInfo > & files )
{
2010-11-09 19:57:05 +00:00
QString name = misc : : removeNewLine ( subjectEdit - > text ( ) ) ;
2010-01-18 21:02:16 +00:00
if ( name . isEmpty ( ) )
{ /* error message */
2010-07-23 18:52:58 +00:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) ,
2010-01-18 21:02:16 +00:00
tr ( " Please add a Subject " ) ,
QMessageBox : : Ok , QMessageBox : : Ok ) ;
2010-05-08 16:21:57 +00:00
return ; //Don't add an empty Subject!!
2010-01-18 21:02:16 +00:00
}
else
/* rsChannels */
if ( rsChannels )
{
ChannelMsgInfo msgInfo ;
msgInfo . channelId = mChannelId ;
msgInfo . msgId = " " ;
msgInfo . subject = subject ;
msgInfo . msg = msg ;
msgInfo . files = files ;
2010-07-17 20:17:14 +00:00
QByteArray ba ;
QBuffer buffer ( & ba ) ;
if ( ! picture . isNull ( ) ) {
// send chan image
buffer . open ( QIODevice : : WriteOnly ) ;
picture . save ( & buffer , " PNG " ) ; // writes image into ba in PNG format
msgInfo . thumbnail . image_thumbnail = ( unsigned char * ) ba . data ( ) ;
msgInfo . thumbnail . im_thumbnail_size = ba . size ( ) ;
}
2010-01-18 21:02:16 +00:00
rsChannels - > ChannelMessageSend ( msgInfo ) ;
}
close ( ) ;
return ;
}
2010-01-18 22:30:21 +00:00
void CreateChannelMsg : : addThumbnail ( )
{
2011-08-12 20:27:05 +00:00
QPixmap img = misc : : getOpenThumbnailedPicture ( this , tr ( " Load thumbnail picture " ) , 156 , 107 ) ;
2010-01-18 22:30:21 +00:00
2011-08-12 20:27:05 +00:00
if ( img . isNull ( ) )
return ;
2010-01-18 21:02:16 +00:00
2011-08-12 20:27:05 +00:00
picture = img ;
2010-01-18 21:02:16 +00:00
2011-08-12 20:27:05 +00:00
// to show the selected
thumbnail_label - > setPixmap ( picture ) ;
2010-01-18 22:30:21 +00:00
}