From 5c909dc17637893436ef6e3fac9161baee9fcef4 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 24 Jan 2015 15:38:39 +0000 Subject: [PATCH] support for a country flag icon on the fader tag --- ChangeLog | 5 +- src/audiomixerboard.cpp | 13 ++++-- src/clientdlg.cpp | 91 +++++++++++++++++++++++++++++++++++-- src/clientdlg.h | 3 ++ src/res/flags/flagnone.png | Bin 0 -> 418 bytes src/settings.cpp | 16 +++++++ src/util.cpp | 42 +++++++++++++++++ src/util.h | 9 ++++ 8 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 src/res/flags/flagnone.png diff --git a/ChangeLog b/ChangeLog index 96311f6d..30721916 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ 3.3.6 -- a licence agreement dialog can be requested by the server +- support for a country flag icon on the fader tag +- a licence agreement dialog can be requested by the server 3.3.5 (2014-07-30) @@ -11,6 +12,7 @@ - added a Linux jamulus.desktop file + 3.3.4 (2014-02-25) - true stereo reverberation effect (previously it was a mono reverberation @@ -28,6 +30,7 @@ - bug fix: the fader level could not be changed if the fader was on solo + 3.3.3 (2013-12-30) - support for storing/recovering the window positions diff --git a/src/audiomixerboard.cpp b/src/audiomixerboard.cpp index 31ee044c..445d27a4 100755 --- a/src/audiomixerboard.cpp +++ b/src/audiomixerboard.cpp @@ -298,12 +298,9 @@ void CChannelFader::SetCountryFlag ( const QLocale::Country eCountry ) { if ( eCountry != QLocale::AnyCountry ) { - // get the resource reference string for this country flag - const QString strCurResourceRef = ":/png/flags/res/flags/" + - QLocale ( QLocale::AnyLanguage, eCountry ).bcp47Name() + ".png"; - // try to load the country flag icon - QPixmap CountryFlagPixmap ( strCurResourceRef ); + QPixmap CountryFlagPixmap ( + CCountyFlagIcons::GetResourceReference ( eCountry ) ); // first check if resource reference was valid if ( CountryFlagPixmap.isNull() ) @@ -322,6 +319,12 @@ void CChannelFader::SetCountryFlag ( const QLocale::Country eCountry ) plblCountryFlag->setVisible ( true ); } } + else + { + // disable country flag and tool tip + plblCountryFlag->setVisible ( false ); + plblCountryFlag->setToolTip ( "" ); + } } double CChannelFader::CalcFaderGain ( const int value ) diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index fefb7c55..e5893a48 100755 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -96,17 +96,17 @@ CClientDlg::CClientDlg ( CClient* pNCliP, "and disconnecting the " ) + APP_NAME + tr ( " software." ) ); // fader tag - QString strFaderTag = tr ( "Your Alias/Instrument: Set your name " + QString strFaderTag = tr ( "Your Alias/Instrument/Country: Set your name " "or an alias here so that the other musicians you want to play with " "know who you are. Additionally you may set an instrument picture of " - "the instrument you play. " + "the instrument you play and a flag of the country you are living. " "What you set here will appear at your fader on the mixer board when " "you are connected to a " ) + APP_NAME + tr ( " server. This tag will " "also show up at each client which is connected to the same server as " "you. If the fader tag is empty, the IP address is shown instead." ); QString strFaderTagTT = tr ( "Set your name and/or instrument and/or " - "pseoudonym here so that the other musicians can identify you." ) + + "country here so that the other musicians can identify you." ) + TOOLTIP_COM_END_TEXT; lblServerTag->setWhatsThis ( strFaderTag ); @@ -117,6 +117,9 @@ CClientDlg::CClientDlg ( CClient* pNCliP, butInstPicture->setWhatsThis ( strFaderTag ); butInstPicture->setToolTip ( strFaderTagTT ); butInstPicture->setAccessibleName ( tr ( "Instrument picture button" ) ); + butCountryFlag->setWhatsThis ( strFaderTag ); + butCountryFlag->setToolTip ( strFaderTagTT ); + butCountryFlag->setAccessibleName ( tr ( "Country flag button" ) ); // local audio input fader QString strAudFader = tr ( "Local Audio Input Fader: With the " @@ -212,11 +215,15 @@ CClientDlg::CClientDlg ( CClient* pNCliP, MainMixerBoard->vecStoredFaderLevels = pClient->vecStoredFaderLevels; MainMixerBoard->vecStoredFaderIsSolo = pClient->vecStoredFaderIsSolo; - // init fader tag line edit and instrument picture + // init fader tag line edit, instrument picture and country flag edtFaderTag->setText ( pClient->ChannelInfo.strName ); + butInstPicture->setIcon ( QIcon ( CInstPictures::GetResourceReference ( pClient->ChannelInfo.iInstrument ) ) ); + butCountryFlag->setIcon ( QIcon ( + CCountyFlagIcons::GetResourceReference ( pClient->ChannelInfo.eCountry ) ) ); + // init status label OnTimerStatus(); @@ -333,6 +340,51 @@ CClientDlg::CClientDlg ( CClient* pNCliP, } + // Country flag icons popup menu ------------------------------------------- + pCountryFlagPopupMenu = new QMenu ( this ); + + // add an entry for all known country flags + for ( int iCurCntry = static_cast ( QLocale::AnyCountry ); + iCurCntry < static_cast ( QLocale::LastCountry ); iCurCntry++ ) + { + // the "Default" country gets a special icon + QIcon CurFlagIcon; + QString sCurCountryName; + + if ( static_cast ( iCurCntry ) == QLocale::AnyCountry ) + { + // default icon and name for no flag selected + CurFlagIcon.addFile ( ":/png/flags/res/flags/flagnone.png" ); + sCurCountryName = "None"; + } + else + { + // get current country enum + QLocale::Country eCountry = + static_cast ( iCurCntry ); + + // get resource file name + CurFlagIcon.addFile ( CCountyFlagIcons::GetResourceReference ( eCountry ) ); + + // get the country name + sCurCountryName = QLocale::countryToString ( eCountry ); + } + + // only add the entry if a flag is available + if ( !CurFlagIcon.isNull() ) + { + // create a menu action with text and image + QAction* pCurAction = + new QAction ( CurFlagIcon, sCurCountryName, this ); + + // add data to identify the action data when it is triggered + pCurAction->setData ( iCurCntry ); + + pCountryFlagPopupMenu->addAction ( pCurAction ); + } + } + + // Window positions -------------------------------------------------------- // main window if ( !pClient->vecWindowPosMain.isEmpty() && !pClient->vecWindowPosMain.isNull() ) @@ -382,6 +434,9 @@ CClientDlg::CClientDlg ( CClient* pNCliP, QObject::connect ( butInstPicture, SIGNAL ( clicked() ), this, SLOT ( OnInstPictureBut() ) ); + QObject::connect ( butCountryFlag, SIGNAL ( clicked() ), + this, SLOT ( OnCountryFlagBut() ) ); + // check boxes QObject::connect ( chbSettings, SIGNAL ( stateChanged ( int ) ), this, SLOT ( OnSettingsStateChanged ( int ) ) ); @@ -424,6 +479,9 @@ CClientDlg::CClientDlg ( CClient* pNCliP, QObject::connect ( pInstrPictPopupMenu, SIGNAL ( triggered ( QAction* ) ), this, SLOT ( OnInstPicturesMenuTriggered ( QAction* ) ) ); + QObject::connect ( pCountryFlagPopupMenu, SIGNAL ( triggered ( QAction* ) ), + this, SLOT ( OnCountryFlagMenuTriggered ( QAction* ) ) ); + // other QObject::connect ( pClient, SIGNAL ( ConClientListNameMesReceived ( CVector ) ), @@ -685,6 +743,14 @@ void CClientDlg::OnInstPictureBut() pInstrPictPopupMenu->exec ( this->mapToGlobal ( butInstPicture->pos() ) ); } +void CClientDlg::OnCountryFlagBut() +{ + // open a menu which shows all available country flags which + // always appears at the same position relative to the country + // flags button + pCountryFlagPopupMenu->exec ( this->mapToGlobal ( butCountryFlag->pos() ) ); +} + void CClientDlg::OnInstPicturesMenuTriggered ( QAction* SelAction ) { // get selected instrument @@ -701,6 +767,23 @@ void CClientDlg::OnInstPicturesMenuTriggered ( QAction* SelAction ) CInstPictures::GetResourceReference ( iSelInstrument ) ) ); } +void CClientDlg::OnCountryFlagMenuTriggered ( QAction* SelAction ) +{ + // get selected country + const QLocale::Country eSelCountry = + static_cast ( SelAction->data().toInt() ); + + // set the new value in the data base + pClient->ChannelInfo.eCountry = eSelCountry; + + // update channel info at the server + pClient->SetRemoteInfo(); + + // update icon on the instrument selection button + butCountryFlag->setIcon ( QIcon ( + CCountyFlagIcons::GetResourceReference ( eSelCountry ) ) ); +} + void CClientDlg::OnChatTextReceived ( QString strChatText ) { ChatDlg.AddChatText ( strChatText ); diff --git a/src/clientdlg.h b/src/clientdlg.h index 03f5c542..77d7e8cb 100755 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -105,6 +105,7 @@ protected: QMenu* pViewMenu; QMenuBar* pMenu; QMenu* pInstrPictPopupMenu; + QMenu* pCountryFlagPopupMenu; CClientSettingsDlg ClientSettingsDlg; CChatDlg ChatDlg; @@ -116,6 +117,7 @@ public slots: void OnConnectDisconBut(); void OnInstPictureBut(); + void OnCountryFlagBut(); void OnTimerSigMet(); void OnTimerBuffersLED(); @@ -140,6 +142,7 @@ public slots: void OnOpenAnalyzerConsole() { ShowAnalyzerConsole(); } void OnInstPicturesMenuTriggered ( QAction* SelAction ); + void OnCountryFlagMenuTriggered ( QAction* SelAction ); void OnSettingsStateChanged ( int value ); void OnChatStateChanged ( int value ); diff --git a/src/res/flags/flagnone.png b/src/res/flags/flagnone.png new file mode 100644 index 0000000000000000000000000000000000000000..af4134d26b729e177e9248b37fcac807f1a0daff GIT binary patch literal 418 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~o!3HGD9`RZNDYhhUcNd2LAh=-f^2tCE&H|6f zVxTHv5N2eUHAey{$X?><>&kwgQG%0+_lSDA76SvLzNd?0h{pNaiMs2U3`JV^$3+F` zG_W3E;?O>@NX=0xja%YCqCmv9hNDRvIobku=rOrww6*N)n4bBgHvW>yOWWnow_Sfy zxo*$IRLR+A+a7=P2o%{8rOVdLxcDMR_S^1jK)JJNpPz2H{PIJuiSJAwwH5zT+XN=8 zs@Q$^(W|oEI@7(&cFVROZakXAc%W>zYKsGhVqB6dOES+f35JlVU#oZ>BBwEYsj_A0 zTIApoaCOD@bCxbF&tq~zLz53ZElRYT&pbhev)7F|^r+?WzjepM4&^`l{L^RFvWoXF zzyIzz{y1WF+0RtA8E4Zf-b?beuL;wB_4QY`q{BVyinRUrnGNRp2~OlMj+}NQ{^hDu zFH3$!RUZp$idy^aqxjo0X@>WIj~hRhU|e@y`@f)5$Fr;&QGTaC+n=1=6KM(zO$JX_ KKbLh*2~7acSgzgx literal 0 HcmV?d00001 diff --git a/src/settings.cpp b/src/settings.cpp index 52f37c0e..0038a044 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -107,6 +107,18 @@ void CSettings::Load() pClient->ChannelInfo.iInstrument = iValue; } + // country + if ( GetNumericIniSet ( IniXMLDocument, "client", "country", + 0, static_cast ( QLocale::LastCountry ), iValue ) ) + { + pClient->ChannelInfo.eCountry = static_cast ( iValue ); + } + else + { + // if no country is given, use the one from the operating system + pClient->ChannelInfo.eCountry = QLocale::system().country(); + } + // audio fader if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad", AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) ) @@ -371,6 +383,10 @@ void CSettings::Save() SetNumericIniSet ( IniXMLDocument, "client", "instrument", pClient->ChannelInfo.iInstrument ); + // country + SetNumericIniSet ( IniXMLDocument, "client", "country", + static_cast ( pClient->ChannelInfo.eCountry ) ); + // audio fader SetNumericIniSet ( IniXMLDocument, "client", "audfad", pClient->GetAudioInFader() ); diff --git a/src/util.cpp b/src/util.cpp index 171b8989..459c8950 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -670,6 +670,48 @@ QString CInstPictures::GetName ( const int iInstrument ) } +// Country flag icon data base ------------------------------------------------- +QString CCountyFlagIcons::GetResourceReference ( const QLocale::Country eCountry ) +{ + QString strReturn = ""; + + // special flag for none + if ( eCountry == QLocale::AnyCountry ) + { + strReturn = ":/png/flags/res/flags/flagnone.png"; + } + else + { + // There is no direct query of the country code in Qt, therefore we use a + // workaround: Get the matching locales properties and split the name of + // that since the second part is the country code + QList vCurLocaleList = QLocale::matchingLocales ( QLocale::AnyLanguage, + QLocale::AnyScript, + eCountry ); + + // check if the matching locales query was successful + if ( vCurLocaleList.size() > 0 ) + { + QStringList vstrLocParts = vCurLocaleList.at ( 0 ).name().split("_"); + + // the second split contains the name we need + if ( vstrLocParts.size() > 1 ) + { + strReturn = + ":/png/flags/res/flags/" + vstrLocParts.at ( 1 ).toLower() + ".png"; + + // check if file actually exists, if not then invalidate reference + if ( !QFile::exists ( strReturn ) ) + { + strReturn = ""; + } + } + } + } + + return strReturn; +} + /******************************************************************************\ * Global Functions Implementation * diff --git a/src/util.h b/src/util.h index be54b8c6..4721df47 100755 --- a/src/util.h +++ b/src/util.h @@ -662,6 +662,15 @@ protected: }; +// Country flag icon data base ------------------------------------------------- +// this is a pure static class +class CCountyFlagIcons +{ +public: + static QString GetResourceReference ( const QLocale::Country eCountry ); +}; + + // Info of a channel ----------------------------------------------------------- class CChannelCoreInfo {