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
2010-05-23 13:21:30 -04:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2007-11-14 22:18:48 -05:00
* Boston , MA 02110 - 1301 , USA .
2008-09-04 15:28:35 -04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-23 14:52:58 -04:00
# include <QStandardItemModel>
# include <QShortcut>
# include <QTimer>
# include <QDateTime>
2011-05-21 12:26:00 -04:00
# include <QKeyEvent>
2009-11-28 09:34:15 -05:00
2008-09-04 15:28:35 -04:00
# include "MessagesDialog.h"
2010-05-23 15:13:41 -04:00
# include "msgs/MessageComposer.h"
2011-06-03 20:46:02 -04:00
# include "msgs/MessageWidget.h"
2011-05-21 12:26:00 -04:00
# include "msgs/TagsMenu.h"
2010-07-23 14:52:58 -04:00
# include "settings/rsharesettings.h"
2010-09-12 18:17:17 -04:00
# include "common/TagDefs.h"
2010-09-28 16:33:34 -04:00
# include "common/PeerDefs.h"
2010-11-09 18:56:02 -05:00
# include "common/RSItemDelegate.h"
2007-11-14 22:18:48 -05:00
2010-08-06 05:40:23 -04:00
# include <retroshare/rspeers.h>
2011-05-21 12:26:00 -04:00
# include <retroshare/rsmsgs.h>
2009-02-11 13:43:37 -05:00
2010-08-22 18:12:26 -04:00
# include <algorithm>
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"
2011-05-23 19:45:31 -04:00
# define IMAGE_MESSAGEREMOVE ": / images / message-mail-imapdelete.png"
# define IMAGE_STAR_ON ": / images / star-on-16.png"
# define IMAGE_STAR_OFF ": / images / star-off-16.png"
# define COLUMN_COUNT 8
2011-05-24 19:35:11 -04:00
# define COLUMN_STAR 0
# define COLUMN_ATTACHEMENTS 1
# define COLUMN_SUBJECT 2
# define COLUMN_UNREAD 3
# define COLUMN_FROM 4
# define COLUMN_DATE 5
2011-05-23 19:45:31 -04:00
# define COLUMN_CONTENT 6
# define COLUMN_TAGS 7
2010-06-25 08:17:46 -04:00
# define COLUMN_DATA 0 // column for storing the userdata like msgid and srcid
2010-11-02 17:11:11 -04:00
# define ROLE_SORT Qt::UserRole
# define ROLE_MSGID Qt::UserRole + 1
# define ROLE_SRCID Qt::UserRole + 2
# define ROLE_UNREAD Qt::UserRole + 3
# define ROLE_MSGFLAGS Qt::UserRole + 4
2010-05-27 15:48:52 -04:00
2011-06-04 18:54:03 -04:00
# define ROLE_QUICKVIEW_TYPE Qt::UserRole
# define ROLE_QUICKVIEW_ID Qt::UserRole + 1
# define ROLE_QUICKVIEW_TEXT Qt::UserRole + 2
# define QUICKVIEW_TYPE_NOTHING 0
# define QUICKVIEW_TYPE_STATIC 1
# define QUICKVIEW_TYPE_TAG 2
# define QUICKVIEW_STATIC_ID_STARRED 1
2010-05-28 10:42:54 -04:00
# define ROW_INBOX 0
# define ROW_OUTBOX 1
# define ROW_DRAFTBOX 2
# define ROW_SENTBOX 3
# define ROW_TRASHBOX 4
2010-05-27 15:48:52 -04:00
2010-06-03 18:12:07 -04:00
MessagesDialog : : LockUpdate : : LockUpdate ( MessagesDialog * pDialog , bool bUpdate )
{
m_pDialog = pDialog ;
m_bUpdate = bUpdate ;
m_pDialog - > m_nLockUpdate + + ;
}
MessagesDialog : : LockUpdate : : ~ LockUpdate ( )
{
2010-07-08 21:10:27 -04:00
if ( - - m_pDialog - > m_nLockUpdate < 0 )
m_pDialog - > m_nLockUpdate = 0 ;
2010-06-03 18:12:07 -04:00
if ( m_bUpdate & & m_pDialog - > m_nLockUpdate = = 0 ) {
m_pDialog - > insertMessages ( ) ;
}
}
2010-08-22 18:12:26 -04:00
void MessagesDialog : : LockUpdate : : setUpdate ( bool bUpdate )
{
m_bUpdate = bUpdate ;
}
2010-05-18 18:37:18 -04:00
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 ;
2010-05-27 15:48:52 -04:00
case 5 :
return COLUMN_TAGS ;
2010-05-18 18:37:18 -04:00
}
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 ;
2010-05-27 15:48:52 -04:00
case COLUMN_TAGS :
return 5 ;
2010-05-18 18:37:18 -04:00
}
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 )
{
2010-05-23 13:21:30 -04:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
m_bProcessSettings = false ;
2011-06-04 18:54:03 -04:00
inChange = false ;
2010-06-03 18:12:07 -04:00
m_nLockUpdate = 0 ;
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
connect ( ui . messagestreeView , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( messageslistWidgetCostumPopupMenu ( QPoint ) ) ) ;
connect ( ui . listWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( folderlistWidgetCostumPopupMenu ( QPoint ) ) ) ;
connect ( ui . messagestreeView , SIGNAL ( clicked ( const QModelIndex & ) ) , this , SLOT ( clicked ( const QModelIndex & ) ) ) ;
connect ( ui . messagestreeView , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( doubleClicked ( const QModelIndex & ) ) ) ;
connect ( ui . listWidget , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( changeBox ( int ) ) ) ;
2011-06-04 18:54:03 -04:00
connect ( ui . quickViewWidget , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( changeQuickView ( int ) ) ) ;
2011-06-03 20:46:02 -04:00
connect ( ui . tabWidget , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( tabChanged ( int ) ) ) ;
connect ( ui . tabWidget , SIGNAL ( tabCloseRequested ( int ) ) , this , SLOT ( tabCloseRequested ( int ) ) ) ;
2010-05-23 13:21:30 -04:00
connect ( ui . newmessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( newmessage ( ) ) ) ;
2011-06-03 20:46:02 -04:00
connect ( ui . actionTextBesideIcon , SIGNAL ( triggered ( ) ) , this , SLOT ( buttonStyle ( ) ) ) ;
connect ( ui . actionIconOnly , SIGNAL ( triggered ( ) ) , this , SLOT ( buttonStyle ( ) ) ) ;
connect ( ui . actionTextUnderIcon , SIGNAL ( triggered ( ) ) , this , SLOT ( buttonStyle ( ) ) ) ;
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
ui . actionTextBesideIcon - > setData ( Qt : : ToolButtonTextBesideIcon ) ;
ui . actionIconOnly - > setData ( Qt : : ToolButtonIconOnly ) ;
ui . actionTextUnderIcon - > setData ( Qt : : ToolButtonTextUnderIcon ) ;
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
connect ( ui . clearButton , SIGNAL ( clicked ( ) ) , this , SLOT ( clearFilter ( ) ) ) ;
connect ( ui . filterPatternLineEdit , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( filterRegExpChanged ( ) ) ) ;
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
connect ( ui . filterColumnComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( filterColumnChanged ( ) ) ) ;
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
msgWidget = new MessageWidget ( true , this ) ;
ui . msgLayout - > addWidget ( msgWidget ) ;
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
connectActions ( ) ;
2010-05-23 13:21:30 -04:00
2010-06-01 18:14:52 -04:00
m_eListMode = LIST_NOTHING ;
2010-05-23 13:21:30 -04:00
mCurrMsgId = " " ;
// Set the QStandardItemModel
2010-05-10 15:55:59 -04:00
MessagesModel = new QStandardItemModel ( 0 , COLUMN_COUNT ) ;
2010-05-23 14:17:08 -04:00
MessagesModel - > setHeaderData ( COLUMN_ATTACHEMENTS , Qt : : Horizontal , QIcon ( " :/images/attachment.png " ) , Qt : : DecorationRole ) ;
2010-05-18 18:37:18 -04:00
MessagesModel - > setHeaderData ( COLUMN_SUBJECT , Qt : : Horizontal , tr ( " Subject " ) ) ;
2010-08-08 18:58:10 -04:00
MessagesModel - > setHeaderData ( COLUMN_UNREAD , Qt : : Horizontal , QIcon ( " :/images/message-state-header.png " ) , Qt : : DecorationRole ) ;
2010-05-18 18:37:18 -04:00
MessagesModel - > setHeaderData ( COLUMN_FROM , Qt : : Horizontal , tr ( " From " ) ) ;
MessagesModel - > setHeaderData ( COLUMN_DATE , Qt : : Horizontal , tr ( " Date " ) ) ;
2010-05-27 15:48:52 -04:00
MessagesModel - > setHeaderData ( COLUMN_TAGS , Qt : : Horizontal , tr ( " Tags " ) ) ;
2010-05-18 18:37:18 -04:00
MessagesModel - > setHeaderData ( COLUMN_CONTENT , Qt : : Horizontal , tr ( " Content " ) ) ;
2011-05-23 19:45:31 -04:00
MessagesModel - > setHeaderData ( COLUMN_STAR , Qt : : Horizontal , QIcon ( IMAGE_STAR_ON ) , Qt : : DecorationRole ) ;
2011-05-16 16:28:07 -04:00
MessagesModel - > setHeaderData ( COLUMN_ATTACHEMENTS , Qt : : Horizontal , tr ( " Click to sort by attachments " ) , Qt : : ToolTipRole ) ;
MessagesModel - > setHeaderData ( COLUMN_SUBJECT , Qt : : Horizontal , tr ( " Click to sort by subject " ) , Qt : : ToolTipRole ) ;
MessagesModel - > setHeaderData ( COLUMN_UNREAD , Qt : : Horizontal , tr ( " Click to sort by read " ) , Qt : : ToolTipRole ) ;
MessagesModel - > setHeaderData ( COLUMN_FROM , Qt : : Horizontal , tr ( " Click to sort by from " ) , Qt : : ToolTipRole ) ;
MessagesModel - > setHeaderData ( COLUMN_DATE , Qt : : Horizontal , tr ( " Click to sort by date " ) , Qt : : ToolTipRole ) ;
MessagesModel - > setHeaderData ( COLUMN_TAGS , Qt : : Horizontal , tr ( " Click to sort by tags " ) , Qt : : ToolTipRole ) ;
2011-05-23 19:45:31 -04:00
MessagesModel - > setHeaderData ( COLUMN_STAR , Qt : : Horizontal , tr ( " Click to sort by star " ) , Qt : : ToolTipRole ) ;
2010-05-18 18:37:18 -04:00
2010-02-13 13:49:56 -05:00
proxyModel = new QSortFilterProxyModel ( this ) ;
proxyModel - > setDynamicSortFilter ( true ) ;
proxyModel - > setSourceModel ( MessagesModel ) ;
2010-06-25 08:17:46 -04:00
proxyModel - > setSortRole ( ROLE_SORT ) ;
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 ) ;
2011-06-03 20:46:02 -04:00
connect ( ui . messagestreeView - > selectionModel ( ) , SIGNAL ( selectionChanged ( QItemSelection , QItemSelection ) ) , this , SLOT ( updateInterface ( ) ) ) ;
2010-05-23 13:21:30 -04:00
2010-11-09 18:56:02 -05:00
RSItemDelegate * itemDelegate = new RSItemDelegate ( this ) ;
itemDelegate - > setSpacing ( QSize ( 0 , 2 ) ) ;
ui . messagestreeView - > setItemDelegate ( itemDelegate ) ;
2010-05-23 13:21:30 -04:00
2010-02-13 13:49:56 -05:00
ui . messagestreeView - > setRootIsDecorated ( false ) ;
2010-05-23 13:21:30 -04:00
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 ( ) ) ) ;
2010-05-28 10:42:54 -04:00
Shortcut = new QShortcut ( QKeySequence ( Qt : : SHIFT | Qt : : Key_Delete ) , ui . messagestreeView , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( Shortcut , SIGNAL ( activated ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
2010-05-06 10:39:50 -04:00
2010-05-23 13:21:30 -04:00
/* Set header initial section sizes */
QHeaderView * msgwheader = ui . messagestreeView - > header ( ) ;
msgwheader - > resizeSection ( COLUMN_ATTACHEMENTS , 24 ) ;
msgwheader - > resizeSection ( COLUMN_SUBJECT , 250 ) ;
2010-08-08 18:58:10 -04:00
msgwheader - > resizeSection ( COLUMN_UNREAD , 16 ) ;
2010-05-23 13:21:30 -04:00
msgwheader - > resizeSection ( COLUMN_FROM , 140 ) ;
msgwheader - > resizeSection ( COLUMN_DATE , 140 ) ;
2011-05-23 19:45:31 -04:00
msgwheader - > resizeSection ( COLUMN_STAR , 16 ) ;
msgwheader - > setResizeMode ( COLUMN_STAR , QHeaderView : : Fixed ) ;
msgwheader - > resizeSection ( COLUMN_STAR , 24 ) ;
2010-05-23 13:21:30 -04:00
ui . forwardmessageButton - > setToolTip ( tr ( " Forward selected Message " ) ) ;
ui . replyallmessageButton - > setToolTip ( tr ( " Reply to All " ) ) ;
2008-11-25 20:19:09 -05:00
2011-06-05 09:37:49 -04:00
QMenu * printmenu = new QMenu ( ) ;
2008-09-04 15:28:35 -04:00
printmenu - > addAction ( ui . actionPrint ) ;
printmenu - > addAction ( ui . actionPrintPreview ) ;
2008-03-26 10:22:51 -04:00
ui . printbutton - > setMenu ( printmenu ) ;
2010-05-23 13:21:30 -04:00
2011-06-05 09:37:49 -04:00
QMenu * viewmenu = new QMenu ( ) ;
2010-01-21 20:05:45 -05:00
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-11-14 12:03:32 -05:00
ui . filterPatternLineEdit - > setMinimumWidth ( 20 ) ;
2008-09-04 15:28:35 -04:00
2010-05-23 13:21:30 -04:00
//setting default filter by column as subject
2010-05-18 18:37:18 -04:00
proxyModel - > setFilterKeyColumn ( FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ) ;
2010-05-23 13:21:30 -04:00
ui . clearButton - > hide ( ) ;
2010-02-14 07:29:50 -05:00
2010-05-18 18:37:18 -04:00
// load settings
processSettings ( true ) ;
2010-05-23 13:21:30 -04:00
/* Set header sizes for the fixed columns and resize modes, must be set after processSettings */
2010-05-23 14:17:08 -04:00
msgwheader - > setResizeMode ( COLUMN_ATTACHEMENTS , QHeaderView : : Fixed ) ;
2010-05-23 13:21:30 -04:00
msgwheader - > setResizeMode ( COLUMN_DATE , QHeaderView : : Interactive ) ;
2010-08-08 18:58:10 -04:00
msgwheader - > setResizeMode ( COLUMN_UNREAD , QHeaderView : : Fixed ) ;
msgwheader - > resizeSection ( COLUMN_UNREAD , 24 ) ;
2011-05-23 19:45:31 -04:00
msgwheader - > resizeSection ( COLUMN_STAR , 24 ) ;
msgwheader - > setResizeMode ( COLUMN_STAR , QHeaderView : : Fixed ) ;
2010-05-23 13:21:30 -04:00
2010-05-18 18:37:18 -04:00
// fill folder list
updateMessageSummaryList ( ) ;
2010-05-28 10:42:54 -04:00
ui . listWidget - > setCurrentRow ( ROW_INBOX ) ;
2010-05-18 18:37:18 -04:00
2010-05-27 15:48:52 -04:00
// create tag menu
2011-05-21 12:26:00 -04:00
TagsMenu * menu = new TagsMenu ( tr ( " Tags " ) , this ) ;
connect ( menu , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( tagAboutToShow ( ) ) ) ;
connect ( menu , SIGNAL ( tagSet ( int , bool ) ) , this , SLOT ( tagSet ( int , bool ) ) ) ;
connect ( menu , SIGNAL ( tagRemoveAll ( ) ) , this , SLOT ( tagRemoveAll ( ) ) ) ;
ui . tagButton - > setMenu ( menu ) ;
2011-06-04 18:54:03 -04:00
// fill quick view
fillQuickView ( ) ;
2010-05-27 15:48:52 -04:00
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 ( ) ) ) ;
2011-05-02 17:50:20 -04:00
ui . messagestreeView - > installEventFilter ( this ) ;
2011-06-03 20:46:02 -04:00
// remove close button of the the first tab
QTabBar : : ButtonPosition buttonPosition = ( QTabBar : : ButtonPosition ) ui . tabWidget - > tabBar ( ) - > style ( ) - > styleHint ( QStyle : : SH_TabBar_CloseButtonPosition , 0 , 0 ) ;
QWidget * tabButton = ui . tabWidget - > tabBar ( ) - > tabButton ( 0 , buttonPosition ) ;
if ( tabButton ) {
tabButton - > hide ( ) ;
}
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 ) ;
}
2011-06-03 20:46:02 -04:00
void MessagesDialog : : processSettings ( bool load )
2010-05-18 18:37:18 -04:00
{
2011-05-24 19:35:11 -04:00
int messageTreeVersion = 2 ; // version number for the settings to solve problems when modifying the column count
2011-05-23 19:45:31 -04:00
2010-05-20 17:53:27 -04:00
m_bProcessSettings = true ;
2010-05-18 18:37:18 -04:00
QHeaderView * msgwheader = ui . messagestreeView - > header ( ) ;
2011-06-03 20:46:02 -04:00
Settings - > beginGroup ( " MessageDialog " ) ;
2010-05-18 18:37:18 -04:00
2011-06-03 20:46:02 -04:00
if ( load ) {
2010-05-18 18:37:18 -04:00
// load settings
// filterColumn
2010-05-20 17:53:27 -04:00
int nValue = FilterColumnToComboBox ( Settings - > value ( " filterColumn " , true ) . toInt ( ) ) ;
2010-05-18 18:37:18 -04:00
ui . filterColumnComboBox - > setCurrentIndex ( nValue ) ;
// state of message tree
2011-05-23 19:45:31 -04:00
if ( Settings - > value ( " MessageTreeVersion " ) . toInt ( ) = = messageTreeVersion ) {
msgwheader - > restoreState ( Settings - > value ( " MessageTree " ) . toByteArray ( ) ) ;
}
2010-05-18 18:37:18 -04:00
2011-06-04 18:54:03 -04:00
// state of quick view list
bool value = Settings - > value ( " QuickViewList " , true ) . toBool ( ) ;
ui . quickViewsButton - > setChecked ( value ) ;
2010-06-01 18:14:52 -04:00
2010-05-18 18:37:18 -04:00
// state of splitter
2010-05-20 17:53:27 -04:00
ui . msgSplitter - > restoreState ( Settings - > value ( " Splitter " ) . toByteArray ( ) ) ;
ui . msgSplitter_2 - > restoreState ( Settings - > value ( " Splitter2 " ) . toByteArray ( ) ) ;
2010-06-19 13:46:19 -04:00
ui . listSplitter - > restoreState ( Settings - > value ( " Splitter3 " ) . toByteArray ( ) ) ;
2011-06-03 20:46:02 -04:00
/* toolbar button style */
Qt : : ToolButtonStyle style = ( Qt : : ToolButtonStyle ) Settings - > value ( " ToolButon_Stlye " , Qt : : ToolButtonIconOnly ) . toInt ( ) ;
setToolbarButtonStyle ( style ) ;
2010-05-18 18:37:18 -04:00
} else {
// save settings
// state of message tree
2010-05-20 17:53:27 -04:00
Settings - > setValue ( " MessageTree " , msgwheader - > saveState ( ) ) ;
2011-05-23 19:45:31 -04:00
Settings - > setValue ( " MessageTreeVersion " , messageTreeVersion ) ;
2010-05-18 18:37:18 -04:00
2011-06-04 18:54:03 -04:00
// state of quick view list
Settings - > setValue ( " QuickViewList " , ui . quickViewsButton - > isChecked ( ) ) ;
2010-06-01 18:14:52 -04:00
2010-05-18 18:37:18 -04:00
// state of splitter
2010-05-20 17:53:27 -04:00
Settings - > setValue ( " Splitter " , ui . msgSplitter - > saveState ( ) ) ;
Settings - > setValue ( " Splitter2 " , ui . msgSplitter_2 - > saveState ( ) ) ;
2010-06-19 13:46:19 -04:00
Settings - > setValue ( " Splitter3 " , ui . listSplitter - > saveState ( ) ) ;
2011-06-03 20:46:02 -04:00
/* toolbar button style */
Settings - > setValue ( " ToolButon_Stlye " , ui . newmessageButton - > toolButtonStyle ( ) ) ;
2010-05-18 18:37:18 -04:00
}
2010-05-20 17:53:27 -04:00
Settings - > endGroup ( ) ;
2011-06-03 20:46:02 -04:00
if ( msgWidget ) {
msgWidget - > processSettings ( " MessageDialog " , load ) ;
}
2010-05-20 17:53:27 -04:00
m_bProcessSettings = false ;
2010-04-27 17:46:28 -04:00
}
2011-05-02 17:50:20 -04:00
bool MessagesDialog : : eventFilter ( QObject * obj , QEvent * event )
{
if ( obj = = ui . messagestreeView ) {
if ( event - > type ( ) = = QEvent : : KeyPress ) {
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( event ) ;
if ( keyEvent & & keyEvent - > key ( ) = = Qt : : Key_Space ) {
// Space pressed
QModelIndex currentIndex = ui . messagestreeView - > currentIndex ( ) ;
QModelIndex index = ui . messagestreeView - > model ( ) - > index ( currentIndex . row ( ) , COLUMN_UNREAD , currentIndex . parent ( ) ) ;
clicked ( index ) ;
return true ; // eat event
}
}
}
// pass the event on to the parent class
return MainPage : : eventFilter ( obj , event ) ;
}
2011-06-04 18:54:03 -04:00
void MessagesDialog : : fillQuickView ( )
2010-05-27 15:48:52 -04:00
{
2011-05-21 12:26:00 -04:00
MsgTagType tags ;
rsMsgs - > getMessageTagTypes ( tags ) ;
std : : map < uint32_t , std : : pair < std : : string , uint32_t > > : : iterator tag ;
2010-06-01 18:14:52 -04:00
2011-05-21 12:26:00 -04:00
// fill tags
2011-06-04 18:54:03 -04:00
inChange = true ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
// save current selection
2011-06-04 18:54:03 -04:00
QListWidgetItem * item = ui . quickViewWidget - > currentItem ( ) ;
int nSelectedType = 0 ;
uint32_t nSelectedId = 0 ;
2011-05-21 12:26:00 -04:00
if ( item ) {
2011-06-04 18:54:03 -04:00
nSelectedType = item - > data ( ROLE_QUICKVIEW_TYPE ) . toInt ( ) ;
nSelectedId = item - > data ( ROLE_QUICKVIEW_ID ) . toInt ( ) ;
2011-05-21 12:26:00 -04:00
}
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
QListWidgetItem * itemToSelect = NULL ;
QString text ;
2010-05-27 15:48:52 -04:00
2011-06-04 18:54:03 -04:00
ui . quickViewWidget - > clear ( ) ;
// add static items
item = new QListWidgetItem ( tr ( " Starred " ) , ui . quickViewWidget ) ;
item - > setIcon ( QIcon ( IMAGE_STAR_ON ) ) ;
item - > setData ( ROLE_QUICKVIEW_TYPE , QUICKVIEW_TYPE_STATIC ) ;
item - > setData ( ROLE_QUICKVIEW_ID , QUICKVIEW_STATIC_ID_STARRED ) ;
item - > setData ( ROLE_QUICKVIEW_TEXT , item - > text ( ) ) ; // for updateMessageSummaryList
if ( nSelectedType = = QUICKVIEW_TYPE_STATIC & & nSelectedId = = QUICKVIEW_STATIC_ID_STARRED ) {
itemToSelect = item ;
}
2011-05-21 12:26:00 -04:00
for ( tag = tags . types . begin ( ) ; tag ! = tags . types . end ( ) ; tag + + ) {
text = TagDefs : : name ( tag - > first , tag - > second . first ) ;
2010-05-27 15:48:52 -04:00
2011-06-04 18:54:03 -04:00
item = new QListWidgetItem ( text , ui . quickViewWidget ) ;
2011-05-21 12:26:00 -04:00
item - > setForeground ( QBrush ( QColor ( tag - > second . second ) ) ) ;
item - > setIcon ( QIcon ( " :/images/foldermail.png " ) ) ;
2011-06-04 18:54:03 -04:00
item - > setData ( ROLE_QUICKVIEW_TYPE , QUICKVIEW_TYPE_TAG ) ;
item - > setData ( ROLE_QUICKVIEW_ID , tag - > first ) ;
item - > setData ( ROLE_QUICKVIEW_TEXT , text ) ; // for updateMessageSummaryList
2010-05-27 15:48:52 -04:00
2011-06-04 18:54:03 -04:00
if ( nSelectedType = = QUICKVIEW_TYPE_TAG & & tag - > first = = nSelectedId ) {
2011-05-21 12:26:00 -04:00
itemToSelect = item ;
}
}
2010-06-01 18:14:52 -04:00
2011-05-21 12:26:00 -04:00
if ( itemToSelect ) {
2011-06-04 18:54:03 -04:00
ui . quickViewWidget - > setCurrentItem ( itemToSelect ) ;
2011-05-21 12:26:00 -04:00
}
2010-06-01 18:14:52 -04:00
2011-06-04 18:54:03 -04:00
inChange = false ;
2010-09-12 18:17:17 -04:00
2011-05-21 12:26:00 -04:00
updateMessageSummaryList ( ) ;
2010-05-27 15:48:52 -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
2011-05-23 19:45:31 -04:00
int MessagesDialog : : getSelectedMsgCount ( QList < int > * pRows , QList < int > * pRowsRead , QList < int > * pRowsUnread , QList < int > * pRowsStar )
2010-05-07 18:23:38 -04:00
{
2010-05-23 13:21:30 -04:00
if ( pRowsRead ) pRowsRead - > clear ( ) ;
if ( pRowsUnread ) pRowsUnread - > clear ( ) ;
2011-05-23 19:45:31 -04:00
if ( pRowsStar ) pRowsStar - > clear ( ) ;
2010-05-23 13:21:30 -04:00
2010-05-07 18:23:38 -04:00
//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 ) ;
2010-05-23 13:21:30 -04:00
2011-05-23 19:45:31 -04:00
if ( pRows | | pRowsRead | | pRowsUnread | | pRowsStar ) {
2010-05-23 13:21:30 -04:00
int mappedRow = proxyModel - > mapToSource ( * it ) . row ( ) ;
2010-05-27 15:48:52 -04:00
if ( pRows ) pRows - > append ( mappedRow ) ;
2010-08-08 18:58:10 -04:00
if ( MessagesModel - > item ( mappedRow , COLUMN_DATA ) - > data ( ROLE_UNREAD ) . toBool ( ) ) {
2010-05-23 13:21:30 -04:00
if ( pRowsUnread ) pRowsUnread - > append ( mappedRow ) ;
} else {
if ( pRowsRead ) pRowsRead - > append ( mappedRow ) ;
}
2011-05-23 19:45:31 -04:00
if ( pRowsStar ) {
if ( MessagesModel - > item ( mappedRow , COLUMN_DATA ) - > data ( ROLE_MSGFLAGS ) . toInt ( ) & RS_MSG_STAR ) {
pRowsStar - > append ( mappedRow ) ;
}
}
2010-05-23 13:21:30 -04:00
}
2010-05-07 18:23:38 -04:00
}
}
return rowList . size ( ) ;
}
2010-05-23 13:21:30 -04:00
bool MessagesDialog : : isMessageRead ( int nRow )
{
2011-05-23 19:45:31 -04:00
QStandardItem * item = MessagesModel - > item ( nRow , COLUMN_DATA ) ;
2010-08-08 18:58:10 -04:00
return ! item - > data ( ROLE_UNREAD ) . toBool ( ) ;
2010-05-23 13:21:30 -04:00
}
2011-05-23 19:45:31 -04:00
bool MessagesDialog : : hasMessageStar ( int nRow )
{
QStandardItem * item = MessagesModel - > item ( nRow , COLUMN_DATA ) ;
return item - > data ( ROLE_MSGFLAGS ) . toInt ( ) & RS_MSG_STAR ;
}
2011-08-12 10:06:29 -04:00
void MessagesDialog : : messageslistWidgetCostumPopupMenu ( QPoint /*point*/ )
2008-09-04 15:28:35 -04:00
{
2011-06-03 20:46:02 -04:00
std : : string cid ;
std : : string mid ;
MessageInfo msgInfo ;
if ( getCurrentMsg ( cid , mid ) ) {
rsMsgs - > getMessage ( mid , msgInfo ) ;
}
2008-09-04 15:28:35 -04:00
2010-05-23 13:21:30 -04:00
QList < int > RowsRead ;
QList < int > RowsUnread ;
2011-05-23 19:45:31 -04:00
QList < int > RowsStar ;
int nCount = getSelectedMsgCount ( NULL , & RowsRead , & RowsUnread , & RowsStar ) ;
2010-05-27 15:48:52 -04:00
2011-05-23 19:45:31 -04:00
/** Defines the actions for the context menu */
2010-06-14 14:16:32 -04:00
2011-06-03 20:46:02 -04:00
QMenu contextMnu ( this ) ;
QAction * action = contextMnu . addAction ( tr ( " Open in a new window " ) , this , SLOT ( openAsWindow ( ) ) ) ;
2011-05-23 19:45:31 -04:00
if ( nCount ! = 1 ) {
action - > setDisabled ( true ) ;
}
2011-06-03 20:46:02 -04:00
action = contextMnu . addAction ( tr ( " Open in a new tab " ) , this , SLOT ( openAsTab ( ) ) ) ;
2011-05-23 19:45:31 -04:00
if ( nCount ! = 1 ) {
action - > setDisabled ( true ) ;
}
2011-06-03 20:46:02 -04:00
contextMnu . addSeparator ( ) ;
2011-06-05 09:37:49 -04:00
contextMnu . addAction ( ui . actionReply ) ;
ui . actionReply - > setEnabled ( nCount = = 1 ) ;
contextMnu . addAction ( ui . actionReplyAll ) ;
ui . actionReplyAll - > setEnabled ( nCount = = 1 ) ;
contextMnu . addAction ( ui . actionForward ) ;
ui . actionForward - > setEnabled ( nCount = = 1 ) ;
2010-06-14 14:16:32 -04:00
contextMnu . addSeparator ( ) ;
2011-05-23 19:45:31 -04:00
action = contextMnu . addAction ( QIcon ( " :/images/message-mail-read.png " ) , tr ( " Mark as read " ) , this , SLOT ( markAsRead ( ) ) ) ;
2010-05-23 13:21:30 -04:00
if ( RowsUnread . size ( ) = = 0 ) {
2011-05-23 19:45:31 -04:00
action - > setDisabled ( true ) ;
2010-05-23 13:21:30 -04:00
}
2011-05-23 19:45:31 -04:00
action = contextMnu . addAction ( QIcon ( " :/images/message-mail.png " ) , tr ( " Mark as unread " ) , this , SLOT ( markAsUnread ( ) ) ) ;
2010-05-23 13:21:30 -04:00
if ( RowsRead . size ( ) = = 0 ) {
2011-05-23 19:45:31 -04:00
action - > setDisabled ( true ) ;
2010-05-23 13:21:30 -04:00
}
2011-05-23 19:45:31 -04:00
action = contextMnu . addAction ( tr ( " Add Star " ) ) ;
action - > setCheckable ( true ) ;
action - > setChecked ( RowsStar . size ( ) ) ;
connect ( action , SIGNAL ( triggered ( bool ) ) , this , SLOT ( markWithStar ( bool ) ) ) ;
2010-05-23 13:21:30 -04:00
contextMnu . addSeparator ( ) ;
2010-05-27 15:48:52 -04:00
// add tags
contextMnu . addMenu ( ui . tagButton - > menu ( ) ) ;
2011-06-03 20:46:02 -04:00
2010-05-27 15:48:52 -04:00
contextMnu . addSeparator ( ) ;
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
QString text ;
if ( ( msgInfo . msgflags & RS_MSG_BOXMASK ) = = RS_MSG_DRAFTBOX ) {
text = tr ( " Edit " ) ;
} else {
text = tr ( " Edit as new " ) ;
}
action = contextMnu . addAction ( text , this , SLOT ( editmessage ( ) ) ) ;
if ( nCount ! = 1 ) {
action - > setDisabled ( true ) ;
}
2011-05-23 19:45:31 -04:00
action = contextMnu . addAction ( QIcon ( IMAGE_MESSAGEREMOVE ) , ( nCount > 1 ) ? tr ( " Remove Messages " ) : tr ( " Remove Message " ) , this , SLOT ( removemessage ( ) ) ) ;
if ( nCount = = 0 ) {
action - > setDisabled ( true ) ;
2010-05-26 11:20:31 -04:00
}
2011-05-23 19:45:31 -04:00
int listrow = ui . listWidget - > currentRow ( ) ;
2010-05-28 10:42:54 -04:00
if ( listrow = = ROW_TRASHBOX ) {
2011-05-23 19:45:31 -04:00
action = contextMnu . addAction ( tr ( " Undelete " ) , this , SLOT ( undeletemessage ( ) ) ) ;
if ( nCount = = 0 ) {
action - > setDisabled ( true ) ;
2010-05-28 10:42:54 -04:00
}
}
2011-06-03 20:46:02 -04:00
contextMnu . addAction ( ui . actionSaveAs ) ;
2011-05-23 19:45:31 -04:00
contextMnu . addAction ( ui . actionPrintPreview ) ;
contextMnu . addAction ( ui . actionPrint ) ;
2010-05-26 11:20:31 -04:00
contextMnu . addSeparator ( ) ;
2011-05-23 19:45:31 -04:00
contextMnu . addAction ( QIcon ( IMAGE_MESSAGE ) , tr ( " New Message " ) , this , SLOT ( newmessage ( ) ) ) ;
2010-05-07 18:23:38 -04:00
2010-05-14 16:55:44 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2008-09-04 15:28:35 -04:00
}
2011-08-12 10:06:29 -04:00
void MessagesDialog : : folderlistWidgetCostumPopupMenu ( QPoint /*point*/ )
2010-10-29 16:57:23 -04:00
{
if ( ui . listWidget - > currentRow ( ) ! = ROW_TRASHBOX ) {
/* Context menu only neede for trash box */
return ;
}
QMenu contextMnu ( this ) ;
contextMnu . addAction ( tr ( " Empty trash " ) , this , SLOT ( emptyTrash ( ) ) ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
2007-11-14 22:18:48 -05:00
void MessagesDialog : : newmessage ( )
{
2010-11-02 17:11:11 -04:00
MessageComposer * nMsgDialog = MessageComposer : : newMsg ( ) ;
if ( nMsgDialog = = NULL ) {
return ;
}
2007-11-14 22:18:48 -05:00
nMsgDialog - > show ( ) ;
2007-11-18 18:35:53 -05:00
nMsgDialog - > activateWindow ( ) ;
2007-11-14 22:18:48 -05:00
/* window will destroy itself! */
}
2011-06-03 20:46:02 -04:00
void MessagesDialog : : openAsWindow ( )
2010-06-14 14:16:32 -04:00
{
std : : string cid ;
std : : string mid ;
if ( ! getCurrentMsg ( cid , mid ) )
return ;
2011-06-03 20:46:02 -04:00
MessageWidget * msgWidget = MessageWidget : : openMsg ( mid , true ) ;
if ( msgWidget = = NULL ) {
2010-06-14 14:16:32 -04:00
return ;
}
2011-06-03 20:46:02 -04:00
msgWidget - > activateWindow ( ) ;
2010-05-23 13:21:30 -04:00
/* window will destroy itself! */
2007-11-14 22:18:48 -05:00
}
2011-06-03 20:46:02 -04:00
void MessagesDialog : : openAsTab ( )
2009-02-09 08:24:05 -05:00
{
2010-05-23 13:21:30 -04:00
std : : string cid ;
std : : string mid ;
if ( ! getCurrentMsg ( cid , mid ) )
return ;
2011-06-03 20:46:02 -04:00
MessageWidget * msgWidget = MessageWidget : : openMsg ( mid , false ) ;
if ( msgWidget = = NULL ) {
2010-11-02 17:11:11 -04:00
return ;
2010-05-23 13:21:30 -04:00
}
2010-05-02 20:09:55 -04:00
2011-06-03 20:46:02 -04:00
ui . tabWidget - > addTab ( msgWidget , msgWidget - > subject ( true ) ) ;
ui . tabWidget - > setCurrentWidget ( msgWidget ) ;
2010-05-23 13:21:30 -04:00
/* window will destroy itself! */
2009-02-09 08:24:05 -05:00
}
2011-06-03 20:46:02 -04:00
void MessagesDialog : : editmessage ( )
2008-11-25 20:19:09 -05:00
{
2010-05-23 13:21:30 -04:00
std : : string cid ;
std : : string mid ;
if ( ! getCurrentMsg ( cid , mid ) )
return ;
2011-06-03 20:46:02 -04:00
MessageComposer * msgComposer = MessageComposer : : newMsg ( mid ) ;
if ( msgComposer = = NULL ) {
2010-11-02 17:11:11 -04:00
return ;
2010-05-23 13:21:30 -04:00
}
2010-05-02 20:09:55 -04:00
2011-06-03 20:46:02 -04:00
msgComposer - > show ( ) ;
msgComposer - > activateWindow ( ) ;
2010-05-23 13:21:30 -04:00
/* window will destroy itself! */
2008-11-25 20:19:09 -05:00
}
2009-02-22 12:36:39 -05:00
void MessagesDialog : : changeBox ( int )
2007-11-14 22:18:48 -05:00
{
2011-06-04 18:54:03 -04:00
if ( inChange ) {
2010-06-01 18:14:52 -04:00
// already in change method
return ;
}
2011-06-04 18:54:03 -04:00
inChange = true ;
2010-06-01 18:14:52 -04:00
2010-05-23 13:21:30 -04:00
MessagesModel - > removeRows ( 0 , MessagesModel - > rowCount ( ) ) ;
2010-05-07 18:23:38 -04:00
2011-06-04 18:54:03 -04:00
ui . quickViewWidget - > setCurrentItem ( NULL ) ;
2010-06-01 18:14:52 -04:00
m_eListMode = LIST_BOX ;
2010-05-23 13:21:30 -04:00
insertMessages ( ) ;
insertMsgTxtAndFiles ( ) ;
2010-06-01 18:14:52 -04:00
2011-06-04 18:54:03 -04:00
inChange = false ;
2010-05-23 13:21:30 -04:00
}
2011-06-04 18:54:03 -04:00
void MessagesDialog : : changeQuickView ( int newrow )
2010-06-01 18:14:52 -04:00
{
2011-06-04 18:54:03 -04:00
Q_UNUSED ( newrow ) ;
if ( inChange ) {
2010-06-01 18:14:52 -04:00
// already in change method
return ;
}
2011-06-04 18:54:03 -04:00
inChange = true ;
2010-06-01 18:14:52 -04:00
MessagesModel - > removeRows ( 0 , MessagesModel - > rowCount ( ) ) ;
ui . listWidget - > setCurrentItem ( NULL ) ;
2011-06-04 18:54:03 -04:00
m_eListMode = LIST_QUICKVIEW ;
2010-06-01 18:14:52 -04:00
insertMessages ( ) ;
insertMsgTxtAndFiles ( ) ;
2011-06-04 18:54:03 -04:00
inChange = false ;
2010-06-01 18:14:52 -04:00
}
2010-08-22 18:12:26 -04:00
void MessagesDialog : : messagesTagsChanged ( )
{
if ( m_nLockUpdate ) {
return ;
}
2011-06-04 18:54:03 -04:00
fillQuickView ( ) ;
2010-08-22 18:12:26 -04:00
insertMessages ( ) ;
}
2011-05-23 19:45:31 -04:00
static void InitIconAndFont ( QStandardItem * item [ COLUMN_COUNT ] )
2010-05-23 13:21:30 -04:00
{
2011-05-23 19:45:31 -04:00
int msgFlags = item [ COLUMN_DATA ] - > data ( ROLE_MSGFLAGS ) . toInt ( ) ;
2010-05-23 13:21:30 -04:00
// show the real "New" state
2011-05-23 19:45:31 -04:00
if ( msgFlags & RS_MSG_NEW ) {
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-state-new.png " ) ) ;
2010-05-23 13:21:30 -04:00
} else {
2011-05-23 19:45:31 -04:00
if ( msgFlags & RS_MSG_UNREAD_BY_USER ) {
if ( ( msgFlags & ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) = = RS_MSG_REPLIED ) {
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-replied.png " ) ) ;
} else if ( ( msgFlags & ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) = = RS_MSG_FORWARDED ) {
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-forwarded.png " ) ) ;
} else if ( ( msgFlags & ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) = = ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) {
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-replied-forw.png " ) ) ;
2010-11-02 17:11:11 -04:00
} else {
2011-05-23 19:45:31 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail.png " ) ) ;
2010-11-02 17:11:11 -04:00
}
2010-05-23 13:21:30 -04:00
} else {
2011-05-23 19:45:31 -04:00
if ( ( msgFlags & ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) = = RS_MSG_REPLIED ) {
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-replied-read.png " ) ) ;
} else if ( ( msgFlags & ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) = = RS_MSG_FORWARDED ) {
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-forwarded-read.png " ) ) ;
} else if ( ( msgFlags & ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) = = ( RS_MSG_REPLIED | RS_MSG_FORWARDED ) ) {
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-replied-forw-read.png " ) ) ;
2010-11-02 17:11:11 -04:00
} else {
2011-05-23 19:45:31 -04:00
item [ COLUMN_SUBJECT ] - > setIcon ( QIcon ( " :/images/message-mail-read.png " ) ) ;
2010-11-02 17:11:11 -04:00
}
2010-05-23 13:21:30 -04:00
}
}
2011-05-23 19:45:31 -04:00
if ( msgFlags & RS_MSG_STAR ) {
item [ COLUMN_STAR ] - > setIcon ( QIcon ( IMAGE_STAR_ON ) ) ;
item [ COLUMN_STAR ] - > setText ( " 1 " ) ;
2011-08-02 17:07:42 -04:00
item [ COLUMN_STAR ] - > setData ( 1 , ROLE_SORT ) ;
2011-05-23 19:45:31 -04:00
} else {
item [ COLUMN_STAR ] - > setIcon ( QIcon ( IMAGE_STAR_OFF ) ) ;
item [ COLUMN_STAR ] - > setText ( " 0 " ) ;
2011-08-02 17:07:42 -04:00
item [ COLUMN_STAR ] - > setData ( 0 , ROLE_SORT ) ;
2011-05-23 19:45:31 -04:00
}
bool isNew = msgFlags & ( RS_MSG_NEW | RS_MSG_UNREAD_BY_USER ) ;
2010-05-23 13:21:30 -04:00
2010-08-08 18:58:10 -04:00
// set icon
2011-05-23 19:45:31 -04:00
if ( isNew ) {
item [ COLUMN_UNREAD ] - > setIcon ( QIcon ( " :/images/message-state-unread.png " ) ) ;
item [ COLUMN_UNREAD ] - > setText ( " 1 " ) ;
2011-08-02 17:07:42 -04:00
item [ COLUMN_UNREAD ] - > setData ( 1 , ROLE_SORT ) ;
2010-05-23 13:21:30 -04:00
} else {
2011-05-23 19:45:31 -04:00
item [ COLUMN_UNREAD ] - > setIcon ( QIcon ( " :/images/message-state-read.png " ) ) ;
item [ COLUMN_UNREAD ] - > setText ( " 0 " ) ;
2011-08-02 17:07:42 -04:00
item [ COLUMN_UNREAD ] - > setData ( 0 , ROLE_SORT ) ;
2010-05-23 13:21:30 -04:00
}
// set font
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
2011-05-23 19:45:31 -04:00
QFont qf = item [ i ] - > font ( ) ;
qf . setBold ( isNew ) ;
item [ i ] - > setFont ( qf ) ;
2010-05-23 13:21:30 -04:00
}
2010-08-08 18:58:10 -04:00
2011-05-23 19:45:31 -04:00
item [ COLUMN_DATA ] - > setData ( isNew , ROLE_UNREAD ) ;
2007-11-14 22:18:48 -05:00
}
void MessagesDialog : : insertMessages ( )
{
2010-06-03 18:12:07 -04:00
if ( m_nLockUpdate ) {
return ;
}
2010-05-23 13:21:30 -04:00
std : : cerr < < " MessagesDialog::insertMessages called " ;
std : : list < MsgInfoSummary > msgList ;
std : : list < MsgInfoSummary > : : const_iterator it ;
MessageInfo msgInfo ;
bool bGotInfo ;
QString text ;
rsMsgs - > getMessageSummaries ( msgList ) ;
std : : cerr < < " MessagesDialog::insertMessages() " < < std : : endl ;
int nFilterColumn = FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ;
/* check the mode we are in */
unsigned int msgbox = 0 ;
2011-05-24 09:15:43 -04:00
bool isTrash = false ;
bool doFill = true ;
2011-06-04 18:54:03 -04:00
int quickViewType = 0 ;
uint32_t quickViewId = 0 ;
2011-05-24 09:15:43 -04:00
QString boxText ;
QIcon boxIcon ;
2011-06-05 16:19:10 -04:00
QString placeholderText ;
2010-06-01 18:14:52 -04:00
switch ( m_eListMode ) {
case LIST_NOTHING :
2011-05-24 09:15:43 -04:00
doFill = false ;
2010-05-23 13:21:30 -04:00
break ;
2010-06-01 18:14:52 -04:00
case LIST_BOX :
{
2011-05-24 09:15:43 -04:00
QListWidgetItem * item = ui . listWidget - > currentItem ( ) ;
if ( item ) {
boxIcon = item - > icon ( ) ;
}
2010-06-01 18:14:52 -04:00
int listrow = ui . listWidget - > currentRow ( ) ;
switch ( listrow ) {
case ROW_INBOX :
msgbox = RS_MSG_INBOX ;
2011-05-24 09:15:43 -04:00
boxText = tr ( " Inbox " ) ;
2010-06-01 18:14:52 -04:00
break ;
case ROW_OUTBOX :
msgbox = RS_MSG_OUTBOX ;
2011-05-24 09:15:43 -04:00
boxText = tr ( " Outbox " ) ;
2010-06-01 18:14:52 -04:00
break ;
case ROW_DRAFTBOX :
msgbox = RS_MSG_DRAFTBOX ;
2011-05-24 09:15:43 -04:00
boxText = tr ( " Drafts " ) ;
2010-06-01 18:14:52 -04:00
break ;
case ROW_SENTBOX :
msgbox = RS_MSG_SENTBOX ;
2011-05-24 09:15:43 -04:00
boxText = tr ( " Sent " ) ;
2010-06-01 18:14:52 -04:00
break ;
case ROW_TRASHBOX :
2011-05-24 09:15:43 -04:00
isTrash = true ;
boxText = tr ( " Trash " ) ;
2010-06-01 18:14:52 -04:00
break ;
default :
2011-05-24 09:15:43 -04:00
doFill = false ;
2010-06-01 18:14:52 -04:00
}
}
2010-05-23 13:21:30 -04:00
break ;
2010-06-01 18:14:52 -04:00
2011-06-04 18:54:03 -04:00
case LIST_QUICKVIEW :
2010-06-01 18:14:52 -04:00
{
2011-06-04 18:54:03 -04:00
QListWidgetItem * item = ui . quickViewWidget - > currentItem ( ) ;
2011-05-24 09:15:43 -04:00
if ( item ) {
2011-06-04 18:54:03 -04:00
quickViewType = item - > data ( ROLE_QUICKVIEW_TYPE ) . toInt ( ) ;
quickViewId = item - > data ( ROLE_QUICKVIEW_ID ) . toInt ( ) ;
2011-05-24 09:15:43 -04:00
boxText = item - > text ( ) ;
boxIcon = item - > icon ( ) ;
2011-06-04 18:54:03 -04:00
2011-06-05 16:19:10 -04:00
switch ( quickViewType ) {
case QUICKVIEW_TYPE_NOTHING :
2011-06-04 18:54:03 -04:00
doFill = false ;
2011-06-05 16:19:10 -04:00
break ;
case QUICKVIEW_TYPE_STATIC :
switch ( quickViewId ) {
case QUICKVIEW_STATIC_ID_STARRED :
placeholderText = tr ( " No starred messages available. Stars let you give messages a special status to make them easier to find. To star a message, click on the light grey star beside any message. " ) ;
break ;
}
break ;
case QUICKVIEW_TYPE_TAG :
break ;
2011-06-04 18:54:03 -04:00
}
2010-06-01 18:14:52 -04:00
} else {
2011-05-24 09:15:43 -04:00
doFill = false ;
2010-06-01 18:14:52 -04:00
}
}
2010-05-23 13:21:30 -04:00
break ;
2010-06-01 18:14:52 -04:00
2010-05-23 13:21:30 -04:00
default :
2011-05-24 09:15:43 -04:00
doFill = false ;
2010-05-23 13:21:30 -04:00
}
2011-05-24 09:15:43 -04:00
ui . tabWidget - > setTabText ( 0 , boxText ) ;
ui . tabWidget - > setTabIcon ( 0 , boxIcon ) ;
2011-06-05 16:19:10 -04:00
ui . messagestreeView - > setPlaceholderText ( placeholderText ) ;
2011-05-24 09:15:43 -04:00
2010-05-23 13:21:30 -04:00
if ( msgbox = = RS_MSG_INBOX ) {
MessagesModel - > setHeaderData ( COLUMN_FROM , Qt : : Horizontal , tr ( " From " ) ) ;
2011-05-16 16:28:07 -04:00
MessagesModel - > setHeaderData ( COLUMN_FROM , Qt : : Horizontal , tr ( " Click to sort by from " ) , Qt : : ToolTipRole ) ;
2010-05-23 13:21:30 -04:00
} else {
MessagesModel - > setHeaderData ( COLUMN_FROM , Qt : : Horizontal , tr ( " To " ) ) ;
2011-05-16 16:28:07 -04:00
MessagesModel - > setHeaderData ( COLUMN_FROM , Qt : : Horizontal , tr ( " Click to sort by to " ) , Qt : : ToolTipRole ) ;
2010-05-23 13:21:30 -04:00
}
2011-05-24 09:15:43 -04:00
if ( doFill ) {
2010-08-22 18:12:26 -04:00
MsgTagType Tags ;
rsMsgs - > getMessageTagTypes ( Tags ) ;
2010-05-27 15:48:52 -04:00
2010-06-01 18:14:52 -04:00
/* search messages */
std : : list < MsgInfoSummary > msgToShow ;
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; it + + ) {
if ( m_eListMode = = LIST_BOX ) {
2011-05-24 09:15:43 -04:00
if ( isTrash ) {
2010-05-28 10:42:54 -04:00
if ( ( it - > msgflags & RS_MSG_TRASH ) = = 0 ) {
continue ;
}
} else {
if ( it - > msgflags & RS_MSG_TRASH ) {
continue ;
}
if ( ( it - > msgflags & RS_MSG_BOXMASK ) ! = msgbox ) {
continue ;
}
2010-05-23 13:21:30 -04:00
}
2011-06-04 18:54:03 -04:00
} else if ( m_eListMode = = LIST_QUICKVIEW & & quickViewType = = QUICKVIEW_TYPE_TAG ) {
2010-08-22 18:12:26 -04:00
MsgTagInfo tagInfo ;
rsMsgs - > getMessageTag ( it - > msgId , tagInfo ) ;
2011-06-04 18:54:03 -04:00
if ( std : : find ( tagInfo . tagIds . begin ( ) , tagInfo . tagIds . end ( ) , quickViewId ) = = tagInfo . tagIds . end ( ) ) {
continue ;
}
} else if ( m_eListMode = = LIST_QUICKVIEW & & quickViewType = = QUICKVIEW_TYPE_STATIC ) {
if ( ( it - > msgflags & RS_MSG_STAR ) = = 0 ) {
2010-06-01 18:14:52 -04:00
continue ;
}
} else {
continue ;
}
2010-05-23 13:21:30 -04:00
2010-06-01 18:14:52 -04:00
msgToShow . push_back ( * it ) ;
}
/* remove old items */
int nRowCount = MessagesModel - > rowCount ( ) ;
int nRow = 0 ;
for ( nRow = 0 ; nRow < nRowCount ; ) {
2010-06-25 08:17:46 -04:00
std : : string msgIdFromRow = MessagesModel - > item ( nRow , COLUMN_DATA ) - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2010-06-01 18:14:52 -04:00
for ( it = msgToShow . begin ( ) ; it ! = msgToShow . end ( ) ; it + + ) {
if ( it - > msgId = = msgIdFromRow ) {
2010-05-23 13:21:30 -04:00
break ;
}
}
2010-06-01 18:14:52 -04:00
if ( it = = msgToShow . end ( ) ) {
2010-05-23 13:21:30 -04:00
MessagesModel - > removeRow ( nRow ) ;
nRowCount = MessagesModel - > rowCount ( ) ;
} else {
nRow + + ;
}
}
2010-06-01 18:14:52 -04:00
for ( it = msgToShow . begin ( ) ; it ! = msgToShow . end ( ) ; it + + )
2010-05-23 13:21:30 -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 .
*
*/
bGotInfo = false ;
msgInfo = MessageInfo ( ) ; // clear
// search exisisting items
nRowCount = MessagesModel - > rowCount ( ) ;
for ( nRow = 0 ; nRow < nRowCount ; nRow + + ) {
2010-06-25 08:17:46 -04:00
if ( it - > msgId = = MessagesModel - > item ( nRow , COLUMN_DATA ) - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ) {
2010-05-23 13:21:30 -04:00
break ;
}
}
/* make a widget per friend */
QStandardItem * item [ COLUMN_COUNT ] ;
bool bInsert = false ;
if ( nRow < nRowCount ) {
2010-05-27 15:48:52 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
2010-05-23 13:21:30 -04:00
item [ i ] = MessagesModel - > item ( nRow , i ) ;
}
} else {
2010-05-27 15:48:52 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
2010-05-23 13:21:30 -04:00
item [ i ] = new QStandardItem ( ) ;
}
bInsert = true ;
}
//set this false if you want to expand on double click
2010-05-27 15:48:52 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
2010-05-23 13:21:30 -04:00
item [ i ] - > setEditable ( false ) ;
}
/* 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
*/
QString dateString ;
// Date First.... (for sorting)
{
QDateTime qdatetime ;
qdatetime . setTime_t ( it - > ts ) ;
// add string to all data
dateString = qdatetime . toString ( " _yyyyMMdd_hhmmss " ) ;
//if the mail is on same date show only time.
if ( qdatetime . daysTo ( QDateTime : : currentDateTime ( ) ) = = 0 )
{
QTime qtime = qdatetime . time ( ) ;
QVariant varTime ( qtime ) ;
item [ COLUMN_DATE ] - > setData ( varTime , Qt : : DisplayRole ) ;
}
else
{
QVariant varDateTime ( qdatetime ) ;
item [ COLUMN_DATE ] - > setData ( varDateTime , Qt : : DisplayRole ) ;
}
// for sorting
2010-06-25 08:17:46 -04:00
item [ COLUMN_DATE ] - > setData ( qdatetime , ROLE_SORT ) ;
2010-05-23 13:21:30 -04:00
}
// From ....
{
2010-05-25 05:32:14 -04:00
if ( msgbox = = RS_MSG_INBOX | | msgbox = = RS_MSG_OUTBOX ) {
2011-07-17 19:07:29 -04:00
text = QString : : fromUtf8 ( rsPeers - > getPeerName ( it - > srcId ) . c_str ( ) ) ;
2010-05-23 13:21:30 -04:00
} else {
if ( bGotInfo | | rsMsgs - > getMessage ( it - > msgId , msgInfo ) ) {
bGotInfo = true ;
text . clear ( ) ;
std : : list < std : : string > : : const_iterator pit ;
for ( pit = msgInfo . msgto . begin ( ) ; pit ! = msgInfo . msgto . end ( ) ; pit + + )
{
if ( text . isEmpty ( ) = = false ) {
2010-05-23 14:31:40 -04:00
text + = " , " ;
2010-05-23 13:21:30 -04:00
}
2010-09-28 16:33:34 -04:00
std : : string peerName = rsPeers - > getPeerName ( * pit ) ;
if ( peerName . empty ( ) ) {
text + = PeerDefs : : rsid ( " " , * pit ) ;
2010-05-23 13:21:30 -04:00
} else {
2011-07-17 19:07:29 -04:00
text + = QString : : fromUtf8 ( peerName . c_str ( ) ) ;
2010-05-23 13:21:30 -04:00
}
2010-05-07 18:23:38 -04:00
}
2010-05-23 13:21:30 -04:00
} else {
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg " < < std : : endl ;
}
}
item [ COLUMN_FROM ] - > setText ( text ) ;
2010-06-25 08:17:46 -04:00
item [ COLUMN_FROM ] - > setData ( text + dateString , ROLE_SORT ) ;
2010-05-23 13:21:30 -04:00
}
// Subject
text = QString : : fromStdWString ( it - > title ) ;
item [ COLUMN_SUBJECT ] - > setText ( text ) ;
2010-06-25 08:17:46 -04:00
item [ COLUMN_SUBJECT ] - > setData ( text + dateString , ROLE_SORT ) ;
2010-05-23 13:21:30 -04:00
// internal data
2010-05-27 15:48:52 -04:00
QString msgId = QString : : fromStdString ( it - > msgId ) ;
2010-06-25 08:17:46 -04:00
item [ COLUMN_DATA ] - > setData ( QString : : fromStdString ( it - > srcId ) , ROLE_SRCID ) ;
item [ COLUMN_DATA ] - > setData ( msgId , ROLE_MSGID ) ;
2010-11-02 17:11:11 -04:00
item [ COLUMN_DATA ] - > setData ( it - > msgflags , ROLE_MSGFLAGS ) ;
2010-05-23 13:21:30 -04:00
// Init icon and font
2010-11-02 17:11:11 -04:00
InitIconAndFont ( item ) ;
2010-05-23 13:21:30 -04:00
2010-05-27 15:48:52 -04:00
// Tags
2010-08-22 18:12:26 -04:00
MsgTagInfo tagInfo ;
rsMsgs - > getMessageTag ( it - > msgId , tagInfo ) ;
2010-05-27 15:48:52 -04:00
text . clear ( ) ;
2010-08-22 18:12:26 -04:00
// build tag names
std : : map < uint32_t , std : : pair < std : : string , uint32_t > > : : iterator Tag ;
for ( std : : list < uint32_t > : : iterator tagId = tagInfo . tagIds . begin ( ) ; tagId ! = tagInfo . tagIds . end ( ) ; tagId + + ) {
2010-05-27 15:48:52 -04:00
if ( text . isEmpty ( ) = = false ) {
text + = " , " ;
}
2010-08-22 18:12:26 -04:00
Tag = Tags . types . find ( * tagId ) ;
if ( Tag ! = Tags . types . end ( ) ) {
2010-09-12 18:17:17 -04:00
text + = TagDefs : : name ( Tag - > first , Tag - > second . first ) ;
2010-08-22 18:12:26 -04:00
} else {
// clean tagId
rsMsgs - > setMessageTag ( it - > msgId , * tagId , false ) ;
}
2010-05-27 15:48:52 -04:00
}
item [ COLUMN_TAGS ] - > setText ( text ) ;
2011-08-02 17:07:42 -04:00
item [ COLUMN_TAGS ] - > setData ( text , ROLE_SORT ) ;
2010-05-27 15:48:52 -04:00
// set color
QBrush Brush ; // standard
2010-08-22 18:12:26 -04:00
if ( tagInfo . tagIds . size ( ) ) {
Tag = Tags . types . find ( tagInfo . tagIds . front ( ) ) ;
if ( Tag ! = Tags . types . end ( ) ) {
Brush = QBrush ( Tag - > second . second ) ;
} else {
// clean tagId
rsMsgs - > setMessageTag ( it - > msgId , tagInfo . tagIds . front ( ) , false ) ;
}
2010-05-27 15:48:52 -04:00
}
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
item [ i ] - > setForeground ( Brush ) ;
}
2010-05-23 13:21:30 -04:00
// No of Files.
{
2011-06-03 20:46:02 -04:00
item [ COLUMN_ATTACHEMENTS ] - > setText ( QString : : number ( it - > count ) ) ;
2010-06-25 08:17:46 -04:00
item [ COLUMN_ATTACHEMENTS ] - > setData ( item [ COLUMN_ATTACHEMENTS ] - > text ( ) + dateString , ROLE_SORT ) ;
2010-06-19 14:06:04 -04:00
item [ COLUMN_ATTACHEMENTS ] - > setTextAlignment ( Qt : : AlignHCenter ) ;
2010-05-23 13:21:30 -04:00
}
if ( nFilterColumn = = COLUMN_CONTENT ) {
// need content for filter
if ( bGotInfo | | rsMsgs - > getMessage ( it - > msgId , msgInfo ) ) {
bGotInfo = true ;
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 ( " " ) ;
}
}
if ( bInsert ) {
/* add to the list */
QList < QStandardItem * > itemList ;
2010-05-27 15:48:52 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + ) {
2010-05-23 13:21:30 -04:00
itemList . append ( item [ i ] ) ;
}
MessagesModel - > appendRow ( itemList ) ;
}
}
} else {
MessagesModel - > removeRows ( 0 , MessagesModel - > rowCount ( ) ) ;
}
2007-11-14 22:18:48 -05:00
2010-05-23 13:21:30 -04:00
ui . messagestreeView - > showColumn ( COLUMN_ATTACHEMENTS ) ;
ui . messagestreeView - > showColumn ( COLUMN_SUBJECT ) ;
2010-08-08 18:58:10 -04:00
ui . messagestreeView - > showColumn ( COLUMN_UNREAD ) ;
2010-05-23 13:21:30 -04:00
ui . messagestreeView - > showColumn ( COLUMN_FROM ) ;
ui . messagestreeView - > showColumn ( COLUMN_DATE ) ;
2010-05-27 15:48:52 -04:00
ui . messagestreeView - > showColumn ( COLUMN_TAGS ) ;
2010-05-23 13:21:30 -04:00
ui . messagestreeView - > hideColumn ( COLUMN_CONTENT ) ;
2010-06-01 18:14:52 -04:00
2010-05-23 13:21:30 -04:00
updateMessageSummaryList ( ) ;
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 )
{
2010-05-23 13:21:30 -04:00
if ( index . isValid ( ) = = false ) {
return ;
}
2011-05-23 19:45:31 -04:00
switch ( index . column ( ) ) {
case COLUMN_UNREAD :
{
int mappedRow = proxyModel - > mapToSource ( index ) . row ( ) ;
2010-05-23 13:21:30 -04:00
2011-05-23 19:45:31 -04:00
QList < int > Rows ;
Rows . append ( mappedRow ) ;
setMsgAsReadUnread ( Rows , ! isMessageRead ( mappedRow ) ) ;
insertMsgTxtAndFiles ( index , false ) ;
updateMessageSummaryList ( ) ;
return ;
}
case COLUMN_STAR :
{
int mappedRow = proxyModel - > mapToSource ( index ) . row ( ) ;
QList < int > Rows ;
Rows . append ( mappedRow ) ;
setMsgStar ( Rows , ! hasMessageStar ( mappedRow ) ) ;
return ;
}
2010-05-23 13:21:30 -04:00
}
2010-04-27 17:46:28 -04:00
timer - > stop ( ) ;
timerIndex = index ;
// show current message directly
updateCurrentMessage ( ) ;
}
2010-05-25 05:32:14 -04:00
// double click in messagestreeView
void MessagesDialog : : doubleClicked ( const QModelIndex & index )
{
2010-06-14 14:16:32 -04:00
/* activate row */
clicked ( index ) ;
2010-05-25 05:32:14 -04:00
2011-06-03 20:46:02 -04:00
std : : string cid ;
std : : string mid ;
if ( ! getCurrentMsg ( cid , mid ) )
return ;
MessageInfo msgInfo ;
if ( ! rsMsgs - > getMessage ( mid , msgInfo ) ) {
return ;
}
if ( ( msgInfo . msgflags & RS_MSG_BOXMASK ) = = RS_MSG_DRAFTBOX ) {
editmessage ( ) ;
return ;
}
2010-06-14 14:16:32 -04:00
/* edit message */
2011-06-03 20:46:02 -04:00
switch ( Settings - > getMsgOpen ( ) ) {
case RshareSettings : : MSG_OPEN_TAB :
openAsTab ( ) ;
break ;
case RshareSettings : : MSG_OPEN_WINDOW :
openAsWindow ( ) ;
break ;
}
2010-05-25 05:32:14 -04:00
}
2010-04-27 17:46:28 -04:00
// show current message directly
void MessagesDialog : : updateCurrentMessage ( )
{
2010-05-23 13:21:30 -04:00
timer - > stop ( ) ;
insertMsgTxtAndFiles ( timerIndex ) ;
2007-11-14 22:18:48 -05:00
}
2011-05-23 19:45:31 -04:00
void MessagesDialog : : setMsgAsReadUnread ( const QList < int > & Rows , bool read )
2009-02-22 12:36:39 -05:00
{
2010-08-09 08:16:21 -04:00
LockUpdate Lock ( this , false ) ;
2010-05-23 13:21:30 -04:00
for ( int nRow = 0 ; nRow < Rows . size ( ) ; nRow + + ) {
QStandardItem * item [ COLUMN_COUNT ] ;
for ( int nCol = 0 ; nCol < COLUMN_COUNT ; nCol + + )
{
item [ nCol ] = MessagesModel - > item ( Rows [ nRow ] , nCol ) ;
}
2010-08-22 18:12:26 -04:00
std : : string mid = item [ COLUMN_DATA ] - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2010-05-23 13:21:30 -04:00
2011-05-23 19:45:31 -04:00
if ( rsMsgs - > MessageRead ( mid , ! read ) ) {
int msgFlag = item [ COLUMN_DATA ] - > data ( ROLE_MSGFLAGS ) . toInt ( ) ;
msgFlag & = ~ RS_MSG_NEW ;
2010-11-02 17:11:11 -04:00
2011-05-23 19:45:31 -04:00
if ( read ) {
msgFlag & = ~ RS_MSG_UNREAD_BY_USER ;
2010-11-02 17:11:11 -04:00
} else {
2011-05-23 19:45:31 -04:00
msgFlag | = RS_MSG_UNREAD_BY_USER ;
2010-11-02 17:11:11 -04:00
}
2011-05-23 19:45:31 -04:00
item [ COLUMN_DATA ] - > setData ( msgFlag , ROLE_MSGFLAGS ) ;
2010-11-02 17:11:11 -04:00
InitIconAndFont ( item ) ;
2010-05-23 13:21:30 -04:00
}
}
2010-08-09 08:16:21 -04:00
// LockUpdate
2009-02-22 12:36:39 -05:00
}
2007-11-14 22:18:48 -05:00
2010-05-23 13:21:30 -04:00
void MessagesDialog : : markAsRead ( )
2007-11-14 22:18:48 -05:00
{
2010-05-23 13:21:30 -04:00
QList < int > RowsUnread ;
2011-05-23 19:45:31 -04:00
getSelectedMsgCount ( NULL , NULL , & RowsUnread , NULL ) ;
2010-05-23 13:21:30 -04:00
setMsgAsReadUnread ( RowsUnread , true ) ;
updateMessageSummaryList ( ) ;
}
void MessagesDialog : : markAsUnread ( )
{
QList < int > RowsRead ;
2011-05-23 19:45:31 -04:00
getSelectedMsgCount ( NULL , & RowsRead , NULL , NULL ) ;
2010-05-23 13:21:30 -04:00
setMsgAsReadUnread ( RowsRead , false ) ;
updateMessageSummaryList ( ) ;
}
2011-05-23 19:45:31 -04:00
void MessagesDialog : : markWithStar ( bool checked )
{
QList < int > Rows ;
getSelectedMsgCount ( & Rows , NULL , NULL , NULL ) ;
setMsgStar ( Rows , checked ) ;
2011-06-04 18:54:03 -04:00
}
2011-05-23 19:45:31 -04:00
void MessagesDialog : : setMsgStar ( const QList < int > & Rows , bool star )
{
LockUpdate Lock ( this , false ) ;
for ( int nRow = 0 ; nRow < Rows . size ( ) ; nRow + + ) {
QStandardItem * item [ COLUMN_COUNT ] ;
for ( int nCol = 0 ; nCol < COLUMN_COUNT ; nCol + + )
{
item [ nCol ] = MessagesModel - > item ( Rows [ nRow ] , nCol ) ;
}
std : : string mid = item [ COLUMN_DATA ] - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
if ( rsMsgs - > MessageStar ( mid , star ) ) {
int msgFlag = item [ COLUMN_DATA ] - > data ( ROLE_MSGFLAGS ) . toInt ( ) ;
msgFlag & = ~ RS_MSG_STAR ;
if ( star ) {
msgFlag | = RS_MSG_STAR ;
} else {
msgFlag & = ~ RS_MSG_STAR ;
}
item [ COLUMN_DATA ] - > setData ( msgFlag , ROLE_MSGFLAGS ) ;
InitIconAndFont ( item ) ;
2011-06-04 18:54:03 -04:00
Lock . setUpdate ( true ) ;
2011-05-23 19:45:31 -04:00
}
}
// LockUpdate
}
2010-05-23 13:21:30 -04:00
void MessagesDialog : : insertMsgTxtAndFiles ( QModelIndex Index , bool bSetToRead )
{
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() " < < std : : endl ;
/* get its Ids */
std : : string cid ;
std : : string mid ;
QModelIndex currentIndex = proxyModel - > mapToSource ( Index ) ;
2011-06-03 20:46:02 -04:00
if ( currentIndex . isValid ( ) = = false ) {
2010-10-31 15:37:05 -04:00
mCurrMsgId . clear ( ) ;
2011-06-03 20:46:02 -04:00
msgWidget - > fill ( mCurrMsgId ) ;
updateInterface ( ) ;
2010-05-23 13:21:30 -04:00
return ;
}
2010-10-31 15:37:05 -04:00
QStandardItem * item = MessagesModel - > item ( currentIndex . row ( ) , COLUMN_DATA ) ;
if ( item = = NULL ) {
2011-06-03 20:46:02 -04:00
mCurrMsgId . clear ( ) ;
msgWidget - > fill ( mCurrMsgId ) ;
updateInterface ( ) ;
2010-10-31 15:37:05 -04:00
return ;
2010-05-23 13:21:30 -04:00
}
2010-10-31 15:37:05 -04:00
mid = item - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2010-05-23 13:21:30 -04:00
2011-05-23 19:45:31 -04:00
int nCount = getSelectedMsgCount ( NULL , NULL , NULL , NULL ) ;
2010-05-23 13:21:30 -04:00
if ( nCount = = 1 ) {
2011-06-03 20:46:02 -04:00
ui . actionSaveAs - > setEnabled ( true ) ;
2010-05-23 13:21:30 -04:00
ui . actionPrintPreview - > setEnabled ( true ) ;
ui . actionPrint - > setEnabled ( true ) ;
} else {
2011-06-03 20:46:02 -04:00
ui . actionSaveAs - > setDisabled ( true ) ;
2010-05-23 13:21:30 -04:00
ui . actionPrintPreview - > setDisabled ( true ) ;
ui . actionPrint - > setDisabled ( true ) ;
}
if ( mCurrMsgId = = mid ) {
// message doesn't changed
return ;
}
/* Save the Data.... for later */
2011-06-03 20:46:02 -04:00
mCurrMsgId = mid ;
2010-05-23 13:21:30 -04:00
MessageInfo msgInfo ;
2011-06-03 20:46:02 -04:00
if ( ! rsMsgs - > getMessage ( mid , msgInfo ) ) {
2010-05-23 13:21:30 -04:00
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg " < < std : : endl ;
return ;
}
QList < int > Rows ;
Rows . append ( currentIndex . row ( ) ) ;
bool bSetToReadOnActive = Settings - > getMsgSetToReadOnActivate ( ) ;
if ( msgInfo . msgflags & RS_MSG_NEW ) {
2010-08-22 18:12:26 -04:00
// set always to read or unread
2010-05-23 13:21:30 -04:00
if ( bSetToReadOnActive = = false | | bSetToRead = = false ) {
// set locally to unread
setMsgAsReadUnread ( Rows , false ) ;
2010-08-22 18:12:26 -04:00
} else {
setMsgAsReadUnread ( Rows , true ) ;
2010-05-23 13:21:30 -04:00
}
updateMessageSummaryList ( ) ;
} else {
2010-08-22 18:12:26 -04:00
if ( ( msgInfo . msgflags & RS_MSG_UNREAD_BY_USER ) & & bSetToRead & & bSetToReadOnActive ) {
2010-05-23 13:21:30 -04:00
// set to read
setMsgAsReadUnread ( Rows , true ) ;
updateMessageSummaryList ( ) ;
}
}
2011-06-03 20:46:02 -04:00
msgWidget - > fill ( mCurrMsgId ) ;
updateInterface ( ) ;
2007-11-14 22:18:48 -05:00
}
bool MessagesDialog : : getCurrentMsg ( std : : string & cid , std : : string & mid )
{
2010-05-23 13:21:30 -04:00
QModelIndex currentIndex = ui . messagestreeView - > currentIndex ( ) ;
currentIndex = proxyModel - > mapToSource ( currentIndex ) ;
int rowSelected = - 1 ;
/* get its Ids */
if ( currentIndex . isValid ( ) = = false )
{
//If no message is selected. assume first message is selected.
if ( MessagesModel - > rowCount ( ) = = 0 )
{
return false ;
}
else
{
rowSelected = 0 ;
}
}
else
{
rowSelected = currentIndex . row ( ) ;
}
2010-06-25 08:17:46 -04:00
QStandardItem * item = MessagesModel - > item ( rowSelected , COLUMN_DATA ) ;
if ( item = = NULL ) {
return false ;
}
cid = item - > data ( ROLE_SRCID ) . toString ( ) . toStdString ( ) ;
mid = item - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2010-05-23 13:21:30 -04:00
return true ;
2010-02-13 13:49:56 -05:00
}
2007-11-14 22:18:48 -05:00
void MessagesDialog : : removemessage ( )
{
2010-06-03 18:12:07 -04:00
LockUpdate Lock ( this , true ) ;
2010-05-23 13:21:30 -04:00
QList < QModelIndex > selectedIndexList = ui . messagestreeView - > selectionModel ( ) - > selectedIndexes ( ) ;
QList < int > rowList ;
QModelIndex selectedIndex ;
for ( QList < QModelIndex > : : iterator it = selectedIndexList . begin ( ) ; it ! = selectedIndexList . end ( ) ; it + + ) {
selectedIndex = proxyModel - > mapToSource ( * it ) ;
int row = selectedIndex . row ( ) ;
2011-06-03 20:46:02 -04:00
if ( rowList . contains ( row ) = = false ) {
2010-05-23 13:21:30 -04:00
rowList . append ( row ) ;
}
}
2010-05-28 10:42:54 -04:00
bool bDelete = false ;
2010-06-03 18:12:07 -04:00
int listrow = ui . listWidget - > currentRow ( ) ;
2010-05-28 10:42:54 -04:00
if ( listrow = = ROW_TRASHBOX ) {
bDelete = true ;
} else {
if ( QApplication : : keyboardModifiers ( ) & Qt : : ShiftModifier ) {
bDelete = true ;
}
}
2010-06-03 18:12:07 -04:00
for ( QList < int > : : const_iterator it1 = rowList . begin ( ) ; it1 ! = rowList . end ( ) ; it1 + + ) {
2010-06-25 08:17:46 -04:00
QStandardItem * pItem = MessagesModel - > item ( ( * it1 ) , COLUMN_DATA ) ;
2010-06-03 18:12:07 -04:00
if ( pItem ) {
2010-06-25 08:17:46 -04:00
QString mid = pItem - > data ( ROLE_MSGID ) . toString ( ) ;
2011-06-03 20:46:02 -04:00
// close tab showing this message
// closeTab(mid.toStdString());
2010-06-03 18:12:07 -04:00
if ( bDelete ) {
rsMsgs - > MessageDelete ( mid . toStdString ( ) ) ;
} else {
rsMsgs - > MessageToTrash ( mid . toStdString ( ) , true ) ;
}
2010-05-28 10:42:54 -04:00
}
}
2010-05-23 13:21:30 -04:00
2010-06-03 18:12:07 -04:00
// LockUpdate -> insertMessages();
2010-05-28 10:42:54 -04:00
}
2010-05-27 15:48:52 -04:00
2010-05-28 10:42:54 -04:00
void MessagesDialog : : undeletemessage ( )
{
2010-08-22 18:12:26 -04:00
LockUpdate Lock ( this , true ) ;
2010-06-03 18:12:07 -04:00
2010-05-28 10:42:54 -04:00
QList < int > Rows ;
2011-05-23 19:45:31 -04:00
getSelectedMsgCount ( & Rows , NULL , NULL , NULL ) ;
2010-05-28 10:42:54 -04:00
for ( int nRow = 0 ; nRow < Rows . size ( ) ; nRow + + ) {
2010-06-25 08:17:46 -04:00
QString mid = MessagesModel - > item ( Rows [ nRow ] , COLUMN_DATA ) - > data ( ROLE_MSGID ) . toString ( ) ;
2010-05-28 10:42:54 -04:00
rsMsgs - > MessageToTrash ( mid . toStdString ( ) , false ) ;
2010-05-23 13:21:30 -04:00
}
2010-06-03 18:12:07 -04:00
// LockUpdate -> insertMessages();
2007-11-14 22:18:48 -05:00
}
2010-05-27 15:48:52 -04:00
void MessagesDialog : : setToolbarButtonStyle ( Qt : : ToolButtonStyle style )
2010-01-21 20:05:45 -05:00
{
2010-05-27 15:48:52 -04:00
ui . newmessageButton - > setToolButtonStyle ( style ) ;
ui . removemessageButton - > setToolButtonStyle ( style ) ;
ui . replymessageButton - > setToolButtonStyle ( style ) ;
ui . replyallmessageButton - > setToolButtonStyle ( style ) ;
ui . forwardmessageButton - > setToolButtonStyle ( style ) ;
ui . tagButton - > setToolButtonStyle ( style ) ;
ui . printbutton - > setToolButtonStyle ( style ) ;
ui . viewtoolButton - > setToolButtonStyle ( style ) ;
}
2010-05-20 17:53:27 -04:00
2011-06-03 20:46:02 -04:00
void MessagesDialog : : buttonStyle ( )
2010-01-25 07:44:12 -05:00
{
2011-06-03 20:46:02 -04:00
setToolbarButtonStyle ( ( Qt : : ToolButtonStyle ) dynamic_cast < QAction * > ( sender ( ) ) - > data ( ) . toInt ( ) ) ;
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 ) ;
2010-05-19 15:44:06 -04:00
QString text = ui . filterPatternLineEdit - > text ( ) ;
if ( text . isEmpty ( ) )
{
2010-05-23 13:21:30 -04:00
ui . clearButton - > hide ( ) ;
2010-05-19 15:44:06 -04:00
}
else
{
2010-05-23 13:21:30 -04:00
ui . clearButton - > show ( ) ;
2010-05-19 15:44:06 -04:00
}
2010-02-13 13:49:56 -05:00
}
void MessagesDialog : : filterColumnChanged ( )
{
2010-05-20 17:53:27 -04:00
if ( m_bProcessSettings ) {
return ;
}
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
2010-05-20 17:53:27 -04:00
Settings - > setValueToGroup ( " MessageDialog " , " filterColumn " , nFilterColumn ) ;
2010-02-13 13:49:56 -05:00
}
void MessagesDialog : : updateMessageSummaryList ( )
{
2010-05-23 13:21:30 -04:00
unsigned int newInboxCount = 0 ;
unsigned int newOutboxCount = 0 ;
unsigned int newDraftCount = 0 ;
unsigned int newSentboxCount = 0 ;
unsigned int inboxCount = 0 ;
2010-05-28 10:42:54 -04:00
unsigned int trashboxCount = 0 ;
2011-06-04 18:54:03 -04:00
unsigned int starredCount = 0 ;
2010-05-23 13:21:30 -04:00
/* calculating the new messages */
// rsMsgs->getMessageCount (&inboxCount, &newInboxCount, &newOutboxCount, &newDraftCount, &newSentboxCount);
std : : list < MsgInfoSummary > msgList ;
std : : list < MsgInfoSummary > : : const_iterator it ;
rsMsgs - > getMessageSummaries ( msgList ) ;
2010-06-01 18:14:52 -04:00
QMap < int , int > tagCount ;
2010-08-22 18:12:26 -04:00
/* calculating the new messages */
2010-05-23 13:21:30 -04:00
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; it + + ) {
2010-06-01 18:14:52 -04:00
/* calcluate tag count */
2010-08-22 18:12:26 -04:00
MsgTagInfo tagInfo ;
rsMsgs - > getMessageTag ( it - > msgId , tagInfo ) ;
for ( std : : list < uint32_t > : : iterator tagId = tagInfo . tagIds . begin ( ) ; tagId ! = tagInfo . tagIds . end ( ) ; tagId + + ) {
2010-06-01 18:14:52 -04:00
int nCount = tagCount [ * tagId ] ;
nCount + + ;
tagCount [ * tagId ] = nCount ;
}
2011-06-04 18:54:03 -04:00
if ( it - > msgflags & RS_MSG_STAR ) {
starredCount + + ;
}
2010-06-01 18:14:52 -04:00
/* calculate box */
2010-05-28 10:42:54 -04:00
if ( it - > msgflags & RS_MSG_TRASH ) {
trashboxCount + + ;
continue ;
}
2010-05-23 13:21:30 -04:00
switch ( it - > msgflags & RS_MSG_BOXMASK ) {
case RS_MSG_INBOX :
inboxCount + + ;
2010-08-22 18:12:26 -04:00
if ( it - > msgflags & ( RS_MSG_NEW | RS_MSG_UNREAD_BY_USER ) ) {
2010-05-23 13:21:30 -04:00
newInboxCount + + ;
}
break ;
case RS_MSG_OUTBOX :
newOutboxCount + + ;
break ;
case RS_MSG_DRAFTBOX :
newDraftCount + + ;
break ;
case RS_MSG_SENTBOX :
newSentboxCount + + ;
break ;
}
}
2010-06-12 11:11:42 -04:00
int listrow = ui . listWidget - > currentRow ( ) ;
QString textTotal ;
switch ( listrow )
{
case ROW_INBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( inboxCount ) ;
ui . total_label - > setText ( textTotal ) ;
break ;
case ROW_OUTBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( newOutboxCount ) ;
ui . total_label - > setText ( textTotal ) ;
break ;
case ROW_DRAFTBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( newDraftCount ) ;
ui . total_label - > setText ( textTotal ) ;
break ;
case ROW_SENTBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( newSentboxCount ) ;
ui . total_label - > setText ( textTotal ) ;
break ;
case ROW_TRASHBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( trashboxCount ) ;
ui . total_label - > setText ( textTotal ) ;
break ;
}
2010-05-23 13:21:30 -04:00
QString textItem ;
/*updating the labels in leftcolumn*/
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
2010-05-28 10:42:54 -04:00
QListWidgetItem * item = ui . listWidget - > item ( ROW_INBOX ) ;
2010-05-23 13:21:30 -04:00
if ( newInboxCount ! = 0 )
{
2010-06-01 18:14:52 -04:00
textItem = tr ( " Inbox " ) + " ( " + QString : : number ( newInboxCount ) + " ) " ;
2010-05-23 13:21:30 -04:00
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( true ) ;
item - > setFont ( qf ) ;
item - > setIcon ( QIcon ( " :/images/folder-inbox-new.png " ) ) ;
item - > setForeground ( QBrush ( QColor ( 49 , 106 , 197 ) ) ) ;
}
else
{
textItem = tr ( " Inbox " ) ;
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( false ) ;
item - > setFont ( qf ) ;
item - > setIcon ( QIcon ( " :/images/folder-inbox.png " ) ) ;
item - > setForeground ( QBrush ( QColor ( 0 , 0 , 0 ) ) ) ;
}
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
2010-05-28 10:42:54 -04:00
item = ui . listWidget - > item ( ROW_OUTBOX ) ;
2010-05-23 13:21:30 -04:00
if ( newOutboxCount ! = 0 )
{
2010-06-01 18:14:52 -04:00
textItem = tr ( " Outbox " ) + " ( " + QString : : number ( newOutboxCount ) + " ) " ;
2010-05-23 13:21:30 -04: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 ) ;
}
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
2010-05-28 10:42:54 -04:00
item = ui . listWidget - > item ( ROW_DRAFTBOX ) ;
2010-05-23 13:21:30 -04:00
if ( newDraftCount ! = 0 )
{
2010-06-01 18:14:52 -04:00
textItem = tr ( " Drafts " ) + " ( " + QString : : number ( newDraftCount ) + " ) " ;
2010-05-23 13:21:30 -04:00
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( true ) ;
item - > setFont ( qf ) ;
}
else
{
2010-05-28 13:29:21 -04:00
textItem = tr ( " Drafts " ) ;
2010-05-23 13:21:30 -04:00
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( false ) ;
item - > setFont ( qf ) ;
}
2010-05-28 10:42:54 -04:00
item = ui . listWidget - > item ( ROW_TRASHBOX ) ;
if ( trashboxCount ! = 0 )
{
2010-06-01 18:14:52 -04:00
textItem = tr ( " Trash " ) + " ( " + QString : : number ( trashboxCount ) + " ) " ;
2010-05-28 10:42:54 -04:00
item - > setText ( textItem ) ;
}
else
{
textItem = tr ( " Trash " ) ;
item - > setText ( textItem ) ;
}
2010-06-01 18:14:52 -04:00
/* set tag counts */
2011-06-04 18:54:03 -04:00
int rowCount = ui . quickViewWidget - > count ( ) ;
for ( int row = 0 ; row < rowCount ; row + + ) {
QListWidgetItem * item = ui . quickViewWidget - > item ( row ) ;
switch ( item - > data ( ROLE_QUICKVIEW_TYPE ) . toInt ( ) ) {
case QUICKVIEW_TYPE_TAG :
{
int count = tagCount [ item - > data ( ROLE_QUICKVIEW_ID ) . toInt ( ) ] ;
QString text = item - > data ( ROLE_QUICKVIEW_TEXT ) . toString ( ) ;
if ( count ) {
text + = " ( " + QString : : number ( count ) + " ) " ;
}
item - > setText ( text ) ;
}
break ;
case QUICKVIEW_TYPE_STATIC :
{
QString text = item - > data ( ROLE_QUICKVIEW_TEXT ) . toString ( ) ;
switch ( item - > data ( ROLE_QUICKVIEW_ID ) . toInt ( ) ) {
case QUICKVIEW_STATIC_ID_STARRED :
text + = " ( " + QString : : number ( starredCount ) + " ) " ;
break ;
}
2010-06-01 18:14:52 -04:00
2011-06-04 18:54:03 -04:00
item - > setText ( text ) ;
}
break ;
}
2010-06-01 18:14:52 -04:00
}
2010-02-13 13:49:56 -05:00
}
2010-02-14 07:29:50 -05:00
/** clear Filter **/
void MessagesDialog : : clearFilter ( )
{
2010-05-23 13:21:30 -04:00
ui . filterPatternLineEdit - > clear ( ) ;
ui . filterPatternLineEdit - > setFocus ( ) ;
2010-02-14 07:29:50 -05:00
}
2010-05-27 15:48:52 -04:00
void MessagesDialog : : tagAboutToShow ( )
{
2011-05-21 12:26:00 -04:00
TagsMenu * menu = dynamic_cast < TagsMenu * > ( ui . tagButton - > menu ( ) ) ;
if ( menu = = NULL ) {
return ;
}
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
// activate actions from the first selected row
MsgTagInfo tagInfo ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
QList < int > rows ;
2011-05-23 19:45:31 -04:00
getSelectedMsgCount ( & rows , NULL , NULL , NULL ) ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
if ( rows . size ( ) ) {
QStandardItem * item = MessagesModel - > item ( rows [ 0 ] , COLUMN_DATA ) ;
std : : string msgId = item - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
rsMsgs - > getMessageTag ( msgId , tagInfo ) ;
}
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
menu - > activateActions ( tagInfo . tagIds ) ;
2010-05-27 15:48:52 -04:00
}
2011-05-21 12:26:00 -04:00
void MessagesDialog : : tagRemoveAll ( )
2010-05-27 15:48:52 -04:00
{
2011-05-21 12:26:00 -04:00
LockUpdate Lock ( this , false ) ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
QList < int > rows ;
2011-05-23 19:45:31 -04:00
getSelectedMsgCount ( & rows , NULL , NULL , NULL ) ;
2011-05-21 12:26:00 -04:00
for ( int row = 0 ; row < rows . size ( ) ; row + + ) {
QStandardItem * item = MessagesModel - > item ( rows [ row ] , COLUMN_DATA ) ;
std : : string msgId = item - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
rsMsgs - > setMessageTag ( msgId , 0 , false ) ;
Lock . setUpdate ( true ) ;
}
2010-08-22 18:12:26 -04:00
2011-05-21 12:26:00 -04:00
// LockUpdate -> insertMessages();
}
2010-08-22 18:12:26 -04:00
2011-05-21 12:26:00 -04:00
void MessagesDialog : : tagSet ( int tagId , bool set )
{
if ( tagId = = 0 ) {
return ;
}
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
LockUpdate Lock ( this , false ) ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
QList < int > rows ;
2011-05-23 19:45:31 -04:00
getSelectedMsgCount ( & rows , NULL , NULL , NULL ) ;
2011-05-21 12:26:00 -04:00
for ( int row = 0 ; row < rows . size ( ) ; row + + ) {
QStandardItem * item = MessagesModel - > item ( rows [ row ] , COLUMN_DATA ) ;
std : : string msgId = item - > data ( ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2010-05-27 15:48:52 -04:00
2011-05-21 12:26:00 -04:00
if ( rsMsgs - > setMessageTag ( msgId , tagId , set ) ) {
Lock . setUpdate ( true ) ;
}
}
2010-08-22 18:12:26 -04:00
2011-05-21 12:26:00 -04:00
// LockUpdate -> insertMessages();
2010-05-27 15:48:52 -04:00
}
2010-09-27 20:03:12 -04:00
2010-10-29 16:57:23 -04:00
void MessagesDialog : : emptyTrash ( )
{
LockUpdate Lock ( this , true ) ;
std : : list < MsgInfoSummary > msgList ;
rsMsgs - > getMessageSummaries ( msgList ) ;
std : : list < MsgInfoSummary > : : const_iterator it ;
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; it + + ) {
if ( it - > msgflags & RS_MSG_TRASH ) {
rsMsgs - > MessageDelete ( it - > msgId ) ;
}
}
// LockUpdate -> insertMessages();
}
2011-06-03 20:46:02 -04:00
2011-08-12 10:06:29 -04:00
void MessagesDialog : : tabChanged ( int /*tab*/ )
2011-06-03 20:46:02 -04:00
{
connectActions ( ) ;
updateInterface ( ) ;
}
void MessagesDialog : : tabCloseRequested ( int tab )
{
if ( tab = = 0 ) {
return ;
}
QWidget * widget = ui . tabWidget - > widget ( tab ) ;
if ( widget ) {
widget - > deleteLater ( ) ;
}
}
void MessagesDialog : : closeTab ( const std : : string & msgId )
{
QList < MessageWidget * > msgWidgets ;
for ( int tab = 1 ; tab < ui . tabWidget - > count ( ) ; tab + + ) {
MessageWidget * msgWidget = dynamic_cast < MessageWidget * > ( ui . tabWidget - > widget ( tab ) ) ;
if ( msgWidget & & msgWidget - > msgId ( ) = = msgId ) {
msgWidgets . append ( msgWidget ) ;
}
}
qDeleteAll ( msgWidgets ) ;
}
void MessagesDialog : : connectActions ( )
{
int tab = ui . tabWidget - > currentIndex ( ) ;
MessageWidget * msg ;
if ( tab = = 0 ) {
msg = msgWidget ;
} else {
msg = dynamic_cast < MessageWidget * > ( ui . tabWidget - > widget ( tab ) ) ;
}
ui . replymessageButton - > disconnect ( ) ;
ui . replyallmessageButton - > disconnect ( ) ;
ui . forwardmessageButton - > disconnect ( ) ;
ui . printbutton - > disconnect ( ) ;
ui . actionPrint - > disconnect ( ) ;
ui . actionPrintPreview - > disconnect ( ) ;
ui . actionSaveAs - > disconnect ( ) ;
ui . removemessageButton - > disconnect ( ) ;
2011-06-05 09:37:49 -04:00
ui . actionReply - > disconnect ( ) ;
ui . actionReplyAll - > disconnect ( ) ;
ui . actionForward - > disconnect ( ) ;
if ( msgWidget ) {
// connect actions
msg - > connectAction ( MessageWidget : : ACTION_REPLY , ui . actionReply ) ;
msg - > connectAction ( MessageWidget : : ACTION_REPLY_ALL , ui . actionReplyAll ) ;
msg - > connectAction ( MessageWidget : : ACTION_FORWARD , ui . actionForward ) ;
}
2011-06-03 20:46:02 -04:00
if ( msg ) {
if ( tab = = 0 ) {
// connect with own slot to remove multiple messages
connect ( ui . removemessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
} else {
msg - > connectAction ( MessageWidget : : ACTION_REMOVE , ui . removemessageButton ) ;
}
msg - > connectAction ( MessageWidget : : ACTION_REPLY , ui . replymessageButton ) ;
msg - > connectAction ( MessageWidget : : ACTION_REPLY_ALL , ui . replyallmessageButton ) ;
msg - > connectAction ( MessageWidget : : ACTION_FORWARD , ui . forwardmessageButton ) ;
msg - > connectAction ( MessageWidget : : ACTION_PRINT , ui . printbutton ) ;
msg - > connectAction ( MessageWidget : : ACTION_PRINT , ui . actionPrint ) ;
msg - > connectAction ( MessageWidget : : ACTION_PRINT_PREVIEW , ui . actionPrintPreview ) ;
msg - > connectAction ( MessageWidget : : ACTION_SAVE_AS , ui . actionSaveAs ) ;
}
}
void MessagesDialog : : updateInterface ( )
{
int count = 0 ;
int tab = ui . tabWidget - > currentIndex ( ) ;
if ( tab = = 0 ) {
count = getSelectedMsgCount ( NULL , NULL , NULL , NULL ) ;
} else {
MessageWidget * msg = dynamic_cast < MessageWidget * > ( ui . tabWidget - > widget ( tab ) ) ;
if ( msg & & msg - > msgId ( ) . empty ( ) = = false ) {
count = 1 ;
}
}
ui . replymessageButton - > setEnabled ( count = = 1 ) ;
ui . replyallmessageButton - > setEnabled ( count = = 1 ) ;
ui . forwardmessageButton - > setEnabled ( count = = 1 ) ;
ui . printbutton - > setEnabled ( count = = 1 ) ;
ui . actionPrint - > setEnabled ( count = = 1 ) ;
ui . actionPrintPreview - > setEnabled ( count = = 1 ) ;
ui . actionSaveAs - > setEnabled ( count = = 1 ) ;
ui . removemessageButton - > setEnabled ( count > = 1 ) ;
ui . tagButton - > setEnabled ( count > = 1 ) ;
}