2007-11-14 22:18:48 -05:00
/****************************************************************
* RetroShare is distributed under the following license :
*
2007-11-18 18:35:53 -05:00
* Copyright ( C ) 2006 , 2007 RetroShare Team
2007-11-14 22:18:48 -05:00
*
* 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-09-27 17:05:52 -04:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2007-11-14 22:18:48 -05:00
* Boston , MA 02110 - 1301 , USA .
2008-11-25 20:19:09 -05:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-23 14:52:58 -04:00
# include <QMessageBox>
# include <QCloseEvent>
# include <QClipboard>
# include <QTextCodec>
# include <QPrintDialog>
# include <QPrinter>
# include <QTextList>
# include <QColorDialog>
# include <QTextDocumentFragment>
# include <QTimer>
2010-09-27 17:05:52 -04:00
# include <QCompleter>
2010-12-02 19:54:40 -05:00
# include <QItemDelegate>
2012-05-11 20:40:53 -04:00
# include <QDateTime>
# include <QFileInfo>
2012-11-15 16:35:37 -05:00
# include <QTextStream>
2010-07-23 14:52:58 -04:00
2010-09-24 07:38:46 -04:00
# include <algorithm>
2010-05-23 15:13:41 -04:00
# include "MessageComposer.h"
2008-11-25 20:19:09 -05:00
2010-08-06 05:40:23 -04:00
# include <retroshare/rsiface.h>
# include <retroshare/rspeers.h>
# include <retroshare/rsmsgs.h>
2010-09-27 17:05:52 -04:00
# include <retroshare/rsstatus.h>
2012-11-11 16:17:00 -05:00
# include <retroshare/rsfiles.h>
2014-03-29 10:18:05 -04:00
# include <retroshare/rsidentity.h>
2015-02-07 20:01:48 -05:00
# include <retroshare/rsgxschannels.h>
# include <retroshare/rsgxsforums.h>
2008-01-25 03:49:40 -05:00
2010-09-27 17:05:52 -04:00
# include "gui/notifyqt.h"
# include "gui/common/RSTreeWidgetItem.h"
# include "gui/common/GroupDefs.h"
# include "gui/common/StatusDefs.h"
2010-09-28 16:33:34 -04:00
# include "gui/common/PeerDefs.h"
2014-12-30 18:14:34 -05:00
# include "gui/common/TagDefs.h"
# include "gui/common/Emoticons.h"
2010-06-07 20:42:15 -04:00
# include "gui/RetroShareLink.h"
2010-09-27 17:05:52 -04:00
# include "gui/settings/rsharesettings.h"
2014-12-30 18:14:34 -05:00
# include "gui/connect/ConfCertDialog.h"
2015-01-24 14:27:19 -05:00
# include "gui/Identity/IdDetailsDialog.h"
2014-12-30 18:14:34 -05:00
# include "gui/gxs/GxsIdDetails.h"
2009-07-10 19:48:20 -04:00
# include "util/misc.h"
2012-11-15 16:35:37 -05:00
# include "util/DateTime.h"
2012-05-11 20:40:53 -04:00
# include "util/HandleRichText.h"
2013-10-19 09:25:06 -04:00
# include "util/QtVersion.h"
2014-12-30 18:14:34 -05:00
# include "textformat.h"
# include "TagsMenu.h"
2008-03-24 21:41:01 -04:00
2011-05-21 12:26:00 -04:00
# define IMAGE_GROUP16 ": / images / user / group16.png"
# define IMAGE_FRIENDINFO ": / images / peerdetails_16x16.png"
2010-09-27 17:05:52 -04:00
# define COLUMN_CONTACT_NAME 0
# define COLUMN_CONTACT_DATA 0
# define ROLE_CONTACT_ID Qt::UserRole
# define ROLE_CONTACT_SORT Qt::UserRole + 1
# define COLOR_CONNECT Qt::blue
# define COLUMN_RECIPIENT_TYPE 0
# define COLUMN_RECIPIENT_ICON 1
# define COLUMN_RECIPIENT_NAME 2
# define COLUMN_RECIPIENT_COUNT 3
# define COLUMN_RECIPIENT_DATA COLUMN_RECIPIENT_ICON // the column with a QTableWidgetItem
# define ROLE_RECIPIENT_ID Qt::UserRole
2014-03-29 10:18:05 -04:00
# define ROLE_RECIPIENT_TYPE Qt::UserRole + 1
2010-09-27 17:05:52 -04:00
2010-11-12 18:48:12 -05:00
# define COLUMN_FILE_CHECKED 0
# define COLUMN_FILE_NAME 0
# define COLUMN_FILE_SIZE 1
# define COLUMN_FILE_HASH 2
# define COLUMN_FILE_COUNT 3
2010-11-07 16:33:48 -05:00
2010-09-27 17:05:52 -04:00
# define STYLE_NORMAL "QLineEdit#%1 { border : none; }"
# define STYLE_FAIL "QLineEdit#%1 { border : none; color : red; }"
class MessageItemDelegate : public QItemDelegate
{
public :
MessageItemDelegate ( QObject * parent = 0 ) : QItemDelegate ( parent )
{
}
void paint ( QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const
{
QStyleOptionViewItem ownOption ( option ) ;
ownOption . state | = QStyle : : State_Enabled ; // the item is disabled to get no focus, but draw the icon as enabled (no grayscale)
QItemDelegate : : paint ( painter , ownOption , index ) ;
}
} ;
2008-11-25 20:19:09 -05:00
/** Constructor */
2013-10-18 17:10:33 -04:00
MessageComposer : : MessageComposer ( QWidget * parent , Qt : : WindowFlags flags )
2011-12-07 08:08:12 -05:00
: QMainWindow ( parent , flags )
2008-11-25 20:19:09 -05:00
{
2010-01-25 09:03:38 -05:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2010-06-14 14:16:32 -04:00
2010-11-02 17:11:11 -04:00
m_msgType = NORMAL ;
2012-05-01 05:18:55 -04:00
// needed to send system flags with reply
2012-05-05 18:20:05 -04:00
msgFlags = 0 ;
2010-11-02 17:11:11 -04:00
2010-01-25 09:03:38 -05:00
setupFileActions ( ) ;
setupEditActions ( ) ;
setupViewActions ( ) ;
setupInsertActions ( ) ;
2010-09-24 07:38:46 -04:00
2010-09-27 17:05:52 -04:00
m_compareRole = new RSTreeWidgetItemCompareRole ;
2010-12-15 16:32:44 -05:00
m_compareRole - > setRole ( COLUMN_CONTACT_NAME , ROLE_CONTACT_SORT ) ;
2010-09-27 17:05:52 -04:00
m_completer = NULL ;
2015-01-02 20:40:23 -05:00
ui . distantFrame - > hide ( ) ;
2015-03-27 18:16:12 -04:00
ui . respond_to_CB - > setEnabled ( false ) ;
ui . fromLabel - > setEnabled ( false ) ;
2010-09-27 17:05:52 -04:00
2010-05-20 17:53:27 -04:00
Settings - > loadWidgetInformation ( this ) ;
2010-01-25 09:03:38 -05:00
setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
2010-09-24 07:38:46 -04:00
2010-11-26 10:32:46 -05:00
ui . hashBox - > hide ( ) ;
2010-09-27 17:05:52 -04:00
// connect up the buttons.
2010-01-25 09:03:38 -05:00
connect ( ui . actionSend , SIGNAL ( triggered ( bool ) ) , this , SLOT ( sendMessage ( ) ) ) ;
//connect( ui.actionReply, SIGNAL( triggered (bool)), this, SLOT( replyMessage( ) ) );
connect ( ui . boldbtn , SIGNAL ( clicked ( ) ) , this , SLOT ( textBold ( ) ) ) ;
connect ( ui . underlinebtn , SIGNAL ( clicked ( ) ) , this , SLOT ( textUnderline ( ) ) ) ;
connect ( ui . italicbtn , SIGNAL ( clicked ( ) ) , this , SLOT ( textItalic ( ) ) ) ;
connect ( ui . colorbtn , SIGNAL ( clicked ( ) ) , this , SLOT ( textColor ( ) ) ) ;
connect ( ui . imagebtn , SIGNAL ( clicked ( ) ) , this , SLOT ( addImage ( ) ) ) ;
2010-11-10 08:35:38 -05:00
connect ( ui . emoticonButton , SIGNAL ( clicked ( ) ) , this , SLOT ( smileyWidget ( ) ) ) ;
2010-01-25 09:03:38 -05:00
//connect(ui.linkbtn, SIGNAL(clicked()), this, SLOT(insertLink()));
connect ( ui . actionContactsView , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleContacts ( ) ) ) ;
2010-05-25 09:22:42 -04:00
connect ( ui . actionSaveas , SIGNAL ( triggered ( ) ) , this , SLOT ( saveasDraft ( ) ) ) ;
2010-01-25 09:03:38 -05:00
connect ( ui . actionAttach , SIGNAL ( triggered ( ) ) , this , SLOT ( attachFile ( ) ) ) ;
2010-07-07 19:03:34 -04:00
connect ( ui . titleEdit , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( titleChanged ( ) ) ) ;
2010-01-25 09:03:38 -05:00
connect ( ui . sizeincreaseButton , SIGNAL ( clicked ( ) ) , this , SLOT ( fontSizeIncrease ( ) ) ) ;
connect ( ui . sizedecreaseButton , SIGNAL ( clicked ( ) ) , this , SLOT ( fontSizeDecrease ( ) ) ) ;
2010-01-25 15:16:54 -05:00
connect ( ui . actionQuote , SIGNAL ( triggered ( ) ) , this , SLOT ( blockQuote ( ) ) ) ;
2010-01-25 09:03:38 -05:00
connect ( ui . codeButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleCode ( ) ) ) ;
2010-01-25 10:36:24 -05:00
2010-01-25 15:16:54 -05:00
connect ( ui . msgText , SIGNAL ( checkSpellingChanged ( bool ) ) , this , SLOT ( spellChecking ( bool ) ) ) ;
2010-09-24 07:38:46 -04:00
connect ( ui . msgText , SIGNAL ( currentCharFormatChanged ( const QTextCharFormat & ) ) , this , SLOT ( currentCharFormatChanged ( const QTextCharFormat & ) ) ) ;
connect ( ui . msgText , SIGNAL ( cursorPositionChanged ( ) ) , this , SLOT ( cursorPositionChanged ( ) ) ) ;
connect ( ui . msgText - > document ( ) , SIGNAL ( modificationChanged ( bool ) ) , actionSave , SLOT ( setEnabled ( bool ) ) ) ;
connect ( ui . msgText - > document ( ) , SIGNAL ( modificationChanged ( bool ) ) , this , SLOT ( setWindowModified ( bool ) ) ) ;
connect ( ui . msgText - > document ( ) , SIGNAL ( undoAvailable ( bool ) ) , actionUndo , SLOT ( setEnabled ( bool ) ) ) ;
connect ( ui . msgText - > document ( ) , SIGNAL ( redoAvailable ( bool ) ) , actionRedo , SLOT ( setEnabled ( bool ) ) ) ;
2008-11-25 20:19:09 -05:00
2010-11-21 16:12:35 -05:00
connect ( ui . msgFileList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenuFileList ( QPoint ) ) ) ;
2011-12-07 08:08:12 -05:00
connect ( ui . hashBox , SIGNAL ( fileHashingStarted ( ) ) , this , SLOT ( fileHashingStarted ( ) ) ) ;
connect ( ui . hashBox , SIGNAL ( fileHashingFinished ( QList < HashedFile > ) ) , this , SLOT ( fileHashingFinished ( QList < HashedFile > ) ) ) ;
2008-11-25 20:19:09 -05:00
setWindowModified ( ui . msgText - > document ( ) - > isModified ( ) ) ;
actionSave - > setEnabled ( ui . msgText - > document ( ) - > isModified ( ) ) ;
actionUndo - > setEnabled ( ui . msgText - > document ( ) - > isUndoAvailable ( ) ) ;
actionRedo - > setEnabled ( ui . msgText - > document ( ) - > isRedoAvailable ( ) ) ;
connect ( actionUndo , SIGNAL ( triggered ( ) ) , ui . msgText , SLOT ( undo ( ) ) ) ;
connect ( actionRedo , SIGNAL ( triggered ( ) ) , ui . msgText , SLOT ( redo ( ) ) ) ;
actionCut - > setEnabled ( false ) ;
actionCopy - > setEnabled ( false ) ;
connect ( actionCut , SIGNAL ( triggered ( ) ) , ui . msgText , SLOT ( cut ( ) ) ) ;
connect ( actionCopy , SIGNAL ( triggered ( ) ) , ui . msgText , SLOT ( copy ( ) ) ) ;
connect ( actionPaste , SIGNAL ( triggered ( ) ) , ui . msgText , SLOT ( paste ( ) ) ) ;
connect ( ui . msgText , SIGNAL ( copyAvailable ( bool ) ) , actionCut , SLOT ( setEnabled ( bool ) ) ) ;
connect ( ui . msgText , SIGNAL ( copyAvailable ( bool ) ) , actionCopy , SLOT ( setEnabled ( bool ) ) ) ;
2008-03-24 21:41:01 -04:00
connect ( QApplication : : clipboard ( ) , SIGNAL ( dataChanged ( ) ) , this , SLOT ( clipboardDataChanged ( ) ) ) ;
2015-01-10 19:53:16 -05:00
connect ( ui . filterComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( filterComboBoxChanged ( int ) ) ) ;
2013-09-07 10:02:24 -04:00
2011-05-21 12:26:00 -04:00
connect ( ui . addToButton , SIGNAL ( clicked ( void ) ) , this , SLOT ( addTo ( ) ) ) ;
connect ( ui . addCcButton , SIGNAL ( clicked ( void ) ) , this , SLOT ( addCc ( ) ) ) ;
connect ( ui . addBccButton , SIGNAL ( clicked ( void ) ) , this , SLOT ( addBcc ( ) ) ) ;
connect ( ui . addRecommendButton , SIGNAL ( clicked ( void ) ) , this , SLOT ( addRecommend ( ) ) ) ;
2010-09-27 17:05:52 -04:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerStatusChanged ( const QString & , int ) ) , this , SLOT ( peerStatusChanged ( const QString & , int ) ) ) ;
2012-01-26 19:32:17 -05:00
connect ( ui . friendSelectionWidget , SIGNAL ( contentChanged ( ) ) , this , SLOT ( buildCompleter ( ) ) ) ;
connect ( ui . friendSelectionWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenuMsgSendList ( QPoint ) ) ) ;
2013-01-22 19:22:17 -05:00
connect ( ui . friendSelectionWidget , SIGNAL ( doubleClicked ( int , QString ) ) , this , SLOT ( addTo ( ) ) ) ;
2010-09-27 17:05:52 -04:00
2010-01-25 09:03:38 -05:00
/* hide the Tree +/- */
ui . msgFileList - > setRootIsDecorated ( false ) ;
2010-09-24 07:38:46 -04:00
2012-01-26 19:32:17 -05:00
/* initialize friends list */
ui . friendSelectionWidget - > setHeaderText ( tr ( " Send To: " ) ) ;
ui . friendSelectionWidget - > setModus ( FriendSelectionWidget : : MODUS_MULTI ) ;
2015-03-27 18:16:12 -04:00
ui . friendSelectionWidget - > setShowType ( //FriendSelectionWidget::SHOW_GROUP // removed this because it's too confusing.
FriendSelectionWidget : : SHOW_SSL
2015-01-10 19:53:16 -05:00
| FriendSelectionWidget : : SHOW_GXS ) ;
2012-01-26 19:32:17 -05:00
ui . friendSelectionWidget - > start ( ) ;
2010-07-12 10:01:29 -04:00
2008-11-25 20:19:09 -05:00
QActionGroup * grp = new QActionGroup ( this ) ;
connect ( grp , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( textAlign ( QAction * ) ) ) ;
actionAlignLeft = new QAction ( QIcon ( " :/images/textedit/textleft.png " ) , tr ( " &Left " ) , grp ) ;
actionAlignLeft - > setShortcut ( Qt : : CTRL + Qt : : Key_L ) ;
actionAlignLeft - > setCheckable ( true ) ;
actionAlignCenter = new QAction ( QIcon ( " :/images/textedit/textcenter.png " ) , tr ( " C&enter " ) , grp ) ;
actionAlignCenter - > setShortcut ( Qt : : CTRL + Qt : : Key_E ) ;
actionAlignCenter - > setCheckable ( true ) ;
actionAlignRight = new QAction ( QIcon ( " :/images/textedit/textright.png " ) , tr ( " &Right " ) , grp ) ;
actionAlignRight - > setShortcut ( Qt : : CTRL + Qt : : Key_R ) ;
actionAlignRight - > setCheckable ( true ) ;
actionAlignJustify = new QAction ( QIcon ( " :/images/textedit/textjustify.png " ) , tr ( " &Justify " ) , grp ) ;
actionAlignJustify - > setShortcut ( Qt : : CTRL + Qt : : Key_J ) ;
2008-03-24 13:36:17 -04:00
actionAlignJustify - > setCheckable ( true ) ;
2010-09-27 17:05:52 -04:00
2010-05-25 18:30:25 -04:00
setupFormatActions ( ) ;
2010-09-27 17:05:52 -04:00
2014-11-24 16:02:18 -05:00
ui . respond_to_CB - > setFlags ( IDCHOOSER_ID_REQUIRED ) ;
2015-01-10 19:53:16 -05:00
/* Add filter types */
ui . filterComboBox - > addItem ( tr ( " All " ) ) ;
2015-01-12 07:01:20 -05:00
ui . filterComboBox - > addItem ( tr ( " Friend Nodes " ) ) ;
2015-03-28 11:49:43 -04:00
ui . filterComboBox - > addItem ( tr ( " Distant peer identities " ) ) ;
2015-01-10 19:53:16 -05:00
ui . filterComboBox - > setCurrentIndex ( 0 ) ;
2010-09-27 17:05:52 -04:00
2015-01-12 07:01:20 -05:00
/*ui.comboStyle->addItem("Standard");
ui . comboStyle - > addItem ( " Bullet List (Disc) " ) ;
ui . comboStyle - > addItem ( " Bullet List (Circle) " ) ;
ui . comboStyle - > addItem ( " Bullet List (Square) " ) ;
ui . comboStyle - > addItem ( " Ordered List (Decimal) " ) ;
ui . comboStyle - > addItem ( " Ordered List (Alpha lower) " ) ;
ui . comboStyle - > addItem ( " Ordered List (Alpha upper) " ) ; */
//connect(ui.comboStyle, SIGNAL(activated(int)),this, SLOT(textStyle(int)));
2014-11-24 16:02:18 -05:00
connect ( ui . comboStyle , SIGNAL ( activated ( int ) ) , this , SLOT ( changeFormatType ( int ) ) ) ;
connect ( ui . comboFont , SIGNAL ( activated ( const QString & ) ) , this , SLOT ( textFamily ( const QString & ) ) ) ;
2010-09-27 17:05:52 -04:00
2008-11-25 20:19:09 -05:00
ui . comboSize - > setEditable ( true ) ;
QFontDatabase db ;
foreach ( int size , db . standardSizes ( ) )
2015-01-10 19:53:16 -05:00
ui . comboSize - > addItem ( QString : : number ( size ) ) ;
2008-11-25 20:19:09 -05:00
connect ( ui . comboSize , SIGNAL ( activated ( const QString & ) ) , this , SLOT ( textSize ( const QString & ) ) ) ;
2008-03-24 13:36:17 -04:00
ui . comboSize - > setCurrentIndex ( ui . comboSize - > findText ( QString : : number ( QApplication : : font ( ) . pointSize ( ) ) ) ) ;
2010-09-27 17:05:52 -04:00
ui . textalignmentbtn - > setIcon ( QIcon ( QString ( " :/images/textedit/textcenter.png " ) ) ) ;
2010-09-24 07:38:46 -04:00
2008-11-25 20:19:09 -05:00
QMenu * alignmentmenu = new QMenu ( ) ;
alignmentmenu - > addAction ( actionAlignLeft ) ;
alignmentmenu - > addAction ( actionAlignCenter ) ;
alignmentmenu - > addAction ( actionAlignRight ) ;
alignmentmenu - > addAction ( actionAlignJustify ) ;
2008-03-24 13:36:17 -04:00
ui . textalignmentbtn - > setMenu ( alignmentmenu ) ;
2010-09-27 17:05:52 -04:00
2009-07-10 19:48:20 -04:00
QPixmap pxm ( 24 , 24 ) ;
pxm . fill ( Qt : : black ) ;
ui . colorbtn - > setIcon ( pxm ) ;
2010-09-24 07:38:46 -04:00
/* Set header resize modes and initial section sizes */
2010-09-27 17:05:52 -04:00
QHeaderView * _smheader = ui . msgFileList - > header ( ) ;
2010-09-24 07:38:46 -04:00
2010-11-07 16:33:48 -05:00
_smheader - > resizeSection ( COLUMN_FILE_NAME , 200 ) ;
_smheader - > resizeSection ( COLUMN_FILE_SIZE , 60 ) ;
_smheader - > resizeSection ( COLUMN_FILE_HASH , 220 ) ;
2010-09-27 17:05:52 -04:00
2010-01-25 09:03:38 -05:00
QPalette palette = QApplication : : palette ( ) ;
codeBackground = palette . color ( QPalette : : Active , QPalette : : Midlight ) ;
2010-09-27 17:05:52 -04:00
ui . recipientWidget - > setColumnCount ( COLUMN_RECIPIENT_COUNT ) ;
QHeaderView * header = ui . recipientWidget - > horizontalHeader ( ) ;
2015-03-27 18:57:58 -04:00
header - > resizeSection ( COLUMN_RECIPIENT_TYPE , 60 ) ;
2010-09-27 17:05:52 -04:00
header - > resizeSection ( COLUMN_RECIPIENT_ICON , 22 ) ;
2013-10-19 09:25:06 -04:00
QHeaderView_setSectionResizeMode ( header , COLUMN_RECIPIENT_TYPE , QHeaderView : : Fixed ) ;
QHeaderView_setSectionResizeMode ( header , COLUMN_RECIPIENT_ICON , QHeaderView : : Fixed ) ;
2015-03-27 18:16:12 -04:00
QHeaderView_setSectionResizeMode ( header , COLUMN_RECIPIENT_NAME , QHeaderView : : Fixed ) ;
2010-09-27 17:05:52 -04:00
header - > setStretchLastSection ( true ) ;
/* Set own item delegate */
QItemDelegate * delegate = new MessageItemDelegate ( this ) ;
ui . recipientWidget - > setItemDelegateForColumn ( COLUMN_RECIPIENT_ICON , delegate ) ;
2015-03-27 18:16:12 -04:00
connect ( ui . recipientWidget , SIGNAL ( cellChanged ( int , int ) ) , this , SLOT ( updateCells ( int , int ) ) ) ;
2010-09-27 17:05:52 -04:00
addEmptyRecipient ( ) ;
// load settings
processSettings ( true ) ;
2012-01-26 19:32:17 -05:00
buildCompleter ( ) ;
2010-11-02 17:11:11 -04:00
2010-07-12 10:01:29 -04:00
/* set focus to subject */
ui . titleEdit - > setFocus ( ) ;
2011-05-21 12:26:00 -04:00
// create tag menu
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 ) ;
2010-11-16 04:31:30 -05:00
setAcceptDrops ( true ) ;
2011-12-07 08:08:12 -05:00
ui . hashBox - > setDropWidget ( this ) ;
ui . hashBox - > setAutoHide ( true ) ;
2010-11-16 04:31:30 -05:00
2013-01-21 19:14:10 -05:00
# if QT_VERSION < 0x040700
// embedded images are not supported before QT 4.7.0
2010-11-17 07:45:46 -05:00
ui . imagebtn - > setVisible ( false ) ;
2013-01-21 19:14:10 -05:00
# endif
2010-11-17 07:45:46 -05:00
2010-09-24 07:38:46 -04:00
/* Hide platform specific features */
2008-11-25 20:19:09 -05:00
# ifdef Q_WS_WIN
# endif
}
2010-09-27 17:05:52 -04:00
MessageComposer : : ~ MessageComposer ( )
2010-06-17 13:39:32 -04:00
{
2010-09-27 17:05:52 -04:00
delete ( m_compareRole ) ;
}
2010-06-17 13:39:32 -04:00
2015-03-27 18:16:12 -04:00
void MessageComposer : : updateCells ( int , int )
{
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
bool has_gxs = false ;
for ( row = 0 ; row < rowCount ; + + row )
{
enumType type ;
destinationType dtype ;
std : : string id ;
if ( getRecipientFromRow ( row , type , dtype , id ) & & ! id . empty ( ) )
if ( dtype = = PEER_TYPE_GXS )
has_gxs = true ;
}
if ( has_gxs )
{
ui . respond_to_CB - > setEnabled ( true ) ;
ui . distantFrame - > show ( ) ;
ui . fromLabel - > setEnabled ( true ) ;
}
else
{
ui . respond_to_CB - > setEnabled ( false ) ;
ui . distantFrame - > hide ( ) ;
ui . fromLabel - > setEnabled ( false ) ;
}
}
2010-09-27 17:05:52 -04:00
void MessageComposer : : processSettings ( bool bLoad )
{
Settings - > beginGroup ( QString ( " MessageComposer " ) ) ;
2010-09-24 07:38:46 -04:00
2010-09-27 17:05:52 -04:00
if ( bLoad ) {
// load settings
2010-06-17 13:39:32 -04:00
2010-09-27 17:05:52 -04:00
// state of contact sidebar
ui . contactsdockWidget - > setVisible ( Settings - > value ( " ContactSidebar " , true ) . toBool ( ) ) ;
2010-09-24 07:38:46 -04:00
2010-09-27 17:05:52 -04:00
// state of splitter
ui . splitter - > restoreState ( Settings - > value ( " Splitter " ) . toByteArray ( ) ) ;
ui . splitter_2 - > restoreState ( Settings - > value ( " Splitter2 " ) . toByteArray ( ) ) ;
2015-01-10 19:53:16 -05:00
// state of filter combobox
int index = Settings - > value ( " ShowType " , 0 ) . toInt ( ) ;
ui . filterComboBox - > setCurrentIndex ( index ) ;
2010-09-27 17:05:52 -04:00
} else {
// save settings
2010-06-17 13:39:32 -04:00
2010-09-27 17:05:52 -04:00
// state of contact sidebar
Settings - > setValue ( " ContactSidebar " , ui . contactsdockWidget - > isVisible ( ) ) ;
// state of splitter
Settings - > setValue ( " Splitter " , ui . splitter - > saveState ( ) ) ;
Settings - > setValue ( " Splitter2 " , ui . splitter_2 - > saveState ( ) ) ;
2015-01-10 19:53:16 -05:00
// state of filter combobox
Settings - > setValue ( " ShowType " , ui . filterComboBox - > currentIndex ( ) ) ;
2010-09-27 17:05:52 -04:00
}
Settings - > endGroup ( ) ;
2010-06-17 13:39:32 -04:00
}
2014-03-29 10:18:05 -04:00
/*static*/ void MessageComposer : : msgGxsIdentity ( const RsGxsId & id )
2013-04-29 18:32:58 -04:00
{
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
/* create a message */
MessageComposer * pMsgDialog = MessageComposer : : newMsg ( ) ;
2014-03-29 10:18:05 -04:00
if ( pMsgDialog = = NULL )
2013-04-29 18:32:58 -04:00
return ;
2014-03-29 10:18:05 -04:00
pMsgDialog - > addRecipient ( TO , id ) ;
2013-04-29 18:32:58 -04:00
pMsgDialog - > show ( ) ;
/* window will destroy itself! */
}
2014-03-29 10:18:05 -04:00
/*static*/ void MessageComposer : : msgFriend ( const RsPeerId & id )
2010-07-15 07:25:34 -04:00
{
2014-03-29 10:18:05 -04:00
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
2010-07-15 07:25:34 -04:00
/* create a message */
2010-09-27 17:05:52 -04:00
2010-11-02 17:11:11 -04:00
MessageComposer * pMsgDialog = MessageComposer : : newMsg ( ) ;
if ( pMsgDialog = = NULL ) {
return ;
}
2010-07-15 07:25:34 -04:00
2014-03-29 10:18:05 -04:00
RsPeerDetails detail ;
if ( rsPeers - > getPeerDetails ( id , detail ) & & detail . accept_connection )
2014-03-17 16:56:06 -04:00
{
2014-03-29 10:18:05 -04:00
pMsgDialog - > addRecipient ( TO , id ) ;
2010-09-27 17:05:52 -04:00
}
pMsgDialog - > show ( ) ;
/* window will destroy itself! */
}
2014-03-17 16:56:06 -04:00
static QString buildRecommendHtml ( const std : : list < RsPeerId > & sslIds , const RsPeerId & excludeId = RsPeerId ( ) )
2010-09-27 17:05:52 -04:00
{
QString text ;
2010-07-15 07:25:34 -04:00
2012-01-23 17:38:50 -05:00
/* process ssl ids */
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > : : const_iterator sslIt ;
2014-10-21 18:33:02 -04:00
for ( sslIt = sslIds . begin ( ) ; sslIt ! = sslIds . end ( ) ; + + sslIt ) {
2012-02-09 14:18:15 -05:00
if ( * sslIt = = excludeId ) {
continue ;
}
2011-05-04 06:22:49 -04:00
RetroShareLink link ;
2012-01-23 17:38:50 -05:00
if ( link . createCertificate ( * sslIt ) ) {
2011-05-12 15:37:13 -04:00
text + = link . toHtml ( ) + " <br> " ;
2010-07-15 07:25:34 -04:00
}
2010-09-27 17:05:52 -04:00
}
return text ;
}
2010-07-15 07:25:34 -04:00
2012-02-09 14:18:15 -05:00
QString MessageComposer : : recommendMessage ( )
{
2012-10-04 17:19:49 -04:00
return tr ( " Hello,<br>I recommend a good friend of mine; you can trust them too when you trust me. <br> " ) ;
2012-02-09 14:18:15 -05:00
}
2014-03-17 16:56:06 -04:00
void MessageComposer : : recommendFriend ( const std : : list < RsPeerId > & sslIds , const RsPeerId & to , const QString & msg , bool autoSend )
2010-09-27 17:05:52 -04:00
{
// std::cerr << "MessageComposer::recommendFriend()" << std::endl;
2014-10-21 18:33:02 -04:00
if ( sslIds . empty ( ) ) {
2010-09-27 17:05:52 -04:00
return ;
2010-07-15 07:25:34 -04:00
}
2010-09-27 17:05:52 -04:00
2012-02-09 14:18:15 -05:00
QString recommendHtml = buildRecommendHtml ( sslIds , to ) ;
if ( recommendHtml . isEmpty ( ) ) {
return ;
}
2010-09-27 17:05:52 -04:00
/* create a message */
2012-05-05 18:20:05 -04:00
MessageComposer * composer = MessageComposer : : newMsg ( ) ;
2010-09-27 17:05:52 -04:00
2012-05-05 18:20:05 -04:00
composer - > setTitleText ( tr ( " You have a friend recommendation " ) ) ;
composer - > msgFlags | = RS_MSG_FRIEND_RECOMMENDATION ;
2010-09-27 17:05:52 -04:00
2014-03-17 16:56:06 -04:00
if ( ! to . isNull ( ) ) {
2014-03-29 10:18:05 -04:00
composer - > addRecipient ( TO , to ) ;
2012-02-09 14:18:15 -05:00
}
2014-03-17 16:56:06 -04:00
RsPgpId ownPgpId = rsPeers - > getGPGOwnId ( ) ;
2012-05-14 10:14:38 -04:00
RetroShareLink link ;
2014-03-17 16:56:06 -04:00
link . createPerson ( ownPgpId ) ;
2012-05-14 10:14:38 -04:00
2012-02-09 14:18:15 -05:00
QString sMsgText = msg . isEmpty ( ) ? recommendMessage ( ) : msg ;
2010-09-27 17:05:52 -04:00
sMsgText + = " <br><br> " ;
2012-02-09 14:18:15 -05:00
sMsgText + = recommendHtml ;
2012-05-14 10:14:38 -04:00
sMsgText + = " <br> " ;
sMsgText + = tr ( " This friend is suggested by " ) + " " + link . toHtml ( ) + " <br><br> " ;
2015-02-19 15:32:09 -05:00
sMsgText + = tr ( " Thanks, <br> " ) + QString : : fromUtf8 ( rsPeers - > getGPGName ( rsPeers - > getGPGOwnId ( ) ) . c_str ( ) ) ;
2012-05-05 18:20:05 -04:00
composer - > setMsgText ( sMsgText ) ;
2010-07-15 07:25:34 -04:00
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > : : const_iterator peerIt ;
2014-10-21 18:33:02 -04:00
for ( peerIt = sslIds . begin ( ) ; peerIt ! = sslIds . end ( ) ; + + peerIt ) {
2012-02-09 14:18:15 -05:00
if ( * peerIt = = to ) {
continue ;
}
2014-03-29 10:18:05 -04:00
composer - > addRecipient ( CC , * peerIt ) ;
2011-06-14 16:42:32 -04:00
}
2012-02-09 14:18:15 -05:00
if ( autoSend ) {
2012-05-05 18:20:05 -04:00
if ( composer - > sendMessage_internal ( false ) ) {
composer - > close ( ) ;
2012-02-09 14:18:15 -05:00
return ;
}
}
2012-05-05 18:20:05 -04:00
composer - > show ( ) ;
2010-07-15 07:25:34 -04:00
/* window will destroy itself! */
}
2015-03-25 04:19:45 -04:00
void MessageComposer : : sendConnectAttemptMsg ( const RsPgpId & gpgId , const RsPeerId & sslId , const QString & /*sslName*/ )
2012-04-26 19:41:14 -04:00
{
2014-03-17 16:56:06 -04:00
if ( gpgId . isNull ( ) ) {
2012-04-26 19:41:14 -04:00
return ;
}
2012-05-01 05:18:55 -04:00
RetroShareLink link ;
if ( link . createUnknwonSslCertificate ( sslId , gpgId ) = = false ) {
return ;
}
2015-03-25 04:19:45 -04:00
QString title = QString ( " %1 %2 " ) . arg ( link . name ( ) , tr ( " wants to be friends with you on RetroShare " ) ) ;
2012-04-26 19:41:14 -04:00
/* search for an exisiting message in the inbox */
std : : list < MsgInfoSummary > msgList ;
std : : list < MsgInfoSummary > : : const_iterator it ;
2015-03-22 00:52:53 -04:00
rsMail - > getMessageSummaries ( msgList ) ;
2014-10-21 18:33:02 -04:00
for ( it = msgList . begin ( ) ; it ! = msgList . end ( ) ; + + it ) {
2012-04-26 19:41:14 -04:00
if ( it - > msgflags & RS_MSG_TRASH ) {
continue ;
}
if ( ( it - > msgflags & RS_MSG_BOXMASK ) ! = RS_MSG_INBOX ) {
continue ;
}
2012-05-01 05:18:55 -04:00
if ( ( it - > msgflags & RS_MSG_USER_REQUEST ) = = 0 ) {
continue ;
}
2013-10-03 17:41:34 -04:00
if ( it - > title = = title . toUtf8 ( ) . constData ( ) ) {
2012-04-26 19:41:14 -04:00
return ;
}
}
/* create a message */
2015-03-25 04:19:45 -04:00
QString msgText = tr ( " Hi %1,<br><br>%2 wants to be friends with you on RetroShare.<br><br>Respond now:<br>%3<br><br>Thanks,<br>The RetroShare Team " ) . arg ( QString : : fromUtf8 ( rsPeers - > getGPGName ( rsPeers - > getGPGOwnId ( ) ) . c_str ( ) ) , link . name ( ) , link . toHtml ( ) ) ;
2015-03-22 00:52:53 -04:00
rsMail - > SystemMessage ( title . toUtf8 ( ) . constData ( ) , msgText . toUtf8 ( ) . constData ( ) , RS_MSG_USER_REQUEST ) ;
2012-04-26 19:41:14 -04:00
}
2015-02-07 20:01:48 -05:00
void MessageComposer : : sendChannelPublishKey ( RsGxsChannelGroup & group )
{
// QString channelName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
// RetroShareLink link;
// if (!link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, group.mMeta.mGroupId, channelName)) {
// return;
// }
// QString title = tr("Publish key for channel %1").arg(channelName);
// /* create a message */
// QString msgText = tr("... %1 ...<br>%2").arg(channelName, link.toHtml());
2015-03-22 00:52:53 -04:00
// rsMail->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_PUBLISH_KEY);
2015-02-07 20:01:48 -05:00
}
void MessageComposer : : sendForumPublishKey ( RsGxsForumGroup & group )
{
// QString forumName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
// RetroShareLink link;
// if (!link.createGxsGroupLink(RetroShareLink::TYPE_FORUM, group.mMeta.mGroupId, forumName)) {
// return;
// }
// QString title = tr("Publish key for forum %1").arg(forumName);
// /* create a message */
// QString msgText = tr("... %1 ...<br>%2").arg(forumName, link.toHtml());
2015-03-22 00:52:53 -04:00
// rsMail->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_PUBLISH_KEY);
2015-02-07 20:01:48 -05:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : closeEvent ( QCloseEvent * event )
2007-11-18 18:35:53 -05:00
{
2010-05-25 05:32:14 -04:00
bool bClose = true ;
/* Save to Drafts? */
if ( ui . msgText - > document ( ) - > isModified ( ) ) {
QMessageBox : : StandardButton ret ;
ret = QMessageBox : : warning ( this , tr ( " Save Message " ) ,
tr ( " Message has not been Sent. \n "
" Do you want to save message to draft box? " ) ,
QMessageBox : : Yes | QMessageBox : : No | QMessageBox : : Cancel ) ;
switch ( ret ) {
case QMessageBox : : Yes :
sendMessage_internal ( true ) ;
break ;
case QMessageBox : : Cancel :
bClose = false ;
break ;
default :
break ;
}
}
2009-02-11 13:43:37 -05:00
2010-05-25 05:32:14 -04:00
if ( bClose ) {
Settings - > saveWidgetInformation ( this ) ;
2009-02-11 13:43:37 -05:00
2010-09-27 17:05:52 -04:00
// save settings
processSettings ( false ) ;
2010-05-25 05:32:14 -04:00
QMainWindow : : closeEvent ( event ) ;
} else {
event - > ignore ( ) ;
2008-03-31 17:02:12 -04:00
}
2007-11-18 18:35:53 -05:00
}
2007-11-14 22:18:48 -05:00
2010-11-21 16:12:35 -05:00
void MessageComposer : : contextMenuFileList ( QPoint )
{
QMenu contextMnu ( this ) ;
QAction * action = contextMnu . addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste RetroShare Link " ) , this , SLOT ( pasteRecommended ( ) ) ) ;
action - > setDisabled ( RSLinkClipboard : : empty ( RetroShareLink : : TYPE_FILE ) ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
2011-05-21 12:26:00 -04:00
void MessageComposer : : contextMenuMsgSendList ( QPoint )
{
2012-01-26 19:32:17 -05:00
QMenu contextMnu ( this ) ;
int selectedCount = ui . friendSelectionWidget - > selectedItemCount ( ) ;
2011-05-21 12:26:00 -04:00
2012-01-26 19:32:17 -05:00
FriendSelectionWidget : : IdType idType ;
ui . friendSelectionWidget - > selectedId ( idType ) ;
2011-05-21 12:26:00 -04:00
QAction * action = contextMnu . addAction ( QIcon ( ) , tr ( " Add to \" To \" " ) , this , SLOT ( addTo ( ) ) ) ;
action - > setEnabled ( selectedCount ) ;
action = contextMnu . addAction ( QIcon ( ) , tr ( " Add to \" CC \" " ) , this , SLOT ( addCc ( ) ) ) ;
action - > setEnabled ( selectedCount ) ;
action = contextMnu . addAction ( QIcon ( ) , tr ( " Add to \" BCC \" " ) , this , SLOT ( addBcc ( ) ) ) ;
action - > setEnabled ( selectedCount ) ;
action = contextMnu . addAction ( QIcon ( ) , tr ( " Add as Recommend " ) , this , SLOT ( addRecommend ( ) ) ) ;
action - > setEnabled ( selectedCount ) ;
contextMnu . addSeparator ( ) ;
action = contextMnu . addAction ( QIcon ( IMAGE_FRIENDINFO ) , tr ( " Friend Details " ) , this , SLOT ( friendDetails ( ) ) ) ;
2015-01-25 09:14:03 -05:00
action - > setEnabled ( selectedCount = = 1 & & idType = = FriendSelectionWidget : : IDTYPE_SSL ) ;
2011-05-21 12:26:00 -04:00
2015-01-24 14:27:19 -05:00
action = contextMnu . addAction ( QIcon ( ) , tr ( " Person Details " ) , this , SLOT ( identityDetails ( ) ) ) ;
2015-01-25 09:14:03 -05:00
action - > setEnabled ( selectedCount = = 1 & & idType = = FriendSelectionWidget : : IDTYPE_GXS ) ;
2015-01-24 14:27:19 -05:00
2012-01-26 19:32:17 -05:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2011-05-21 12:26:00 -04:00
}
2010-11-21 16:12:35 -05:00
void MessageComposer : : pasteRecommended ( )
{
2011-09-11 18:07:24 -04:00
QList < RetroShareLink > links ;
2010-11-21 16:12:35 -05:00
RSLinkClipboard : : pasteLinks ( links ) ;
2014-10-21 18:33:02 -04:00
for ( int i = 0 ; i < links . size ( ) ; + + i ) {
2010-11-21 16:12:35 -05:00
if ( links [ i ] . valid ( ) & & links [ i ] . type ( ) = = RetroShareLink : : TYPE_FILE ) {
FileInfo fileInfo ;
fileInfo . fname = links [ i ] . name ( ) . toStdString ( ) ;
2014-04-20 12:34:26 -04:00
fileInfo . hash = RsFileHash ( links [ i ] . hash ( ) . toStdString ( ) ) ;
2010-11-21 16:12:35 -05:00
fileInfo . size = links [ i ] . size ( ) ;
addFile ( fileInfo ) ;
}
}
}
2010-09-27 17:05:52 -04:00
static void setNewCompleter ( QTableWidget * tableWidget , QCompleter * completer )
2007-11-14 22:18:48 -05:00
{
2010-09-27 17:05:52 -04:00
int rowCount = tableWidget - > rowCount ( ) ;
int row ;
2007-11-14 22:18:48 -05:00
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row ) {
2010-09-27 17:05:52 -04:00
QLineEdit * lineEdit = dynamic_cast < QLineEdit * > ( tableWidget - > cellWidget ( row , COLUMN_RECIPIENT_NAME ) ) ;
if ( lineEdit ) {
lineEdit - > setCompleter ( completer ) ;
}
}
}
2012-01-26 19:32:17 -05:00
void MessageComposer : : buildCompleter ( )
2010-09-27 17:05:52 -04:00
{
// get existing groups
std : : list < RsGroupInfo > groupInfoList ;
std : : list < RsGroupInfo > : : iterator groupIt ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
2015-01-12 07:01:20 -05:00
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > peers ;
std : : list < RsPeerId > : : iterator peerIt ;
2010-09-27 17:05:52 -04:00
rsPeers - > getFriendList ( peers ) ;
2015-01-12 07:01:20 -05:00
std : : list < RsGxsId > gxsIds ;
2015-03-27 18:57:58 -04:00
QList < QTreeWidgetItem * > gxsitems ;
ui . friendSelectionWidget - > items ( gxsitems , FriendSelectionWidget : : IDTYPE_GXS ) ;
2010-09-27 17:05:52 -04:00
// create completer list for friends
QStringList completerList ;
QStringList completerGroupList ;
2015-01-12 07:01:20 -05:00
2015-03-27 18:57:58 -04:00
for ( QList < QTreeWidgetItem * > : : const_iterator idIt = gxsitems . begin ( ) ; idIt ! = gxsitems . end ( ) ; + + idIt )
{
RsGxsId id ( ui . friendSelectionWidget - > idFromItem ( * idIt ) ) ;
RsIdentityDetails detail ;
if ( rsIdentity - > getIdDetails ( id , detail ) )
2015-03-28 11:46:47 -04:00
completerList . append ( getRecipientEmailAddress ( id , detail ) ) ;
2015-03-27 18:57:58 -04:00
}
2007-11-14 22:18:48 -05:00
2015-03-28 11:46:47 -04:00
for ( peerIt = peers . begin ( ) ; peerIt ! = peers . end ( ) ; + + peerIt )
{
2010-09-27 17:05:52 -04:00
RsPeerDetails detail ;
2007-11-14 22:18:48 -05:00
2015-03-28 11:46:47 -04:00
if ( rsPeers - > getPeerDetails ( * peerIt , detail ) )
completerList . append ( getRecipientEmailAddress ( * peerIt , detail ) ) ;
// QString name = PeerDefs::nameWithLocation(detail);
// if (completerList.indexOf(name) == -1) {
// completerList.append(name);
// }
2010-09-27 17:05:52 -04:00
}
completerList . sort ( ) ;
// create completer list for groups
2014-10-21 18:33:02 -04:00
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; + + groupIt ) {
2010-09-27 17:05:52 -04:00
completerGroupList . append ( GroupDefs : : name ( * groupIt ) ) ;
}
completerGroupList . sort ( ) ;
completerList . append ( completerGroupList ) ;
2007-11-14 22:18:48 -05:00
2010-09-27 17:05:52 -04:00
m_completer = new QCompleter ( completerList , this ) ;
m_completer - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
2015-03-27 18:57:58 -04:00
2010-09-27 17:05:52 -04:00
setNewCompleter ( ui . recipientWidget , m_completer ) ;
}
void MessageComposer : : peerStatusChanged ( const QString & peer_id , int status )
{
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row ) {
2010-09-27 17:05:52 -04:00
enumType type ;
2014-10-09 11:19:17 -04:00
destinationType dtype ;
2010-09-27 17:05:52 -04:00
std : : string id ;
2014-03-29 10:18:05 -04:00
if ( getRecipientFromRow ( row , type , dtype , id ) & & ! id . empty ( ) ) {
if ( dtype = = PEER_TYPE_SSL & & QString : : fromStdString ( id ) = = peer_id )
2014-10-09 11:19:17 -04:00
{
2010-09-27 17:05:52 -04:00
QTableWidgetItem * item = ui . recipientWidget - > item ( row , COLUMN_RECIPIENT_ICON ) ;
2014-03-29 10:18:05 -04:00
if ( item )
2010-09-27 17:05:52 -04:00
item - > setIcon ( QIcon ( StatusDefs : : imageUser ( status ) ) ) ;
}
}
}
2015-03-27 18:16:12 -04:00
2010-09-27 17:05:52 -04:00
}
2007-11-14 22:18:48 -05:00
2012-05-04 19:39:36 -04:00
void MessageComposer : : setFileList ( const std : : list < DirDetails > & dir_info )
2010-04-26 17:11:19 -04:00
{
2010-09-27 17:05:52 -04:00
std : : list < FileInfo > files_info ;
std : : list < DirDetails > : : const_iterator it ;
/* convert dir_info to files_info */
2014-10-21 18:33:02 -04:00
for ( it = dir_info . begin ( ) ; it ! = dir_info . end ( ) ; + + it )
2010-09-27 17:05:52 -04:00
{
FileInfo info ;
info . fname = it - > name ;
info . hash = it - > hash ;
info . size = it - > count ;
files_info . push_back ( info ) ;
}
2010-04-26 17:11:19 -04:00
2012-05-04 19:39:36 -04:00
setFileList ( files_info ) ;
2010-04-26 17:11:19 -04:00
}
2012-05-04 19:39:36 -04:00
void MessageComposer : : setFileList ( const std : : list < FileInfo > & files_info )
2007-11-14 22:18:48 -05:00
{
2010-09-27 17:05:52 -04:00
_recList . clear ( ) ;
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
ui . msgFileList - > clear ( ) ;
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
std : : list < FileInfo > : : const_iterator it ;
2014-10-21 18:33:02 -04:00
for ( it = files_info . begin ( ) ; it ! = files_info . end ( ) ; + + it ) {
2010-11-07 16:33:48 -05:00
addFile ( * it ) ;
}
2009-05-17 15:38:42 -04:00
2010-11-07 16:33:48 -05:00
ui . msgFileList - > update ( ) ; /* update display */
}
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
void MessageComposer : : addFile ( const FileInfo & fileInfo )
{
2014-10-21 18:33:02 -04:00
for ( std : : list < FileInfo > : : iterator it = _recList . begin ( ) ; it ! = _recList . end ( ) ; + + it ) {
2010-11-26 10:32:46 -05:00
if ( it - > hash = = fileInfo . hash ) {
/* File already added */
return ;
}
}
2010-11-07 16:33:48 -05:00
_recList . push_back ( fileInfo ) ;
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
/* make a widget per person */
QTreeWidgetItem * item = new QTreeWidgetItem ;
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
item - > setText ( COLUMN_FILE_NAME , QString : : fromUtf8 ( fileInfo . fname . c_str ( ) ) ) ;
item - > setText ( COLUMN_FILE_SIZE , misc : : friendlyUnit ( fileInfo . size ) ) ;
2015-01-22 17:54:41 -05:00
item - > setTextAlignment ( COLUMN_FILE_SIZE , Qt : : AlignRight ) ;
2014-03-17 16:56:06 -04:00
item - > setText ( COLUMN_FILE_HASH , QString : : fromStdString ( fileInfo . hash . toStdString ( ) ) ) ;
2010-11-07 16:33:48 -05:00
item - > setFlags ( Qt : : ItemIsUserCheckable | Qt : : ItemIsEnabled ) ;
2010-11-12 18:48:12 -05:00
item - > setCheckState ( COLUMN_FILE_CHECKED , Qt : : Checked ) ;
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
/* add to the list */
ui . msgFileList - > addTopLevelItem ( item ) ;
2007-11-14 22:18:48 -05:00
}
2010-07-07 19:03:34 -04:00
/* title changed */
void MessageComposer : : titleChanged ( )
2007-11-14 22:18:48 -05:00
{
2010-07-07 19:03:34 -04:00
calculateTitle ( ) ;
ui . msgText - > document ( ) - > setModified ( true ) ;
}
2010-01-21 11:35:00 -05:00
2010-07-07 19:03:34 -04:00
void MessageComposer : : calculateTitle ( )
{
2010-11-09 14:57:05 -05:00
setWindowTitle ( tr ( " Compose " ) + " : " + misc : : removeNewLine ( ui . titleEdit - > text ( ) ) ) ;
2010-09-27 17:05:52 -04:00
}
2014-03-17 16:56:06 -04:00
static void calculateGroupsOfSslIds ( const std : : list < RsGroupInfo > & existingGroupInfos , std : : list < RsPeerId > & checkSslIds , std : : list < std : : string > & checkGroupIds )
2010-09-27 17:05:52 -04:00
{
checkGroupIds . clear ( ) ;
if ( checkSslIds . empty ( ) ) {
// nothing to do
return ;
}
2014-03-17 16:56:06 -04:00
std : : map < RsPeerId , RsPgpId > sslToGpg ;
std : : map < RsPgpId , std : : list < RsPeerId > > gpgToSslIds ;
2010-09-27 17:05:52 -04:00
std : : list < RsGroupInfo > groupInfos ;
// iterate all groups
2014-03-17 16:56:06 -04:00
std : : list < RsGroupInfo > : : const_iterator groupInfoIt ;
2014-10-21 18:33:02 -04:00
for ( groupInfoIt = existingGroupInfos . begin ( ) ; groupInfoIt ! = existingGroupInfos . end ( ) ; + + groupInfoIt ) {
2010-09-27 17:05:52 -04:00
if ( groupInfoIt - > peerIds . empty ( ) ) {
continue ;
}
// iterate all assigned peers (gpg id's)
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > : : const_iterator peerIt ;
2014-10-21 18:33:02 -04:00
for ( peerIt = groupInfoIt - > peerIds . begin ( ) ; peerIt ! = groupInfoIt - > peerIds . end ( ) ; + + peerIt ) {
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > sslIds ;
2010-09-27 17:05:52 -04:00
2014-03-17 16:56:06 -04:00
std : : map < RsPgpId , std : : list < RsPeerId > > : : const_iterator it = gpgToSslIds . find ( * peerIt ) ;
2010-09-27 17:05:52 -04:00
if ( it = = gpgToSslIds . end ( ) ) {
2011-08-07 17:14:09 -04:00
rsPeers - > getAssociatedSSLIds ( * peerIt , sslIds ) ;
2010-09-27 17:05:52 -04:00
gpgToSslIds [ * peerIt ] = sslIds ;
} else {
sslIds = it - > second ;
}
// iterate all ssl id's
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > : : const_iterator sslIt ;
2014-10-21 18:33:02 -04:00
for ( sslIt = sslIds . begin ( ) ; sslIt ! = sslIds . end ( ) ; + + sslIt ) {
2010-09-27 17:05:52 -04:00
// search in ssl list
if ( std : : find ( checkSslIds . begin ( ) , checkSslIds . end ( ) , * sslIt ) = = checkSslIds . end ( ) ) {
// not found
break ;
}
}
if ( sslIt ! = sslIds . end ( ) ) {
// one or more ssl id's not found
break ;
}
}
if ( peerIt = = groupInfoIt - > peerIds . end ( ) ) {
// all ssl id's of all assigned gpg id's found
groupInfos . push_back ( * groupInfoIt ) ;
}
}
// remove all ssl id's of all found groups from the list
2014-10-21 18:33:02 -04:00
for ( groupInfoIt = groupInfos . begin ( ) ; groupInfoIt ! = groupInfos . end ( ) ; + + groupInfoIt ) {
2010-09-27 17:05:52 -04:00
// iterate all assigned peers (gpg id's)
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > : : const_iterator peerIt ;
2014-10-21 18:33:02 -04:00
for ( peerIt = groupInfoIt - > peerIds . begin ( ) ; peerIt ! = groupInfoIt - > peerIds . end ( ) ; + + peerIt ) {
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > sslIds ;
2010-09-27 17:05:52 -04:00
2014-03-17 16:56:06 -04:00
std : : map < RsPgpId , std : : list < RsPeerId > > : : iterator it = gpgToSslIds . find ( * peerIt ) ;
2010-09-27 17:05:52 -04:00
if ( it = = gpgToSslIds . end ( ) ) {
2011-08-07 17:14:09 -04:00
rsPeers - > getAssociatedSSLIds ( * peerIt , sslIds ) ;
2010-09-27 17:05:52 -04:00
gpgToSslIds [ * peerIt ] = sslIds ;
} else {
sslIds = it - > second ;
}
// iterate all ssl id's
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > : : const_iterator sslIt ;
2014-10-21 18:33:02 -04:00
for ( sslIt = sslIds . begin ( ) ; sslIt ! = sslIds . end ( ) ; + + sslIt ) {
2010-09-27 17:05:52 -04:00
// search in ssl list
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > : : iterator it = std : : find ( checkSslIds . begin ( ) , checkSslIds . end ( ) , * sslIt ) ;
2010-09-27 17:05:52 -04:00
if ( it ! = checkSslIds . end ( ) ) {
checkSslIds . erase ( it ) ;
}
}
}
checkGroupIds . push_back ( groupInfoIt - > id ) ;
}
2010-07-07 19:03:34 -04:00
}
2010-01-21 11:35:00 -05:00
2012-02-08 07:11:15 -05:00
MessageComposer * MessageComposer : : newMsg ( const std : : string & msgId /* = ""*/ )
2010-07-07 19:03:34 -04:00
{
2010-11-02 17:11:11 -04:00
MessageComposer * msgComposer = new MessageComposer ( ) ;
2010-05-25 05:32:14 -04:00
2010-11-02 17:11:11 -04:00
msgComposer - > addEmptyRecipient ( ) ;
2010-05-25 05:32:14 -04:00
2010-11-02 17:11:11 -04:00
if ( msgId . empty ( ) = = false ) {
2010-05-25 05:32:14 -04:00
// fill existing message
MessageInfo msgInfo ;
2015-03-22 00:52:53 -04:00
if ( ! rsMail - > getMessage ( msgId , msgInfo ) ) {
2010-05-25 05:32:14 -04:00
std : : cerr < < " MessageComposer::newMsg() Couldn't find Msg " < < std : : endl ;
2010-11-02 17:11:11 -04:00
delete msgComposer ;
return NULL ;
2010-05-25 05:32:14 -04:00
}
2010-09-11 06:39:40 -04:00
if ( msgInfo . msgflags & RS_MSG_DRAFT ) {
2010-11-02 17:11:11 -04:00
msgComposer - > m_sDraftMsgId = msgId ;
2015-03-22 00:52:53 -04:00
rsMail - > getMsgParentId ( msgId , msgComposer - > m_msgParentId ) ;
2010-11-02 17:11:11 -04:00
if ( msgInfo . msgflags & RS_MSG_REPLIED ) {
msgComposer - > m_msgType = REPLY ;
} else if ( msgInfo . msgflags & RS_MSG_FORWARDED ) {
msgComposer - > m_msgType = FORWARD ;
}
2010-09-11 06:39:40 -04:00
}
2010-06-14 14:16:32 -04:00
2012-05-01 05:18:55 -04:00
// needed to send system flags with reply
2012-05-05 18:20:05 -04:00
msgComposer - > msgFlags = ( msgInfo . msgflags & RS_MSG_SYSTEM ) ;
2012-05-01 05:18:55 -04:00
2013-10-03 17:41:34 -04:00
msgComposer - > setTitleText ( QString : : fromUtf8 ( msgInfo . title . c_str ( ) ) ) ;
msgComposer - > setMsgText ( QString : : fromUtf8 ( msgInfo . msg . c_str ( ) ) ) ;
2012-05-04 19:39:36 -04:00
msgComposer - > setFileList ( msgInfo . files ) ;
2010-05-25 05:32:14 -04:00
2010-09-27 17:05:52 -04:00
// get existing groups
std : : list < RsGroupInfo > groupInfoList ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
std : : list < std : : string > groupIds ;
std : : list < std : : string > : : iterator groupIt ;
2014-03-29 10:18:05 -04:00
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgto, groupIds);
2014-10-21 18:33:02 -04:00
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); ++groupIt ) {
2014-03-29 10:18:05 -04:00
// msgComposer->addRecipient(MessageComposer::TO, *groupIt, true) ;
// }
2010-09-27 17:05:52 -04:00
2014-03-29 10:18:05 -04:00
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgcc, groupIds);
2014-10-21 18:33:02 -04:00
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); ++groupIt ) {
2014-03-29 10:18:05 -04:00
// msgComposer->addRecipient(MessageComposer::CC, *groupIt, true) ;
// }
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgbcc, groupIds);
2014-10-21 18:33:02 -04:00
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); ++groupIt ) {
2014-03-29 10:18:05 -04:00
// msgComposer->addRecipient(MessageComposer::BCC, *groupIt, true) ;
// }
2014-10-21 18:33:02 -04:00
for ( std : : list < RsPeerId > : : const_iterator it = msgInfo . rspeerid_msgto . begin ( ) ; it ! = msgInfo . rspeerid_msgto . end ( ) ; + + it ) msgComposer - > addRecipient ( MessageComposer : : TO , * it ) ;
for ( std : : list < RsPeerId > : : const_iterator it = msgInfo . rspeerid_msgcc . begin ( ) ; it ! = msgInfo . rspeerid_msgcc . end ( ) ; + + it ) msgComposer - > addRecipient ( MessageComposer : : CC , * it ) ;
for ( std : : list < RsPeerId > : : const_iterator it = msgInfo . rspeerid_msgbcc . begin ( ) ; it ! = msgInfo . rspeerid_msgbcc . end ( ) ; + + it ) msgComposer - > addRecipient ( MessageComposer : : BCC , * it ) ;
for ( std : : list < RsGxsId > : : const_iterator it = msgInfo . rsgxsid_msgto . begin ( ) ; it ! = msgInfo . rsgxsid_msgto . end ( ) ; + + it ) msgComposer - > addRecipient ( MessageComposer : : TO , * it ) ;
for ( std : : list < RsGxsId > : : const_iterator it = msgInfo . rsgxsid_msgcc . begin ( ) ; it ! = msgInfo . rsgxsid_msgcc . end ( ) ; + + it ) msgComposer - > addRecipient ( MessageComposer : : CC , * it ) ;
for ( std : : list < RsGxsId > : : const_iterator it = msgInfo . rsgxsid_msgbcc . begin ( ) ; it ! = msgInfo . rsgxsid_msgbcc . end ( ) ; + + it ) msgComposer - > addRecipient ( MessageComposer : : BCC , * it ) ;
2010-05-25 05:32:14 -04:00
2011-05-21 12:26:00 -04:00
MsgTagInfo tagInfo ;
2015-03-22 00:52:53 -04:00
rsMail - > getMessageTag ( msgId , tagInfo ) ;
2011-05-21 12:26:00 -04:00
2014-03-29 10:18:05 -04:00
msgComposer - > m_tagIds = tagInfo . tagIds ;
2011-05-21 12:26:00 -04:00
msgComposer - > showTagLabels ( ) ;
2010-11-02 17:11:11 -04:00
msgComposer - > ui . msgText - > document ( ) - > setModified ( false ) ;
2010-05-25 05:32:14 -04:00
}
2010-07-07 19:03:34 -04:00
2010-11-02 17:11:11 -04:00
msgComposer - > calculateTitle ( ) ;
return msgComposer ;
2007-11-14 22:18:48 -05:00
}
2012-05-04 19:39:36 -04:00
QString MessageComposer : : buildReplyHeader ( const MessageInfo & msgInfo )
{
RetroShareLink link ;
2014-03-29 10:18:05 -04:00
link . createMessage ( msgInfo . rspeerid_srcId , " " ) ;
2012-05-04 19:39:36 -04:00
QString from = link . toHtml ( ) ;
QString to ;
2014-10-21 18:33:02 -04:00
for ( std : : list < RsPeerId > : : const_iterator it = msgInfo . rspeerid_msgto . begin ( ) ; it ! = msgInfo . rspeerid_msgto . end ( ) ; + + it )
2014-03-29 10:18:05 -04:00
if ( link . createMessage ( * it , " " ) )
{
if ( ! to . isEmpty ( ) )
2012-05-04 19:39:36 -04:00
to + = " , " ;
2014-03-29 10:18:05 -04:00
2012-05-04 19:39:36 -04:00
to + = link . toHtml ( ) ;
}
2014-10-21 18:33:02 -04:00
for ( std : : list < RsGxsId > : : const_iterator it = msgInfo . rsgxsid_msgto . begin ( ) ; it ! = msgInfo . rsgxsid_msgto . end ( ) ; + + it )
2014-03-29 10:18:05 -04:00
if ( link . createMessage ( * it , " " ) )
{
if ( ! to . isEmpty ( ) )
to + = " , " ;
to + = link . toHtml ( ) ;
}
2012-05-04 19:39:36 -04:00
QString cc ;
2014-10-21 18:33:02 -04:00
for ( std : : list < RsPeerId > : : const_iterator it = msgInfo . rspeerid_msgcc . begin ( ) ; it ! = msgInfo . rspeerid_msgcc . end ( ) ; + + it )
2014-03-29 10:18:05 -04:00
if ( link . createMessage ( * it , " " ) ) {
if ( ! cc . isEmpty ( ) ) {
cc + = " , " ;
}
cc + = link . toHtml ( ) ;
}
2014-10-21 18:33:02 -04:00
for ( std : : list < RsGxsId > : : const_iterator it = msgInfo . rsgxsid_msgcc . begin ( ) ; it ! = msgInfo . rsgxsid_msgcc . end ( ) ; + + it )
2012-05-04 19:39:36 -04:00
if ( link . createMessage ( * it , " " ) ) {
if ( ! cc . isEmpty ( ) ) {
cc + = " , " ;
}
cc + = link . toHtml ( ) ;
}
2014-03-29 10:18:05 -04:00
2012-05-04 19:39:36 -04:00
QString header = QString ( " <span>-----%1----- " ) . arg ( tr ( " Original Message " ) ) ;
header + = QString ( " <br><font size='3'><strong>%1: </strong>%2</font><br> " ) . arg ( tr ( " From " ) , from ) ;
header + = QString ( " <font size='3'><strong>%1: </strong>%2</font><br> " ) . arg ( tr ( " To " ) , to ) ;
if ( ! cc . isEmpty ( ) ) {
header + = QString ( " <font size='3'><strong>%1: </strong>%2</font><br> " ) . arg ( tr ( " Cc " ) , cc ) ;
}
2012-11-15 16:35:37 -05:00
header + = QString ( " <br><font size='3'><strong>%1: </strong>%2</font><br> " ) . arg ( tr ( " Sent " ) , DateTime : : formatLongDateTime ( msgInfo . ts ) ) ;
2013-10-03 17:41:34 -04:00
header + = QString ( " <font size='3'><strong>%1: </strong>%2</font></span><br> " ) . arg ( tr ( " Subject " ) , QString : : fromUtf8 ( msgInfo . title . c_str ( ) ) ) ;
2012-05-04 19:39:36 -04:00
header + = " <br> " ;
2012-11-15 16:35:37 -05:00
header + = tr ( " On %1, %2 wrote: " ) . arg ( DateTime : : formatDateTime ( msgInfo . ts ) , from ) ;
2012-05-04 19:39:36 -04:00
return header ;
}
void MessageComposer : : setQuotedMsg ( const QString & msg , const QString & header )
{
ui . msgText - > setUndoRedoEnabled ( false ) ;
2012-09-27 16:32:28 -04:00
ui . msgText - > setText ( msg ) ;
2012-05-04 19:39:36 -04:00
QTextBlock block = ui . msgText - > document ( ) - > firstBlock ( ) ;
while ( block . isValid ( ) ) {
QTextCursor cursor = ui . msgText - > textCursor ( ) ;
cursor . setPosition ( block . position ( ) ) ;
QTextBlockFormat format ;
format . setProperty ( TextFormat : : IsBlockQuote , true ) ;
format . setLeftMargin ( block . blockFormat ( ) . leftMargin ( ) + 20 ) ;
format . setRightMargin ( block . blockFormat ( ) . rightMargin ( ) + 20 ) ;
cursor . mergeBlockFormat ( format ) ;
block = block . next ( ) ;
}
ui . msgText - > moveCursor ( QTextCursor : : Start ) ;
ui . msgText - > textCursor ( ) . insertBlock ( ) ;
ui . msgText - > moveCursor ( QTextCursor : : Start ) ;
if ( header . isEmpty ( ) ) {
ui . msgText - > insertHtml ( " <br><br> " ) ;
} else {
ui . msgText - > insertHtml ( " <br><br> " + header + " <br> " ) ;
}
ui . msgText - > moveCursor ( QTextCursor : : Start ) ;
ui . msgText - > setUndoRedoEnabled ( true ) ;
ui . msgText - > document ( ) - > setModified ( true ) ;
ui . msgText - > setFocus ( Qt : : OtherFocusReason ) ;
}
2010-11-02 17:11:11 -04:00
MessageComposer * MessageComposer : : replyMsg ( const std : : string & msgId , bool all )
2007-11-14 22:18:48 -05:00
{
2010-11-02 17:11:11 -04:00
MessageInfo msgInfo ;
2015-03-22 00:52:53 -04:00
if ( ! rsMail - > getMessage ( msgId , msgInfo ) ) {
2010-11-02 17:11:11 -04:00
return NULL ;
}
MessageComposer * msgComposer = MessageComposer : : newMsg ( ) ;
msgComposer - > m_msgParentId = msgId ;
msgComposer - > m_msgType = REPLY ;
/* fill it in */
2013-10-03 17:41:34 -04:00
msgComposer - > setTitleText ( QString : : fromUtf8 ( msgInfo . title . c_str ( ) ) , REPLY ) ;
msgComposer - > setQuotedMsg ( QString : : fromUtf8 ( msgInfo . msg . c_str ( ) ) , buildReplyHeader ( msgInfo ) ) ;
2010-11-02 17:11:11 -04:00
2014-03-29 10:18:05 -04:00
if ( ! msgInfo . rspeerid_srcId . isNull ( ) ) msgComposer - > addRecipient ( MessageComposer : : TO , msgInfo . rspeerid_srcId ) ;
if ( ! msgInfo . rsgxsid_srcId . isNull ( ) ) msgComposer - > addRecipient ( MessageComposer : : TO , msgInfo . rsgxsid_srcId ) ;
2010-11-02 17:11:11 -04:00
2014-03-29 10:18:05 -04:00
if ( all )
{
2014-03-17 16:56:06 -04:00
RsPeerId ownId = rsPeers - > getOwnId ( ) ;
2010-11-02 17:11:11 -04:00
2014-10-21 18:33:02 -04:00
for ( std : : list < RsPeerId > : : iterator tli = msgInfo . rspeerid_msgto . begin ( ) ; tli ! = msgInfo . rspeerid_msgto . end ( ) ; + + tli )
2014-03-29 10:18:05 -04:00
if ( ownId ! = * tli )
msgComposer - > addRecipient ( MessageComposer : : TO , * tli ) ;
2010-11-02 17:11:11 -04:00
2014-10-21 18:33:02 -04:00
for ( std : : list < RsPeerId > : : iterator tli = msgInfo . rspeerid_msgcc . begin ( ) ; tli ! = msgInfo . rspeerid_msgcc . end ( ) ; + + tli )
2014-03-29 10:18:05 -04:00
if ( ownId ! = * tli )
msgComposer - > addRecipient ( MessageComposer : : TO , * tli ) ;
2014-10-21 18:33:02 -04:00
for ( std : : list < RsGxsId > : : iterator tli = msgInfo . rsgxsid_msgto . begin ( ) ; tli ! = msgInfo . rsgxsid_msgto . end ( ) ; + + tli )
2014-03-29 10:18:05 -04:00
//if (ownId != *tli)
msgComposer - > addRecipient ( MessageComposer : : TO , * tli ) ;
2014-10-21 18:33:02 -04:00
for ( std : : list < RsGxsId > : : iterator tli = msgInfo . rsgxsid_msgcc . begin ( ) ; tli ! = msgInfo . rsgxsid_msgcc . end ( ) ; + + tli )
2014-03-29 10:18:05 -04:00
//if (ownId != *tli)
msgComposer - > addRecipient ( MessageComposer : : TO , * tli ) ;
2010-11-02 17:11:11 -04:00
}
2012-05-01 05:18:55 -04:00
// needed to send system flags with reply
2012-05-05 18:20:05 -04:00
msgComposer - > msgFlags = ( msgInfo . msgflags & RS_MSG_SYSTEM ) ;
2012-05-01 05:18:55 -04:00
2010-11-02 17:11:11 -04:00
msgComposer - > calculateTitle ( ) ;
/* window will destroy itself! */
return msgComposer ;
2007-11-14 22:18:48 -05:00
}
2010-11-02 17:11:11 -04:00
MessageComposer * MessageComposer : : forwardMsg ( const std : : string & msgId )
2008-09-08 08:41:46 -04:00
{
2010-11-02 17:11:11 -04:00
MessageInfo msgInfo ;
2015-03-22 00:52:53 -04:00
if ( ! rsMail - > getMessage ( msgId , msgInfo ) ) {
2010-11-02 17:11:11 -04:00
return NULL ;
}
MessageComposer * msgComposer = MessageComposer : : newMsg ( ) ;
msgComposer - > m_msgParentId = msgId ;
msgComposer - > m_msgType = FORWARD ;
/* fill it in */
2013-10-03 17:41:34 -04:00
msgComposer - > setTitleText ( QString : : fromUtf8 ( msgInfo . title . c_str ( ) ) , FORWARD ) ;
msgComposer - > setQuotedMsg ( QString : : fromUtf8 ( msgInfo . msg . c_str ( ) ) , buildReplyHeader ( msgInfo ) ) ;
2010-11-02 17:11:11 -04:00
std : : list < FileInfo > & files_info = msgInfo . files ;
2012-05-04 19:39:36 -04:00
msgComposer - > setFileList ( files_info ) ;
2010-11-02 17:11:11 -04:00
2012-05-01 05:18:55 -04:00
// needed to send system flags with reply
2012-05-05 18:20:05 -04:00
msgComposer - > msgFlags = ( msgInfo . msgflags & RS_MSG_SYSTEM ) ;
2012-05-01 05:18:55 -04:00
2010-11-02 17:11:11 -04:00
msgComposer - > calculateTitle ( ) ;
/* window will destroy itself! */
return msgComposer ;
}
2012-05-04 19:39:36 -04:00
void MessageComposer : : setTitleText ( const QString & title , enumMessageType type )
2010-11-02 17:11:11 -04:00
{
QString titleText ;
switch ( type ) {
case NORMAL :
titleText = title ;
break ;
case REPLY :
if ( title . startsWith ( " Re: " , Qt : : CaseInsensitive ) ) {
titleText = title ;
} else {
titleText = tr ( " Re: " ) + " " + title ;
}
break ;
case FORWARD :
if ( title . startsWith ( " Fwd: " , Qt : : CaseInsensitive ) ) {
titleText = title ;
} else {
titleText = tr ( " Fwd: " ) + " " + title ;
}
break ;
}
2010-11-09 14:57:05 -05:00
ui . titleEdit - > setText ( misc : : removeNewLine ( titleText ) ) ;
2010-11-02 17:11:11 -04:00
}
2012-05-04 19:39:36 -04:00
void MessageComposer : : setMsgText ( const QString & msg , bool asHtml )
2007-11-14 22:18:48 -05:00
{
2012-04-26 19:41:14 -04:00
if ( asHtml ) {
ui . msgText - > setHtml ( msg ) ;
} else {
ui . msgText - > setText ( msg ) ;
}
2010-05-25 05:32:14 -04:00
ui . msgText - > setFocus ( Qt : : OtherFocusReason ) ;
QTextCursor c = ui . msgText - > textCursor ( ) ;
c . movePosition ( QTextCursor : : End ) ;
ui . msgText - > setTextCursor ( c ) ;
ui . msgText - > document ( ) - > setModified ( true ) ;
2007-11-14 22:18:48 -05:00
}
2012-02-09 14:18:15 -05:00
void MessageComposer : : sendMessage ( )
2007-11-14 22:18:48 -05:00
{
2010-10-29 16:57:23 -04:00
if ( sendMessage_internal ( false ) ) {
close ( ) ;
}
2010-05-25 05:32:14 -04:00
}
2007-11-14 22:18:48 -05:00
2014-03-29 10:18:05 -04:00
template < class T > void addUnique ( std : : list < T > & lst , const T & t ) { if ( std : : find ( lst . begin ( ) , lst . end ( ) , t ) = = lst . end ( ) ) lst . push_back ( t ) ; }
2010-10-29 16:57:23 -04:00
bool MessageComposer : : sendMessage_internal ( bool bDraftbox )
2010-05-25 05:32:14 -04:00
{
/* construct a message */
MessageInfo mi ;
2008-02-04 12:55:59 -05:00
2014-05-07 16:53:16 -04:00
// add a GXS signer/from in case the message is to be sent to a distant peer
mi . rsgxsid_srcId = RsGxsId ( ui . respond_to_CB - > itemData ( ui . respond_to_CB - > currentIndex ( ) ) . toString ( ) . toStdString ( ) ) ;
std : : cerr < < " MessageSend: setting 'from' field to GXS id = " < < mi . rsgxsid_srcId < < std : : endl ;
2013-10-03 17:41:34 -04:00
mi . title = misc : : removeNewLine ( ui . titleEdit - > text ( ) ) . toUtf8 ( ) . constData ( ) ;
2012-05-01 05:18:55 -04:00
// needed to send system flags with reply
2012-05-05 18:20:05 -04:00
mi . msgflags = msgFlags ;
2010-05-25 05:32:14 -04:00
2011-09-29 05:20:09 -04:00
QString text ;
RsHtml : : optimizeHtml ( ui . msgText , text ) ;
2013-10-03 17:41:34 -04:00
mi . msg = text . toUtf8 ( ) . constData ( ) ;
2011-09-09 15:54:17 -04:00
2010-10-29 16:57:23 -04:00
/* check for existing title */
if ( bDraftbox = = false & & mi . title . empty ( ) ) {
if ( QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Do you want to send the message without a subject ? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) = = QMessageBox : : No ) {
2011-01-31 15:35:09 -05:00
ui . titleEdit - > setFocus ( ) ;
2010-10-29 16:57:23 -04:00
return false ; // Don't send with an empty subject
}
}
2010-11-12 18:48:12 -05:00
int filesCount = ui . msgFileList - > topLevelItemCount ( ) ;
2014-10-21 18:33:02 -04:00
for ( int i = 0 ; i < filesCount ; + + i ) {
2010-11-12 18:48:12 -05:00
QTreeWidgetItem * item = ui . msgFileList - > topLevelItem ( i ) ;
if ( item - > checkState ( COLUMN_FILE_CHECKED ) ) {
2014-03-29 10:18:05 -04:00
RsFileHash hash ( item - > text ( COLUMN_FILE_HASH ) . toStdString ( ) ) ;
2014-10-21 18:33:02 -04:00
for ( std : : list < FileInfo > : : iterator it = _recList . begin ( ) ; it ! = _recList . end ( ) ; + + it ) {
2010-11-12 18:48:12 -05:00
if ( it - > hash = = hash ) {
mi . files . push_back ( * it ) ;
break ;
}
}
}
}
2007-11-14 22:18:48 -05:00
2010-05-25 05:32:14 -04:00
/* get the ids from the send list */
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > peers ;
2010-05-25 05:32:14 -04:00
rsPeers - > getFriendList ( peers ) ;
2007-11-14 22:18:48 -05:00
2012-04-26 19:41:14 -04:00
/* add own id */
peers . push_back ( rsPeers - > getOwnId ( ) ) ;
2010-09-27 17:05:52 -04:00
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row )
2014-03-29 10:18:05 -04:00
{
2010-09-27 17:05:52 -04:00
enumType type ;
2014-03-29 10:18:05 -04:00
destinationType dtype ;
2010-09-27 17:05:52 -04:00
std : : string id ;
2014-03-29 10:18:05 -04:00
if ( ! getRecipientFromRow ( row , type , dtype , id ) | | id . empty ( ) )
continue ;
switch ( dtype )
{
case PEER_TYPE_GROUP : {
RsGroupInfo groupInfo ;
if ( rsPeers - > getGroupInfo ( id , groupInfo ) = = false ) {
// group not found
continue ;
}
2010-09-27 17:05:52 -04:00
2014-03-29 10:18:05 -04:00
std : : list < RsPgpId > : : const_iterator groupIt ;
2014-10-21 18:33:02 -04:00
for ( groupIt = groupInfo . peerIds . begin ( ) ; groupIt ! = groupInfo . peerIds . end ( ) ; + + groupIt ) {
2014-03-29 10:18:05 -04:00
std : : list < RsPeerId > sslIds ;
rsPeers - > getAssociatedSSLIds ( * groupIt , sslIds ) ;
std : : list < RsPeerId > : : const_iterator sslIt ;
2014-10-21 18:33:02 -04:00
for ( sslIt = sslIds . begin ( ) ; sslIt ! = sslIds . end ( ) ; + + sslIt ) {
2014-03-29 10:18:05 -04:00
if ( std : : find ( peers . begin ( ) , peers . end ( ) , * sslIt ) = = peers . end ( ) ) {
// no friend
continue ;
2010-09-27 17:05:52 -04:00
}
2014-03-29 10:18:05 -04:00
switch ( type )
{
case TO : addUnique ( mi . rspeerid_msgto , * sslIt ) ;
2010-09-27 17:05:52 -04:00
break ;
2014-03-29 10:18:05 -04:00
case CC : addUnique ( mi . rspeerid_msgcc , * sslIt ) ;
2010-09-27 17:05:52 -04:00
break ;
2014-03-29 10:18:05 -04:00
case BCC : addUnique ( mi . rspeerid_msgbcc , * sslIt ) ;
2010-09-27 17:05:52 -04:00
break ;
2014-03-29 10:18:05 -04:00
}
2010-09-27 17:05:52 -04:00
}
}
2010-05-25 05:32:14 -04:00
}
2014-03-29 10:18:05 -04:00
break ;
case PEER_TYPE_SSL :
{
RsPeerId pid ( id ) ;
switch ( type )
{
case TO : addUnique ( mi . rspeerid_msgto , pid ) ;
break ;
case CC : addUnique ( mi . rspeerid_msgcc , pid ) ;
break ;
case BCC : addUnique ( mi . rspeerid_msgbcc , pid ) ;
break ;
}
}
break ;
case PEER_TYPE_GXS :
{
RsGxsId gid ( id ) ;
switch ( type )
{
case TO : addUnique ( mi . rsgxsid_msgto , gid ) ;
break ;
case CC : addUnique ( mi . rsgxsid_msgcc , gid ) ;
break ;
case BCC : addUnique ( mi . rsgxsid_msgbcc , gid ) ;
break ;
}
}
break ;
default :
std : : cerr < < __PRETTY_FUNCTION__ < < " : Unhandled desitnation type " < < dtype < < std : : endl ;
break ;
}
2010-05-25 05:32:14 -04:00
}
2007-11-14 22:18:48 -05:00
2014-03-29 10:18:05 -04:00
if ( bDraftbox )
{
2010-09-11 06:39:40 -04:00
mi . msgId = m_sDraftMsgId ;
2010-11-02 17:11:11 -04:00
2015-03-22 00:52:53 -04:00
rsMail - > MessageToDraft ( mi , m_msgParentId ) ;
2010-09-11 06:39:40 -04:00
// use new message id
m_sDraftMsgId = mi . msgId ;
2010-11-02 17:11:11 -04:00
switch ( m_msgType ) {
case NORMAL :
break ;
case REPLY :
2015-03-22 00:52:53 -04:00
rsMail - > MessageReplied ( m_sDraftMsgId , true ) ;
2010-11-02 17:11:11 -04:00
break ;
case FORWARD :
2015-03-22 00:52:53 -04:00
rsMail - > MessageForwarded ( m_sDraftMsgId , true ) ;
2010-11-02 17:11:11 -04:00
break ;
}
2014-03-29 10:18:05 -04:00
}
else
{
2010-10-29 16:57:23 -04:00
/* check for the recipient */
2014-03-29 10:18:05 -04:00
if ( mi . rspeerid_msgto . empty ( ) & & mi . rspeerid_msgcc . empty ( ) & & mi . rspeerid_msgbcc . empty ( )
& & mi . rsgxsid_msgto . empty ( ) & & mi . rsgxsid_msgcc . empty ( ) & & mi . rsgxsid_msgbcc . empty ( ) )
{
2010-10-29 16:57:23 -04:00
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Please insert at least one recipient. " ) , QMessageBox : : Ok ) ;
return false ; // Don't send with no recipient
}
2010-11-02 17:11:11 -04:00
2015-02-08 15:43:34 -05:00
if ( mi . rsgxsid_srcId . isNull ( ) & & ! ( mi . rsgxsid_msgto . empty ( ) & & mi . rsgxsid_msgcc . empty ( ) & & mi . rsgxsid_msgbcc . empty ( ) ) )
{
QMessageBox : : warning ( this , tr ( " RetroShare " ) , tr ( " Please create an identity to sign distant messages, or remove the distant peers fro the destination list. " ) , QMessageBox : : Ok ) ;
return false ; // Don't send if cannot sign.
}
2015-03-22 00:52:53 -04:00
if ( rsMail - > MessageSend ( mi ) = = false ) {
2010-11-02 17:11:11 -04:00
return false ;
}
if ( m_msgParentId . empty ( ) = = false ) {
switch ( m_msgType ) {
case NORMAL :
break ;
case REPLY :
2015-03-22 00:52:53 -04:00
rsMail - > MessageReplied ( m_msgParentId , true ) ;
2010-11-02 17:11:11 -04:00
break ;
case FORWARD :
2015-03-22 00:52:53 -04:00
rsMail - > MessageForwarded ( m_msgParentId , true ) ;
2010-11-02 17:11:11 -04:00
break ;
}
}
2010-05-25 05:32:14 -04:00
}
2007-11-14 22:18:48 -05:00
2011-05-21 12:26:00 -04:00
if ( mi . msgId . empty ( ) = = false ) {
MsgTagInfo tagInfo ;
2015-03-22 00:52:53 -04:00
rsMail - > getMessageTag ( mi . msgId , tagInfo ) ;
2011-05-21 12:26:00 -04:00
/* insert new tags */
std : : list < uint32_t > : : iterator tag ;
2014-10-21 18:33:02 -04:00
for ( tag = m_tagIds . begin ( ) ; tag ! = m_tagIds . end ( ) ; + + tag ) {
2011-05-21 12:26:00 -04:00
if ( std : : find ( tagInfo . tagIds . begin ( ) , tagInfo . tagIds . end ( ) , * tag ) = = tagInfo . tagIds . end ( ) ) {
2015-03-22 00:52:53 -04:00
rsMail - > setMessageTag ( mi . msgId , * tag , true ) ;
2011-05-21 12:26:00 -04:00
} else {
tagInfo . tagIds . remove ( * tag ) ;
}
}
/* remove deleted tags */
2014-10-21 18:33:02 -04:00
for ( tag = tagInfo . tagIds . begin ( ) ; tag ! = tagInfo . tagIds . end ( ) ; + + tag ) {
2015-03-22 00:52:53 -04:00
rsMail - > setMessageTag ( mi . msgId , * tag , false ) ;
2011-05-21 12:26:00 -04:00
}
}
2010-05-25 05:32:14 -04:00
ui . msgText - > document ( ) - > setModified ( false ) ;
2014-03-29 10:18:05 -04:00
2010-10-29 16:57:23 -04:00
return true ;
2010-05-25 05:32:14 -04:00
}
2007-11-14 22:18:48 -05:00
2010-05-23 15:13:41 -04:00
void MessageComposer : : cancelMessage ( )
2007-11-14 22:18:48 -05:00
{
2010-09-27 17:05:52 -04:00
close ( ) ;
return ;
2007-11-14 22:18:48 -05:00
}
/* Toggling .... Check Boxes.....
2010-09-27 17:05:52 -04:00
* This is dependent on whether we are a
2007-11-14 22:18:48 -05:00
*
* Chan or Msg Dialog .
*/
2010-09-27 17:05:52 -04:00
void MessageComposer : : addEmptyRecipient ( )
2008-09-03 08:56:37 -04:00
{
2010-09-27 17:05:52 -04:00
int lastRow = ui . recipientWidget - > rowCount ( ) ;
if ( lastRow > 0 ) {
QTableWidgetItem * item = ui . recipientWidget - > item ( lastRow - 1 , COLUMN_RECIPIENT_DATA ) ;
if ( item & & item - > data ( ROLE_RECIPIENT_ID ) . toString ( ) . isEmpty ( ) ) {
return ;
}
}
2008-09-03 08:56:37 -04:00
2014-03-29 10:18:05 -04:00
setRecipientToRow ( lastRow , TO , PEER_TYPE_SSL , " " ) ;
2008-09-03 08:56:37 -04:00
}
2007-11-14 22:18:48 -05:00
2014-03-29 10:18:05 -04:00
bool MessageComposer : : getRecipientFromRow ( int row , enumType & type , destinationType & dest_type , std : : string & id )
2007-11-14 22:18:48 -05:00
{
2010-09-27 17:05:52 -04:00
if ( row > = ui . recipientWidget - > rowCount ( ) ) {
return false ;
}
QComboBox * cb = dynamic_cast < QComboBox * > ( ui . recipientWidget - > cellWidget ( row , COLUMN_RECIPIENT_TYPE ) ) ;
if ( cb = = NULL ) {
return false ;
}
2007-11-14 22:18:48 -05:00
2010-09-27 17:05:52 -04:00
type = ( enumType ) cb - > itemData ( cb - > currentIndex ( ) , Qt : : UserRole ) . toInt ( ) ;
id = ui . recipientWidget - > item ( row , COLUMN_RECIPIENT_DATA ) - > data ( ROLE_RECIPIENT_ID ) . toString ( ) . toStdString ( ) ;
2014-03-29 10:18:05 -04:00
dest_type = ( destinationType ) ui . recipientWidget - > item ( row , COLUMN_RECIPIENT_DATA ) - > data ( ROLE_RECIPIENT_TYPE ) . toInt ( ) ;
2007-11-14 22:18:48 -05:00
2010-09-27 17:05:52 -04:00
return true ;
}
2015-03-28 11:46:47 -04:00
QString MessageComposer : : getRecipientEmailAddress ( const RsGxsId & id , const RsIdentityDetails & detail )
2015-03-27 18:57:58 -04:00
{
2015-03-28 11:46:47 -04:00
return ( QString ( " %2 < " ) + tr ( " Distant identity: " ) + " %2@%1> " ) . arg ( QString : : fromStdString ( id . toStdString ( ) ) ) . arg ( QString : : fromUtf8 ( detail . mNickname . c_str ( ) ) ) ;
2015-03-27 18:57:58 -04:00
}
2015-03-28 11:46:47 -04:00
QString MessageComposer : : getRecipientEmailAddress ( const RsPeerId & id , const RsPeerDetails & detail )
{
QString location_name = detail . location . empty ( ) ? tr ( " [Missing] " ) : QString : : fromUtf8 ( detail . location . c_str ( ) ) ;
return ( QString ( " %1 ( " ) + tr ( " Friend node & location: " ) + " %2, %3) " ) . arg ( QString : : fromUtf8 ( detail . name . c_str ( ) ) )
. arg ( location_name )
. arg ( QString : : fromUtf8 ( detail . id . toStdString ( ) . c_str ( ) ) ) ;
}
2014-03-29 10:18:05 -04:00
void MessageComposer : : setRecipientToRow ( int row , enumType type , destinationType dest_type , const std : : string & id )
2010-09-27 17:05:52 -04:00
{
if ( row + 1 > ui . recipientWidget - > rowCount ( ) ) {
ui . recipientWidget - > setRowCount ( row + 1 ) ;
}
QComboBox * comboBox = dynamic_cast < QComboBox * > ( ui . recipientWidget - > cellWidget ( row , COLUMN_RECIPIENT_TYPE ) ) ;
if ( comboBox = = NULL ) {
comboBox = new QComboBox ;
comboBox - > addItem ( tr ( " To " ) , TO ) ;
comboBox - > addItem ( tr ( " Cc " ) , CC ) ;
comboBox - > addItem ( tr ( " Bcc " ) , BCC ) ;
ui . recipientWidget - > setCellWidget ( row , COLUMN_RECIPIENT_TYPE , comboBox ) ;
2015-01-15 11:09:01 -05:00
comboBox - > setLayoutDirection ( Qt : : RightToLeft ) ;
2010-09-27 17:05:52 -04:00
comboBox - > installEventFilter ( this ) ;
}
QLineEdit * lineEdit = dynamic_cast < QLineEdit * > ( ui . recipientWidget - > cellWidget ( row , COLUMN_RECIPIENT_NAME ) ) ;
if ( lineEdit = = NULL ) {
lineEdit = new QLineEdit ;
QString objectName = " lineEdit " + QString : : number ( row ) ;
lineEdit - > setObjectName ( objectName ) ;
lineEdit - > setCompleter ( m_completer ) ;
2007-11-14 22:18:48 -05:00
2010-09-27 17:05:52 -04:00
ui . recipientWidget - > setCellWidget ( row , COLUMN_RECIPIENT_NAME , lineEdit ) ;
2007-11-14 22:18:48 -05:00
2010-09-27 17:05:52 -04:00
connect ( lineEdit , SIGNAL ( editingFinished ( ) ) , this , SLOT ( editingRecipientFinished ( ) ) ) ;
lineEdit - > installEventFilter ( this ) ;
}
QIcon icon ;
QString name ;
2014-03-17 16:56:06 -04:00
if ( ! id . empty ( ) )
2014-03-29 10:18:05 -04:00
{
switch ( dest_type )
{
case PEER_TYPE_GROUP : {
2010-09-27 17:05:52 -04:00
icon = QIcon ( IMAGE_GROUP16 ) ;
RsGroupInfo groupInfo ;
if ( rsPeers - > getGroupInfo ( id , groupInfo ) ) {
name = GroupDefs : : name ( groupInfo ) ;
} else {
name = tr ( " Unknown " ) ;
}
2014-03-29 10:18:05 -04:00
}
break ;
case PEER_TYPE_GXS : {
RsIdentityDetails detail ;
2014-12-30 18:14:34 -05:00
RsGxsId gid ( id ) ;
2014-03-29 10:18:05 -04:00
if ( ! rsIdentity - > getIdDetails ( gid , detail ) )
{
std : : cerr < < " Can't get peer details from " < < gid < < std : : endl ;
return ;
}
2015-03-27 18:16:12 -04:00
QList < QIcon > icons ;
GxsIdDetails : : getIcons ( detail , icons , GxsIdDetails : : ICON_TYPE_AVATAR ) ;
2014-03-29 10:18:05 -04:00
2015-03-28 11:46:47 -04:00
name = getRecipientEmailAddress ( gid , detail ) ;
2015-03-27 18:16:12 -04:00
if ( ! icons . empty ( ) )
icon = icons . front ( ) ;
2014-03-29 10:18:05 -04:00
}
break ;
case PEER_TYPE_SSL : {
RsPeerDetails details ;
if ( ! rsPeers - > getPeerDetails ( RsPeerId ( id ) , details ) )
{
std : : cerr < < " Can't get peer details from " < < id < < std : : endl ;
return ;
}
2015-03-28 11:46:47 -04:00
name = getRecipientEmailAddress ( RsPeerId ( id ) , details ) ;
2014-03-29 10:18:05 -04:00
StatusInfo peerStatusInfo ;
// No check of return value. Non existing status info is handled as offline.
rsStatus - > getStatus ( RsPeerId ( id ) , peerStatusInfo ) ;
icon = QIcon ( StatusDefs : : imageUser ( peerStatusInfo . status ) ) ;
}
break ;
default :
std : : cerr < < __PRETTY_FUNCTION__ < < " : Unhandled type " < < dest_type < < std : : endl ;
return ;
}
2010-09-27 17:05:52 -04:00
}
comboBox - > setCurrentIndex ( comboBox - > findData ( type , Qt : : UserRole ) ) ;
lineEdit - > setText ( name ) ;
2014-03-29 10:18:05 -04:00
if ( id . empty ( ) )
2010-09-28 19:16:50 -04:00
lineEdit - > setStyleSheet ( QString ( STYLE_FAIL ) . arg ( lineEdit - > objectName ( ) ) ) ;
2014-03-29 10:18:05 -04:00
else
2010-09-28 19:16:50 -04:00
lineEdit - > setStyleSheet ( QString ( STYLE_NORMAL ) . arg ( lineEdit - > objectName ( ) ) ) ;
2010-09-27 17:05:52 -04:00
QTableWidgetItem * item = new QTableWidgetItem ( icon , " " , 0 ) ;
item - > setFlags ( Qt : : NoItemFlags ) ;
ui . recipientWidget - > setItem ( row , COLUMN_RECIPIENT_ICON , item ) ;
ui . recipientWidget - > item ( row , COLUMN_RECIPIENT_DATA ) - > setData ( ROLE_RECIPIENT_ID , QString : : fromStdString ( id ) ) ;
2014-03-29 10:18:05 -04:00
ui . recipientWidget - > item ( row , COLUMN_RECIPIENT_DATA ) - > setData ( ROLE_RECIPIENT_TYPE , dest_type ) ;
2010-09-27 17:05:52 -04:00
addEmptyRecipient ( ) ;
}
bool MessageComposer : : eventFilter ( QObject * obj , QEvent * event )
{
if ( event - > type ( ) = = QEvent : : FocusIn ) {
QLineEdit * lineEdit = dynamic_cast < QLineEdit * > ( obj ) ;
if ( lineEdit ) {
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row ) {
2010-09-27 17:05:52 -04:00
if ( ui . recipientWidget - > cellWidget ( row , COLUMN_RECIPIENT_NAME ) = = lineEdit ) {
break ;
}
}
if ( row < rowCount ) {
ui . recipientWidget - > setCurrentCell ( row , COLUMN_RECIPIENT_NAME ) ;
// lineEdit->setFocus();
}
} else {
QComboBox * comboBox = dynamic_cast < QComboBox * > ( obj ) ;
if ( comboBox ) {
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row ) {
2010-09-27 17:05:52 -04:00
if ( ui . recipientWidget - > cellWidget ( row , COLUMN_RECIPIENT_TYPE ) = = comboBox ) {
break ;
}
}
if ( row < rowCount ) {
ui . recipientWidget - > setCurrentCell ( row , COLUMN_RECIPIENT_TYPE ) ;
// comboBox->setFocus();
}
}
2010-09-24 07:38:46 -04:00
}
}
2010-09-27 17:05:52 -04:00
// pass the event on to the parent class
return QMainWindow : : eventFilter ( obj , event ) ;
}
void MessageComposer : : editingRecipientFinished ( )
{
QLineEdit * lineEdit = dynamic_cast < QLineEdit * > ( QObject : : sender ( ) ) ;
2015-03-28 11:46:47 -04:00
if ( lineEdit = = NULL )
2010-09-27 17:05:52 -04:00
return ;
lineEdit - > setStyleSheet ( QString ( STYLE_NORMAL ) . arg ( lineEdit - > objectName ( ) ) ) ;
// find row of the widget
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2015-03-28 11:46:47 -04:00
for ( row = 0 ; row < rowCount ; + + row )
if ( ui . recipientWidget - > cellWidget ( row , COLUMN_RECIPIENT_NAME ) = = lineEdit )
2010-09-27 17:05:52 -04:00
break ;
2015-03-28 11:46:47 -04:00
if ( row > = rowCount ) // not found
2010-09-27 17:05:52 -04:00
return ;
enumType type ;
std : : string id ; // dummy
2014-03-29 10:18:05 -04:00
destinationType dtype ;
getRecipientFromRow ( row , type , dtype , id ) ;
2010-09-27 17:05:52 -04:00
QString text = lineEdit - > text ( ) ;
if ( text . isEmpty ( ) ) {
2014-03-29 10:18:05 -04:00
setRecipientToRow ( row , type , PEER_TYPE_SSL , " " ) ;
2010-09-27 17:05:52 -04:00
return ;
}
// start with peers
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > peers ;
2010-09-27 17:05:52 -04:00
rsPeers - > getFriendList ( peers ) ;
2015-03-28 11:46:47 -04:00
RsPeerDetails details ;
2010-09-27 17:05:52 -04:00
2015-03-28 11:46:47 -04:00
for ( std : : list < RsPeerId > : : iterator peerIt = peers . begin ( ) ; peerIt ! = peers . end ( ) ; + + peerIt )
if ( rsPeers - > getPeerDetails ( * peerIt , details ) & & text = = getRecipientEmailAddress ( * peerIt , details ) )
{
setRecipientToRow ( row , type , PEER_TYPE_SSL , details . id . toStdString ( ) ) ;
return ;
}
2010-09-27 17:05:52 -04:00
2015-03-28 11:46:47 -04:00
QList < QTreeWidgetItem * > gxsitems ;
ui . friendSelectionWidget - > items ( gxsitems , FriendSelectionWidget : : IDTYPE_GXS ) ;
RsIdentityDetails detail ;
for ( QList < QTreeWidgetItem * > : : const_iterator idIt = gxsitems . begin ( ) ; idIt ! = gxsitems . end ( ) ; + + idIt )
{
RsGxsId id ( ui . friendSelectionWidget - > idFromItem ( * idIt ) ) ;
if ( rsIdentity - > getIdDetails ( id , detail ) & & text = = getRecipientEmailAddress ( id , detail ) )
{
setRecipientToRow ( row , type , PEER_TYPE_GXS , id . toStdString ( ) ) ;
return ;
}
2010-09-27 17:05:52 -04:00
}
2015-03-28 11:46:47 -04:00
2010-09-27 17:05:52 -04:00
// then groups
std : : list < RsGroupInfo > groupInfoList ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
std : : list < RsGroupInfo > : : iterator groupIt ;
2014-10-21 18:33:02 -04:00
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; + + groupIt ) {
2010-09-27 17:05:52 -04:00
QString groupName = GroupDefs : : name ( * groupIt ) ;
if ( text . compare ( groupName , Qt : : CaseSensitive ) = = 0 ) {
// found it
2014-03-29 10:18:05 -04:00
setRecipientToRow ( row , type , PEER_TYPE_GROUP , groupIt - > id ) ;
2010-09-27 17:05:52 -04:00
return ;
}
}
2014-03-29 10:18:05 -04:00
setRecipientToRow ( row , type , PEER_TYPE_SSL , " " ) ;
2010-09-27 17:05:52 -04:00
lineEdit - > setStyleSheet ( QString ( STYLE_FAIL ) . arg ( lineEdit - > objectName ( ) ) ) ;
lineEdit - > setText ( text ) ;
}
2015-03-28 11:46:47 -04:00
2014-03-29 10:18:05 -04:00
void MessageComposer : : addRecipient ( enumType type , const RsPeerId & pid )
2013-04-29 18:32:58 -04:00
{
2014-03-29 10:18:05 -04:00
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row )
2014-03-29 10:18:05 -04:00
{
enumType rowType ;
std : : string rowId ;
destinationType dtype ;
2013-04-29 18:32:58 -04:00
2014-03-29 10:18:05 -04:00
if ( getRecipientFromRow ( row , rowType , dtype , rowId ) )
{
if ( rowId . empty ( ) ) // use row
break ;
2013-04-29 18:32:58 -04:00
2014-03-29 10:18:05 -04:00
if ( RsPeerId ( rowId ) = = pid & & rowType = = type ) // existing row
break ;
}
else // use row
break ;
}
2013-04-29 18:32:58 -04:00
2014-03-29 10:18:05 -04:00
setRecipientToRow ( row , type , PEER_TYPE_SSL , pid . toStdString ( ) ) ;
2013-04-29 18:32:58 -04:00
}
2014-03-29 10:18:05 -04:00
void MessageComposer : : addRecipient ( enumType type , const RsGxsId & gxs_id )
2010-09-27 17:05:52 -04:00
{
2015-04-09 17:34:50 -04:00
static bool already = false ;
if ( ! already )
{
QMessageBox : : warning ( NULL , " Distant messaging not stable " , " Distant messaging is currently unstable. Do not expect too much from it. " ) ;
already = true ;
}
2010-09-27 17:05:52 -04:00
2014-03-29 10:18:05 -04:00
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row )
2014-03-29 10:18:05 -04:00
{
enumType rowType ;
std : : string rowId ;
destinationType dtype ;
2010-09-27 17:05:52 -04:00
2014-03-29 10:18:05 -04:00
if ( getRecipientFromRow ( row , rowType , dtype , rowId ) )
{
if ( rowId . empty ( ) ) // use row
break ;
if ( RsGxsId ( rowId ) = = gxs_id & & rowType = = type ) // existing row
break ;
}
else // use row
break ;
}
setRecipientToRow ( row , type , PEER_TYPE_GXS , gxs_id . toStdString ( ) ) ;
}
2014-10-09 11:19:17 -04:00
2014-03-29 10:18:05 -04:00
void MessageComposer : : addRecipient ( enumType type , const std : : string & id )
{
// search existing or empty row
int rowCount = ui . recipientWidget - > rowCount ( ) ;
int row ;
2014-10-21 18:33:02 -04:00
for ( row = 0 ; row < rowCount ; + + row ) {
2014-03-29 10:18:05 -04:00
enumType rowType ;
std : : string rowId ;
destinationType dtype ;
if ( getRecipientFromRow ( row , rowType , dtype , rowId ) )
{
if ( rowId . empty ( ) ) {
2011-05-07 19:14:09 -04:00
// use row
2010-09-27 17:05:52 -04:00
break ;
}
2014-03-29 10:18:05 -04:00
if ( rowId = = id & & rowType = = type & & dtype = = PEER_TYPE_GROUP ) {
// existing row
break ;
}
} else {
// use row
break ;
}
2011-05-07 19:14:09 -04:00
}
2014-03-29 10:18:05 -04:00
setRecipientToRow ( row , type , PEER_TYPE_GROUP , id ) ;
2007-11-14 22:18:48 -05:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : setupFileActions ( )
2008-11-25 20:19:09 -05:00
{
QMenu * menu = new QMenu ( tr ( " &File " ) , this ) ;
menuBar ( ) - > addMenu ( menu ) ;
QAction * a ;
a = new QAction ( QIcon ( " :/images/textedit/filenew.png " ) , tr ( " &New " ) , this ) ;
a - > setShortcut ( QKeySequence : : New ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( fileNew ( ) ) ) ;
menu - > addAction ( a ) ;
a = new QAction ( QIcon ( " :/images/textedit/fileopen.png " ) , tr ( " &Open... " ) , this ) ;
a - > setShortcut ( QKeySequence : : Open ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( fileOpen ( ) ) ) ;
menu - > addAction ( a ) ;
menu - > addSeparator ( ) ;
actionSave = a = new QAction ( QIcon ( " :/images/textedit/filesave.png " ) , tr ( " &Save " ) , this ) ;
a - > setShortcut ( QKeySequence : : Save ) ;
2010-05-25 09:22:42 -04:00
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( saveasDraft ( ) ) ) ;
2008-11-25 20:19:09 -05:00
a - > setEnabled ( false ) ;
menu - > addAction ( a ) ;
2010-05-25 09:22:42 -04:00
a = new QAction ( tr ( " Save &As File " ) , this ) ;
2008-11-25 20:19:09 -05:00
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
menu - > addAction ( a ) ;
2010-09-27 17:05:52 -04:00
2010-05-25 06:41:26 -04:00
a = new QAction ( tr ( " Save &As Draft " ) , this ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( saveasDraft ( ) ) ) ;
menu - > addAction ( a ) ;
2008-11-25 20:19:09 -05:00
menu - > addSeparator ( ) ;
a = new QAction ( QIcon ( " :/images/textedit/fileprint.png " ) , tr ( " &Print... " ) , this ) ;
a - > setShortcut ( QKeySequence : : Print ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( filePrint ( ) ) ) ;
menu - > addAction ( a ) ;
/*a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("Print Preview..."), this);
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( filePrintPreview ( ) ) ) ;
menu - > addAction ( a ) ; */
a = new QAction ( QIcon ( " :/images/textedit/exportpdf.png " ) , tr ( " &Export PDF... " ) , this ) ;
a - > setShortcut ( Qt : : CTRL + Qt : : Key_D ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( filePrintPdf ( ) ) ) ;
menu - > addAction ( a ) ;
menu - > addSeparator ( ) ;
a = new QAction ( tr ( " &Quit " ) , this ) ;
a - > setShortcut ( Qt : : CTRL + Qt : : Key_Q ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( close ( ) ) ) ;
menu - > addAction ( a ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : setupEditActions ( )
2008-11-25 20:19:09 -05:00
{
QMenu * menu = new QMenu ( tr ( " &Edit " ) , this ) ;
menuBar ( ) - > addMenu ( menu ) ;
QAction * a ;
a = actionUndo = new QAction ( QIcon ( " :/images/textedit/editundo.png " ) , tr ( " &Undo " ) , this ) ;
a - > setShortcut ( QKeySequence : : Undo ) ;
menu - > addAction ( a ) ;
a = actionRedo = new QAction ( QIcon ( " :/images/textedit/editredo.png " ) , tr ( " &Redo " ) , this ) ;
a - > setShortcut ( QKeySequence : : Redo ) ;
menu - > addAction ( a ) ;
menu - > addSeparator ( ) ;
a = actionCut = new QAction ( QIcon ( " :/images/textedit/editcut.png " ) , tr ( " Cu&t " ) , this ) ;
a - > setShortcut ( QKeySequence : : Cut ) ;
menu - > addAction ( a ) ;
a = actionCopy = new QAction ( QIcon ( " :/images/textedit/editcopy.png " ) , tr ( " &Copy " ) , this ) ;
a - > setShortcut ( QKeySequence : : Copy ) ;
menu - > addAction ( a ) ;
a = actionPaste = new QAction ( QIcon ( " :/images/textedit/editpaste.png " ) , tr ( " &Paste " ) , this ) ;
a - > setShortcut ( QKeySequence : : Paste ) ;
menu - > addAction ( a ) ;
actionPaste - > setEnabled ( ! QApplication : : clipboard ( ) - > text ( ) . isEmpty ( ) ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : setupViewActions ( )
2008-11-25 20:19:09 -05:00
{
QMenu * menu = new QMenu ( tr ( " &View " ) , this ) ;
menuBar ( ) - > addMenu ( menu ) ;
2010-09-27 17:05:52 -04:00
contactSidebarAction = menu - > addAction ( QIcon ( ) , tr ( " &Contacts Sidebar " ) , this , SLOT ( toggleContacts ( ) ) ) ;
contactSidebarAction - > setCheckable ( true ) ;
2008-11-25 20:19:09 -05:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : setupInsertActions ( )
2008-11-25 20:19:09 -05:00
{
QMenu * menu = new QMenu ( tr ( " &Insert " ) , this ) ;
menuBar ( ) - > addMenu ( menu ) ;
QAction * a ;
2012-09-18 18:59:23 -04:00
# if QT_VERSION >= 0x040700
// embedded images are not supported before QT 4.7.0
2008-11-25 20:19:09 -05:00
a = new QAction ( QIcon ( " " ) , tr ( " &Image " ) , this ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( addImage ( ) ) ) ;
menu - > addAction ( a ) ;
2010-11-17 07:45:46 -05:00
# endif
2010-09-27 17:05:52 -04:00
2010-05-25 13:18:12 -04:00
a = new QAction ( QIcon ( " " ) , tr ( " &Horizontal Line " ) , this ) ;
connect ( a , SIGNAL ( triggered ( ) ) , this , SLOT ( addPostSplitter ( ) ) ) ;
menu - > addAction ( a ) ;
2008-11-25 20:19:09 -05:00
}
2010-05-25 18:30:25 -04:00
void MessageComposer : : setupFormatActions ( )
{
QMenu * menu = new QMenu ( tr ( " &Format " ) , this ) ;
menuBar ( ) - > addMenu ( menu ) ;
menu - > addAction ( actionAlignLeft ) ;
menu - > addAction ( actionAlignCenter ) ;
menu - > addAction ( actionAlignRight ) ;
menu - > addAction ( actionAlignJustify ) ;
2010-09-27 17:05:52 -04:00
2010-05-25 18:30:25 -04:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textBold ( )
2008-11-25 20:19:09 -05:00
{
QTextCharFormat fmt ;
fmt . setFontWeight ( ui . boldbtn - > isChecked ( ) ? QFont : : Bold : QFont : : Normal ) ;
mergeFormatOnWordOrSelection ( fmt ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textUnderline ( )
2008-11-25 20:19:09 -05:00
{
QTextCharFormat fmt ;
fmt . setFontUnderline ( ui . underlinebtn - > isChecked ( ) ) ;
mergeFormatOnWordOrSelection ( fmt ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textItalic ( )
2008-11-25 20:19:09 -05:00
{
QTextCharFormat fmt ;
fmt . setFontItalic ( ui . italicbtn - > isChecked ( ) ) ;
mergeFormatOnWordOrSelection ( fmt ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textFamily ( const QString & f )
2008-11-25 20:19:09 -05:00
{
QTextCharFormat fmt ;
fmt . setFontFamily ( f ) ;
mergeFormatOnWordOrSelection ( fmt ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textSize ( const QString & p )
2008-11-25 20:19:09 -05:00
{
2010-02-22 09:20:40 -05:00
qreal pointSize = p . toFloat ( ) ;
if ( p . toFloat ( ) > 0 ) {
QTextCharFormat fmt ;
fmt . setFontPointSize ( pointSize ) ;
mergeFormatOnWordOrSelection ( fmt ) ;
}
2008-11-25 20:19:09 -05:00
}
2010-05-25 13:18:12 -04:00
void MessageComposer : : changeFormatType ( int styleIndex )
{
ui . msgText - > setFocus ( Qt : : OtherFocusReason ) ;
QTextCursor cursor = ui . msgText - > textCursor ( ) ;
//QTextBlockFormat bformat = cursor.blockFormat();
QTextBlockFormat bformat ;
QTextCharFormat cformat ;
switch ( styleIndex ) {
default :
case 0 :
bformat . setProperty ( TextFormat : : HtmlHeading , QVariant ( 0 ) ) ;
cformat . setFontWeight ( QFont : : Normal ) ;
cformat . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( 0 ) ) ;
break ;
case 1 :
bformat . setProperty ( TextFormat : : HtmlHeading , QVariant ( 1 ) ) ;
cformat . setFontWeight ( QFont : : Bold ) ;
cformat . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( 3 ) ) ;
break ;
case 2 :
bformat . setProperty ( TextFormat : : HtmlHeading , QVariant ( 2 ) ) ;
cformat . setFontWeight ( QFont : : Bold ) ;
cformat . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( 2 ) ) ;
break ;
case 3 :
bformat . setProperty ( TextFormat : : HtmlHeading , QVariant ( 3 ) ) ;
cformat . setFontWeight ( QFont : : Bold ) ;
cformat . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( 1 ) ) ;
break ;
case 4 :
bformat . setProperty ( TextFormat : : HtmlHeading , QVariant ( 4 ) ) ;
cformat . setFontWeight ( QFont : : Bold ) ;
cformat . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( 0 ) ) ;
break ;
case 5 :
bformat . setProperty ( TextFormat : : HtmlHeading , QVariant ( 5 ) ) ;
cformat . setFontWeight ( QFont : : Bold ) ;
cformat . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( - 1 ) ) ;
break ;
case 6 :
bformat . setProperty ( TextFormat : : HtmlHeading , QVariant ( 6 ) ) ;
cformat . setFontWeight ( QFont : : Bold ) ;
cformat . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( - 2 ) ) ;
break ;
}
//cformat.clearProperty( TextFormat::HasCodeStyle );
cursor . beginEditBlock ( ) ;
cursor . mergeBlockFormat ( bformat ) ;
cursor . select ( QTextCursor : : BlockUnderCursor ) ;
cursor . mergeCharFormat ( cformat ) ;
cursor . endEditBlock ( ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textStyle ( int styleIndex )
2008-11-25 20:19:09 -05:00
{
QTextCursor cursor = ui . msgText - > textCursor ( ) ;
if ( styleIndex ! = 0 ) {
QTextListFormat : : Style style = QTextListFormat : : ListDisc ;
switch ( styleIndex ) {
default :
case 1 :
style = QTextListFormat : : ListDisc ;
break ;
case 2 :
style = QTextListFormat : : ListCircle ;
break ;
case 3 :
style = QTextListFormat : : ListSquare ;
break ;
case 4 :
style = QTextListFormat : : ListDecimal ;
break ;
case 5 :
style = QTextListFormat : : ListLowerAlpha ;
break ;
case 6 :
style = QTextListFormat : : ListUpperAlpha ;
break ;
}
cursor . beginEditBlock ( ) ;
QTextBlockFormat blockFmt = cursor . blockFormat ( ) ;
QTextListFormat listFmt ;
if ( cursor . currentList ( ) ) {
listFmt = cursor . currentList ( ) - > format ( ) ;
} else {
listFmt . setIndent ( blockFmt . indent ( ) + 1 ) ;
blockFmt . setIndent ( 0 ) ;
cursor . setBlockFormat ( blockFmt ) ;
}
listFmt . setStyle ( style ) ;
cursor . createList ( listFmt ) ;
cursor . endEditBlock ( ) ;
} else {
// ####
QTextBlockFormat bfmt ;
bfmt . setObjectIndex ( - 1 ) ;
cursor . mergeBlockFormat ( bfmt ) ;
}
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textColor ( )
2008-11-25 20:19:09 -05:00
{
QColor col = QColorDialog : : getColor ( ui . msgText - > textColor ( ) , this ) ;
if ( ! col . isValid ( ) )
return ;
QTextCharFormat fmt ;
fmt . setForeground ( col ) ;
mergeFormatOnWordOrSelection ( fmt ) ;
colorChanged ( col ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : textAlign ( QAction * a )
2008-11-25 20:19:09 -05:00
{
if ( a = = actionAlignLeft )
ui . msgText - > setAlignment ( Qt : : AlignLeft ) ;
else if ( a = = actionAlignCenter )
ui . msgText - > setAlignment ( Qt : : AlignHCenter ) ;
else if ( a = = actionAlignRight )
ui . msgText - > setAlignment ( Qt : : AlignRight ) ;
else if ( a = = actionAlignJustify )
ui . msgText - > setAlignment ( Qt : : AlignJustify ) ;
}
2010-11-10 08:35:38 -05:00
void MessageComposer : : smileyWidget ( )
{
Emoticons : : showSmileyWidget ( this , ui . emoticonButton , SLOT ( addSmileys ( ) ) , false ) ;
}
void MessageComposer : : addSmileys ( )
{
ui . msgText - > textCursor ( ) . insertText ( qobject_cast < QPushButton * > ( sender ( ) ) - > toolTip ( ) . split ( " | " ) . first ( ) ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : currentCharFormatChanged ( const QTextCharFormat & format )
2008-11-25 20:19:09 -05:00
{
fontChanged ( format . font ( ) ) ;
colorChanged ( format . foreground ( ) . color ( ) ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : cursorPositionChanged ( )
2008-11-25 20:19:09 -05:00
{
alignmentChanged ( ui . msgText - > alignment ( ) ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : mergeFormatOnWordOrSelection ( const QTextCharFormat & format )
2008-11-25 20:19:09 -05:00
{
QTextCursor cursor = ui . msgText - > textCursor ( ) ;
if ( ! cursor . hasSelection ( ) )
cursor . select ( QTextCursor : : WordUnderCursor ) ;
cursor . mergeCharFormat ( format ) ;
ui . msgText - > mergeCurrentCharFormat ( format ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : fontChanged ( const QFont & f )
2008-11-25 20:19:09 -05:00
{
ui . comboFont - > setCurrentIndex ( ui . comboFont - > findText ( QFontInfo ( f ) . family ( ) ) ) ;
ui . comboSize - > setCurrentIndex ( ui . comboSize - > findText ( QString : : number ( f . pointSize ( ) ) ) ) ;
ui . boldbtn - > setChecked ( f . bold ( ) ) ;
ui . italicbtn - > setChecked ( f . italic ( ) ) ;
ui . underlinebtn - > setChecked ( f . underline ( ) ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : colorChanged ( const QColor & c )
2008-11-25 20:19:09 -05:00
{
QPixmap pix ( 16 , 16 ) ;
pix . fill ( c ) ;
ui . colorbtn - > setIcon ( pix ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : alignmentChanged ( Qt : : Alignment a )
2008-11-25 20:19:09 -05:00
{
if ( a & Qt : : AlignLeft ) {
actionAlignLeft - > setChecked ( true ) ;
} else if ( a & Qt : : AlignHCenter ) {
actionAlignCenter - > setChecked ( true ) ;
} else if ( a & Qt : : AlignRight ) {
actionAlignRight - > setChecked ( true ) ;
} else if ( a & Qt : : AlignJustify ) {
actionAlignJustify - > setChecked ( true ) ;
}
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : clipboardDataChanged ( )
2008-11-25 20:19:09 -05:00
{
actionPaste - > setEnabled ( ! QApplication : : clipboard ( ) - > text ( ) . isEmpty ( ) ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : fileNew ( )
2008-11-25 20:19:09 -05:00
{
if ( maybeSave ( ) ) {
ui . msgText - > clear ( ) ;
//setCurrentFileName(QString());
}
2008-03-24 21:41:01 -04:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : fileOpen ( )
2008-11-25 20:19:09 -05:00
{
2010-12-02 19:54:40 -05:00
QString fn ;
if ( misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_MESSAGES , tr ( " Open File... " ) , tr ( " HTML-Files (*.htm *.html);;All Files (*) " ) , fn ) ) {
2008-11-25 20:19:09 -05:00
load ( fn ) ;
2010-12-02 19:54:40 -05:00
}
2008-03-24 21:41:01 -04:00
}
2007-11-14 22:18:48 -05:00
2010-05-23 15:13:41 -04:00
bool MessageComposer : : fileSave ( )
2008-11-25 20:19:09 -05:00
{
if ( fileName . isEmpty ( ) )
return fileSaveAs ( ) ;
QFile file ( fileName ) ;
if ( ! file . open ( QFile : : WriteOnly ) )
return false ;
QTextStream ts ( & file ) ;
ts . setCodec ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
ts < < ui . msgText - > document ( ) - > toHtml ( " UTF-8 " ) ;
ui . msgText - > document ( ) - > setModified ( false ) ;
return true ;
2008-03-26 15:30:34 -04:00
}
2010-05-23 15:13:41 -04:00
bool MessageComposer : : fileSaveAs ( )
2008-11-25 20:19:09 -05:00
{
2010-12-02 19:54:40 -05:00
QString fn ;
if ( misc : : getSaveFileName ( this , RshareSettings : : LASTDIR_MESSAGES , tr ( " Save as... " ) , tr ( " HTML-Files (*.htm *.html);;All Files (*) " ) , fn ) ) {
setCurrentFileName ( fn ) ;
return fileSave ( ) ;
}
return false ;
2008-03-26 15:30:34 -04:00
}
2010-05-25 06:41:26 -04:00
void MessageComposer : : saveasDraft ( )
{
sendMessage_internal ( true ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : filePrint ( )
2008-11-25 20:19:09 -05:00
{
# ifndef QT_NO_PRINTER
QPrinter printer ( QPrinter : : HighResolution ) ;
printer . setFullPage ( true ) ;
QPrintDialog * dlg = new QPrintDialog ( & printer , this ) ;
if ( ui . msgText - > textCursor ( ) . hasSelection ( ) )
dlg - > addEnabledOption ( QAbstractPrintDialog : : PrintSelection ) ;
dlg - > setWindowTitle ( tr ( " Print Document " ) ) ;
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
ui . msgText - > print ( & printer ) ;
}
delete dlg ;
# endif
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : filePrintPdf ( )
2008-11-25 20:19:09 -05:00
{
# ifndef QT_NO_PRINTER
2010-12-02 19:54:40 -05:00
QString fileName ;
if ( misc : : getSaveFileName ( this , RshareSettings : : LASTDIR_MESSAGES , tr ( " Export PDF " ) , " *.pdf " , fileName ) ) {
2008-11-25 20:19:09 -05:00
if ( QFileInfo ( fileName ) . suffix ( ) . isEmpty ( ) )
fileName . append ( " .pdf " ) ;
QPrinter printer ( QPrinter : : HighResolution ) ;
printer . setOutputFormat ( QPrinter : : PdfFormat ) ;
printer . setOutputFileName ( fileName ) ;
ui . msgText - > document ( ) - > print ( & printer ) ;
}
# endif
2008-03-24 21:41:01 -04:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : setCurrentFileName ( const QString & fileName )
2008-11-25 20:19:09 -05:00
{
this - > fileName = fileName ;
ui . msgText - > document ( ) - > setModified ( false ) ;
setWindowModified ( false ) ;
2008-03-24 21:41:01 -04:00
}
2010-05-23 15:13:41 -04:00
bool MessageComposer : : load ( const QString & f )
2008-11-25 20:19:09 -05:00
{
if ( ! QFile : : exists ( f ) )
return false ;
QFile file ( f ) ;
if ( ! file . open ( QFile : : ReadOnly ) )
return false ;
QByteArray data = file . readAll ( ) ;
QTextCodec * codec = Qt : : codecForHtml ( data ) ;
QString str = codec - > toUnicode ( data ) ;
if ( Qt : : mightBeRichText ( str ) ) {
ui . msgText - > setHtml ( str ) ;
} else {
str = QString : : fromLocal8Bit ( data ) ;
ui . msgText - > setPlainText ( str ) ;
}
setCurrentFileName ( f ) ;
return true ;
2008-03-24 21:41:01 -04:00
}
2010-05-23 15:13:41 -04:00
bool MessageComposer : : maybeSave ( )
2008-11-25 20:19:09 -05:00
{
if ( ! ui . msgText - > document ( ) - > isModified ( ) )
return true ;
if ( fileName . startsWith ( QLatin1String ( " :/ " ) ) )
return true ;
QMessageBox : : StandardButton ret ;
ret = QMessageBox : : warning ( this , tr ( " Save Message " ) ,
tr ( " Message has not been Sent. \n "
" Do you want to save message ? " ) ,
QMessageBox : : Save | QMessageBox : : Discard
| QMessageBox : : Cancel ) ;
if ( ret = = QMessageBox : : Save )
return fileSave ( ) ;
else if ( ret = = QMessageBox : : Cancel )
return false ;
return true ;
2008-03-24 21:41:01 -04:00
}
2008-11-25 20:19:09 -05:00
2010-05-23 15:13:41 -04:00
void MessageComposer : : toggleContacts ( )
2008-11-25 20:19:09 -05:00
{
2010-09-27 17:05:52 -04:00
ui . contactsdockWidget - > setVisible ( ! ui . contactsdockWidget - > isVisible ( ) ) ;
2015-01-02 20:40:23 -05:00
updatecontactsviewicons ( ) ;
2010-09-27 17:05:52 -04:00
}
void MessageComposer : : on_contactsdockWidget_visibilityChanged ( bool visible )
{
contactSidebarAction - > setChecked ( visible ) ;
2015-01-02 20:40:23 -05:00
updatecontactsviewicons ( ) ;
}
void MessageComposer : : updatecontactsviewicons ( )
{
if ( ! ui . contactsdockWidget - > isVisible ( ) ) {
ui . actionContactsView - > setIcon ( QIcon ( " :/images/contactsclosed24.png " ) ) ;
} else {
ui . actionContactsView - > setIcon ( QIcon ( " :/images/contacts24.png " ) ) ;
}
2008-03-24 13:36:17 -04:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : addImage ( )
2008-11-25 20:19:09 -05:00
{
2012-09-18 18:59:23 -04:00
QString file ;
if ( misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_IMAGES , tr ( " Choose Image " ) , tr ( " Image Files supported (*.png *.jpeg *.jpg *.gif) " ) , file ) ) {
QString encodedImage ;
if ( RsHtml : : makeEmbeddedImage ( file , encodedImage , 640 * 480 ) ) {
QTextDocumentFragment fragment = QTextDocumentFragment : : fromHtml ( encodedImage ) ;
ui . msgText - > textCursor ( ) . insertFragment ( fragment ) ;
}
2010-12-02 19:54:40 -05:00
}
2008-03-25 08:28:13 -04:00
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : fontSizeIncrease ( )
2010-01-25 09:03:38 -05:00
{
if ( ! ( ui . msgText - > textCursor ( ) . blockFormat ( ) . hasProperty ( TextFormat : : HtmlHeading ) & &
ui . msgText - > textCursor ( ) . blockFormat ( ) . intProperty ( TextFormat : : HtmlHeading ) ) ) {
QTextCharFormat format ;
int idx = ui . msgText - > currentCharFormat ( ) . intProperty ( QTextFormat : : FontSizeAdjustment ) ;
if ( idx < 3 ) {
format . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( + + idx ) ) ;
ui . msgText - > textCursor ( ) . mergeCharFormat ( format ) ;
}
}
ui . msgText - > setFocus ( Qt : : OtherFocusReason ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : fontSizeDecrease ( )
2010-01-25 09:03:38 -05:00
{
if ( ! ( ui . msgText - > textCursor ( ) . blockFormat ( ) . hasProperty ( TextFormat : : HtmlHeading ) & &
ui . msgText - > textCursor ( ) . blockFormat ( ) . intProperty ( TextFormat : : HtmlHeading ) ) ) {
QTextCharFormat format ;
int idx = ui . msgText - > currentCharFormat ( ) . intProperty ( QTextFormat : : FontSizeAdjustment ) ;
if ( idx > - 1 ) {
format . setProperty ( QTextFormat : : FontSizeAdjustment , QVariant ( - - idx ) ) ;
ui . msgText - > textCursor ( ) . mergeCharFormat ( format ) ;
}
}
ui . msgText - > setFocus ( Qt : : OtherFocusReason ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : blockQuote ( )
2010-01-25 09:03:38 -05:00
{
QTextBlockFormat blockFormat = ui . msgText - > textCursor ( ) . blockFormat ( ) ;
QTextBlockFormat f ;
2010-09-27 17:05:52 -04:00
if ( blockFormat . hasProperty ( TextFormat : : IsBlockQuote ) & &
2010-01-25 09:03:38 -05:00
blockFormat . boolProperty ( TextFormat : : IsBlockQuote ) ) {
f . setProperty ( TextFormat : : IsBlockQuote , QVariant ( false ) ) ;
f . setLeftMargin ( 0 ) ;
f . setRightMargin ( 0 ) ;
} else {
f . setProperty ( TextFormat : : IsBlockQuote , QVariant ( true ) ) ;
f . setLeftMargin ( 40 ) ;
f . setRightMargin ( 40 ) ;
}
ui . msgText - > textCursor ( ) . mergeBlockFormat ( f ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : toggleCode ( )
2010-01-25 09:03:38 -05:00
{
static QString preFontFamily ;
QTextCharFormat charFormat = ui . msgText - > currentCharFormat ( ) ;
QTextCharFormat f ;
2010-09-27 17:05:52 -04:00
2010-01-25 09:03:38 -05:00
if ( charFormat . hasProperty ( TextFormat : : HasCodeStyle ) & &
charFormat . boolProperty ( TextFormat : : HasCodeStyle ) ) {
f . setProperty ( TextFormat : : HasCodeStyle , QVariant ( false ) ) ;
f . setBackground ( defaultCharFormat . background ( ) ) ;
f . setFontFamily ( preFontFamily ) ;
ui . msgText - > textCursor ( ) . mergeCharFormat ( f ) ;
} else {
preFontFamily = ui . msgText - > fontFamily ( ) ;
f . setProperty ( TextFormat : : HasCodeStyle , QVariant ( true ) ) ;
f . setBackground ( codeBackground ) ;
f . setFontFamily ( " Dejavu Sans Mono " ) ;
ui . msgText - > textCursor ( ) . mergeCharFormat ( f ) ;
}
ui . msgText - > setFocus ( Qt : : OtherFocusReason ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : addPostSplitter ( )
2010-01-25 10:36:24 -05:00
{
QTextBlockFormat f = ui . msgText - > textCursor ( ) . blockFormat ( ) ;
QTextBlockFormat f1 = f ;
f . setProperty ( TextFormat : : IsHtmlTagSign , true ) ;
2010-09-27 17:05:52 -04:00
f . setProperty ( QTextFormat : : BlockTrailingHorizontalRulerWidth ,
2010-01-25 10:36:24 -05:00
QTextLength ( QTextLength : : PercentageLength , 80 ) ) ;
if ( ui . msgText - > textCursor ( ) . block ( ) . text ( ) . isEmpty ( ) ) {
ui . msgText - > textCursor ( ) . mergeBlockFormat ( f ) ;
} else {
ui . msgText - > textCursor ( ) . insertBlock ( f ) ;
}
ui . msgText - > textCursor ( ) . insertBlock ( f1 ) ;
}
2010-05-23 15:13:41 -04:00
void MessageComposer : : attachFile ( )
2010-01-20 16:39:27 -05:00
{
2010-09-27 17:05:52 -04:00
// select a file
2010-12-02 19:54:40 -05:00
QStringList files ;
if ( misc : : getOpenFileNames ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , files ) ) {
2012-11-11 16:17:00 -05:00
ui . hashBox - > addAttachments ( files , TransferRequestFlags ( 0u ) ) ;
2010-09-27 17:05:52 -04:00
}
}
2011-12-07 08:08:12 -05:00
void MessageComposer : : fileHashingStarted ( )
2010-09-27 17:05:52 -04:00
{
2011-12-07 08:08:12 -05:00
std : : cerr < < " MessageComposer::fileHashingStarted() started. " < < std : : endl ;
2010-09-27 17:05:52 -04:00
/* add widget in for new destination */
2010-11-26 10:32:46 -05:00
ui . msgFileList - > hide ( ) ;
2011-12-07 08:08:12 -05:00
ui . hashBox - > show ( ) ;
2010-01-20 16:39:27 -05:00
}
2008-03-26 15:30:34 -04:00
2011-12-07 08:08:12 -05:00
void MessageComposer : : fileHashingFinished ( QList < HashedFile > hashedFiles )
2010-01-21 11:35:00 -05:00
{
2011-12-07 08:08:12 -05:00
std : : cerr < < " MessageComposer::fileHashingFinished() started. " < < std : : endl ;
2010-01-21 11:35:00 -05:00
2011-12-07 08:08:12 -05:00
QList < HashedFile > : : iterator it ;
for ( it = hashedFiles . begin ( ) ; it ! = hashedFiles . end ( ) ; + + it ) {
FileInfo info ;
info . fname = it - > filename . toUtf8 ( ) . constData ( ) ;
info . hash = it - > hash ;
info . size = it - > size ;
addFile ( info ) ;
2010-09-27 17:05:52 -04:00
}
2010-01-21 11:35:00 -05:00
2011-12-07 08:08:12 -05:00
ui . actionSend - > setEnabled ( true ) ;
ui . hashBox - > hide ( ) ;
ui . msgFileList - > show ( ) ;
2010-01-21 11:35:00 -05:00
}
2010-05-29 15:05:10 -04:00
2012-01-26 19:32:17 -05:00
void MessageComposer : : addContact ( enumType type )
2010-05-29 15:05:10 -04:00
{
2014-11-07 14:06:23 -05:00
std : : list < RsPeerId > peerIds ;
ui . friendSelectionWidget - > selectedIds < RsPeerId , FriendSelectionWidget : : IDTYPE_SSL > ( peerIds , false ) ;
for ( std : : list < RsPeerId > : : const_iterator idIt = peerIds . begin ( ) ; idIt ! = peerIds . end ( ) ; + + idIt )
addRecipient ( type , * idIt ) ;
2014-11-24 16:02:18 -05:00
std : : list < RsGxsId > gxsIds ;
ui . friendSelectionWidget - > selectedIds < RsGxsId , FriendSelectionWidget : : IDTYPE_GXS > ( gxsIds , false ) ;
2014-11-07 14:06:23 -05:00
for ( std : : list < RsGxsId > : : const_iterator idIt = gxsIds . begin ( ) ; idIt ! = gxsIds . end ( ) ; + + idIt )
2014-03-29 10:18:05 -04:00
addRecipient ( type , * idIt ) ;
2010-09-27 17:05:52 -04:00
}
2015-01-10 19:53:16 -05:00
void MessageComposer : : filterComboBoxChanged ( int i )
2013-09-07 10:02:24 -04:00
{
2015-01-10 19:53:16 -05:00
switch ( i )
{
case 0 : ui . friendSelectionWidget - > setShowType ( FriendSelectionWidget : : SHOW_GROUP
2013-09-07 10:02:24 -04:00
| FriendSelectionWidget : : SHOW_SSL
2015-01-10 19:53:16 -05:00
| FriendSelectionWidget : : SHOW_GXS ) ;
break ;
case 1 : ui . friendSelectionWidget - > setShowType ( FriendSelectionWidget : : SHOW_GROUP
| FriendSelectionWidget : : SHOW_SSL ) ;
break ;
case 2 : ui . friendSelectionWidget - > setShowType ( FriendSelectionWidget : : SHOW_GXS ) ;
break ;
default : ;
}
2014-03-29 10:18:05 -04:00
2013-09-07 10:02:24 -04:00
}
2011-05-21 12:26:00 -04:00
void MessageComposer : : addTo ( )
{
addContact ( TO ) ;
}
void MessageComposer : : addCc ( )
{
addContact ( CC ) ;
}
void MessageComposer : : addBcc ( )
{
addContact ( BCC ) ;
}
void MessageComposer : : addRecommend ( )
2010-09-27 17:05:52 -04:00
{
2014-03-29 10:18:05 -04:00
std : : list < RsPeerId > sslIds ;
ui . friendSelectionWidget - > selectedIds < RsPeerId , FriendSelectionWidget : : IDTYPE_SSL > ( sslIds , false ) ;
2010-09-27 17:05:52 -04:00
2014-03-29 10:18:05 -04:00
std : : list < RsGxsId > gxsIds ;
ui . friendSelectionWidget - > selectedIds < RsGxsId , FriendSelectionWidget : : IDTYPE_GXS > ( gxsIds , true ) ;
2010-09-27 17:05:52 -04:00
2014-03-29 10:18:05 -04:00
if ( sslIds . empty ( ) & & gxsIds . empty ( ) )
return ;
2014-10-21 18:33:02 -04:00
for ( std : : list < RsPeerId > : : iterator it = sslIds . begin ( ) ; it ! = sslIds . end ( ) ; + + it )
2014-03-29 10:18:05 -04:00
addRecipient ( CC , * it ) ;
2014-10-21 18:33:02 -04:00
for ( std : : list < RsGxsId > : : const_iterator it = gxsIds . begin ( ) ; it ! = gxsIds . end ( ) ; + + it )
2014-03-29 10:18:05 -04:00
addRecipient ( TO , * it ) ;
2011-06-14 16:42:32 -04:00
2014-03-29 10:18:05 -04:00
QString text = buildRecommendHtml ( sslIds ) ;
ui . msgText - > textCursor ( ) . insertHtml ( text ) ;
ui . msgText - > setFocus ( Qt : : OtherFocusReason ) ;
2010-09-27 17:05:52 -04:00
}
2010-11-16 04:31:30 -05:00
2011-05-21 12:26:00 -04:00
void MessageComposer : : friendDetails ( )
{
2012-01-26 19:32:17 -05:00
FriendSelectionWidget : : IdType idType ;
2013-01-22 19:22:17 -05:00
std : : string id = ui . friendSelectionWidget - > selectedId ( idType ) ;
2011-05-21 12:26:00 -04:00
2013-01-22 19:22:17 -05:00
if ( id . empty ( ) | | idType ! = FriendSelectionWidget : : IDTYPE_SSL ) {
2011-05-21 12:26:00 -04:00
return ;
}
2014-03-17 16:56:06 -04:00
ConfCertDialog : : showIt ( RsPeerId ( id ) , ConfCertDialog : : PageDetails ) ;
2011-05-21 12:26:00 -04:00
}
2015-01-24 14:27:19 -05:00
void MessageComposer : : identityDetails ( )
{
FriendSelectionWidget : : IdType idType ;
std : : string id = ui . friendSelectionWidget - > selectedId ( idType ) ;
if ( id . empty ( ) | | idType ! = FriendSelectionWidget : : IDTYPE_GXS ) {
return ;
}
if ( RsGxsGroupId ( id ) . isNull ( ) ) {
return ;
}
2015-01-25 07:24:10 -05:00
IdDetailsDialog * dialog = new IdDetailsDialog ( RsGxsGroupId ( id ) ) ;
dialog - > show ( ) ;
/* Dialog will destroy itself */
2015-01-24 14:27:19 -05:00
}
2011-05-21 12:26:00 -04:00
void MessageComposer : : tagAboutToShow ( )
{
TagsMenu * menu = dynamic_cast < TagsMenu * > ( ui . tagButton - > menu ( ) ) ;
if ( menu = = NULL ) {
return ;
}
menu - > activateActions ( m_tagIds ) ;
}
void MessageComposer : : tagRemoveAll ( )
{
m_tagIds . clear ( ) ;
showTagLabels ( ) ;
}
void MessageComposer : : tagSet ( int tagId , bool set )
{
if ( tagId = = 0 ) {
return ;
}
std : : list < uint32_t > : : iterator tag = std : : find ( m_tagIds . begin ( ) , m_tagIds . end ( ) , tagId ) ;
if ( tag = = m_tagIds . end ( ) ) {
if ( set ) {
m_tagIds . push_back ( tagId ) ;
/* Keep the list sorted */
m_tagIds . sort ( ) ;
2011-12-07 08:08:12 -05:00
}
2011-05-21 12:26:00 -04:00
} else {
if ( set = = false ) {
m_tagIds . remove ( tagId ) ;
}
}
showTagLabels ( ) ;
}
void MessageComposer : : clearTagLabels ( )
{
/* clear all tags */
while ( tagLabels . size ( ) ) {
delete tagLabels . front ( ) ;
tagLabels . pop_front ( ) ;
}
while ( ui . tagLayout - > count ( ) ) {
delete ui . tagLayout - > takeAt ( 0 ) ;
}
}
void MessageComposer : : showTagLabels ( )
{
clearTagLabels ( ) ;
if ( m_tagIds . empty ( ) = = false ) {
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 ;
2014-10-21 18:33:02 -04:00
for ( std : : list < uint32_t > : : iterator tagId = m_tagIds . begin ( ) ; tagId ! = m_tagIds . end ( ) ; + + tagId ) {
2011-05-21 12:26:00 -04:00
tag = tags . types . find ( * tagId ) ;
if ( tag ! = tags . types . end ( ) ) {
QLabel * tagLabel = new QLabel ( TagDefs : : name ( tag - > first , tag - > second . first ) , this ) ;
tagLabel - > setMaximumHeight ( 16 ) ;
tagLabel - > setStyleSheet ( TagDefs : : labelStyleSheet ( tag - > second . second ) ) ;
tagLabels . push_back ( tagLabel ) ;
ui . tagLayout - > addWidget ( tagLabel ) ;
ui . tagLayout - > addSpacing ( 3 ) ;
}
}
ui . tagLayout - > addStretch ( ) ;
}
}
2015-01-02 20:40:23 -05:00
void MessageComposer : : on_closeInfoFrameButton_clicked ( )
{
ui . distantFrame - > setVisible ( false ) ;
2015-01-22 17:54:41 -05:00
}