modstate.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * modstate.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "modstate.h"
  12. #include "../../lib/modding/ModDescription.h"
  13. #include "../../lib/json/JsonNode.h"
  14. #include "../../lib/texts/CGeneralTextHandler.h"
  15. ModState::ModState(const ModDescription & impl)
  16. : impl(impl)
  17. {
  18. }
  19. QString ModState::getName() const
  20. {
  21. return QString::fromStdString(impl.getName());
  22. }
  23. QString ModState::getType() const
  24. {
  25. return QString::fromStdString(impl.getValue("modType").String());
  26. }
  27. QString ModState::getDescription() const
  28. {
  29. return QString::fromStdString(impl.getValue("description").String());
  30. }
  31. QString ModState::getID() const
  32. {
  33. return QString::fromStdString(impl.getID());
  34. }
  35. QString ModState::getParentID() const
  36. {
  37. return QString::fromStdString(impl.getParentID());
  38. }
  39. QString ModState::getTopParentID() const
  40. {
  41. return QString::fromStdString(impl.getParentID());
  42. }
  43. template<typename Container>
  44. QStringList stringListStdToQt(const Container & container)
  45. {
  46. QStringList result;
  47. for (const auto & str : container)
  48. result.push_back(QString::fromStdString(str));
  49. return result;
  50. }
  51. QStringList ModState::getDependencies() const
  52. {
  53. return stringListStdToQt(impl.getDependencies());
  54. }
  55. QStringList ModState::getConflicts() const
  56. {
  57. return stringListStdToQt(impl.getConflicts());
  58. }
  59. QStringList ModState::getScreenshots() const
  60. {
  61. return {}; // TODO
  62. }
  63. QString ModState::getBaseLanguage() const
  64. {
  65. return QString::fromStdString(impl.getBaseLanguage());
  66. }
  67. QStringList ModState::getSupportedLanguages() const
  68. {
  69. return {}; //TODO
  70. }
  71. QMap<QString, QStringList> ModState::getChangelog() const
  72. {
  73. return {}; //TODO
  74. }
  75. QString ModState::getInstalledVersion() const
  76. {
  77. return QString::fromStdString(impl.getLocalValue("version").String());
  78. }
  79. QString ModState::getRepositoryVersion() const
  80. {
  81. return QString::fromStdString(impl.getRepositoryValue("version").String());
  82. }
  83. double ModState::getDownloadSizeMegabytes() const
  84. {
  85. return impl.getRepositoryValue("downloadSize").Float();
  86. }
  87. size_t ModState::getDownloadSizeBytes() const
  88. {
  89. return getDownloadSizeMegabytes() * 1024 * 1024;
  90. }
  91. QString ModState::getDownloadSizeFormatted() const
  92. {
  93. return {}; // TODO
  94. }
  95. QString ModState::getLocalSizeFormatted() const
  96. {
  97. return {}; // TODO
  98. }
  99. QString ModState::getAuthors() const
  100. {
  101. return QString::fromStdString(impl.getValue("author").String());
  102. }
  103. QString ModState::getContact() const
  104. {
  105. return QString::fromStdString(impl.getValue("contact").String());
  106. }
  107. QString ModState::getLicenseUrl() const
  108. {
  109. return QString::fromStdString(impl.getValue("licenseURL").String());
  110. }
  111. QString ModState::getLicenseName() const
  112. {
  113. return QString::fromStdString(impl.getValue("licenseName").String());
  114. }
  115. QString ModState::getDownloadUrl() const
  116. {
  117. return QString::fromStdString(impl.getRepositoryValue("download").String());
  118. }
  119. QPair<QString, QString> ModState::getCompatibleVersionRange() const
  120. {
  121. return {}; // TODO
  122. }
  123. bool ModState::isSubmod() const
  124. {
  125. return !getParentID().isEmpty();
  126. }
  127. bool ModState::isCompatibility() const
  128. {
  129. return impl.isCompatibility();
  130. }
  131. bool ModState::isTranslation() const
  132. {
  133. return impl.isTranslation();
  134. }
  135. bool ModState::isVisible() const
  136. {
  137. return !isHidden();
  138. }
  139. bool ModState::isHidden() const
  140. {
  141. if (isTranslation() && !isInstalled())
  142. return impl.getBaseLanguage() == CGeneralTextHandler::getPreferredLanguage();
  143. return isCompatibility() || getID() == "vcmi" || getID() == "core";
  144. }
  145. bool ModState::isDisabled() const
  146. {
  147. return false; // TODO
  148. }
  149. bool ModState::isEnabled() const
  150. {
  151. return true; // TODO
  152. }
  153. bool ModState::isAvailable() const
  154. {
  155. return !isInstalled();
  156. }
  157. bool ModState::isInstalled() const
  158. {
  159. return impl.isInstalled();
  160. }
  161. bool ModState::isUpdateAvailable() const
  162. {
  163. return getInstalledVersion() != getRepositoryVersion() && !getRepositoryVersion().isEmpty() && !getInstalledVersion().isEmpty();;
  164. }
  165. bool ModState::isCompatible() const
  166. {
  167. return true; //TODO
  168. }
  169. bool ModState::isKeptDisabled() const
  170. {
  171. return impl.keepDisabled();
  172. }