2009-01-30 14:52:47 -05:00
/****************************************************************
2010-08-06 08:30:06 -04:00
*
2009-01-30 14:52:47 -05:00
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-23 14:52:58 -04:00
# include <QMessageBox>
# include <QTimer>
# include <QScrollBar>
# include <QCloseEvent>
# include <QColorDialog>
# include <QDateTime>
# include <QFontDialog>
# include <QBuffer>
# include <QTextCodec>
2010-09-01 13:56:15 -04:00
# include <QSound>
2009-05-11 10:35:50 -04:00
# include <sys/stat.h>
2009-01-30 14:52:47 -05:00
# include "PopupChatDialog.h"
2011-12-04 09:31:48 -05:00
# include "ChatLobbyDialog.h"
2010-11-15 15:49:24 -05:00
# include "PopupChatWindow.h"
2010-10-02 18:42:30 -04:00
# include "gui/RetroShareLink.h"
2010-12-02 19:54:40 -05:00
# include "util/misc.h"
2010-05-03 17:17:36 -04:00
# include "rshare.h"
2009-01-30 14:52:47 -05:00
2010-08-06 05:40:23 -04:00
# include <retroshare/rspeers.h>
# include <retroshare/rsnotify.h>
2010-08-18 08:02:36 -04:00
# include <retroshare/rsstatus.h>
2011-09-29 05:20:09 -04:00
# include <retroshare/rshistory.h>
2010-05-11 16:02:52 -04:00
# include "gui/settings/rsharesettings.h"
2010-09-10 14:38:46 -04:00
# include "gui/settings/RsharePeerSettings.h"
2010-08-20 14:45:44 -04:00
# include "gui/notifyqt.h"
2010-09-01 21:37:47 -04:00
# include "../RsAutoUpdatePage.h"
2010-09-12 10:10:28 -04:00
# include "gui/common/StatusDefs.h"
2011-09-02 06:22:44 -04:00
# include "gui/common/AvatarDefs.h"
2010-09-14 13:47:11 -04:00
# include "gui/common/Emoticons.h"
2011-12-07 08:08:12 -05:00
# include "gui/common/PeerDefs.h"
# include "gui/common/FilesDefs.h"
2010-10-02 18:42:30 -04:00
# include "gui/im_history/ImHistoryBrowser.h"
2010-06-17 13:39:32 -04:00
# include "gui/msgs/MessageComposer.h"
2010-09-28 16:33:34 -04:00
2010-01-20 17:02:43 -05:00
# include <time.h>
2011-09-29 05:20:09 -04:00
# include <algorithm>
2009-01-30 14:52:47 -05:00
# define appDir QApplication::applicationDirPath()
2010-11-15 15:49:24 -05:00
# define WINDOW(This) dynamic_cast<PopupChatWindow*>(This->window())
2009-01-30 14:52:47 -05:00
/*****
* # define CHAT_DEBUG 1
* * * * */
2010-06-17 13:39:32 -04:00
static std : : map < std : : string , PopupChatDialog * > chatDialogs ;
2010-09-01 13:56:15 -04:00
// play sound when recv a message
void playsound ( )
{
Settings - > beginGroup ( " Sound " ) ;
Settings - > beginGroup ( " SoundFilePath " ) ;
QString OnlineSound = Settings - > value ( " NewChatMessage " , " " ) . toString ( ) ;
Settings - > endGroup ( ) ;
Settings - > beginGroup ( " Enable " ) ;
bool flag = Settings - > value ( " NewChatMessage " , false ) . toBool ( ) ;
Settings - > endGroup ( ) ;
Settings - > endGroup ( ) ;
if ( ! OnlineSound . isEmpty ( ) & & flag ) {
if ( QSound : : isAvailable ( ) ) {
QSound : : play ( OnlineSound ) ;
}
}
}
2009-01-30 14:52:47 -05:00
/** Default constructor */
2010-11-15 15:49:24 -05:00
PopupChatDialog : : PopupChatDialog ( const std : : string & id , const QString & name , QWidget * parent , Qt : : WFlags flags )
: QWidget ( parent , flags ) , dialogId ( id ) , dialogName ( name ) ,
2009-01-30 14:52:47 -05:00
lastChatTime ( 0 ) , lastChatName ( " " )
{
2011-09-29 05:20:09 -04:00
/* Invoke Qt Designer generated QObject setup routine */
ui . setupUi ( this ) ;
newMessages = false ;
typing = false ;
manualDelete = false ;
peerStatus = 0 ;
last_status_send_time = 0 ;
chatStyle . setStyleFromSettings ( ChatStyle : : TYPE_PRIVATE ) ;
/* Hide or show the frames */
showAvatarFrame ( PeerSettings - > getShowAvatarFrame ( dialogId ) ) ;
ui . infoframe - > setVisible ( false ) ;
ui . statusmessagelabel - > hide ( ) ;
connect ( ui . avatarFrameButton , SIGNAL ( toggled ( bool ) ) , this , SLOT ( showAvatarFrame ( bool ) ) ) ;
connect ( ui . sendButton , SIGNAL ( clicked ( ) ) , this , SLOT ( sendChat ( ) ) ) ;
connect ( ui . addFileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
connect ( ui . textboldButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textunderlineButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textitalicButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . attachPictureButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraPicture ( ) ) ) ;
connect ( ui . fontButton , SIGNAL ( clicked ( ) ) , this , SLOT ( getFont ( ) ) ) ;
connect ( ui . colorButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setColor ( ) ) ) ;
connect ( ui . emoteiconButton , SIGNAL ( clicked ( ) ) , this , SLOT ( smileyWidget ( ) ) ) ;
connect ( ui . actionSave_Chat_History , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
connect ( ui . actionClearOfflineMessages , SIGNAL ( triggered ( ) ) , this , SLOT ( clearOfflineMessages ( ) ) ) ;
2011-12-07 08:08:12 -05:00
connect ( ui . hashBox , SIGNAL ( fileHashingFinished ( QList < HashedFile > ) ) , this , SLOT ( fileHashingFinished ( QList < HashedFile > ) ) ) ;
2011-12-04 09:31:48 -05:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerStatusChanged ( const QString & , int ) ) , this , SLOT ( updateStatus_slot ( const QString & , int ) ) ) ;
2011-09-29 05:20:09 -04:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerHasNewCustomStateString ( const QString & , const QString & ) ) , this , SLOT ( updatePeersCustomStateString ( const QString & , const QString & ) ) ) ;
connect ( ui . chattextEdit , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
ui . avatarWidget - > setFrameType ( AvatarWidget : : STATUS_FRAME ) ;
ui . avatarWidget - > setId ( dialogId , false ) ;
ui . ownAvatarWidget - > setFrameType ( AvatarWidget : : STATUS_FRAME ) ;
ui . ownAvatarWidget - > setOwnId ( ) ;
// Create the status bar
resetStatusBar ( ) ;
ui . textboldButton - > setIcon ( QIcon ( QString ( " :/images/edit-bold.png " ) ) ) ;
ui . textunderlineButton - > setIcon ( QIcon ( QString ( " :/images/edit-underline.png " ) ) ) ;
ui . textitalicButton - > setIcon ( QIcon ( QString ( " :/images/edit-italic.png " ) ) ) ;
ui . fontButton - > setIcon ( QIcon ( QString ( " :/images/fonts.png " ) ) ) ;
ui . emoteiconButton - > setIcon ( QIcon ( QString ( " :/images/emoticons/kopete/kopete020.png " ) ) ) ;
ui . textboldButton - > setCheckable ( true ) ;
ui . textunderlineButton - > setCheckable ( true ) ;
ui . textitalicButton - > setCheckable ( true ) ;
setAcceptDrops ( true ) ;
ui . chattextEdit - > setAcceptDrops ( false ) ;
2011-12-07 08:08:12 -05:00
ui . hashBox - > setDropWidget ( this ) ;
ui . hashBox - > setAutoHide ( true ) ;
2011-09-29 05:20:09 -04:00
QMenu * toolmenu = new QMenu ( ) ;
toolmenu - > addAction ( ui . actionClear_Chat_History ) ;
toolmenu - > addAction ( ui . actionDelete_Chat_History ) ;
toolmenu - > addAction ( ui . actionSave_Chat_History ) ;
toolmenu - > addAction ( ui . actionClearOfflineMessages ) ;
toolmenu - > addAction ( ui . actionMessageHistory ) ;
//toolmenu->addAction(ui.action_Disable_Emoticons);
ui . pushtoolsButton - > setMenu ( toolmenu ) ;
mCurrentColor . setNamedColor ( PeerSettings - > getPrivateChatColor ( dialogId ) ) ;
mCurrentFont . fromString ( PeerSettings - > getPrivateChatFont ( dialogId ) ) ;
colorChanged ( mCurrentColor ) ;
fontChanged ( mCurrentFont ) ;
// load settings
processSettings ( true ) ;
// load style
PeerSettings - > getStyle ( dialogId , " PopupChatDialog " , style ) ;
// initialize first status
StatusInfo peerStatusInfo ;
// No check of return value. Non existing status info is handled as offline.
rsStatus - > getStatus ( dialogId , peerStatusInfo ) ;
updateStatus ( QString : : fromStdString ( dialogId ) , peerStatusInfo . status ) ;
// initialize first custom state string
QString customStateString = QString : : fromUtf8 ( rsMsgs - > getCustomStateString ( dialogId ) . c_str ( ) ) ;
updatePeersCustomStateString ( QString : : fromStdString ( dialogId ) , customStateString ) ;
if ( rsHistory - > getEnable ( false ) ) {
// get chat messages from history
std : : list < HistoryMsg > historyMsgs ;
int messageCount = Settings - > getPrivateChatHistoryCount ( ) ;
if ( messageCount > 0 ) {
rsHistory - > getMessages ( dialogId , historyMsgs , messageCount ) ;
std : : list < HistoryMsg > : : iterator historyIt ;
for ( historyIt = historyMsgs . begin ( ) ; historyIt ! = historyMsgs . end ( ) ; historyIt + + ) {
addChatMsg ( historyIt - > incoming , QString : : fromUtf8 ( historyIt - > peerName . c_str ( ) ) , QDateTime : : fromTime_t ( historyIt - > sendTime ) , QDateTime : : fromTime_t ( historyIt - > recvTime ) , QString : : fromUtf8 ( historyIt - > message . c_str ( ) ) , TYPE_HISTORY ) ;
}
}
}
ui . chattextEdit - > installEventFilter ( this ) ;
// add offline chat messages
2011-09-29 05:52:01 -04:00
onPrivateChatChanged ( NOTIFY_LIST_PRIVATE_OUTGOING_CHAT , NOTIFY_TYPE_ADD ) ;
2010-11-17 07:45:46 -05:00
# ifdef RS_RELEASE_VERSION
2011-09-29 05:20:09 -04:00
ui . attachPictureButton - > setVisible ( false ) ;
2010-11-17 07:45:46 -05:00
# endif
2010-08-06 10:58:53 -04:00
}
/** Destructor. */
PopupChatDialog : : ~ PopupChatDialog ( )
{
// save settings
processSettings ( false ) ;
2010-11-15 15:49:24 -05:00
PopupChatWindow * window = WINDOW ( this ) ;
if ( window ) {
window - > removeDialog ( this ) ;
window - > calculateTitle ( NULL ) ;
}
std : : map < std : : string , PopupChatDialog * > : : iterator it ;
if ( chatDialogs . end ( ) ! = ( it = chatDialogs . find ( dialogId ) ) ) {
chatDialogs . erase ( it ) ;
}
2010-08-06 10:58:53 -04:00
}
void PopupChatDialog : : processSettings ( bool bLoad )
{
Settings - > beginGroup ( QString ( " ChatDialog " ) ) ;
if ( bLoad ) {
// load settings
// state of splitter
ui . chatsplitter - > restoreState ( Settings - > value ( " ChatSplitter " ) . toByteArray ( ) ) ;
} else {
// save settings
// state of splitter
Settings - > setValue ( " ChatSplitter " , ui . chatsplitter - > saveState ( ) ) ;
}
Settings - > endGroup ( ) ;
2009-01-30 14:52:47 -05:00
}
2010-11-15 15:49:24 -05:00
/*static*/ PopupChatDialog * PopupChatDialog : : getExistingInstance ( const std : : string & id )
2010-06-17 13:39:32 -04:00
{
2010-09-01 13:56:15 -04:00
std : : map < std : : string , PopupChatDialog * > : : iterator it ;
2010-11-13 16:53:06 -05:00
if ( chatDialogs . end ( ) ! = ( it = chatDialogs . find ( id ) ) ) {
2010-06-17 13:39:32 -04:00
/* exists already */
2010-11-13 16:53:06 -05:00
return it - > second ;
2010-09-01 13:56:15 -04:00
}
2010-06-17 13:39:32 -04:00
2010-11-13 16:53:06 -05:00
return NULL ;
}
2010-11-15 15:49:24 -05:00
/*static*/ PopupChatDialog * PopupChatDialog : : getPrivateChat ( const std : : string & id , uint chatflags )
2010-11-13 16:53:06 -05:00
{
/* see if it exists already */
PopupChatDialog * popupchatdialog = getExistingInstance ( id ) ;
2011-12-04 09:31:48 -05:00
2010-11-15 15:49:24 -05:00
if ( popupchatdialog = = NULL ) {
2010-11-13 16:53:06 -05:00
if ( chatflags & RS_CHAT_OPEN ) {
2010-09-01 13:56:15 -04:00
RsPeerDetails sslDetails ;
2011-12-04 09:31:48 -05:00
ChatLobbyId lobby_id ;
if ( rsPeers - > getPeerDetails ( id , sslDetails ) )
{
2010-09-28 16:33:34 -04:00
popupchatdialog = new PopupChatDialog ( id , PeerDefs : : nameWithLocation ( sslDetails ) ) ;
2010-09-01 13:56:15 -04:00
chatDialogs [ id ] = popupchatdialog ;
2010-11-15 15:49:24 -05:00
PopupChatWindow * window = PopupChatWindow : : getWindow ( false ) ;
window - > addDialog ( popupchatdialog ) ;
2010-09-01 13:56:15 -04:00
}
2011-12-04 09:31:48 -05:00
else if ( rsMsgs - > isLobbyId ( id , lobby_id ) )
{
2011-12-26 17:43:54 -05:00
std : : list < ChatLobbyInfo > linfos ;
rsMsgs - > getChatLobbyList ( linfos ) ;
for ( std : : list < ChatLobbyInfo > : : const_iterator it ( linfos . begin ( ) ) ; it ! = linfos . end ( ) ; + + it )
if ( ( * it ) . lobby_id = = lobby_id )
{
2012-01-01 19:25:43 -05:00
popupchatdialog = new ChatLobbyDialog ( id , lobby_id , QString : : fromUtf8 ( ( * it ) . lobby_name . c_str ( ) ) ) ;
2011-12-26 17:43:54 -05:00
chatDialogs [ id ] = popupchatdialog ;
PopupChatWindow * window = PopupChatWindow : : getWindow ( false ) ;
window - > addDialog ( popupchatdialog ) ;
}
}
2010-06-17 13:39:32 -04:00
}
2010-09-01 13:56:15 -04:00
}
2010-06-17 13:39:32 -04:00
2010-11-13 16:53:06 -05:00
if ( popupchatdialog = = NULL ) {
return NULL ;
2010-09-01 13:56:15 -04:00
}
2010-11-15 15:49:24 -05:00
popupchatdialog - > insertChatMsgs ( ) ;
PopupChatWindow * window = WINDOW ( popupchatdialog ) ;
if ( window ) {
window - > showDialog ( popupchatdialog , chatflags ) ;
2010-09-01 13:56:15 -04:00
}
2010-06-17 13:39:32 -04:00
2010-09-01 13:56:15 -04:00
return popupchatdialog ;
2010-06-17 13:39:32 -04:00
}
/*static*/ void PopupChatDialog : : cleanupChat ( )
{
2010-11-15 15:49:24 -05:00
PopupChatWindow : : cleanup ( ) ;
/* PopupChatDialog destuctor removes the entry from the map */
std : : list < PopupChatDialog * > list ;
std : : map < std : : string , PopupChatDialog * > : : iterator it ;
2010-06-17 13:39:32 -04:00
for ( it = chatDialogs . begin ( ) ; it ! = chatDialogs . end ( ) ; it + + ) {
if ( it - > second ) {
2010-11-15 15:49:24 -05:00
list . push_back ( it - > second ) ;
2010-06-17 13:39:32 -04:00
}
}
chatDialogs . clear ( ) ;
2010-11-15 15:49:24 -05:00
std : : list < PopupChatDialog * > : : iterator it1 ;
for ( it1 = list . begin ( ) ; it1 ! = list . end ( ) ; it1 + + ) {
delete ( * it1 ) ;
}
2010-06-17 13:39:32 -04:00
}
2010-09-20 20:08:06 -04:00
/*static*/ void PopupChatDialog : : privateChatChanged ( int list , int type )
2010-09-01 13:56:15 -04:00
{
2010-09-20 20:08:06 -04:00
if ( list = = NOTIFY_LIST_PRIVATE_INCOMING_CHAT & & type = = NOTIFY_TYPE_ADD ) {
std : : list < std : : string > ids ;
if ( rsMsgs - > getPrivateChatQueueIds ( true , ids ) ) {
uint chatflags = Settings - > getChatFlags ( ) ;
2010-09-01 13:56:15 -04:00
2010-09-20 20:08:06 -04:00
std : : list < std : : string > : : iterator id ;
for ( id = ids . begin ( ) ; id ! = ids . end ( ) ; id + + ) {
PopupChatDialog * pcd = getPrivateChat ( * id , chatflags ) ;
2010-09-01 13:56:15 -04:00
2010-09-20 20:08:06 -04:00
if ( pcd ) {
pcd - > insertChatMsgs ( ) ;
}
}
}
}
2010-09-01 13:56:15 -04:00
2010-09-20 20:08:06 -04:00
/* now notify all open priavate chat windows */
std : : map < std : : string , PopupChatDialog * > : : iterator it ;
for ( it = chatDialogs . begin ( ) ; it ! = chatDialogs . end ( ) ; it + + ) {
if ( it - > second ) {
it - > second - > onPrivateChatChanged ( list , type ) ;
2010-09-01 13:56:15 -04:00
}
}
}
2011-12-27 08:47:37 -05:00
void PopupChatDialog : : closeChat ( const std : : string & id )
{
PopupChatDialog * popupchatdialog = getExistingInstance ( id ) ;
if ( popupchatdialog ! = NULL )
popupchatdialog - > hide ( ) ;
}
2010-11-15 15:49:24 -05:00
void PopupChatDialog : : chatFriend ( const std : : string & id )
2010-06-17 13:39:32 -04:00
{
if ( id . empty ( ) ) {
return ;
}
2010-08-06 08:30:06 -04:00
std : : cerr < < " popup dialog chat friend 1 " < < std : : endl ;
2010-06-17 13:39:32 -04:00
2011-12-06 19:12:17 -05:00
ChatLobbyId lid ;
if ( rsMsgs - > isLobbyId ( id , lid ) )
{
getPrivateChat ( id , RS_CHAT_OPEN | RS_CHAT_FOCUS ) ;
return ;
}
2010-06-17 13:39:32 -04:00
RsPeerDetails detail ;
2011-12-06 19:12:17 -05:00
if ( ! rsPeers - > getPeerDetails ( id , detail ) )
2010-06-17 13:39:32 -04:00
return ;
2010-09-20 20:08:06 -04:00
std : : string firstId ;
2010-06-17 13:39:32 -04:00
if ( detail . isOnlyGPGdetail ) {
//let's get the ssl child details, and open all the chat boxes
std : : list < std : : string > sslIds ;
2011-08-07 17:14:09 -04:00
rsPeers - > getAssociatedSSLIds ( detail . gpg_id , sslIds ) ;
2010-06-17 13:39:32 -04:00
for ( std : : list < std : : string > : : iterator it = sslIds . begin ( ) ; it ! = sslIds . end ( ) ; it + + ) {
2010-09-20 20:08:06 -04:00
if ( firstId . empty ( ) ) {
firstId = * it ;
}
2010-06-17 13:39:32 -04:00
RsPeerDetails sslDetails ;
if ( rsPeers - > getPeerDetails ( * it , sslDetails ) ) {
if ( sslDetails . state & RS_PEER_STATE_CONNECTED ) {
2010-11-13 16:53:06 -05:00
getPrivateChat ( * it , RS_CHAT_OPEN | RS_CHAT_FOCUS ) ;
2010-09-20 20:08:06 -04:00
return ;
2010-06-17 13:39:32 -04:00
}
}
}
} else {
if ( detail . state & RS_PEER_STATE_CONNECTED ) {
2010-11-13 16:53:06 -05:00
getPrivateChat ( id , RS_CHAT_OPEN | RS_CHAT_FOCUS ) ;
2010-09-20 20:08:06 -04:00
return ;
2010-06-17 13:39:32 -04:00
}
2010-09-20 20:08:06 -04:00
firstId = id ;
2010-06-17 13:39:32 -04:00
}
2010-09-20 20:08:06 -04:00
/* info dialog */
2010-10-02 18:42:30 -04:00
QMessageBox mb ( QMessageBox : : Question , tr ( " Friend not Online " ) , tr ( " Your Friend is offline \n Do you want to send them a Message instead " ) , QMessageBox : : Yes | QMessageBox : : No ) ;
mb . setWindowIcon ( QIcon ( " :/images/rstray3.png " ) ) ;
if ( mb . exec ( ) = = QMessageBox : : Yes ) {
2010-09-27 17:05:52 -04:00
MessageComposer : : msgFriend ( id , false ) ;
2010-09-20 20:08:06 -04:00
} else {
if ( firstId . empty ( ) = = false ) {
2010-11-13 16:53:06 -05:00
getPrivateChat ( firstId , RS_CHAT_OPEN | RS_CHAT_FOCUS ) ;
2010-06-17 13:39:32 -04:00
}
}
}
2010-11-15 15:49:24 -05:00
void PopupChatDialog : : focusDialog ( )
{
ui . chattextEdit - > setFocus ( ) ;
}
2010-03-17 11:34:36 -04:00
void PopupChatDialog : : pasteLink ( )
{
std : : cerr < < " In paste link " < < std : : endl ;
ui . chattextEdit - > insertHtml ( RSLinkClipboard : : toHtml ( ) ) ;
}
2011-08-12 10:06:29 -04:00
void PopupChatDialog : : contextMenu ( QPoint /*point*/ )
2010-03-17 11:34:36 -04:00
{
2010-11-21 16:12:35 -05:00
std : : cerr < < " In context menu " < < std : : endl ;
QMenu * contextMnu = ui . chattextEdit - > createStandardContextMenu ( ) ;
2010-03-17 11:34:36 -04:00
2010-11-21 16:12:35 -05:00
contextMnu - > addSeparator ( ) ;
QAction * action = contextMnu - > addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste RetroShare Link " ) , this , SLOT ( pasteLink ( ) ) ) ;
action - > setDisabled ( RSLinkClipboard : : empty ( ) ) ;
2010-03-17 11:34:36 -04:00
2010-11-21 16:12:35 -05:00
contextMnu - > exec ( QCursor : : pos ( ) ) ;
delete ( contextMnu ) ;
2010-03-17 11:34:36 -04:00
}
2009-05-05 09:18:53 -04:00
void PopupChatDialog : : resetStatusBar ( )
{
2010-11-15 15:49:24 -05:00
ui . statusLabel - > clear ( ) ;
ui . typingpixmapLabel - > clear ( ) ;
2010-09-07 13:35:08 -04:00
2010-11-15 15:49:24 -05:00
typing = false ;
PopupChatWindow * window = WINDOW ( this ) ;
if ( window ) {
window - > calculateTitle ( this ) ;
}
2009-05-05 09:18:53 -04:00
}
void PopupChatDialog : : updateStatusTyping ( )
{
2010-08-30 14:33:19 -04:00
if ( time ( NULL ) - last_status_send_time > 5 ) // limit 'peer is typing' packets to at most every 10 sec
{
# ifdef ONLY_FOR_LINGUIST
tr ( " is typing... " ) ;
# endif
rsMsgs - > sendStatusString ( dialogId , " is typing... " ) ;
last_status_send_time = time ( NULL ) ;
}
2009-05-05 09:18:53 -04:00
}
2012-01-06 17:17:08 -05:00
QString PopupChatDialog : : makeStatusString ( const QString & peer_id , const QString & status_string ) const
{
return QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id . toStdString ( ) ) . c_str ( ) ) + " " + tr ( status_string . toAscii ( ) ) ;
}
2009-05-05 09:18:53 -04:00
// Called by libretroshare through notifyQt to display the peer's status
//
2010-08-30 14:33:19 -04:00
void PopupChatDialog : : updateStatusString ( const QString & peer_id , const QString & status_string )
2009-05-05 09:18:53 -04:00
{
2012-01-06 17:17:08 -05:00
QString status = makeStatusString ( peer_id , status_string ) ;
2010-11-15 15:49:24 -05:00
ui . statusLabel - > setText ( status ) ; // displays info for 5 secs.
2010-09-06 16:54:48 -04:00
ui . typingpixmapLabel - > setPixmap ( QPixmap ( " :images/typing.png " ) ) ;
2009-05-05 09:18:53 -04:00
2010-09-07 13:35:08 -04:00
if ( status_string = = " is typing... " ) {
2010-11-15 15:49:24 -05:00
typing = true ;
PopupChatWindow * window = WINDOW ( this ) ;
if ( window ) {
window - > calculateTitle ( this ) ;
}
2010-09-07 13:35:08 -04:00
}
2010-08-30 14:33:19 -04:00
QTimer : : singleShot ( 5000 , this , SLOT ( resetStatusBar ( ) ) ) ;
2009-05-05 09:18:53 -04:00
}
2011-08-12 10:06:29 -04:00
void PopupChatDialog : : resizeEvent ( QResizeEvent */ * event */ )
2009-01-30 14:52:47 -05:00
{
2010-11-15 15:49:24 -05:00
// Workaround: now the scroll position is correct calculated
QScrollBar * scrollbar = ui . textBrowser - > verticalScrollBar ( ) ;
scrollbar - > setValue ( scrollbar - > maximum ( ) ) ;
2009-01-30 14:52:47 -05:00
}
2010-11-15 15:49:24 -05:00
void PopupChatDialog : : activate ( )
2010-09-01 13:56:15 -04:00
{
2010-11-15 15:49:24 -05:00
PopupChatWindow * window = WINDOW ( this ) ;
if ( window ) {
if ( window - > isActiveWindow ( ) ) {
newMessages = false ;
window - > calculateTitle ( this ) ;
2010-11-18 18:29:39 -05:00
focusDialog ( ) ;
2010-11-15 15:49:24 -05:00
}
} else {
newMessages = false ;
2010-11-13 16:53:06 -05:00
}
2010-09-01 13:56:15 -04:00
}
2011-09-29 05:52:01 -04:00
void PopupChatDialog : : onPrivateChatChanged ( int list , int type )
2010-09-20 20:08:06 -04:00
{
2010-10-02 18:42:30 -04:00
if ( list = = NOTIFY_LIST_PRIVATE_OUTGOING_CHAT ) {
switch ( type ) {
case NOTIFY_TYPE_ADD :
{
2011-09-29 05:20:09 -04:00
std : : list < ChatInfo > savedOfflineChatNew ;
2010-10-02 18:42:30 -04:00
2010-10-31 17:53:41 -04:00
QString name = QString : : fromUtf8 ( rsPeers - > getPeerName ( rsPeers - > getOwnId ( ) ) . c_str ( ) ) ;
2010-10-02 18:42:30 -04:00
std : : list < ChatInfo > offlineChat ;
if ( rsMsgs - > getPrivateChatQueueCount ( false ) & & rsMsgs - > getPrivateChatQueue ( false , dialogId , offlineChat ) ) {
ui . actionClearOfflineMessages - > setEnabled ( true ) ;
std : : list < ChatInfo > : : iterator it ;
for ( it = offlineChat . begin ( ) ; it ! = offlineChat . end ( ) ; it + + ) {
/* are they public? */
if ( ( it - > chatflags & RS_CHAT_PRIVATE ) = = 0 ) {
/* this should not happen */
continue ;
}
2011-09-29 05:20:09 -04:00
savedOfflineChatNew . push_back ( * it ) ;
if ( std : : find ( savedOfflineChat . begin ( ) , savedOfflineChat . end ( ) , * it ) ! = savedOfflineChat . end ( ) ) {
continue ;
}
2010-10-02 18:42:30 -04:00
QDateTime sendTime = QDateTime : : fromTime_t ( it - > sendTime ) ;
2010-10-03 06:08:58 -04:00
QDateTime recvTime = QDateTime : : fromTime_t ( it - > recvTime ) ;
2010-10-02 18:42:30 -04:00
QString message = QString : : fromStdWString ( it - > msg ) ;
2011-09-29 05:20:09 -04:00
addChatMsg ( false , name , sendTime , recvTime , message , TYPE_OFFLINE ) ;
2010-10-02 18:42:30 -04:00
}
}
2011-09-29 05:20:09 -04:00
savedOfflineChat = savedOfflineChatNew ;
2010-10-02 18:42:30 -04:00
}
break ;
case NOTIFY_TYPE_DEL :
{
2011-09-29 05:20:09 -04:00
if ( manualDelete = = false ) {
2010-10-31 17:53:41 -04:00
QString name = QString : : fromUtf8 ( rsPeers - > getPeerName ( rsPeers - > getOwnId ( ) ) . c_str ( ) ) ;
2010-10-02 18:42:30 -04:00
// now show saved offline chat messages as sent
std : : list < ChatInfo > : : iterator it ;
2011-09-29 05:20:09 -04:00
for ( it = savedOfflineChat . begin ( ) ; it ! = savedOfflineChat . end ( ) ; + + it ) {
2010-10-02 18:42:30 -04:00
QDateTime sendTime = QDateTime : : fromTime_t ( it - > sendTime ) ;
2010-10-03 06:08:58 -04:00
QDateTime recvTime = QDateTime : : fromTime_t ( it - > recvTime ) ;
2010-10-02 18:42:30 -04:00
QString message = QString : : fromStdWString ( it - > msg ) ;
2011-09-29 05:20:09 -04:00
addChatMsg ( false , name , sendTime , recvTime , message , TYPE_NORMAL ) ;
2010-10-02 18:42:30 -04:00
}
2010-09-20 20:08:06 -04:00
}
2011-09-29 05:20:09 -04:00
savedOfflineChat . clear ( ) ;
2010-09-20 20:08:06 -04:00
}
2010-10-02 18:42:30 -04:00
break ;
2010-09-20 20:08:06 -04:00
}
2010-10-02 18:42:30 -04:00
2011-09-29 05:20:09 -04:00
ui . actionClearOfflineMessages - > setEnabled ( ! savedOfflineChat . empty ( ) ) ;
2010-09-20 20:08:06 -04:00
}
}
2011-12-28 04:15:28 -05:00
void PopupChatDialog : : addIncomingChatMsg ( const ChatInfo & info )
{
QDateTime sendTime = QDateTime : : fromTime_t ( info . sendTime ) ;
QDateTime recvTime = QDateTime : : fromTime_t ( info . recvTime ) ;
QString message = QString : : fromStdWString ( info . msg ) ;
QString name = QString : : fromUtf8 ( rsPeers - > getPeerName ( info . rsid ) . c_str ( ) ) ;
addChatMsg ( true , name , sendTime , recvTime , message , TYPE_NORMAL ) ;
}
2010-09-01 13:56:15 -04:00
void PopupChatDialog : : insertChatMsgs ( )
2009-01-30 14:52:47 -05:00
{
2010-09-01 13:56:15 -04:00
std : : list < ChatInfo > newchat ;
2010-09-20 20:08:06 -04:00
if ( ! rsMsgs - > getPrivateChatQueue ( true , dialogId , newchat ) )
2010-09-01 13:56:15 -04:00
{
# ifdef PEERS_DEBUG
std : : cerr < < " no chat for " < < dialogId < < " available. " < < std : : endl ;
2009-01-30 14:52:47 -05:00
# endif
2010-09-01 13:56:15 -04:00
return ;
}
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
std : : list < ChatInfo > : : iterator it ;
2011-12-28 04:15:28 -05:00
for ( it = newchat . begin ( ) ; it ! = newchat . end ( ) ; it + + )
{
2010-09-01 13:56:15 -04:00
/* are they public? */
if ( ( it - > chatflags & RS_CHAT_PRIVATE ) = = 0 ) {
/* this should not happen */
continue ;
}
2011-12-28 04:15:28 -05:00
addIncomingChatMsg ( * it ) ;
2010-09-01 13:56:15 -04:00
}
2010-09-20 20:08:06 -04:00
rsMsgs - > clearPrivateChatQueue ( true , dialogId ) ;
2010-09-01 13:56:15 -04:00
playsound ( ) ;
2010-11-15 15:49:24 -05:00
PopupChatWindow * window = WINDOW ( this ) ;
if ( window ) {
window - > alertDialog ( this ) ;
}
if ( isVisible ( ) = = false | | ( window & & window - > isActiveWindow ( ) = = false ) ) {
newMessages = true ;
if ( window ) {
window - > calculateTitle ( this ) ;
}
}
2010-09-01 13:56:15 -04:00
}
2011-09-29 05:20:09 -04:00
void PopupChatDialog : : addChatMsg ( bool incoming , const QString & name , const QDateTime & sendTime , const QDateTime & recvTime , const QString & message , enumChatType chatType )
2010-09-01 13:56:15 -04:00
{
2009-05-11 10:21:11 -04:00
# ifdef CHAT_DEBUG
2010-09-01 13:56:15 -04:00
std : : cout < < " PopupChatDialog:addChatMsg message : " < < message . toStdString ( ) < < std : : endl ;
2009-05-11 10:21:11 -04:00
# endif
2010-09-04 10:23:30 -04:00
unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS ;
// embed smileys ?
if ( Settings - > valueFromGroup ( QString ( " Chat " ) , QString : : fromUtf8 ( " Emoteicons_PrivatChat " ) , true ) . toBool ( ) ) {
formatFlag | = CHAT_FORMATMSG_EMBED_SMILEYS ;
2010-09-01 13:56:15 -04:00
}
2010-10-02 18:42:30 -04:00
ChatStyle : : enumFormatMessage type ;
if ( chatType = = TYPE_OFFLINE ) {
type = ChatStyle : : FORMATMSG_OOUTGOING ;
} else if ( chatType = = TYPE_HISTORY ) {
type = incoming ? ChatStyle : : FORMATMSG_HINCOMING : ChatStyle : : FORMATMSG_HOUTGOING ;
} else {
type = incoming ? ChatStyle : : FORMATMSG_INCOMING : ChatStyle : : FORMATMSG_OUTGOING ;
}
2011-09-29 05:20:09 -04:00
QString formatMsg = chatStyle . formatMessage ( type , name , incoming ? sendTime : recvTime , message , formatFlag ) ;
2010-09-20 20:08:06 -04:00
2010-09-04 10:23:30 -04:00
ui . textBrowser - > append ( formatMsg ) ;
2010-09-01 13:56:15 -04:00
2010-11-13 16:53:06 -05:00
/* Scroll to the end */
QScrollBar * scrollbar = ui . textBrowser - > verticalScrollBar ( ) ;
scrollbar - > setValue ( scrollbar - > maximum ( ) ) ;
2010-11-15 15:49:24 -05:00
resetStatusBar ( ) ;
2009-01-30 14:52:47 -05:00
}
2010-09-04 10:23:30 -04:00
bool PopupChatDialog : : eventFilter ( QObject * obj , QEvent * event )
{
if ( obj = = ui . chattextEdit ) {
if ( event - > type ( ) = = QEvent : : KeyPress ) {
updateStatusTyping ( ) ;
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( event ) ;
if ( keyEvent & & ( keyEvent - > key ( ) = = Qt : : Key_Enter | | keyEvent - > key ( ) = = Qt : : Key_Return ) ) {
// Enter pressed
if ( Settings - > getChatSendMessageWithCtrlReturn ( ) ) {
if ( keyEvent - > modifiers ( ) & Qt : : ControlModifier ) {
// send message with Ctrl+Enter
sendChat ( ) ;
return true ; // eat event
}
} else {
if ( keyEvent - > modifiers ( ) & Qt : : ControlModifier ) {
// insert return
ui . chattextEdit - > textCursor ( ) . insertText ( " \n " ) ;
} else {
// send message with Enter
sendChat ( ) ;
}
return true ; // eat event
}
}
}
}
// pass the event on to the parent class
2010-11-15 15:49:24 -05:00
return QWidget : : eventFilter ( obj , event ) ;
2009-01-30 14:52:47 -05:00
}
void PopupChatDialog : : sendChat ( )
{
2010-09-01 13:56:15 -04:00
QTextEdit * chatWidget = ui . chattextEdit ;
2009-01-30 14:52:47 -05:00
2010-09-04 10:23:30 -04:00
if ( chatWidget - > toPlainText ( ) . isEmpty ( ) ) {
// nothing to send
return ;
}
2011-09-29 05:20:09 -04:00
QString text ;
RsHtml : : optimizeHtml ( chatWidget , text ) ;
std : : wstring msg = text . toStdWString ( ) ;
2010-09-04 10:23:30 -04:00
if ( msg . empty ( ) ) {
// nothing to send
return ;
}
2010-09-01 13:56:15 -04:00
std : : string ownId ;
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
{
rsiface - > lockData ( ) ; /* Lock Interface */
const RsConfig & conf = rsiface - > getConfig ( ) ;
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
ownId = conf . ownId ;
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
rsiface - > unlockData ( ) ; /* Unlock Interface */
}
2009-01-30 14:52:47 -05:00
# ifdef CHAT_DEBUG
2010-09-12 20:27:50 -04:00
std : : cout < < " PopupChatDialog:sendChat " < < std : : endl ;
2009-01-30 14:52:47 -05:00
# endif
2011-11-27 16:04:10 -05:00
if ( sendPrivateChat ( msg ) )
{
2010-10-03 06:08:58 -04:00
QDateTime currentTime = QDateTime : : currentDateTime ( ) ;
2011-09-29 05:20:09 -04:00
addChatMsg ( false , QString : : fromUtf8 ( rsPeers - > getPeerName ( ownId ) . c_str ( ) ) , currentTime , currentTime , QString : : fromStdWString ( msg ) , TYPE_NORMAL ) ;
2010-09-20 20:08:06 -04:00
}
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
chatWidget - > clear ( ) ;
2010-10-07 20:07:44 -04:00
// workaround for Qt bug - http://bugreports.qt.nokia.com/browse/QTBUG-2533
// QTextEdit::clear() does not reset the CharFormat if document contains hyperlinks that have been accessed.
chatWidget - > setCurrentCharFormat ( QTextCharFormat ( ) ) ;
2010-09-01 13:56:15 -04:00
setFont ( ) ;
2009-01-30 14:52:47 -05:00
}
2011-11-27 16:04:10 -05:00
bool PopupChatDialog : : sendPrivateChat ( const std : : wstring & msg )
{
return rsMsgs - > sendPrivateChat ( dialogId , msg ) ;
}
2009-01-30 14:52:47 -05:00
/**
Toggles the ToolBox on and off , changes toggle button text
*/
void PopupChatDialog : : showAvatarFrame ( bool show )
{
if ( show ) {
ui . avatarframe - > setVisible ( true ) ;
ui . avatarFrameButton - > setChecked ( true ) ;
ui . avatarFrameButton - > setToolTip ( tr ( " Hide Avatar " ) ) ;
2010-09-12 20:27:50 -04:00
ui . avatarFrameButton - > setIcon ( QIcon ( " :images/hide_toolbox_frame.png " ) ) ;
2009-01-30 14:52:47 -05:00
} else {
ui . avatarframe - > setVisible ( false ) ;
ui . avatarFrameButton - > setChecked ( false ) ;
ui . avatarFrameButton - > setToolTip ( tr ( " Show Avatar " ) ) ;
2010-09-12 20:27:50 -04:00
ui . avatarFrameButton - > setIcon ( QIcon ( " :images/show_toolbox_frame.png " ) ) ;
2009-01-30 14:52:47 -05:00
}
2011-03-26 19:19:28 -04:00
PeerSettings - > setShowAvatarFrame ( dialogId , show ) ;
2009-01-30 14:52:47 -05:00
}
2010-08-24 11:28:50 -04:00
void PopupChatDialog : : on_closeInfoFrameButton_clicked ( )
{
ui . infoframe - > setVisible ( false ) ;
}
2009-01-30 14:52:47 -05:00
void PopupChatDialog : : setColor ( )
{
2010-09-10 14:38:46 -04:00
bool ok ;
2011-04-09 18:52:52 -04:00
QRgb color = QColorDialog : : getRgba ( ui . chattextEdit - > textColor ( ) . rgba ( ) , & ok , window ( ) ) ;
2009-01-30 14:52:47 -05:00
if ( ok ) {
mCurrentColor = QColor ( color ) ;
2010-09-10 14:38:46 -04:00
PeerSettings - > setPrivateChatColor ( dialogId , mCurrentColor . name ( ) ) ;
2009-01-30 14:52:47 -05:00
colorChanged ( mCurrentColor ) ;
}
setFont ( ) ;
}
void PopupChatDialog : : colorChanged ( const QColor & c )
{
QPixmap pix ( 16 , 16 ) ;
pix . fill ( c ) ;
ui . colorButton - > setIcon ( pix ) ;
}
void PopupChatDialog : : getFont ( )
{
bool ok ;
2010-09-10 14:38:46 -04:00
QFont font = QFontDialog : : getFont ( & ok , mCurrentFont , this ) ;
if ( ok ) {
fontChanged ( font ) ;
}
}
void PopupChatDialog : : fontChanged ( const QFont & font )
{
mCurrentFont = font ;
ui . textboldButton - > setChecked ( mCurrentFont . bold ( ) ) ;
ui . textunderlineButton - > setChecked ( mCurrentFont . underline ( ) ) ;
ui . textitalicButton - > setChecked ( mCurrentFont . italic ( ) ) ;
2009-01-30 14:52:47 -05:00
setFont ( ) ;
}
void PopupChatDialog : : setFont ( )
{
2010-09-10 14:38:46 -04:00
mCurrentFont . setBold ( ui . textboldButton - > isChecked ( ) ) ;
mCurrentFont . setUnderline ( ui . textunderlineButton - > isChecked ( ) ) ;
mCurrentFont . setItalic ( ui . textitalicButton - > isChecked ( ) ) ;
2009-01-30 14:52:47 -05:00
2010-09-10 14:38:46 -04:00
ui . chattextEdit - > setFont ( mCurrentFont ) ;
ui . chattextEdit - > setTextColor ( mCurrentColor ) ;
2009-01-30 14:52:47 -05:00
2010-09-10 14:38:46 -04:00
ui . chattextEdit - > setFocus ( ) ;
2009-01-30 14:52:47 -05:00
2010-09-10 14:38:46 -04:00
PeerSettings - > setPrivateChatFont ( dialogId , mCurrentFont . toString ( ) ) ;
2009-01-30 14:52:47 -05:00
}
2009-03-12 13:57:30 -04:00
//============================================================================
2009-01-30 14:52:47 -05:00
void PopupChatDialog : : smileyWidget ( )
{
2010-09-14 13:47:11 -04:00
Emoticons : : showSmileyWidget ( this , ui . emoteiconButton , SLOT ( addSmiley ( ) ) , true ) ;
2009-01-30 14:52:47 -05:00
}
2009-03-12 13:57:30 -04:00
//============================================================================
2009-01-30 14:52:47 -05:00
void PopupChatDialog : : addSmiley ( )
{
2010-09-04 10:23:30 -04:00
ui . chattextEdit - > textCursor ( ) . insertText ( qobject_cast < QPushButton * > ( sender ( ) ) - > toolTip ( ) . split ( " | " ) . first ( ) ) ;
2009-01-30 14:52:47 -05:00
}
2009-03-12 13:57:30 -04:00
//============================================================================
2011-02-08 16:59:17 -05:00
void PopupChatDialog : : on_actionClear_Chat_History_triggered ( )
2011-02-06 15:41:15 -05:00
{
ui . textBrowser - > clear ( ) ;
}
2011-02-08 16:59:17 -05:00
void PopupChatDialog : : on_actionDelete_Chat_History_triggered ( )
2010-02-19 17:31:32 -05:00
{
2011-02-27 16:47:49 -05:00
if ( ( QMessageBox : : question ( this , " RetroShare " , tr ( " Do you really want to physically delete the history? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes ) {
on_actionClear_Chat_History_triggered ( ) ;
2011-09-29 05:20:09 -04:00
rsHistory - > clear ( dialogId ) ;
2011-02-27 16:47:49 -05:00
}
2010-02-19 17:31:32 -05:00
}
2009-05-11 10:21:11 -04:00
void PopupChatDialog : : addExtraFile ( )
{
2011-12-07 08:08:12 -05:00
QStringList files ;
if ( misc : : getOpenFileNames ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , files ) ) {
ui . hashBox - > addAttachments ( files /*, 0*/ ) ;
2010-12-02 19:54:40 -05:00
}
2009-05-11 10:27:45 -04:00
}
2010-08-06 08:30:06 -04:00
void PopupChatDialog : : addExtraPicture ( )
{
2010-12-02 19:54:40 -05:00
// select a picture file
QString file ;
2011-04-09 18:52:52 -04:00
if ( misc : : getOpenFileName ( window ( ) , RshareSettings : : LASTDIR_IMAGES , tr ( " Load Picture File " ) , " Pictures (*.png *.xpm *.jpg) " , file ) ) {
2011-12-07 08:08:12 -05:00
ui . hashBox - > addAttachments ( QStringList ( file ) , HashedFile : : Picture ) ;
2010-12-02 19:54:40 -05:00
}
2010-08-06 08:30:06 -04:00
}
2011-12-07 08:08:12 -05:00
void PopupChatDialog : : fileHashingFinished ( QList < HashedFile > hashedFiles )
2010-03-17 11:34:36 -04:00
{
2011-12-07 08:08:12 -05:00
std : : cerr < < " PopupChatDialog::fileHashingFinished() started. " < < std : : endl ;
2011-04-09 18:52:52 -04:00
2011-12-07 08:08:12 -05:00
QString message ;
2010-09-01 13:56:15 -04:00
2011-12-07 08:08:12 -05:00
QList < HashedFile > : : iterator it ;
for ( it = hashedFiles . begin ( ) ; it ! = hashedFiles . end ( ) ; + + it ) {
HashedFile & hashedFile = * it ;
QString ext = QFileInfo ( hashedFile . filename ) . suffix ( ) ;
RetroShareLink link ;
link . createFile ( hashedFile . filename , hashedFile . size , QString : : fromStdString ( hashedFile . hash ) ) ;
if ( hashedFile . flag & HashedFile : : Picture ) {
message + = QString ( " <img src= \" file:///%1 \" width= \" 100 \" height= \" 100 \" > " ) . arg ( hashedFile . filepath ) ;
message + = " <br> " ;
} else {
QString image = FilesDefs : : getImageFromFilename ( hashedFile . filename , false ) ;
if ( ! image . isEmpty ( ) ) {
message + = QString ( " <img src= \" %1 \" > " ) . arg ( image ) ;
}
}
message + = link . toHtmlSize ( ) ;
if ( it ! = hashedFiles . end ( ) ) {
message + = " <BR> " ;
}
2010-09-01 13:56:15 -04:00
}
2009-05-11 10:21:11 -04:00
# ifdef CHAT_DEBUG
2010-11-17 20:18:31 -05:00
std : : cerr < < " PopupChatDialog::fileHashingFinished message : " < < message . toStdString ( ) < < std : : endl ;
2009-05-11 10:21:11 -04:00
# endif
2010-11-19 20:40:24 -05:00
/* convert to real html document */
QTextBrowser textBrowser ;
textBrowser . setHtml ( message ) ;
std : : wstring msg = textBrowser . toHtml ( ) . toStdWString ( ) ;
2010-08-06 08:30:06 -04:00
2010-09-20 20:08:06 -04:00
if ( rsMsgs - > sendPrivateChat ( dialogId , msg ) ) {
2011-12-07 08:08:12 -05:00
std : : string ownId = rsPeers - > getOwnId ( ) ;
2010-10-03 06:08:58 -04:00
QDateTime currentTime = QDateTime : : currentDateTime ( ) ;
2011-09-29 05:20:09 -04:00
addChatMsg ( false , QString : : fromUtf8 ( rsPeers - > getPeerName ( ownId ) . c_str ( ) ) , currentTime , currentTime , QString : : fromStdWString ( msg ) , TYPE_NORMAL ) ;
2010-09-20 20:08:06 -04:00
}
2009-05-11 10:21:11 -04:00
}
2010-04-27 18:08:38 -04:00
bool PopupChatDialog : : fileSave ( )
{
if ( fileName . isEmpty ( ) )
return fileSaveAs ( ) ;
QFile file ( fileName ) ;
if ( ! file . open ( QFile : : WriteOnly ) )
return false ;
QTextStream ts ( & file ) ;
ts . setCodec ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
ts < < ui . textBrowser - > document ( ) - > toPlainText ( ) ;
ui . textBrowser - > document ( ) - > setModified ( false ) ;
return true ;
}
2010-03-04 09:15:30 -05:00
2010-04-27 18:08:38 -04:00
bool PopupChatDialog : : fileSaveAs ( )
{
2010-12-02 19:54:40 -05:00
QString fn ;
2011-04-09 18:52:52 -04:00
if ( misc : : getSaveFileName ( window ( ) , RshareSettings : : LASTDIR_HISTORY , tr ( " Save as... " ) , tr ( " Text File (*.txt );;All Files (*) " ) , fn ) ) {
2010-12-02 19:54:40 -05:00
setCurrentFileName ( fn ) ;
return fileSave ( ) ;
}
return false ;
2010-04-27 18:08:38 -04:00
}
void PopupChatDialog : : setCurrentFileName ( const QString & fileName )
{
this - > fileName = fileName ;
ui . textBrowser - > document ( ) - > setModified ( false ) ;
setWindowModified ( false ) ;
}
2010-08-18 08:02:36 -04:00
2010-09-20 20:08:06 -04:00
void PopupChatDialog : : clearOfflineMessages ( )
{
2011-09-29 05:20:09 -04:00
manualDelete = true ;
2010-09-20 20:08:06 -04:00
rsMsgs - > clearPrivateChatQueue ( false , dialogId ) ;
2011-09-29 05:20:09 -04:00
manualDelete = false ;
2010-09-20 20:08:06 -04:00
}
2011-12-04 09:31:48 -05:00
void PopupChatDialog : : updateStatus_slot ( const QString & peer_id , int status )
{
updateStatus ( peer_id , status ) ;
}
2010-08-20 14:45:44 -04:00
void PopupChatDialog : : updateStatus ( const QString & peer_id , int status )
2010-08-18 08:02:36 -04:00
{
2010-08-30 16:14:58 -04:00
std : : string stdPeerId = peer_id . toStdString ( ) ;
2010-09-03 12:46:47 -04:00
/* set font size for status */
2010-08-30 16:14:58 -04:00
if ( stdPeerId = = dialogId ) {
// the peers status has changed
2010-11-15 15:49:24 -05:00
2010-08-30 16:14:58 -04:00
switch ( status ) {
case RS_STATUS_OFFLINE :
ui . infoframe - > setVisible ( true ) ;
2010-09-28 16:33:34 -04:00
ui . infolabel - > setText ( dialogName + " " + tr ( " apears to be Offline. " ) + " \n " + tr ( " Messages you send will be delivered after Friend is again Online " ) ) ;
2010-08-30 16:14:58 -04:00
break ;
case RS_STATUS_INACTIVE :
ui . infoframe - > setVisible ( true ) ;
2010-09-28 16:33:34 -04:00
ui . infolabel - > setText ( dialogName + " " + tr ( " is Idle and may not reply " ) ) ;
2010-08-30 16:14:58 -04:00
break ;
case RS_STATUS_ONLINE :
ui . infoframe - > setVisible ( false ) ;
break ;
case RS_STATUS_AWAY :
2010-09-28 16:33:34 -04:00
ui . infolabel - > setText ( dialogName + " " + tr ( " is Away and may not reply " ) ) ;
2010-08-30 16:14:58 -04:00
ui . infoframe - > setVisible ( true ) ;
break ;
case RS_STATUS_BUSY :
2010-09-28 16:33:34 -04:00
ui . infolabel - > setText ( dialogName + " " + tr ( " is Busy and may not reply " ) ) ;
2010-08-30 16:14:58 -04:00
ui . infoframe - > setVisible ( true ) ;
break ;
}
2010-09-12 10:10:28 -04:00
QString statusString ( " <span style= \" font-size:11pt; font-weight:500; " " \" >%1</span> " ) ;
2010-09-28 16:33:34 -04:00
ui . friendnamelabel - > setText ( dialogName + " ( " + statusString . arg ( StatusDefs : : name ( status ) ) + " ) " ) ;
2010-09-12 10:10:28 -04:00
2010-11-15 15:49:24 -05:00
peerStatus = status ;
PopupChatWindow * window = WINDOW ( this ) ;
if ( window ) {
window - > calculateTitle ( this ) ;
}
2010-08-20 14:45:44 -04:00
return ;
2010-08-18 08:02:36 -04:00
}
2010-08-30 16:14:58 -04:00
// ignore status change
2010-08-18 08:02:36 -04:00
}
2010-09-01 21:37:47 -04:00
2010-09-02 06:15:13 -04:00
void PopupChatDialog : : updatePeersCustomStateString ( const QString & peer_id , const QString & status_string )
2010-09-01 21:37:47 -04:00
{
2010-09-02 06:15:13 -04:00
std : : string stdPeerId = peer_id . toStdString ( ) ;
2011-05-04 11:07:03 -04:00
QString status_text ;
2010-09-01 21:37:47 -04:00
2010-09-02 06:15:13 -04:00
if ( stdPeerId = = dialogId ) {
// the peers status string has changed
if ( status_string . isEmpty ( ) ) {
2010-09-01 21:37:47 -04:00
ui . statusmessagelabel - > hide ( ) ;
2010-09-02 06:15:13 -04:00
} else {
2010-09-01 21:37:47 -04:00
ui . statusmessagelabel - > show ( ) ;
2011-05-08 19:11:27 -04:00
status_text = RsHtml : : formatText ( status_string , RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS ) ;
2011-05-04 11:07:03 -04:00
ui . statusmessagelabel - > setText ( status_text ) ;
2010-09-01 21:37:47 -04:00
}
}
}
2010-09-02 06:15:13 -04:00
2010-10-02 18:42:30 -04:00
void PopupChatDialog : : on_actionMessageHistory_triggered ( )
{
2011-09-29 05:20:09 -04:00
ImHistoryBrowser imBrowser ( dialogId , ui . chattextEdit , window ( ) ) ;
2010-10-02 18:42:30 -04:00
imBrowser . exec ( ) ;
}
2011-04-09 18:52:52 -04:00
bool PopupChatDialog : : setStyle ( )
{
if ( style . showDialog ( window ( ) ) ) {
PeerSettings - > setStyle ( dialogId , " PopupChatDialog " , style ) ;
return true ;
}
return false ;
}
const RSStyle & PopupChatDialog : : getStyle ( )
{
return style ;
}