tizensettingspage.cpp 11 KB

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