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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef CHATWIDGET_H
# define CHATWIDGET_H
# include <QWidget>
2013-07-04 19:36:12 +00:00
# include <QCompleter>
2012-01-17 20:36:36 +00:00
# include "gui/common/HashBox.h"
# include "ChatStyle.h"
# include "gui/style/RSStyle.h"
# include <retroshare/rsmsgs.h>
2012-11-11 21:17:00 +00:00
# include <retroshare/rsfiles.h>
2012-01-17 20:36:36 +00:00
class QAction ;
class QTextEdit ;
2012-02-25 12:17:36 +00:00
class QPushButton ;
2014-01-02 00:56:46 +00:00
class ChatWidget ;
2012-01-17 20:36:36 +00:00
namespace Ui {
class ChatWidget ;
}
2014-01-02 00:56:46 +00:00
// a Container for the logic behind buttons in a PopupChatDialog
// Plugins can implement this interface to provide their own buttons
class ChatWidgetHolder
{
public :
ChatWidgetHolder ( ChatWidget * chatWidget ) : mChatWidget ( chatWidget ) { }
virtual ~ ChatWidgetHolder ( ) { }
// status comes from notifyPeerStatusChanged
// see rststaus.h for possible values
virtual void updateStatus ( int /*status*/ ) { }
protected :
ChatWidget * mChatWidget ;
} ;
2012-01-17 20:36:36 +00:00
class ChatWidget : public QWidget
{
Q_OBJECT
2012-02-03 21:43:09 +00:00
2012-01-17 20:36:36 +00:00
public :
2014-01-02 00:56:46 +00:00
enum MsgType { MSGTYPE_NORMAL , MSGTYPE_HISTORY , MSGTYPE_OFFLINE , MSGTYPE_SYSTEM } ;
enum ChatType { CHATTYPE_UNKNOWN , CHATTYPE_PRIVATE , CHATTYPE_LOBBY , CHATTYPE_DISTANT } ;
2012-01-17 20:36:36 +00:00
explicit ChatWidget ( QWidget * parent = 0 ) ;
~ ChatWidget ( ) ;
2012-01-18 00:32:15 +00:00
2014-03-17 20:56:06 +00:00
void init ( const RsPeerId & peerId , const QString & title ) ;
2014-01-02 00:56:46 +00:00
ChatType chatType ( ) { return mChatType ; }
2012-01-17 20:36:36 +00:00
bool hasNewMessages ( ) { return newMessages ; }
bool isTyping ( ) { return typing ; }
void focusDialog ( ) ;
void addToParent ( QWidget * newParent ) ;
void removeFromParent ( QWidget * oldParent ) ;
2012-03-20 23:05:17 +00:00
void setWelcomeMessage ( QString & text ) ;
2014-01-02 00:56:46 +00:00
void addChatMsg ( bool incoming , const QString & name , const QDateTime & sendTime , const QDateTime & recvTime , const QString & message , MsgType chatType ) ;
2012-01-17 20:36:36 +00:00
void updateStatusString ( const QString & statusMask , const QString & statusString ) ;
void addToolsAction ( QAction * action ) ;
2014-03-17 20:56:06 +00:00
RsPeerId getPeerId ( ) { return peerId ; }
2012-01-18 00:32:15 +00:00
QString getTitle ( ) { return title ; }
2012-01-17 20:36:36 +00:00
int getPeerStatus ( ) { return peerStatus ; }
2012-01-18 00:32:15 +00:00
void setName ( const QString & name ) ;
2012-01-17 20:36:36 +00:00
bool setStyle ( ) ;
const RSStyle * getStyle ( ) { return & style ; }
2013-04-23 22:43:19 +00:00
void addChatBarWidget ( QWidget * w ) ;
2012-02-25 12:17:36 +00:00
2012-03-30 23:02:52 +00:00
bool isActive ( ) ;
2012-11-11 21:17:00 +00:00
void setDefaultExtraFileFlags ( TransferRequestFlags f ) ;
2013-02-22 21:42:27 +00:00
void pasteText ( const QString & ) ;
2012-03-30 23:02:52 +00:00
2014-01-02 00:56:46 +00:00
const QList < ChatWidgetHolder * > & chatWidgetHolderList ( ) { return mChatWidgetHolder ; }
2013-06-17 21:58:26 +00:00
public slots :
void updateStatus ( const QString & peer_id , int status ) ;
2013-12-30 19:12:16 +00:00
2012-01-17 20:36:36 +00:00
private slots :
2013-04-13 13:12:13 +00:00
void pasteCreateMsgLink ( ) ;
2012-01-17 20:36:36 +00:00
void clearChatHistory ( ) ;
void deleteChatHistory ( ) ;
void messageHistory ( ) ;
2012-03-15 13:18:47 +00:00
void resetStatusBar ( ) ;
2012-01-17 20:36:36 +00:00
signals :
void infoChanged ( ChatWidget * ) ;
void newMessage ( ChatWidget * ) ;
2012-03-11 00:22:25 +00:00
void statusChanged ( int ) ;
2012-01-17 20:36:36 +00:00
protected :
bool eventFilter ( QObject * obj , QEvent * event ) ;
virtual void showEvent ( QShowEvent * event ) ;
virtual void resizeEvent ( QResizeEvent * event ) ;
2012-01-28 15:11:58 +00:00
void updateTitle ( ) ;
2012-01-17 20:36:36 +00:00
private slots :
2012-08-22 08:19:46 +00:00
void contextMenuTextBrowser ( QPoint ) ;
2012-04-12 23:00:39 +00:00
void chatCharFormatChanged ( ) ;
2012-01-17 20:36:36 +00:00
void fileHashingFinished ( QList < HashedFile > hashedFiles ) ;
void smileyWidget ( ) ;
void addSmiley ( ) ;
void addExtraFile ( ) ;
void addExtraPicture ( ) ;
void on_closeInfoFrameButton_clicked ( ) ;
2012-02-11 21:41:41 +00:00
void chooseColor ( ) ;
void chooseFont ( ) ;
void resetFont ( ) ;
2012-01-17 20:36:36 +00:00
void setFont ( ) ;
void sendChat ( ) ;
void updatePeersCustomStateString ( const QString & peer_id , const QString & status_string ) ;
bool fileSave ( ) ;
bool fileSaveAs ( ) ;
private :
void updateStatusTyping ( ) ;
void setCurrentFileName ( const QString & fileName ) ;
2012-02-11 21:41:41 +00:00
void colorChanged ( ) ;
void fontChanged ( ) ;
void setColorAndFont ( ) ;
2012-01-17 20:36:36 +00:00
void processSettings ( bool load ) ;
2013-03-06 19:41:08 +00:00
void completeNickname ( bool reverse ) ;
2013-07-04 19:36:12 +00:00
QAbstractItemModel * modelFromPeers ( ) ;
2013-03-06 19:41:08 +00:00
2014-03-17 20:56:06 +00:00
RsPeerId peerId ;
2012-01-18 00:32:15 +00:00
QString title ;
QString name ;
2013-03-06 19:41:08 +00:00
QString completionWord ;
int completionPosition ;
2012-01-17 20:36:36 +00:00
QColor currentColor ;
QFont currentFont ;
QString fileName ;
bool newMessages ;
bool typing ;
int peerStatus ;
2014-01-02 00:56:46 +00:00
ChatType mChatType ;
2012-01-17 20:36:36 +00:00
time_t lastStatusSendTime ;
ChatStyle chatStyle ;
RSStyle style ;
2012-01-23 19:57:06 +00:00
bool firstShow ;
2012-04-12 23:00:39 +00:00
bool inChatCharFormatChanged ;
2012-01-23 19:57:06 +00:00
2012-11-11 21:17:00 +00:00
TransferRequestFlags mDefaultExtraFileFlags ; // flags for extra files shared in this chat. Will be 0 by default, but might be ANONYMOUS for chat lobbies.
2013-07-16 21:14:48 +00:00
QDate lastMsgDate ;
2012-11-11 21:17:00 +00:00
2013-07-04 19:36:12 +00:00
QCompleter * completer ;
2014-01-02 00:56:46 +00:00
QList < ChatWidgetHolder * > mChatWidgetHolder ;
2012-01-17 20:36:36 +00:00
Ui : : ChatWidget * ui ;
} ;
# endif // CHATWIDGET_H