2007-11-14 22:18:48 -05:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* 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 .
2008-09-04 15:28:35 -04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-11-28 09:34:15 -05:00
2008-09-04 15:28:35 -04:00
# include "MessagesDialog.h"
2007-11-14 22:18:48 -05:00
# include "msgs/ChanMsgDialog.h"
# include "gui/toaster/MessageToaster.h"
2008-03-26 10:22:51 -04:00
# include "util/printpreview.h"
2009-07-10 19:48:20 -04:00
# include "util/misc.h"
2007-11-14 22:18:48 -05:00
2008-02-05 08:45:04 -05:00
# include "rsiface/rsiface.h"
2008-02-04 12:55:59 -05:00
# include "rsiface/rspeers.h"
# include "rsiface/rsmsgs.h"
2008-07-02 12:59:56 -04:00
# include "rsiface/rsfiles.h"
2007-11-14 22:18:48 -05:00
# include <sstream>
2009-02-11 13:43:37 -05:00
# include <list>
# include <iostream>
# include <string>
2007-11-14 22:18:48 -05:00
# include <QContextMenuEvent>
# include <QMenu>
# include <QCursor>
# include <QPoint>
# include <QMouseEvent>
# include <QPixmap>
2008-09-04 15:28:35 -04:00
# include <QPrintDialog>
2008-03-26 10:22:51 -04:00
# include <QPrinter>
2007-11-14 22:18:48 -05:00
# include <QDateTime>
2007-11-18 18:35:53 -05:00
# include <QHeaderView>
2007-11-14 22:18:48 -05:00
2008-09-04 15:28:35 -04:00
/* Images for context menu icons */
2008-11-25 20:19:09 -05:00
# define IMAGE_MESSAGE ": / images / folder-draft.png"
# define IMAGE_MESSAGEREPLY ": / images / mail_reply.png"
2009-02-09 08:24:05 -05:00
# define IMAGE_MESSAGEREPLYALL ": / images / mail_replyall.png"
2008-11-25 20:19:09 -05:00
# define IMAGE_MESSAGEFORWARD ": / images / mail_forward.png"
# define IMAGE_MESSAGEREMOVE ": / images / message-mail-imapdelete.png"
# define IMAGE_DOWNLOAD ": / images / start.png"
# define IMAGE_DOWNLOADALL ": / images / startall.png"
2007-11-14 22:18:48 -05:00
2008-09-04 15:28:35 -04:00
/** Constructor */
MessagesDialog : : MessagesDialog ( QWidget * parent )
: MainPage ( parent )
{
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2010-01-25 07:44:12 -05:00
/* Create RshareSettings object */
_settings = new RshareSettings ( ) ;
2008-09-04 15:28:35 -04:00
connect ( ui . msgWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( messageslistWidgetCostumPopupMenu ( QPoint ) ) ) ;
connect ( ui . msgList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( msgfilelistWidgetCostumPopupMenu ( QPoint ) ) ) ;
2009-02-22 12:36:39 -05:00
connect ( ui . msgWidget , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( updateCurrentMessage ( QTreeWidgetItem * , QTreeWidgetItem * ) ) ) ;
2007-11-14 22:18:48 -05:00
connect ( ui . listWidget , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( changeBox ( int ) ) ) ;
connect ( ui . newmessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( newmessage ( ) ) ) ;
connect ( ui . removemessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
2008-09-03 08:56:37 -04:00
connect ( ui . replymessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( replytomessage ( ) ) ) ;
2009-02-09 08:24:05 -05:00
connect ( ui . replyallmessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( replyallmessage ( ) ) ) ;
2008-11-25 20:19:09 -05:00
connect ( ui . forwardmessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( forwardmessage ( ) ) ) ;
2008-03-26 10:22:51 -04:00
connect ( ui . actionPrint , SIGNAL ( triggered ( ) ) , this , SLOT ( print ( ) ) ) ;
connect ( ui . actionPrintPreview , SIGNAL ( triggered ( ) ) , this , SLOT ( printpreview ( ) ) ) ;
2008-01-26 08:08:28 -05:00
connect ( ui . expandFilesButton , SIGNAL ( clicked ( ) ) , this , SLOT ( togglefileview ( ) ) ) ;
2009-05-17 15:38:42 -04:00
connect ( ui . downloadButton , SIGNAL ( clicked ( ) ) , this , SLOT ( getcurrentrecommended ( ) ) ) ;
2007-11-14 22:18:48 -05:00
2010-01-16 13:03:35 -05:00
connect ( ui . msgText , SIGNAL ( anchorClicked ( const QUrl & ) ) , SLOT ( anchorClicked ( const QUrl & ) ) ) ;
2010-01-21 20:05:45 -05:00
connect ( ui . actionTextBesideIcon , SIGNAL ( triggered ( ) ) , this , SLOT ( buttonstextbesideicon ( ) ) ) ;
connect ( ui . actionIconOnly , SIGNAL ( triggered ( ) ) , this , SLOT ( buttonsicononly ( ) ) ) ;
connect ( ui . actionTextUnderIcon , SIGNAL ( triggered ( ) ) , this , SLOT ( buttonstextundericon ( ) ) ) ;
2010-01-22 14:23:12 -05:00
connect ( ui . actionSave_as , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
2007-11-14 22:18:48 -05:00
mCurrCertId = " " ;
mCurrMsgId = " " ;
/* hide the Tree +/- */
2007-11-18 18:35:53 -05:00
ui . msgList - > setRootIsDecorated ( false ) ;
2009-05-17 15:38:42 -04:00
ui . msgList - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
2008-03-27 19:40:37 -04:00
ui . msgWidget - > setRootIsDecorated ( false ) ;
2007-11-18 18:35:53 -05:00
/* Set header resize modes and initial section sizes */
2008-09-04 15:28:35 -04:00
QHeaderView * msgwheader = ui . msgWidget - > header ( ) ;
2008-03-27 19:40:37 -04:00
msgwheader - > setResizeMode ( 0 , QHeaderView : : Custom ) ;
2008-09-04 15:28:35 -04:00
msgwheader - > setResizeMode ( 3 , QHeaderView : : Interactive ) ;
2008-03-27 19:40:37 -04:00
msgwheader - > resizeSection ( 0 , 24 ) ;
2010-01-25 18:58:48 -05:00
msgwheader - > resizeSection ( 1 , 250 ) ;
msgwheader - > resizeSection ( 2 , 140 ) ;
2008-03-27 19:40:37 -04:00
msgwheader - > resizeSection ( 3 , 140 ) ;
2007-11-18 18:35:53 -05:00
/* Set header resize modes and initial section sizes */
2008-09-04 15:28:35 -04:00
QHeaderView * msglheader = ui . msgList - > header ( ) ;
2009-07-10 19:48:20 -04:00
msglheader - > setResizeMode ( 0 , QHeaderView : : Interactive ) ;
2008-09-04 15:28:35 -04:00
msglheader - > setResizeMode ( 1 , QHeaderView : : Interactive ) ;
2007-11-18 18:35:53 -05:00
msglheader - > setResizeMode ( 2 , QHeaderView : : Interactive ) ;
2008-09-04 15:28:35 -04:00
msglheader - > setResizeMode ( 3 , QHeaderView : : Interactive ) ;
2008-03-22 21:13:09 -04:00
msglheader - > resizeSection ( 0 , 200 ) ;
2007-11-18 18:35:53 -05:00
msglheader - > resizeSection ( 1 , 100 ) ;
2008-03-22 21:13:09 -04:00
msglheader - > resizeSection ( 2 , 100 ) ;
msglheader - > resizeSection ( 3 , 200 ) ;
2008-11-25 20:19:09 -05:00
ui . forwardmessageButton - > setToolTip ( tr ( " Forward selected Message " ) ) ;
2010-01-21 11:35:00 -05:00
ui . replyallmessageButton - > setToolTip ( tr ( " Reply to All " ) ) ;
2008-11-25 20:19:09 -05:00
2008-09-04 15:28:35 -04:00
QMenu * printmenu = new QMenu ( ) ;
printmenu - > addAction ( ui . actionPrint ) ;
printmenu - > addAction ( ui . actionPrintPreview ) ;
2008-03-26 10:22:51 -04:00
ui . printbutton - > setMenu ( printmenu ) ;
2010-01-21 20:05:45 -05:00
QMenu * viewmenu = new QMenu ( ) ;
viewmenu - > addAction ( ui . actionTextBesideIcon ) ;
viewmenu - > addAction ( ui . actionIconOnly ) ;
viewmenu - > addAction ( ui . actionTextUnderIcon ) ;
ui . viewtoolButton - > setMenu ( viewmenu ) ;
2007-11-14 22:18:48 -05:00
2008-09-04 15:28:35 -04:00
ui . msgWidget - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
2008-11-25 20:19:09 -05:00
ui . msgWidget - > sortItems ( 3 , Qt : : DescendingOrder ) ;
2010-01-25 07:44:12 -05:00
loadToolButtonsettings ( ) ;
2010-01-25 18:58:48 -05:00
mFont = QFont ( " Times " , 11 , QFont : : Bold ) ;
ui . subjectText - > setFont ( mFont ) ;
2008-09-04 15:28:35 -04:00
/* Hide platform specific features */
# ifdef Q_WS_WIN
# endif
}
void MessagesDialog : : keyPressEvent ( QKeyEvent * e )
{
if ( e - > key ( ) = = Qt : : Key_Delete )
{
removemessage ( ) ;
e - > accept ( ) ;
}
else
MainPage : : keyPressEvent ( e ) ;
}
void MessagesDialog : : messageslistWidgetCostumPopupMenu ( QPoint point )
{
QMenu contextMnu ( this ) ;
QMouseEvent * mevent = new QMouseEvent ( QEvent : : MouseButtonPress , point , Qt : : RightButton , Qt : : RightButton , Qt : : NoModifier ) ;
contextMnu . clear ( ) ;
newmsgAct = new QAction ( QIcon ( IMAGE_MESSAGE ) , tr ( " New Message " ) , this ) ;
2007-11-14 22:18:48 -05:00
connect ( newmsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( newmessage ( ) ) ) ;
2008-09-04 15:28:35 -04:00
int nn = ui . msgWidget - > selectedItems ( ) . size ( ) ;
if ( nn > 1 )
{
removemsgAct = new QAction ( QIcon ( IMAGE_MESSAGEREMOVE ) , tr ( " Remove Messages " ) , this ) ;
connect ( removemsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
contextMnu . addAction ( removemsgAct ) ;
}
else if ( nn = = 1 )
{
replytomsgAct = new QAction ( QIcon ( IMAGE_MESSAGEREPLY ) , tr ( " Reply to Message " ) , this ) ;
connect ( replytomsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( replytomessage ( ) ) ) ;
contextMnu . addAction ( replytomsgAct ) ;
2009-02-09 08:24:05 -05:00
replyallmsgAct = new QAction ( QIcon ( IMAGE_MESSAGEREPLYALL ) , tr ( " Reply to All " ) , this ) ;
connect ( replyallmsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( replyallmessage ( ) ) ) ;
contextMnu . addAction ( replyallmsgAct ) ;
2008-11-25 20:19:09 -05:00
forwardmsgAct = new QAction ( QIcon ( IMAGE_MESSAGEFORWARD ) , tr ( " Forward Message " ) , this ) ;
connect ( forwardmsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( forwardmessage ( ) ) ) ;
contextMnu . addAction ( forwardmsgAct ) ;
contextMnu . addSeparator ( ) ;
2008-09-04 15:28:35 -04:00
removemsgAct = new QAction ( QIcon ( IMAGE_MESSAGEREMOVE ) , tr ( " Remove Message " ) , this ) ;
connect ( removemsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
contextMnu . addAction ( removemsgAct ) ;
}
2010-01-22 14:23:12 -05:00
contextMnu . addAction ( ui . actionSave_as ) ;
contextMnu . addAction ( ui . actionPrintPreview ) ;
contextMnu . addAction ( ui . actionPrint ) ;
contextMnu . addSeparator ( ) ;
2007-11-14 22:18:48 -05:00
contextMnu . addAction ( newmsgAct ) ;
2008-09-04 15:28:35 -04:00
contextMnu . exec ( mevent - > globalPos ( ) ) ;
}
void MessagesDialog : : msgfilelistWidgetCostumPopupMenu ( QPoint point )
{
QMenu contextMnu ( this ) ;
QMouseEvent * mevent = new QMouseEvent ( QEvent : : MouseButtonPress , point , Qt : : RightButton , Qt : : RightButton , Qt : : NoModifier ) ;
2009-05-17 15:38:42 -04:00
getRecAct = new QAction ( QIcon ( IMAGE_DOWNLOAD ) , tr ( " Download " ) , this ) ;
connect ( getRecAct , SIGNAL ( triggered ( ) ) , this , SLOT ( getcurrentrecommended ( ) ) ) ;
2007-11-14 22:18:48 -05:00
2009-05-17 15:38:42 -04:00
// getAllRecAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Download" ), this );
// connect( getAllRecAct , SIGNAL( triggered() ), this, SLOT( getallrecommended() ) );
2007-11-14 22:18:48 -05:00
2008-09-04 15:28:35 -04:00
contextMnu . clear ( ) ;
2009-05-17 15:38:42 -04:00
contextMnu . addAction ( getRecAct ) ;
// contextMnu.addAction( getAllRecAct);
2008-09-04 15:28:35 -04:00
contextMnu . exec ( mevent - > globalPos ( ) ) ;
}
2007-11-14 22:18:48 -05:00
void MessagesDialog : : newmessage ( )
{
ChanMsgDialog * nMsgDialog = new ChanMsgDialog ( true ) ;
/* fill it in */
//std::cerr << "MessagesDialog::newmessage()" << std::endl;
nMsgDialog - > newMsg ( ) ;
nMsgDialog - > show ( ) ;
2007-11-18 18:35:53 -05:00
nMsgDialog - > activateWindow ( ) ;
2007-11-14 22:18:48 -05:00
/* window will destroy itself! */
}
2008-09-04 15:28:35 -04:00
void MessagesDialog : : replytomessage ( )
2007-11-14 22:18:48 -05:00
{
/* put msg on msgBoard, and switch to it. */
2008-09-03 08:56:37 -04:00
std : : string cid ;
std : : string mid ;
2007-11-14 22:18:48 -05:00
2008-09-03 08:56:37 -04:00
if ( ! getCurrentMsg ( cid , mid ) )
return ;
mCurrCertId = cid ;
mCurrMsgId = mid ;
MessageInfo msgInfo ;
if ( ! rsMsgs - > getMessage ( mid , msgInfo ) )
return ;
ChanMsgDialog * nMsgDialog = new ChanMsgDialog ( true ) ;
/* fill it in */
//std::cerr << "MessagesDialog::newmessage()" << std::endl;
nMsgDialog - > newMsg ( ) ;
2010-01-15 21:42:11 -05:00
QString text = QString : : fromStdWString ( msgInfo . title ) ;
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
nMsgDialog - > insertTitleText ( QString : : fromStdWString ( msgInfo . title ) . toStdString ( ) ) ;
}
else
{
2008-09-03 08:56:37 -04:00
nMsgDialog - > insertTitleText ( ( QString ( " Re: " ) + QString : : fromStdWString ( msgInfo . title ) ) . toStdString ( ) ) ;
2010-01-15 21:42:11 -05:00
}
2010-01-21 11:35:00 -05:00
nMsgDialog - > setWindowTitle ( tr ( " Compose: " ) + tr ( " Re: " ) + QString : : fromStdWString ( msgInfo . title ) ) ;
2008-11-25 20:19:09 -05:00
2008-09-03 08:56:37 -04:00
QTextDocument doc ;
doc . setHtml ( QString : : fromStdWString ( msgInfo . msg ) ) ;
std : : string cited_text ( doc . toPlainText ( ) . toStdString ( ) ) ;
2008-09-08 08:41:46 -04:00
nMsgDialog - > insertPastedText ( cited_text ) ;
2008-09-03 08:56:37 -04:00
nMsgDialog - > addRecipient ( msgInfo . srcId ) ;
nMsgDialog - > show ( ) ;
nMsgDialog - > activateWindow ( ) ;
2007-11-14 22:18:48 -05:00
}
2009-02-09 08:24:05 -05:00
void MessagesDialog : : replyallmessage ( )
{
/* put msg on msgBoard, and switch to it. */
std : : string cid ;
std : : string mid ;
if ( ! getCurrentMsg ( cid , mid ) )
return ;
mCurrCertId = cid ;
mCurrMsgId = mid ;
MessageInfo msgInfo ;
if ( ! rsMsgs - > getMessage ( mid , msgInfo ) )
return ;
ChanMsgDialog * nMsgDialog = new ChanMsgDialog ( true ) ;
/* fill it in */
//std::cerr << "MessagesDialog::newmessage()" << std::endl;
nMsgDialog - > newMsg ( ) ;
2010-01-15 21:42:11 -05:00
QString text = QString : : fromStdWString ( msgInfo . title ) ;
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
nMsgDialog - > insertTitleText ( QString : : fromStdWString ( msgInfo . title ) . toStdString ( ) ) ;
}
else
{
2009-02-09 08:24:05 -05:00
nMsgDialog - > insertTitleText ( ( QString ( " Re: " ) + QString : : fromStdWString ( msgInfo . title ) ) . toStdString ( ) ) ;
2010-01-15 21:42:11 -05:00
}
2010-01-21 11:35:00 -05:00
nMsgDialog - > setWindowTitle ( tr ( " Compose: " ) + tr ( " Re: " ) + QString : : fromStdWString ( msgInfo . title ) ) ;
2009-02-09 08:24:05 -05:00
QTextDocument doc ;
doc . setHtml ( QString : : fromStdWString ( msgInfo . msg ) ) ;
std : : string cited_text ( doc . toPlainText ( ) . toStdString ( ) ) ;
nMsgDialog - > insertPastedText ( cited_text ) ;
nMsgDialog - > addRecipient ( msgInfo . srcId ) ;
2009-02-11 13:43:37 -05:00
std : : list < std : : string > tl ( msgInfo . msgto ) ;
for ( std : : list < std : : string > : : iterator tli = tl . begin ( ) ;
tli ! = tl . end ( ) ;
tli + + )
{
nMsgDialog - > addRecipient ( * tli ) ;
}
2009-02-09 08:24:05 -05:00
nMsgDialog - > show ( ) ;
nMsgDialog - > activateWindow ( ) ;
}
2008-11-25 20:19:09 -05:00
void MessagesDialog : : forwardmessage ( )
{
/* put msg on msgBoard, and switch to it. */
std : : string cid ;
std : : string mid ;
if ( ! getCurrentMsg ( cid , mid ) )
return ;
mCurrCertId = cid ;
mCurrMsgId = mid ;
MessageInfo msgInfo ;
if ( ! rsMsgs - > getMessage ( mid , msgInfo ) )
return ;
ChanMsgDialog * nMsgDialog = new ChanMsgDialog ( true ) ;
/* fill it in */
//std::cerr << "MessagesDialog::newmessage()" << std::endl;
nMsgDialog - > newMsg ( ) ;
2010-01-15 21:42:11 -05:00
QString text = QString : : fromStdWString ( msgInfo . title ) ;
if ( text . startsWith ( " Fwd: " , Qt : : CaseInsensitive ) )
{
nMsgDialog - > insertTitleText ( QString : : fromStdWString ( msgInfo . title ) . toStdString ( ) ) ;
}
else
{
2008-11-25 20:19:09 -05:00
nMsgDialog - > insertTitleText ( ( QString ( " Fwd: " ) + QString : : fromStdWString ( msgInfo . title ) ) . toStdString ( ) ) ;
2010-01-15 21:42:11 -05:00
}
2010-01-21 11:35:00 -05:00
nMsgDialog - > setWindowTitle ( tr ( " Compose: " ) + tr ( " Fwd: " ) + QString : : fromStdWString ( msgInfo . title ) ) ;
2008-11-25 20:19:09 -05:00
QTextDocument doc ;
doc . setHtml ( QString : : fromStdWString ( msgInfo . msg ) ) ;
std : : string cited_text ( doc . toPlainText ( ) . toStdString ( ) ) ;
nMsgDialog - > insertForwardPastedText ( cited_text ) ;
2009-02-09 08:36:08 -05:00
//nMsgDialog->addRecipient( msgInfo.srcId ) ;
2008-11-25 20:19:09 -05:00
nMsgDialog - > show ( ) ;
nMsgDialog - > activateWindow ( ) ;
}
2008-01-26 08:08:28 -05:00
void MessagesDialog : : togglefileview ( )
{
/* if msg header visible -> hide by changing splitter
* three widgets . . .
*/
QList < int > sizeList = ui . msgSplitter - > sizes ( ) ;
QList < int > : : iterator it ;
int listSize = 0 ;
int msgSize = 0 ;
int recommendSize = 0 ;
int i = 0 ;
for ( it = sizeList . begin ( ) ; it ! = sizeList . end ( ) ; it + + , i + + )
{
if ( i = = 0 )
{
listSize = ( * it ) ;
}
else if ( i = = 1 )
{
msgSize = ( * it ) ;
}
else if ( i = = 2 )
{
recommendSize = ( * it ) ;
}
}
int totalSize = listSize + msgSize + recommendSize ;
bool toShrink = true ;
if ( recommendSize < ( int ) totalSize / 10 )
{
toShrink = false ;
}
QList < int > newSizeList ;
if ( toShrink )
{
newSizeList . push_back ( listSize + recommendSize / 3 ) ;
newSizeList . push_back ( msgSize + recommendSize * 2 / 3 ) ;
newSizeList . push_back ( 0 ) ;
2008-08-12 14:41:08 -04:00
ui . expandFilesButton - > setIcon ( QIcon ( QString ( " :/images/edit_add24.png " ) ) ) ;
ui . expandFilesButton - > setToolTip ( " Expand " ) ;
2008-01-26 08:08:28 -05:00
}
else
{
/* no change */
int nlistSize = ( totalSize * 2 / 3 ) * listSize / ( listSize + msgSize ) ;
int nMsgSize = ( totalSize * 2 / 3 ) - listSize ;
newSizeList . push_back ( nlistSize ) ;
newSizeList . push_back ( nMsgSize ) ;
newSizeList . push_back ( totalSize * 1 / 3 ) ;
2008-08-12 14:41:08 -04:00
ui . expandFilesButton - > setIcon ( QIcon ( QString ( " :/images/edit_remove24.png " ) ) ) ;
ui . expandFilesButton - > setToolTip ( " Hide " ) ;
2008-01-26 08:08:28 -05:00
}
ui . msgSplitter - > setSizes ( newSizeList ) ;
}
2007-11-14 22:18:48 -05:00
/* download the recommendations... */
void MessagesDialog : : getcurrentrecommended ( )
{
2009-05-17 15:38:42 -04:00
MessageInfo msgInfo ;
if ( ! rsMsgs - > getMessage ( mCurrMsgId , msgInfo ) )
return ;
std : : list < std : : string > srcIds ;
srcIds . push_back ( msgInfo . srcId ) ;
QModelIndexList list = ui . msgList - > selectionModel ( ) - > selectedIndexes ( ) ;
std : : map < int , FileInfo > files ;
for ( QModelIndexList : : const_iterator it ( list . begin ( ) ) ; it ! = list . end ( ) ; + + it )
{
FileInfo & f ( files [ it - > row ( ) ] ) ;
switch ( it - > column ( ) )
{
case 0 : f . fname = it - > data ( ) . toString ( ) . toStdString ( ) ;
break ;
case 1 : f . size = it - > data ( ) . toString ( ) . toInt ( ) ;
break ;
case 3 : f . hash = it - > data ( ) . toString ( ) . toStdString ( ) ;
break ;
default : ;
}
}
2007-11-14 22:18:48 -05:00
2009-05-17 15:38:42 -04:00
for ( std : : map < int , FileInfo > : : const_iterator it ( files . begin ( ) ) ; it ! = files . end ( ) ; + + it )
rsFiles - > FileRequest ( it - > second . fname , it - > second . hash , it - > second . size , " " , 0 , srcIds ) ;
2007-11-14 22:18:48 -05:00
}
2009-05-17 15:38:42 -04:00
#if 0
2007-11-14 22:18:48 -05:00
void MessagesDialog : : getallrecommended ( )
{
/* get Message */
2008-02-04 12:55:59 -05:00
MessageInfo msgInfo ;
if ( ! rsMsgs - > getMessage ( mCurrMsgId , msgInfo ) )
2007-11-14 22:18:48 -05:00
{
return ;
}
2008-02-04 12:55:59 -05:00
const std : : list < FileInfo > & recList = msgInfo . files ;
2007-11-14 22:18:48 -05:00
std : : list < FileInfo > : : const_iterator it ;
std : : list < std : : string > fnames ;
std : : list < std : : string > hashes ;
std : : list < int > sizes ;
for ( it = recList . begin ( ) ; it ! = recList . end ( ) ; it + + )
{
fnames . push_back ( it - > fname ) ;
hashes . push_back ( it - > hash ) ;
sizes . push_back ( it - > size ) ;
}
/* now do requests */
std : : list < std : : string > : : const_iterator fit ;
std : : list < std : : string > : : const_iterator hit ;
std : : list < int > : : const_iterator sit ;
2009-05-17 15:38:42 -04:00
for ( fit = fnames . begin ( ) , hit = hashes . begin ( ) , sit = sizes . begin ( ) ; fit ! = fnames . end ( ) ; fit + + , hit + + , sit + + )
2007-11-14 22:18:48 -05:00
{
2008-08-16 13:10:01 -04:00
std : : cerr < < " MessagesDialog::getallrecommended() Calling File Request " ;
std : : cerr < < std : : endl ;
2008-08-17 12:14:03 -04:00
std : : list < std : : string > srcIds ;
2008-11-09 17:21:14 -05:00
srcIds . push_back ( msgInfo . srcId ) ;
2008-08-17 12:14:03 -04:00
rsFiles - > FileRequest ( * fit , * hit , * sit , " " , 0 , srcIds ) ;
2007-11-14 22:18:48 -05:00
}
}
2009-05-17 15:38:42 -04:00
# endif
2007-11-14 22:18:48 -05:00
2009-02-22 12:36:39 -05:00
void MessagesDialog : : changeBox ( int )
2007-11-14 22:18:48 -05:00
{
2009-02-22 12:36:39 -05:00
insertMessages ( ) ; // show current msg list
2007-11-14 22:18:48 -05:00
}
void MessagesDialog : : insertMessages ( )
{
2008-02-04 12:55:59 -05:00
std : : list < MsgInfoSummary > msgList ;
std : : list < MsgInfoSummary > : : const_iterator it ;
2007-11-14 22:18:48 -05:00
2008-02-04 12:55:59 -05:00
rsMsgs - > getMessageSummaries ( msgList ) ;
2007-11-14 22:18:48 -05:00
/* get a link to the table */
2009-02-22 12:36:39 -05:00
QTreeWidget * msgWidget = ui . msgWidget ;
2007-11-14 22:18:48 -05:00
/* get the MsgId of the current one ... */
std : : string cid ;
std : : string mid ;
bool oldSelected = getCurrentMsg ( cid , mid ) ;
QTreeWidgetItem * newSelected = NULL ;
/* remove old items ??? */
int listrow = ui . listWidget - > currentRow ( ) ;
//std::cerr << "MessagesDialog::insertMessages()" << std::endl;
//std::cerr << "Current Row: " << listrow << std::endl;
/* check the mode we are in */
unsigned int msgbox = 0 ;
switch ( listrow )
{
case 3 :
msgbox = RS_MSG_SENTBOX ;
break ;
case 2 :
msgbox = RS_MSG_DRAFTBOX ;
break ;
case 1 :
msgbox = RS_MSG_OUTBOX ;
break ;
case 0 :
default :
msgbox = RS_MSG_INBOX ;
2009-01-22 20:58:56 -05:00
2007-11-14 22:18:48 -05:00
break ;
}
2009-02-22 12:36:39 -05:00
QList < QTreeWidgetItem * > items ;
2008-02-04 12:55:59 -05:00
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; it + + )
2007-11-14 22:18:48 -05:00
{
/* check the message flags, to decide which
* group it should go in . . .
*
* InBox
* OutBox
* Drafts
* Sent
*
* FLAGS = OUTGOING .
* - > Outbox / Drafts / Sent
* + SENT - > Sent
* + IN_PROGRESS - > Draft .
* + nuffing - > Outbox .
* FLAGS = INCOMING = ( ! OUTGOING )
* - > + NEW - > Bold .
*
*/
if ( ( it - > msgflags & RS_MSG_BOXMASK ) ! = msgbox )
{
//std::cerr << "Msg from other box: " << it->msgflags;
//std::cerr << std::endl;
continue ;
}
2009-01-22 20:58:56 -05:00
2007-11-14 22:18:48 -05:00
/* make a widget per friend */
2009-02-22 12:36:39 -05:00
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
2007-11-14 22:18:48 -05:00
/* So Text should be:
* ( 1 ) Msg / Broadcast
* ( 1 b ) Person / Channel Name
* ( 2 ) Rank
* ( 3 ) Date
* ( 4 ) Title
* ( 5 ) Msg
* ( 6 ) File Count
* ( 7 ) File Total
*/
// Date First.... (for sorting)
{
QDateTime qtime ;
qtime . setTime_t ( it - > ts ) ;
QString timestamp = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
2008-03-27 19:40:37 -04:00
item - > setText ( 3 , timestamp ) ;
2007-11-14 22:18:48 -05:00
}
// From ....
{
2010-01-25 18:58:48 -05:00
item - > setText ( 2 , QString : : fromStdString ( rsPeers - > getPeerName ( it - > srcId ) ) ) ;
2007-11-14 22:18:48 -05:00
}
2008-01-26 08:08:28 -05:00
// Subject
2010-01-25 18:58:48 -05:00
item - > setText ( 1 , QString : : fromStdWString ( it - > title ) ) ;
2010-01-15 21:42:11 -05:00
// Change Message icon when Subject is Re: or Fwd:
QString text = QString : : fromStdWString ( it - > title ) ;
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
2010-01-25 18:58:48 -05:00
item - > setIcon ( 1 , ( QIcon ( " :/images/message-mail-replied-read.png " ) ) ) ;
2010-01-15 21:42:11 -05:00
}
else if ( text . startsWith ( " Fwd: " , Qt : : CaseInsensitive ) )
{
2010-01-25 18:58:48 -05:00
item - > setIcon ( 1 , ( QIcon ( " :/images/message-mail-forwarded-read.png " ) ) ) ;
2010-01-15 21:42:11 -05:00
}
else
{
2010-01-25 18:58:48 -05:00
item - > setIcon ( 1 , ( QIcon ( " :/images/message-mail-read.png " ) ) ) ;
2010-01-15 21:42:11 -05:00
}
if ( it - > msgflags & RS_MSG_NEW )
{
for ( int i = 0 ; i < 10 ; i + + )
{
QFont qf = item - > font ( i ) ;
qf . setBold ( true ) ;
item - > setFont ( i , qf ) ;
}
QString text = QString : : fromStdWString ( it - > title ) ;
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
2010-01-25 18:58:48 -05:00
item - > setIcon ( 1 , ( QIcon ( " :/images/message-mail-replied.png " ) ) ) ;
2010-01-15 21:42:11 -05:00
}
else if ( text . startsWith ( " Fwd: " , Qt : : CaseInsensitive ) )
{
2010-01-25 18:58:48 -05:00
item - > setIcon ( 1 , ( QIcon ( " :/images/message-mail-forwarded.png " ) ) ) ;
2010-01-15 21:42:11 -05:00
}
else
{
2010-01-25 18:58:48 -05:00
item - > setIcon ( 1 , ( QIcon ( " :/images/message-mail.png " ) ) ) ;
2010-01-15 21:42:11 -05:00
}
}
2007-11-14 22:18:48 -05:00
// No of Files.
{
std : : ostringstream out ;
out < < it - > count ;
2008-03-27 19:40:37 -04:00
item - > setText ( 0 , QString : : fromStdString ( out . str ( ) ) ) ;
2008-11-25 20:19:09 -05:00
item - > setTextAlignment ( 0 , Qt : : AlignCenter ) ;
2007-11-14 22:18:48 -05:00
}
2008-02-04 12:55:59 -05:00
item - > setText ( 4 , QString : : fromStdString ( it - > srcId ) ) ;
2008-01-26 08:08:28 -05:00
item - > setText ( 5 , QString : : fromStdString ( it - > msgId ) ) ;
if ( ( oldSelected ) & & ( mid = = it - > msgId ) )
2007-11-14 22:18:48 -05:00
{
2008-01-26 08:08:28 -05:00
newSelected = item ;
2007-11-14 22:18:48 -05:00
}
/* add to the list */
items . append ( item ) ;
}
/* add the items in! */
msgWidget - > clear ( ) ;
msgWidget - > insertTopLevelItems ( 0 , items ) ;
if ( newSelected )
{
msgWidget - > setCurrentItem ( newSelected ) ;
}
}
2009-02-22 12:36:39 -05:00
void MessagesDialog : : updateCurrentMessage ( QTreeWidgetItem * item , QTreeWidgetItem * )
2007-11-14 22:18:48 -05:00
{
insertMsgTxtAndFiles ( ) ;
2009-02-22 12:36:39 -05:00
setMsgAsRead ( item ) ;
2007-11-14 22:18:48 -05:00
}
2009-02-22 12:36:39 -05:00
void MessagesDialog : : setMsgAsRead ( QTreeWidgetItem * item )
{
if ( item = = NULL )
return ;
for ( int i = 0 ; i < 10 ; i + + )
{
QFont qf = item - > font ( i ) ;
qf . setBold ( false ) ;
item - > setFont ( i , qf ) ;
}
std : : string mid ( item - > text ( 5 ) . toStdString ( ) ) ;
rsMsgs - > MessageRead ( mid ) ;
}
2007-11-14 22:18:48 -05:00
void MessagesDialog : : insertMsgTxtAndFiles ( )
{
/* Locate the current Message */
QTreeWidget * msglist = ui . msgWidget ;
2008-02-04 12:55:59 -05:00
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() " < < std : : endl ;
2007-11-14 22:18:48 -05:00
/* get its Ids */
std : : string cid ;
std : : string mid ;
QTreeWidgetItem * qtwi = msglist - > currentItem ( ) ;
if ( ! qtwi )
{
/* blank it */
2008-01-26 08:08:28 -05:00
ui . dateText - > setText ( " " ) ;
ui . toText - > setText ( " " ) ;
ui . fromText - > setText ( " " ) ;
ui . filesText - > setText ( " " ) ;
ui . subjectText - > setText ( " " ) ;
2007-11-14 22:18:48 -05:00
ui . msgList - > clear ( ) ;
2010-01-15 14:24:21 -05:00
ui . msgText - > clear ( ) ;
2008-01-26 08:08:28 -05:00
2007-11-14 22:18:48 -05:00
return ;
}
else
{
2008-01-26 08:08:28 -05:00
cid = qtwi - > text ( 4 ) . toStdString ( ) ;
mid = qtwi - > text ( 5 ) . toStdString ( ) ;
2007-11-14 22:18:48 -05:00
}
2008-02-04 12:55:59 -05:00
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() mid: " < < mid < < std : : endl ;
2007-11-14 22:18:48 -05:00
/* Save the Data.... for later */
mCurrCertId = cid ;
mCurrMsgId = mid ;
2008-02-04 12:55:59 -05:00
MessageInfo msgInfo ;
if ( ! rsMsgs - > getMessage ( mid , msgInfo ) )
2007-11-14 22:18:48 -05:00
{
2008-02-04 12:55:59 -05:00
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg " < < std : : endl ;
2007-11-14 22:18:48 -05:00
return ;
}
2009-02-22 12:36:39 -05:00
const std : : list < FileInfo > & recList = msgInfo . files ;
2007-11-14 22:18:48 -05:00
std : : list < FileInfo > : : const_iterator it ;
/* get a link to the table */
QTreeWidget * tree = ui . msgList ;
/* get the MessageInfo */
2009-02-22 12:36:39 -05:00
tree - > clear ( ) ;
tree - > setColumnCount ( 5 ) ;
2007-11-14 22:18:48 -05:00
2009-02-22 12:36:39 -05:00
QList < QTreeWidgetItem * > items ;
2007-11-14 22:18:48 -05:00
for ( it = recList . begin ( ) ; it ! = recList . end ( ) ; it + + )
{
/* make a widget per person */
2009-02-22 12:36:39 -05:00
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
2007-11-14 22:18:48 -05:00
/* (0) Filename */
item - > setText ( 0 , QString : : fromStdString ( it - > fname ) ) ;
//std::cerr << "Msg FileItem(" << it->fname.length() << ") :" << it->fname << std::endl;
2009-02-22 12:36:39 -05:00
2009-07-10 19:48:20 -04:00
item - > setText ( 1 , misc : : friendlyUnit ( it - > size ) ) ; /* (1) Size */
2009-05-17 15:38:42 -04:00
item - > setText ( 2 , QString : : number ( 0 ) ) ; /* (2) Rank */ // what is this ???
item - > setText ( 3 , QString : : fromStdString ( it - > hash ) ) ;
2009-02-22 12:36:39 -05:00
2007-11-14 22:18:48 -05:00
/* add to the list */
items . append ( item ) ;
}
/* add the items in! */
tree - > insertTopLevelItems ( 0 , items ) ;
2008-02-04 12:55:59 -05:00
/* iterate through the sources */
std : : list < std : : string > : : const_iterator pit ;
2008-01-26 08:08:28 -05:00
QString msgTxt ;
2008-02-04 12:55:59 -05:00
for ( pit = msgInfo . msgto . begin ( ) ; pit ! = msgInfo . msgto . end ( ) ; pit + + )
2007-12-11 21:55:50 -05:00
{
2008-02-04 12:55:59 -05:00
msgTxt + = QString : : fromStdString ( * pit ) ;
2008-01-26 08:08:28 -05:00
msgTxt + = " < " ;
2008-02-04 12:55:59 -05:00
msgTxt + = QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) ;
2008-01-26 08:08:28 -05:00
msgTxt + = " >, " ;
2007-12-11 21:55:50 -05:00
}
2008-02-04 12:55:59 -05:00
if ( msgInfo . msgcc . size ( ) > 0 )
2008-01-26 08:08:28 -05:00
msgTxt + = " \n Cc: " ;
2008-02-04 12:55:59 -05:00
for ( pit = msgInfo . msgcc . begin ( ) ; pit ! = msgInfo . msgcc . end ( ) ; pit + + )
2007-12-11 21:55:50 -05:00
{
2008-02-04 12:55:59 -05:00
msgTxt + = QString : : fromStdString ( * pit ) ;
2008-01-26 08:08:28 -05:00
msgTxt + = " < " ;
2008-02-04 12:55:59 -05:00
msgTxt + = QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) ;
2008-01-26 08:08:28 -05:00
msgTxt + = " >, " ;
2007-12-11 21:55:50 -05:00
}
2008-02-04 12:55:59 -05:00
if ( msgInfo . msgbcc . size ( ) > 0 )
2008-01-26 08:08:28 -05:00
msgTxt + = " \n Bcc: " ;
2008-02-04 12:55:59 -05:00
for ( pit = msgInfo . msgbcc . begin ( ) ; pit ! = msgInfo . msgbcc . end ( ) ; pit + + )
2007-12-11 21:55:50 -05:00
{
2008-02-04 12:55:59 -05:00
msgTxt + = QString : : fromStdString ( * pit ) ;
2008-01-26 08:08:28 -05:00
msgTxt + = " < " ;
2008-02-04 12:55:59 -05:00
msgTxt + = QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) ;
2008-01-26 08:08:28 -05:00
msgTxt + = " >, " ;
2007-12-11 21:55:50 -05:00
}
2008-01-26 08:08:28 -05:00
{
QDateTime qtime ;
2008-02-04 12:55:59 -05:00
qtime . setTime_t ( msgInfo . ts ) ;
2008-01-26 08:08:28 -05:00
QString timestamp = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
ui . dateText - > setText ( timestamp ) ;
}
ui . toText - > setText ( msgTxt ) ;
2008-02-04 12:55:59 -05:00
ui . fromText - > setText ( QString : : fromStdString ( rsPeers - > getPeerName ( msgInfo . srcId ) ) ) ;
2007-11-14 22:18:48 -05:00
2008-02-04 12:55:59 -05:00
ui . subjectText - > setText ( QString : : fromStdWString ( msgInfo . title ) ) ;
2008-04-24 08:58:27 -04:00
ui . msgText - > setHtml ( QString : : fromStdWString ( msgInfo . msg ) ) ;
2007-11-14 22:18:48 -05:00
2008-01-26 08:08:28 -05:00
{
std : : ostringstream out ;
2008-02-04 12:55:59 -05:00
out < < " ( " < < msgInfo . count < < " Files) " ;
2008-01-26 08:08:28 -05:00
ui . filesText - > setText ( QString : : fromStdString ( out . str ( ) ) ) ;
}
2007-11-14 22:18:48 -05:00
2008-02-04 12:55:59 -05:00
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Msg Displayed OK! " < < std : : endl ;
2007-11-14 22:18:48 -05:00
}
bool MessagesDialog : : getCurrentMsg ( std : : string & cid , std : : string & mid )
{
/* Locate the current Message */
QTreeWidget * msglist = ui . msgWidget ;
//std::cerr << "MessagesDialog::getCurrentMsg()" << std::endl;
/* get its Ids */
QTreeWidgetItem * qtwi = msglist - > currentItem ( ) ;
if ( qtwi )
{
2008-01-26 08:08:28 -05:00
cid = qtwi - > text ( 4 ) . toStdString ( ) ;
mid = qtwi - > text ( 5 ) . toStdString ( ) ;
2007-11-14 22:18:48 -05:00
return true ;
}
return false ;
}
void MessagesDialog : : removemessage ( )
{
2008-09-04 15:28:35 -04:00
QList < QTreeWidgetItem * > list ( ui . msgWidget - > selectedItems ( ) ) ;
2007-11-14 22:18:48 -05:00
2009-02-22 12:36:39 -05:00
int maxrow = - 1 ;
2008-09-04 15:28:35 -04:00
for ( QList < QTreeWidgetItem * > : : const_iterator it ( list . begin ( ) ) ; it ! = list . end ( ) ; + + it )
2009-02-22 12:36:39 -05:00
maxrow = std : : max ( maxrow , ui . msgWidget - > indexOfTopLevelItem ( * it ) ) ;
2007-11-14 22:18:48 -05:00
2009-02-22 12:36:39 -05:00
QTreeWidgetItem * next = ui . msgWidget - > topLevelItem ( maxrow + 1 ) ;
2007-11-14 22:18:48 -05:00
2009-02-22 12:36:39 -05:00
for ( QList < QTreeWidgetItem * > : : const_iterator it ( list . begin ( ) ) ; it ! = list . end ( ) ; + + it )
rsMsgs - > MessageDelete ( ( * it ) - > text ( 5 ) . toStdString ( ) ) ;
2007-11-14 22:18:48 -05:00
2009-02-22 12:36:39 -05:00
if ( next ! = NULL )
ui . msgWidget - > setCurrentItem ( next ) ;
2007-11-14 22:18:48 -05:00
2009-02-22 12:36:39 -05:00
insertMessages ( ) ;
2007-11-14 22:18:48 -05:00
return ;
}
2008-09-04 15:28:35 -04:00
void MessagesDialog : : print ( )
{
# ifndef QT_NO_PRINTER
QPrinter printer ( QPrinter : : HighResolution ) ;
printer . setFullPage ( true ) ;
QPrintDialog * dlg = new QPrintDialog ( & printer , this ) ;
if ( ui . msgText - > textCursor ( ) . hasSelection ( ) )
dlg - > addEnabledOption ( QAbstractPrintDialog : : PrintSelection ) ;
dlg - > setWindowTitle ( tr ( " Print Document " ) ) ;
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
ui . msgText - > print ( & printer ) ;
}
delete dlg ;
# endif
2008-03-26 10:22:51 -04:00
}
2007-11-14 22:18:48 -05:00
2008-09-04 15:28:35 -04:00
void MessagesDialog : : printpreview ( )
{
PrintPreview * preview = new PrintPreview ( ui . msgText - > document ( ) , this ) ;
preview - > setWindowModality ( Qt : : WindowModal ) ;
preview - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
preview - > show ( ) ;
2008-03-27 19:40:37 -04:00
}
2010-01-16 13:03:35 -05:00
void MessagesDialog : : anchorClicked ( const QUrl & link )
{
# ifdef FORUM_DEBUG
std : : cerr < < " MessagesDialog::anchorClicked link.scheme() : " < < link . scheme ( ) . toStdString ( ) < < std : : endl ;
# endif
if ( link . scheme ( ) = = " retroshare " )
{
QStringList L = link . toString ( ) . split ( " | " ) ;
std : : string fileName = L . at ( 1 ) . toStdString ( ) ;
uint64_t fileSize = L . at ( 2 ) . toULongLong ( ) ;
std : : string fileHash = L . at ( 3 ) . toStdString ( ) ;
# ifdef FORUM_DEBUG
std : : cerr < < " MessagesDialog::anchorClicked FileRequest : fileName : " < < fileName < < " . fileHash : " < < fileHash < < " . fileSize : " < < fileSize < < std : : endl ;
# endif
if ( fileName ! = " " & & fileHash ! = " " )
{
std : : list < std : : string > srcIds ;
if ( rsFiles - > FileRequest ( fileName , fileHash , fileSize , " " , RS_FILE_HINTS_NETWORK_WIDE , srcIds ) )
{
QMessageBox mb ( tr ( " File Request Confirmation " ) , tr ( " The file has been added to your download list. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
}
else
{
QMessageBox mb ( tr ( " File Request canceled " ) , tr ( " The file has not been added to your download list, because you already have it. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
}
}
else
{
QMessageBox mb ( tr ( " File Request Error " ) , tr ( " The file link is malformed. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
}
}
else if ( link . scheme ( ) = = " http " )
{
QDesktopServices : : openUrl ( link ) ;
}
else if ( link . scheme ( ) = = " " )
{
//it's probably a web adress, let's add http:// at the beginning of the link
QString newAddress = link . toString ( ) ;
newAddress . prepend ( " http:// " ) ;
QDesktopServices : : openUrl ( QUrl ( newAddress ) ) ;
}
2010-01-21 20:05:45 -05:00
}
2010-01-22 14:23:12 -05:00
bool MessagesDialog : : fileSave ( )
{
if ( fileName . isEmpty ( ) )
return fileSaveAs ( ) ;
QFile file ( fileName ) ;
if ( ! file . open ( QFile : : WriteOnly ) )
return false ;
QTextStream ts ( & file ) ;
ts . setCodec ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
ts < < ui . msgText - > document ( ) - > toHtml ( " UTF-8 " ) ;
ui . msgText - > document ( ) - > setModified ( false ) ;
return true ;
}
bool MessagesDialog : : fileSaveAs ( )
{
QString fn = QFileDialog : : getSaveFileName ( this , tr ( " Save as... " ) ,
QString ( ) , tr ( " HTML-Files (*.htm *.html);;All Files (*) " ) ) ;
if ( fn . isEmpty ( ) )
return false ;
setCurrentFileName ( fn ) ;
return fileSave ( ) ;
}
void MessagesDialog : : setCurrentFileName ( const QString & fileName )
{
this - > fileName = fileName ;
ui . msgText - > document ( ) - > setModified ( false ) ;
setWindowModified ( false ) ;
}
2010-01-21 20:05:45 -05:00
void MessagesDialog : : buttonsicononly ( )
{
2010-01-25 07:44:12 -05:00
_settings - > beginGroup ( " MessageDialog " ) ;
2010-01-21 20:05:45 -05:00
ui . newmessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . removemessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . replymessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . replyallmessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . forwardmessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . printbutton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . viewtoolButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
2010-01-25 07:44:12 -05:00
_settings - > setValue ( " ToolButon_Stlye1 " , ui . newmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye2 " , ui . removemessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye3 " , ui . replymessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye4 " , ui . replyallmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye5 " , ui . forwardmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye6 " , ui . printbutton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye7 " , ui . viewtoolButton - > toolButtonStyle ( ) ) ;
_settings - > endGroup ( ) ;
2010-01-21 20:05:45 -05:00
}
void MessagesDialog : : buttonstextbesideicon ( )
{
2010-01-25 07:44:12 -05:00
_settings - > beginGroup ( " MessageDialog " ) ;
2010-01-21 20:05:45 -05:00
ui . newmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . removemessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . replymessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . replyallmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . forwardmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . printbutton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . viewtoolButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
2010-01-25 07:44:12 -05:00
_settings - > setValue ( " ToolButon_Stlye1 " , ui . newmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye2 " , ui . removemessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye3 " , ui . replymessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye4 " , ui . replyallmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye5 " , ui . forwardmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye6 " , ui . printbutton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye7 " , ui . viewtoolButton - > toolButtonStyle ( ) ) ;
_settings - > endGroup ( ) ;
2010-01-21 20:05:45 -05:00
}
void MessagesDialog : : buttonstextundericon ( )
{
2010-01-25 07:44:12 -05:00
_settings - > beginGroup ( " MessageDialog " ) ;
2010-01-21 20:05:45 -05:00
ui . newmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . removemessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . replymessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . replyallmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . forwardmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . printbutton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . viewtoolButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
2010-01-25 07:44:12 -05:00
_settings - > setValue ( " ToolButon_Stlye1 " , ui . newmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye2 " , ui . removemessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye3 " , ui . replymessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye4 " , ui . replyallmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye5 " , ui . forwardmessageButton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye6 " , ui . printbutton - > toolButtonStyle ( ) ) ;
_settings - > setValue ( " ToolButon_Stlye7 " , ui . viewtoolButton - > toolButtonStyle ( ) ) ;
_settings - > endGroup ( ) ;
}
void MessagesDialog : : loadToolButtonsettings ( )
{
_settings - > beginGroup ( " MessageDialog " ) ;
if ( _settings - > value ( " ToolButon_Stlye1 " , " 0 " ) . toInt ( ) = = 0 )
{
qDebug ( ) < < " ToolButon IconOnly " ;
ui . newmessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . removemessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . replymessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . replyallmessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . forwardmessageButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . printbutton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
ui . viewtoolButton - > setToolButtonStyle ( Qt : : ToolButtonIconOnly ) ;
}
else if ( _settings - > value ( " ToolButon_Stlye1 " , " 2 " ) . toInt ( ) = = 2 )
{
qDebug ( ) < < " ToolButon TextBesideIcon " ;
ui . newmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . removemessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . replymessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . replyallmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . forwardmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . printbutton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
ui . viewtoolButton - > setToolButtonStyle ( Qt : : ToolButtonTextBesideIcon ) ;
}
else if ( _settings - > value ( " ToolButon_Stlye1 " , " 3 " ) . toInt ( ) = = 3 )
{
qDebug ( ) < < " ToolButton TextUnderIcon " ;
ui . newmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . removemessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . replymessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . replyallmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . forwardmessageButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . printbutton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . viewtoolButton - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
}
_settings - > endGroup ( ) ;
}