2011-06-04 00:46:02 +00:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 - 2011 RetroShare Team
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QMenu>
# include <QToolButton>
# include <QDateTime>
# include <QMessageBox>
# include <QPrinter>
# include <QPrintDialog>
2012-05-12 00:40:53 +00:00
# include <QFile>
# include <QTextStream>
# include <QTextCodec>
2011-06-04 00:46:02 +00:00
# include "gui/notifyqt.h"
# include "gui/RetroShareLink.h"
# include "gui/common/TagDefs.h"
# include "gui/common/PeerDefs.h"
# include "gui/common/Emoticons.h"
# include "gui/settings/rsharesettings.h"
# include "MessageComposer.h"
# include "MessageWidget.h"
# include "MessageWindow.h"
# include "util/misc.h"
# include "util/printpreview.h"
2012-05-12 00:40:53 +00:00
# include "util/HandleRichText.h"
2012-11-15 21:35:37 +00:00
# include "util/DateTime.h"
2013-10-19 13:25:06 +00:00
# include "util/QtVersion.h"
2011-06-04 00:46:02 +00:00
# include <retroshare/rspeers.h>
# include <retroshare/rsfiles.h>
# include <retroshare/rsmsgs.h>
/* Images for context menu icons */
# define IMAGE_DOWNLOAD ": / images / start.png"
# define IMAGE_DOWNLOADALL ": / images / startall.png"
# define COLUMN_FILE_NAME 0
# define COLUMN_FILE_SIZE 1
# define COLUMN_FILE_HASH 2
# define COLUMN_FILE_COUNT 3
2015-03-22 04:52:53 +00:00
# include "gui/msgs/MessageInterface.h"
2012-05-12 00:40:53 +00:00
class RsHtmlMsg : public RsHtml
{
public :
RsHtmlMsg ( uint msgFlags ) : RsHtml ( )
{
this - > msgFlags = msgFlags ;
}
protected :
virtual void anchorTextForImg ( QDomDocument & doc , QDomElement & element , const RetroShareLink & link , QString & text )
{
if ( link . type ( ) = = RetroShareLink : : TYPE_CERTIFICATE ) {
if ( msgFlags & RS_MSG_USER_REQUEST ) {
text = QApplication : : translate ( " MessageWidget " , " Confirm %1 as friend " ) . arg ( link . name ( ) ) ;
return ;
}
if ( msgFlags & RS_MSG_FRIEND_RECOMMENDATION ) {
text = QApplication : : translate ( " MessageWidget " , " Add %1 as friend " ) . arg ( link . name ( ) ) ;
return ;
}
}
RsHtml : : anchorTextForImg ( doc , element , link , text ) ;
}
protected :
uint msgFlags ;
} ;
2011-06-04 00:46:02 +00:00
MessageWidget * MessageWidget : : openMsg ( const std : : string & msgId , bool window )
{
if ( msgId . empty ( ) ) {
return NULL ;
}
MessageInfo msgInfo ;
2015-03-22 04:52:53 +00:00
if ( ! rsMail - > getMessage ( msgId , msgInfo ) ) {
2011-06-04 00:46:02 +00:00
std : : cerr < < " MessageWidget::openMsg() Couldn't find Msg " < < std : : endl ;
return NULL ;
}
MessageWindow * parent = NULL ;
if ( window ) {
parent = new MessageWindow ;
}
MessageWidget * msgWidget = new MessageWidget ( false , parent ) ;
msgWidget - > isWindow = window ;
2014-05-08 08:39:04 +00:00
msgWidget - > fill ( msgId ) ;
2011-06-04 00:46:02 +00:00
if ( parent ) {
parent - > addWidget ( msgWidget ) ;
}
if ( parent ) {
parent - > show ( ) ;
parent - > activateWindow ( ) ;
}
return msgWidget ;
}
/** Constructor */
2013-10-18 21:10:33 +00:00
MessageWidget : : MessageWidget ( bool controlled , QWidget * parent , Qt : : WindowFlags flags )
2017-11-18 18:49:42 +01:00
: QWidget ( parent , flags ) , toolButtonReply ( NULL )
2011-06-04 00:46:02 +00:00
{
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
isControlled = controlled ;
isWindow = false ;
2012-08-16 10:20:34 +00:00
currMsgFlags = 0 ;
2011-06-04 00:46:02 +00:00
connect ( ui . msgList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( msgfilelistWidgetCostumPopupMenu ( QPoint ) ) ) ;
connect ( ui . expandFilesButton , SIGNAL ( clicked ( ) ) , this , SLOT ( togglefileview ( ) ) ) ;
connect ( ui . downloadButton , SIGNAL ( clicked ( ) ) , this , SLOT ( getallrecommended ( ) ) ) ;
2012-08-16 10:20:34 +00:00
connect ( ui . msgText , SIGNAL ( anchorClicked ( QUrl ) ) , this , SLOT ( anchorClicked ( QUrl ) ) ) ;
2017-06-21 06:35:29 +02:00
connect ( ui . sendInviteButton , SIGNAL ( clicked ( ) ) , this , SLOT ( sendInvite ( ) ) ) ;
2011-06-04 00:46:02 +00:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( messagesTagsChanged ( ) ) , this , SLOT ( messagesTagsChanged ( ) ) ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( messagesChanged ( ) ) , this , SLOT ( messagesChanged ( ) ) ) ;
2013-09-24 20:19:21 +00:00
ui . imageBlockWidget - > addButtonAction ( tr ( " Load images always for this message " ) , this , SLOT ( loadImagesAlways ( ) ) , true ) ;
2013-09-23 19:53:26 +00:00
ui . msgText - > setImageBlockWidget ( ui . imageBlockWidget ) ;
2011-06-04 00:46:02 +00:00
/* hide the Tree +/- */
ui . msgList - > setRootIsDecorated ( false ) ;
ui . msgList - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
/* Set header resize modes and initial section sizes */
QHeaderView * msglheader = ui . msgList - > header ( ) ;
2015-06-26 08:14:09 +00:00
QHeaderView_setSectionResizeModeColumn ( msglheader , COLUMN_FILE_NAME , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( msglheader , COLUMN_FILE_SIZE , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( msglheader , COLUMN_FILE_HASH , QHeaderView : : Interactive ) ;
2011-06-04 00:46:02 +00:00
msglheader - > resizeSection ( COLUMN_FILE_NAME , 200 ) ;
msglheader - > resizeSection ( COLUMN_FILE_SIZE , 100 ) ;
msglheader - > resizeSection ( COLUMN_FILE_HASH , 200 ) ;
QFont font = QFont ( " Arial " , 10 , QFont : : Bold ) ;
ui . subjectText - > setFont ( font ) ;
2017-06-21 06:35:29 +02:00
ui . toText - > setMaximumHeight ( ui . toText - > fontMetrics ( ) . lineSpacing ( ) * 1.5 ) ;
ui . ccLabel - > setVisible ( false ) ;
2011-06-04 00:46:02 +00:00
ui . ccText - > setVisible ( false ) ;
2017-06-21 06:35:29 +02:00
ui . ccText - > setMaximumHeight ( ui . ccText - > fontMetrics ( ) . lineSpacing ( ) * 1.5 ) ;
ui . bccLabel - > setVisible ( false ) ;
ui . bccText - > setVisible ( false ) ;
ui . bccText - > setMaximumHeight ( ui . bccText - > fontMetrics ( ) . lineSpacing ( ) * 1.5 ) ;
2011-06-04 00:46:02 +00:00
ui . tagsLabel - > setVisible ( false ) ;
2015-03-16 14:40:30 +00:00
ui . msgText - > activateLinkClick ( false ) ;
2011-06-04 00:46:02 +00:00
if ( isControlled = = false ) {
processSettings ( " MessageWidget " , true ) ;
}
2012-03-12 00:27:18 +00:00
ui . dateText - > setText ( " " ) ;
2017-02-07 17:01:36 +01:00
ui . inviteFrame - > hide ( ) ;
2011-06-04 00:46:02 +00:00
}
MessageWidget : : ~ MessageWidget ( )
{
if ( isControlled = = false ) {
processSettings ( " MessageWidget " , false ) ;
}
}
void MessageWidget : : connectAction ( enumActionType actionType , QToolButton * button )
{
switch ( actionType ) {
case ACTION_REMOVE :
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( remove ( ) ) ) ;
break ;
case ACTION_REPLY :
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( reply ( ) ) ) ;
2017-11-18 18:49:42 +01:00
toolButtonReply = button ;
2011-06-04 00:46:02 +00:00
break ;
case ACTION_REPLY_ALL :
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( replyAll ( ) ) ) ;
break ;
case ACTION_FORWARD :
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( forward ( ) ) ) ;
break ;
case ACTION_PRINT :
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( print ( ) ) ) ;
break ;
case ACTION_PRINT_PREVIEW :
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( printPreview ( ) ) ) ;
break ;
case ACTION_SAVE_AS :
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( saveAs ( ) ) ) ;
break ;
}
}
void MessageWidget : : connectAction ( enumActionType actionType , QAction * action )
{
switch ( actionType ) {
case ACTION_REMOVE :
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( remove ( ) ) ) ;
break ;
case ACTION_REPLY :
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( reply ( ) ) ) ;
break ;
case ACTION_REPLY_ALL :
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( replyAll ( ) ) ) ;
break ;
case ACTION_FORWARD :
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( forward ( ) ) ) ;
break ;
case ACTION_PRINT :
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( print ( ) ) ) ;
break ;
case ACTION_PRINT_PREVIEW :
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( printPreview ( ) ) ) ;
break ;
case ACTION_SAVE_AS :
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( saveAs ( ) ) ) ;
break ;
}
}
void MessageWidget : : processSettings ( const QString & settingsGroup , bool load )
{
Settings - > beginGroup ( settingsGroup ) ;
if ( load ) {
// load settings
// expandFiles
2014-11-25 01:01:43 +00:00
bool value = Settings - > value ( " expandFiles " , false ) . toBool ( ) ;
2011-06-04 00:46:02 +00:00
ui . expandFilesButton - > setChecked ( value ) ;
ui . msgList - > setVisible ( value ) ;
togglefileview ( ) ;
} else {
// save settings
// expandFiles
Settings - > setValue ( " expandFiles " , ui . expandFilesButton - > isChecked ( ) ) ;
}
Settings - > endGroup ( ) ;
}
QString MessageWidget : : subject ( bool noEmpty )
{
QString subject = ui . subjectText - > text ( ) ;
if ( subject . isEmpty ( ) & & noEmpty ) {
return " [ " + tr ( " No subject " ) + " ] " ;
}
return subject ;
}
2011-08-12 14:06:29 +00:00
void MessageWidget : : msgfilelistWidgetCostumPopupMenu ( QPoint /*point*/ )
2011-06-04 00:46:02 +00:00
{
QMenu contextMnu ( this ) ;
contextMnu . addAction ( QIcon ( IMAGE_DOWNLOAD ) , tr ( " Download " ) , this , SLOT ( getcurrentrecommended ( ) ) ) ;
contextMnu . addAction ( QIcon ( IMAGE_DOWNLOADALL ) , tr ( " Download all " ) , this , SLOT ( getallrecommended ( ) ) ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
void MessageWidget : : togglefileview ( )
{
/* if msg header visible -> change icon and tooltip
* three widgets . . .
*/
if ( ui . expandFilesButton - > isChecked ( ) ) {
ui . expandFilesButton - > setIcon ( QIcon ( QString ( " :/images/edit_remove24.png " ) ) ) ;
2014-11-25 01:01:43 +00:00
ui . expandFilesButton - > setToolTip ( tr ( " Hide the attachment pane " ) ) ;
2011-06-04 00:46:02 +00:00
} else {
ui . expandFilesButton - > setIcon ( QIcon ( QString ( " :/images/edit_add24.png " ) ) ) ;
2014-11-25 01:01:43 +00:00
ui . expandFilesButton - > setToolTip ( tr ( " Show the attachment pane " ) ) ;
2011-06-04 00:46:02 +00:00
}
}
/* download the recommendations... */
void MessageWidget : : getcurrentrecommended ( )
{
MessageInfo msgInfo ;
2015-03-22 04:52:53 +00:00
if ( rsMail - > getMessage ( currMsgId , msgInfo ) = = false ) {
2011-06-04 00:46:02 +00:00
return ;
}
2014-03-17 20:56:06 +00:00
std : : list < RsPeerId > srcIds ;
2014-03-29 14:18:05 +00:00
srcIds . push_back ( msgInfo . rspeerid_srcId ) ;
2011-06-04 00:46:02 +00:00
QModelIndexList list = ui . msgList - > selectionModel ( ) - > selectedIndexes ( ) ;
std : : map < int , FileInfo > files ;
for ( QModelIndexList : : const_iterator it ( list . begin ( ) ) ; it ! = list . end ( ) ; + + it ) {
FileInfo & fi ( files [ it - > row ( ) ] ) ;
switch ( it - > column ( ) ) {
case COLUMN_FILE_NAME :
2011-10-11 23:29:38 +00:00
fi . fname = it - > data ( ) . toString ( ) . toUtf8 ( ) . constData ( ) ;
2011-06-04 00:46:02 +00:00
break ;
case COLUMN_FILE_SIZE :
fi . size = it - > data ( ) . toULongLong ( ) ;
break ;
case COLUMN_FILE_HASH :
2014-04-20 16:34:26 +00:00
fi . hash = RsFileHash ( it - > data ( ) . toString ( ) . toStdString ( ) ) ;
2011-06-04 00:46:02 +00:00
break ;
}
}
for ( std : : map < int , FileInfo > : : const_iterator it ( files . begin ( ) ) ; it ! = files . end ( ) ; + + it ) {
const FileInfo & fi ( it - > second ) ;
std : : cout < < " Requesting file " < < fi . fname < < " , size= " < < fi . size < < " , hash= " < < fi . hash < < std : : endl ;
2012-11-02 13:52:29 +00:00
if ( rsFiles - > FileRequest ( fi . fname , fi . hash , fi . size , " " , RS_FILE_REQ_ANONYMOUS_ROUTING , srcIds ) = = false ) {
2015-06-12 08:27:26 +00:00
QMessageBox mb ( QObject : : tr ( " File Request canceled " ) , QObject : : tr ( " The following has not been added to your download list, because you already have it: " ) + " \n " + QString : : fromUtf8 ( fi . fname . c_str ( ) ) , QMessageBox : : Critical , QMessageBox : : Ok , 0 , 0 ) ;
2011-06-04 00:46:02 +00:00
mb . exec ( ) ;
}
}
}
void MessageWidget : : getallrecommended ( )
{
/* get Message */
MessageInfo msgInfo ;
2015-03-22 04:52:53 +00:00
if ( rsMail - > getMessage ( currMsgId , msgInfo ) = = false ) {
2011-06-04 00:46:02 +00:00
return ;
}
const std : : list < FileInfo > & recList = msgInfo . files ;
std : : list < FileInfo > : : const_iterator it ;
/* do the requests */
2014-10-21 22:33:02 +00:00
for ( it = recList . begin ( ) ; it ! = recList . end ( ) ; + + it ) {
2011-06-04 00:46:02 +00:00
std : : cerr < < " MessageWidget::getallrecommended() Calling File Request " < < std : : endl ;
2014-03-17 20:56:06 +00:00
std : : list < RsPeerId > srcIds ;
2014-03-29 14:18:05 +00:00
srcIds . push_back ( msgInfo . rspeerid_srcId ) ;
2012-11-02 13:52:29 +00:00
rsFiles - > FileRequest ( it - > fname , it - > hash , it - > size , " " , RS_FILE_REQ_ANONYMOUS_ROUTING , srcIds ) ;
2011-06-04 00:46:02 +00:00
}
}
void MessageWidget : : messagesTagsChanged ( )
{
showTagLabels ( ) ;
}
void MessageWidget : : messagesChanged ( )
{
if ( isControlled ) {
/* processed by MessagesDialog */
return ;
}
/* test Message */
MessageInfo msgInfo ;
2015-03-22 04:52:53 +00:00
if ( rsMail - > getMessage ( currMsgId , msgInfo ) = = false ) {
2011-06-04 00:46:02 +00:00
/* messages was removed */
if ( isWindow ) {
window ( ) - > close ( ) ;
} else {
deleteLater ( ) ;
}
}
}
void MessageWidget : : clearTagLabels ( )
{
/* clear all tags */
while ( tagLabels . size ( ) ) {
delete tagLabels . front ( ) ;
tagLabels . pop_front ( ) ;
}
while ( ui . tagLayout - > count ( ) ) {
delete ui . tagLayout - > takeAt ( 0 ) ;
}
ui . tagsLabel - > setVisible ( false ) ;
}
void MessageWidget : : showTagLabels ( )
{
clearTagLabels ( ) ;
if ( currMsgId . empty ( ) ) {
return ;
}
MsgTagInfo tagInfo ;
2015-03-22 04:52:53 +00:00
rsMail - > getMessageTag ( currMsgId , tagInfo ) ;
2011-06-04 00:46:02 +00:00
if ( tagInfo . tagIds . empty ( ) = = false ) {
ui . tagsLabel - > setVisible ( true ) ;
MsgTagType Tags ;
2015-03-22 04:52:53 +00:00
rsMail - > getMessageTagTypes ( Tags ) ;
2011-06-04 00:46:02 +00:00
std : : map < uint32_t , std : : pair < std : : string , uint32_t > > : : iterator Tag ;
2014-10-21 22:33:02 +00:00
for ( std : : list < uint32_t > : : iterator tagId = tagInfo . tagIds . begin ( ) ; tagId ! = tagInfo . tagIds . end ( ) ; + + tagId ) {
2011-06-04 00:46:02 +00: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 ( ) ;
} else {
ui . tagsLabel - > setVisible ( false ) ;
}
}
2014-05-08 08:39:04 +00:00
void MessageWidget : : refill ( )
{
//uint32_t msg_id = currMsgId ;
//currMsgId = 0 ;
//fill(msg_id) ;
}
2011-06-04 00:46:02 +00:00
void MessageWidget : : fill ( const std : : string & msgId )
{
2014-05-08 08:39:04 +00:00
// if (currMsgId == msgId) {
// // message doesn't changed
// return;
// }
2011-06-04 00:46:02 +00:00
currMsgId = msgId ;
if ( currMsgId . empty ( ) ) {
/* blank it */
ui . dateText - > setText ( " " ) ;
ui . toText - > setText ( " " ) ;
ui . fromText - > setText ( " " ) ;
ui . filesText - > setText ( " " ) ;
2017-06-21 06:35:29 +02:00
ui . ccLabel - > setVisible ( false ) ;
2011-06-04 00:46:02 +00:00
ui . ccText - > setVisible ( false ) ;
ui . ccText - > clear ( ) ;
2017-06-21 06:35:29 +02:00
ui . bccLabel - > setVisible ( false ) ;
2011-06-04 00:46:02 +00:00
ui . bccText - > setVisible ( false ) ;
ui . bccText - > clear ( ) ;
ui . subjectText - > setText ( " " ) ;
ui . msgList - > clear ( ) ;
ui . msgText - > clear ( ) ;
2013-09-23 19:53:26 +00:00
ui . msgText - > resetImagesStatus ( false ) ;
2011-06-04 00:46:02 +00:00
clearTagLabels ( ) ;
2012-08-16 10:20:34 +00:00
currMsgFlags = 0 ;
2011-06-04 00:46:02 +00:00
return ;
}
clearTagLabels ( ) ;
MessageInfo msgInfo ;
2015-03-22 04:52:53 +00:00
if ( rsMail - > getMessage ( currMsgId , msgInfo ) = = false ) {
2011-06-04 00:46:02 +00:00
std : : cerr < < " MessageWidget::fill() Couldn't find Msg " < < std : : endl ;
return ;
}
2017-02-07 17:01:36 +01:00
if ( msgInfo . msgflags & RS_MSG_USER_REQUEST ) {
ui . inviteFrame - > show ( ) ;
} else {
ui . inviteFrame - > hide ( ) ;
}
2011-06-04 00:46:02 +00:00
const std : : list < FileInfo > & recList = msgInfo . files ;
std : : list < FileInfo > : : const_iterator it ;
ui . msgList - > clear ( ) ;
QList < QTreeWidgetItem * > items ;
2014-10-21 22:33:02 +00:00
for ( it = recList . begin ( ) ; it ! = recList . end ( ) ; + + it ) {
2011-06-04 00:46:02 +00:00
QTreeWidgetItem * item = new QTreeWidgetItem ;
2011-10-11 23:29:38 +00:00
item - > setText ( COLUMN_FILE_NAME , QString : : fromUtf8 ( it - > fname . c_str ( ) ) ) ;
2015-01-22 22:54:41 +00:00
item - > setText ( COLUMN_FILE_SIZE , misc : : friendlyUnit ( it - > size ) ) ;
item - > setText ( COLUMN_FILE_HASH , QString : : fromStdString ( it - > hash . toStdString ( ) ) ) ;
item - > setTextAlignment ( COLUMN_FILE_SIZE , Qt : : AlignRight ) ;
2011-06-04 00:46:02 +00:00
/* add to the list */
items . append ( item ) ;
}
/* add the items in! */
ui . msgList - > insertTopLevelItems ( 0 , items ) ;
/* iterate through the sources */
RetroShareLink link ;
QString text ;
2017-07-16 13:11:47 +02:00
for ( std : : set < RsPeerId > : : const_iterator pit = msgInfo . rspeerid_msgto . begin ( ) ; pit ! = msgInfo . rspeerid_msgto . end ( ) ; + + pit ) {
link = RetroShareLink : : createMessage ( * pit , " " ) ;
if ( link . valid ( ) )
text + = link . toHtml ( ) + " " ;
}
for ( std : : set < RsGxsId > : : const_iterator pit = msgInfo . rsgxsid_msgto . begin ( ) ; pit ! = msgInfo . rsgxsid_msgto . end ( ) ; + + pit ) {
link = RetroShareLink : : createMessage ( * pit , " " ) ;
if ( link . valid ( ) )
text + = link . toHtml ( ) + " " ;
}
2014-03-29 14:18:05 +00:00
2011-06-04 00:46:02 +00:00
ui . toText - > setText ( text ) ;
2014-03-29 14:18:05 +00:00
if ( ! msgInfo . rspeerid_msgcc . empty ( ) | | ! msgInfo . rsgxsid_msgcc . empty ( ) )
{
2017-06-21 06:35:29 +02:00
ui . ccLabel - > setVisible ( true ) ;
2011-06-04 00:46:02 +00:00
ui . ccText - > setVisible ( true ) ;
text . clear ( ) ;
2017-07-16 13:11:47 +02:00
for ( std : : set < RsPeerId > : : const_iterator pit = msgInfo . rspeerid_msgcc . begin ( ) ; pit ! = msgInfo . rspeerid_msgcc . end ( ) ; + + pit ) {
link = RetroShareLink : : createMessage ( * pit , " " ) ;
if ( link . valid ( ) )
text + = link . toHtml ( ) + " " ;
}
for ( std : : set < RsGxsId > : : const_iterator pit = msgInfo . rsgxsid_msgcc . begin ( ) ; pit ! = msgInfo . rsgxsid_msgcc . end ( ) ; + + pit ) {
link = RetroShareLink : : createMessage ( * pit , " " ) ;
if ( link . valid ( ) )
text + = link . toHtml ( ) + " " ;
}
2014-03-29 14:18:05 +00:00
2011-06-04 00:46:02 +00:00
ui . ccText - > setText ( text ) ;
} else {
2017-06-21 06:35:29 +02:00
ui . ccLabel - > setVisible ( false ) ;
2011-06-04 00:46:02 +00:00
ui . ccText - > setVisible ( false ) ;
ui . ccText - > clear ( ) ;
}
2017-07-16 13:11:47 +02:00
if ( ! msgInfo . rspeerid_msgbcc . empty ( ) | | ! msgInfo . rsgxsid_msgbcc . empty ( ) )
{
ui . bccLabel - > setVisible ( true ) ;
ui . bccText - > setVisible ( true ) ;
2014-03-29 14:18:05 +00:00
2017-07-16 13:11:47 +02:00
text . clear ( ) ;
for ( std : : set < RsPeerId > : : const_iterator pit = msgInfo . rspeerid_msgbcc . begin ( ) ; pit ! = msgInfo . rspeerid_msgbcc . end ( ) ; + + pit ) {
link = RetroShareLink : : createMessage ( * pit , " " ) ;
if ( link . valid ( ) )
text + = link . toHtml ( ) + " " ;
}
for ( std : : set < RsGxsId > : : const_iterator pit = msgInfo . rsgxsid_msgbcc . begin ( ) ; pit ! = msgInfo . rsgxsid_msgbcc . end ( ) ; + + pit ) {
link = RetroShareLink : : createMessage ( * pit , " " ) ;
if ( link . valid ( ) )
text + = link . toHtml ( ) + " " ;
}
2011-06-04 00:46:02 +00:00
ui . bccText - > setText ( text ) ;
} else {
2017-06-21 06:35:29 +02:00
ui . bccLabel - > setVisible ( false ) ;
2011-06-04 00:46:02 +00:00
ui . bccText - > setVisible ( false ) ;
ui . bccText - > clear ( ) ;
}
2012-11-15 21:35:37 +00:00
ui . dateText - > setText ( DateTime : : formatDateTime ( msgInfo . ts ) ) ;
2011-06-04 00:46:02 +00:00
2014-03-17 20:56:06 +00:00
RsPeerId ownId = rsPeers - > getOwnId ( ) ;
2017-08-12 13:40:28 +02:00
QString tooltip_string ;
2012-05-01 09:18:55 +00:00
2015-02-20 10:34:11 +00:00
// if ((msgInfo.msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX) // outgoing message are from me
// {
// tooltip_string = PeerDefs::rsidFromId(ownId) ;
// link.createMessage(ownId, "");
// }
2017-08-12 13:40:28 +02:00
if ( msgInfo . msgflags & RS_MSG_DISTANT ) // distant message
{
tooltip_string = PeerDefs : : rsidFromId ( msgInfo . rsgxsid_srcId ) ;
link = RetroShareLink : : createMessage ( msgInfo . rsgxsid_srcId , " " ) ;
}
else
{
tooltip_string = PeerDefs : : rsidFromId ( msgInfo . rspeerid_srcId ) ;
link = RetroShareLink : : createMessage ( msgInfo . rspeerid_srcId , " " ) ;
}
if ( ( msgInfo . msgflags & RS_MSG_SYSTEM ) & & msgInfo . rspeerid_srcId = = ownId ) {
2012-05-01 09:18:55 +00:00
ui . fromText - > setText ( " RetroShare " ) ;
2017-11-18 18:49:42 +01:00
if ( toolButtonReply ) toolButtonReply - > setEnabled ( false ) ;
2012-05-01 09:18:55 +00:00
} else {
ui . fromText - > setText ( link . toHtml ( ) ) ;
2014-05-08 08:39:04 +00:00
ui . fromText - > setToolTip ( tooltip_string ) ;
2017-11-18 18:49:42 +01:00
if ( toolButtonReply ) toolButtonReply - > setEnabled ( true ) ;
2012-05-01 09:18:55 +00:00
}
2011-06-04 00:46:02 +00:00
2017-08-12 13:40:28 +02:00
ui . subjectText - > setText ( QString : : fromUtf8 ( msgInfo . title . c_str ( ) ) ) ;
2011-06-04 00:46:02 +00:00
2017-08-12 13:40:28 +02:00
// emoticons disabled because of crazy cost.
2017-01-20 23:00:05 +01:00
//text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromUtf8(msgInfo.msg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
text = RsHtmlMsg ( msgInfo . msgflags ) . formatText ( ui . msgText - > document ( ) , QString : : fromUtf8 ( msgInfo . msg . c_str ( ) ) , RSHTML_FORMATTEXT_EMBED_LINKS ) ;
2013-09-24 20:19:21 +00:00
ui . msgText - > resetImagesStatus ( Settings - > getMsgLoadEmbeddedImages ( ) | | ( msgInfo . msgflags & RS_MSG_LOAD_EMBEDDED_IMAGES ) ) ;
2011-06-04 00:46:02 +00:00
ui . msgText - > setHtml ( text ) ;
2015-01-08 01:02:21 +00:00
ui . filesText - > setText ( QString ( " %1 " ) . arg ( msgInfo . count ) ) ;
ui . filesSize - > setText ( QString ( misc : : friendlyUnit ( msgInfo . size ) ) ) ;
2011-06-04 00:46:02 +00:00
showTagLabels ( ) ;
2012-08-16 10:20:34 +00:00
currMsgFlags = msgInfo . msgflags ;
2011-06-04 00:46:02 +00:00
}
void MessageWidget : : remove ( )
{
MessageInfo msgInfo ;
2015-03-22 04:52:53 +00:00
if ( rsMail - > getMessage ( currMsgId , msgInfo ) = = false ) {
2011-06-04 00:46:02 +00:00
std : : cerr < < " MessageWidget::fill() Couldn't find Msg " < < std : : endl ;
return ;
}
bool deleteReal = false ;
if ( msgInfo . msgflags & RS_MSG_TRASH ) {
deleteReal = true ;
} else {
if ( QApplication : : keyboardModifiers ( ) & Qt : : ShiftModifier ) {
deleteReal = true ;
}
}
if ( deleteReal ) {
2015-03-22 04:52:53 +00:00
rsMail - > MessageDelete ( currMsgId ) ;
2011-06-04 00:46:02 +00:00
} else {
2015-03-22 04:52:53 +00:00
rsMail - > MessageToTrash ( currMsgId , true ) ;
2011-06-04 00:46:02 +00:00
}
if ( isWindow ) {
window ( ) - > close ( ) ;
} else {
deleteLater ( ) ;
}
}
void MessageWidget : : print ( )
{
# ifndef QT_NO_PRINTER
QPrinter printer ( QPrinter : : HighResolution ) ;
printer . setFullPage ( true ) ;
QPrintDialog * dlg = new QPrintDialog ( & printer , this ) ;
if ( ui . msgText - > textCursor ( ) . hasSelection ( ) )
dlg - > addEnabledOption ( QAbstractPrintDialog : : PrintSelection ) ;
dlg - > setWindowTitle ( tr ( " Print Document " ) ) ;
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
ui . msgText - > print ( & printer ) ;
}
delete dlg ;
# endif
}
void MessageWidget : : printPreview ( )
{
PrintPreview * preview = new PrintPreview ( ui . msgText - > document ( ) , this ) ;
preview - > setWindowModality ( Qt : : WindowModal ) ;
preview - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
preview - > show ( ) ;
/* window will destroy itself! */
}
void MessageWidget : : saveAs ( )
{
QString filename ;
if ( misc : : getSaveFileName ( window ( ) , RshareSettings : : LASTDIR_MESSAGES , tr ( " Save as... " ) , tr ( " HTML-Files (*.htm *.html);;All Files (*) " ) , filename ) ) {
QFile file ( filename ) ;
if ( ! file . open ( QFile : : WriteOnly ) )
return ;
QTextStream ts ( & file ) ;
ts . setCodec ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
ts < < ui . msgText - > document ( ) - > toHtml ( " UTF-8 " ) ;
ui . msgText - > document ( ) - > setModified ( false ) ;
}
}
void MessageWidget : : reply ( )
{
/* put msg on msgBoard, and switch to it. */
if ( currMsgId . empty ( ) ) {
return ;
}
MessageComposer * msgComposer = MessageComposer : : replyMsg ( currMsgId , false ) ;
if ( msgComposer = = NULL ) {
return ;
}
msgComposer - > show ( ) ;
msgComposer - > activateWindow ( ) ;
/* window will destroy itself! */
}
void MessageWidget : : replyAll ( )
{
/* put msg on msgBoard, and switch to it. */
if ( currMsgId . empty ( ) ) {
return ;
}
MessageComposer * msgComposer = MessageComposer : : replyMsg ( currMsgId , true ) ;
if ( msgComposer = = NULL ) {
return ;
}
msgComposer - > show ( ) ;
msgComposer - > activateWindow ( ) ;
/* window will destroy itself! */
}
void MessageWidget : : forward ( )
{
/* put msg on msgBoard, and switch to it. */
if ( currMsgId . empty ( ) ) {
return ;
}
MessageComposer * msgComposer = MessageComposer : : forwardMsg ( currMsgId ) ;
if ( msgComposer = = NULL ) {
return ;
}
msgComposer - > show ( ) ;
msgComposer - > activateWindow ( ) ;
/* window will destroy itself! */
}
2012-08-16 10:20:34 +00:00
void MessageWidget : : anchorClicked ( const QUrl & url )
{
RetroShareLink link ( url ) ;
if ( link . valid ( ) = = false ) {
return ;
}
2015-06-02 08:00:30 +00:00
if ( link . type ( ) = = RetroShareLink : : TYPE_CERTIFICATE & & currMsgFlags & RS_MSG_USER_REQUEST ) {
std : : cerr < < " (WW) Calling some disabled code in MessageWidget::anchorClicked(). Please contact the developpers. " < < std : : endl ;
// link.setSubType(RSLINK_SUBTYPE_CERTIFICATE_USER_REQUEST);
}
2012-08-16 10:20:34 +00:00
QList < RetroShareLink > links ;
links . append ( link ) ;
RetroShareLink : : process ( links ) ;
}
2013-09-24 20:19:21 +00:00
void MessageWidget : : loadImagesAlways ( )
{
if ( currMsgId . empty ( ) ) {
return ;
}
2015-03-22 04:52:53 +00:00
rsMail - > MessageLoadEmbeddedImages ( currMsgId , true ) ;
2013-09-24 20:19:21 +00:00
}
2017-02-07 17:01:36 +01:00
void MessageWidget : : sendInvite ( )
{
MessageInfo mi ;
if ( ! rsMail )
return ;
if ( ! rsMail - > getMessage ( currMsgId , mi ) )
return ;
if ( ( QMessageBox : : question ( this , tr ( " Send invite? " ) , tr ( " Do you really want send a invite with your Certificate? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes )
{
MessageComposer : : sendInvite ( mi . rsgxsid_srcId ) ;
}
}