tizenconfigurations.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Jarek Pelczar <jpelczar@gmail.com>
  4. ** Copyright (C) 2014 Tomasz Olszak <olszak.tomasz@gmail.com>
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Digia. For licensing terms and
  13. ** conditions see http://qt.digia.com/licensing. For further information
  14. ** use the contact form at http://qt.digia.com/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 as published by the Free Software
  19. ** Foundation and appearing in the file LICENSE.LGPL included in the
  20. ** packaging of this file. Please review the following information to
  21. ** ensure the GNU Lesser General Public License version 2.1 requirements
  22. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  23. **
  24. ** In addition, as a special exception, Digia gives you certain additional
  25. ** rights. These rights are described in the Digia Qt LGPL Exception
  26. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  27. **
  28. ****************************************************************************/
  29. #include "tizendebug.h"
  30. #include "tizenqtversion.h"
  31. #include "tizentoolchain.h"
  32. #include "tizenconstants.h"
  33. #include "tizenconfigurations.h"
  34. #include <coreplugin/icore.h>
  35. #include <utils/environment.h>
  36. #include <projectexplorer/devicesupport/devicemanager.h>
  37. #include <projectexplorer/abi.h>
  38. #include <utils/hostosinfo.h>
  39. #include <projectexplorer/kit.h>
  40. #include <projectexplorer/devicesupport/devicemanager.h>
  41. #include <projectexplorer/kitinformation.h>
  42. #include <projectexplorer/kitmanager.h>
  43. #include <qtsupport/qtkitinformation.h>
  44. #include <qtsupport/qtversionmanager.h>
  45. #include <projectexplorer/toolchainmanager.h>
  46. #include <projectexplorer/toolchain.h>
  47. #include <QDebug>
  48. #include <QFileInfo>
  49. #include <QDir>
  50. #include <QFile>
  51. Q_LOGGING_CATEGORY(QTC_TIZEN, "qtcreator.plugin.tizen")
  52. namespace Tizen {
  53. namespace Internal {
  54. namespace {
  55. const QLatin1String TizenGroupKey("TizenPluginSettings");
  56. const QLatin1String TizenSDKLocationKey("TizenSDKLocation");
  57. const QLatin1String TizenSDKDataLocationKey("TizenSDKDataLocation");
  58. const QLatin1String TizenSDBLocationKey("TizenSDBLocation");
  59. const QLatin1String TizenNativePackagingLocationKey("TizenNativePackagingLocation");
  60. const QLatin1String TizenSDBPortKey("TizenSDBPort");
  61. const QLatin1String TizenAuthorCertificateLocationKey("TizenAuthorCertificateLocation");
  62. const QLatin1String TizenAuthorCertificatePasswordKey("TizenAuthorCertificatePassword");
  63. const QLatin1String ArmToolchainPrefix("arm-linux-gnueabi");
  64. const QLatin1String X86ToolchainPrefix("i386-linux-gnueabi");
  65. }
  66. TizenConfigurations * TizenConfigurations::m_instance;
  67. TizenConfig::TizenConfig() :
  68. m_sdbPort(26099)
  69. {
  70. }
  71. Utils::FileName TizenConfig::sdkLocation() const
  72. {
  73. return m_sdkLocation;
  74. }
  75. void TizenConfig::setSdkLocation(const Utils::FileName &sdkLocation)
  76. {
  77. m_sdkLocation = sdkLocation;
  78. }
  79. Utils::FileName TizenConfig::sdkDataLocation() const
  80. {
  81. return m_sdkDataLocation;
  82. }
  83. void TizenConfig::setSdkDataLocation(const Utils::FileName &sdkDataLocation)
  84. {
  85. m_sdkDataLocation = sdkDataLocation;
  86. }
  87. Utils::FileName TizenConfig::sdbLocation() const
  88. {
  89. return m_sdbLocation;
  90. }
  91. void TizenConfig::setSdbLocation(const Utils::FileName &sdbLocation)
  92. {
  93. m_sdbLocation = sdbLocation;
  94. }
  95. int TizenConfig::sdbPort() const
  96. {
  97. return m_sdbPort;
  98. }
  99. void TizenConfig::setSdbPort(int port)
  100. {
  101. m_sdbPort = port;
  102. }
  103. Utils::FileName TizenConfig::nativePackagingLocation() const
  104. {
  105. return m_nativePackagingLocation;
  106. }
  107. void TizenConfig::setNativePackagingLocation(const Utils::FileName &nativePackaging)
  108. {
  109. m_nativePackagingLocation = nativePackaging;
  110. }
  111. Utils::FileName TizenConfig::authorCertificateLocation() const
  112. {
  113. return m_authorCertificateLocation;
  114. }
  115. void TizenConfig::setAuthorCertificateLocation(const Utils::FileName &authorCertificateLocation)
  116. {
  117. m_authorCertificateLocation = authorCertificateLocation;
  118. }
  119. QString TizenConfig::authorCertificatePassword() const
  120. {
  121. return m_authorCertificatePassword;
  122. }
  123. void TizenConfig::setAuthorCertificatePassword(const QString &authorCertificatePassword)
  124. {
  125. m_authorCertificatePassword = authorCertificatePassword;
  126. }
  127. void TizenConfig::save(QSettings &settings) const
  128. {
  129. settings.setValue(TizenSDKLocationKey, m_sdkLocation.toString());
  130. settings.setValue(TizenSDKDataLocationKey, m_sdkDataLocation.toString());
  131. settings.setValue(TizenSDBLocationKey, m_sdbLocation.toString());
  132. settings.setValue(TizenNativePackagingLocationKey, m_nativePackagingLocation.toString());
  133. settings.setValue(TizenSDBPortKey, m_sdbPort);
  134. settings.setValue(TizenAuthorCertificateLocationKey, m_authorCertificateLocation.toString());
  135. settings.setValue(TizenAuthorCertificatePasswordKey, m_authorCertificatePassword);
  136. }
  137. void TizenConfig::load(const QSettings &settings)
  138. {
  139. m_sdkLocation = Utils::FileName::fromString(settings.value(TizenSDKLocationKey).toString());
  140. m_sdkDataLocation = Utils::FileName::fromString(settings.value(TizenSDKDataLocationKey).toString());
  141. m_sdbLocation = Utils::FileName::fromString(settings.value(TizenSDBLocationKey).toString());
  142. m_nativePackagingLocation = Utils::FileName::fromString(settings.value(TizenNativePackagingLocationKey).toString());
  143. m_authorCertificateLocation = Utils::FileName::fromString(settings.value(TizenAuthorCertificateLocationKey).toString());
  144. m_authorCertificatePassword = settings.value(TizenAuthorCertificatePasswordKey).toString();
  145. m_sdbPort = settings.value(TizenSDBPortKey).toInt();
  146. }
  147. ProjectExplorer::Abi::Architecture TizenConfig::architectureForToolChainPrefix(const QString &toolchainprefix)
  148. {
  149. if (toolchainprefix == ArmToolchainPrefix)
  150. return ProjectExplorer::Abi::ArmArchitecture;
  151. if (toolchainprefix == X86ToolchainPrefix)
  152. return ProjectExplorer::Abi::X86Architecture;
  153. return ProjectExplorer::Abi::UnknownArchitecture;
  154. }
  155. TizenConfigurations::TizenConfigurations(QObject *parent) :
  156. QObject(parent)
  157. {
  158. Q_ASSERT(!m_instance);
  159. m_instance = this;
  160. load();
  161. }
  162. TizenConfigurations::~TizenConfigurations()
  163. {
  164. Q_ASSERT(m_instance == this);
  165. m_instance = NULL;
  166. }
  167. void TizenConfigurations::updateAutomaticKitList()
  168. {
  169. qCDebug(QTC_TIZEN);
  170. QMap<Utils::FileName, TizenQtVersion *> tizenGbsQtVersions;
  171. foreach(QtSupport::BaseQtVersion *qtVersion, QtSupport::QtVersionManager::versions()) {
  172. if (qtVersion->type() == QLatin1String(Constants::TIZEN_QT)) {
  173. qCDebug(QTC_TIZEN) << qtVersion;
  174. TizenQtVersion *tmp = static_cast<TizenQtVersion *>(qtVersion);
  175. qCDebug(QTC_TIZEN) << tmp << tmp->gbsBuildRoot().toString();
  176. if (!tmp->gbsBuildRoot().isEmpty())
  177. tizenGbsQtVersions.insert(tmp->gbsBuildRoot(), tmp);
  178. }
  179. }
  180. foreach (ProjectExplorer::Kit * kit, ProjectExplorer::KitManager::kits()) {
  181. if (kit->isAutoDetected() && kit->hasValue(Core::Id(Constants::TIZEN_KIT_GBS_ID))) {
  182. TizenGccToolChain *toolchain = static_cast<TizenGccToolChain *>(ProjectExplorer::ToolChainKitInformation::toolChain(kit));
  183. if (toolchain && !toolchain->gbsBuildRoot().isEmpty()) {
  184. if (!tizenGbsQtVersions.contains(toolchain->gbsBuildRoot())) {
  185. ProjectExplorer::KitManager::deregisterKit(kit);
  186. ProjectExplorer::ToolChainManager::deregisterToolChain(toolchain);
  187. } else
  188. tizenGbsQtVersions.remove(toolchain->gbsBuildRoot());
  189. } else {
  190. ProjectExplorer::KitManager::deregisterKit(kit);
  191. }
  192. }
  193. }
  194. foreach(Utils::FileName gbsBuildRoot, tizenGbsQtVersions.keys()) {
  195. ProjectExplorer::ToolChain *toolchain = TizenToolChainFactory::createToolChainForGbs(gbsBuildRoot.toString());
  196. Q_ASSERT(toolchain);
  197. ProjectExplorer::ToolChainManager::registerToolChain(toolchain);
  198. TizenQtVersion * qtVersion = tizenGbsQtVersions.value(gbsBuildRoot);
  199. ProjectExplorer::Kit *tizenGbsAutodetectedKit = new ProjectExplorer::Kit();
  200. tizenGbsAutodetectedKit->setValue(Core::Id(Constants::TIZEN_KIT_GBS_ID), true);
  201. tizenGbsAutodetectedKit->setDisplayName(QString(QStringLiteral("Tizen GBS Kit(from %1)"))
  202. .arg(qtVersion->displayName()));
  203. tizenGbsAutodetectedKit->setAutoDetected(true);
  204. ProjectExplorer::DeviceTypeKitInformation::setDeviceTypeId(tizenGbsAutodetectedKit, Core::Id(Constants::TIZEN_DEVICE_TYPE));
  205. ProjectExplorer::ToolChainKitInformation::setToolChain(tizenGbsAutodetectedKit, toolchain);
  206. QtSupport::QtKitInformation::setQtVersion(tizenGbsAutodetectedKit, qtVersion);
  207. ProjectExplorer::DeviceKitInformation::setDevice(tizenGbsAutodetectedKit,
  208. ProjectExplorer::DeviceManager::instance()->find(Core::Id(Constants::TIZEN_DEVICE_ID)));
  209. tizenGbsAutodetectedKit->setup();
  210. tizenGbsAutodetectedKit->fix();
  211. ProjectExplorer::KitManager::registerKit(tizenGbsAutodetectedKit);
  212. }
  213. }
  214. void TizenConfigurations::load()
  215. {
  216. QSettings * settings = Core::ICore::instance()->settings();
  217. settings->beginGroup(TizenGroupKey);
  218. m_config = TizenConfig();
  219. m_config.load(*settings);
  220. settings->endGroup();
  221. }
  222. void TizenConfigurations::save()
  223. {
  224. QSettings * settings = Core::ICore::instance()->settings();
  225. settings->beginGroup(TizenGroupKey);
  226. m_config.save(*settings);
  227. settings->endGroup();
  228. }
  229. void TizenConfigurations::clearDefaultDevices(ProjectExplorer::Project */*project*/)
  230. {
  231. }
  232. TizenConfig TizenConfigurations::currentConfig()
  233. {
  234. return m_instance->m_config;
  235. }
  236. void TizenConfigurations::setConfig(const TizenConfig &config)
  237. {
  238. m_instance->m_config = config;
  239. m_instance->save();
  240. m_instance->updateAutomaticKitList();
  241. // m_instance->updateAndroidDevice();
  242. emit m_instance->updated();
  243. }
  244. } //namespace Internal
  245. } // namespace Tizen