From 70d368c9b7eeaf415fa62bbc04f574269dc5bc72 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Thu, 24 Jul 2008 16:20:25 +0000 Subject: [PATCH] first working version of chat functionality --- src/channel.cpp | 16 +++---- src/channel.h | 24 +++++------ src/chatdlg.cpp | 20 ++++++++- src/chatdlg.h | 8 ++++ src/chatdlgbase.ui | 6 +-- src/client.cpp | 6 ++- src/client.h | 12 +++++- src/clientsettingsdlg.cpp | 20 +++++++++ src/clientsettingsdlg.h | 1 + src/clientsettingsdlgbase.ui | 82 ++++++++++++++++-------------------- src/llconclientdlg.cpp | 38 +++++++++++++++-- src/llconclientdlg.h | 8 ++++ src/protocol.cpp | 12 +++--- src/protocol.h | 4 +- src/settings.cpp | 9 ++-- windows/llcon.vcproj | 4 ++ 16 files changed, 182 insertions(+), 88 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 9fa3aeb9..33e6260a 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -71,12 +71,12 @@ CChannelSet::CChannelSet() QObject::connect(&vecChannels[5],SIGNAL(NameHasChanged()),this,SLOT(OnNameHasChangedCh5())); // chate text received - QObject::connect(&vecChannels[0],SIGNAL(ChatTextReceived()),this,SLOT(OnChatTextReceivedCh0())); - QObject::connect(&vecChannels[1],SIGNAL(ChatTextReceived()),this,SLOT(OnChatTextReceivedCh1())); - QObject::connect(&vecChannels[2],SIGNAL(ChatTextReceived()),this,SLOT(OnChatTextReceivedCh2())); - QObject::connect(&vecChannels[3],SIGNAL(ChatTextReceived()),this,SLOT(OnChatTextReceivedCh3())); - QObject::connect(&vecChannels[4],SIGNAL(ChatTextReceived()),this,SLOT(OnChatTextReceivedCh4())); - QObject::connect(&vecChannels[5],SIGNAL(ChatTextReceived()),this,SLOT(OnChatTextReceivedCh5())); + QObject::connect(&vecChannels[0],SIGNAL(ChatTextReceived(QString)),this,SLOT(OnChatTextReceivedCh0(QString))); + QObject::connect(&vecChannels[1],SIGNAL(ChatTextReceived(QString)),this,SLOT(OnChatTextReceivedCh1(QString))); + QObject::connect(&vecChannels[2],SIGNAL(ChatTextReceived(QString)),this,SLOT(OnChatTextReceivedCh2(QString))); + QObject::connect(&vecChannels[3],SIGNAL(ChatTextReceived(QString)),this,SLOT(OnChatTextReceivedCh3(QString))); + QObject::connect(&vecChannels[4],SIGNAL(ChatTextReceived(QString)),this,SLOT(OnChatTextReceivedCh4(QString))); + QObject::connect(&vecChannels[5],SIGNAL(ChatTextReceived(QString)),this,SLOT(OnChatTextReceivedCh5(QString))); } CVector CChannelSet::CreateChannelList() @@ -115,7 +115,7 @@ void CChannelSet::CreateAndSendChanListForAllConChannels() } } -void CChannelSet::CreateAndSendChatTextForAllConChannels ( const QString& strName ) +void CChannelSet::CreateAndSendChatTextForAllConChannels ( const QString& strChatText ) { // send chat text to all connected clients for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) @@ -123,7 +123,7 @@ void CChannelSet::CreateAndSendChatTextForAllConChannels ( const QString& strNam if ( vecChannels[i].IsConnected() ) { // send message - vecChannels[i].CreateChatTextMes ( strName ); + vecChannels[i].CreateChatTextMes ( strChatText ); } } } diff --git a/src/channel.h b/src/channel.h index ef3ffab7..3175c564 100755 --- a/src/channel.h +++ b/src/channel.h @@ -115,9 +115,9 @@ public: Protocol.CreateJitBufMes ( iJitBufSize ); } } - void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } - void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); } - void CreateChatTextMes ( const QString& strName ) { Protocol.CreateChatTextMes ( strName ); } + void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } + void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); } + void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); } void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) { @@ -193,7 +193,7 @@ signals: void ConClientListMesReceived ( CVector vecChanInfo ); void ProtocolStatus ( bool bOk ); void NameHasChanged(); - void ChatTextReceived ( QString strName ); + void ChatTextReceived ( QString strChatText ); }; @@ -238,8 +238,8 @@ protected: CVector CreateChannelList(); void CreateAndSendChanListForAllConChannels(); void CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID ); - void CreateAndSendChanListForThisChan ( const int iCurChanID ); - void CreateAndSendChatTextForAllConChannels ( const QString& strName ); + void CreateAndSendChanListForThisChan ( const int iCurChanID ); + void CreateAndSendChatTextForAllConChannels ( const QString& strChatText ); /* do not use the vector class since CChannel does not have appropriate copy constructor/operator */ @@ -278,12 +278,12 @@ public slots: void OnNameHasChangedCh4() { CreateAndSendChanListForAllConChannels(); } void OnNameHasChangedCh5() { CreateAndSendChanListForAllConChannels(); } - void OnChatTextReceivedCh0(QString strName) { CreateAndSendChatTextForAllConChannels(strName); } - void OnChatTextReceivedCh1(QString strName) { CreateAndSendChatTextForAllConChannels(strName); } - void OnChatTextReceivedCh2(QString strName) { CreateAndSendChatTextForAllConChannels(strName); } - void OnChatTextReceivedCh3(QString strName) { CreateAndSendChatTextForAllConChannels(strName); } - void OnChatTextReceivedCh4(QString strName) { CreateAndSendChatTextForAllConChannels(strName); } - void OnChatTextReceivedCh5(QString strName) { CreateAndSendChatTextForAllConChannels(strName); } + void OnChatTextReceivedCh0(QString strChatText) { CreateAndSendChatTextForAllConChannels(strChatText); } + void OnChatTextReceivedCh1(QString strChatText) { CreateAndSendChatTextForAllConChannels(strChatText); } + void OnChatTextReceivedCh2(QString strChatText) { CreateAndSendChatTextForAllConChannels(strChatText); } + void OnChatTextReceivedCh3(QString strChatText) { CreateAndSendChatTextForAllConChannels(strChatText); } + void OnChatTextReceivedCh4(QString strChatText) { CreateAndSendChatTextForAllConChannels(strChatText); } + void OnChatTextReceivedCh5(QString strChatText) { CreateAndSendChatTextForAllConChannels(strChatText); } signals: void MessReadyForSending ( int iChID, CVector vecMessage ); diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp index e6cf5796..a6f35c26 100755 --- a/src/chatdlg.cpp +++ b/src/chatdlg.cpp @@ -30,7 +30,25 @@ CChatDlg::CChatDlg ( QWidget* parent, Qt::WindowFlags f ) { setupUi ( this ); + // clear chat window and edit line + TextViewChatWindow->clear(); + lineEditLocalInputText->clear(); + // Connections ------------------------------------------------------------- - + QObject::connect ( lineEditLocalInputText, SIGNAL ( returnPressed() ), + this, SLOT ( OnNewLocalInputText() ) ); +} + +void CChatDlg::OnNewLocalInputText() +{ + // send new text and clear line afterwards + emit NewLocalInputText ( lineEditLocalInputText->text() ); + lineEditLocalInputText->clear(); +} + +void CChatDlg::AddChatText ( QString strChatText ) +{ + // add new text in chat window + TextViewChatWindow->append ( strChatText ); } diff --git a/src/chatdlg.h b/src/chatdlg.h index a2bee451..1627ebdd 100755 --- a/src/chatdlg.h +++ b/src/chatdlg.h @@ -43,4 +43,12 @@ class CChatDlg : public QDialog, private Ui_CChatDlgBase public: CChatDlg ( QWidget* parent = 0, Qt::WindowFlags f = 0 ); + + void AddChatText ( QString strChatText ); + +public slots: + void OnNewLocalInputText(); + +signals: + void NewLocalInputText ( QString strNewText ); }; diff --git a/src/chatdlgbase.ui b/src/chatdlgbase.ui index 0b9c0d61..374eba4f 100755 --- a/src/chatdlgbase.ui +++ b/src/chatdlgbase.ui @@ -5,8 +5,8 @@ 0 0 - 535 - 397 + 360 + 405 @@ -82,9 +82,9 @@ - TextViewChatWindow lineEditLocalInputText buttonClose + TextViewChatWindow diff --git a/src/client.cpp b/src/client.cpp index 8f094b4c..66dd1fb9 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -31,7 +31,8 @@ CClient::CClient() : bRun ( false ), Socket ( &Channel ), iReverbLevel ( AUD_REVERB_MAX / 6 ), bReverbOnLeftChan ( false ), iNetwBufSizeFactIn ( DEF_NET_BLOCK_SIZE_FACTOR ), - strIPAddress ( "" ), strName ( "" ) + strIPAddress ( "" ), strName ( "" ), + bOpenChatOnNewMessage ( true ) { // connection for protocol QObject::connect ( &Channel, @@ -50,6 +51,9 @@ CClient::CClient() : bRun ( false ), Socket ( &Channel ), QObject::connect ( &Channel, SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnection() ) ); + + QObject::connect ( &Channel, SIGNAL ( ChatTextReceived ( QString ) ), + this, SIGNAL ( ChatTextReceived ( QString ) ) ); } void CClient::OnSendProtMessage ( CVector vecMessage ) diff --git a/src/client.h b/src/client.h index 863eb095..d8b42001 100755 --- a/src/client.h +++ b/src/client.h @@ -1,5 +1,5 @@ /******************************************************************************\ - * Copyright (c) 2004-2006 + * Copyright (c) 2004-2008 * * Author(s): * Volker Fischer @@ -75,6 +75,9 @@ public: the sqaure root. */ double GetTimingStdDev() { return sqrt ( RespTimeMoAvBuf.GetAverage() ); } + bool GetOpenChatOnNewMessage() { return bOpenChatOnNewMessage; } + void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; } + int GetAudioInFader() { return iAudioInFader; } void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; } @@ -98,7 +101,6 @@ public: } int GetSockBufSize() { return Channel.GetSockBufSize(); } - void SetNetwBufSizeFactIn ( const int iNewNetNetwBlSiFactIn ) { // store value and tell the server about new value @@ -119,6 +121,9 @@ public: void SetRemoteName() { Channel.SetRemoteName ( strName ); } + void SendTextMess ( const QString& strChatText ) + { Channel.CreateChatTextMes ( strChatText ); } + CSound* GetSndInterface() { return &Sound; } CChannel* GetChannel() { return &Channel; } @@ -151,6 +156,8 @@ protected: int iNetwBufSizeFactIn; + bool bOpenChatOnNewMessage; + CVector vecsAudioSndCrd; CVector vecdAudioSndCrdL; CVector vecdAudioSndCrdR; @@ -178,6 +185,7 @@ public slots: signals: void ConClientListMesReceived ( CVector vecChanInfo ); + void ChatTextReceived ( QString strChatText ); }; diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index d4735b6a..09680800 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -77,6 +77,16 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, double ( iCurNetBufSiFactOut * MIN_BLOCK_DURATION_MS), 'f', 2 ) + " ms" ); + // "OpenChatOnNewMessage" check box + if ( pClient->GetOpenChatOnNewMessage() ) + { + cbOpenChatOnNewMessage->setCheckState ( Qt::Checked ); + } + else + { + cbOpenChatOnNewMessage->setCheckState ( Qt::Unchecked ); + } + // Connections ------------------------------------------------------------- // timers @@ -97,6 +107,10 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, QObject::connect ( SliderNetBufSiFactOut, SIGNAL ( valueChanged ( int ) ), this, SLOT ( OnSliderNetBufSiFactOut ( int ) ) ); + // check boxes + QObject::connect ( cbOpenChatOnNewMessage, SIGNAL ( stateChanged ( int ) ), + this, SLOT ( OnOpenChatOnNewMessageStateChanged ( int ) ) ); + // Timers ------------------------------------------------------------------ // start timer for status bar @@ -142,6 +156,12 @@ void CClientSettingsDlg::OnSliderNetBufSiFactOut ( int value ) UpdateDisplay(); } +void CClientSettingsDlg::OnOpenChatOnNewMessageStateChanged ( int value ) +{ + pClient->SetOpenChatOnNewMessage ( value == Qt::Checked ); + UpdateDisplay(); +} + void CClientSettingsDlg::UpdateDisplay() { // response time diff --git a/src/clientsettingsdlg.h b/src/clientsettingsdlg.h index 255c633c..289f9ba8 100755 --- a/src/clientsettingsdlg.h +++ b/src/clientsettingsdlg.h @@ -71,4 +71,5 @@ public slots: void OnSliderNetBuf ( int value ); void OnSliderNetBufSiFactIn ( int value ); void OnSliderNetBufSiFactOut ( int value ); + void OnOpenChatOnNewMessageStateChanged ( int value ); }; diff --git a/src/clientsettingsdlgbase.ui b/src/clientsettingsdlgbase.ui index 254d3c9b..ce06f290 100755 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -5,8 +5,8 @@ 0 0 - 469 - 268 + 425 + 271 @@ -19,21 +19,6 @@ true - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - @@ -735,24 +720,42 @@ - Debug + Misc - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - + + + + Qt::Horizontal + + + + + + + + + Open chat on new message + + + true + + + + + + + + Qt::Vertical + + + + 20 + 71 + + + + @@ -843,19 +846,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 6c354d8f..da2b86a0 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -28,7 +28,8 @@ /* Implementation *************************************************************/ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent ) : pClient ( pNCliP ), QDialog ( parent ), - ClientSettingsDlg ( pNCliP, parent, Qt::WindowMinMaxButtonsHint ) + ClientSettingsDlg ( pNCliP, parent, Qt::WindowMinMaxButtonsHint ), + ChatDlg ( parent, Qt::WindowMinMaxButtonsHint ) { setupUi ( this ); @@ -138,7 +139,9 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent ) // Settings menu ---------------------------------------------------------- - pSettingsMenu = new QMenu ( "&Settings", this ); + pSettingsMenu = new QMenu ( "&View", this ); + pSettingsMenu->addAction ( tr ( "&Chat..." ), this, + SLOT ( OnOpenChatDialog() ) ); pSettingsMenu->addAction ( tr ( "&General Settings..." ), this, SLOT ( OnOpenGeneralSettings() ) ); @@ -187,8 +190,13 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent ) QObject::connect ( pClient, SIGNAL ( ConClientListMesReceived ( CVector ) ), this, SLOT ( OnConClientListMesReceived ( CVector ) ) ); + QObject::connect ( pClient, + SIGNAL ( ChatTextReceived ( QString ) ), + this, SLOT ( OnChatTextReceived ( QString ) ) ); QObject::connect ( MainMixerBoard, SIGNAL ( ChangeChanGain ( int, double ) ), this, SLOT ( OnChangeChanGain ( int, double ) ) ); + QObject::connect ( &ChatDlg, SIGNAL ( NewLocalInputText ( QString ) ), + this, SLOT ( OnNewLocalInputText ( QString ) ) ); // Timers ------------------------------------------------------------------ @@ -207,8 +215,9 @@ CLlconClientDlg::~CLlconClientDlg() void CLlconClientDlg::closeEvent ( QCloseEvent * Event ) { - // if settings dialog is open, close it + // if settings dialog or chat dialog is open, close it ClientSettingsDlg.close(); + ChatDlg.close(); // store IP address pClient->strIPAddress = LineEditServerAddr->text(); @@ -273,6 +282,27 @@ void CLlconClientDlg::OnOpenGeneralSettings() ClientSettingsDlg.activateWindow(); } +void CLlconClientDlg::OnChatTextReceived ( QString strChatText ) +{ + ChatDlg.AddChatText ( strChatText ); + + // if requested, open window + if ( pClient->GetOpenChatOnNewMessage() ) + { + ShowChatWindow(); + } +} + +void CLlconClientDlg::ShowChatWindow() +{ + // open chat dialog + ChatDlg.show(); + + // make sure dialog is upfront and has focus + ChatDlg.raise(); + ChatDlg.activateWindow(); +} + void CLlconClientDlg::OnFaderTagTextChanged ( const QString& strNewName ) { // refresh internal name parameter @@ -318,7 +348,7 @@ void CLlconClientDlg::OnTimerSigMet() void CLlconClientDlg::UpdateDisplay() { // show connection status in status bar - if ( pClient->IsConnected () && pClient->IsRunning () ) + if ( pClient->IsConnected() && pClient->IsRunning() ) { TextLabelStatus->setText ( tr ( "connected" ) ); } diff --git a/src/llconclientdlg.h b/src/llconclientdlg.h index ac097900..96956afb 100755 --- a/src/llconclientdlg.h +++ b/src/llconclientdlg.h @@ -38,6 +38,7 @@ #include "multicolorled.h" #include "audiomixerboard.h" #include "clientsettingsdlg.h" +#include "chatdlg.h" #ifdef _WIN32 # include "../windows/moc/llconclientdlgbase.h" #else @@ -72,6 +73,8 @@ public: virtual ~CLlconClientDlg(); protected: + void ShowChatWindow(); + CClient* pClient; bool bConnected; QTimer TimerSigMet; @@ -85,12 +88,14 @@ protected: QMenuBar* pMenu; CClientSettingsDlg ClientSettingsDlg; + CChatDlg ChatDlg; public slots: void OnConnectDisconBut(); void OnTimerSigMet(); void OnTimerStatus() { UpdateDisplay(); } void OnOpenGeneralSettings(); + void OnOpenChatDialog() { ShowChatWindow(); } void OnSliderAudInFader ( int value ) { pClient->SetAudioInFader ( value ); } void OnSliderAudReverb ( int value ) { pClient->SetReverbLevel ( value ); } void OnRevSelL() { pClient->SetReverbOnLeftChan ( true ); } @@ -100,4 +105,7 @@ public slots: void OnChangeChanGain ( int iId, double dGain ) { pClient->SetRemoteChanGain ( iId, dGain ); } void OnFaderTagTextChanged ( const QString& strNewName ); + void OnChatTextReceived ( QString strChatText ); + void OnNewLocalInputText ( QString strChatText ) + { pClient->SendTextMess ( strChatText ); } }; diff --git a/src/protocol.cpp b/src/protocol.cpp index ef22948d..2a4033cd 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -603,10 +603,10 @@ void CProtocol::CreateChanNameMes ( const QString strName ) CreateAndSendMessage ( PROTMESSID_CHANNEL_NAME, vecData ); } -void CProtocol::CreateChatTextMes ( const QString strName ) +void CProtocol::CreateChatTextMes ( const QString strChatText ) { unsigned int iPos = 0; // init position pointer - const int iStrLen = strName.size(); // get string size + const int iStrLen = strChatText.size(); // get string size // size of current list entry const int iEntrLen = 2 /* str. size */ + iStrLen; @@ -622,7 +622,7 @@ void CProtocol::CreateChatTextMes ( const QString strName ) { // byte-by-byte copying of the string data PutValOnStream ( vecData, iPos, - static_cast ( strName[j].toAscii() ), 1 ); + static_cast ( strChatText[j].toAscii() ), 1 ); } CreateAndSendMessage ( PROTMESSID_CHAT_TEXT, vecData ); @@ -654,16 +654,16 @@ void CProtocol::EvaluateChatTextMes ( unsigned int iPos, const CVector& static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); // name string (n bytes) - QString strName = ""; + QString strChatText = ""; for ( int j = 0; j < iStrLen; j++ ) { // byte-by-byte copying of the string data int iData = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); - strName += QString ( (char*) &iData ); + strChatText += QString ( (char*) &iData ); } // invoke message action - emit ChatTextReceived ( strName ); + emit ChatTextReceived ( strChatText ); } diff --git a/src/protocol.h b/src/protocol.h index 4a004e01..a37eb1ec 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -71,7 +71,7 @@ public: void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ); void CreateChanGainMes ( const int iChanID, const double dGain ); void CreateChanNameMes ( const QString strName ); - void CreateChatTextMes ( const QString strName ); + void CreateChatTextMes ( const QString strChatText ); void CreateConClientListMes ( const CVector& vecChanInfo ); @@ -164,7 +164,7 @@ signals: void ChangeNetwBlSiFact ( int iNewNetwBlSiFact ); void ChangeChanGain ( int iChanID, double dNewGain ); void ChangeChanName ( QString strName ); - void ChatTextReceived ( QString strName ); + void ChatTextReceived ( QString strChatText ); void ConClientListMesReceived ( CVector vecChanInfo ); void ReqJittBufSize(); void ReqConnClientsList(); diff --git a/src/settings.cpp b/src/settings.cpp index f4d8e836..5bdf8a4b 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -101,10 +101,10 @@ void CSettings::ReadIniFile ( const QString& sFileName ) pClient->SetNetwBufSizeFactIn ( iValue ); } - // network buffer size factor out - if ( GetNumericIniSet ( IniXMLDocument, "client", "netwbusifactout", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) ) + // flag whether the chat window shall be opened on a new chat message + if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) ) { - pClient->SetNetwBufSizeFactOut ( iValue ); + pClient->SetOpenChatOnNewMessage ( bValue ); } } @@ -145,6 +145,9 @@ void CSettings::WriteIniFile ( const QString& sFileName ) // network buffer size factor out SetNumericIniSet ( IniXMLDocument, "client", "netwbusifactout", pClient->GetNetwBufSizeFactOut() ); + // flag whether the chat window shall be opened on a new chat message + SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", pClient->GetOpenChatOnNewMessage() ); + // prepare file name for storing initialization data in XML file QString sCurFileName = sFileName; diff --git a/windows/llcon.vcproj b/windows/llcon.vcproj index 220328d9..b8ded784 100755 --- a/windows/llcon.vcproj +++ b/windows/llcon.vcproj @@ -303,6 +303,10 @@ /> + +