From 82f5ad18f4feeb34aa2618105e957268d78af068 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 11 Apr 2020 14:27:50 +0200 Subject: [PATCH] added support for Central Server (North America) (Ticket #50), small bug fix for the Mac audio interface --- mac/sound.cpp | 2 +- src/client.cpp | 2 +- src/client.h | 16 +++------- src/clientdlg.cpp | 4 +-- src/clientsettingsdlg.cpp | 57 +++++++++++++++------------------ src/clientsettingsdlg.h | 2 +- src/clientsettingsdlgbase.ui | 10 ++---- src/global.h | 1 - src/main.cpp | 5 --- src/res/homepage/manual.md | 3 +- src/server.h | 8 ++--- src/serverdlg.cpp | 62 ++++++++++++++++-------------------- src/serverdlg.h | 2 +- src/serverdlgbase.ui | 8 ++--- src/serverlist.cpp | 16 +++++----- src/serverlist.h | 9 ++---- src/settings.cpp | 56 +++++++++++++++++++++++++------- src/util.cpp | 30 ++++++++++++++++- src/util.h | 20 +++++++++--- 19 files changed, 175 insertions(+), 138 deletions(-) diff --git a/mac/sound.cpp b/mac/sound.cpp index 7d33be84..18c1edc0 100755 --- a/mac/sound.cpp +++ b/mac/sound.cpp @@ -466,7 +466,7 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx ) // store the input and out number of channels for this device iNumInChan = CountChannels ( audioInputDevice[iDriverIdx], true ); - iNumOutChan = CountChannels ( audioInputDevice[iDriverIdx], false ); + iNumOutChan = CountChannels ( audioOutputDevice[iDriverIdx], false ); // clip the number of input/output channels to our allowed maximum if ( iNumInChan > MAX_NUM_IN_OUT_CHANNELS ) diff --git a/src/client.cpp b/src/client.cpp index 05769f00..4374bdff 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -69,7 +69,7 @@ CClient::CClient ( const quint16 iPortNumber, bDisplayChannelLevels ( true ), bJitterBufferOK ( true ), strCentralServerAddress ( "" ), - bUseDefaultCentralServerAddress ( true ), + eCentralServerAddressType ( AT_DEFAULT ), iServerSockBufNumFrames ( DEF_NET_BUF_SIZE_NUM_BL ) { int iOpusError; diff --git a/src/client.h b/src/client.h index 9daf466c..653a9ee7 100755 --- a/src/client.h +++ b/src/client.h @@ -137,17 +137,11 @@ public: EAudChanConf GetAudioChannels() const { return eAudioChannelConf; } void SetAudioChannels ( const EAudChanConf eNAudChanConf ); - void SetServerListCentralServerAddress ( const QString& sNCentServAddr ) - { strCentralServerAddress = sNCentServAddr; } + void SetServerListCentralServerAddress ( const QString& sNCentServAddr ) { strCentralServerAddress = sNCentServAddr; } + QString GetServerListCentralServerAddress() { return strCentralServerAddress; } - QString GetServerListCentralServerAddress() - { return strCentralServerAddress; } - - void SetUseDefaultCentralServerAddress ( const bool bNUDCSeAddr ) - { bUseDefaultCentralServerAddress = bNUDCSeAddr; } - - bool GetUseDefaultCentralServerAddress() - { return bUseDefaultCentralServerAddress; } + void SetCentralServerAddressType ( const ECSAddType eNCSAT ) { eCentralServerAddressType = eNCSAT; } + ECSAddType GetCentralServerAddressType() { return eCentralServerAddressType; } int GetAudioInFader() const { return iAudioInFader; } void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; } @@ -370,7 +364,7 @@ protected: bool bJitterBufferOK; QString strCentralServerAddress; - bool bUseDefaultCentralServerAddress; + ECSAddType eCentralServerAddressType; CVector vecsAudioSndCrdMono; diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 3196e99e..1d49ee49 100755 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -816,8 +816,8 @@ void CClientDlg::ShowConnectionSetupDialog() { // get the central server address string const QString strCurCentServAddr = - SELECT_SERVER_ADDRESS ( pClient->GetUseDefaultCentralServerAddress(), - pClient->GetServerListCentralServerAddress() ); + NetworkUtil::GetCentralServerAddress ( pClient->GetCentralServerAddressType(), + pClient->GetServerListCentralServerAddress() ); // init the connect dialog ConnectDlg.Init ( strCurCentServAddr, pClient->vstrIPAddress ); diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 98f8a1f3..d0addd32 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -244,19 +244,16 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, // central server address QString strCentrServAddr = tr ( "Central Server Address: The " "central server address is the IP address or URL of the central server " - "at which the server list of the connection dialog is managed. If the " - "Default check box is checked, the default central server address is " - "shown read-only." ); + "at which the server list of the connection dialog is managed. With the " + "central server address type either the local region can be selected of " + "the default central servers or a manual address can be specified." ); lblCentralServerAddress->setWhatsThis ( strCentrServAddr ); - chbDefaultCentralServer->setWhatsThis ( strCentrServAddr ); + cbxCentServAddrType->setWhatsThis ( strCentrServAddr ); edtCentralServerAddress->setWhatsThis ( strCentrServAddr ); - chbDefaultCentralServer->setAccessibleName ( - tr ( "Default central server check box" ) ); - - edtCentralServerAddress->setAccessibleName ( - tr ( "Central server address line edit" ) ); + cbxCentServAddrType->setAccessibleName ( tr ( "Default central server type combo box" ) ); + edtCentralServerAddress->setAccessibleName ( tr ( "Central server address line edit" ) ); // current connection status parameter QString strConnStats = tr ( "Current Connection Status " @@ -346,15 +343,12 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, cbxAudioQuality->addItem ( "High" ); // AQ_HIGH cbxAudioQuality->setCurrentIndex ( static_cast ( pClient->GetAudioQuality() ) ); - // update default central server address check box - if ( pClient->GetUseDefaultCentralServerAddress() ) - { - chbDefaultCentralServer->setCheckState ( Qt::Checked ); - } - else - { - chbDefaultCentralServer->setCheckState ( Qt::Unchecked ); - } + // central server address type combo box + cbxCentServAddrType->clear(); + cbxCentServAddrType->addItem ( "Manual" ); // AT_MANUAL + cbxCentServAddrType->addItem ( "Default" ); // AT_DEFAULT + cbxCentServAddrType->addItem ( "Default (North America)" ); // AT_NORTH_AMERICA + cbxCentServAddrType->setCurrentIndex ( static_cast ( pClient->GetCentralServerAddressType() ) ); UpdateCentralServerDependency(); // update new client fader level edit box @@ -401,9 +395,6 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, QObject::connect ( chbAutoJitBuf, SIGNAL ( stateChanged ( int ) ), this, SLOT ( OnAutoJitBufStateChanged ( int ) ) ); - QObject::connect ( chbDefaultCentralServer, SIGNAL ( stateChanged ( int ) ), - this, SLOT ( OnDefaultCentralServerStateChanged ( int ) ) ); - // line edits QObject::connect ( edtCentralServerAddress, SIGNAL ( editingFinished() ), this, SLOT ( OnCentralServerAddressEditingFinished() ) ); @@ -433,6 +424,9 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, QObject::connect ( cbxAudioQuality, SIGNAL ( activated ( int ) ), this, SLOT ( OnAudioQualityActivated ( int ) ) ); + QObject::connect ( cbxCentServAddrType, SIGNAL ( activated ( int ) ), + this, SLOT ( OnCentServAddrTypeActivated ( int ) ) ); + // buttons QObject::connect ( butDriverSetup, SIGNAL ( clicked() ), this, SLOT ( OnDriverSetupClicked() ) ); @@ -591,8 +585,7 @@ void CClientSettingsDlg::UpdateSoundChannelSelectionFrame() void CClientSettingsDlg::UpdateCentralServerDependency() { - const bool bCurUseDefCentServAddr = - pClient->GetUseDefaultCentralServerAddress(); + const bool bCurUseDefCentServAddr = ( pClient->GetCentralServerAddressType() != AT_MANUAL ); // make sure the line edit does not fire signals when we update the text edtCentralServerAddress->blockSignals ( true ); @@ -696,6 +689,15 @@ void CClientSettingsDlg::OnAudioQualityActivated ( int iQualityIdx ) UpdateDisplay(); // upload rate will be changed } +void CClientSettingsDlg::OnCentServAddrTypeActivated ( int iTypeIdx ) +{ + // apply new setting to the client + pClient->SetCentralServerAddressType ( static_cast ( iTypeIdx ) ); + + // update GUI dependencies + UpdateCentralServerDependency(); +} + void CClientSettingsDlg::OnAutoJitBufStateChanged ( int value ) { pClient->SetDoAutoSockBufSize ( value == Qt::Checked ); @@ -722,15 +724,6 @@ void CClientSettingsDlg::OnDisplayChannelLevelsStateChanged ( int value ) emit DisplayChannelLevelsChanged(); } -void CClientSettingsDlg::OnDefaultCentralServerStateChanged ( int value ) -{ - // apply new setting to the client - pClient->SetUseDefaultCentralServerAddress ( value == Qt::Checked ); - - // update GUI dependencies - UpdateCentralServerDependency(); -} - void CClientSettingsDlg::OnCentralServerAddressEditingFinished() { // store new setting in the client diff --git a/src/clientsettingsdlg.h b/src/clientsettingsdlg.h index ce478cdf..23b2aad7 100755 --- a/src/clientsettingsdlg.h +++ b/src/clientsettingsdlg.h @@ -91,7 +91,6 @@ protected: void OnAutoJitBufStateChanged ( int value ); void OnGUIDesignFancyStateChanged ( int value ); void OnDisplayChannelLevelsStateChanged ( int value ); - void OnDefaultCentralServerStateChanged ( int value ); void OnCentralServerAddressEditingFinished(); void OnNewClientLevelEditingFinished(); void OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* button ); @@ -102,6 +101,7 @@ protected: void OnROutChanActivated ( int iChanIdx ); void OnAudioChannelsActivated ( int iChanIdx ); void OnAudioQualityActivated ( int iQualityIdx ); + void OnCentServAddrTypeActivated ( int iTypeIdx ); void OnDriverSetupClicked(); signals: diff --git a/src/clientsettingsdlgbase.ui b/src/clientsettingsdlgbase.ui index 65cc3650..5028d30f 100755 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -7,7 +7,7 @@ 0 0 567 - 351 + 371 @@ -557,11 +557,7 @@ - - - Default - - + @@ -731,7 +727,7 @@ edtNewClientLevel chbGUIDesignFancy chbDisplayChannelLevels - chbDefaultCentralServer + cbxCentServAddrType edtCentralServerAddress diff --git a/src/global.h b/src/global.h index aa5a8024..cd2b74d2 100755 --- a/src/global.h +++ b/src/global.h @@ -105,7 +105,6 @@ LED bar: lbr // default server address #define DEFAULT_SERVER_ADDRESS "jamulus.fischvolk.de" #define DEFAULT_SERVER_NAME "Central Server" -#define SELECT_SERVER_ADDRESS(a, b) ((a) ? (DEFAULT_SERVER_ADDRESS) : (b)) // download URL #define LLCON_DOWNLOAD_URL "http://sourceforge.net/projects/llcon/files" diff --git a/src/main.cpp b/src/main.cpp index 46a7a2a2..90e137c8 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -545,11 +545,6 @@ int main ( int argc, char** argv ) eLicenceType ); if ( bUseGUI ) { - // special case for the GUI mode: as the default we want to use - // the default central server address (if not given in the - // settings file) - Server.SetUseDefaultCentralServerAddress ( true ); - // special case for the GUI mode: we want the licenct type to be // creative commons per default (if not given in the settings file) Server.SetLicenceType ( LT_CREATIVECOMMONS ); diff --git a/src/res/homepage/manual.md b/src/res/homepage/manual.md index 6b88035a..95e8931b 100644 --- a/src/res/homepage/manual.md +++ b/src/res/homepage/manual.md @@ -219,7 +219,8 @@ If enabled, the channel input level for each connected client will be displayed ![Central server address](centralserveraddress.png) The central server address is the IP address or URL of the central server at which the server list of the connection -dialog is managed. If the Default check box is checked, the default central server address is shown read-only. +dialog is managed. With the central server address type either the local region can be selected of the default +central servers or a manual address can be specified. ### Current connection status parameter diff --git a/src/server.h b/src/server.h index 25eebb1d..e8e6d225 100755 --- a/src/server.h +++ b/src/server.h @@ -168,11 +168,11 @@ public: QString GetServerListCentralServerAddress() { return ServerListManager.GetCentralServerAddress(); } - void SetUseDefaultCentralServerAddress ( const bool bNUDCSeAddr ) - { ServerListManager.SetUseDefaultCentralServerAddress ( bNUDCSeAddr ); } + void SetCentralServerAddressType ( const ECSAddType eNCSAT ) + { ServerListManager.SetCentralServerAddressType ( eNCSAT ); } - bool GetUseDefaultCentralServerAddress() - { return ServerListManager.GetUseDefaultCentralServerAddress(); } + ECSAddType GetCentralServerAddressType() + { return ServerListManager.GetCentralServerAddressType(); } void SetServerName ( const QString& strNewName ) { ServerListManager.SetServerName ( strNewName ); } diff --git a/src/serverdlg.cpp b/src/serverdlg.cpp index e4bfe7d8..83de9f1a 100755 --- a/src/serverdlg.cpp +++ b/src/serverdlg.cpp @@ -73,18 +73,16 @@ CServerDlg::CServerDlg ( CServer* pNServP, // central server address QString strCentrServAddr = tr ( "Central Server Address: The " "Central server address is the IP address or URL of the central server " - "at which this server is registered. If the Default check box is " - "checked, the default central server address is shown read-only." ); + "at which this server is registered. With the central server address " + "type either the local region can be selected of the default central " + "servers or a manual address can be specified." ); lblCentralServerAddress->setWhatsThis ( strCentrServAddr ); - chbDefaultCentralServer->setWhatsThis ( strCentrServAddr ); + cbxCentServAddrType->setWhatsThis ( strCentrServAddr ); edtCentralServerAddress->setWhatsThis ( strCentrServAddr ); - chbDefaultCentralServer->setAccessibleName ( - tr ( "Default central server check box" ) ); - - edtCentralServerAddress->setAccessibleName ( - tr ( "Central server address line edit" ) ); + cbxCentServAddrType->setAccessibleName ( tr ( "Default central server type combo box" ) ); + edtCentralServerAddress->setAccessibleName ( tr ( "Central server address line edit" ) ); // server name QString strServName = tr ( "Server Name: The server name identifies " @@ -183,15 +181,12 @@ lvwClients->setMinimumHeight ( 140 ); vecpListViewItems[i]->setHidden ( true ); } - // update default central server address check box - if ( pServer->GetUseDefaultCentralServerAddress() ) - { - chbDefaultCentralServer->setCheckState ( Qt::Checked ); - } - else - { - chbDefaultCentralServer->setCheckState ( Qt::Unchecked ); - } + // central server address type combo box + cbxCentServAddrType->clear(); + cbxCentServAddrType->addItem ( "Manual" ); // AT_MANUAL + cbxCentServAddrType->addItem ( "Default" ); // AT_DEFAULT + cbxCentServAddrType->addItem ( "Default (North America)" ); // AT_NORTH_AMERICA + cbxCentServAddrType->setCurrentIndex ( static_cast ( pServer->GetCentralServerAddressType() ) ); // update server name line edit edtServerName->setText ( pServer->GetServerName() ); @@ -293,9 +288,6 @@ lvwClients->setMinimumHeight ( 140 ); QObject::connect ( chbRegisterServer, SIGNAL ( stateChanged ( int ) ), this, SLOT ( OnRegisterServerStateChanged ( int ) ) ); - QObject::connect ( chbDefaultCentralServer, SIGNAL ( stateChanged ( int ) ), - this, SLOT ( OnDefaultCentralServerStateChanged ( int ) ) ); - QObject::connect ( chbStartOnOSStart, SIGNAL ( stateChanged ( int ) ), this, SLOT ( OnStartOnOSStartStateChanged ( int ) ) ); @@ -316,6 +308,9 @@ lvwClients->setMinimumHeight ( 140 ); QObject::connect ( cbxLocationCountry, SIGNAL ( activated ( int ) ), this, SLOT ( OnLocationCountryActivated ( int ) ) ); + QObject::connect ( cbxCentServAddrType, SIGNAL ( activated ( int ) ), + this, SLOT ( OnCentServAddrTypeActivated ( int ) ) ); + // timers QObject::connect ( &Timer, SIGNAL ( timeout() ), this, SLOT ( OnTimer() ) ); @@ -372,16 +367,6 @@ void CServerDlg::OnUseCCLicenceStateChanged ( int value ) } } -void CServerDlg::OnDefaultCentralServerStateChanged ( int value ) -{ - // apply new setting to the server and update it - pServer->SetUseDefaultCentralServerAddress ( value == Qt::Checked ); - pServer->UpdateServerList(); - - // update GUI dependencies - UpdateGUIDependencies(); -} - void CServerDlg::OnRegisterServerStateChanged ( int value ) { const bool bRegState = ( value == Qt::Checked ); @@ -451,6 +436,16 @@ void CServerDlg::OnLocationCountryActivated ( int iCntryListItem ) pServer->UpdateServerList(); } +void CServerDlg::OnCentServAddrTypeActivated ( int iTypeIdx ) +{ + // apply new setting to the server and update it + pServer->SetCentralServerAddressType ( static_cast ( iTypeIdx ) ); + pServer->UpdateServerList(); + + // update GUI dependencies + UpdateGUIDependencies(); +} + void CServerDlg::OnSysTrayActivated ( QSystemTrayIcon::ActivationReason ActReason ) { // on double click on the icon, show window in fore ground @@ -515,13 +510,12 @@ void CServerDlg::UpdateGUIDependencies() // get the states which define the GUI dependencies from the server const bool bCurSerListEnabled = pServer->GetServerListEnabled(); - const bool bCurUseDefCentServAddr = - pServer->GetUseDefaultCentralServerAddress(); + const bool bCurUseDefCentServAddr = ( pServer->GetCentralServerAddressType() != AT_MANUAL ); // if register server is not enabled, we disable all the configuration // controls for the server list - chbDefaultCentralServer->setEnabled ( bCurSerListEnabled ); - grbServerInfo->setEnabled ( bCurSerListEnabled ); + cbxCentServAddrType->setEnabled ( bCurSerListEnabled ); + grbServerInfo->setEnabled ( bCurSerListEnabled ); // make sure the line edit does not fire signals when we update the text edtCentralServerAddress->blockSignals ( true ); diff --git a/src/serverdlg.h b/src/serverdlg.h index ece00181..50f40b27 100755 --- a/src/serverdlg.h +++ b/src/serverdlg.h @@ -84,13 +84,13 @@ public slots: void OnAboutToQuit() { pSettings->Save(); } void OnRegisterServerStateChanged ( int value ); - void OnDefaultCentralServerStateChanged ( int value ); void OnStartOnOSStartStateChanged ( int value ); void OnUseCCLicenceStateChanged ( int value ); void OnCentralServerAddressEditingFinished(); void OnServerNameTextChanged ( const QString& strNewName ); void OnLocationCityTextChanged ( const QString& strNewCity ); void OnLocationCountryActivated ( int iCntryListItem ); + void OnCentServAddrTypeActivated ( int iTypeIdx ); void OnTimer(); void OnServerStarted() { UpdateSystemTrayIcon ( true ); } void OnServerStopped() { UpdateSystemTrayIcon ( false ); } diff --git a/src/serverdlgbase.ui b/src/serverdlgbase.ui index 08e420b0..8b28750d 100755 --- a/src/serverdlgbase.ui +++ b/src/serverdlgbase.ui @@ -82,11 +82,7 @@ - - - Default - - + @@ -190,7 +186,7 @@ chbUseCCLicence chbRegisterServer edtCentralServerAddress - chbDefaultCentralServer + cbxCentServAddrType edtServerName edtLocationCity cbxLocationCountry diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 881033ca..5dba5d74 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -31,11 +31,11 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum, const int iNumChannels, const bool bNCentServPingServerInList, CProtocol* pNConLProt ) - : iPortNumber ( iNPortNum ), - iNumPredefinedServers ( 0 ), - bUseDefaultCentralServerAddress ( false ), // must be false for the "no GUI" case - bCentServPingServerInList ( bNCentServPingServerInList ), - pConnLessProtocol ( pNConLProt ) + : iPortNumber ( iNPortNum ), + iNumPredefinedServers ( 0 ), + eCentralServerAddressType ( AT_MANUAL ), // must be AT_MANUAL for the "no GUI" case + bCentServPingServerInList ( bNCentServPingServerInList ), + pConnLessProtocol ( pNConLProt ) { // set the central server address SetCentralServerAddress ( sNCentServAddr ); @@ -199,7 +199,7 @@ void CServerListManager::SetCentralServerAddress ( const QString sNCentServAddr ( ( !strCentralServerAddress.toLower().compare ( "localhost" ) || !strCentralServerAddress.compare ( "127.0.0.1" ) ) && - ( !bUseDefaultCentralServerAddress ) + ( eCentralServerAddressType == AT_MANUAL ) ); bEnabled = true; @@ -480,8 +480,8 @@ void CServerListManager::SlaveServerRegisterServer ( const bool bIsRegister ) // get the correct central server address const QString strCurCentrServAddr = - SELECT_SERVER_ADDRESS ( bUseDefaultCentralServerAddress, - strCentralServerAddress ); + NetworkUtil::GetCentralServerAddress ( eCentralServerAddressType, + strCentralServerAddress ); // For the slave server, the slave server properties are stored in the // very first item in the server list (which is actually no server list diff --git a/src/serverlist.h b/src/serverlist.h index ce1571b7..5a5e7984 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -142,11 +142,8 @@ public: void SetCentralServerAddress ( const QString sNCentServAddr ); QString GetCentralServerAddress() { return strCentralServerAddress; } - void SetUseDefaultCentralServerAddress ( const bool bNUDCSeAddr ) - { bUseDefaultCentralServerAddress = bNUDCSeAddr; } - - bool GetUseDefaultCentralServerAddress() - { return bUseDefaultCentralServerAddress; } + void SetCentralServerAddressType ( const ECSAddType eNCSAT ) { eCentralServerAddressType = eNCSAT; } + ECSAddType GetCentralServerAddressType() { return eCentralServerAddressType; } bool GetIsCentralServer() const { return bIsCentralServer; } @@ -195,7 +192,7 @@ protected: int iNumPredefinedServers; bool bEnabled; bool bIsCentralServer; - bool bUseDefaultCentralServerAddress; + ECSAddType eCentralServerAddressType; bool bCentServPingServerInList; CHostAddress SlaveCurCentServerHostAddress; diff --git a/src/settings.cpp b/src/settings.cpp index 36861f09..69953a72 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -274,11 +274,27 @@ void CSettings::Load() pClient->SetServerListCentralServerAddress ( GetIniSetting ( IniXMLDocument, "client", "centralservaddr" ) ); - // use default central server address flag - if ( GetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", bValue ) ) + // central server address type + if ( GetNumericIniSet ( IniXMLDocument, "client", "centservaddrtype", + 0, 2 /* AT_NORTH_AMERICA */, iValue ) ) { - pClient->SetUseDefaultCentralServerAddress ( bValue ); + pClient->SetCentralServerAddressType ( static_cast ( iValue ) ); } + else + { + // if no address type is given, choose one from the operating system locale + pClient->SetCentralServerAddressType ( CLocale::GetCentralServerAddressType ( QLocale::system().country() ) ); + } + +// TODO compatibility to old version +if ( GetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", bValue ) ) +{ + // only the case that manual was set in old ini must be considered + if ( !bValue ) + { + pClient->SetCentralServerAddressType ( AT_MANUAL ); + } +} // window position of the main window pClient->vecWindowPosMain = FromBase64ToByteArray ( @@ -328,12 +344,28 @@ void CSettings::Load() { // server: - // use default central server address flag (note that it is important + // central server address type (note that it is important // to set this setting prior to the "central server address") - if ( GetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr", bValue ) ) + if ( GetNumericIniSet ( IniXMLDocument, "server", "centservaddrtype", + 0, 2 /* AT_NORTH_AMERICA */, iValue ) ) { - pServer->SetUseDefaultCentralServerAddress ( bValue ); + pServer->SetCentralServerAddressType ( static_cast ( iValue ) ); } + else + { + // if no address type is given, choose one from the operating system locale + pServer->SetCentralServerAddressType ( CLocale::GetCentralServerAddressType ( QLocale::system().country() ) ); + } + +// TODO compatibility to old version +if ( GetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr", bValue ) ) +{ + // only the case that manual was set in old ini must be considered + if ( !bValue ) + { + pServer->SetCentralServerAddressType ( AT_MANUAL ); + } +} // central server address (to be set after the "use default central // server address) @@ -519,9 +551,9 @@ void CSettings::Save() PutIniSetting ( IniXMLDocument, "client", "centralservaddr", pClient->GetServerListCentralServerAddress() ); - // use default central server address flag - SetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", - pClient->GetUseDefaultCentralServerAddress() ); + // central server address type + SetNumericIniSet ( IniXMLDocument, "client", "centservaddrtype", + static_cast ( pClient->GetCentralServerAddressType() ) ); // window position of the main window PutIniSetting ( IniXMLDocument, "client", "winposmain_base64", @@ -567,9 +599,9 @@ void CSettings::Save() PutIniSetting ( IniXMLDocument, "server", "centralservaddr", pServer->GetServerListCentralServerAddress() ); - // use default central server address flag - SetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr", - pServer->GetUseDefaultCentralServerAddress() ); + // central server address type + SetNumericIniSet ( IniXMLDocument, "server", "centservaddrtype", + static_cast ( pServer->GetCentralServerAddressType() ) ); // server list enabled flag SetFlagIniSet ( IniXMLDocument, "server", "servlistenabled", diff --git a/src/util.cpp b/src/util.cpp index d43dbe55..1af4d1ed 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -908,6 +908,17 @@ CHostAddress NetworkUtil::GetLocalAddress() } } +QString NetworkUtil::GetCentralServerAddress ( const ECSAddType eCentralServerAddressType, + const QString& strCentralServerAddress ) +{ + switch ( eCentralServerAddressType ) + { + case AT_MANUAL: return strCentralServerAddress; + case AT_NORTH_AMERICA: return QString ( "%1:%2" ).arg ( DEFAULT_SERVER_ADDRESS ).arg ( LLCON_PORT_NUMBER_NORTHAMERICA ); + default: return DEFAULT_SERVER_ADDRESS; // AT_DEFAULT + } +} + // Instrument picture data base ------------------------------------------------ CVector& CInstPictures::GetTable() @@ -992,7 +1003,7 @@ QString CInstPictures::GetName ( const int iInstrument ) } -// Country flag icon data base ------------------------------------------------- +// Locale management class ----------------------------------------------------- QString CLocale::GetCountryFlagIconsResourceReference ( const QLocale::Country eCountry ) { QString strReturn = ""; @@ -1248,6 +1259,23 @@ QString CLocale::GetCountryFlagIconsResourceReference ( const QLocale::Country e return strReturn; } +ECSAddType CLocale::GetCentralServerAddressType ( const QLocale::Country eCountry ) +{ +// TODO this is the initial implementation and should be extended in the future, +// maybe there is/will be some function in Qt to get the continent + switch ( eCountry ) + { + case QLocale::UnitedStates: + case QLocale::Canada: + case QLocale::Mexico: + case QLocale::Greenland: + return AT_NORTH_AMERICA; + + default: + return AT_DEFAULT; + } +} + // Console writer factory ------------------------------------------------------ QTextStream* ConsoleWriterFactory::get() diff --git a/src/util.h b/src/util.h index 12800ef0..fcc86d2d 100755 --- a/src/util.h +++ b/src/util.h @@ -518,9 +518,9 @@ enum EAudChanConf enum EAudComprType { // used for protocol -> enum values must be fixed! - CT_NONE = 0, - CT_CELT = 1, - CT_OPUS = 2, + CT_NONE = 0, + CT_CELT = 1, + CT_OPUS = 2, CT_OPUS64 = 3 // using OPUS with 64 samples frame size }; @@ -563,6 +563,15 @@ enum ELicenceType }; +// Central server address type ------------------------------------------------- +enum ECSAddType +{ + AT_MANUAL = 0, + AT_DEFAULT = 1, // Europe and others + AT_NORTH_AMERICA = 2 +}; + + // Skill level enum ------------------------------------------------------------ enum ESkillLevel { @@ -738,7 +747,8 @@ protected: class CLocale { public: - static QString GetCountryFlagIconsResourceReference ( const QLocale::Country eCountry ); + static QString GetCountryFlagIconsResourceReference ( const QLocale::Country eCountry ); + static ECSAddType GetCentralServerAddressType ( const QLocale::Country eCountry ); }; @@ -980,6 +990,8 @@ public: CHostAddress& HostAddress ); static CHostAddress GetLocalAddress(); + static QString GetCentralServerAddress ( const ECSAddType eCentralServerAddressType, + const QString& strCentralServerAddress ); };