From ea9b0e9167ba8a09249d9f8a6da9992aa8a13f01 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sun, 15 Mar 2020 08:26:29 +0100 Subject: [PATCH] change audio directory setting to language --- SGSXLConfig.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++------ SGSXLConfig.h | 5 ++-- example.cfg | 3 +-- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/SGSXLConfig.cpp b/SGSXLConfig.cpp index ddaf1e4..3d0d9c0 100644 --- a/SGSXLConfig.cpp +++ b/SGSXLConfig.cpp @@ -224,15 +224,10 @@ CSGSXLConfig::CSGSXLConfig(const std::string &pathname) //audio get_value(cfg, "audio.enabled", m_audioEnabled, true); - get_value(cfg, "audio.directory", m_audioDirectory, 0, 2000, ""); - std::string audioDirectory = std::string(DATA_DIR) + "/" + m_audioDirectory; + get_value(cfg, "audio.language", m_audioLanguage, TL_ENGLISH_UK); - if(m_audioEnabled && !std::filesystem::exists(audioDirectory)) { - m_audioEnabled = false; - printf("Audio directory: %s does not exist\n", audioDirectory.c_str()); - } if(m_audioEnabled) { - printf("Audio enabled, auudio directory : %s\n", audioDirectory.c_str()); + printf("Audio enabled\n"); } else { printf("Audio disabled\n"); } @@ -270,6 +265,12 @@ unsigned int CSGSXLConfig::getLinkCount(const char *type) return count; } +void CSGSXLConfig::getAudio(bool & enabled, TEXT_LANG & lang) const +{ + enabled = m_audioEnabled; + lang = m_audioLanguage; +} + bool CSGSXLConfig::hasErrors() { return m_hasErrors; @@ -285,6 +286,56 @@ bool CSGSXLConfig::get_value(const Config &cfg, const std::string &path, int &va return true; } +bool CSGSXLConfig::get_value(const Config &cfg, const std::string &path, TEXT_LANG& lang, TEXT_LANG defaultValue) +{ + lang = defaultValue; + std::string value; + if(cfg.lookupValue(path, value)) { + if(value == "de_DE") + { + lang = TL_DEUTSCH; + } + else if(value == "dk_DK") + { + lang = TL_DANSK; + } + else if(value == "it_IT") + { + lang = TL_ITALIANO; + } + else if(value == "fr_FR") + { + lang = TL_FRANCAIS; + } + else if(value == "es_ES") + { + lang = TL_ESPANOL; + } + else if(value == "se_SE") + { + lang = TL_SVENSKA; + } + else if(value == "pl_PL") + { + lang = TL_POLSKI; + } + else if(value == "en_US") + { + lang = TL_ENGLISH_US; + } + else if(value == "en_GB") + { + lang = TL_ENGLISH_UK; + } + else if(value == "no_NO") + { + lang = TL_NORSK; + } + } + + return true; +} + bool CSGSXLConfig::get_value(const Config &cfg, const std::string &path, bool &value, bool default_value) { if (! cfg.lookupValue(path, value)) diff --git a/SGSXLConfig.h b/SGSXLConfig.h index 84fe4ae..9b401ea 100644 --- a/SGSXLConfig.h +++ b/SGSXLConfig.h @@ -56,7 +56,7 @@ public: void getRemote(bool &enabled, std::string &password, unsigned int &port) const; - void getAudio(bool & enabled, std::string &audioDir) const; + void getAudio(bool & enabled, TEXT_LANG & lang) const; unsigned int getModCount(); unsigned int getLinkCount(const char *type); @@ -68,6 +68,7 @@ private: bool get_value(const Config &cfg, const std::string &path, int &value, int min, int max, int default_value); bool get_value(const Config &cfg, const std::string &path, bool &value, bool default_value); bool get_value(const Config &cfg, const std::string &path, std::string &value, int min, int max, const std::string &default_value); + bool get_value(const Config &cfg, const std::string &path, TEXT_LANG &lang, TEXT_LANG defaultValue); std::string m_fileName; std::string m_callsign; @@ -80,7 +81,7 @@ private: unsigned int m_remotePort; bool m_audioEnabled; - std::string m_audioDirectory; + TEXT_LANG m_audioLanguage; bool m_hasErrors; }; diff --git a/example.cfg b/example.cfg index 8242558..e6b61e1 100644 --- a/example.cfg +++ b/example.cfg @@ -9,8 +9,7 @@ gateway = { audio = { enabled = true -# The directory containing audio files for announcement. This is relative to DATADIR (see Makefile). It is case senstitive - directory = "en_GB" + language = "en_GB" } # NOTHING usually needs to be specified in the ircddb section, quadnet is the default network. To make you groups available on more than Quadnet