2018-12-25 15:34:59 -05:00
/*******************************************************************************
* gui / MessagesDialog . cpp *
* *
* Copyright ( c ) 2006 Crypton < retroshare . project @ gmail . com > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 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 Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-09-04 15:28:35 -04:00
2016-11-25 16:14:08 -05:00
# include <QDateTime>
# include <QKeyEvent>
# include <QMessageBox>
2010-07-23 14:52:58 -04:00
# include <QStandardItemModel>
# include <QShortcut>
# include <QTimer>
2009-11-28 09:34:15 -05:00
2008-09-04 15:28:35 -04:00
# include "MessagesDialog.h"
2016-11-25 16:14:08 -05:00
# include "notifyqt.h"
# include "common/TagDefs.h"
# include "common/PeerDefs.h"
# include "common/RSElidedItemDelegate.h"
# include "gxs/GxsIdTreeWidgetItem.h"
# include "gxs/GxsIdDetails.h"
2019-01-03 16:20:00 -05:00
# include "gui/Identity/IdDialog.h"
# include "gui/MainWindow.h"
2010-05-23 15:13:41 -04:00
# include "msgs/MessageComposer.h"
2016-11-25 16:14:08 -05:00
# include "msgs/MessageInterface.h"
# include "msgs/MessageUserNotify.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"
2019-02-08 09:41:20 -05:00
# include "msgs/MessageModel.h"
2010-07-23 14:52:58 -04:00
# include "settings/rsharesettings.h"
2016-11-25 16:14:08 -05:00
2012-11-15 16:35:37 -05:00
# include "util/DateTime.h"
2013-08-02 19:00:36 -04:00
# include "util/RsProtectedTimer.h"
2013-10-19 09:25:06 -04:00
# include "util/QtVersion.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 */
2014-10-09 18:04:12 -04: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"
2012-05-05 18:20:05 -04:00
# define IMAGE_SYSTEM ": / images / user / user_request16.png"
2019-01-03 16:20:00 -05:00
# define IMAGE_DECRYPTMESSAGE ": / images / decrypt-mail.png"
# define IMAGE_AUTHOR_INFO ": / images / info16.png"
2011-05-23 19:45:31 -04:00
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
2019-02-26 04:46:32 -05:00
//#define COLUMN_SIGNATURE 5
# define COLUMN_DATE 5
# define COLUMN_CONTENT 6
# define COLUMN_TAGS 7
# define COLUMN_COUNT 8
2010-06-25 08:17:46 -04:00
# define COLUMN_DATA 0 // column for storing the userdata like msgid and srcid
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
2012-05-01 05:18:55 -04:00
# define QUICKVIEW_STATIC_ID_SYSTEM 2
2011-06-04 18:54:03 -04:00
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 )
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2010-06-03 18:12:07 -04:00
m_pDialog = pDialog ;
m_bUpdate = bUpdate ;
2014-10-21 18:33:02 -04:00
+ + m_pDialog - > lockUpdate ;
2019-02-08 09:41:20 -05:00
# endif
2010-06-03 18:12:07 -04:00
}
MessagesDialog : : LockUpdate : : ~ LockUpdate ( )
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2012-05-01 05:18:55 -04:00
if ( - - m_pDialog - > lockUpdate < 0 )
m_pDialog - > lockUpdate = 0 ;
2010-06-03 18:12:07 -04:00
2012-05-01 05:18:55 -04:00
if ( m_bUpdate & & m_pDialog - > lockUpdate = = 0 ) {
2010-06-03 18:12:07 -04:00
m_pDialog - > insertMessages ( ) ;
}
2019-02-08 09:41:20 -05:00
# endif
2010-06-03 18:12:07 -04:00
}
2010-08-22 18:12:26 -04:00
void MessagesDialog : : LockUpdate : : setUpdate ( bool bUpdate )
{
m_bUpdate = bUpdate ;
}
2019-02-08 09:41:20 -05:00
class MessageSortFilterProxyModel : public QSortFilterProxyModel
{
public :
MessageSortFilterProxyModel ( const QHeaderView * header , QObject * parent = NULL ) : QSortFilterProxyModel ( parent ) , m_header ( header ) { }
bool lessThan ( const QModelIndex & left , const QModelIndex & right ) const override
{
return left . data ( RsMessageModel : : SortRole ) < right . data ( RsMessageModel : : SortRole ) ;
}
bool filterAcceptsRow ( int source_row , const QModelIndex & source_parent ) const override
{
return sourceModel ( ) - > index ( source_row , 0 , source_parent ) . data ( RsMessageModel : : FilterRole ) . toString ( ) = = RsMessageModel : : FilterString ;
}
private :
const QHeaderView * m_header ;
} ;
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 ) ;
2012-05-01 05:18:55 -04:00
inProcessSettings = false ;
2011-06-04 18:54:03 -04:00
inChange = false ;
2012-05-01 05:18:55 -04:00
lockUpdate = 0 ;
2010-05-23 13:21:30 -04:00
2015-06-09 18:57:01 -04:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( messagesChanged ( ) ) , this , SLOT ( insertMessages ( ) ) ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( messagesTagsChanged ( ) ) , this , SLOT ( messagesTagsChanged ( ) ) ) ;
2019-02-26 05:29:10 -05:00
connect ( ui . messageTreeWidget , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( messageTreeWidgetCustomPopupMenu ( const QPoint & ) ) ) ;
2013-05-04 18:03:48 -04:00
connect ( ui . listWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( folderlistWidgetCustomPopupMenu ( QPoint ) ) ) ;
2019-02-26 08:09:49 -05:00
connect ( ui . messageTreeWidget , SIGNAL ( clicked ( const QModelIndex & ) ) , this , SLOT ( clicked ( const QModelIndex & ) ) ) ;
connect ( ui . messageTreeWidget , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( doubleClicked ( const QModelIndex & ) ) ) ;
2014-10-09 18:04:12 -04:00
connect ( ui . messageTreeWidget , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( currentItemChanged ( QTreeWidgetItem * ) ) ) ;
connect ( ui . messageTreeWidget - > selectionModel ( ) , SIGNAL ( currentChanged ( QModelIndex , QModelIndex ) ) , this , SLOT ( currentChanged ( const QModelIndex & ) ) ) ;
2011-06-03 20:46:02 -04:00
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
2012-04-05 17:03:03 -04:00
connect ( ui . filterLineEdit , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( filterChanged ( QString ) ) ) ;
2012-10-29 06:59:26 -04:00
connect ( ui . filterLineEdit , SIGNAL ( filterChanged ( int ) ) , this , SLOT ( filterColumnChanged ( int ) ) ) ;
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
2012-05-01 05:18:55 -04:00
listMode = LIST_NOTHING ;
2010-06-01 18:14:52 -04:00
2019-02-08 09:41:20 -05:00
mMessageModel = new RsMessageModel ( this ) ;
mMessageProxyModel = new MessageSortFilterProxyModel ( ui . messageTreeWidget - > header ( ) , this ) ;
mMessageProxyModel - > setSourceModel ( mMessageModel ) ;
mMessageProxyModel - > setSortRole ( RsMessageModel : : SortRole ) ;
ui . messageTreeWidget - > setModel ( mMessageProxyModel ) ;
2019-02-26 04:46:32 -05:00
changeBox ( RsMessageModel : : BOX_INBOX ) ;
2019-02-10 09:13:39 -05:00
2019-02-08 09:41:20 -05:00
mMessageProxyModel - > setFilterRole ( RsMessageModel : : FilterRole ) ;
mMessageProxyModel - > setFilterRegExp ( QRegExp ( QString ( RsMessageModel : : FilterString ) ) ) ;
ui . messageTreeWidget - > setSortingEnabled ( true ) ;
//ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_DISTRIBUTION,new DistributionItemDelegate()) ;
ui . messageTreeWidget - > setItemDelegateForColumn ( RsMessageModel : : COLUMN_THREAD_AUTHOR , new GxsIdTreeItemDelegate ( ) ) ;
//ui.messageTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_READ,new ReadStatusItemDelegate()) ;
# ifdef TO_REMOVE
2010-05-23 13:21:30 -04:00
// Set the QStandardItemModel
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > setColumnCount ( COLUMN_COUNT ) ;
QTreeWidgetItem * headerItem = ui . messageTreeWidget - > headerItem ( ) ;
headerItem - > setText ( COLUMN_ATTACHEMENTS , " " ) ;
headerItem - > setIcon ( COLUMN_ATTACHEMENTS , QIcon ( " :/images/attachment.png " ) ) ;
headerItem - > setText ( COLUMN_SUBJECT , tr ( " Subject " ) ) ;
headerItem - > setText ( COLUMN_UNREAD , " " ) ;
headerItem - > setIcon ( COLUMN_UNREAD , QIcon ( " :/images/message-state-header.png " ) ) ;
headerItem - > setText ( COLUMN_FROM , tr ( " From " ) ) ;
headerItem - > setText ( COLUMN_SIGNATURE , " " ) ;
headerItem - > setIcon ( COLUMN_SIGNATURE , QIcon ( " :/images/signature.png " ) ) ;
headerItem - > setText ( COLUMN_DATE , tr ( " Date " ) ) ;
headerItem - > setText ( COLUMN_TAGS , tr ( " Tags " ) ) ;
headerItem - > setText ( COLUMN_CONTENT , tr ( " Content " ) ) ;
headerItem - > setText ( COLUMN_STAR , " " ) ;
headerItem - > setIcon ( COLUMN_STAR , QIcon ( IMAGE_STAR_ON ) ) ;
headerItem - > setToolTip ( COLUMN_ATTACHEMENTS , tr ( " Click to sort by attachments " ) ) ;
headerItem - > setToolTip ( COLUMN_SUBJECT , tr ( " Click to sort by subject " ) ) ;
headerItem - > setToolTip ( COLUMN_UNREAD , tr ( " Click to sort by read " ) ) ;
headerItem - > setToolTip ( COLUMN_FROM , tr ( " Click to sort by from " ) ) ;
headerItem - > setToolTip ( COLUMN_SIGNATURE , tr ( " Click to sort by signature " ) ) ;
headerItem - > setToolTip ( COLUMN_DATE , tr ( " Click to sort by date " ) ) ;
headerItem - > setToolTip ( COLUMN_TAGS , tr ( " Click to sort by tags " ) ) ;
headerItem - > setToolTip ( COLUMN_STAR , tr ( " Click to sort by star " ) ) ;
2019-02-08 09:41:20 -05:00
# endif
2014-10-09 18:04:12 -04:00
mMessageCompareRole = new RSTreeWidgetItemCompareRole ;
2019-02-26 08:09:49 -05:00
mMessageCompareRole - > setRole ( COLUMN_SUBJECT , RsMessageModel : : SortRole ) ;
mMessageCompareRole - > setRole ( COLUMN_UNREAD , RsMessageModel : : SortRole ) ;
mMessageCompareRole - > setRole ( COLUMN_FROM , RsMessageModel : : SortRole ) ;
mMessageCompareRole - > setRole ( COLUMN_DATE , RsMessageModel : : SortRole ) ;
mMessageCompareRole - > setRole ( COLUMN_TAGS , RsMessageModel : : SortRole ) ;
2019-02-26 05:29:10 -05:00
mMessageCompareRole - > setRole ( COLUMN_ATTACHEMENTS , RsMessageModel : : SortRole ) ;
2019-02-26 08:09:49 -05:00
mMessageCompareRole - > setRole ( COLUMN_STAR , RsMessageModel : : SortRole ) ;
2010-05-23 13:21:30 -04:00
2016-11-25 16:14:08 -05:00
RSElidedItemDelegate * itemDelegate = new RSElidedItemDelegate ( this ) ;
2010-11-09 18:56:02 -05:00
itemDelegate - > setSpacing ( QSize ( 0 , 2 ) ) ;
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > setItemDelegate ( itemDelegate ) ;
2010-05-23 13:21:30 -04:00
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > sortByColumn ( COLUMN_DATA , Qt : : DescendingOrder ) ;
2010-04-27 17:46:28 -04:00
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
2014-10-09 18:04:12 -04:00
QShortcut * Shortcut = new QShortcut ( QKeySequence ( Qt : : Key_Delete ) , ui . messageTreeWidget , 0 , 0 , Qt : : WidgetShortcut ) ;
2010-05-06 10:39:50 -04:00
connect ( Shortcut , SIGNAL ( activated ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
2014-10-09 18:04:12 -04:00
Shortcut = new QShortcut ( QKeySequence ( Qt : : SHIFT | Qt : : Key_Delete ) , ui . messageTreeWidget , 0 , 0 , Qt : : WidgetShortcut ) ;
2010-05-28 10:42:54 -04:00
connect ( Shortcut , SIGNAL ( activated ( ) ) , this , SLOT ( removemessage ( ) ) ) ;
2010-05-06 10:39:50 -04:00
2019-02-26 04:46:32 -05:00
QFontMetricsF fm ( font ( ) ) ;
2014-10-09 18:04:12 -04:00
/* Set initial section sizes */
QHeaderView * msgwheader = ui . messageTreeWidget - > header ( ) ;
2019-02-26 05:29:10 -05:00
msgwheader - > resizeSection ( COLUMN_ATTACHEMENTS , fm . width ( ' 0 ' ) * 1.2f ) ;
2010-05-23 13:21:30 -04:00
msgwheader - > resizeSection ( COLUMN_SUBJECT , 250 ) ;
msgwheader - > resizeSection ( COLUMN_FROM , 140 ) ;
msgwheader - > resizeSection ( COLUMN_DATE , 140 ) ;
2011-05-23 19:45:31 -04:00
2015-06-26 04:14:09 -04:00
QHeaderView_setSectionResizeModeColumn ( msgwheader , COLUMN_STAR , QHeaderView : : Fixed ) ;
2011-05-23 19:45:31 -04:00
msgwheader - > resizeSection ( COLUMN_STAR , 24 ) ;
2010-05-23 13:21:30 -04:00
2015-06-26 04:14:09 -04:00
QHeaderView_setSectionResizeModeColumn ( msgwheader , COLUMN_UNREAD , QHeaderView : : Fixed ) ;
2014-10-09 18:04:12 -04:00
msgwheader - > resizeSection ( COLUMN_UNREAD , 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 ) ;
2017-11-18 12:49:42 -05: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 ) ;
ui . viewtoolButton - > setMenu ( viewmenu ) ;
2014-12-14 10:46:20 -05:00
// Set initial size of the splitter
ui . listSplitter - > setStretchFactor ( 0 , 0 ) ;
2014-12-16 12:22:56 -05:00
ui . listSplitter - > setStretchFactor ( 1 , 1 ) ;
2007-11-14 22:18:48 -05:00
2012-10-29 06:59:26 -04:00
/* add filter actions */
2012-10-29 22:44:14 -04:00
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Subject " ) , COLUMN_SUBJECT , tr ( " Search Subject " ) ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " From " ) , COLUMN_FROM , tr ( " Search From " ) ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Date " ) , COLUMN_DATE , tr ( " Search Date " ) ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Content " ) , COLUMN_CONTENT , tr ( " Search Content " ) ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Tags " ) , COLUMN_TAGS , tr ( " Search Tags " ) ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Attachments " ) , COLUMN_ATTACHEMENTS , tr ( " Search Attachments " ) ) ;
2012-10-29 06:59:26 -04:00
2010-05-23 13:21:30 -04:00
//setting default filter by column as subject
2012-10-29 06:59:26 -04:00
ui . filterLineEdit - > setCurrentFilter ( COLUMN_SUBJECT ) ;
2010-05-23 13:21:30 -04: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 */
2015-06-26 04:14:09 -04:00
QHeaderView_setSectionResizeModeColumn ( msgwheader , COLUMN_ATTACHEMENTS , QHeaderView : : Fixed ) ;
QHeaderView_setSectionResizeModeColumn ( msgwheader , COLUMN_DATE , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( msgwheader , COLUMN_UNREAD , QHeaderView : : Fixed ) ;
2019-02-26 04:46:32 -05:00
//QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_SIGNATURE, QHeaderView::Fixed);
2010-08-08 18:58:10 -04:00
msgwheader - > resizeSection ( COLUMN_UNREAD , 24 ) ;
2019-02-26 04:46:32 -05:00
//msgwheader->resizeSection (COLUMN_SIGNATURE, 24);
2011-05-23 19:45:31 -04:00
msgwheader - > resizeSection ( COLUMN_STAR , 24 ) ;
2015-06-26 04:14:09 -04:00
QHeaderView_setSectionResizeModeColumn ( msgwheader , COLUMN_STAR , QHeaderView : : Fixed ) ;
2012-05-03 11:42:43 -04:00
msgwheader - > setStretchLastSection ( false ) ;
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
2013-08-02 19:00:36 -04:00
timer = new RsProtectedTimer ( this ) ;
2019-02-08 09:41:20 -05:00
# ifdef TODO
2010-04-27 17:46:28 -04:00
timer - > setInterval ( 300 ) ;
timer - > setSingleShot ( true ) ;
connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateCurrentMessage ( ) ) ) ;
2019-02-08 09:41:20 -05:00
# endif
2010-04-27 17:46:28 -04:00
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > installEventFilter ( this ) ;
2011-05-02 17:50:20 -04:00
2011-06-03 20:46:02 -04:00
// remove close button of the the first tab
2012-01-18 15:02:19 -05:00
ui . tabWidget - > hideCloseButton ( 0 ) ;
2011-06-03 20:46:02 -04:00
2015-06-30 12:44:58 -04:00
int S = QFontMetricsF ( font ( ) ) . height ( ) ;
2013-09-08 11:08:36 -04:00
QString help_str = tr (
2015-06-30 12:44:58 -04:00
" <h1><img width= \" %1 \" src= \" :/icons/help_64.png \" > Messages</h1> \
2014-09-09 16:04:58 -04:00
< p > Retroshare has its own internal email system . You can send / receive emails to / from connected friend nodes . < / p > \
< p > It is also possible to send messages to other people ' s Identities using the global routing system . These messages \
2015-06-30 12:44:58 -04:00
are always encrypted and signed , and are relayed by intermediate nodes until they reach their final destination . < / p > \
< p > Distant messages stay into your Outbox until an acknowledgement of receipt has been received . < / p > \
2014-09-09 16:04:58 -04:00
< p > Generally , you may use messages to recommend files to your friends by pasting file links , \
2015-06-01 10:20:26 -04:00
or recommend friend nodes to other friend nodes , in order to strenghten your network , or send feedback \
2014-09-09 16:04:58 -04:00
to a channel ' s owner . < / p > \
2015-06-30 12:44:58 -04:00
" ).arg(QString::number(2*S)).arg(QString::number(S)) ;
2013-07-19 14:36:09 -04:00
2017-02-25 17:52:57 -05:00
registerHelpButton ( ui . helpButton , help_str , " MessagesDialog " ) ;
2008-09-04 15:28:35 -04:00
}
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 ) ;
}
2012-08-05 16:12:55 -04:00
UserNotify * MessagesDialog : : getUserNotify ( QObject * parent )
{
return new MessageUserNotify ( parent ) ;
}
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
2012-05-01 05:18:55 -04:00
inProcessSettings = true ;
2010-05-20 17:53:27 -04:00
2014-10-09 18:04:12 -04:00
QHeaderView * msgwheader = ui . messageTreeWidget - > header ( ) ;
2010-05-18 18:37:18 -04:00
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
2012-10-29 06:59:26 -04:00
ui . filterLineEdit - > setCurrentFilter ( Settings - > value ( " filterColumn " , COLUMN_SUBJECT ) . toInt ( ) ) ;
2010-05-18 18:37:18 -04:00
// 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
// state of splitter
2017-11-18 12:49:42 -05:00
ui . msgSplitter - > restoreState ( Settings - > value ( " SplitterMsg " ) . toByteArray ( ) ) ;
ui . listSplitter - > restoreState ( Settings - > value ( " SplitterList " ) . toByteArray ( ) ) ;
2011-06-03 20:46:02 -04:00
/* toolbar button style */
2014-10-09 18:04:12 -04:00
Qt : : ToolButtonStyle style = ( Qt : : ToolButtonStyle ) Settings - > value ( " ToolButon_Style " , Qt : : ToolButtonIconOnly ) . toInt ( ) ;
2011-06-03 20:46:02 -04:00
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
// state of splitter
2017-11-18 12:49:42 -05:00
Settings - > setValue ( " SplitterMsg " , ui . msgSplitter - > saveState ( ) ) ;
Settings - > setValue ( " SplitterList " , ui . listSplitter - > saveState ( ) ) ;
2011-06-03 20:46:02 -04:00
/* toolbar button style */
2014-10-09 18:04:12 -04:00
Settings - > setValue ( " ToolButon_Style " , 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 ) ;
}
2012-05-01 05:18:55 -04:00
inProcessSettings = false ;
2010-04-27 17:46:28 -04:00
}
2011-05-02 17:50:20 -04:00
bool MessagesDialog : : eventFilter ( QObject * obj , QEvent * event )
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2014-10-09 18:04:12 -04:00
if ( obj = = ui . messageTreeWidget ) {
2011-05-02 17:50:20 -04:00
if ( event - > type ( ) = = QEvent : : KeyPress ) {
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( event ) ;
if ( keyEvent & & keyEvent - > key ( ) = = Qt : : Key_Space ) {
// Space pressed
2014-10-09 18:04:12 -04:00
clicked ( ui . messageTreeWidget - > currentItem ( ) , COLUMN_UNREAD ) ;
2011-05-02 17:50:20 -04:00
return true ; // eat event
}
}
}
2019-02-08 09:41:20 -05:00
# endif
2011-05-02 17:50:20 -04:00
// pass the event on to the parent class
return MainPage : : eventFilter ( obj , event ) ;
}
2012-11-19 11:01:21 -05:00
void MessagesDialog : : changeEvent ( QEvent * e )
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2012-11-19 11:01:21 -05:00
QWidget : : changeEvent ( e ) ;
switch ( e - > type ( ) ) {
case QEvent : : StyleChange :
insertMessages ( ) ;
break ;
default :
// remove compiler warnings
break ;
}
2019-02-08 09:41:20 -05:00
# endif
2012-11-19 11:01:21 -05:00
}
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 ;
2015-03-22 00:52:53 -04:00
rsMail - > getMessageTagTypes ( tags ) ;
2011-05-21 12:26:00 -04:00
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 ( ) ;
2012-05-01 05:18:55 -04:00
int selectedType = 0 ;
uint32_t selectedId = 0 ;
2011-05-21 12:26:00 -04:00
if ( item ) {
2012-05-01 05:18:55 -04:00
selectedType = item - > data ( ROLE_QUICKVIEW_TYPE ) . toInt ( ) ;
selectedId = 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
2012-05-01 05:18:55 -04:00
if ( selectedType = = QUICKVIEW_TYPE_STATIC & & selectedId = = QUICKVIEW_STATIC_ID_STARRED ) {
itemToSelect = item ;
}
item = new QListWidgetItem ( tr ( " System " ) , ui . quickViewWidget ) ;
item - > setIcon ( QIcon ( IMAGE_SYSTEM ) ) ;
item - > setData ( ROLE_QUICKVIEW_TYPE , QUICKVIEW_TYPE_STATIC ) ;
item - > setData ( ROLE_QUICKVIEW_ID , QUICKVIEW_STATIC_ID_SYSTEM ) ;
item - > setData ( ROLE_QUICKVIEW_TEXT , item - > text ( ) ) ; // for updateMessageSummaryList
if ( selectedType = = QUICKVIEW_TYPE_STATIC & & selectedId = = QUICKVIEW_STATIC_ID_SYSTEM ) {
2011-06-04 18:54:03 -04:00
itemToSelect = item ;
}
2014-10-21 18:33:02 -04:00
for ( tag = tags . types . begin ( ) ; tag ! = tags . types . end ( ) ; + + tag ) {
2011-05-21 12:26:00 -04:00
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
2012-05-01 05:18:55 -04:00
if ( selectedType = = QUICKVIEW_TYPE_TAG & & tag - > first = = selectedId ) {
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) ;
//}
2019-02-08 09:41:20 -05:00
int MessagesDialog : : getSelectedMessages ( QList < QString > & mid )
{
//To check if the selection has more than one row.
mid . clear ( ) ;
QModelIndexList qmil = ui . messageTreeWidget - > selectionModel ( ) - > selectedRows ( ) ;
foreach ( const QModelIndex & m , qmil )
2019-02-26 05:29:10 -05:00
mid . push_back ( m . sibling ( m . row ( ) , COLUMN_DATA ) . data ( RsMessageModel : : MsgIdRole ) . toString ( ) ) ;
2019-02-08 09:41:20 -05:00
return mid . size ( ) ;
}
2008-09-04 15:28:35 -04:00
2014-10-09 18:04:12 -04:00
int MessagesDialog : : getSelectedMsgCount ( QList < QTreeWidgetItem * > * items , QList < QTreeWidgetItem * > * itemsRead , QList < QTreeWidgetItem * > * itemsUnread , QList < QTreeWidgetItem * > * itemsStar )
2010-05-07 18:23:38 -04:00
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2014-10-09 18:04:12 -04:00
if ( items ) items - > clear ( ) ;
if ( itemsRead ) itemsRead - > clear ( ) ;
if ( itemsUnread ) itemsUnread - > clear ( ) ;
if ( itemsStar ) itemsStar - > 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.
2019-02-08 09:41:20 -05:00
QList < QString > selectedMessages ;
getSelectedMessages ( selectedMessages ) ;
foreach ( const QString & , selectedMessages )
2010-05-07 18:23:38 -04:00
{
2014-10-09 18:04:12 -04:00
if ( items | | itemsRead | | itemsUnread | | itemsStar ) {
if ( items ) items - > append ( item ) ;
2010-05-23 13:21:30 -04:00
2014-10-09 18:04:12 -04:00
if ( item - > data ( COLUMN_DATA , ROLE_UNREAD ) . toBool ( ) ) {
if ( itemsUnread ) itemsUnread - > append ( item ) ;
} else {
if ( itemsRead ) itemsRead - > append ( item ) ;
}
2011-05-23 19:45:31 -04:00
2014-10-09 18:04:12 -04:00
if ( itemsStar ) {
if ( item - > data ( COLUMN_DATA , ROLE_MSGFLAGS ) . toInt ( ) & RS_MSG_STAR ) {
itemsStar - > append ( item ) ;
2011-05-23 19:45:31 -04:00
}
2010-05-23 13:21:30 -04:00
}
2010-05-07 18:23:38 -04:00
}
}
2014-10-09 18:04:12 -04:00
return selectedItems . size ( ) ;
2019-02-08 09:41:20 -05:00
# endif
return 0 ;
2010-05-07 18:23:38 -04:00
}
2019-02-26 08:45:48 -05:00
bool MessagesDialog : : isMessageRead ( const QModelIndex & index )
2010-05-23 13:21:30 -04:00
{
2019-02-26 08:45:48 -05:00
if ( ! index . isValid ( ) )
2014-10-09 18:04:12 -04:00
return true ;
2019-02-26 08:45:48 -05:00
return ! index . data ( RsMessageModel : : UnreadRole ) . toBool ( ) ;
2010-05-23 13:21:30 -04:00
}
2019-02-26 08:45:48 -05:00
bool MessagesDialog : : hasMessageStar ( const QModelIndex & index )
2011-05-23 19:45:31 -04:00
{
2019-02-26 08:45:48 -05:00
if ( ! index . isValid ( ) )
2014-10-09 18:04:12 -04:00
return false ;
2019-02-26 08:45:48 -05:00
return index . data ( RsMessageModel : : MsgFlagsRole ) . toInt ( ) & RS_MSG_STAR ;
2011-05-23 19:45:31 -04:00
}
2014-10-09 18:04:12 -04:00
void MessagesDialog : : messageTreeWidgetCustomPopupMenu ( 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 ;
2015-06-14 11:20:25 -04:00
if ( ! getCurrentMsg ( cid , mid ) )
2019-02-26 04:46:32 -05:00
{
std : : cerr < < " No current message! " < < std : : endl ;
2015-06-14 11:20:25 -04:00
return ;
2019-02-26 04:46:32 -05:00
}
2015-06-14 11:20:25 -04:00
if ( ! rsMail - > getMessage ( mid , msgInfo ) )
return ;
2008-09-04 15:28:35 -04:00
2014-10-09 18:04:12 -04:00
QList < QTreeWidgetItem * > itemsRead ;
QList < QTreeWidgetItem * > itemsUnread ;
QList < QTreeWidgetItem * > itemsStar ;
int nCount = getSelectedMsgCount ( NULL , & itemsRead , & itemsUnread , & itemsStar ) ;
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 ) ;
2013-09-02 19:01:24 -04:00
QAction * action = contextMnu . addAction ( QIcon ( " :/images/view_split_top_bottom.png " ) , tr ( " Open in a new window " ) , this , SLOT ( openAsWindow ( ) ) ) ;
2019-01-03 16:20:00 -05:00
2011-05-23 19:45:31 -04:00
if ( nCount ! = 1 ) {
action - > setDisabled ( true ) ;
}
2011-06-03 20:46:02 -04:00
2013-09-02 19:01:24 -04:00
action = contextMnu . addAction ( QIcon ( " :/images/tab-dock.png " ) , 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 ( ) ) ) ;
2014-10-21 18:33:02 -04:00
if ( itemsUnread . isEmpty ( ) ) {
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 ( ) ) ) ;
2019-01-03 16:20:00 -05:00
2014-10-21 18:33:02 -04:00
if ( itemsRead . isEmpty ( ) ) {
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 ) ;
2014-10-09 18:04:12 -04:00
action - > setChecked ( itemsStar . size ( ) ) ;
2011-05-23 19:45:31 -04:00
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 ( ) ;
2019-01-03 16:20:00 -05:00
RsIdentityDetails details ;
// test if identity is known. If not, no need to call the people tab. Also some mails come from nodes and we wont show that node in the people tab either.
// The problem here is that the field rsgxsid_srcId is always populated with either the GxsId or the node of the source, which is inconsistent.
if ( nCount = = 1 & & rsIdentity - > getIdDetails ( msgInfo . rsgxsid_srcId , details ) )
{
std : : cerr < < " Src ID = " < < msgInfo . rsgxsid_srcId < < std : : endl ;
contextMnu . addAction ( QIcon ( IMAGE_AUTHOR_INFO ) , tr ( " Show author in People " ) , this , SLOT ( showAuthorInPeopleTab ( ) ) ) ;
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
}
2019-01-03 16:20:00 -05:00
void MessagesDialog : : showAuthorInPeopleTab ( )
{
std : : string cid ;
std : : string mid ;
if ( ! getCurrentMsg ( cid , mid ) )
return ;
MessageInfo msgInfo ;
if ( ! rsMail - > getMessage ( mid , msgInfo ) )
return ;
if ( msgInfo . rsgxsid_srcId . isNull ( ) )
return ;
/* window will destroy itself! */
IdDialog * idDialog = dynamic_cast < IdDialog * > ( MainWindow : : getPage ( MainWindow : : People ) ) ;
if ( ! idDialog )
return ;
MainWindow : : showWindow ( MainWindow : : People ) ;
idDialog - > navigate ( RsGxsId ( msgInfo . rsgxsid_srcId ) ) ;
}
2013-05-04 18:03:48 -04:00
void MessagesDialog : : folderlistWidgetCustomPopupMenu ( 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
}
2019-02-08 09:41:20 -05:00
void MessagesDialog : : changeBox ( int box_row )
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
2019-02-08 09:41:20 -05:00
// ui.messageTreeWidget->clear();
2010-05-07 18:23:38 -04:00
2011-06-04 18:54:03 -04:00
ui . quickViewWidget - > setCurrentItem ( NULL ) ;
2012-05-01 05:18:55 -04:00
listMode = LIST_BOX ;
2010-06-01 18:14:52 -04:00
2019-02-08 09:41:20 -05:00
// insertMessages();
// insertMsgTxtAndFiles(ui.messageTreeWidget->currentItem());
2010-06-01 18:14:52 -04:00
2019-02-08 09:41:20 -05:00
switch ( box_row )
{
case 0 : mMessageModel - > setCurrentBox ( RsMessageModel : : BOX_INBOX ) ; break ;
case 1 : mMessageModel - > setCurrentBox ( RsMessageModel : : BOX_OUTBOX ) ; break ;
case 2 : mMessageModel - > setCurrentBox ( RsMessageModel : : BOX_DRAFTS ) ; break ;
case 3 : mMessageModel - > setCurrentBox ( RsMessageModel : : BOX_SENT ) ; break ;
case 4 : mMessageModel - > setCurrentBox ( RsMessageModel : : BOX_TRASH ) ; break ;
default :
mMessageModel - > setCurrentBox ( RsMessageModel : : BOX_NONE ) ; break ;
}
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
{
2019-02-08 09:41:20 -05:00
# warning Missing code here!
# ifdef TODO
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
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > clear ( ) ;
2010-06-01 18:14:52 -04:00
ui . listWidget - > setCurrentItem ( NULL ) ;
2012-05-01 05:18:55 -04:00
listMode = LIST_QUICKVIEW ;
2010-06-01 18:14:52 -04:00
insertMessages ( ) ;
2014-10-09 18:04:12 -04:00
insertMsgTxtAndFiles ( ui . messageTreeWidget - > currentItem ( ) ) ;
2010-06-01 18:14:52 -04:00
2011-06-04 18:54:03 -04:00
inChange = false ;
2019-02-08 09:41:20 -05:00
# endif
2010-06-01 18:14:52 -04:00
}
2010-08-22 18:12:26 -04:00
void MessagesDialog : : messagesTagsChanged ( )
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2012-05-01 05:18:55 -04:00
if ( lockUpdate ) {
2010-08-22 18:12:26 -04:00
return ;
}
2011-06-04 18:54:03 -04:00
fillQuickView ( ) ;
2010-08-22 18:12:26 -04:00
insertMessages ( ) ;
2019-02-08 09:41:20 -05:00
# endif
# warning Missing code here!
2010-08-22 18:12:26 -04:00
}
2014-10-09 18:04:12 -04:00
static void InitIconAndFont ( QTreeWidgetItem * item )
2010-05-23 13:21:30 -04:00
{
2007-11-14 22:18:48 -05:00
}
2019-02-08 09:41:20 -05:00
# ifdef TO_REMOVE
2007-11-14 22:18:48 -05:00
void MessagesDialog : : insertMessages ( )
{
2012-05-01 05:18:55 -04:00
if ( lockUpdate ) {
2010-06-03 18:12:07 -04:00
return ;
}
2010-05-23 13:21:30 -04:00
std : : list < MsgInfoSummary > msgList ;
std : : list < MsgInfoSummary > : : const_iterator it ;
MessageInfo msgInfo ;
2012-05-01 05:18:55 -04:00
bool gotInfo ;
2010-05-23 13:21:30 -04:00
QString text ;
2014-03-17 16:56:06 -04:00
RsPeerId ownId = rsPeers - > getOwnId ( ) ;
2012-05-01 05:18:55 -04:00
2015-03-22 00:52:53 -04:00
rsMail - > getMessageSummaries ( msgList ) ;
2010-05-23 13:21:30 -04:00
2012-10-29 06:59:26 -04:00
int filterColumn = ui . filterLineEdit - > currentFilter ( ) ;
2010-05-23 13:21:30 -04:00
/* 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
2012-05-01 05:18:55 -04:00
switch ( listMode ) {
2010-06-01 18:14:52 -04:00
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 :
{
2014-10-09 18:04:12 -04:00
QListWidgetItem * listItem = ui . listWidget - > currentItem ( ) ;
if ( listItem ) {
boxIcon = listItem - > icon ( ) ;
2011-05-24 09:15:43 -04:00
}
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
{
2014-10-09 18:04:12 -04:00
QListWidgetItem * listItem = ui . quickViewWidget - > currentItem ( ) ;
if ( listItem ) {
quickViewType = listItem - > data ( ROLE_QUICKVIEW_TYPE ) . toInt ( ) ;
quickViewId = listItem - > data ( ROLE_QUICKVIEW_ID ) . toInt ( ) ;
2011-05-24 09:15:43 -04:00
2014-10-09 18:04:12 -04:00
boxText = listItem - > text ( ) ;
boxIcon = listItem - > 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 :
2012-10-11 06:28:24 -04:00
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 gray star beside any message. " ) ;
2011-06-05 16:19:10 -04:00
break ;
2012-05-01 05:18:55 -04:00
case QUICKVIEW_STATIC_ID_SYSTEM :
placeholderText = tr ( " No system messages available. " ) ;
break ;
2011-06-05 16:19:10 -04:00
}
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 ) ;
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > setPlaceholderText ( placeholderText ) ;
2011-05-24 09:15:43 -04:00
2014-10-09 18:04:12 -04:00
QTreeWidgetItem * headerItem = ui . messageTreeWidget - > headerItem ( ) ;
2010-05-23 13:21:30 -04:00
if ( msgbox = = RS_MSG_INBOX ) {
2014-10-09 18:04:12 -04:00
headerItem - > setText ( COLUMN_FROM , tr ( " From " ) ) ;
headerItem - > setToolTip ( COLUMN_FROM , tr ( " Click to sort by from " ) ) ;
2010-05-23 13:21:30 -04:00
} else {
2014-10-09 18:04:12 -04:00
headerItem - > setText ( COLUMN_FROM , tr ( " To " ) ) ;
headerItem - > setToolTip ( COLUMN_FROM , tr ( " Click to sort by to " ) ) ;
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 ;
2015-03-22 00:52:53 -04:00
rsMail - > getMessageTagTypes ( Tags ) ;
2010-05-27 15:48:52 -04:00
2010-06-01 18:14:52 -04:00
/* search messages */
std : : list < MsgInfoSummary > msgToShow ;
2014-10-21 18:33:02 -04:00
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; + + it ) {
2012-05-01 05:18:55 -04:00
if ( listMode = = 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
}
2012-05-01 05:18:55 -04:00
} else if ( listMode = = LIST_QUICKVIEW & & quickViewType = = QUICKVIEW_TYPE_TAG ) {
2010-08-22 18:12:26 -04:00
MsgTagInfo tagInfo ;
2015-03-22 00:52:53 -04:00
rsMail - > 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 ;
}
2012-05-01 05:18:55 -04:00
} else if ( listMode = = LIST_QUICKVIEW & & quickViewType = = QUICKVIEW_TYPE_STATIC ) {
if ( quickViewId = = QUICKVIEW_STATIC_ID_STARRED & & ( it - > msgflags & RS_MSG_STAR ) = = 0 ) {
continue ;
}
if ( quickViewId = = QUICKVIEW_STATIC_ID_SYSTEM & & ( it - > msgflags & RS_MSG_SYSTEM ) = = 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 */
2014-10-09 18:04:12 -04:00
QTreeWidgetItemIterator itemIterator ( ui . messageTreeWidget ) ;
QTreeWidgetItem * treeItem ;
while ( ( treeItem = * itemIterator ) ! = NULL ) {
+ + itemIterator ;
std : : string msgIdFromRow = treeItem - > data ( COLUMN_DATA , ROLE_MSGID ) . toString ( ) . toStdString ( ) ;
2014-10-21 18:33:02 -04:00
for ( it = msgToShow . begin ( ) ; it ! = msgToShow . end ( ) ; + + it ) {
2010-06-01 18:14:52 -04:00
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 ( ) ) {
2014-10-09 18:04:12 -04:00
delete ( treeItem ) ;
2010-05-23 13:21:30 -04:00
}
}
2014-10-21 18:33:02 -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 .
*
*/
2012-05-01 05:18:55 -04:00
gotInfo = false ;
2010-05-23 13:21:30 -04:00
msgInfo = MessageInfo ( ) ; // clear
// search exisisting items
2014-10-09 18:04:12 -04:00
QTreeWidgetItemIterator existingItemIterator ( ui . messageTreeWidget ) ;
while ( ( treeItem = * existingItemIterator ) ! = NULL ) {
+ + existingItemIterator ;
if ( it - > msgId = = treeItem - > data ( COLUMN_DATA , ROLE_MSGID ) . toString ( ) . toStdString ( ) ) {
2010-05-23 13:21:30 -04:00
break ;
}
}
/* make a widget per friend */
2014-10-09 18:04:12 -04:00
bool insertItem = false ;
2010-05-23 13:21:30 -04:00
2014-10-09 18:04:12 -04:00
GxsIdRSTreeWidgetItem * item ;
if ( treeItem ) {
item = dynamic_cast < GxsIdRSTreeWidgetItem * > ( treeItem ) ;
if ( ! item ) {
std : : cerr < < " MessagesDialog::insertMessages() Item is no GxsIdRSTreeWidgetItem " < < std : : endl ;
continue ;
2010-05-23 13:21:30 -04:00
}
} else {
2015-03-14 15:19:34 -04:00
item = new GxsIdRSTreeWidgetItem ( mMessageCompareRole , GxsIdDetails : : ICON_TYPE_AVATAR ) ;
2014-10-09 18:04:12 -04:00
insertItem = true ;
2010-05-23 13:21:30 -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
*/
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 )
{
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_DATE , DateTime : : formatTime ( qdatetime . time ( ) ) ) ;
2010-05-23 13:21:30 -04:00
}
else
{
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_DATE , DateTime : : formatDateTime ( qdatetime ) ) ;
2010-05-23 13:21:30 -04:00
}
// for sorting
2014-10-09 18:04:12 -04:00
item - > setData ( COLUMN_DATE , ROLE_SORT , qdatetime ) ;
2010-05-23 13:21:30 -04:00
}
// From ....
{
2015-02-22 10:06:27 -05:00
bool setText = true ;
2016-01-08 20:48:47 -05:00
if ( msgbox = = RS_MSG_INBOX | | msgbox = = RS_MSG_OUTBOX )
{
2012-05-01 05:18:55 -04:00
if ( ( it - > msgflags & RS_MSG_SYSTEM ) & & it - > srcId = = ownId ) {
text = " RetroShare " ;
2016-01-08 20:48:47 -05:00
}
else
{
2015-02-20 05:34:11 -05:00
if ( it - > msgflags & RS_MSG_DISTANT )
2015-02-22 10:06:27 -05:00
{
2014-10-09 18:04:12 -04:00
// distant message
2015-02-22 10:06:27 -05:00
setText = false ;
2015-03-22 00:52:53 -04:00
if ( gotInfo | | rsMail - > getMessage ( it - > msgId , msgInfo ) ) {
2014-10-09 18:04:12 -04:00
gotInfo = true ;
2016-01-08 20:48:47 -05:00
if ( msgbox ! = RS_MSG_INBOX & & ! msgInfo . rsgxsid_msgto . empty ( ) )
item - > setId ( RsGxsId ( * msgInfo . rsgxsid_msgto . begin ( ) ) , COLUMN_FROM , false ) ;
else
item - > setId ( RsGxsId ( msgInfo . rsgxsid_srcId ) , COLUMN_FROM , false ) ;
}
else
2014-10-09 18:04:12 -04:00
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg " < < std : : endl ;
2016-01-08 20:48:47 -05:00
}
else
2014-10-09 18:04:12 -04:00
text = QString : : fromUtf8 ( rsPeers - > getPeerName ( it - > srcId ) . c_str ( ) ) ;
2012-05-01 05:18:55 -04:00
}
2016-01-08 20:48:47 -05:00
}
else
{
2015-03-22 00:52:53 -04:00
if ( gotInfo | | rsMail - > getMessage ( it - > msgId , msgInfo ) ) {
2012-05-01 05:18:55 -04:00
gotInfo = true ;
2010-05-23 13:21:30 -04:00
text . clear ( ) ;
2015-04-17 17:36:22 -04:00
for ( std : : set < RsPeerId > : : const_iterator pit = msgInfo . rspeerid_msgto . begin ( ) ; pit ! = msgInfo . rspeerid_msgto . end ( ) ; + + pit )
2010-05-23 13:21:30 -04:00
{
2014-03-29 10:18:05 -04:00
if ( ! text . isEmpty ( ) )
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 ) ;
2014-03-29 10:18:05 -04:00
if ( peerName . empty ( ) )
2010-09-28 16:33:34 -04:00
text + = PeerDefs : : rsid ( " " , * pit ) ;
2014-03-29 10:18:05 -04:00
else
text + = QString : : fromUtf8 ( peerName . c_str ( ) ) ;
}
2015-04-17 17:36:22 -04:00
for ( std : : set < RsGxsId > : : const_iterator pit = msgInfo . rsgxsid_msgto . begin ( ) ; pit ! = msgInfo . rsgxsid_msgto . end ( ) ; + + pit )
2014-03-29 10:18:05 -04:00
{
if ( ! text . isEmpty ( ) )
text + = " , " ;
2014-10-09 18:04:12 -04:00
RsIdentityDetails details ;
if ( rsIdentity - > getIdDetails ( * pit , details ) & & ! details . mNickname . empty ( ) )
text + = QString : : fromUtf8 ( details . mNickname . c_str ( ) ) ;
else
2014-03-29 10:18:05 -04:00
text + = PeerDefs : : rsid ( " " , * pit ) ;
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 ;
}
}
2015-02-22 10:06:27 -05:00
if ( setText )
{
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_FROM , text ) ;
item - > setData ( COLUMN_FROM , ROLE_SORT , text + dateString ) ;
2015-02-22 10:06:27 -05:00
} else {
item - > setData ( COLUMN_FROM , ROLE_SORT , item - > text ( COLUMN_FROM ) + dateString ) ;
2014-10-09 18:04:12 -04:00
}
2010-05-23 13:21:30 -04:00
}
// Subject
2015-02-22 10:06:27 -05:00
text = QString : : fromUtf8 ( it - > title . c_str ( ) ) ;
2013-09-25 11:58:01 -04:00
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_SUBJECT , text ) ;
item - > setData ( COLUMN_SUBJECT , ROLE_SORT , text + dateString ) ;
2010-05-23 13:21:30 -04:00
// internal data
2010-05-27 15:48:52 -04:00
QString msgId = QString : : fromStdString ( it - > msgId ) ;
2014-10-09 18:04:12 -04:00
item - > setData ( COLUMN_DATA , ROLE_SRCID , QString : : fromStdString ( it - > srcId . toStdString ( ) ) ) ;
item - > setData ( COLUMN_DATA , ROLE_MSGID , msgId ) ;
item - > setData ( COLUMN_DATA , ROLE_MSGFLAGS , it - > 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 ;
2015-03-22 00:52:53 -04:00
rsMail - > 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 ;
2014-10-21 18:33:02 -04:00
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
2015-03-22 00:52:53 -04:00
rsMail - > setMessageTag ( it - > msgId , * tagId , false ) ;
2010-08-22 18:12:26 -04:00
}
2010-05-27 15:48:52 -04:00
}
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_TAGS , text ) ;
item - > setData ( COLUMN_TAGS , ROLE_SORT , text ) ;
2010-05-27 15:48:52 -04:00
// set color
2012-11-19 11:01:21 -05:00
QColor color ;
2010-08-22 18:12:26 -04:00
if ( tagInfo . tagIds . size ( ) ) {
Tag = Tags . types . find ( tagInfo . tagIds . front ( ) ) ;
if ( Tag ! = Tags . types . end ( ) ) {
2012-11-19 11:01:21 -05:00
color = Tag - > second . second ;
2010-08-22 18:12:26 -04:00
} else {
// clean tagId
2015-03-22 00:52:53 -04:00
rsMail - > setMessageTag ( it - > msgId , tagInfo . tagIds . front ( ) , false ) ;
2010-08-22 18:12:26 -04:00
}
2010-05-27 15:48:52 -04:00
}
2012-11-19 11:01:21 -05:00
if ( ! color . isValid ( ) ) {
2014-10-09 18:04:12 -04:00
color = ui . messageTreeWidget - > palette ( ) . color ( QPalette : : Text ) ;
2012-11-19 11:01:21 -05:00
}
QBrush brush = QBrush ( color ) ;
2014-10-21 18:33:02 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; + + i ) {
2014-10-09 18:04:12 -04:00
item - > setForeground ( i , brush ) ;
2010-05-27 15:48:52 -04:00
}
2010-05-23 13:21:30 -04:00
// No of Files.
{
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_ATTACHEMENTS , QString : : number ( it - > count ) ) ;
item - > setData ( COLUMN_ATTACHEMENTS , ROLE_SORT , item - > text ( COLUMN_ATTACHEMENTS ) + dateString ) ;
item - > setTextAlignment ( COLUMN_ATTACHEMENTS , Qt : : AlignHCenter ) ;
2010-05-23 13:21:30 -04:00
}
2012-05-01 05:18:55 -04:00
if ( filterColumn = = COLUMN_CONTENT ) {
2010-05-23 13:21:30 -04:00
// need content for filter
2015-03-22 00:52:53 -04:00
if ( gotInfo | | rsMail - > getMessage ( it - > msgId , msgInfo ) ) {
2012-05-01 05:18:55 -04:00
gotInfo = true ;
2010-05-23 13:21:30 -04:00
QTextDocument doc ;
2013-10-06 16:12:34 -04:00
doc . setHtml ( QString : : fromUtf8 ( msgInfo . msg . c_str ( ) ) ) ;
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_CONTENT , doc . toPlainText ( ) . replace ( QString ( " \n " ) , QString ( " " ) ) ) ;
2010-05-23 13:21:30 -04:00
} else {
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg " < < std : : endl ;
2014-10-09 18:04:12 -04:00
item - > setText ( COLUMN_CONTENT , " " ) ;
2010-05-23 13:21:30 -04:00
}
}
2015-02-20 05:34:11 -05:00
else if ( it - > msgflags & RS_MSG_DISTANT )
2014-10-09 18:04:12 -04:00
{
item - > setIcon ( COLUMN_SIGNATURE , QIcon ( " :/images/blue_lock_open.png " ) ) ;
2014-12-23 14:58:49 -05:00
item - > setIcon ( COLUMN_SUBJECT , QIcon ( " :/images/message-mail-read.png " ) ) ;
2015-10-27 20:59:19 -04:00
if ( msgbox = = RS_MSG_INBOX )
{
item - > setToolTip ( COLUMN_SIGNATURE , tr ( " This message comes from a distant person. " ) ) ;
}
else if ( msgbox = = RS_MSG_OUTBOX )
{
item - > setToolTip ( COLUMN_SIGNATURE , tr ( " This message goes to a distant person. " ) ) ;
}
2014-10-09 18:04:12 -04:00
if ( it - > msgflags & RS_MSG_SIGNED )
{
if ( it - > msgflags & RS_MSG_SIGNATURE_CHECKS )
{
item - > setIcon ( COLUMN_SIGNATURE , QIcon ( " :/images/stock_signature_ok.png " ) ) ;
item - > setToolTip ( COLUMN_SIGNATURE , tr ( " This message was signed and the signature checks " ) ) ;
}
else
{
item - > setIcon ( COLUMN_SIGNATURE , QIcon ( " :/images/stock_signature_bad.png " ) ) ;
item - > setToolTip ( COLUMN_SIGNATURE , tr ( " This message was signed but the signature doesn't check " ) ) ;
}
2010-05-23 13:21:30 -04:00
}
2014-10-09 18:04:12 -04:00
}
else
item - > setIcon ( COLUMN_SIGNATURE , QIcon ( ) ) ;
if ( insertItem ) {
/* add to the list */
ui . messageTreeWidget - > addTopLevelItem ( item ) ;
2010-05-23 13:21:30 -04:00
}
}
} else {
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > clear ( ) ;
2010-05-23 13:21:30 -04:00
}
2007-11-14 22:18:48 -05:00
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > showColumn ( COLUMN_ATTACHEMENTS ) ;
ui . messageTreeWidget - > showColumn ( COLUMN_SUBJECT ) ;
ui . messageTreeWidget - > showColumn ( COLUMN_UNREAD ) ;
ui . messageTreeWidget - > showColumn ( COLUMN_FROM ) ;
ui . messageTreeWidget - > showColumn ( COLUMN_DATE ) ;
ui . messageTreeWidget - > showColumn ( COLUMN_TAGS ) ;
ui . messageTreeWidget - > hideColumn ( COLUMN_CONTENT ) ;
if ( ! ui . filterLineEdit - > text ( ) . isEmpty ( ) ) {
ui . messageTreeWidget - > filterItems ( ui . filterLineEdit - > currentFilter ( ) , ui . filterLineEdit - > text ( ) ) ;
}
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
}
2019-02-08 09:41:20 -05:00
# endif
2007-11-14 22:18:48 -05:00
2014-10-09 18:04:12 -04:00
// current row in messageTreeWidget has changed
void MessagesDialog : : currentItemChanged ( QTreeWidgetItem * item )
2007-11-14 22:18:48 -05:00
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2010-04-27 17:46:28 -04:00
timer - > stop ( ) ;
2014-10-09 18:04:12 -04:00
if ( item ) {
timerIndex = ui . messageTreeWidget - > indexOfTopLevelItem ( item ) ;
timer - > start ( ) ;
} else {
timerIndex = - 1 ;
}
updateInterface ( ) ;
2019-02-08 09:41:20 -05:00
# endif
2010-04-27 17:46:28 -04:00
}
2014-10-09 18:04:12 -04:00
// click in messageTreeWidget
2019-02-26 08:09:49 -05:00
void MessagesDialog : : clicked ( const QModelIndex & index )
2010-04-27 17:46:28 -04:00
{
2019-02-26 08:09:49 -05:00
if ( ! index . isValid ( ) )
2010-05-23 13:21:30 -04:00
return ;
2019-02-26 08:45:48 -05:00
switch ( index . column ( ) )
{
case COLUMN_UNREAD :
{
mMessageModel - > setMsgReadStatus ( index , ! isMessageRead ( index ) ) ;
insertMsgTxtAndFiles ( index ) ;
updateMessageSummaryList ( ) ;
return ;
}
case COLUMN_STAR :
{
mMessageModel - > setMsgStar ( index , ! hasMessageStar ( index ) ) ;
return ;
}
}
2019-02-08 09:41:20 -05:00
# ifdef TODO
2010-04-27 17:46:28 -04:00
timer - > stop ( ) ;
2014-10-09 18:04:12 -04:00
timerIndex = ui . messageTreeWidget - > indexOfTopLevelItem ( item ) ;
2019-02-08 09:41:20 -05:00
# endif
2014-10-09 18:04:12 -04:00
2010-04-27 17:46:28 -04:00
// show current message directly
2019-02-26 08:09:49 -05:00
insertMsgTxtAndFiles ( index ) ;
2010-04-27 17:46:28 -04:00
}
2014-10-09 18:04:12 -04:00
// double click in messageTreeWidget
2019-02-26 08:09:49 -05:00
void MessagesDialog : : doubleClicked ( const QModelIndex & index )
2010-05-25 05:32:14 -04:00
{
2010-06-14 14:16:32 -04:00
/* activate row */
2019-02-26 08:09:49 -05:00
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 ;
2015-03-22 00:52:53 -04:00
if ( ! rsMail - > getMessage ( mid , msgInfo ) ) {
2011-06-03 20:46:02 -04:00
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 ( )
{
2007-11-14 22:18:48 -05:00
}
2014-10-09 18:04:12 -04:00
void MessagesDialog : : setMsgAsReadUnread ( const QList < QTreeWidgetItem * > & items , bool read )
2009-02-22 12:36:39 -05:00
{
2010-08-09 08:16:21 -04:00
LockUpdate Lock ( this , false ) ;
2014-10-09 18:04:12 -04:00
foreach ( QTreeWidgetItem * item , items ) {
2019-02-26 05:29:10 -05:00
std : : string mid = item - > data ( COLUMN_DATA , RsMessageModel : : MsgIdRole ) . toString ( ) . toStdString ( ) ;
2010-05-23 13:21:30 -04:00
2015-03-22 00:52:53 -04:00
if ( rsMail - > MessageRead ( mid , ! read ) ) {
2019-02-26 05:29:10 -05:00
int msgFlag = item - > data ( COLUMN_DATA , RsMessageModel : : MsgFlagsRole ) . toInt ( ) ;
2011-05-23 19:45:31 -04:00
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
}
2019-02-26 05:29:10 -05:00
item - > setData ( COLUMN_DATA , RsMessageModel : : MsgFlagsRole , msgFlag ) ;
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
{
2014-10-09 18:04:12 -04:00
QList < QTreeWidgetItem * > itemsUnread ;
getSelectedMsgCount ( NULL , NULL , & itemsUnread , NULL ) ;
2010-05-23 13:21:30 -04:00
2014-10-09 18:04:12 -04:00
setMsgAsReadUnread ( itemsUnread , true ) ;
2010-05-23 13:21:30 -04:00
updateMessageSummaryList ( ) ;
}
void MessagesDialog : : markAsUnread ( )
{
2014-10-09 18:04:12 -04:00
QList < QTreeWidgetItem * > itemsRead ;
getSelectedMsgCount ( NULL , & itemsRead , NULL , NULL ) ;
2010-05-23 13:21:30 -04:00
2014-10-09 18:04:12 -04:00
setMsgAsReadUnread ( itemsRead , false ) ;
2010-05-23 13:21:30 -04:00
updateMessageSummaryList ( ) ;
}
2011-05-23 19:45:31 -04:00
void MessagesDialog : : markWithStar ( bool checked )
{
2019-02-26 08:45:48 -05:00
QModelIndexList lst = ui . messageTreeWidget - > selectionModel ( ) - > selectedRows ( ) ;
2011-05-23 19:45:31 -04:00
2019-02-26 08:45:48 -05:00
foreach ( const QModelIndex & index , lst )
mMessageModel - > setMsgStar ( index , checked ) ;
2011-06-04 18:54:03 -04:00
}
2011-05-23 19:45:31 -04:00
2019-02-26 08:09:49 -05:00
void MessagesDialog : : insertMsgTxtAndFiles ( const QModelIndex & index )
2010-05-23 13:21:30 -04:00
{
/* get its Ids */
std : : string cid ;
std : : string mid ;
2019-02-26 08:09:49 -05:00
if ( ! index . isValid ( ) )
{
mCurrMsgId . clear ( ) ;
msgWidget - > fill ( mCurrMsgId ) ;
updateInterface ( ) ;
return ;
}
mid = index . data ( RsMessageModel : : MsgIdRole ) . toString ( ) . toStdString ( ) ;
// int nCount = getSelectedMsgCount (NULL, NULL, NULL, NULL);
//
// if (nCount == 1) {
// ui.actionSaveAs->setEnabled(true);
// ui.actionPrintPreview->setEnabled(true);
// ui.actionPrint->setEnabled(true);
// } else {
// ui.actionSaveAs->setDisabled(true);
// ui.actionPrintPreview->setDisabled(true);
// ui.actionPrint->setDisabled(true);
// }
2010-05-23 13:21:30 -04:00
/* Save the Data.... for later */
MessageInfo msgInfo ;
2015-03-22 00:52:53 -04:00
if ( ! rsMail - > getMessage ( mid , msgInfo ) ) {
2010-05-23 13:21:30 -04:00
std : : cerr < < " MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg " < < std : : endl ;
return ;
}
2019-02-26 08:09:49 -05:00
// QList<QTreeWidgetItem*> items;
// items.append(item);
//
// bool bSetToReadOnActive = Settings->getMsgSetToReadOnActivate();
//
// if (msgInfo.msgflags & RS_MSG_NEW) {
// // set always to read or unread
// if (bSetToReadOnActive == false || bSetToRead == false) {
// // set locally to unread
// setMsgAsReadUnread(items, false);
// } else {
// setMsgAsReadUnread(items, true);
// }
// updateMessageSummaryList();
// } else {
// if ((msgInfo.msgflags & RS_MSG_UNREAD_BY_USER) && bSetToRead && bSetToReadOnActive) {
// // set to read
// setMsgAsReadUnread(items, true);
// updateMessageSummaryList();
// }
// }
2010-05-23 13:21:30 -04:00
2011-06-03 20:46:02 -04:00
updateInterface ( ) ;
2019-02-26 08:09:49 -05:00
msgWidget - > fill ( mid ) ;
2007-11-14 22:18:48 -05:00
}
bool MessagesDialog : : getCurrentMsg ( std : : string & cid , std : : string & mid )
{
2019-02-08 09:41:20 -05:00
QModelIndex indx = ui . messageTreeWidget - > currentIndex ( ) ;
2010-05-23 13:21:30 -04:00
2019-02-08 09:41:20 -05:00
# ifdef TODO
2010-05-23 13:21:30 -04:00
/* get its Ids */
2019-02-08 09:41:20 -05:00
if ( ! indx . isValid ( ) )
2010-05-23 13:21:30 -04:00
{
//If no message is selected. assume first message is selected.
2014-10-09 18:04:12 -04:00
if ( ui . messageTreeWidget - > topLevelItemCount ( ) = = 0 )
2010-05-23 13:21:30 -04:00
{
2014-10-09 18:04:12 -04:00
item = ui . messageTreeWidget - > topLevelItem ( 0 ) ;
2010-05-23 13:21:30 -04:00
}
}
2014-10-09 18:04:12 -04:00
if ( ! item ) {
2010-06-25 08:17:46 -04:00
return false ;
}
2019-02-08 09:41:20 -05:00
# endif
if ( ! indx . isValid ( ) )
return false ;
2019-02-26 05:29:10 -05:00
cid = indx . sibling ( indx . row ( ) , COLUMN_DATA ) . data ( RsMessageModel : : SrcIdRole ) . toString ( ) . toStdString ( ) ;
mid = indx . sibling ( indx . row ( ) , COLUMN_DATA ) . data ( RsMessageModel : : MsgIdRole ) . toString ( ) . toStdString ( ) ;
2019-02-08 09:41:20 -05:00
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 ) ;
2019-02-08 09:41:20 -05:00
QList < QString > selectedMessages ;
getSelectedMessages ( selectedMessages ) ;
2010-05-23 13:21:30 -04:00
2014-10-09 18:04:12 -04:00
bool doDelete = 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 ) {
2014-10-09 18:04:12 -04:00
doDelete = true ;
2010-05-28 10:42:54 -04:00
} else {
if ( QApplication : : keyboardModifiers ( ) & Qt : : ShiftModifier ) {
2014-10-09 18:04:12 -04:00
doDelete = true ;
2010-05-28 10:42:54 -04:00
}
}
2019-02-08 09:41:20 -05:00
foreach ( const QString & m , selectedMessages ) {
2014-10-09 18:04:12 -04:00
if ( doDelete ) {
2019-02-08 09:41:20 -05:00
rsMail - > MessageDelete ( m . toStdString ( ) ) ;
2014-10-09 18:04:12 -04:00
} else {
2019-02-08 09:41:20 -05:00
rsMail - > MessageToTrash ( m . 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
2019-02-26 04:46:32 -05:00
QList < QString > msgids ;
getSelectedMessages ( msgids ) ;
foreach ( const QString & s , msgids )
rsMail - > MessageToTrash ( s . 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 ) ;
2017-11-18 12:49:42 -05:00
ui . printButton - > setToolButtonStyle ( style ) ;
2010-05-27 15:48:52 -04:00
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
2012-04-05 17:03:03 -04:00
void MessagesDialog : : filterChanged ( const QString & text )
2010-02-13 13:49:56 -05:00
{
2019-02-08 09:41:20 -05:00
# ifdef TODO
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > filterItems ( ui . filterLineEdit - > currentFilter ( ) , text ) ;
2019-02-08 09:41:20 -05:00
# endif
2010-02-13 13:49:56 -05:00
}
2012-10-29 06:59:26 -04:00
void MessagesDialog : : filterColumnChanged ( int column )
2010-02-13 13:49:56 -05:00
{
2012-05-01 05:18:55 -04:00
if ( inProcessSettings ) {
2010-05-20 17:53:27 -04:00
return ;
}
2012-10-29 06:59:26 -04:00
if ( column = = COLUMN_CONTENT ) {
2010-05-18 18:37:18 -04:00
// need content ... refill
2019-02-08 09:41:20 -05:00
//insertMessages();
2010-05-18 18:37:18 -04:00
}
2019-02-08 09:41:20 -05:00
# ifdef TODO
2014-10-09 18:04:12 -04:00
ui . messageTreeWidget - > filterItems ( column , ui . filterLineEdit - > text ( ) ) ;
2019-02-08 09:41:20 -05:00
# endif
2010-05-18 18:37:18 -04:00
// save index
2012-10-29 06:59:26 -04:00
Settings - > setValueToGroup ( " MessageDialog " , " filterColumn " , column ) ;
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 ;
2012-05-01 05:18:55 -04:00
unsigned int systemCount = 0 ;
2010-05-23 13:21:30 -04:00
/* calculating the new messages */
2015-03-22 00:52:53 -04:00
// rsMail->getMessageCount (&inboxCount, &newInboxCount, &newOutboxCount, &newDraftCount, &newSentboxCount);
2010-05-23 13:21:30 -04:00
std : : list < MsgInfoSummary > msgList ;
std : : list < MsgInfoSummary > : : const_iterator it ;
2015-03-22 00:52:53 -04:00
rsMail - > getMessageSummaries ( msgList ) ;
2010-05-23 13:21:30 -04:00
2010-06-01 18:14:52 -04:00
QMap < int , int > tagCount ;
2010-08-22 18:12:26 -04:00
/* calculating the new messages */
2014-10-21 18:33:02 -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 ;
2015-03-22 00:52:53 -04:00
rsMail - > getMessageTag ( it - > msgId , tagInfo ) ;
2014-10-21 18:33:02 -04:00
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 ] ;
2014-10-21 18:33:02 -04:00
+ + nCount ;
2010-06-01 18:14:52 -04:00
tagCount [ * tagId ] = nCount ;
}
2011-06-04 18:54:03 -04:00
if ( it - > msgflags & RS_MSG_STAR ) {
2014-10-21 18:33:02 -04:00
+ + starredCount ;
2011-06-04 18:54:03 -04:00
}
2012-05-01 05:18:55 -04:00
if ( it - > msgflags & RS_MSG_SYSTEM ) {
2014-10-21 18:33:02 -04:00
+ + systemCount ;
2012-05-01 05:18:55 -04:00
}
2010-06-01 18:14:52 -04:00
/* calculate box */
2010-05-28 10:42:54 -04:00
if ( it - > msgflags & RS_MSG_TRASH ) {
2014-10-21 18:33:02 -04:00
+ + trashboxCount ;
2010-05-28 10:42:54 -04:00
continue ;
}
2010-05-23 13:21:30 -04:00
switch ( it - > msgflags & RS_MSG_BOXMASK ) {
case RS_MSG_INBOX :
2014-10-21 18:33:02 -04:00
+ + inboxCount ;
2010-08-22 18:12:26 -04:00
if ( it - > msgflags & ( RS_MSG_NEW | RS_MSG_UNREAD_BY_USER ) ) {
2014-10-21 18:33:02 -04:00
+ + newInboxCount ;
2010-05-23 13:21:30 -04:00
}
break ;
case RS_MSG_OUTBOX :
2014-10-21 18:33:02 -04:00
+ + newOutboxCount ;
2010-05-23 13:21:30 -04:00
break ;
case RS_MSG_DRAFTBOX :
2014-10-21 18:33:02 -04:00
+ + newDraftCount ;
2010-05-23 13:21:30 -04:00
break ;
case RS_MSG_SENTBOX :
2014-10-21 18:33:02 -04:00
+ + newSentboxCount ;
2010-05-23 13:21:30 -04:00
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 ) ;
2017-11-18 12:49:42 -05:00
ui . totalLabel - > setText ( textTotal ) ;
2010-06-12 11:11:42 -04:00
break ;
case ROW_OUTBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( newOutboxCount ) ;
2017-11-18 12:49:42 -05:00
ui . totalLabel - > setText ( textTotal ) ;
2010-06-12 11:11:42 -04:00
break ;
case ROW_DRAFTBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( newDraftCount ) ;
2017-11-18 12:49:42 -05:00
ui . totalLabel - > setText ( textTotal ) ;
2010-06-12 11:11:42 -04:00
break ;
case ROW_SENTBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( newSentboxCount ) ;
2017-11-18 12:49:42 -05:00
ui . totalLabel - > setText ( textTotal ) ;
2010-06-12 11:11:42 -04:00
break ;
case ROW_TRASHBOX :
textTotal = tr ( " Total: " ) + " " + QString : : number ( trashboxCount ) ;
2017-11-18 12:49:42 -05:00
ui . totalLabel - > setText ( textTotal ) ;
2010-06-12 11:11:42 -04:00
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 " ) ) ;
2012-11-19 11:01:21 -05:00
item - > setForeground ( QBrush ( mTextColorInbox ) ) ;
2010-05-23 13:21:30 -04:00
}
else
{
textItem = tr ( " Inbox " ) ;
item - > setText ( textItem ) ;
QFont qf = item - > font ( ) ;
qf . setBold ( false ) ;
item - > setFont ( qf ) ;
item - > setIcon ( QIcon ( " :/images/folder-inbox.png " ) ) ;
2014-10-09 18:04:12 -04:00
item - > setForeground ( QBrush ( ui . messageTreeWidget - > palette ( ) . color ( QPalette : : Text ) ) ) ;
2010-05-23 13:21:30 -04:00
}
//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 ( ) ;
2014-10-21 18:33:02 -04:00
for ( int row = 0 ; row < rowCount ; + + row ) {
2011-06-04 18:54:03 -04:00
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 ;
2012-05-01 05:18:55 -04:00
case QUICKVIEW_STATIC_ID_SYSTEM :
text + = " ( " + QString : : number ( systemCount ) + " ) " ;
break ;
2011-06-04 18:54:03 -04:00
}
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
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
2019-02-26 04:46:32 -05:00
QList < QString > msgids ;
getSelectedMessages ( msgids ) ;
2010-05-27 15:48:52 -04:00
2019-02-26 04:46:32 -05:00
if ( ! msgids . empty ( ) )
rsMail - > getMessageTag ( msgids . front ( ) . toStdString ( ) , 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
2019-02-26 04:46:32 -05:00
QList < QString > msgids ;
getSelectedMessages ( msgids ) ;
2010-05-27 15:48:52 -04:00
2019-02-26 04:46:32 -05:00
foreach ( const QString & s , msgids )
{
rsMail - > setMessageTag ( s . toStdString ( ) , 0 , false ) ;
2011-05-21 12:26:00 -04:00
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
2019-02-26 04:46:32 -05:00
QList < QString > msgids ;
getSelectedMessages ( msgids ) ;
2010-05-27 15:48:52 -04:00
2019-02-26 04:46:32 -05:00
foreach ( const QString & s , msgids )
if ( rsMail - > setMessageTag ( s . toStdString ( ) , tagId , set ) )
2011-05-21 12:26:00 -04:00
Lock . setUpdate ( true ) ;
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 ) ;
2019-02-26 04:46:32 -05:00
std : : list < Rs : : Msgs : : MsgInfoSummary > msgs ;
mMessageModel - > getMessageSummaries ( RsMessageModel : : BOX_TRASH , msgs ) ;
2010-10-29 16:57:23 -04:00
2019-02-26 04:46:32 -05:00
for ( auto it ( msgs . begin ( ) ) ; it ! = msgs . end ( ) ; + + it )
rsMail - > MessageDelete ( it - > msgId ) ;
2010-10-29 16:57:23 -04:00
// 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 ;
2014-10-21 18:33:02 -04:00
for ( int tab = 1 ; tab < ui . tabWidget - > count ( ) ; + + tab ) {
2011-06-03 20:46:02 -04:00
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 ( ) ;
2017-11-18 12:49:42 -05:00
ui . printButton - > disconnect ( ) ;
2011-06-03 20:46:02 -04:00
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 ) ;
2017-11-18 12:49:42 -05:00
msg - > connectAction ( MessageWidget : : ACTION_PRINT , ui . printButton ) ;
2011-06-03 20:46:02 -04:00
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 ( ) ;
2019-02-26 04:46:32 -05:00
if ( tab = = 0 )
{
QList < QString > msgs ;
count = getSelectedMessages ( msgs ) ;
}
else
{
2011-06-03 20:46:02 -04:00
MessageWidget * msg = dynamic_cast < MessageWidget * > ( ui . tabWidget - > widget ( tab ) ) ;
2019-02-26 04:46:32 -05:00
if ( msg & & msg - > msgId ( ) . empty ( ) = = false )
2011-06-03 20:46:02 -04:00
count = 1 ;
}
ui . replymessageButton - > setEnabled ( count = = 1 ) ;
ui . replyallmessageButton - > setEnabled ( count = = 1 ) ;
ui . forwardmessageButton - > setEnabled ( count = = 1 ) ;
2017-11-18 12:49:42 -05:00
ui . printButton - > setEnabled ( count = = 1 ) ;
2011-06-03 20:46:02 -04:00
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 ) ;
}