tizensettingspage.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 "tizensettingspage.h"
  30. #include "tizenconfigurations.h"
  31. #include "tizentoolchain.h"
  32. #include "tizenconstants.h"
  33. #include <utils/hostosinfo.h>
  34. #include <utils/environment.h>
  35. #include <QFileDialog>
  36. #include <projectexplorer/toolchain.h>
  37. #include <projectexplorer/toolchainmanager.h>
  38. using namespace Core;
  39. namespace Tizen {
  40. namespace Internal {
  41. TizenSettingsWidget::TizenSettingsWidget(QWidget * parent) :
  42. QWidget(parent)
  43. {
  44. ui.setupUi(this);
  45. TizenConfig config = TizenConfigurations::currentConfig();
  46. ui.sdkLocationLineEdit->setText(config.sdkLocation().toString());
  47. ui.sdkDataPathLineEdit->setText(config.sdkDataLocation().toString());
  48. ui.sdbPortSpinBox->setValue(config.sdbPort());
  49. ui.sdbExecutablePath->setText(config.sdbLocation().toString());
  50. ui.nativePackagingExecutablePath->setText(config.nativePackagingLocation().toString());
  51. ui.authorCertificatePath->setText(config.authorCertificateLocation().toString());
  52. ui.authorCertificatePassword->setText(config.authorCertificatePassword());
  53. connect(ui.sdkLocationBrowse, SIGNAL(clicked()), SLOT(browseSdk()));
  54. connect(ui.sdkDataPathBrowse, SIGNAL(clicked()), SLOT(browseSdkData()));
  55. connect(ui.sdbLocationBrowse, SIGNAL(clicked()), SLOT(browseSdbPath()));
  56. connect(ui.authorCertificatePathBrowse, SIGNAL(clicked()), SLOT(browseAuthorCertificatePath()));
  57. connect(ui.nativePackagingLocationBrowse, SIGNAL(clicked()), SLOT(browseNativePackagingPath()));
  58. connect(ui.sdkLocationLineEdit, SIGNAL(editingFinished()),SLOT(tryToFindOutConfigurationFromSdkPath()));
  59. }
  60. QString TizenSettingsWidget::widgetKeywords() const
  61. {
  62. QString result;
  63. result.append(ui.label->text());
  64. result.append(ui.label_2->text());
  65. result.append(ui.label_3->text());
  66. result.append(ui.label_4->text());
  67. result.append(ui.label_5->text());
  68. result.append(ui.label_6->text());
  69. result.append(ui.label_7->text());
  70. return result;
  71. }
  72. void TizenSettingsWidget::browseSdk()
  73. {
  74. Utils::FileName dir = Utils::FileName::fromString(
  75. QFileDialog::getExistingDirectory(this,
  76. tr("Select Tizen SDK folder"),
  77. ui.sdkLocationLineEdit->text()));
  78. if(!QFileInfo(dir.toString()).exists())
  79. return;
  80. ui.sdkLocationLineEdit->setText(dir.toString());
  81. tryToFindOutConfigurationFromSdkPath();
  82. }
  83. void TizenSettingsWidget::browseSdkData()
  84. {
  85. Utils::FileName dir = Utils::FileName::fromString(
  86. QFileDialog::getExistingDirectory(this,
  87. tr("Select Tizen SDK data folder"),
  88. ui.sdkDataPathLineEdit->text()));
  89. if(!QFileInfo(dir.toString()).exists())
  90. return;
  91. ui.sdkDataPathLineEdit->setText(dir.toString());
  92. }
  93. void TizenSettingsWidget::browseSdbPath()
  94. {
  95. Utils::FileName file = Utils::FileName::fromString(
  96. QFileDialog::getOpenFileName(this,
  97. tr("Select SDB executable"),
  98. ui.sdbExecutablePath->text()));
  99. QFileInfo fi(file.toFileInfo());
  100. if(!fi.exists() || !fi.isExecutable())
  101. return;
  102. ui.sdbExecutablePath->setText(file.toString());
  103. }
  104. void TizenSettingsWidget::browseNativePackagingPath()
  105. {
  106. QString dir = ui.nativePackagingExecutablePath->text();
  107. if (ui.nativePackagingExecutablePath->text().isEmpty() && !ui.sdkLocationLineEdit->text().isEmpty()) {
  108. QDir tmpDir = QDir(ui.sdkLocationLineEdit->text());
  109. if (tmpDir.cd(QLatin1String("tools"))) {
  110. dir = tmpDir.canonicalPath();
  111. }
  112. }
  113. Utils::FileName file = Utils::FileName::fromString(
  114. QFileDialog::getOpenFileName(this,
  115. tr("Select native-packaging executable"),
  116. dir));
  117. QFileInfo fi(file.toFileInfo());
  118. if(!fi.exists() || !fi.isExecutable())
  119. return;
  120. ui.nativePackagingExecutablePath->setText(file.toString());
  121. }
  122. void TizenSettingsWidget::browseAuthorCertificatePath()
  123. {
  124. QString dir = ui.authorCertificatePath->text();
  125. if (ui.authorCertificatePath->text().isEmpty() && !ui.sdkDataPathLineEdit->text().isEmpty()) {
  126. QDir tmpDir = QDir(ui.sdkDataPathLineEdit->text());
  127. if (tmpDir.cd(QLatin1String("keystore")) && tmpDir.cd(QLatin1String("author"))) {
  128. dir = tmpDir.canonicalPath();
  129. }
  130. }
  131. Utils::FileName file = Utils::FileName::fromString(
  132. QFileDialog::getOpenFileName(this,
  133. tr("Select author certificate executable"),
  134. dir,
  135. QLatin1String("*.p12")));
  136. QFileInfo fi(file.toFileInfo());
  137. if(!fi.exists())
  138. return;
  139. ui.authorCertificatePath->setText(file.toString());
  140. }
  141. void TizenSettingsWidget::tryToFindOutConfigurationFromSdkPath()
  142. {
  143. QString sdkPath = ui.sdkLocationLineEdit->text();
  144. if (sdkPath.isEmpty())
  145. return;
  146. if (ui.sdkDataPathLineEdit->text().isEmpty()) {
  147. QDir sdkDataDir(sdkPath);
  148. if (sdkDataDir.cdUp()
  149. && sdkDataDir.cd(QLatin1String("tizen-sdk-data"))
  150. && sdkDataDir.exists()) {
  151. ui.sdkDataPathLineEdit->setText(sdkDataDir.canonicalPath());
  152. }
  153. }
  154. if (ui.sdbExecutablePath->text().isEmpty()) {
  155. ui.sdbExecutablePath->setText(Utils::FileName::fromString(sdkPath)
  156. .appendPath(QLatin1String("tools"))
  157. .appendPath(Utils::HostOsInfo::withExecutableSuffix(QLatin1String("sdb")))
  158. .toString());
  159. }
  160. if (ui.nativePackagingExecutablePath->text().isEmpty()) {
  161. ui.nativePackagingExecutablePath->setText(Utils::FileName::fromString(sdkPath)
  162. .appendPath(QLatin1String("tools"))
  163. .appendPath(QLatin1String("native-packaging"))
  164. .toString());
  165. }
  166. }
  167. TizenSettingsPage::TizenSettingsPage(QObject *parent) :
  168. IOptionsPage(parent),
  169. m_widget(NULL)
  170. {
  171. setId(Constants::TIZEN_SETTINGS_ID);
  172. setDisplayName(tr("Tizen Configuration"));
  173. setCategory(Constants::TIZEN_SETTINGS_CATEGORY);
  174. setDisplayCategory(QCoreApplication::translate("Tizen", Constants::TIZEN_SETTINGS_TR_CATEGORY));
  175. setCategoryIcon(QLatin1String(":/tizen/images/tizen.png"));
  176. }
  177. bool TizenSettingsPage::matches(const QString& searchKeyWord) const
  178. {
  179. return m_keywords.contains(searchKeyWord, Qt::CaseInsensitive);
  180. }
  181. QWidget * TizenSettingsPage::createPage(QWidget *parent)
  182. {
  183. m_widget = new TizenSettingsWidget(parent);
  184. if(m_keywords.isEmpty())
  185. m_keywords = m_widget->widgetKeywords();
  186. return m_widget;
  187. }
  188. void TizenSettingsPage::apply()
  189. {
  190. if(m_widget) {
  191. TizenConfig config = TizenConfigurations::currentConfig();
  192. config.setSdkLocation(Utils::FileName::fromString(m_widget->ui.sdkLocationLineEdit->text()));
  193. config.setSdkDataLocation(Utils::FileName::fromString(m_widget->ui.sdkDataPathLineEdit->text()));
  194. config.setSdbPort(m_widget->ui.sdbPortSpinBox->value());
  195. config.setSdbLocation(Utils::FileName::fromString(m_widget->ui.sdbExecutablePath->text()));
  196. config.setNativePackagingLocation(Utils::FileName::fromString(m_widget->ui.nativePackagingExecutablePath->text()));
  197. config.setAuthorCertificateLocation(Utils::FileName::fromString(m_widget->ui.authorCertificatePath->text()));
  198. config.setAuthorCertificatePassword(m_widget->ui.authorCertificatePassword->text());
  199. TizenConfigurations::setConfig(config);
  200. QList<ProjectExplorer::ToolChain *> existingToolChains = ProjectExplorer::ToolChainManager::toolChains();
  201. QList<ProjectExplorer::ToolChain *> toolchains = TizenToolChainFactory::createToolChainsForSdk(TizenConfigurations::currentConfig().sdkLocation().toString());
  202. foreach (ProjectExplorer::ToolChain *tc, toolchains) {
  203. bool found = false;
  204. for (int i = 0; i < existingToolChains.count(); ++i) {
  205. if (*(existingToolChains.at(i)) == *tc) {
  206. found = true;
  207. break;
  208. }
  209. }
  210. if (found)
  211. delete tc;
  212. else
  213. ProjectExplorer::ToolChainManager::registerToolChain(tc);
  214. }
  215. foreach (ProjectExplorer::ToolChain *tc, existingToolChains) {
  216. if (tc->type() == QLatin1String(Constants::TIZEN_TOOLCHAIN_GCC_TYPE)) {
  217. if (!tc->isValid())
  218. ProjectExplorer::ToolChainManager::deregisterToolChain(tc);
  219. }
  220. }
  221. TizenConfigurations::updateAutomaticKitList();
  222. }
  223. }
  224. void TizenSettingsPage::finish()
  225. {
  226. }
  227. } // namespace Internal
  228. } // namespace Tizen