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"
2010-03-10 16:38:26 -05:00
# include "gui/RetroShareLink.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"
2008-07-02 12:59:56 -04:00
# include "rsiface/rsfiles.h"
2009-02-11 13:43:37 -05:00
2010-05-18 18:37:18 -04:00
# include "settings/RSettings.h"
2010-02-13 13:49:56 -05:00
# include <QtGui>
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
2010-05-18 18:37:18 -04:00
# define COLUMN_COUNT 7
# define COLUMN_ATTACHEMENTS 0
# define COLUMN_SUBJECT 1
# define COLUMN_FROM 2
# define COLUMN_DATE 3
# define COLUMN_SRCID 4
# define COLUMN_MSGID 5
# define COLUMN_CONTENT 6
static int FilterColumnFromComboBox ( int nIndex )
{
switch ( nIndex ) {
case 0 :
return COLUMN_ATTACHEMENTS ;
case 1 :
return COLUMN_SUBJECT ;
case 2 :
return COLUMN_FROM ;
case 3 :
return COLUMN_DATE ;
case 4 :
return COLUMN_CONTENT ;
}
return COLUMN_SUBJECT ;
}
static int FilterColumnToComboBox ( int nIndex )
{
switch ( nIndex ) {
case COLUMN_ATTACHEMENTS :
return 0 ;
case COLUMN_SUBJECT :
return 1 ;
case COLUMN_FROM :
return 2 ;
case COLUMN_DATE :
return 3 ;
case COLUMN_CONTENT :
return 4 ;
}
return FilterColumnToComboBox ( COLUMN_SUBJECT ) ;
}
2010-05-10 15:55:59 -04: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
2010-02-13 13:49:56 -05:00
connect ( ui . messagestreeView , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( messageslistWidgetCostumPopupMenu ( QPoint ) ) ) ;
2008-09-04 15:28:35 -04:00
connect ( ui . msgList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( msgfilelistWidgetCostumPopupMenu ( QPoint ) ) ) ;
2010-04-27 17:46:28 -04:00
connect ( ui . messagestreeView , SIGNAL ( clicked ( const QModelIndex & ) ) , this , SLOT ( clicked ( const QModelIndex & ) ) ) ;
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 ( ) ) ) ;
2010-05-07 18:23:38 -04:00
ui . actionPrint - > setDisabled ( true ) ;
2008-03-26 10:22:51 -04:00
connect ( ui . actionPrintPreview , SIGNAL ( triggered ( ) ) , this , SLOT ( printpreview ( ) ) ) ;
2010-05-07 18:23:38 -04:00
ui . actionPrintPreview - > setDisabled ( true ) ;
2010-02-26 11:59:24 -05:00
connect ( ui . printbutton , SIGNAL ( clicked ( ) ) , this , SLOT ( print ( ) ) ) ;
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 ( ) ) ) ;
2010-05-07 18:23:38 -04:00
ui . actionSave_as - > setDisabled ( true ) ;
2010-02-14 07:29:50 -05:00
connect ( ui . clearButton , SIGNAL ( clicked ( ) ) , this , SLOT ( clearFilter ( ) ) ) ;
connect ( ui . filterPatternLineEdit , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( toggleclearButton ( ) ) ) ;
2010-02-13 13:49:56 -05:00
connect ( ui . filterPatternLineEdit , SIGNAL ( textChanged ( const QString & ) ) ,
this , SLOT ( filterRegExpChanged ( ) ) ) ;
connect ( ui . filterColumnComboBox , SIGNAL ( currentIndexChanged ( int ) ) ,
this , SLOT ( filterColumnChanged ( ) ) ) ;
2007-11-14 22:18:48 -05:00
mCurrCertId = " " ;
mCurrMsgId = " " ;
2010-02-13 13:49:56 -05:00
// Set the QStandardItemModel
2010-05-10 15:55:59 -04:00
MessagesModel = new QStandardItemModel ( 0 , COLUMN_COUNT ) ;
2010-05-18 18:37:18 -04:00
MessagesModel - > setHeaderData ( COLUMN_ATTACHEMENTS , Qt : : Horizontal , tr ( " # " ) ) ;
MessagesModel - > setHeaderData ( COLUMN_SUBJECT , Qt : : Horizontal , tr ( " Subject " ) ) ;
MessagesModel - > setHeaderData ( COLUMN_FROM , Qt : : Horizontal , tr ( " From " ) ) ;
MessagesModel - > setHeaderData ( COLUMN_DATE , Qt : : Horizontal , tr ( " Date " ) ) ;
MessagesModel - > setHeaderData ( COLUMN_SRCID , Qt : : Horizontal , tr ( " SRCID " ) ) ;
MessagesModel - > setHeaderData ( COLUMN_MSGID , Qt : : Horizontal , tr ( " MSGID " ) ) ;
MessagesModel - > setHeaderData ( COLUMN_CONTENT , Qt : : Horizontal , tr ( " Content " ) ) ;
2010-02-13 13:49:56 -05:00
proxyModel = new QSortFilterProxyModel ( this ) ;
proxyModel - > setDynamicSortFilter ( true ) ;
proxyModel - > setSourceModel ( MessagesModel ) ;
2010-05-07 18:23:38 -04:00
proxyModel - > setSortRole ( Qt : : UserRole ) ;
2010-05-10 15:55:59 -04:00
proxyModel - > sort ( COLUMN_DATE , Qt : : DescendingOrder ) ;
2010-02-13 13:49:56 -05:00
ui . messagestreeView - > setModel ( proxyModel ) ;
ui . messagestreeView - > setSelectionBehavior ( QTreeView : : SelectRows ) ;
ui . messagestreeView - > setRootIsDecorated ( false ) ;
ui . messagestreeView - > setSortingEnabled ( true ) ;
2010-05-10 15:55:59 -04:00
ui . messagestreeView - > sortByColumn ( COLUMN_DATE , Qt : : DescendingOrder ) ;
2010-04-27 17:46:28 -04:00
// connect after setting model
connect ( ui . messagestreeView - > selectionModel ( ) , SIGNAL ( currentChanged ( QModelIndex , QModelIndex ) ) , this , SLOT ( currentChanged ( const QModelIndex & ) ) ) ;
2010-05-06 10:39:50 -04:00
// workaround for Qt bug, should be solved in next Qt release 4.7.0
// http://bugreports.qt.nokia.com/browse/QTBUG-8270
QShortcut * Shortcut = new QShortcut ( QKeySequence ( Qt : : Key_Delete ) , ui . messagestreeView , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( Shortcut , SIGNAL ( activated ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
2007-11-14 22:18:48 -05:00
/* 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 ) ;
2007-11-18 18:35:53 -05:00
/* Set header resize modes and initial section sizes */
2010-02-13 13:49:56 -05:00
QHeaderView * msgwheader = ui . messagestreeView - > header ( ) ;
2010-05-10 15:55:59 -04:00
msgwheader - > setResizeMode ( COLUMN_DATE , QHeaderView : : Interactive ) ;
2008-09-04 15:28:35 -04:00
2010-05-18 18:37:18 -04:00
msgwheader - > resizeSection ( COLUMN_ATTACHEMENTS , 24 ) ;
msgwheader - > resizeSection ( COLUMN_SUBJECT , 250 ) ;
msgwheader - > resizeSection ( COLUMN_FROM , 140 ) ;
msgwheader - > resizeSection ( COLUMN_DATE , 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 ) ;
2010-03-24 06:52:52 -04:00
//viewmenu->addAction(ui.actionTextUnderIcon);
2010-01-21 20:05:45 -05:00
ui . viewtoolButton - > setMenu ( viewmenu ) ;
2007-11-14 22:18:48 -05:00
2010-01-25 07:44:12 -05:00
loadToolButtonsettings ( ) ;
2010-01-25 18:58:48 -05:00
2010-01-28 07:56:17 -05:00
mFont = QFont ( " Arial " , 10 , QFont : : Bold ) ;
2010-01-25 18:58:48 -05:00
ui . subjectText - > setFont ( mFont ) ;
2008-09-04 15:28:35 -04:00
2010-04-27 17:46:28 -04:00
//setting default filter by column as subject
2010-05-18 18:37:18 -04:00
proxyModel - > setFilterKeyColumn ( FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ) ;
2010-02-14 07:29:50 -05:00
ui . clearButton - > hide ( ) ;
2010-05-18 18:37:18 -04:00
// load settings
processSettings ( true ) ;
// fill folder list
updateMessageSummaryList ( ) ;
ui . listWidget - > setCurrentRow ( 0 ) ;
2010-04-27 17:46:28 -04:00
// create timer for navigation
timer = new QTimer ( this ) ;
timer - > setInterval ( 300 ) ;
timer - > setSingleShot ( true ) ;
connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateCurrentMessage ( ) ) ) ;
2008-09-04 15:28:35 -04:00
/* Hide platform specific features */
# ifdef Q_WS_WIN
# endif
}
2010-04-27 17:46:28 -04:00
MessagesDialog : : ~ MessagesDialog ( )
{
// stop and delete timer
timer - > stop ( ) ;
delete ( timer ) ;
2010-05-18 18:37:18 -04:00
// save settings
processSettings ( false ) ;
}
void MessagesDialog : : processSettings ( bool bLoad )
{
QHeaderView * msgwheader = ui . messagestreeView - > header ( ) ;
RSettings settings ( QString ( " MessageDialog " ) ) ;
if ( bLoad ) {
// load settings
// expandFiles
bool bValue = settings . value ( " expandFiles " , true ) . toBool ( ) ;
ui . expandFilesButton - > setChecked ( bValue ) ;
ui . msgList - > setVisible ( bValue ) ;
togglefileview_internal ( ) ;
// filterColumn
int nValue = FilterColumnToComboBox ( settings . value ( " filterColumn " , true ) . toInt ( ) ) ;
ui . filterColumnComboBox - > setCurrentIndex ( nValue ) ;
// state of message tree
msgwheader - > restoreState ( settings . value ( " MessageTree " ) . toByteArray ( ) ) ;
// state of splitter
ui . msgSplitter_2 - > restoreState ( settings . value ( " Splitter2 " ) . toByteArray ( ) ) ;
} else {
// save settings
// state of message tree
settings . setValue ( " MessageTree " , msgwheader - > saveState ( ) ) ;
// state of splitter
settings . setValue ( " Splitter2 " , ui . msgSplitter_2 - > saveState ( ) ) ;
}
2010-04-27 17:46:28 -04:00
}
2010-05-06 10:39:50 -04:00
// replaced by shortcut
//void MessagesDialog::keyPressEvent(QKeyEvent *e)
//{
// if(e->key() == Qt::Key_Delete)
// {
// removemessage() ;
// e->accept() ;
// }
// else
// MainPage::keyPressEvent(e) ;
//}
2008-09-04 15:28:35 -04:00
2010-05-07 18:23:38 -04:00
int MessagesDialog : : getSelectedMsgCount ( )
{
//To check if the selection has more than one row.
QList < QModelIndex > selectedIndexList = ui . messagestreeView - > selectionModel ( ) - > selectedIndexes ( ) ;
QList < int > rowList ;
for ( QList < QModelIndex > : : iterator it = selectedIndexList . begin ( ) ; it ! = selectedIndexList . end ( ) ; it + + )
{
int row = it - > row ( ) ;
if ( rowList . contains ( row ) = = false )
{
rowList . append ( row ) ;
}
}
return rowList . size ( ) ;
}
2008-09-04 15:28:35 -04:00
void MessagesDialog : : messageslistWidgetCostumPopupMenu ( QPoint point )
{
2010-05-07 18:23:38 -04:00
QMenu contextMnu ( this ) ;
2008-09-04 15:28:35 -04:00
2010-05-07 18:23:38 -04:00
/** Defines the actions for the context menu */
QAction * newmsgAct = NULL ;
QAction * replytomsgAct = NULL ;
QAction * replyallmsgAct = NULL ;
QAction * forwardmsgAct = NULL ;
QAction * removemsgAct = NULL ;
2008-09-04 15:28:35 -04:00
2010-05-07 18:23:38 -04:00
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
2010-05-07 18:23:38 -04: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
2010-05-07 18:23:38 -04:00
forwardmsgAct = new QAction ( QIcon ( IMAGE_MESSAGEFORWARD ) , tr ( " Forward Message " ) , this ) ;
connect ( forwardmsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( forwardmessage ( ) ) ) ;
contextMnu . addAction ( forwardmsgAct ) ;
2008-11-25 20:19:09 -05:00
2010-05-07 18:23:38 -04:00
contextMnu . addSeparator ( ) ;
int nCount = getSelectedMsgCount ( ) ;
if ( nCount > 1 ) {
removemsgAct = new QAction ( QIcon ( IMAGE_MESSAGEREMOVE ) , tr ( " Remove Messages " ) , this ) ;
} else {
removemsgAct = new QAction ( QIcon ( IMAGE_MESSAGEREMOVE ) , tr ( " Remove Message " ) , this ) ;
}
connect ( removemsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
contextMnu . addAction ( removemsgAct ) ;
contextMnu . addAction ( ui . actionSave_as ) ;
contextMnu . addAction ( ui . actionPrintPreview ) ;
contextMnu . addAction ( ui . actionPrint ) ;
contextMnu . addSeparator ( ) ;
newmsgAct = new QAction ( QIcon ( IMAGE_MESSAGE ) , tr ( " New Message " ) , this ) ;
connect ( newmsgAct , SIGNAL ( triggered ( ) ) , this , SLOT ( newmessage ( ) ) ) ;
contextMnu . addAction ( newmsgAct ) ;
if ( nCount ! = 1 ) {
replytomsgAct - > setDisabled ( true ) ;
replyallmsgAct - > setDisabled ( true ) ;
forwardmsgAct - > setDisabled ( true ) ;
}
if ( nCount = = 0 ) {
removemsgAct - > setDisabled ( true ) ;
}
2010-05-14 16:55:44 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2008-09-04 15:28:35 -04:00
}
void MessagesDialog : : msgfilelistWidgetCostumPopupMenu ( QPoint point )
{
2010-05-07 18:23:38 -04:00
QAction * getRecAct = NULL ;
2010-05-14 16:55:44 -04:00
// QAction* getAllRecAct = NULL;
2008-09-04 15:28:35 -04:00
2010-05-07 18:23:38 -04:00
QMenu contextMnu ( this ) ;
2008-09-04 15:28:35 -04:00
2010-05-07 18:23:38 -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
2010-05-07 18:23:38 -04:00
// getAllRecAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Download" ), this );
// connect( getAllRecAct , SIGNAL( triggered() ), this, SLOT( getallrecommended() ) );
2008-09-04 15:28:35 -04:00
2010-05-07 18:23:38 -04:00
contextMnu . addAction ( getRecAct ) ;
// contextMnu.addAction( getAllRecAct);
2010-05-14 16:55:44 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2008-09-04 15:28:35 -04:00
}
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 ( ) ;
2010-05-02 20:09:55 -04:00
/* window will destroy itself! */
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 ( ) ;
2010-05-02 20:09:55 -04:00
/* window will destroy itself! */
2009-02-09 08:24:05 -05:00
}
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 ) ;
2010-04-26 17:11:19 -04:00
std : : list < FileInfo > & files_info = msgInfo . files ;
/* enable all files for sending */
std : : list < FileInfo > : : iterator it ;
for ( it = files_info . begin ( ) ; it ! = files_info . end ( ) ; it + + )
{
it - > inRecommend = true ;
}
nMsgDialog - > insertFileList ( files_info ) ;
2009-02-09 08:36:08 -05:00
//nMsgDialog->addRecipient( msgInfo.srcId ) ;
2008-11-25 20:19:09 -05:00
nMsgDialog - > show ( ) ;
nMsgDialog - > activateWindow ( ) ;
2010-05-02 20:09:55 -04:00
/* window will destroy itself! */
2008-11-25 20:19:09 -05:00
}
2010-05-18 18:37:18 -04:00
void MessagesDialog : : togglefileview_internal ( )
2008-01-26 08:08:28 -05:00
{
2010-05-18 18:37:18 -04:00
/* if msg header visible -> change icon and tooltip
* three widgets . . .
*/
2008-01-26 08:08:28 -05:00
2010-05-18 18:37:18 -04:00
if ( ui . expandFilesButton - > isChecked ( ) )
{
ui . expandFilesButton - > setIcon ( QIcon ( QString ( " :/images/edit_remove24.png " ) ) ) ;
ui . expandFilesButton - > setToolTip ( tr ( " Hide " ) ) ;
}
else
{
ui . expandFilesButton - > setIcon ( QIcon ( QString ( " :/images/edit_add24.png " ) ) ) ;
ui . expandFilesButton - > setToolTip ( tr ( " Expand " ) ) ;
}
}
2008-01-26 08:08:28 -05:00
2010-05-18 18:37:18 -04:00
void MessagesDialog : : togglefileview ( )
{
// save state of files view
RSettings settings ( QString ( " MessageDialog " ) ) ;
settings . setValue ( " expandFiles " , ui . expandFilesButton - > isChecked ( ) ) ;
togglefileview_internal ( ) ;
2008-01-26 08:08:28 -05:00
}
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 ;
2010-02-24 09:25:23 -05:00
case 1 : f . size = it - > data ( ) . toULongLong ( ) ;
2009-05-17 15:38:42 -04:00
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 )
2010-02-24 09:25:23 -05:00
{
const FileInfo & f ( it - > second ) ;
std : : cout < < " Requesting file " < < f . fname < < " , size= " < < f . size < < " , hash= " < < f . hash < < std : : endl ;
2010-02-24 09:27:12 -05:00
rsFiles - > FileRequest ( it - > second . fname , it - > second . hash , it - > second . size , " " , RS_FILE_HINTS_NETWORK_WIDE , srcIds ) ;
2010-02-24 09:25:23 -05:00
}
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
{
2010-05-07 18:23:38 -04:00
MessagesModel - > removeRows ( 0 , MessagesModel - > rowCount ( ) ) ;
2010-02-13 13:49:56 -05:00
insertMessages ( ) ;
insertMsgTxtAndFiles ( ) ;
2007-11-14 22:18:48 -05:00
}
void MessagesDialog : : insertMessages ( )
{
2010-02-13 13:49:56 -05:00
std : : cerr < < " MessagesDialog::insertMessages called " ;
fflush ( 0 ) ;
2010-05-07 18:23:38 -04:00
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
int listrow = ui . listWidget - > currentRow ( ) ;
2010-02-13 13:49:56 -05:00
std : : cerr < < " MessagesDialog::insertMessages() " < < std : : endl ;
std : : cerr < < " Current Row: " < < listrow < < std : : endl ;
fflush ( 0 ) ;
2010-05-07 18:23:38 -04:00
2010-05-18 18:37:18 -04:00
int nFilterColumn = FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ;
2007-11-14 22:18:48 -05:00
/* check the mode we are in */
unsigned int msgbox = 0 ;
2010-05-07 18:23:38 -04:00
bool bFill = true ;
2007-11-14 22:18:48 -05:00
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 :
msgbox = RS_MSG_INBOX ;
break ;
2010-05-07 18:23:38 -04:00
default :
bFill = false ;
2007-11-14 22:18:48 -05:00
}
2010-05-07 18:23:38 -04:00
if ( bFill ) {
/* remove old items */
int nRowCount = MessagesModel - > rowCount ( ) ;
int nRow = 0 ;
for ( nRow = 0 ; nRow < nRowCount ; ) {
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; it + + ) {
if ( ( it - > msgflags & RS_MSG_BOXMASK ) ! = msgbox ) {
continue ;
}
if ( it - > msgId = = MessagesModel - > item ( nRow , 5 ) - > text ( ) . toStdString ( ) ) {
break ;
}
}
2009-01-22 20:58:56 -05:00
2010-05-07 18:23:38 -04:00
if ( it = = msgList . end ( ) ) {
MessagesModel - > removeRow ( nRow ) ;
nRowCount = MessagesModel - > rowCount ( ) ;
} else {
nRow + + ;
}
}
2007-11-14 22:18:48 -05:00
2010-05-07 18:23:38 -04:00
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; it + + )
2007-11-14 22:18:48 -05:00
{
2010-05-07 18:23:38 -04: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 )
2010-02-27 13:40:16 -05:00
{
2010-05-07 18:23:38 -04:00
//std::cerr << "Msg from other box: " << it->msgflags;
//std::cerr << std::endl;
continue ;
2010-02-27 13:40:16 -05:00
}
2010-05-07 18:23:38 -04:00
// search exisisting items
nRowCount = MessagesModel - > rowCount ( ) ;
for ( nRow = 0 ; nRow < nRowCount ; nRow + + ) {
if ( it - > msgId = = MessagesModel - > item ( nRow , 5 ) - > text ( ) . toStdString ( ) ) {
break ;
}
}
/* make a widget per friend */
2010-05-10 15:55:59 -04:00
QStandardItem * item [ COLUMN_COUNT ] ;
2010-05-07 18:23:38 -04:00
bool bInsert = false ;
if ( nRow < nRowCount ) {
2010-05-10 15:55:59 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
item [ i ] = MessagesModel - > item ( nRow , i ) ;
}
2010-05-07 18:23:38 -04:00
} else {
2010-05-10 15:55:59 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
item [ i ] = new QStandardItem ( ) ;
}
2010-05-07 18:23:38 -04:00
bInsert = true ;
}
//set this false if you want to expand on double click
2010-05-18 18:37:18 -04:00
item [ COLUMN_ATTACHEMENTS ] - > setEditable ( false ) ;
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setEditable ( false ) ;
item [ COLUMN_FROM ] - > setEditable ( false ) ;
item [ COLUMN_DATE ] - > setEditable ( false ) ;
item [ COLUMN_SRCID ] - > setEditable ( false ) ;
2010-05-18 18:37:18 -04:00
item [ COLUMN_CONTENT ] - > setEditable ( false ) ;
2010-05-07 18:23:38 -04: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
*/
2010-05-10 15:55:59 -04:00
QString dateString ;
2010-05-07 18:23:38 -04:00
// Date First.... (for sorting)
2010-02-27 13:40:16 -05:00
{
2010-05-07 18:23:38 -04:00
QDateTime qdatetime ;
qdatetime . setTime_t ( it - > ts ) ;
2010-05-10 15:55:59 -04:00
// add string to all data
dateString = qdatetime . toString ( " _yyyyMMdd_hhmmss " ) ;
2010-05-07 18:23:38 -04:00
//if the mail is on same date show only time.
if ( qdatetime . daysTo ( QDateTime : : currentDateTime ( ) ) = = 0 )
{
QTime qtime = qdatetime . time ( ) ;
QVariant varTime ( qtime ) ;
2010-05-10 15:55:59 -04:00
item [ COLUMN_DATE ] - > setData ( varTime , Qt : : DisplayRole ) ;
2010-05-07 18:23:38 -04:00
}
else
{
QVariant varDateTime ( qdatetime ) ;
2010-05-10 15:55:59 -04:00
item [ COLUMN_DATE ] - > setData ( varDateTime , Qt : : DisplayRole ) ;
2010-05-07 18:23:38 -04:00
}
// for sorting
2010-05-10 15:55:59 -04:00
item [ COLUMN_DATE ] - > setData ( qdatetime , Qt : : UserRole ) ;
2010-02-27 13:40:16 -05:00
}
2007-11-14 22:18:48 -05:00
2010-05-07 18:23:38 -04:00
// From ....
{
2010-05-10 15:55:59 -04:00
item [ COLUMN_FROM ] - > setText ( QString : : fromStdString ( rsPeers - > getPeerName ( it - > srcId ) ) ) ;
item [ COLUMN_FROM ] - > setData ( item [ COLUMN_FROM ] - > text ( ) + dateString , Qt : : UserRole ) ;
2010-05-07 18:23:38 -04:00
}
2007-11-14 22:18:48 -05:00
2010-05-07 18:23:38 -04:00
// Subject
2010-05-10 15:55:59 -04:00
QString text = QString : : fromStdWString ( it - > title ) ;
item [ COLUMN_SUBJECT ] - > setText ( text ) ;
item [ COLUMN_SUBJECT ] - > setData ( text + dateString , Qt : : UserRole ) ;
2010-05-07 18:23:38 -04:00
if ( ( it - > msgflags & RS_MSG_NEW ) = = RS_MSG_NEW )
2010-01-15 21:42:11 -05:00
{
2010-05-10 15:55:59 -04:00
QFont qf = item [ COLUMN_SUBJECT ] - > font ( ) ;
2010-01-15 21:42:11 -05:00
qf . setBold ( true ) ;
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setFont ( qf ) ;
2010-05-07 18:23:38 -04:00
2010-01-15 21:42:11 -05:00
}
2010-05-07 18:23:38 -04:00
// Change Message icon when Subject is Re: or Fwd:
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-replied-read.png " ) ) ;
2010-05-07 18:23:38 -04:00
}
else if ( text . startsWith ( " Fwd: " , Qt : : CaseInsensitive ) )
{
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-forwarded-read.png " ) ) ;
2010-05-07 18:23:38 -04:00
}
else
{
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-read.png " ) ) ;
2010-05-07 18:23:38 -04:00
}
2010-01-15 21:42:11 -05:00
2010-05-07 18:23:38 -04: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 ) ; */
}
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-replied.png " ) ) ;
2010-05-07 18:23:38 -04:00
}
else if ( text . startsWith ( " Fwd: " , Qt : : CaseInsensitive ) )
{
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-forwarded.png " ) ) ;
2010-05-07 18:23:38 -04:00
}
else
{
2010-05-10 15:55:59 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail.png " ) ) ;
2010-05-07 18:23:38 -04:00
}
}
2007-11-14 22:18:48 -05:00
2010-05-07 18:23:38 -04:00
if ( ( it - > msgflags & RS_MSG_BOXMASK ) = = RS_MSG_OUTBOX )
{
MessagesModel - > setHeaderData ( 2 , Qt : : Horizontal , tr ( " Recipient " ) ) ;
}
else
{
MessagesModel - > setHeaderData ( 2 , Qt : : Horizontal , tr ( " From " ) ) ;
}
2007-11-14 22:18:48 -05:00
2010-05-07 18:23:38 -04:00
// No of Files.
{
std : : ostringstream out ;
out < < it - > count ;
2010-05-18 18:37:18 -04:00
item [ COLUMN_ATTACHEMENTS ] - > setText ( QString : : fromStdString ( out . str ( ) ) ) ;
item [ COLUMN_ATTACHEMENTS ] - > setData ( item [ COLUMN_ATTACHEMENTS ] - > text ( ) + dateString , Qt : : UserRole ) ;
2010-05-10 15:55:59 -04:00
//item -> setTextAlignment( 0, Qt::AlignCenter );
2010-05-07 18:23:38 -04:00
}
2010-05-10 15:55:59 -04:00
item [ COLUMN_SRCID ] - > setText ( QString : : fromStdString ( it - > srcId ) ) ;
item [ COLUMN_MSGID ] - > setText ( QString : : fromStdString ( it - > msgId ) ) ;
2010-05-07 18:23:38 -04:00
2010-05-18 18:37:18 -04:00
if ( nFilterColumn = = COLUMN_CONTENT ) {
// need content for filter
MessageInfo msgInfo ;
if ( rsMsgs - > getMessage ( it - > msgId , msgInfo ) ) {
QTextDocument doc ;
doc . setHtml ( QString : : fromStdWString ( msgInfo . msg ) ) ;
item [ COLUMN_CONTENT ] - > setText ( doc . toPlainText ( ) . replace ( QString ( " \n " ) , QString ( " " ) ) ) ;
} else {
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg " < < std : : endl ;
item [ COLUMN_CONTENT ] - > setText ( " " ) ;
}
}
2010-05-07 18:23:38 -04:00
if ( bInsert ) {
/* add to the list */
QList < QStandardItem * > itemList ;
2010-05-10 15:55:59 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
itemList . append ( item [ i ] ) ;
}
2010-05-07 18:23:38 -04:00
MessagesModel - > appendRow ( itemList ) ;
}
}
} else {
MessagesModel - > removeRows ( 0 , MessagesModel - > rowCount ( ) ) ;
2007-11-14 22:18:48 -05:00
}
2010-05-07 18:23:38 -04:00
2010-02-13 13:49:56 -05:00
updateMessageSummaryList ( ) ;
2010-05-10 15:55:59 -04:00
ui . messagestreeView - > hideColumn ( COLUMN_SRCID ) ;
ui . messagestreeView - > hideColumn ( COLUMN_MSGID ) ;
2010-05-18 18:37:18 -04:00
ui . messagestreeView - > hideColumn ( COLUMN_CONTENT ) ;
2007-11-14 22:18:48 -05:00
}
2010-04-27 17:46:28 -04:00
// current row in messagestreeView has changed
void MessagesDialog : : currentChanged ( const QModelIndex & index )
2007-11-14 22:18:48 -05:00
{
2010-04-27 17:46:28 -04:00
timer - > stop ( ) ;
timerIndex = index ;
timer - > start ( ) ;
}
// click in messagestreeView
void MessagesDialog : : clicked ( const QModelIndex & index )
{
timer - > stop ( ) ;
timerIndex = index ;
// show current message directly
updateCurrentMessage ( ) ;
}
// show current message directly
void MessagesDialog : : updateCurrentMessage ( )
{
timer - > stop ( ) ;
insertMsgTxtAndFiles ( timerIndex ) ;
setMsgAsRead ( timerIndex ) ;
updateMessageSummaryList ( ) ;
2007-11-14 22:18:48 -05:00
}
2010-02-13 13:49:56 -05:00
void MessagesDialog : : setMsgAsRead ( const QModelIndex & index )
2009-02-22 12:36:39 -05:00
{
2010-02-13 13:49:56 -05:00
QString text ;
QModelIndex currentIndex = proxyModel - > mapToSource ( index ) ;
if ( currentIndex . isValid ( ) = = false )
2009-02-22 12:36:39 -05:00
{
2010-02-13 13:49:56 -05:00
return ;
2009-02-22 12:36:39 -05:00
}
2010-02-13 13:49:56 -05:00
else
{
2010-05-10 15:55:59 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + )
2010-02-13 13:49:56 -05:00
{
QStandardItem * item ;
item = MessagesModel - > item ( currentIndex . row ( ) , i ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( false ) ;
item - > setFont ( qf ) ;
2009-02-22 12:36:39 -05:00
2010-02-13 13:49:56 -05:00
//change the icon to read. this need to be done when user clicks to the new message
2010-05-10 15:55:59 -04:00
if ( i = = COLUMN_SUBJECT )
2010-02-13 13:49:56 -05:00
{
text = item - > text ( ) ;
if ( text . startsWith ( " Re: " , Qt : : CaseInsensitive ) )
{
item - > setIcon ( QIcon ( " :/images/message-mail-replied-read.png " ) ) ;
}
else if ( text . startsWith ( " Fwd: " , Qt : : CaseInsensitive ) )
{
item - > setIcon ( QIcon ( " :/images/message-mail-forwarded-read.png " ) ) ;
}
else
{
item - > setIcon ( QIcon ( " :/images/message-mail-read.png " ) ) ;
}
}
2010-05-10 15:55:59 -04:00
if ( i = = COLUMN_MSGID )
2010-02-13 13:49:56 -05:00
{
std : : string mid ( item - > text ( ) . toStdString ( ) ) ;
rsMsgs - > MessageRead ( mid ) ;
}
}
}
2009-02-22 12:36:39 -05:00
}
2007-11-14 22:18:48 -05:00
2010-02-13 13:49:56 -05:00
void MessagesDialog : : insertMsgTxtAndFiles ( QModelIndex Index )
2007-11-14 22:18:48 -05:00
{
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 ;
2010-02-13 13:49:56 -05:00
QModelIndex currentIndex = proxyModel - > mapToSource ( Index ) ;
if ( currentIndex . isValid ( ) = = false )
2007-11-14 22:18:48 -05:00
{
/* 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
2010-05-07 18:23:38 -04:00
ui . actionSave_as - > setDisabled ( true ) ;
ui . actionPrintPreview - > setDisabled ( true ) ;
ui . actionPrint - > setDisabled ( true ) ;
2007-11-14 22:18:48 -05:00
return ;
}
else
{
2010-02-13 13:49:56 -05:00
QStandardItem * item ;
2010-05-10 15:55:59 -04:00
item = MessagesModel - > item ( currentIndex . row ( ) , COLUMN_SRCID ) ;
2010-02-13 13:49:56 -05:00
cid = item - > text ( ) . toStdString ( ) ;
fflush ( 0 ) ;
2010-05-10 15:55:59 -04:00
item = MessagesModel - > item ( currentIndex . row ( ) , COLUMN_MSGID ) ;
2010-02-13 13:49:56 -05:00
mid = item - > text ( ) . toStdString ( ) ;
2007-11-14 22:18:48 -05:00
}
2010-05-07 18:23:38 -04:00
int nCount = getSelectedMsgCount ( ) ;
if ( nCount = = 1 ) {
ui . actionSave_as - > setEnabled ( true ) ;
ui . actionPrintPreview - > setEnabled ( true ) ;
ui . actionPrint - > setEnabled ( true ) ;
} else {
ui . actionSave_as - > setDisabled ( true ) ;
ui . actionPrintPreview - > setDisabled ( true ) ;
ui . actionPrint - > setDisabled ( true ) ;
}
2008-02-04 12:55:59 -05:00
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
2010-03-24 09:05:57 -04:00
item - > setText ( 1 , QString : : number ( 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
{
2010-03-29 11:27:37 -04:00
if ( QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) = = " " )
{
msgTxt + = " <a style='color: black;'href=' " + tr ( " Anonymous " ) + " @ " + QString : : fromStdString ( * pit ) + " '> " + tr ( " Anonymous " ) + " </a> " + " " ;
}
else
msgTxt + = " <a style='color: black;'href=' " + QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) + " @ " + QString : : fromStdString ( * pit ) + " '> " + QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) + " </a> " + " " ;
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
{
2010-03-29 11:27:37 -04:00
if ( QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) = = " " )
{
msgTxt + = " <a style='color: black;'href=' " + tr ( " Anonymous " ) + " @ " + QString : : fromStdString ( * pit ) + " '> " + tr ( " Anonymous " ) + " </a> " + " " ;
}
else
2010-03-29 09:39:23 -04:00
msgTxt + = " <a style='color: black;'href=' " + QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) + " @ " + QString : : fromStdString ( * pit ) + " '> " + QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) + " </a> " + " " ;
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
{
2010-03-29 11:27:37 -04:00
if ( QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) = = " " )
{
msgTxt + = " <a style='color: black;'href=' " + tr ( " Anonymous " ) + " @ " + QString : : fromStdString ( * pit ) + " '> " + tr ( " Anonymous " ) + " </a> " + " " ;
}
else
2010-03-29 09:39:23 -04:00
msgTxt + = " <a style='color: black;'href=' " + QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) + " @ " + QString : : fromStdString ( * pit ) + " '> " + QString : : fromStdString ( rsPeers - > getPeerName ( * pit ) ) + " </a> " + " " ;
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 ) ;
2010-01-28 07:56:17 -05:00
QString timestamp = qtime . toString ( " dd.MM.yyyy hh:mm:ss " ) ;
2008-01-26 08:08:28 -05:00
ui . dateText - > setText ( timestamp ) ;
}
ui . toText - > setText ( msgTxt ) ;
2010-03-28 11:56:38 -04:00
ui . fromText - > setText ( " <a style='color: blue;' href=' " + QString : : fromStdString ( rsPeers - > getPeerName ( msgInfo . srcId ) ) + " @ " + QString : : fromStdString ( msgInfo . srcId ) + " '> " + QString : : fromStdString ( rsPeers - > getPeerName ( msgInfo . srcId ) ) + " </a> " ) ;
ui . fromText - > setToolTip ( QString : : fromStdString ( rsPeers - > getPeerName ( msgInfo . srcId ) ) + " @ " + QString : : fromStdString ( 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 )
{
2010-02-13 13:49:56 -05:00
QModelIndex currentIndex = ui . messagestreeView - > currentIndex ( ) ;
currentIndex = proxyModel - > mapToSource ( currentIndex ) ;
int rowSelected = - 1 ;
2007-11-14 22:18:48 -05:00
/* get its Ids */
2010-02-13 13:49:56 -05:00
if ( currentIndex . isValid ( ) = = false )
2007-11-14 22:18:48 -05:00
{
2010-02-13 13:49:56 -05:00
//If no message is selected. assume first message is selected.
if ( MessagesModel - > rowCount ( ) = = 0 )
{
return false ;
}
else
{
rowSelected = 0 ;
}
}
else
{
rowSelected = currentIndex . row ( ) ;
2007-11-14 22:18:48 -05:00
}
2010-02-13 13:49:56 -05:00
QStandardItem * item ;
2010-05-10 15:55:59 -04:00
item = MessagesModel - > item ( rowSelected , COLUMN_SRCID ) ;
2010-02-13 13:49:56 -05:00
cid = item - > text ( ) . toStdString ( ) ;
2010-05-10 15:55:59 -04:00
item = MessagesModel - > item ( rowSelected , COLUMN_MSGID ) ;
2010-02-13 13:49:56 -05:00
mid = item - > text ( ) . toStdString ( ) ;
return true ;
}
2007-11-14 22:18:48 -05:00
void MessagesDialog : : removemessage ( )
{
2010-02-13 13:49:56 -05:00
QList < QModelIndex > selectedIndexList = ui . messagestreeView - > selectionModel ( ) - > selectedIndexes ( ) ;
QList < int > rowList ;
2010-03-28 11:03:20 -04:00
QModelIndex selectedIndex ;
2010-02-13 13:49:56 -05:00
for ( QList < QModelIndex > : : iterator it = selectedIndexList . begin ( ) ; it ! = selectedIndexList . end ( ) ; it + + )
{
2010-03-28 11:03:20 -04:00
selectedIndex = proxyModel - > mapToSource ( * it ) ;
int row = selectedIndex . row ( ) ;
2010-02-13 13:49:56 -05:00
if ( rowList . contains ( row ) = = false )
{
rowList . append ( row ) ;
}
}
2007-11-14 22:18:48 -05:00
2010-02-13 13:49:56 -05:00
for ( QList < int > : : const_iterator it1 ( rowList . begin ( ) ) ; it1 ! = rowList . end ( ) ; + + it1 )
{
2010-05-10 15:55:59 -04:00
rsMsgs - > MessageDelete ( MessagesModel - > item ( ( * it1 ) , COLUMN_MSGID ) - > text ( ) . toStdString ( ) ) ;
2010-02-13 13:49:56 -05:00
}
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 )
{
2010-03-10 16:38:26 -05:00
# ifdef FORUM_DEBUG
std : : cerr < < " MessagesDialog::anchorClicked link.scheme() : " < < link . scheme ( ) . toStdString ( ) < < std : : endl ;
# endif
2010-01-16 13:03:35 -05:00
if ( link . scheme ( ) = = " retroshare " )
{
2010-03-10 16:38:26 -05:00
RetroShareLink rslnk ( link . toString ( ) ) ;
2010-01-16 13:03:35 -05:00
# ifdef FORUM_DEBUG
std : : cerr < < " MessagesDialog::anchorClicked FileRequest : fileName : " < < fileName < < " . fileHash : " < < fileHash < < " . fileSize : " < < fileSize < < std : : endl ;
# endif
2010-03-10 16:38:26 -05:00
if ( rslnk . valid ( ) )
2010-01-16 13:03:35 -05:00
{
std : : list < std : : string > srcIds ;
2010-03-10 16:38:26 -05:00
if ( rsFiles - > FileRequest ( rslnk . name ( ) . toStdString ( ) , rslnk . hash ( ) . toStdString ( ) , rslnk . size ( ) , " " , RS_FILE_HINTS_NETWORK_WIDE , srcIds ) )
2010-01-16 13:03:35 -05:00
{
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 ( )
{
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-05-18 18:37:18 -04:00
RSettings settings ( QString ( " MessageDialog " ) ) ;
2010-05-11 16:02:52 -04: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 ( ) ) ;
2010-01-21 20:05:45 -05:00
}
void MessagesDialog : : buttonstextbesideicon ( )
{
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-05-18 18:37:18 -04:00
RSettings settings ( QString ( " MessageDialog " ) ) ;
2010-05-11 16:02:52 -04: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 ( ) ) ;
2010-01-21 20:05:45 -05:00
}
void MessagesDialog : : buttonstextundericon ( )
{
2010-05-11 16:02:52 -04:00
RshareSettings settings ;
settings . beginGroup ( " MessageDialog " ) ;
2010-01-25 07:44:12 -05:00
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-05-11 16:02:52 -04: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 ( ) ) ;
2010-01-25 07:44:12 -05:00
2010-05-11 16:02:52 -04:00
settings . endGroup ( ) ;
2010-01-25 07:44:12 -05:00
}
void MessagesDialog : : loadToolButtonsettings ( )
{
2010-05-11 16:02:52 -04:00
RshareSettings settings ;
settings . beginGroup ( " MessageDialog " ) ;
2010-01-25 07:44:12 -05:00
2010-05-11 16:02:52 -04:00
if ( settings . value ( " ToolButon_Stlye1 " , " 0 " ) . toInt ( ) = = 0 )
2010-01-25 07:44:12 -05:00
{
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 ) ;
}
2010-05-11 16:02:52 -04:00
else if ( settings . value ( " ToolButon_Stlye1 " , " 2 " ) . toInt ( ) = = 2 )
2010-01-25 07:44:12 -05:00
{
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 ) ;
}
2010-05-11 16:02:52 -04:00
else if ( settings . value ( " ToolButon_Stlye1 " , " 3 " ) . toInt ( ) = = 3 )
2010-01-25 07:44:12 -05:00
{
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 ) ;
}
2010-05-11 16:02:52 -04:00
settings . endGroup ( ) ;
2010-01-25 07:44:12 -05:00
}
2010-02-13 13:49:56 -05:00
void MessagesDialog : : filterRegExpChanged ( )
{
QRegExp regExp ( ui . filterPatternLineEdit - > text ( ) , Qt : : CaseInsensitive , QRegExp : : FixedString ) ;
proxyModel - > setFilterRegExp ( regExp ) ;
}
void MessagesDialog : : filterColumnChanged ( )
{
2010-05-18 18:37:18 -04:00
int nFilterColumn = FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ;
if ( nFilterColumn = = COLUMN_CONTENT ) {
// need content ... refill
insertMessages ( ) ;
}
proxyModel - > setFilterKeyColumn ( nFilterColumn ) ;
// save index
RSettings settings ( QString ( " MessageDialog " ) ) ;
settings . setValue ( " filterColumn " , nFilterColumn ) ;
2010-02-13 13:49:56 -05:00
}
void MessagesDialog : : updateMessageSummaryList ( )
{
2010-05-13 15:20:40 -04:00
unsigned int newInboxCount = 0 ;
unsigned int newOutboxCount = 0 ;
unsigned int newDraftCount = 0 ;
unsigned int newSentboxCount = 0 ;
unsigned int inboxCount = 0 ;
/* calculating the new messages */
rsMsgs - > getMessageCount ( & inboxCount , & newInboxCount , & newOutboxCount , & newDraftCount , & newSentboxCount ) ;
2010-02-13 13:49:56 -05:00
2010-05-07 18:23:38 -04:00
QString textItem ;
2010-02-13 13:49:56 -05:00
/*updating the labels in leftcolumn*/
2010-05-07 18:23:38 -04:00
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
QListWidgetItem * item = ui . listWidget - > item ( 0 ) ;
if ( newInboxCount ! = 0 )
2010-02-13 13:49:56 -05:00
{
2010-02-27 07:45:09 -05:00
textItem = tr ( " Inbox " ) + " " + " ( " + QString : : number ( newInboxCount ) + " ) " ;
2010-02-13 13:49:56 -05:00
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( true ) ;
item - > setFont ( qf ) ;
item - > setIcon ( QIcon ( " :/images/folder-inbox-new.png " ) ) ;
2010-03-03 11:22:32 -05:00
item - > setForeground ( QBrush ( QColor ( 49 , 106 , 197 ) ) ) ;
2010-02-13 13:49:56 -05:00
}
else
{
textItem = tr ( " Inbox " ) ;
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( false ) ;
item - > setFont ( qf ) ;
2010-03-03 11:22:32 -05:00
item - > setIcon ( QIcon ( " :/images/folder-inbox.png " ) ) ;
item - > setForeground ( QBrush ( QColor ( 0 , 0 , 0 ) ) ) ;
2010-02-13 13:49:56 -05:00
}
2010-05-07 18:23:38 -04:00
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
item = ui . listWidget - > item ( 1 ) ;
if ( newOutboxCount ! = 0 )
2010-02-13 13:49:56 -05:00
{
2010-02-27 07:45:09 -05:00
textItem = tr ( " Outbox " ) + " " + " ( " + QString : : number ( newOutboxCount ) + " ) " ;
2010-02-13 13:49:56 -05:00
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( true ) ;
item - > setFont ( qf ) ;
}
else
{
textItem = tr ( " Outbox " ) ;
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( false ) ;
item - > setFont ( qf ) ;
}
2010-05-07 18:23:38 -04:00
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
item = ui . listWidget - > item ( 2 ) ;
if ( newDraftCount ! = 0 )
{
2010-02-13 13:49:56 -05:00
textItem = tr ( " Draft " ) + " ( " + QString : : number ( newDraftCount ) + " ) " ;
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( true ) ;
item - > setFont ( qf ) ;
}
else
{
textItem = tr ( " Draft " ) ;
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( false ) ;
item - > setFont ( qf ) ;
2010-04-28 17:05:11 -04:00
}
2010-05-07 18:23:38 -04:00
/* Total Inbox */
item = ui . listWidget - > item ( 5 ) ;
textItem = tr ( " Total Inbox: " ) + " " + QString : : number ( inboxCount ) ;
item - > setText ( textItem ) ;
2010-04-28 17:05:11 -04:00
/* Total Sent */
2010-05-07 18:23:38 -04:00
item = ui . listWidget - > item ( 6 ) ;
textItem = tr ( " Total Sent: " ) + " " + QString : : number ( newSentboxCount ) ;
item - > setText ( textItem ) ;
2010-02-13 13:49:56 -05:00
}
2010-02-14 07:29:50 -05:00
/** clear Filter **/
void MessagesDialog : : clearFilter ( )
{
ui . filterPatternLineEdit - > clear ( ) ;
ui . filterPatternLineEdit - > setFocus ( ) ;
}
/* toggle clearButton */
void MessagesDialog : : toggleclearButton ( )
{
QString text = ui . filterPatternLineEdit - > text ( ) ;
if ( text . isEmpty ( ) )
{
ui . clearButton - > hide ( ) ;
}
else
{
ui . clearButton - > show ( ) ;
}
2010-02-24 09:25:23 -05:00
}