Open Source Snapmatic picture and Savegame viewer/editor for GTA V https://gta5view.syping.de/

GlobalString.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*****************************************************************************
  2. * gta5view Grand Theft Auto V Profile Viewer
  3. * Copyright (C) 2016-2018 Syping
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *****************************************************************************/
  18. #include "TranslationClass.h"
  19. #include "GlobalString.h"
  20. #include "config.h"
  21. #include <QStringBuilder>
  22. #include <QStringList>
  23. #include <QFileInfo>
  24. #include <QSettings>
  25. #include <QLocale>
  26. #include <QDebug>
  27. GlobalString::GlobalString()
  28. {
  29. }
  30. QMap<QString, QString> GlobalString::getGlobalMap()
  31. {
  32. QMap<QString, QString> globalMap;
  33. QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
  34. globalFile.setIniCodec("UTF-8");
  35. globalFile.beginGroup("Global");
  36. for (QString globalStr : globalFile.childKeys())
  37. {
  38. globalMap[globalStr] = globalFile.value(globalStr, globalStr).toString();
  39. }
  40. globalFile.endGroup();
  41. return globalMap;
  42. }
  43. QString GlobalString::getString(QString valueStr, bool *ok)
  44. {
  45. QString globalString = valueStr;
  46. QSettings globalFile(getLanguageFile(), QSettings::IniFormat);
  47. globalFile.setIniCodec("UTF-8");
  48. globalFile.beginGroup("Global");
  49. QStringList globalStrList = globalFile.childKeys();
  50. if (globalStrList.contains(valueStr))
  51. {
  52. if (ok != nullptr) *ok = true;
  53. globalString = globalFile.value(valueStr, valueStr).toString();
  54. }
  55. globalFile.endGroup();
  56. return globalString;
  57. }
  58. QString GlobalString::getLanguageFile()
  59. {
  60. QString language = getLanguage();
  61. QString languageFile = ":/global/global." % language % ".ini";
  62. if (!QFileInfo(languageFile).exists())
  63. {
  64. languageFile = ":/global/global.en.ini";
  65. }
  66. return languageFile;
  67. }
  68. QString GlobalString::getLanguage()
  69. {
  70. return Translator->getCurrentAreaLanguage();
  71. }