From e7daf340631ee6a876823c4b02985d8c85c63b42 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Thu, 9 Jul 2020 20:03:09 +0200 Subject: [PATCH] added a GUI control to set the server Welcome Message in the server GUI --- ChangeLog | 3 +++ src/server.cpp | 20 +++++++++++++++----- src/server.h | 4 ++++ src/serverdlg.cpp | 9 +++++++++ src/serverdlg.h | 1 + src/serverdlgbase.ui | 20 +++++++++++++++++++- 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8aea6349..3a85daa9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,9 +19,12 @@ - scale channel instrument picture in Compact skin mode +- redesign of the server dialog + - bug fix: grouping faders in the client should be proportional (see discussion in #202, #419) +TODO store welcome message set in the GUI in the ini file TODO improve settings management -> move settings class in client/server classes, move actual settings variables TODO improve interaction between use of inifile and command line parameters (edited) #120 diff --git a/src/server.cpp b/src/server.cpp index 499c57cc..af42563f 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -404,7 +404,8 @@ CServer::CServer ( const int iNewMaxNumChan, // manage welcome message: if the welcome message is a valid link to a local // file, the content of that file is used as the welcome message (#361) - strWelcomeMessage = strNewWelcomeMessage; // first copy text, may be overwritten + SetWelcomeMessage ( strNewWelcomeMessage ); // first use given text, may be overwritten + if ( QFileInfo ( strNewWelcomeMessage ).exists() ) { QFile file ( strNewWelcomeMessage ); @@ -412,13 +413,10 @@ CServer::CServer ( const int iNewMaxNumChan, if ( file.open ( QIODevice::ReadOnly | QIODevice::Text ) ) { // use entire file content for the welcome message - strWelcomeMessage = file.readAll(); + SetWelcomeMessage ( file.readAll() ); } } - // restrict welcome message to maximum allowed length - strWelcomeMessage = strWelcomeMessage.left ( MAX_LEN_CHAT_TEXT ); - // enable jam recording (if requested) - kicks off the thread (note // that jam recorder needs the frame size which is given to the jam // recorder in the SetRecordingDir() function) @@ -631,6 +629,7 @@ void CServer::OnNewConnection ( int iChID, vecChannels[iChID].CreateReqChanInfoMes(); // send welcome message (if enabled) + MutexWelcomeMessage.lock(); if ( !strWelcomeMessage.isEmpty() ) { // create formatted server welcome message and send it just to @@ -640,6 +639,7 @@ void CServer::OnNewConnection ( int iChID, vecChannels[iChID].CreateChatTextMes ( strWelcomeMessageFormated ); } + MutexWelcomeMessage.unlock(); // send licence request message (if enabled) if ( eLicenceType != LT_NO_LICENCE ) @@ -1554,6 +1554,16 @@ void CServer::SetEnableRecording ( bool bNewEnableRecording ) CreateAndSendRecorderStateForAllConChannels(); } +void CServer::SetWelcomeMessage ( const QString& strNWelcMess ) +{ + // we need a mutex to secure access + QMutexLocker locker ( &MutexWelcomeMessage ); + strWelcomeMessage = strNWelcMess; + + // restrict welcome message to maximum allowed length + strWelcomeMessage = strWelcomeMessage.left ( MAX_LEN_CHAT_TEXT ); +} + void CServer::StartStatusHTMLFileWriting ( const QString& strNewFileName, const QString& strNewServerNameWithPort ) { diff --git a/src/server.h b/src/server.h index 08766acb..79d20ea6 100755 --- a/src/server.h +++ b/src/server.h @@ -254,6 +254,9 @@ public: QLocale::Country GetServerCountry() { return ServerListManager.GetServerCountry(); } + void SetWelcomeMessage ( const QString& strNWelcMess ); + QString GetWelcomeMessage() { return strWelcomeMessage; } + ESvrRegStatus GetSvrRegStatus() { return ServerListManager.GetSvrRegStatus(); } @@ -323,6 +326,7 @@ protected: int iMaxNumChannels; CProtocol ConnLessProtocol; QMutex Mutex; + QMutex MutexWelcomeMessage; // audio encoder/decoder OpusCustomMode* Opus64Mode[MAX_NUM_CHANNELS]; diff --git a/src/serverdlg.cpp b/src/serverdlg.cpp index 7936c333..05ba19cf 100755 --- a/src/serverdlg.cpp +++ b/src/serverdlg.cpp @@ -333,6 +333,12 @@ lvwClients->setMinimumHeight ( 140 ); // language combo box (corrects the setting if language not found) cbxLanguage->Init ( pSettings->strLanguage ); + // setup welcome message GUI control + tedWelcomeMessage->setPlaceholderText ( tr ( + "Type a message here. If no message is set, the server welcome is disabled." ) ); + + tedWelcomeMessage->setText ( pServer->GetWelcomeMessage() ); + // update GUI dependencies UpdateGUIDependencies(); @@ -415,6 +421,9 @@ lvwClients->setMinimumHeight ( 140 ); this, &CServerDlg::OnTimer ); // other + QObject::connect ( tedWelcomeMessage, &QTextEdit::textChanged, + this, &CServerDlg::OnWelcomeMessageChanged ); + QObject::connect ( pServer, &CServer::Started, this, &CServerDlg::OnServerStarted ); diff --git a/src/serverdlg.h b/src/serverdlg.h index 9e40001e..f9fcb980 100755 --- a/src/serverdlg.h +++ b/src/serverdlg.h @@ -113,6 +113,7 @@ public slots: void OnSysTrayMenuHide() { hide(); } void OnSysTrayMenuExit() { close(); } void OnSysTrayActivated ( QSystemTrayIcon::ActivationReason ActReason ); + void OnWelcomeMessageChanged() { pServer->SetWelcomeMessage ( tedWelcomeMessage->toPlainText() ); } void keyPressEvent ( QKeyEvent *e ) // block escape key { if ( e->key() != Qt::Key_Escape ) QDialog::keyPressEvent ( e ); } diff --git a/src/serverdlgbase.ui b/src/serverdlgbase.ui index 09c45c50..98866bdd 100755 --- a/src/serverdlgbase.ui +++ b/src/serverdlgbase.ui @@ -7,7 +7,7 @@ 0 0 588 - 435 + 560 @@ -185,6 +185,23 @@ + + + + Chat Window Welcome (HTML/CSS Supported) + + + + + + + + 0 + 0 + + + + @@ -279,6 +296,7 @@ chbEnableRecorder edtCurrentSessionDir pbtNewRecording + tedWelcomeMessage cbxLanguage pbtRecordingDir edtRecordingDir