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 <QDir>
# include <QFileDialog>
# 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"
2010-03-17 11:34:36 -04:00
# include <gui/RetroShareLink.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/rsmsgs.h>
# include <retroshare/rsfiles.h>
# include <retroshare/rsnotify.h>
2010-08-18 08:02:36 -04:00
# include <retroshare/rsstatus.h>
2010-08-06 05:40:23 -04:00
# include <retroshare/rsiface.h>
2010-05-11 16:02:52 -04:00
# include "gui/settings/rsharesettings.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-04-15 08:02:23 -04:00
2010-01-25 09:35:32 -05:00
# include "gui/feeds/AttachFileItem.h"
2010-06-17 13:39:32 -04:00
# include "gui/msgs/MessageComposer.h"
2010-01-20 17:02:43 -05:00
# include <time.h>
2009-01-30 14:52:47 -05:00
# define appDir QApplication::applicationDirPath()
2010-09-07 13:35:08 -04:00
# define IMAGE_WINDOW ": / images / rstray3.png"
# define IMAGE_WINDOW_TYPING ": / images / typing.png"
2009-01-30 14:52:47 -05:00
/* Define the format used for displaying the date and time */
# define DATETIME_FMT "MMM dd hh:mm:ss"
/*****
* # define CHAT_DEBUG 1
* * * * */
2010-08-18 08:02:36 -04:00
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 */
PopupChatDialog : : PopupChatDialog ( std : : string id , std : : string name ,
QWidget * parent , Qt : : WFlags flags )
: QMainWindow ( parent , flags ) , dialogId ( id ) , dialogName ( name ) ,
lastChatTime ( 0 ) , lastChatName ( " " )
{
/* Invoke Qt Designer generated QObject setup routine */
ui . setupUi ( this ) ;
2010-05-03 17:17:36 -04:00
2010-05-20 17:53:27 -04:00
Settings - > loadWidgetInformation ( this ) ;
2010-01-18 17:50:14 -05:00
this - > move ( qrand ( ) % 100 , qrand ( ) % 100 ) ; //avoid to stack multiple popup chat windows on the same position
2010-09-01 13:56:15 -04:00
m_bInsertOnVisible = true ;
2010-09-04 10:23:30 -04:00
2009-05-05 09:18:53 -04:00
last_status_send_time = 0 ;
2010-09-07 11:49:31 -04:00
style . setStyleFromSettings ( ChatStyle : : TYPE_PRIVATE ) ;
2010-09-04 10:23:30 -04:00
style . loadEmoticons ( ) ;
2010-09-03 12:46:47 -04:00
/* Hide or show the frames */
showAvatarFrame ( true ) ;
2010-08-23 15:09:16 -04:00
ui . infoframe - > setVisible ( false ) ;
2010-09-01 21:37:47 -04:00
ui . statusmessagelabel - > hide ( ) ;
2009-01-30 14:52:47 -05:00
connect ( ui . avatarFrameButton , SIGNAL ( toggled ( bool ) ) , this , SLOT ( showAvatarFrame ( bool ) ) ) ;
connect ( ui . actionAvatar , SIGNAL ( triggered ( ) ) , this , SLOT ( getAvatar ( ) ) ) ;
connect ( ui . sendButton , SIGNAL ( clicked ( ) ) , this , SLOT ( sendChat ( ) ) ) ;
2009-05-11 10:21:11 -04:00
connect ( ui . addFileButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraFile ( ) ) ) ;
2009-01-30 14:52:47 -05:00
connect ( ui . textboldButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textunderlineButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
connect ( ui . textitalicButton , SIGNAL ( clicked ( ) ) , this , SLOT ( setFont ( ) ) ) ;
2010-08-06 08:30:06 -04:00
connect ( ui . attachPictureButton , SIGNAL ( clicked ( ) ) , this , SLOT ( addExtraPicture ( ) ) ) ;
2009-01-30 14:52:47 -05:00
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 . styleButton , SIGNAL ( clicked ( ) ) , SLOT ( changeStyle ( ) ) ) ;
2010-04-27 18:08:38 -04:00
connect ( ui . actionSave_Chat_History , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSaveAs ( ) ) ) ;
2009-01-30 14:52:47 -05:00
2009-05-11 10:21:11 -04:00
connect ( ui . textBrowser , SIGNAL ( anchorClicked ( const QUrl & ) ) , SLOT ( anchorClicked ( const QUrl & ) ) ) ;
2010-08-20 14:45:44 -04:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerStatusChanged ( const QString & , int ) ) , this , SLOT ( updateStatus ( const QString & , int ) ) ) ;
2010-09-02 06:15:13 -04:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerHasNewCustomStateString ( const QString & , const QString & ) ) , this , SLOT ( updatePeersCustomStateString ( const QString & , const QString & ) ) ) ;
2010-08-20 14:45:44 -04:00
2010-09-04 10:23:30 -04:00
// hide until it works
ui . styleButton - > setVisible ( false ) ;
2010-03-17 11:34:36 -04:00
std : : cerr < < " Connecting custom context menu " < < std : : endl ;
ui . chattextEdit - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui . chattextEdit , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenu ( QPoint ) ) ) ;
2009-01-30 14:52:47 -05:00
// Create the status bar
2009-05-05 09:18:53 -04:00
resetStatusBar ( ) ;
2010-02-07 07:36:37 -05:00
//ui.textBrowser->setOpenExternalLinks ( false );
//ui.textBrowser->setOpenLinks ( false );
2009-01-30 14:52:47 -05:00
2010-08-18 08:02:36 -04:00
QString title = tr ( " RetroShare - " ) + QString : : fromStdString ( name ) ;
2009-01-30 14:52:47 -05:00
setWindowTitle ( title ) ;
2009-09-07 09:59:38 -04:00
2010-09-07 13:35:08 -04:00
setWindowIcon ( QIcon ( IMAGE_WINDOW ) ) ;
2009-01-30 14:52:47 -05:00
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 . styleButton - > setIcon ( QIcon ( QString ( " :/images/looknfeel.png " ) ) ) ;
ui . textboldButton - > setCheckable ( true ) ;
ui . textunderlineButton - > setCheckable ( true ) ;
ui . textitalicButton - > setCheckable ( true ) ;
2009-05-11 10:27:45 -04:00
setAcceptDrops ( true ) ;
ui . chattextEdit - > setAcceptDrops ( false ) ;
2009-01-30 14:52:47 -05:00
/*Disabled style Button when will switch chat style RetroShare will crash need to be fix */
//ui.styleButton->setEnabled(false);
2010-02-19 17:31:32 -05:00
QMenu * toolmenu = new QMenu ( ) ;
toolmenu - > addAction ( ui . actionClear_Chat ) ;
2010-04-27 18:08:38 -04:00
toolmenu - > addAction ( ui . actionSave_Chat_History ) ;
2010-05-03 17:17:36 -04:00
//toolmenu->addAction(ui.action_Disable_Emoticons);
2010-02-19 17:31:32 -05:00
ui . pushtoolsButton - > setMenu ( toolmenu ) ;
2009-09-07 09:59:38 -04:00
2009-01-30 14:52:47 -05:00
mCurrentColor = Qt : : black ;
mCurrentFont = QFont ( " Comic Sans MS " , 10 ) ;
colorChanged ( mCurrentColor ) ;
setFont ( ) ;
2010-03-17 11:34:36 -04:00
pasteLinkAct = new QAction ( QIcon ( " :/images/pasterslink.png " ) , tr ( " Paste retroshare Link " ) , this ) ;
connect ( pasteLinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( pasteLink ( ) ) ) ;
2009-01-30 14:52:47 -05:00
updateAvatar ( ) ;
updatePeerAvatar ( id ) ;
2010-09-01 21:37:47 -04:00
2010-08-20 14:45:44 -04:00
// load settings
2010-08-06 10:58:53 -04:00
processSettings ( true ) ;
2010-08-20 14:45:44 -04:00
// initialize first status
2010-08-30 16:14:58 -04:00
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 ) ;
StatusInfo ownStatusInfo ;
if ( rsStatus - > getOwnStatus ( ownStatusInfo ) ) {
updateStatus ( QString : : fromStdString ( ownStatusInfo . id ) , ownStatusInfo . status ) ;
}
2010-09-02 06:15:13 -04:00
// initialize first custom state string
QString customStateString = QString : : fromStdString ( rsMsgs - > getCustomStateString ( dialogId ) ) ;
updatePeersCustomStateString ( QString : : fromStdString ( dialogId ) , customStateString ) ;
2010-09-04 10:23:30 -04:00
ui . chattextEdit - > installEventFilter ( this ) ;
2010-08-06 10:58:53 -04:00
}
/** Destructor. */
PopupChatDialog : : ~ PopupChatDialog ( )
{
// save settings
processSettings ( false ) ;
}
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-09-01 13:56:15 -04:00
/*static*/ PopupChatDialog * PopupChatDialog : : getPrivateChat ( std : : string id , uint chatflags )
2010-06-17 13:39:32 -04:00
{
2010-09-01 13:56:15 -04:00
/* see if it exists already */
PopupChatDialog * popupchatdialog = NULL ;
bool show = false ;
2010-06-17 13:39:32 -04:00
2010-09-01 13:56:15 -04:00
if ( chatflags & RS_CHAT_REOPEN )
{
2010-06-17 13:39:32 -04:00
show = true ;
2010-09-01 13:56:15 -04:00
# ifdef PEERS_DEBUG
2010-06-17 13:39:32 -04:00
std : : cerr < < " reopen flag so: enable SHOW popupchatdialog() " < < std : : endl ;
2010-09-01 13:56:15 -04:00
# endif
}
2010-06-17 13:39:32 -04:00
2010-09-01 13:56:15 -04:00
std : : map < std : : string , PopupChatDialog * > : : iterator it ;
if ( chatDialogs . end ( ) ! = ( it = chatDialogs . find ( id ) ) )
{
2010-06-17 13:39:32 -04:00
/* exists already */
popupchatdialog = it - > second ;
2010-09-01 13:56:15 -04:00
}
else
{
2010-06-17 13:39:32 -04:00
if ( chatflags & RS_CHAT_OPEN_NEW )
{
2010-09-01 13:56:15 -04:00
RsPeerDetails sslDetails ;
if ( rsPeers - > getPeerDetails ( id , sslDetails ) ) {
popupchatdialog = new PopupChatDialog ( id , sslDetails . name + " - " + sslDetails . location ) ;
chatDialogs [ id ] = popupchatdialog ;
# ifdef PEERS_DEBUG
2010-06-17 13:39:32 -04:00
std : : cerr < < " new chat so: enable SHOW popupchatdialog() " < < std : : endl ;
2010-09-01 13:56:15 -04:00
# endif
2010-06-17 13:39:32 -04:00
show = true ;
2010-09-01 13:56:15 -04:00
}
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-09-01 13:56:15 -04:00
if ( show & & popupchatdialog )
{
# ifdef PEERS_DEBUG
2010-06-17 13:39:32 -04:00
std : : cerr < < " SHOWING popupchatdialog() " < < std : : endl ;
2010-09-01 13:56:15 -04:00
# endif
2010-06-17 13:39:32 -04:00
if ( popupchatdialog - > isVisible ( ) = = false ) {
if ( chatflags & RS_CHAT_FOCUS ) {
popupchatdialog - > show ( ) ;
} else {
popupchatdialog - > showMinimized ( ) ;
}
}
2010-09-01 13:56:15 -04:00
}
/* now only do these if the window is visible */
if ( popupchatdialog & & popupchatdialog - > isVisible ( ) )
{
if ( chatflags & RS_CHAT_FOCUS )
{
# ifdef PEERS_DEBUG
std : : cerr < < " focus chat flag so: GETFOCUS popupchatdialog() " < < std : : endl ;
# endif
popupchatdialog - > getfocus ( ) ;
}
else
{
# ifdef PEERS_DEBUG
std : : cerr < < " no focus chat flag so: FLASH popupchatdialog() " < < std : : endl ;
# endif
popupchatdialog - > flash ( ) ;
}
}
else
{
# ifdef PEERS_DEBUG
2010-06-17 13:39:32 -04:00
std : : cerr < < " not visible ... so leave popupchatdialog() " < < std : : endl ;
2010-09-01 13:56:15 -04:00
# endif
}
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 ( )
{
std : : map < std : : string , PopupChatDialog * > : : iterator it ;
for ( it = chatDialogs . begin ( ) ; it ! = chatDialogs . end ( ) ; it + + ) {
if ( it - > second ) {
delete ( it - > second ) ;
}
}
chatDialogs . clear ( ) ;
}
2010-09-01 13:56:15 -04:00
/*static*/ void PopupChatDialog : : privateChatChanged ( )
{
std : : list < std : : string > ids ;
if ( ! rsMsgs - > getPrivateChatQueueIds ( ids ) ) {
# ifdef PEERS_DEBUG
std : : cerr < < " no chat available. " < < std : : endl ;
# endif
return ;
}
uint chatflags = Settings - > getChatFlags ( ) ;
std : : list < std : : string > : : iterator id ;
for ( id = ids . begin ( ) ; id ! = ids . end ( ) ; id + + ) {
PopupChatDialog * pcd = getPrivateChat ( * id , chatflags ) ;
if ( pcd ) {
pcd - > insertChatMsgs ( ) ;
}
}
}
2010-06-17 13:39:32 -04:00
void PopupChatDialog : : chatFriend ( std : : string id )
{
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
bool oneLocationConnected = false ;
RsPeerDetails detail ;
if ( ! rsPeers - > getPeerDetails ( id , detail ) ) {
return ;
}
2010-08-06 08:30:06 -04:00
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 ;
rsPeers - > getSSLChildListOfGPGId ( detail . gpg_id , sslIds ) ;
for ( std : : list < std : : string > : : iterator it = sslIds . begin ( ) ; it ! = sslIds . end ( ) ; it + + ) {
RsPeerDetails sslDetails ;
if ( rsPeers - > getPeerDetails ( * it , sslDetails ) ) {
if ( sslDetails . state & RS_PEER_STATE_CONNECTED ) {
oneLocationConnected = true ;
2010-09-01 13:56:15 -04:00
getPrivateChat ( * it , RS_CHAT_OPEN_NEW | RS_CHAT_REOPEN | RS_CHAT_FOCUS ) ;
2010-06-17 13:39:32 -04:00
}
}
}
} else {
if ( detail . state & RS_PEER_STATE_CONNECTED ) {
oneLocationConnected = true ;
2010-09-01 13:56:15 -04:00
getPrivateChat ( id , RS_CHAT_OPEN_NEW | RS_CHAT_REOPEN | RS_CHAT_FOCUS ) ;
2010-06-17 13:39:32 -04:00
}
}
if ( ! oneLocationConnected ) {
/* info dialog */
if ( ( QMessageBox : : question ( NULL , tr ( " Friend Not Online " ) , tr ( " Your Friend is offline \n Do you want to send them a Message instead " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes ) {
MessageComposer : : msgFriend ( id ) ;
}
}
}
/*static*/ void PopupChatDialog : : updateAllAvatars ( )
{
for ( std : : map < std : : string , PopupChatDialog * > : : const_iterator it ( chatDialogs . begin ( ) ) ; it ! = chatDialogs . end ( ) ; + + it )
it - > second - > updateAvatar ( ) ;
}
2010-03-17 11:34:36 -04:00
void PopupChatDialog : : pasteLink ( )
{
std : : cerr < < " In paste link " < < std : : endl ;
ui . chattextEdit - > insertHtml ( RSLinkClipboard : : toHtml ( ) ) ;
}
void PopupChatDialog : : contextMenu ( QPoint point )
{
std : : cerr < < " In context menu " < < std : : endl ;
if ( RSLinkClipboard : : empty ( ) )
return ;
QMenu contextMnu ( this ) ;
contextMnu . addAction ( pasteLinkAct ) ;
2010-05-14 16:55:44 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2010-03-17 11:34:36 -04:00
}
2009-05-05 09:18:53 -04:00
void PopupChatDialog : : resetStatusBar ( )
{
2010-09-06 16:54:48 -04:00
ui . statusLabel - > clear ( ) ;
ui . typingpixmapLabel - > clear ( ) ;
2010-09-07 13:35:08 -04:00
setWindowIcon ( QIcon ( IMAGE_WINDOW ) ) ;
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
}
// 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
{
2010-08-30 14:33:19 -04:00
QString status = QString : : fromStdString ( rsPeers - > getPeerName ( peer_id . toStdString ( ) ) ) + " " + tr ( status_string . toAscii ( ) ) ;
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... " ) {
setWindowIcon ( QIcon ( IMAGE_WINDOW_TYPING ) ) ;
}
2010-08-30 14:33:19 -04:00
QTimer : : singleShot ( 5000 , this , SLOT ( resetStatusBar ( ) ) ) ;
2009-05-05 09:18:53 -04:00
}
2009-01-30 14:52:47 -05:00
/**
Overloads the default show ( ) slot so we can set opacity */
void PopupChatDialog : : show ( )
{
if ( ! this - > isVisible ( ) ) {
QMainWindow : : show ( ) ;
} else {
//QMainWindow::activateWindow();
//setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
//QMainWindow::raise();
}
}
void PopupChatDialog : : getfocus ( )
{
QMainWindow : : activateWindow ( ) ;
setWindowState ( ( windowState ( ) & ( ~ Qt : : WindowMinimized ) ) | Qt : : WindowActive ) ;
QMainWindow : : raise ( ) ;
}
void PopupChatDialog : : flash ( )
{
if ( ! this - > isVisible ( ) ) {
//QMainWindow::show();
} else {
// Want to reduce the interference on other applications.
//QMainWindow::activateWindow();
//setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
//QMainWindow::raise();
}
}
2010-09-01 13:56:15 -04:00
void PopupChatDialog : : showEvent ( QShowEvent * event )
{
if ( m_bInsertOnVisible ) {
insertChatMsgs ( ) ;
}
}
2009-01-30 14:52:47 -05:00
void PopupChatDialog : : closeEvent ( QCloseEvent * event )
{
2010-05-20 17:53:27 -04:00
Settings - > saveWidgetInformation ( this ) ;
2009-01-30 14:52:47 -05:00
hide ( ) ;
event - > ignore ( ) ;
}
void PopupChatDialog : : updateChat ( )
{
/* get chat off queue */
/* write it out */
}
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
if ( isVisible ( ) = = false ) {
m_bInsertOnVisible = true ;
return ;
}
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
m_bInsertOnVisible = false ;
std : : list < ChatInfo > newchat ;
if ( ! rsMsgs - > getPrivateChatQueue ( dialogId , newchat ) )
{
# 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 ;
for ( it = newchat . begin ( ) ; it ! = newchat . end ( ) ; it + + ) {
/* are they public? */
if ( ( it - > chatflags & RS_CHAT_PRIVATE ) = = 0 ) {
/* this should not happen */
continue ;
}
2010-09-04 10:23:30 -04:00
addChatMsg ( it - > rsid , it - > sendTime , it - > msg ) ;
2010-09-01 13:56:15 -04:00
}
playsound ( ) ;
QApplication : : alert ( this ) ;
}
2010-09-04 10:23:30 -04:00
void PopupChatDialog : : addChatMsg ( std : : string & id , uint sendTime , std : : wstring & msg )
2010-09-01 13:56:15 -04:00
{
2010-09-04 10:23:30 -04:00
QDateTime timestamp = QDateTime : : fromTime_t ( sendTime ) ;
2010-09-01 13:56:15 -04:00
QString name = QString : : fromStdString ( rsPeers - > getPeerName ( id ) ) ;
QString message = QString : : fromStdWString ( msg ) ;
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-09-04 10:23:30 -04:00
ChatStyle : : enumFormatMessage type = ( id = = rsPeers - > getOwnId ( ) ) ? ChatStyle : : FORMATMSG_INCOMING : ChatStyle : : FORMATMSG_OUTGOING ;
2010-09-01 13:56:15 -04:00
2010-09-04 10:23:30 -04:00
QString formatMsg = style . formatMessage ( type , name , timestamp , message , formatFlag ) ;
2010-09-01 13:56:15 -04:00
2010-09-04 10:23:30 -04:00
ui . textBrowser - > append ( formatMsg ) ;
2010-09-01 13:56:15 -04: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
return QMainWindow : : 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 ;
}
std : : wstring msg = chatWidget - > toHtml ( ) . toStdWString ( ) ;
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-01 13:56:15 -04:00
std : : cout < < " PopupChatDialog:sendChat " < < styleHtm . toStdString ( ) < < std : : endl ;
2009-01-30 14:52:47 -05:00
# endif
2010-09-04 10:23:30 -04:00
addChatMsg ( ownId , time ( NULL ) , msg ) ;
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
rsMsgs - > sendPrivateChat ( dialogId , msg ) ;
chatWidget - > clear ( ) ;
setFont ( ) ;
2009-01-30 14:52:47 -05:00
2010-09-01 13:56:15 -04:00
/* redraw send list */
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 " ) ) ;
ui . avatarFrameButton - > setIcon ( QIcon ( tr ( " :images/hide_toolbox_frame.png " ) ) ) ;
} else {
ui . avatarframe - > setVisible ( false ) ;
ui . avatarFrameButton - > setChecked ( false ) ;
ui . avatarFrameButton - > setToolTip ( tr ( " Show Avatar " ) ) ;
ui . avatarFrameButton - > setIcon ( QIcon ( tr ( " :images/show_toolbox_frame.png " ) ) ) ;
}
}
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 ( )
{
bool ok ;
QRgb color = QColorDialog : : getRgba ( ui . chattextEdit - > textColor ( ) . rgba ( ) , & ok , this ) ;
if ( ok ) {
mCurrentColor = QColor ( color ) ;
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 ;
mCurrentFont = QFontDialog : : getFont ( & ok , mCurrentFont , this ) ;
setFont ( ) ;
}
void PopupChatDialog : : setFont ( )
{
2010-08-06 08:30:06 -04:00
// mCurrentFont.setBold(ui.textboldButton->isChecked());
bool flag ;
flag = ui . textboldButton - > isChecked ( ) ;
mCurrentFont . setBold ( flag ) ;
2009-01-30 14:52:47 -05:00
mCurrentFont . setUnderline ( ui . textunderlineButton - > isChecked ( ) ) ;
mCurrentFont . setItalic ( ui . textitalicButton - > isChecked ( ) ) ;
ui . chattextEdit - > setFont ( mCurrentFont ) ;
ui . chattextEdit - > setTextColor ( mCurrentColor ) ;
ui . chattextEdit - > setFocus ( ) ;
}
2009-03-12 13:57:30 -04:00
//============================================================================
2009-01-30 14:52:47 -05:00
void PopupChatDialog : : smileyWidget ( )
{
2010-09-04 10:23:30 -04:00
style . showSmileyWidget ( this , ui . emoteiconButton , SLOT ( addSmiley ( ) ) ) ;
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
//============================================================================
2010-02-19 17:31:32 -05:00
void PopupChatDialog : : on_actionClear_Chat_triggered ( )
{
ui . textBrowser - > clear ( ) ;
}
2009-01-30 14:52:47 -05:00
void PopupChatDialog : : changeStyle ( )
{
2010-09-04 10:23:30 -04:00
// QString newStyle = QFileDialog::getOpenFileName(this, tr("Open Style"),
// appDir + "/style/chat/",
// tr("Styles (*.htm)"));
// if(!newStyle.isEmpty())
// {
// QString wholeChat;
// styleHtm = newStyle;
//
//
// for(int i = 0; i < history.size(); i+=4)
// {
// QString formatMsg = loadEmptyStyle();
// wholeChat += formatMsg.replace("%timestamp%", history.at(i+1))
// .replace("%name%", history.at(i+2))
// .replace("%message%", history.at(i+3)) + "\n";
// }
// ui.textBrowser->setHtml(wholeChat);
// }
// QTextCursor cursor = ui.textBrowser->textCursor();
// cursor.movePosition(QTextCursor::End);
// ui.textBrowser->setTextCursor(cursor);
2009-01-30 14:52:47 -05:00
}
void PopupChatDialog : : updatePeerAvatar ( const std : : string & peer_id )
{
2010-02-10 05:56:54 -05:00
# ifdef CHAT_DEBUG
std : : cerr < < " popupchatDialog::updatePeerAvatar() updating avatar for peer " < < peer_id < < std : : endl ;
std : : cerr < < " Requesting avatar image for peer " < < peer_id < < std : : endl ;
# endif
2009-09-30 16:53:18 -04:00
2009-01-30 14:52:47 -05:00
unsigned char * data = NULL ;
int size = 0 ;
rsMsgs - > getAvatarData ( peer_id , data , size ) ;
2010-02-10 05:56:54 -05:00
# ifdef CHAT_DEBUG
std : : cerr < < " Image size = " < < size < < std : : endl ;
# endif
2009-01-30 14:52:47 -05:00
2010-02-10 05:56:54 -05:00
if ( size = = 0 ) {
# ifdef CHAT_DEBUG
2009-01-30 14:52:47 -05:00
std : : cerr < < " Got no image " < < std : : endl ;
2010-02-10 05:56:54 -05:00
# endif
2010-08-30 12:06:06 -04:00
ui . avatarlabel - > setPixmap ( QPixmap ( " :/images/no_avatar_background.png " ) ) ;
2009-01-30 14:52:47 -05:00
return ;
}
// set the image
QPixmap pix ;
2009-09-30 16:53:18 -04:00
pix . loadFromData ( data , size , " PNG " ) ;
2009-01-30 14:52:47 -05:00
ui . avatarlabel - > setPixmap ( pix ) ; // writes image into ba in JPG format
delete [ ] data ;
}
void PopupChatDialog : : updateAvatar ( )
{
unsigned char * data = NULL ;
int size = 0 ;
rsMsgs - > getOwnAvatarData ( data , size ) ;
2010-02-10 05:56:54 -05:00
# ifdef CHAT_DEBUG
2009-01-30 14:52:47 -05:00
std : : cerr < < " Image size = " < < size < < std : : endl ;
2010-02-10 05:56:54 -05:00
# endif
2009-01-30 14:52:47 -05:00
2010-02-10 05:56:54 -05:00
if ( size = = 0 ) {
# ifdef CHAT_DEBUG
std : : cerr < < " Got no image " < < std : : endl ;
# endif
}
2009-01-30 14:52:47 -05:00
// set the image
QPixmap pix ;
2009-09-07 09:59:38 -04:00
pix . loadFromData ( data , size , " PNG " ) ;
ui . myavatarlabel - > setPixmap ( pix ) ; // writes image into ba in PNGformat
2009-01-30 14:52:47 -05:00
delete [ ] data ;
}
void PopupChatDialog : : getAvatar ( )
{
QString fileName = QFileDialog : : getOpenFileName ( this , " Load File " , QDir : : homePath ( ) , " Pictures (*.png *.xpm *.jpg) " ) ;
2009-03-01 10:18:34 -05:00
2009-01-30 14:52:47 -05:00
if ( ! fileName . isEmpty ( ) )
{
2010-08-30 11:43:07 -04:00
picture = QPixmap ( fileName ) . scaled ( 96 , 96 , Qt : : IgnoreAspectRatio , Qt : : SmoothTransformation ) ;
2009-01-30 14:52:47 -05:00
std : : cerr < < " Sending avatar image down the pipe " < < std : : endl ;
// send avatar down the pipe for other peers to get it.
QByteArray ba ;
QBuffer buffer ( & ba ) ;
buffer . open ( QIODevice : : WriteOnly ) ;
2009-09-07 09:59:38 -04:00
picture . save ( & buffer , " PNG " ) ; // writes image into ba in PNG format
2009-01-30 14:52:47 -05:00
std : : cerr < < " Image size = " < < ba . size ( ) < < std : : endl ;
rsMsgs - > setOwnAvatarData ( ( unsigned char * ) ( ba . data ( ) ) , ba . size ( ) ) ; // last char 0 included.
updateAvatar ( ) ;
}
}
2009-05-11 10:21:11 -04:00
void PopupChatDialog : : addExtraFile ( )
{
// select a file
QString qfile = QFileDialog : : getOpenFileName ( this , tr ( " Add Extra File " ) , " " , " " , 0 ,
QFileDialog : : DontResolveSymlinks ) ;
std : : string filePath = qfile . toStdString ( ) ;
if ( filePath ! = " " )
{
2010-08-06 08:30:06 -04:00
PopupChatDialog : : addAttachment ( filePath , 0 ) ;
2009-05-11 10:27:45 -04:00
}
}
2010-08-06 08:30:06 -04:00
void PopupChatDialog : : addExtraPicture ( )
{
// select a picture file
QString qfile = QFileDialog : : getOpenFileName ( this , " Load Picture File " , QDir : : homePath ( ) , " Pictures (*.png *.xpm *.jpg) " , 0 ,
QFileDialog : : DontResolveSymlinks ) ;
std : : string filePath = qfile . toStdString ( ) ;
if ( filePath ! = " " )
{
PopupChatDialog : : addAttachment ( filePath , 1 ) ; //picture
}
}
void PopupChatDialog : : addAttachment ( std : : string filePath , int flag )
2010-03-17 11:34:36 -04:00
{
2010-01-25 09:35:32 -05:00
/* add a AttachFileItem to the attachment section */
2009-05-11 10:21:11 -04:00
std : : cerr < < " PopupChatDialog::addExtraFile() hashing file. " ;
std : : cerr < < std : : endl ;
/* add widget in for new destination */
2010-08-06 08:30:06 -04:00
AttachFileItem * file = new AttachFileItem ( filePath ) ;
2009-05-11 10:21:11 -04:00
//file->
2010-08-06 08:30:06 -04:00
if ( flag = = 1 )
file - > setPicFlag ( 1 ) ;
2009-05-11 10:21:11 -04:00
ui . vboxLayout - > addWidget ( file , 1 , 0 ) ;
//when the file is local or is finished hashing, call the fileHashingFinished method to send a chat message
2010-01-25 09:35:32 -05:00
if ( file - > getState ( ) = = AFI_STATE_LOCAL ) {
2009-05-11 10:21:11 -04:00
fileHashingFinished ( file ) ;
} else {
2010-01-25 09:35:32 -05:00
QObject : : connect ( file , SIGNAL ( fileFinished ( AttachFileItem * ) ) , SLOT ( fileHashingFinished ( AttachFileItem * ) ) ) ;
2009-05-11 10:21:11 -04:00
}
}
2010-08-06 08:30:06 -04:00
2010-03-17 11:34:36 -04:00
void PopupChatDialog : : fileHashingFinished ( AttachFileItem * file )
{
2010-09-01 13:56:15 -04:00
std : : cerr < < " PopupChatDialog::fileHashingFinished() started. " ;
std : : cerr < < std : : endl ;
2009-05-11 10:21:11 -04:00
2010-09-01 13:56:15 -04:00
//check that the file is ok tos end
if ( file - > getState ( ) = = AFI_STATE_ERROR ) {
# ifdef CHAT_DEBUG
std : : cerr < < " PopupChatDialog::fileHashingFinished error file is not hashed. " ;
# endif
return ;
}
2009-05-14 11:54:38 -04:00
2010-09-01 13:56:15 -04:00
std : : string ownId ;
2009-05-11 10:21:11 -04:00
2010-09-01 13:56:15 -04:00
{
rsiface - > lockData ( ) ; /* Lock Interface */
const RsConfig & conf = rsiface - > getConfig ( ) ;
2009-05-11 10:21:11 -04:00
2010-09-01 13:56:15 -04:00
ownId = conf . ownId ;
rsiface - > unlockData ( ) ; /* Unlock Interface */
}
QString message ;
2010-09-02 13:26:29 -04:00
QString ext = QFileInfo ( QString : : fromStdString ( file - > FileName ( ) ) ) . suffix ( ) ;
2009-05-11 10:21:11 -04:00
2010-08-06 08:30:06 -04:00
if ( file - > getPicFlag ( ) = = 1 ) {
2010-09-01 13:56:15 -04:00
message + = " <img src= \" file:/// " ;
message + = file - > FilePath ( ) . c_str ( ) ;
message + = " \" width= \" 100 \" height= \" 100 \" > " ;
2010-08-06 08:30:06 -04:00
message + = " <br> " ;
2010-09-02 13:26:29 -04:00
}
else if ( ext = = " ogg " | | ext = = " mp3 " | | ext = = " MP3 " | | ext = = " mp1 " | | ext = = " mp2 " | | ext = = " wav " | | ext = = " wma " )
{
message + = " <img src= \" :/images/audio-x-monkey.png " ;
message + = " \" width= \" 48 \" height= \" 48 \" > " ;
message + = " <br> " ;
}
else if ( ext = = " avi " | | ext = = " AVI " | | ext = = " mpg " | | ext = = " mpeg " | | ext = = " wmv " | | ext = = " ogm "
| | ext = = " mkv " | | ext = = " mp4 " | | ext = = " flv " | | ext = = " mov "
| | ext = = " vob " | | ext = = " qt " | | ext = = " rm " | | ext = = " 3gp " )
{
message + = " <img src= \" :/images/video-x-generic.png " ;
message + = " \" width= \" 48 \" height= \" 48 \" > " ;
message + = " <br> " ;
}
else if ( ext = = " tar " | | ext = = " bz2 " | | ext = = " zip " | | ext = = " gz " | | ext = = " 7z "
| | ext = = " rar " | | ext = = " rpm " | | ext = = " deb " )
{
message + = " <img src= \" :/images/application-x-rar.png " ;
message + = " \" width= \" 48 \" height= \" 48 \" > " ;
message + = " <br> " ;
}
2009-05-11 10:21:11 -04:00
2010-08-06 11:31:30 -04:00
message + = RetroShareLink ( QString : : fromStdString ( file - > FileName ( ) ) , file - > FileSize ( ) , QString : : fromStdString ( file - > FileHash ( ) ) ) . toHtmlSize ( ) ;
2010-03-17 11:34:36 -04:00
2009-05-11 10:21:11 -04:00
# ifdef CHAT_DEBUG
2010-09-01 13:56:15 -04:00
std : : cerr < < " PopupChatDialog::anchorClicked message : " < < message . toStdString ( ) < < std : : endl ;
2009-05-11 10:21:11 -04:00
# endif
2010-09-01 13:56:15 -04:00
std : : wstring msg = message . toStdWString ( ) ;
2010-08-06 08:30:06 -04:00
2010-09-04 10:23:30 -04:00
addChatMsg ( ownId , time ( NULL ) , msg ) ;
2009-05-11 10:21:11 -04:00
2010-09-01 13:56:15 -04:00
rsMsgs - > sendPrivateChat ( dialogId , msg ) ;
2009-05-11 10:21:11 -04:00
}
2010-03-17 11:34:36 -04:00
void PopupChatDialog : : anchorClicked ( const QUrl & link )
{
2010-01-16 10:42:26 -05:00
# ifdef CHAT_DEBUG
std : : cerr < < " PopupChatDialog::anchorClicked link.scheme() : " < < link . scheme ( ) . toStdString ( ) < < std : : endl ;
# endif
2010-03-17 11:34:36 -04:00
2010-07-15 07:25:34 -04:00
std : : list < std : : string > srcIds ;
srcIds . push_back ( dialogId ) ;
RetroShareLink : : processUrl ( link , & srcIds , RSLINK_PROCESS_NOTIFY_ALL ) ;
2009-05-11 10:21:11 -04:00
}
2009-05-11 10:27:45 -04:00
void PopupChatDialog : : dropEvent ( QDropEvent * event )
{
if ( ! ( Qt : : CopyAction & event - > possibleActions ( ) ) )
{
std : : cerr < < " PopupChatDialog::dropEvent() Rejecting uncopyable DropAction " ;
std : : cerr < < std : : endl ;
/* can't do it */
return ;
}
std : : cerr < < " PopupChatDialog::dropEvent() Formats " ;
std : : cerr < < std : : endl ;
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; it + + )
{
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasUrls ( ) )
{
2009-05-11 10:35:50 -04:00
std : : cerr < < " PopupChatDialog::dropEvent() Urls: " ;
2009-05-11 10:27:45 -04:00
std : : cerr < < std : : endl ;
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
QList < QUrl > : : iterator uit ;
for ( uit = urls . begin ( ) ; uit ! = urls . end ( ) ; uit + + )
{
std : : string localpath = uit - > toLocalFile ( ) . toStdString ( ) ;
std : : cerr < < " Whole URL: " < < uit - > toString ( ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
std : : cerr < < " or As Local File: " < < localpath ;
std : : cerr < < std : : endl ;
if ( localpath . size ( ) > 0 )
{
2009-05-11 10:35:50 -04:00
struct stat buf ;
//Check that the file does exist and is not a directory
if ( ( - 1 = = stat ( localpath . c_str ( ) , & buf ) ) ) {
std : : cerr < < " PopupChatDialog::dropEvent() file does not exists. " < < std : : endl ;
2009-05-14 11:54:38 -04:00
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " File not found or file name not accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
2009-05-11 10:35:50 -04:00
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
} else if ( S_ISDIR ( buf . st_mode ) ) {
std : : cerr < < " PopupChatDialog::dropEvent() directory not accepted. " < < std : : endl ;
QMessageBox mb ( tr ( " Drop file error. " ) , tr ( " Directory can't be dropped, only files are accepted. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
} else {
2010-08-06 08:30:06 -04:00
PopupChatDialog : : addAttachment ( localpath , false ) ;
2009-05-11 10:35:50 -04:00
}
2009-05-11 10:27:45 -04:00
}
}
}
event - > setDropAction ( Qt : : CopyAction ) ;
event - > accept ( ) ;
}
void PopupChatDialog : : dragEnterEvent ( QDragEnterEvent * event )
{
/* print out mimeType */
std : : cerr < < " PopupChatDialog::dragEnterEvent() Formats " ;
std : : cerr < < std : : endl ;
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
QStringList : : iterator it ;
for ( it = formats . begin ( ) ; it ! = formats . end ( ) ; it + + )
{
std : : cerr < < " Format: " < < ( * it ) . toStdString ( ) ;
std : : cerr < < std : : endl ;
}
if ( event - > mimeData ( ) - > hasUrls ( ) )
{
std : : cerr < < " PopupChatDialog::dragEnterEvent() Accepting Urls " ;
std : : cerr < < std : : endl ;
event - > acceptProposedAction ( ) ;
}
else
{
std : : cerr < < " PopupChatDialog::dragEnterEvent() No Urls " ;
std : : cerr < < std : : endl ;
}
}
2010-03-04 09:15:30 -05: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 ( )
{
QString fn = QFileDialog : : getSaveFileName ( this , tr ( " Save as... " ) ,
QString ( ) , tr ( " Text File (*.txt );;All Files (*) " ) ) ;
if ( fn . isEmpty ( ) )
return false ;
setCurrentFileName ( fn ) ;
return fileSave ( ) ;
}
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-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 */
QString statusString ( " <span style= \" font-size:11pt; font-weight:500; " " \" >%1</span> " ) ;
2010-08-30 16:14:58 -04:00
if ( stdPeerId = = dialogId ) {
// the peers status has changed
switch ( status ) {
case RS_STATUS_OFFLINE :
ui . avatarlabel - > setStyleSheet ( " QLabel#avatarlabel{ border-image:url(:/images/avatarstatus_bg_offline.png); } " ) ;
ui . avatarlabel - > setEnabled ( false ) ;
ui . infoframe - > setVisible ( true ) ;
ui . infolabel - > setText ( QString : : fromStdString ( dialogName ) + " " + tr ( " apears to be Offline. " ) + " \n " + tr ( " Messages you send will be lost and not delivered, rs-Mail this contact instead. " ) ) ;
2010-09-03 12:57:53 -04:00
ui . friendnamelabel - > setText ( QString : : fromStdString ( dialogName ) + " " + statusString . arg ( tr ( " (Offline) " ) ) ) ;
2010-08-30 16:14:58 -04:00
break ;
case RS_STATUS_INACTIVE :
ui . avatarlabel - > setStyleSheet ( " QLabel#avatarlabel{ border-image:url(:/images/avatarstatus_bg_away.png); } " ) ;
ui . avatarlabel - > setEnabled ( true ) ;
ui . infoframe - > setVisible ( true ) ;
ui . infolabel - > setText ( QString : : fromStdString ( dialogName ) + " " + tr ( " is Idle and may not reply " ) ) ;
2010-09-03 12:57:53 -04:00
ui . friendnamelabel - > setText ( QString : : fromStdString ( dialogName ) + " " + statusString . arg ( tr ( " (Idle) " ) ) ) ;
2010-08-30 16:14:58 -04:00
break ;
case RS_STATUS_ONLINE :
ui . avatarlabel - > setStyleSheet ( " QLabel#avatarlabel{ border-image:url(:/images/avatarstatus_bg_online.png); } " ) ;
ui . avatarlabel - > setEnabled ( true ) ;
ui . infoframe - > setVisible ( false ) ;
2010-09-03 12:57:53 -04:00
ui . friendnamelabel - > setText ( QString : : fromStdString ( dialogName ) + " " + statusString . arg ( tr ( " (Online) " ) ) ) ;
2010-08-30 16:14:58 -04:00
break ;
case RS_STATUS_AWAY :
ui . avatarlabel - > setStyleSheet ( " QLabel#avatarlabel{ border-image:url(:/images/avatarstatus_bg_away.png); } " ) ;
ui . avatarlabel - > setEnabled ( true ) ;
ui . infolabel - > setText ( QString : : fromStdString ( dialogName ) + " " + tr ( " is Away and may not reply " ) ) ;
ui . infoframe - > setVisible ( true ) ;
2010-09-03 12:57:53 -04:00
ui . friendnamelabel - > setText ( QString : : fromStdString ( dialogName ) + " " + statusString . arg ( tr ( " (Away) " ) ) ) ;
2010-08-30 16:14:58 -04:00
break ;
case RS_STATUS_BUSY :
ui . avatarlabel - > setStyleSheet ( " QLabel#avatarlabel{ border-image:url(:/images/avatarstatus_bg_busy.png); } " ) ;
ui . avatarlabel - > setEnabled ( true ) ;
ui . infolabel - > setText ( QString : : fromStdString ( dialogName ) + " " + tr ( " is Busy and may not reply " ) ) ;
ui . infoframe - > setVisible ( true ) ;
2010-09-03 12:57:53 -04:00
ui . friendnamelabel - > setText ( QString : : fromStdString ( dialogName ) + " " + statusString . arg ( tr ( " (Busy) " ) ) ) ;
2010-08-30 16:14:58 -04:00
break ;
}
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
if ( stdPeerId = = rsPeers - > getOwnId ( ) ) {
// my status has changed
2010-08-30 17:41:19 -04:00
switch ( status ) {
case RS_STATUS_OFFLINE :
ui . myavatarlabel - > setStyleSheet ( " QLabel#myavatarlabel{border-image:url(:/images/avatarstatus_bg_offline.png); } " ) ;
break ;
case RS_STATUS_INACTIVE :
ui . myavatarlabel - > setStyleSheet ( " QLabel#myavatarlabel{border-image:url(:/images/avatarstatus_bg_away.png); } " ) ;
break ;
case RS_STATUS_ONLINE :
ui . myavatarlabel - > setStyleSheet ( " QLabel#myavatarlabel{border-image:url(:/images/avatarstatus_bg_online.png); } " ) ;
break ;
case RS_STATUS_AWAY :
ui . myavatarlabel - > setStyleSheet ( " QLabel#myavatarlabel{border-image:url(:/images/avatarstatus_bg_away.png); } " ) ;
break ;
case RS_STATUS_BUSY :
ui . myavatarlabel - > setStyleSheet ( " QLabel#myavatarlabel{border-image:url(:/images/avatarstatus_bg_busy.png); } " ) ;
break ;
}
2010-08-30 16:14:58 -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 ( ) ;
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 ( ) ;
2010-09-02 06:15:13 -04:00
ui . statusmessagelabel - > setText ( status_string ) ;
2010-09-01 21:37:47 -04:00
}
}
}
2010-09-02 06:15:13 -04:00