2012-01-17 15:36:36 -05: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
2014-12-06 09:21:36 -05:00
# include <QWidget>
# include <QCompleter>
# include <QTextCursor>
# include <QTextCharFormat>
2015-03-26 18:17:48 -04:00
# include <QToolButton>
2014-12-06 09:21:36 -05:00
# include "gui/common/HashBox.h"
2015-03-21 17:25:17 -04:00
# include "gui/common/RsButtonOnText.h"
2014-12-06 09:21:36 -05:00
# include "ChatStyle.h"
# include "gui/style/RSStyle.h"
2015-03-26 18:17:48 -04:00
# include "ChatLobbyUserNotify.h"
2012-01-17 15:36:36 -05:00
# include <retroshare/rsmsgs.h>
2012-11-11 16:17:00 -05:00
# include <retroshare/rsfiles.h>
2012-01-17 15:36:36 -05:00
class QAction ;
2014-12-06 09:21:36 -05:00
class QTextEdit ;
class QPushButton ;
class ChatWidget ;
class QMenu ;
namespace Ui {
class ChatWidget ;
2012-01-17 15:36:36 -05:00
}
2014-01-01 19:56:46 -05: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 15:36:36 -05:00
class ChatWidget : public QWidget
{
Q_OBJECT
2012-02-03 16:43:09 -05:00
2012-01-17 15:36:36 -05:00
public :
2014-01-01 19:56:46 -05:00
enum MsgType { MSGTYPE_NORMAL , MSGTYPE_HISTORY , MSGTYPE_OFFLINE , MSGTYPE_SYSTEM } ;
enum ChatType { CHATTYPE_UNKNOWN , CHATTYPE_PRIVATE , CHATTYPE_LOBBY , CHATTYPE_DISTANT } ;
2012-01-17 15:36:36 -05:00
explicit ChatWidget ( QWidget * parent = 0 ) ;
~ ChatWidget ( ) ;
2012-01-17 19:32:15 -05:00
2014-12-29 16:41:05 -05:00
void init ( const ChatId & chat_id , const QString & title ) ;
2014-12-30 09:26:04 -05:00
ChatId getChatId ( ) ;
2014-12-29 16:41:05 -05:00
ChatType chatType ( ) ;
2012-01-17 15:36:36 -05:00
2015-01-10 08:13:41 -05:00
// allow/disallow sendng of messages
void blockSending ( QString msg ) ;
void unblockSending ( ) ;
2012-01-17 15:36:36 -05:00
bool hasNewMessages ( ) { return newMessages ; }
bool isTyping ( ) { return typing ; }
void focusDialog ( ) ;
2015-03-26 18:17:48 -04:00
QToolButton * getNotifyButton ( ) ;
void setNotify ( ChatLobbyUserNotify * clun ) ;
void scrollToAnchor ( QString anchor ) ;
2012-01-17 15:36:36 -05:00
void addToParent ( QWidget * newParent ) ;
void removeFromParent ( QWidget * oldParent ) ;
2012-03-20 19:05:17 -04:00
void setWelcomeMessage ( QString & text ) ;
2014-01-01 19:56:46 -05:00
void addChatMsg ( bool incoming , const QString & name , const QDateTime & sendTime , const QDateTime & recvTime , const QString & message , MsgType chatType ) ;
2015-01-10 08:13:41 -05:00
void updateStatusString ( const QString & statusMask , const QString & statusString , bool permanent = false ) ;
2012-01-17 15:36:36 -05:00
void addToolsAction ( QAction * action ) ;
2012-01-17 19:32:15 -05:00
QString getTitle ( ) { return title ; }
2012-01-17 15:36:36 -05:00
int getPeerStatus ( ) { return peerStatus ; }
2012-01-17 19:32:15 -05:00
void setName ( const QString & name ) ;
2012-01-17 15:36:36 -05:00
bool setStyle ( ) ;
const RSStyle * getStyle ( ) { return & style ; }
2014-12-06 09:21:36 -05:00
// Adds one widget in the chat bar. Used to add e.g. new buttons. The widget should be
// small enough in size.
2013-04-23 18:43:19 -04:00
void addChatBarWidget ( QWidget * w ) ;
2014-12-19 07:17:58 -05:00
void addVOIPBarWidget ( QWidget * w ) ;
2015-03-21 17:25:17 -04:00
RSButtonOnText * getNewButtonOnTextBrowser ( ) ;
RSButtonOnText * getNewButtonOnTextBrowser ( QString text ) ;
2014-12-29 16:41:05 -05:00
2014-12-06 09:21:36 -05:00
// Adds a new horizonal widget in the layout of the chat window.
2014-07-15 11:59:12 -04:00
void addChatHorizontalWidget ( QWidget * w ) ;
2012-02-25 07:17:36 -05:00
2012-03-30 19:02:52 -04:00
bool isActive ( ) ;
2012-11-11 16:17:00 -05:00
void setDefaultExtraFileFlags ( TransferRequestFlags f ) ;
2013-02-22 16:42:27 -05:00
void pasteText ( const QString & ) ;
2012-03-30 19:02:52 -04:00
2014-01-01 19:56:46 -05:00
const QList < ChatWidgetHolder * > & chatWidgetHolderList ( ) { return mChatWidgetHolder ; }
2013-06-17 17:58:26 -04:00
public slots :
void updateStatus ( const QString & peer_id , int status ) ;
2013-12-30 14:12:16 -05:00
2012-01-17 15:36:36 -05:00
private slots :
2013-04-13 09:12:13 -04:00
void pasteCreateMsgLink ( ) ;
2012-01-17 15:36:36 -05:00
void clearChatHistory ( ) ;
void deleteChatHistory ( ) ;
void messageHistory ( ) ;
2012-03-15 09:18:47 -04:00
void resetStatusBar ( ) ;
2014-12-19 07:17:58 -05:00
void searchHistory ( ) ;
2012-01-17 15:36:36 -05:00
signals :
void infoChanged ( ChatWidget * ) ;
void newMessage ( ChatWidget * ) ;
2012-03-10 19:22:25 -05:00
void statusChanged ( int ) ;
2012-01-17 15:36:36 -05:00
protected :
bool eventFilter ( QObject * obj , QEvent * event ) ;
virtual void showEvent ( QShowEvent * event ) ;
virtual void resizeEvent ( QResizeEvent * event ) ;
2012-01-28 10:11:58 -05:00
void updateTitle ( ) ;
2014-12-06 09:21:36 -05:00
private slots :
void contextMenuTextBrowser ( QPoint ) ;
void contextMenuSearchButton ( QPoint ) ;
void chatCharFormatChanged ( ) ;
void fileHashingFinished ( QList < HashedFile > hashedFiles ) ;
2012-01-17 15:36:36 -05:00
void smileyWidget ( ) ;
void addSmiley ( ) ;
2014-12-06 09:21:36 -05:00
void addExtraFile ( ) ;
void addExtraPicture ( ) ;
void on_closeInfoFrameButton_clicked ( ) ;
void on_searchButton_clicked ( bool bValue ) ;
void on_searchBefore_clicked ( ) ;
void on_searchAfter_clicked ( ) ;
void toogle_FindCaseSensitively ( ) ;
void toogle_FindWholeWords ( ) ;
void toogle_MoveToCursor ( ) ;
void toogle_SeachWithoutLimit ( ) ;
2015-03-26 18:17:48 -04:00
void on_notifyButton_clicked ( ) ;
2014-12-06 09:21:36 -05:00
void on_markButton_clicked ( bool bValue ) ;
void chooseColor ( ) ;
void chooseFont ( ) ;
2012-02-11 16:41:41 -05:00
void resetFont ( ) ;
2015-01-08 14:12:47 -05:00
void resetFonts ( ) ;
2012-01-17 15:36:36 -05:00
void setFont ( ) ;
2014-07-06 07:33:04 -04:00
void updateLenOfChatTextEdit ( ) ;
2012-01-17 15:36:36 -05:00
void sendChat ( ) ;
void updatePeersCustomStateString ( const QString & peer_id , const QString & status_string ) ;
bool fileSave ( ) ;
2014-12-06 09:21:36 -05:00
bool fileSaveAs ( ) ;
private :
bool findText ( const QString & qsStringToFind ) ;
bool findText ( const QString & qsStringToFind , bool bBackWard , bool bForceMove ) ;
void removeFoundText ( ) ;
void updateStatusTyping ( ) ;
void setCurrentFileName ( const QString & fileName ) ;
2012-02-11 16:41:41 -05:00
void colorChanged ( ) ;
2015-01-08 14:12:47 -05:00
void setColorAndFont ( bool both ) ;
2012-01-17 15:36:36 -05:00
void processSettings ( bool load ) ;
2013-03-06 14:41:08 -05:00
void completeNickname ( bool reverse ) ;
2013-07-04 15:36:12 -04:00
QAbstractItemModel * modelFromPeers ( ) ;
2013-03-06 14:41:08 -05:00
2014-12-29 16:41:05 -05:00
ChatId chatId ;
2012-01-17 19:32:15 -05:00
QString title ;
QString name ;
2013-03-06 14:41:08 -05:00
QString completionWord ;
int completionPosition ;
2012-01-17 15:36:36 -05:00
QColor currentColor ;
QFont currentFont ;
QString fileName ;
bool newMessages ;
bool typing ;
int peerStatus ;
2015-01-10 08:13:41 -05:00
bool sendingBlocked ;
2012-01-17 15:36:36 -05:00
time_t lastStatusSendTime ;
ChatStyle chatStyle ;
RSStyle style ;
2014-12-06 09:21:36 -05:00
bool firstShow ;
bool inChatCharFormatChanged ;
bool firstSearch ;
QPalette qpSave_leSearch ;
std : : map < QTextCursor , QTextCharFormat > smFoundCursor ;
int iCharToStartSearch ;
bool bFindCaseSensitively ;
bool bFindWholeWords ;
bool bMoveToCursor ;
bool bSearchWithoutLimit ;
uint uiMaxSearchLimitColor ;
QColor cFoundColor ;
QString qsLastsearchText ;
QTextCursor qtcCurrent ;
QTextCursor qtcMark ;
2015-08-30 20:09:55 -04:00
int lastUpdateCursorPos ;
int lastUpdateCursorEnd ;
2014-12-06 09:21:36 -05:00
TransferRequestFlags mDefaultExtraFileFlags ; // flags for extra files shared in this chat. Will be 0 by default, but might be ANONYMOUS for chat lobbies.
QDate lastMsgDate ;
2012-11-11 16:17:00 -05:00
2013-07-04 15:36:12 -04:00
QCompleter * completer ;
2014-01-01 19:56:46 -05:00
QList < ChatWidgetHolder * > mChatWidgetHolder ;
2015-03-26 18:17:48 -04:00
ChatLobbyUserNotify * notify ;
2014-01-01 19:56:46 -05:00
2012-01-17 15:36:36 -05:00
Ui : : ChatWidget * ui ;
} ;
# endif // CHATWIDGET_H