2012-01-17 20:36:36 +00:00
/****************************************************************
*
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 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 <QApplication>
# include <QMenu>
# include <QKeyEvent>
# include <QScrollBar>
# include <QColorDialog>
# include <QFontDialog>
# include <QMessageBox>
2012-05-12 00:40:53 +00:00
# include <QTextStream>
# include <QTextCodec>
# include <QTimer>
2012-09-18 22:59:23 +00:00
# include <QTextDocumentFragment>
2013-07-04 19:36:12 +00:00
# include <QStringListModel>
2012-01-17 20:36:36 +00:00
# include "ChatWidget.h"
# include "ui_ChatWidget.h"
# include "gui/notifyqt.h"
# include "gui/RetroShareLink.h"
2013-04-13 13:12:13 +00:00
# include "gui/CreateMsgLinkDialog.h"
2012-01-17 20:36:36 +00:00
# include "gui/settings/rsharesettings.h"
2013-06-16 14:39:44 +00:00
# include "gui/settings/rsettingswin.h"
2012-01-17 20:36:36 +00:00
# include "gui/settings/RsharePeerSettings.h"
# include "gui/im_history/ImHistoryBrowser.h"
# include "gui/common/StatusDefs.h"
# include "gui/common/FilesDefs.h"
# include "gui/common/Emoticons.h"
# include "util/misc.h"
2012-05-12 00:40:53 +00:00
# include "util/HandleRichText.h"
2012-01-17 20:36:36 +00:00
# include <retroshare/rsstatus.h>
# include <retroshare/rspeers.h>
# include <retroshare/rshistory.h>
2013-06-18 20:13:58 +00:00
# include <retroshare/rsmsgs.h>
2012-01-17 20:36:36 +00:00
# include <time.h>
/*****
* # define CHAT_DEBUG 1
* * * * */
ChatWidget : : ChatWidget ( QWidget * parent ) :
QWidget ( parent ) , ui ( new Ui : : ChatWidget )
{
ui - > setupUi ( this ) ;
newMessages = false ;
typing = false ;
peerStatus = 0 ;
isChatLobby = false ;
2012-01-23 19:57:06 +00:00
firstShow = true ;
2012-04-12 23:00:39 +00:00
inChatCharFormatChanged = false ;
2013-07-06 15:37:22 +00:00
completer = NULL ;
2013-07-16 21:14:48 +00:00
lastMsgDate = QDate : : currentDate ( ) ;
2012-01-17 20:36:36 +00:00
lastStatusSendTime = 0 ;
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 ( ) ) ) ;
2012-02-11 21:41:41 +00:00
connect ( ui - > colorButton , SIGNAL ( clicked ( ) ) , this , SLOT ( chooseColor ( ) ) ) ;
2012-01-17 20:36:36 +00:00
connect ( ui - > emoteiconButton , SIGNAL ( clicked ( ) ) , this , SLOT ( smileyWidget ( ) ) ) ;
connect ( ui - > actionSaveChatHistory , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
connect ( ui - > actionClearChatHistory , SIGNAL ( triggered ( ) ) , this , SLOT ( clearChatHistory ( ) ) ) ;
connect ( ui - > actionDeleteChatHistory , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteChatHistory ( ) ) ) ;
connect ( ui - > actionMessageHistory , SIGNAL ( triggered ( ) ) , this , SLOT ( messageHistory ( ) ) ) ;
2012-02-11 21:41:41 +00:00
connect ( ui - > actionChooseFont , SIGNAL ( triggered ( ) ) , this , SLOT ( chooseFont ( ) ) ) ;
connect ( ui - > actionResetFont , SIGNAL ( triggered ( ) ) , this , SLOT ( resetFont ( ) ) ) ;
2012-01-17 20:36:36 +00:00
connect ( ui - > hashBox , SIGNAL ( fileHashingFinished ( QList < HashedFile > ) ) , this , SLOT ( fileHashingFinished ( QList < HashedFile > ) ) ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerStatusChanged ( const QString & , int ) ) , this , SLOT ( updateStatus ( const QString & , int ) ) ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerHasNewCustomStateString ( const QString & , const QString & ) ) , this , SLOT ( updatePeersCustomStateString ( const QString & , const QString & ) ) ) ;
2012-08-22 08:19:46 +00:00
connect ( ui - > textBrowser , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenuTextBrowser ( QPoint ) ) ) ;
2012-08-27 21:48:00 +00:00
connect ( ui - > chatTextEdit , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
2012-04-12 23:00:39 +00:00
// reset text and color after removing all characters from the QTextEdit and after calling QTextEdit::clear
2012-08-27 21:48:00 +00:00
connect ( ui - > chatTextEdit , SIGNAL ( currentCharFormatChanged ( QTextCharFormat ) ) , this , SLOT ( chatCharFormatChanged ( ) ) ) ;
2012-01-17 20:36:36 +00:00
2012-08-27 21:48:00 +00:00
ui - > infoFrame - > setVisible ( false ) ;
ui - > statusMessageLabel - > hide ( ) ;
2012-01-17 20:36:36 +00:00
setAcceptDrops ( true ) ;
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > setAcceptDrops ( false ) ;
2012-01-17 20:36:36 +00:00
ui - > hashBox - > setDropWidget ( this ) ;
ui - > hashBox - > setAutoHide ( true ) ;
2012-02-11 21:41:41 +00:00
QMenu * menu = new QMenu ( ) ;
menu - > addAction ( ui - > actionChooseFont ) ;
menu - > addAction ( ui - > actionResetFont ) ;
ui - > fontButton - > setMenu ( menu ) ;
menu = new QMenu ( ) ;
menu - > addAction ( ui - > actionClearChatHistory ) ;
menu - > addAction ( ui - > actionDeleteChatHistory ) ;
menu - > addAction ( ui - > actionSaveChatHistory ) ;
menu - > addAction ( ui - > actionMessageHistory ) ;
ui - > pushtoolsButton - > setMenu ( menu ) ;
2012-01-17 20:36:36 +00:00
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > installEventFilter ( this ) ;
2012-01-17 20:36:36 +00:00
2013-01-22 00:14:10 +00:00
# if QT_VERSION < 0x040700
2012-09-18 22:59:23 +00:00
// embedded images are not supported before QT 4.7.0
2012-01-17 20:36:36 +00:00
ui - > attachPictureButton - > setVisible ( false ) ;
2013-01-22 00:14:10 +00:00
# endif
2012-01-17 20:36:36 +00:00
resetStatusBar ( ) ;
2013-07-18 21:50:32 +00:00
completer = new QCompleter ( this ) ;
completer - > setModel ( modelFromPeers ( ) ) ;
completer - > setModelSorting ( QCompleter : : CaseInsensitivelySortedModel ) ;
completer - > setModelSorting ( QCompleter : : UnsortedModel ) ;
//completer->setCaseSensitivity(Qt::CaseInsensitive);
completer - > setWrapAround ( false ) ;
ui - > chatTextEdit - > setCompleter ( completer ) ;
ui - > chatTextEdit - > setCompleterKeyModifiers ( Qt : : ControlModifier ) ;
ui - > chatTextEdit - > setCompleterKey ( Qt : : Key_Space ) ;
2012-01-17 20:36:36 +00:00
}
ChatWidget : : ~ ChatWidget ( )
{
processSettings ( false ) ;
delete ui ;
}
2012-11-11 21:17:00 +00:00
void ChatWidget : : setDefaultExtraFileFlags ( TransferRequestFlags fl )
{
mDefaultExtraFileFlags = fl ;
ui - > hashBox - > setDefaultTransferRequestFlags ( fl ) ;
}
2013-04-23 22:43:19 +00:00
void ChatWidget : : addChatBarWidget ( QWidget * w )
2012-02-25 12:17:36 +00:00
{
2013-04-23 22:43:19 +00:00
ui - > toolBarFrame - > layout ( ) - > addWidget ( w ) ;
2012-02-25 12:17:36 +00:00
}
2012-01-18 00:32:15 +00:00
void ChatWidget : : init ( const std : : string & peerId , const QString & title )
2012-01-17 20:36:36 +00:00
{
this - > peerId = peerId ;
2012-01-18 00:32:15 +00:00
this - > title = title ;
2012-01-17 20:36:36 +00:00
2013-07-01 20:35:07 +00:00
ui - > titleLabel - > setText ( RsHtml : : plainText ( title ) ) ;
2012-01-18 00:32:15 +00:00
std : : string ownId = rsPeers - > getOwnId ( ) ;
setName ( QString : : fromUtf8 ( rsPeers - > getPeerName ( ownId ) . c_str ( ) ) ) ;
2012-01-17 20:36:36 +00:00
ChatLobbyId lid ;
if ( rsMsgs - > isLobbyId ( peerId , lid ) ) {
isChatLobby = true ;
2012-02-06 16:58:45 +00:00
chatStyle . setStyleFromSettings ( ChatStyle : : TYPE_PUBLIC ) ;
} else {
chatStyle . setStyleFromSettings ( ChatStyle : : TYPE_PRIVATE ) ;
2012-01-17 20:36:36 +00:00
}
currentColor . setNamedColor ( PeerSettings - > getPrivateChatColor ( peerId ) ) ;
currentFont . fromString ( PeerSettings - > getPrivateChatFont ( peerId ) ) ;
2012-02-11 21:41:41 +00:00
colorChanged ( ) ;
fontChanged ( ) ;
setColorAndFont ( ) ;
2012-01-17 20:36:36 +00:00
// load style
PeerSettings - > getStyle ( peerId , " ChatWidget " , style ) ;
if ( ! isChatLobby ) {
// initialize first status
StatusInfo peerStatusInfo ;
// No check of return value. Non existing status info is handled as offline.
rsStatus - > getStatus ( peerId , peerStatusInfo ) ;
updateStatus ( QString : : fromStdString ( peerId ) , peerStatusInfo . status ) ;
// initialize first custom state string
QString customStateString = QString : : fromUtf8 ( rsMsgs - > getCustomStateString ( peerId ) . c_str ( ) ) ;
updatePeersCustomStateString ( QString : : fromStdString ( peerId ) , customStateString ) ;
} else {
2013-07-06 15:37:22 +00:00
completer = new QCompleter ( this ) ;
completer - > setModel ( modelFromPeers ( ) ) ;
completer - > setModelSorting ( QCompleter : : CaseInsensitivelySortedModel ) ;
completer - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
completer - > setWrapAround ( false ) ;
ui - > chatTextEdit - > setCompleter ( completer ) ;
ui - > chatTextEdit - > setCompleterKeyModifiers ( Qt : : ControlModifier ) ;
ui - > chatTextEdit - > setCompleterKey ( Qt : : Key_Space ) ;
2012-01-28 15:11:58 +00:00
updateTitle ( ) ;
2012-01-17 20:36:36 +00:00
}
if ( rsHistory - > getEnable ( false ) ) {
// get chat messages from history
std : : list < HistoryMsg > historyMsgs ;
int messageCount = Settings - > getPrivateChatHistoryCount ( ) ;
if ( messageCount > 0 ) {
rsHistory - > getMessages ( peerId , 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 ) ;
}
}
}
processSettings ( true ) ;
}
void ChatWidget : : processSettings ( bool load )
{
Settings - > beginGroup ( QString ( " ChatWidget " ) ) ;
if ( load ) {
// 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 ( ) ;
}
bool ChatWidget : : eventFilter ( QObject * obj , QEvent * event )
{
2012-08-27 21:48:00 +00:00
if ( obj = = ui - > chatTextEdit ) {
2012-01-17 20:36:36 +00:00
if ( event - > type ( ) = = QEvent : : KeyPress ) {
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( event ) ;
2013-03-06 19:41:08 +00:00
if ( keyEvent ) {
2013-04-21 20:18:58 +00:00
if ( ! keyEvent - > text ( ) . isEmpty ( ) ) {
updateStatusTyping ( ) ;
}
2013-03-06 19:41:08 +00:00
if ( isChatLobby ) {
if ( keyEvent - > key ( ) = = Qt : : Key_Tab ) {
completeNickname ( ( bool ) ( keyEvent - > modifiers ( ) & Qt : : ShiftModifier ) ) ;
2012-01-17 20:36:36 +00:00
return true ; // eat event
}
2013-03-06 19:41:08 +00:00
else {
completionWord . clear ( ) ;
}
}
2013-07-06 15:37:22 +00:00
if ( ( keyEvent - > modifiers ( ) & ui - > chatTextEdit - > getCompleterKeyModifiers ( ) ) & & keyEvent - > key ( ) = = ui - > chatTextEdit - > getCompleterKey ( ) ) {
completer - > setModel ( modelFromPeers ( ) ) ;
}
if ( keyEvent - > text ( ) = = " @ " ) {
ui - > chatTextEdit - > forceCompleterShowNextKeyEvent ( " @ " ) ;
completer - > setModel ( modelFromPeers ( ) ) ;
}
2013-03-06 19:41:08 +00:00
if ( 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
}
2012-01-17 20:36:36 +00:00
} else {
2013-03-06 19:41:08 +00:00
if ( keyEvent - > modifiers ( ) & Qt : : ControlModifier ) {
// insert return
ui - > chatTextEdit - > textCursor ( ) . insertText ( " \n " ) ;
} else {
// send message with Enter
sendChat ( ) ;
}
return true ; // eat event
2012-01-17 20:36:36 +00:00
}
}
}
}
} else {
if ( event - > type ( ) = = QEvent : : WindowActivate ) {
if ( isVisible ( ) & & ( window ( ) = = NULL | | window ( ) - > isActiveWindow ( ) ) ) {
newMessages = false ;
emit infoChanged ( this ) ;
focusDialog ( ) ;
}
}
}
// pass the event on to the parent class
return QWidget : : eventFilter ( obj , event ) ;
}
2013-03-06 19:41:08 +00:00
/**
* @ brief Utility function for completeNickname .
*/
static bool caseInsensitiveCompare ( QString a , QString b )
{
return a . toLower ( ) < b . toLower ( ) ;
}
/**
* @ brief Completes nickname based on previous characters .
* @ param reverse true to list nicknames in reverse alphabetical order .
*/
void ChatWidget : : completeNickname ( bool reverse )
{
// Find lobby we belong to
const ChatLobbyInfo * lobby = NULL ;
std : : list < ChatLobbyInfo > lobbies ;
rsMsgs - > getChatLobbyList ( lobbies ) ;
std : : list < ChatLobbyInfo > : : const_iterator lobbyIt ;
for ( lobbyIt = lobbies . begin ( ) ; lobbyIt ! = lobbies . end ( ) ; + + lobbyIt ) {
std : : string vpid ;
if ( rsMsgs - > getVirtualPeerId ( lobbyIt - > lobby_id , vpid ) ) {
if ( vpid = = peerId ) {
lobby = & * lobbyIt ;
break ;
}
}
}
if ( ! lobby )
return ;
QTextCursor cursor = ui - > chatTextEdit - > textCursor ( ) ;
// Do nothing if there is a selection
if ( cursor . anchor ( ) ! = cursor . position ( ) )
return ;
// We want to complete the word typed by the user. This is easy.
// But also, if there are two participants whose name start with the word
// the user typed, the first press on <tab> should show the first
// participant’ s name, and the second press on <tab> should show the
// second participant’ s name.
cursor . beginEditBlock ( ) ;
if ( ! completionWord . isEmpty ( ) ) {
cursor . movePosition ( QTextCursor : : PreviousCharacter , QTextCursor : : KeepAnchor , cursor . position ( ) - completionPosition ) ;
}
else {
cursor . movePosition ( QTextCursor : : PreviousWord , QTextCursor : : KeepAnchor ) ;
completionPosition = cursor . position ( ) ;
}
if ( cursor . selectedText ( ) = = " : " ) {
cursor . movePosition ( QTextCursor : : PreviousWord , QTextCursor : : KeepAnchor ) ;
}
bool firstWord = ( cursor . position ( ) = = 0 ) ;
QString word = cursor . selectedText ( ) ;
if ( word . endsWith ( " : " ) ) {
word . chop ( 2 ) ;
}
if ( word . length ( ) > 0 ) {
// Sort participants list
std : : list < QString > participants ;
for ( std : : map < std : : string , time_t > : : const_iterator it = lobby - > nick_names . begin ( ) ;
it ! = lobby - > nick_names . end ( ) ;
it + + ) {
participants . push_front ( QString : : fromUtf8 ( it - > first . c_str ( ) ) ) ;
}
participants . sort ( caseInsensitiveCompare ) ;
// Search for a participant nickname that starts with the previous word
std : : list < QString > : : const_iterator it , start , end ;
int delta ;
bool skippedParticipant = false ;
if ( reverse ) {
// Note: at the moment reverse completion doesn’ t work because
// shift-tab selects the previous widget
start = participants . end ( ) ;
- - start ;
end = participants . begin ( ) ;
- - end ;
delta = - 1 ;
}
else {
start = participants . begin ( ) ;
end = participants . end ( ) ;
delta = 1 ;
}
do {
for ( it = start ; it ! = end ; ( delta = = 1 ) ? + + it : - - it ) {
QString participant = * it ;
if ( participant . startsWith ( word , Qt : : CaseInsensitive ) ) {
if ( ! completionWord . isEmpty ( ) & & ! skippedParticipant ) {
// This participant nicknaem was completed with <tab>;
// skip it and find the next one that starts with
// completionWord
word = completionWord ;
skippedParticipant = true ;
continue ;
}
skippedParticipant = false ;
cursor . insertText ( participant ) ;
if ( firstWord ) {
cursor . insertText ( QString ( " : " ) ) ;
}
break ;
}
}
} while ( skippedParticipant ) ;
if ( completionWord . isEmpty ( ) ) {
completionWord = word ;
}
}
cursor . endEditBlock ( ) ;
}
2013-07-04 19:36:12 +00:00
QAbstractItemModel * ChatWidget : : modelFromPeers ( )
{
2013-07-06 15:37:22 +00:00
// Find lobby we belong to
const ChatLobbyInfo * lobby = NULL ;
std : : list < ChatLobbyInfo > lobbies ;
rsMsgs - > getChatLobbyList ( lobbies ) ;
std : : list < ChatLobbyInfo > : : const_iterator lobbyIt ;
for ( lobbyIt = lobbies . begin ( ) ; lobbyIt ! = lobbies . end ( ) ; + + lobbyIt ) {
std : : string vpid ;
if ( rsMsgs - > getVirtualPeerId ( lobbyIt - > lobby_id , vpid ) ) {
if ( vpid = = peerId ) {
lobby = & * lobbyIt ;
break ;
}
}
}
2013-07-04 19:36:12 +00:00
2013-07-06 15:37:22 +00:00
if ( ! lobby )
return new QStringListModel ( completer ) ;
2013-07-04 19:36:12 +00:00
# ifndef QT_NO_CURSOR
2013-07-06 15:37:22 +00:00
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
2013-07-04 19:36:12 +00:00
# endif
2013-07-06 15:37:22 +00:00
// Get participants list
QStringList participants ;
for ( std : : map < std : : string , time_t > : : const_iterator it = lobby - > nick_names . begin ( ) ;
it ! = lobby - > nick_names . end ( ) ;
it + + ) {
participants . push_front ( QString : : fromUtf8 ( it - > first . c_str ( ) ) ) ;
}
2013-07-04 19:36:12 +00:00
# ifndef QT_NO_CURSOR
2013-07-06 15:37:22 +00:00
QApplication : : restoreOverrideCursor ( ) ;
2013-07-04 19:36:12 +00:00
# endif
2013-07-06 15:37:22 +00:00
return new QStringListModel ( participants , completer ) ;
2013-07-04 19:36:12 +00:00
}
2012-01-17 20:36:36 +00:00
void ChatWidget : : addToolsAction ( QAction * action )
{
ui - > pushtoolsButton - > menu ( ) - > addAction ( action ) ;
}
void ChatWidget : : showEvent ( QShowEvent */ * event */ )
{
newMessages = false ;
emit infoChanged ( this ) ;
focusDialog ( ) ;
2012-01-23 19:57:06 +00:00
if ( firstShow ) {
// Workaround: now the scroll position is correct calculated
firstShow = false ;
QScrollBar * scrollbar = ui - > textBrowser - > verticalScrollBar ( ) ;
scrollbar - > setValue ( scrollbar - > maximum ( ) ) ;
}
2012-01-17 20:36:36 +00:00
}
void ChatWidget : : resizeEvent ( QResizeEvent */ * event */ )
{
// Workaround: now the scroll position is correct calculated
QScrollBar * scrollbar = ui - > textBrowser - > verticalScrollBar ( ) ;
scrollbar - > setValue ( scrollbar - > maximum ( ) ) ;
}
void ChatWidget : : addToParent ( QWidget * newParent )
{
newParent - > window ( ) - > installEventFilter ( this ) ;
}
void ChatWidget : : removeFromParent ( QWidget * oldParent )
{
oldParent - > window ( ) - > removeEventFilter ( this ) ;
}
void ChatWidget : : focusDialog ( )
{
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > setFocus ( ) ;
2012-01-17 20:36:36 +00:00
}
2012-03-20 23:05:17 +00:00
void ChatWidget : : setWelcomeMessage ( QString & text )
{
ui - > textBrowser - > setText ( text ) ;
}
2012-01-17 20:36:36 +00:00
void ChatWidget : : addChatMsg ( bool incoming , const QString & name , const QDateTime & sendTime , const QDateTime & recvTime , const QString & message , enumChatType chatType )
{
# ifdef CHAT_DEBUG
std : : cout < < " ChatWidget::addChatMsg message : " < < message . toStdString ( ) < < std : : endl ;
# endif
2012-05-12 00:40:53 +00:00
unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_OPTIMIZE ;
unsigned int formatFlag = 0 ;
2012-01-17 20:36:36 +00:00
2013-07-16 21:14:48 +00:00
bool addDate = false ;
if ( QDate : : currentDate ( ) > lastMsgDate )
{
lastMsgDate = QDate : : currentDate ( ) ;
addDate = true ;
}
2012-01-17 20:36:36 +00:00
// embed smileys ?
if ( Settings - > valueFromGroup ( QString ( " Chat " ) , QString : : fromUtf8 ( " Emoteicons_PrivatChat " ) , true ) . toBool ( ) ) {
2012-05-12 00:40:53 +00:00
formatTextFlag | = RSHTML_FORMATTEXT_EMBED_SMILEYS ;
2012-01-17 20:36:36 +00:00
}
2012-09-21 21:23:14 +00:00
// Always fix colors
formatTextFlag | = RSHTML_FORMATTEXT_FIX_COLORS ;
qreal desiredContrast = Settings - > valueFromGroup ( " Chat " , " MinimumContrast " , 4.5 ) . toDouble ( ) ;
QColor backgroundColor = ui - > textBrowser - > palette ( ) . base ( ) . color ( ) ;
// Remove font name, size, bold, italics?
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableCustomFonts " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY ;
}
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableCustomFontSize " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_SIZE ;
}
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableBold " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT ;
}
if ( ! Settings - > valueFromGroup ( " Chat " , " EnableItalics " , true ) . toBool ( ) ) {
formatTextFlag | = RSHTML_FORMATTEXT_REMOVE_FONT_STYLE ;
}
2012-01-17 20:36:36 +00:00
ChatStyle : : enumFormatMessage type ;
if ( chatType = = TYPE_OFFLINE ) {
type = ChatStyle : : FORMATMSG_OOUTGOING ;
2012-05-01 12:58:28 +00:00
} else if ( chatType = = TYPE_SYSTEM ) {
type = ChatStyle : : FORMATMSG_SYSTEM ;
2013-07-16 21:14:48 +00:00
} else if ( chatType = = TYPE_HISTORY | | addDate ) {
2012-01-17 20:36:36 +00:00
type = incoming ? ChatStyle : : FORMATMSG_HINCOMING : ChatStyle : : FORMATMSG_HOUTGOING ;
} else {
type = incoming ? ChatStyle : : FORMATMSG_INCOMING : ChatStyle : : FORMATMSG_OUTGOING ;
}
2012-02-03 21:43:09 +00:00
if ( chatType = = TYPE_SYSTEM ) {
formatFlag | = CHAT_FORMATMSG_SYSTEM ;
}
2012-09-21 21:23:14 +00:00
QString formattedMessage = RsHtml ( ) . formatText ( ui - > textBrowser - > document ( ) , message , formatTextFlag , backgroundColor , desiredContrast ) ;
2012-05-12 00:40:53 +00:00
QString formatMsg = chatStyle . formatMessage ( type , name , incoming ? sendTime : recvTime , formattedMessage , formatFlag ) ;
2012-01-17 20:36:36 +00:00
ui - > textBrowser - > append ( formatMsg ) ;
resetStatusBar ( ) ;
if ( incoming & & chatType = = TYPE_NORMAL ) {
emit newMessage ( this ) ;
2012-03-30 23:02:52 +00:00
if ( ! isActive ( ) ) {
2012-01-17 20:36:36 +00:00
newMessages = true ;
}
emit infoChanged ( this ) ;
}
}
2012-03-30 23:02:52 +00:00
bool ChatWidget : : isActive ( )
{
if ( ! isVisible ( ) | | ( window ( ) & & ( ! window ( ) - > isActiveWindow ( ) | | window ( ) - > isMinimized ( ) ) ) ) {
return false ;
}
return true ;
}
2013-02-22 21:42:27 +00:00
void ChatWidget : : pasteText ( const QString & S )
{
//std::cerr << "In paste link" << std::endl;
ui - > chatTextEdit - > insertHtml ( S ) ;
2013-06-18 21:24:27 +00:00
setColorAndFont ( ) ;
2013-02-22 21:42:27 +00:00
}
2012-01-17 20:36:36 +00:00
void ChatWidget : : pasteLink ( )
{
2013-02-22 21:42:27 +00:00
//std::cerr << "In paste link" << std::endl;
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > insertHtml ( RSLinkClipboard : : toHtml ( ) ) ;
2013-06-18 21:24:27 +00:00
setColorAndFont ( ) ;
2012-01-17 20:36:36 +00:00
}
2012-04-27 12:04:40 +00:00
void ChatWidget : : pasteOwnCertificateLink ( )
{
2013-02-22 21:42:27 +00:00
//std::cerr << "In paste own certificate link" << std::endl;
2012-04-27 12:04:40 +00:00
RetroShareLink link ;
std : : string ownId = rsPeers - > getOwnId ( ) ;
if ( link . createCertificate ( ownId ) ) {
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > insertHtml ( link . toHtml ( ) + " " ) ;
2013-06-18 21:24:27 +00:00
setColorAndFont ( ) ;
2012-04-27 12:04:40 +00:00
}
}
2012-09-07 21:28:25 +00:00
void ChatWidget : : contextMenu ( QPoint point )
2012-01-17 20:36:36 +00:00
{
std : : cerr < < " In context menu " < < std : : endl ;
2012-09-07 21:28:25 +00:00
QMenu * contextMnu = ui - > chatTextEdit - > createStandardContextMenu ( point ) ;
2012-01-17 20:36:36 +00:00
contextMnu - > addSeparator ( ) ;
QAction * action = contextMnu - > addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste RetroShare Link " ) , this , SLOT ( pasteLink ( ) ) ) ;
action - > setDisabled ( RSLinkClipboard : : empty ( ) ) ;
2012-11-28 19:58:14 +00:00
contextMnu - > addAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste my certificate link " ) , this , SLOT ( pasteOwnCertificateLink ( ) ) ) ;
2013-06-16 14:39:44 +00:00
//#ifdef ENABLE_DISTANT_CHAT_AND_MSGS
// contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste/Create private chat or Message link..."), this, SLOT(pasteCreateMsgLink()));
//#endif
2012-01-17 20:36:36 +00:00
contextMnu - > exec ( QCursor : : pos ( ) ) ;
delete ( contextMnu ) ;
}
2013-04-13 13:12:13 +00:00
void ChatWidget : : pasteCreateMsgLink ( )
{
2013-06-16 14:39:44 +00:00
RSettingsWin : : showYourself ( this , RSettingsWin : : Chat ) ;
2013-04-13 13:12:13 +00:00
}
2012-09-07 21:28:25 +00:00
void ChatWidget : : contextMenuTextBrowser ( QPoint point )
2012-08-22 08:19:46 +00:00
{
2012-09-26 17:52:58 +00:00
QMatrix matrix ;
matrix . translate ( ui - > textBrowser - > horizontalScrollBar ( ) - > value ( ) , ui - > textBrowser - > verticalScrollBar ( ) - > value ( ) ) ;
QMenu * contextMnu = ui - > textBrowser - > createStandardContextMenu ( matrix . map ( point ) ) ;
2012-08-22 08:19:46 +00:00
contextMnu - > addSeparator ( ) ;
contextMnu - > addAction ( ui - > actionClearChatHistory ) ;
2012-09-26 17:52:58 +00:00
contextMnu - > exec ( ui - > textBrowser - > viewport ( ) - > mapToGlobal ( point ) ) ;
2012-08-22 08:19:46 +00:00
delete ( contextMnu ) ;
}
2012-04-12 23:00:39 +00:00
void ChatWidget : : chatCharFormatChanged ( )
{
if ( inChatCharFormatChanged ) {
return ;
}
inChatCharFormatChanged = true ;
// Reset font and color before inserting a character if edit box is empty
// (color info disappears when the user deletes all text)
2012-08-27 21:48:00 +00:00
if ( ui - > chatTextEdit - > toPlainText ( ) . isEmpty ( ) ) {
2012-04-12 23:00:39 +00:00
setColorAndFont ( ) ;
}
inChatCharFormatChanged = false ;
}
2012-01-17 20:36:36 +00:00
void ChatWidget : : resetStatusBar ( )
{
ui - > statusLabel - > clear ( ) ;
ui - > typingpixmapLabel - > clear ( ) ;
typing = false ;
emit infoChanged ( this ) ;
}
void ChatWidget : : updateStatusTyping ( )
{
if ( time ( NULL ) - lastStatusSendTime > 5 ) // limit 'peer is typing' packets to at most every 10 sec
{
# ifdef ONLY_FOR_LINGUIST
tr ( " is typing... " ) ;
# endif
rsMsgs - > sendStatusString ( peerId , " is typing... " ) ;
lastStatusSendTime = time ( NULL ) ;
}
}
void ChatWidget : : sendChat ( )
{
2012-08-27 21:48:00 +00:00
QTextEdit * chatWidget = ui - > chatTextEdit ;
2012-01-17 20:36:36 +00:00
if ( chatWidget - > toPlainText ( ) . isEmpty ( ) ) {
// nothing to send
return ;
}
QString text ;
RsHtml : : optimizeHtml ( chatWidget , text ) ;
std : : wstring msg = text . toStdWString ( ) ;
if ( msg . empty ( ) ) {
// nothing to send
return ;
}
# ifdef CHAT_DEBUG
std : : cout < < " ChatWidget:sendChat " < < std : : endl ;
# endif
if ( rsMsgs - > sendPrivateChat ( peerId , msg ) ) {
QDateTime currentTime = QDateTime : : currentDateTime ( ) ;
2012-01-18 00:32:15 +00:00
addChatMsg ( false , name , currentTime , currentTime , QString : : fromStdWString ( msg ) , TYPE_NORMAL ) ;
2012-01-17 20:36:36 +00:00
}
chatWidget - > clear ( ) ;
// 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 ( ) ) ;
}
void ChatWidget : : on_closeInfoFrameButton_clicked ( )
{
2012-08-27 21:48:00 +00:00
ui - > infoFrame - > setVisible ( false ) ;
2012-01-17 20:36:36 +00:00
}
2012-02-11 21:41:41 +00:00
void ChatWidget : : chooseColor ( )
2012-01-17 20:36:36 +00:00
{
bool ok ;
2012-08-27 21:48:00 +00:00
QRgb color = QColorDialog : : getRgba ( ui - > chatTextEdit - > textColor ( ) . rgba ( ) , & ok , window ( ) ) ;
2012-01-17 20:36:36 +00:00
if ( ok ) {
currentColor = QColor ( color ) ;
PeerSettings - > setPrivateChatColor ( peerId , currentColor . name ( ) ) ;
2012-02-11 21:41:41 +00:00
colorChanged ( ) ;
setColorAndFont ( ) ;
2012-01-17 20:36:36 +00:00
}
}
2012-02-11 21:41:41 +00:00
void ChatWidget : : colorChanged ( )
2012-01-17 20:36:36 +00:00
{
QPixmap pix ( 16 , 16 ) ;
2012-02-11 21:41:41 +00:00
pix . fill ( currentColor ) ;
2012-01-17 20:36:36 +00:00
ui - > colorButton - > setIcon ( pix ) ;
}
2012-02-11 21:41:41 +00:00
void ChatWidget : : chooseFont ( )
2012-01-17 20:36:36 +00:00
{
bool ok ;
QFont font = QFontDialog : : getFont ( & ok , currentFont , this ) ;
if ( ok ) {
2012-02-11 21:41:41 +00:00
currentFont = font ;
fontChanged ( ) ;
setFont ( ) ;
2012-01-17 20:36:36 +00:00
}
}
2012-02-11 21:41:41 +00:00
void ChatWidget : : resetFont ( )
2012-01-17 20:36:36 +00:00
{
2012-02-11 21:41:41 +00:00
currentFont . fromString ( Settings - > getChatScreenFont ( ) ) ;
fontChanged ( ) ;
setFont ( ) ;
}
2012-01-17 20:36:36 +00:00
2012-02-11 21:41:41 +00:00
void ChatWidget : : fontChanged ( )
{
2012-01-17 20:36:36 +00:00
ui - > textboldButton - > setChecked ( currentFont . bold ( ) ) ;
ui - > textunderlineButton - > setChecked ( currentFont . underline ( ) ) ;
ui - > textitalicButton - > setChecked ( currentFont . italic ( ) ) ;
}
2012-02-11 21:41:41 +00:00
void ChatWidget : : setColorAndFont ( )
2012-01-17 20:36:36 +00:00
{
currentFont . setBold ( ui - > textboldButton - > isChecked ( ) ) ;
currentFont . setUnderline ( ui - > textunderlineButton - > isChecked ( ) ) ;
currentFont . setItalic ( ui - > textitalicButton - > isChecked ( ) ) ;
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > setFont ( currentFont ) ;
ui - > chatTextEdit - > setTextColor ( currentColor ) ;
2012-01-17 20:36:36 +00:00
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > setFocus ( ) ;
2012-02-11 21:41:41 +00:00
}
2012-01-17 20:36:36 +00:00
2012-02-11 21:41:41 +00:00
void ChatWidget : : setFont ( )
{
setColorAndFont ( ) ;
2012-01-17 20:36:36 +00:00
PeerSettings - > setPrivateChatFont ( peerId , currentFont . toString ( ) ) ;
}
void ChatWidget : : smileyWidget ( )
{
Emoticons : : showSmileyWidget ( this , ui - > emoteiconButton , SLOT ( addSmiley ( ) ) , true ) ;
}
void ChatWidget : : addSmiley ( )
{
2012-08-27 21:48:00 +00:00
ui - > chatTextEdit - > textCursor ( ) . insertText ( qobject_cast < QPushButton * > ( sender ( ) ) - > toolTip ( ) . split ( " | " ) . first ( ) ) ;
2012-01-17 20:36:36 +00:00
}
void ChatWidget : : clearChatHistory ( )
{
ui - > textBrowser - > clear ( ) ;
}
void ChatWidget : : deleteChatHistory ( )
{
if ( ( QMessageBox : : question ( this , " RetroShare " , tr ( " Do you really want to physically delete the history? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes ) {
clearChatHistory ( ) ;
rsHistory - > clear ( peerId ) ;
}
}
void ChatWidget : : messageHistory ( )
{
2012-08-27 21:48:00 +00:00
ImHistoryBrowser imBrowser ( peerId , ui - > chatTextEdit , window ( ) ) ;
2012-01-17 20:36:36 +00:00
imBrowser . exec ( ) ;
}
void ChatWidget : : addExtraFile ( )
{
QStringList files ;
if ( misc : : getOpenFileNames ( this , RshareSettings : : LASTDIR_EXTRAFILE , tr ( " Add Extra File " ) , " " , files ) ) {
2012-11-11 21:17:00 +00:00
ui - > hashBox - > addAttachments ( files , mDefaultExtraFileFlags /*, 0*/ ) ;
2012-01-17 20:36:36 +00:00
}
}
void ChatWidget : : addExtraPicture ( )
{
// select a picture file
QString file ;
if ( misc : : getOpenFileName ( window ( ) , RshareSettings : : LASTDIR_IMAGES , tr ( " Load Picture File " ) , " Pictures (*.png *.xpm *.jpg) " , file ) ) {
2012-09-18 22:59:23 +00:00
QString encodedImage ;
if ( RsHtml : : makeEmbeddedImage ( file , encodedImage , 640 * 480 ) ) {
QTextDocumentFragment fragment = QTextDocumentFragment : : fromHtml ( encodedImage ) ;
ui - > chatTextEdit - > textCursor ( ) . insertFragment ( fragment ) ;
}
2012-01-17 20:36:36 +00:00
}
}
void ChatWidget : : fileHashingFinished ( QList < HashedFile > hashedFiles )
{
std : : cerr < < " ChatWidget::fileHashingFinished() started. " < < std : : endl ;
QString message ;
QList < HashedFile > : : iterator it ;
for ( it = hashedFiles . begin ( ) ; it ! = hashedFiles . end ( ) ; + + it ) {
HashedFile & hashedFile = * it ;
QString ext = QFileInfo ( hashedFile . filename ) . suffix ( ) ;
RetroShareLink link ;
2012-11-11 21:17:00 +00:00
if ( mDefaultExtraFileFlags & RS_FILE_REQ_ANONYMOUS_ROUTING )
link . createFile ( hashedFile . filename , hashedFile . size , QString : : fromStdString ( hashedFile . hash ) ) ;
else
link . createExtraFile ( hashedFile . filename , hashedFile . size , QString : : fromStdString ( hashedFile . hash ) , QString : : fromStdString ( rsPeers - > getOwnId ( ) ) ) ;
2012-01-17 20:36:36 +00:00
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> " ;
}
}
# ifdef CHAT_DEBUG
std : : cerr < < " ChatWidget::fileHashingFinished message : " < < message . toStdString ( ) < < std : : endl ;
# endif
/* convert to real html document */
QTextBrowser textBrowser ;
textBrowser . setHtml ( message ) ;
std : : wstring msg = textBrowser . toHtml ( ) . toStdWString ( ) ;
if ( rsMsgs - > sendPrivateChat ( peerId , msg ) ) {
QDateTime currentTime = QDateTime : : currentDateTime ( ) ;
2012-01-18 00:32:15 +00:00
addChatMsg ( false , name , currentTime , currentTime , QString : : fromStdWString ( msg ) , TYPE_NORMAL ) ;
2012-01-17 20:36:36 +00:00
}
}
bool ChatWidget : : 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 ;
}
bool ChatWidget : : fileSaveAs ( )
{
QString fn ;
if ( misc : : getSaveFileName ( window ( ) , RshareSettings : : LASTDIR_HISTORY , tr ( " Save as... " ) , tr ( " Text File (*.txt );;All Files (*) " ) , fn ) ) {
setCurrentFileName ( fn ) ;
return fileSave ( ) ;
}
return false ;
}
void ChatWidget : : setCurrentFileName ( const QString & fileName )
{
this - > fileName = fileName ;
ui - > textBrowser - > document ( ) - > setModified ( false ) ;
setWindowModified ( false ) ;
}
void ChatWidget : : updateStatus ( const QString & peer_id , int status )
{
2012-01-28 15:11:58 +00:00
if ( isChatLobby ) {
// updateTitle is used
return ;
}
2012-01-17 20:36:36 +00:00
/* set font size for status */
if ( peer_id . toStdString ( ) = = peerId ) {
// the peers status has changed
2013-06-18 20:13:58 +00:00
QString peerName ;
2013-06-20 20:19:10 +00:00
uint32_t stts ;
2013-06-18 20:13:58 +00:00
std : : string pgp_id ;
2013-06-20 20:19:10 +00:00
if ( rsMsgs - > getDistantChatStatus ( peerId , stts , pgp_id ) )
2013-06-18 20:13:58 +00:00
peerName = QString : : fromUtf8 ( rsPeers - > getPeerName ( pgp_id ) . c_str ( ) ) ;
else
peerName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peerId ) . c_str ( ) ) ;
2012-01-18 00:32:15 +00:00
2012-02-23 23:30:53 +00:00
// is scrollbar at the end?
QScrollBar * scrollbar = ui - > textBrowser - > verticalScrollBar ( ) ;
bool atEnd = ( scrollbar - > value ( ) = = scrollbar - > maximum ( ) ) ;
2012-01-17 20:36:36 +00:00
switch ( status ) {
case RS_STATUS_OFFLINE :
2012-08-27 21:48:00 +00:00
ui - > infoFrame - > setVisible ( true ) ;
2012-10-11 10:28:24 +00:00
ui - > infoLabel - > setText ( peerName + " " + tr ( " appears to be Offline. " ) + " \n " + tr ( " Messages you send will be delivered after Friend is again Online " ) ) ;
2012-01-17 20:36:36 +00:00
break ;
case RS_STATUS_INACTIVE :
2012-08-27 21:48:00 +00:00
ui - > infoFrame - > setVisible ( true ) ;
ui - > infoLabel - > setText ( peerName + " " + tr ( " is Idle and may not reply " ) ) ;
2012-01-17 20:36:36 +00:00
break ;
case RS_STATUS_ONLINE :
2012-08-27 21:48:00 +00:00
ui - > infoFrame - > setVisible ( false ) ;
2012-01-17 20:36:36 +00:00
break ;
case RS_STATUS_AWAY :
2012-08-27 21:48:00 +00:00
ui - > infoLabel - > setText ( peerName + " " + tr ( " is Away and may not reply " ) ) ;
ui - > infoFrame - > setVisible ( true ) ;
2012-01-17 20:36:36 +00:00
break ;
case RS_STATUS_BUSY :
2012-08-27 21:48:00 +00:00
ui - > infoLabel - > setText ( peerName + " " + tr ( " is Busy and may not reply " ) ) ;
ui - > infoFrame - > setVisible ( true ) ;
2012-01-17 20:36:36 +00:00
break ;
}
QString statusString ( " <span style= \" font-size:11pt; font-weight:500; " " \" >%1</span> " ) ;
2012-01-28 15:11:58 +00:00
ui - > titleLabel - > setText ( peerName + " ( " + statusString . arg ( StatusDefs : : name ( status ) ) + " ) " ) ;
2012-01-17 20:36:36 +00:00
peerStatus = status ;
2012-02-23 23:30:53 +00:00
if ( atEnd ) {
// scroll to the end
scrollbar - > setValue ( scrollbar - > maximum ( ) ) ;
}
2012-01-17 20:36:36 +00:00
emit infoChanged ( this ) ;
2012-03-11 00:22:25 +00:00
emit statusChanged ( status ) ;
2012-01-17 20:36:36 +00:00
return ;
}
// ignore status change
}
2012-01-28 15:11:58 +00:00
void ChatWidget : : updateTitle ( )
{
if ( ! isChatLobby ) {
// updateStatus is used
return ;
}
2013-07-01 20:35:07 +00:00
ui - > titleLabel - > setText ( RsHtml : : plainText ( name ) + " @ " + RsHtml : : plainText ( title ) ) ;
2012-01-28 15:11:58 +00:00
}
2012-01-17 20:36:36 +00:00
void ChatWidget : : updatePeersCustomStateString ( const QString & peer_id , const QString & status_string )
{
std : : string stdPeerId = peer_id . toStdString ( ) ;
QString status_text ;
if ( stdPeerId = = peerId ) {
// the peers status string has changed
if ( status_string . isEmpty ( ) ) {
2012-08-27 21:48:00 +00:00
ui - > statusMessageLabel - > hide ( ) ;
2012-01-17 20:36:36 +00:00
} else {
2012-08-27 21:48:00 +00:00
ui - > statusMessageLabel - > show ( ) ;
2012-05-12 00:40:53 +00:00
status_text = RsHtml ( ) . formatText ( NULL , status_string , RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS ) ;
2012-08-27 21:48:00 +00:00
ui - > statusMessageLabel - > setText ( status_text ) ;
2012-01-17 20:36:36 +00:00
}
}
}
void ChatWidget : : updateStatusString ( const QString & statusMask , const QString & statusString )
{
ui - > statusLabel - > setText ( QString ( statusMask ) . arg ( tr ( statusString . toAscii ( ) ) ) ) ; // displays info for 5 secs.
ui - > typingpixmapLabel - > setPixmap ( QPixmap ( " :images/typing.png " ) ) ;
if ( statusString = = " is typing... " ) {
typing = true ;
emit infoChanged ( this ) ;
}
QTimer : : singleShot ( 5000 , this , SLOT ( resetStatusBar ( ) ) ) ;
}
2012-01-18 00:32:15 +00:00
void ChatWidget : : setName ( const QString & name )
{
this - > name = name ;
2012-01-28 15:11:58 +00:00
updateTitle ( ) ;
2012-01-18 00:32:15 +00:00
}
2012-01-17 20:36:36 +00:00
bool ChatWidget : : setStyle ( )
{
if ( style . showDialog ( window ( ) ) ) {
PeerSettings - > setStyle ( peerId , " PopupChatDialog " , style ) ;
return true ;
}
return false ;
}