diff options
author | Thomas Preud'homme <robotux@celest.fr> | 2018-02-23 23:49:48 +0000 |
---|---|---|
committer | Thomas Preud'homme <robotux@celest.fr> | 2018-02-23 23:49:48 +0000 |
commit | bd56579c7d9de94c17287adefa118290e6b7ba33 (patch) | |
tree | 666d7d0b6945b442573b7a3145969f66a53aa460 /LanguagesManager.cpp | |
parent | b3c8bdcc0d1e4b2ab298847a7902b6d60410a5bc (diff) |
New upstream version 1.4.0.3
Diffstat (limited to 'LanguagesManager.cpp')
-rw-r--r-- | LanguagesManager.cpp | 152 |
1 files changed, 77 insertions, 75 deletions
diff --git a/LanguagesManager.cpp b/LanguagesManager.cpp index 5393e28..a8849c4 100644 --- a/LanguagesManager.cpp +++ b/LanguagesManager.cpp @@ -8,20 +8,21 @@ #include "LanguagesManager.h" #include "FacilityEngine.h" +#include "cpp11addition.h" /// \brief Create the manager and load the defaults variables LanguagesManager::LanguagesManager() { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); //load the rest - QStringList resourcesPaths=ResourcesManager::resourcesManager->getReadPath(); - int index=0; + std::vector<std::string> resourcesPaths=ResourcesManager::resourcesManager->getReadPath(); + unsigned int index=0; while(index<resourcesPaths.size()) { - QString composedTempPath=resourcesPaths.at(index)+QStringLiteral("Languages")+QDir::separator(); - QDir LanguagesConfiguration(composedTempPath); + std::string composedTempPath=resourcesPaths.at(index)+"Languages"+FacilityEngine::separator(); + QDir LanguagesConfiguration(QString::fromStdString(composedTempPath)); if(LanguagesConfiguration.exists()) - languagePath<<composedTempPath; + languagePath.push_back(composedTempPath); index++; } //load the plugins @@ -32,14 +33,14 @@ LanguagesManager::LanguagesManager() connect(PluginsManager::pluginsManager,&PluginsManager::onePluginWillBeRemoved, this, &LanguagesManager::onePluginWillBeRemoved,Qt::DirectConnection); #endif connect(PluginsManager::pluginsManager,&PluginsManager::pluginListingIsfinish, this, &LanguagesManager::allPluginIsLoaded,Qt::QueuedConnection); - QList<PluginsAvailable> list=PluginsManager::pluginsManager->getPluginsByCategory(PluginType_Languages); + std::vector<PluginsAvailable> list=PluginsManager::pluginsManager->getPluginsByCategory(PluginType_Languages); foreach(PluginsAvailable currentPlugin,list) emit previouslyPluginAdded(currentPlugin); PluginsManager::pluginsManager->unlockPluginListEdition(); //load the GUI option - QList<QPair<QString, QVariant> > KeysList; - KeysList.append(qMakePair(QStringLiteral("Language"),QVariant("en"))); - KeysList.append(qMakePair(QStringLiteral("Language_force"),QVariant(false))); + std::vector<std::pair<std::string, std::string> > KeysList; + KeysList.push_back(std::pair<std::string, std::string>("Language","en")); + KeysList.push_back(std::pair<std::string, std::string>("Language_force","false")); OptionEngine::optionEngine->addOptionGroup("Language",KeysList); // connect(this, &LanguagesManager::newLanguageLoaded, plugins,&PluginsManager::refreshPluginList); // connect(this, &LanguagesManager::newLanguageLoaded, this,&LanguagesManager::retranslateTheUI); @@ -53,9 +54,9 @@ LanguagesManager::~LanguagesManager() } /// \brief load the language selected, return the main short code like en, fr, .. -QString LanguagesManager::getTheRightLanguage() const +std::string LanguagesManager::getTheRightLanguage() const { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); if(LanguagesAvailableList.size()==0) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"empty combobox list, failing back to english"); @@ -63,43 +64,43 @@ QString LanguagesManager::getTheRightLanguage() const } else { - if(!OptionEngine::optionEngine->getOptionValue(QStringLiteral("Language"),QStringLiteral("Language_force")).toBool()) + if(!stringtobool(OptionEngine::optionEngine->getOptionValue("Language","Language_force"))) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("language auto-detection, QLocale::system().name(): ")+QLocale::system().name()+QStringLiteral(", QLocale::languageToString(QLocale::system().language()): ")+QLocale::languageToString(QLocale::system().language())); - QString tempLanguage=getMainShortName(QLocale::languageToString(QLocale::system().language())); - if(tempLanguage!=QStringLiteral("")) + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"language auto-detection, QLocale::system().name(): "+QLocale::system().name().toStdString()+", QLocale::languageToString(QLocale::system().language()): "+QLocale::languageToString(QLocale::system().language()).toStdString()); + std::string tempLanguage=getMainShortName(QLocale::languageToString(QLocale::system().language()).toStdString()); + if(!tempLanguage.empty()) return tempLanguage; else { - tempLanguage=getMainShortName(QLocale::system().name()); - if(tempLanguage!=QStringLiteral("")) + tempLanguage=getMainShortName(QLocale::system().name().toStdString()); + if(!tempLanguage.empty()) return tempLanguage; else { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("Autodetection of the language failed, QLocale::languageToString(QLocale::system().language()): ")+QLocale::languageToString(QLocale::system().language())+QStringLiteral(", QLocale::system().name(): ")+QLocale::system().name()+", failing back to english"); - return OptionEngine::optionEngine->getOptionValue(QStringLiteral("Language"),QStringLiteral("Language")).toString(); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Autodetection of the language failed, QLocale::languageToString(QLocale::system().language()): "+QLocale::languageToString(QLocale::system().language()).toStdString()+", QLocale::system().name(): "+QLocale::system().name().toStdString()+", failing back to english"); + return OptionEngine::optionEngine->getOptionValue("Language","Language"); } } } else - return OptionEngine::optionEngine->getOptionValue(QStringLiteral("Language"),QStringLiteral("Language")).toString(); + return OptionEngine::optionEngine->getOptionValue("Language","Language"); } } /* \brief To set the current language \param newLanguage Should be short name code found into informations.xml of language file */ -void LanguagesManager::setCurrentLanguage(const QString &newLanguage) +void LanguagesManager::setCurrentLanguage(const std::string &newLanguage) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start: ")+newLanguage); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start: "+newLanguage); //protection for re-set the same language if(currentLanguage==newLanguage) return; //store the language PluginsManager::pluginsManager->setLanguage(newLanguage); //unload the old language - if(currentLanguage!=QStringLiteral("en")) + if(currentLanguage!="en") { - int indexTranslator=0; + unsigned int indexTranslator=0; while(indexTranslator<installedTranslator.size()) { QCoreApplication::removeTranslator(installedTranslator.at(indexTranslator)); @@ -108,60 +109,60 @@ void LanguagesManager::setCurrentLanguage(const QString &newLanguage) } installedTranslator.clear(); } - int index=0; + unsigned int index=0; while(index<LanguagesAvailableList.size()) { if(LanguagesAvailableList.at(index).mainShortName==newLanguage) { //load the new language - if(newLanguage!=QStringLiteral("en")) + if(newLanguage!="en") { QTranslator *temp; - QStringList fileToLoad; + std::vector<std::string> fileToLoad; //load the language main - if(newLanguage==QStringLiteral("en")) - fileToLoad<<QStringLiteral(":/Languages/en/translation.qm"); + if(newLanguage=="en") + fileToLoad.push_back(":/Languages/en/translation.qm"); else - fileToLoad<<LanguagesAvailableList.at(index).path+QStringLiteral("translation.qm"); + fileToLoad.push_back(LanguagesAvailableList.at(index).path+"translation.qm"); //load the language plugin - QList<PluginsAvailable> listLoadedPlugins=PluginsManager::pluginsManager->getPlugins(); - int indexPluginIndex=0; + std::vector<PluginsAvailable> listLoadedPlugins=PluginsManager::pluginsManager->getPlugins(); + unsigned int indexPluginIndex=0; while(indexPluginIndex<listLoadedPlugins.size()) { if(listLoadedPlugins.at(indexPluginIndex).category!=PluginType_Languages) { - QString tempPath=listLoadedPlugins.at(indexPluginIndex).path+QStringLiteral("Languages")+QDir::separator()+LanguagesAvailableList.at(index).mainShortName+QDir::separator()+QStringLiteral("translation.qm"); - if(QFile::exists(tempPath)) - fileToLoad<<tempPath; + std::string tempPath=listLoadedPlugins.at(indexPluginIndex).path+"Languages"+FacilityEngine::separator()+LanguagesAvailableList.at(index).mainShortName+FacilityEngine::separator()+"translation.qm"; + if(QFile::exists(QString::fromStdString(tempPath))) + fileToLoad.push_back(tempPath); } indexPluginIndex++; } - int indexTranslationFile=0; + unsigned int indexTranslationFile=0; while(indexTranslationFile<fileToLoad.size()) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("Translation to load: ")+fileToLoad.at(indexTranslationFile)); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"Translation to load: "+fileToLoad.at(indexTranslationFile)); temp=new QTranslator(); - if(!temp->load(fileToLoad.at(indexTranslationFile)) || temp->isEmpty()) + if(!temp->load(QString::fromStdString(fileToLoad.at(indexTranslationFile))) || temp->isEmpty()) { delete temp; - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("Unable to load the translation file: ")+fileToLoad.at(indexTranslationFile)); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to load the translation file: "+fileToLoad.at(indexTranslationFile)); } else { QCoreApplication::installTranslator(temp); - installedTranslator<<temp; + installedTranslator.push_back(temp); } indexTranslationFile++; } temp=new QTranslator(); - if(temp->load(QString("qt_")+newLanguage, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) && !temp->isEmpty()) + if(temp->load(QString("qt_")+QString::fromStdString(newLanguage), QLibraryInfo::location(QLibraryInfo::TranslationsPath)) && !temp->isEmpty()) { QCoreApplication::installTranslator(temp); - installedTranslator<<temp; + installedTranslator.push_back(temp); } else { - if(!temp->load(LanguagesAvailableList.at(index).path+QStringLiteral("qt.qm")) || temp->isEmpty()) + if(!temp->load(QString::fromStdString(LanguagesAvailableList.at(index).path)+"qt.qm") || temp->isEmpty()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to load the translation file: qt.qm, into: "+LanguagesAvailableList.at(index).path); delete temp; @@ -169,30 +170,31 @@ void LanguagesManager::setCurrentLanguage(const QString &newLanguage) else { QCoreApplication::installTranslator(temp); - installedTranslator<<temp; + installedTranslator.push_back(temp); } } } currentLanguage=newLanguage; FacilityEngine::facilityEngine.retranslate(); - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("emit newLanguageLoaded()")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"emit newLanguageLoaded()"); emit newLanguageLoaded(currentLanguage); return; } index++; } - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to found language: "+newLanguage+", LanguagesAvailableList.size(): "+QString::number(LanguagesAvailableList.size())); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to found language: "+newLanguage+", LanguagesAvailableList.size(): "+std::to_string(LanguagesAvailableList.size())); } /// \brief check if short name is found into language -QString LanguagesManager::getMainShortName(const QString &shortName) const +std::string LanguagesManager::getMainShortName(const std::string &shortName) const { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start")); - int index=0; + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); + unsigned int index=0; while(index<LanguagesAvailableList.size()) { - if(LanguagesAvailableList.at(index).shortName.contains(shortName) || LanguagesAvailableList.at(index).fullName.contains(shortName)) - return LanguagesAvailableList.at(index).mainShortName; + const LanguagesAvailable &languagesAvailable=LanguagesAvailableList.at(index); + if(languagesAvailable.shortName.find(shortName)!=languagesAvailable.shortName.cend() || languagesAvailable.fullName==shortName) + return languagesAvailable.mainShortName; index++; } return ""; @@ -201,60 +203,60 @@ QString LanguagesManager::getMainShortName(const QString &shortName) const /// \brief load the language in languagePath void LanguagesManager::allPluginIsLoaded() { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); setCurrentLanguage(getTheRightLanguage()); } -const QString LanguagesManager::autodetectedLanguage() const +const std::string LanguagesManager::autodetectedLanguage() const { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("language auto-detection, QLocale::system().name(): ")+QLocale::system().name()+QStringLiteral(", QLocale::languageToString(QLocale::system().language()): ")+QLocale::languageToString(QLocale::system().language())); - QString tempLanguage=getMainShortName(QLocale::languageToString(QLocale::system().language())); - if(tempLanguage!=QStringLiteral("")) + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"language auto-detection, QLocale::system().name(): "+QLocale::system().name().toStdString()+", QLocale::languageToString(QLocale::system().language()): "+QLocale::languageToString(QLocale::system().language()).toStdString()); + std::string tempLanguage=getMainShortName(QLocale::languageToString(QLocale::system().language()).toStdString()); + if(!tempLanguage.empty()) return tempLanguage; else { - tempLanguage=getMainShortName(QLocale::system().name()); - if(tempLanguage!=QStringLiteral("")) + tempLanguage=getMainShortName(QLocale::system().name().toStdString()); + if(!tempLanguage.empty()) return tempLanguage; } - return ""; + return std::string(); } void LanguagesManager::onePluginAdded(const PluginsAvailable &plugin) { if(plugin.category!=PluginType_Languages) return; - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); QDomElement child = plugin.categorySpecific.firstChildElement(QStringLiteral("fullName")); LanguagesAvailable temp; if(!child.isNull() && child.isElement()) - temp.fullName=child.text(); + temp.fullName=child.text().toStdString(); child = plugin.categorySpecific.firstChildElement(QStringLiteral("shortName")); while(!child.isNull()) { if(child.isElement()) { if(child.hasAttribute("mainCode") && child.attribute(QStringLiteral("mainCode"))==QStringLiteral("true")) - temp.mainShortName=child.text(); - temp.shortName<<child.text(); + temp.mainShortName=child.text().toStdString(); + temp.shortName.insert(child.text().toStdString()); } child = child.nextSiblingElement(QStringLiteral("shortName")); } temp.path=plugin.path; - if(temp.fullName.isEmpty()) + if(temp.fullName.empty()) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"fullName empty for: "+plugin.path); - else if(temp.path.isEmpty()) + else if(temp.path.empty()) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"path empty for: "+plugin.path); - else if(temp.mainShortName.isEmpty()) + else if(temp.mainShortName.empty()) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"mainShortName empty for: "+plugin.path); else if(temp.shortName.size()<=0) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"temp.shortName.size()<=0 for: "+plugin.path); - else if(!QFile::exists(temp.path+QStringLiteral("flag.png"))) + else if(!QFile::exists(QString::fromStdString(temp.path)+QStringLiteral("flag.png"))) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"flag file not found for: "+plugin.path); - else if(!QFile::exists(temp.path+QStringLiteral("translation.qm")) && temp.mainShortName!=QStringLiteral("en")) + else if(!QFile::exists(QString::fromStdString(temp.path)+QStringLiteral("translation.qm")) && temp.mainShortName!="en") ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"translation not found for: "+plugin.path); else - LanguagesAvailableList<<temp; + LanguagesAvailableList.push_back(temp); if(PluginsManager::pluginsManager->allPluginHaveBeenLoaded()) setCurrentLanguage(getTheRightLanguage()); } @@ -262,8 +264,8 @@ void LanguagesManager::onePluginAdded(const PluginsAvailable &plugin) #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE void LanguagesManager::onePluginWillBeRemoved(const PluginsAvailable &plugin) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start")); - int index=0; + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); + unsigned int index=0; while(index<LanguagesAvailableList.size()) { if(plugin.path==LanguagesAvailableList.at(index).path) @@ -275,11 +277,11 @@ void LanguagesManager::onePluginWillBeRemoved(const PluginsAvailable &plugin) } #endif -void LanguagesManager::newOptionValue(const QString &group) +void LanguagesManager::newOptionValue(const std::string &group) { - if(group==QStringLiteral("Language")) + if(group=="Language") { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("group: ")+group); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"group: "+group); setCurrentLanguage(getTheRightLanguage()); } } |