PageRenderTime 33ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/plugins/qnx/blackberrysetupwizardpages.cpp

https://gitlab.com/pteam/pteam-qt-creator
C++ | 345 lines | 245 code | 63 blank | 37 comment | 26 complexity | 6221e10585dc9f2882cdfd12417f8c62 MD5 | raw file
  1. /**************************************************************************
  2. **
  3. ** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
  4. **
  5. ** Contact: BlackBerry (qt@blackberry.com)
  6. ** Contact: KDAB (info@kdab.com)
  7. **
  8. ** This file is part of Qt Creator.
  9. **
  10. ** Commercial License Usage
  11. ** Licensees holding valid commercial Qt licenses may use this file in
  12. ** accordance with the commercial license agreement provided with the
  13. ** Software or, alternatively, in accordance with the terms contained in
  14. ** a written agreement between you and Digia. For licensing terms and
  15. ** conditions see http://www.qt.io/licensing. For further information
  16. ** use the contact form at http://www.qt.io/contact-us.
  17. **
  18. ** GNU Lesser General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU Lesser
  20. ** General Public License version 2.1 or version 3 as published by the Free
  21. ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
  22. ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
  23. ** following information to ensure the GNU Lesser General Public License
  24. ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
  25. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  26. **
  27. ** In addition, as a special exception, Digia gives you certain additional
  28. ** rights. These rights are described in the Digia Qt LGPL Exception
  29. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  30. **
  31. ****************************************************************************/
  32. #include "blackberrysetupwizardpages.h"
  33. #include "blackberryndksettingswidget.h"
  34. #include "blackberrysigningutils.h"
  35. #include "ui_blackberrysetupwizardkeyspage.h"
  36. #include "ui_blackberrysetupwizardcertificatepage.h"
  37. #include "ui_blackberrysetupwizarddevicepage.h"
  38. #include "ui_blackberrysetupwizardfinishpage.h"
  39. #include <QVBoxLayout>
  40. #include <QFileInfo>
  41. #include <QLabel>
  42. #include <QVBoxLayout>
  43. #include <QMessageBox>
  44. #include <QAbstractButton>
  45. #include <QDesktopServices>
  46. #include <QUrl>
  47. #include <QDebug>
  48. using namespace Qnx;
  49. using namespace Qnx::Internal;
  50. BlackBerrySetupWizardWelcomePage::BlackBerrySetupWizardWelcomePage(QWidget *parent) :
  51. QWizardPage(parent)
  52. {
  53. const QString welcomeMessage =
  54. tr("Welcome to the BlackBerry Development "
  55. "Environment Setup Wizard.\nThis wizard will guide you through "
  56. "the essential steps to deploy a ready-to-go development environment "
  57. "for BlackBerry 10 devices.");
  58. setTitle(tr("BlackBerry Development Environment Setup"));
  59. QLabel *label = new QLabel(this);
  60. label->setWordWrap(true);
  61. label->setText(welcomeMessage);
  62. QVBoxLayout *layout = new QVBoxLayout;
  63. layout->addStretch();
  64. layout->addWidget(label);
  65. layout->addStretch();
  66. setLayout(layout);
  67. }
  68. //-----------------------------------------------------------------------------
  69. BlackBerrySetupWizardNdkPage::BlackBerrySetupWizardNdkPage(QWidget *parent) :
  70. QWizardPage(parent),
  71. m_widget(0)
  72. {
  73. setTitle(tr("Configure the NDK Path"));
  74. m_widget = new BlackBerryNDKSettingsWidget(this);
  75. m_widget->setWizardMessageVisible(false);
  76. connect(m_widget, SIGNAL(targetsUpdated()), this, SIGNAL(completeChanged()));
  77. connect(m_widget, SIGNAL(targetsUpdated()), this, SIGNAL(targetsUpdated()));
  78. QVBoxLayout *layout = new QVBoxLayout;
  79. layout->addWidget(m_widget);
  80. setLayout(layout);
  81. }
  82. BlackBerrySetupWizardNdkPage::~BlackBerrySetupWizardNdkPage()
  83. {
  84. }
  85. bool BlackBerrySetupWizardNdkPage::isComplete() const
  86. {
  87. return m_widget->hasActiveNdk();
  88. }
  89. //-----------------------------------------------------------------------------
  90. BlackBerrySetupWizardKeysPage::BlackBerrySetupWizardKeysPage(QWidget *parent) :
  91. QWizardPage(parent),
  92. m_ui(0),
  93. m_complete(false)
  94. {
  95. setTitle(tr("Setup Signing Keys"));
  96. initUi();
  97. }
  98. BlackBerrySetupWizardKeysPage::~BlackBerrySetupWizardKeysPage()
  99. {
  100. delete m_ui;
  101. m_ui = 0;
  102. }
  103. void BlackBerrySetupWizardKeysPage::showKeysMessage(const QString &url)
  104. {
  105. const QMessageBox::StandardButton button = QMessageBox::question(this,
  106. tr("Qt Creator"),
  107. tr("This wizard will be closed and you will be taken to the BlackBerry "
  108. "key request web page. Do you want to continue?"),
  109. QMessageBox::Yes | QMessageBox::No);
  110. if (button == QMessageBox::Yes) {
  111. QDesktopServices::openUrl(QUrl(url));
  112. wizard()->reject();
  113. }
  114. }
  115. bool BlackBerrySetupWizardKeysPage::isComplete() const
  116. {
  117. return m_complete;
  118. }
  119. void BlackBerrySetupWizardKeysPage::initUi()
  120. {
  121. BlackBerrySigningUtils &utils = BlackBerrySigningUtils::instance();
  122. m_ui = new Ui::BlackBerrySetupWizardKeysPage;
  123. m_ui->setupUi(this);
  124. if (utils.hasLegacyKeys()) {
  125. m_ui->linkLabel->setVisible(false);
  126. m_ui->legacyLabel->setVisible(true);
  127. m_ui->statusLabel->setVisible(false);
  128. setComplete(false);
  129. } else if (utils.hasRegisteredKeys()) {
  130. m_ui->linkLabel->setVisible(false);
  131. m_ui->legacyLabel->setVisible(false);
  132. m_ui->statusLabel->setVisible(true);
  133. setComplete(true);
  134. } else {
  135. m_ui->linkLabel->setVisible(true);
  136. m_ui->legacyLabel->setVisible(false);
  137. m_ui->statusLabel->setVisible(false);
  138. setComplete(false);
  139. }
  140. connect(m_ui->linkLabel, SIGNAL(linkActivated(QString)),
  141. this, SLOT(showKeysMessage(QString)));
  142. connect(m_ui->legacyLabel, SIGNAL(linkActivated(QString)),
  143. this, SLOT(showKeysMessage(QString)));
  144. connect(m_ui->helpLabel, SIGNAL(linkActivated(QString)),
  145. this, SLOT(showKeysMessage(QString)));
  146. }
  147. void BlackBerrySetupWizardKeysPage::setComplete(bool complete)
  148. {
  149. if (m_complete != complete) {
  150. m_complete = complete;
  151. m_ui->linkLabel->setVisible(!complete);
  152. m_ui->statusLabel->setVisible(complete);
  153. emit completeChanged();
  154. }
  155. }
  156. //-----------------------------------------------------------------------------
  157. const char BlackBerrySetupWizardCertificatePage::AuthorField[] = "CertificatePage::Author";
  158. const char BlackBerrySetupWizardCertificatePage::PasswordField[] = "CertificatePage::Password";
  159. const char BlackBerrySetupWizardCertificatePage::PasswordField2[] = "CertificatePage::Password2";
  160. BlackBerrySetupWizardCertificatePage::BlackBerrySetupWizardCertificatePage(QWidget *parent)
  161. : QWizardPage(parent),
  162. m_ui(0),
  163. m_complete(false)
  164. {
  165. setTitle(tr("Create Developer Certificate"));
  166. initUi();
  167. }
  168. bool BlackBerrySetupWizardCertificatePage::isComplete() const
  169. {
  170. return m_complete;
  171. }
  172. void BlackBerrySetupWizardCertificatePage::validate()
  173. {
  174. if (m_ui->author->text().isEmpty()
  175. || m_ui->password->text().isEmpty()
  176. || m_ui->password2->text().isEmpty()) {
  177. m_ui->status->clear();
  178. setComplete(false);
  179. return;
  180. }
  181. if (m_ui->password->text() != m_ui->password2->text()) {
  182. m_ui->status->setText(tr("The entered passwords do not match."));
  183. setComplete(false);
  184. return;
  185. }
  186. if (m_ui->password->text().size() < 6) {
  187. // TODO: Use tr() once string freeze is over
  188. m_ui->status->setText(QCoreApplication::translate("Qnx::Internal::BlackBerryCreateCertificateDialog", "Password must be at least 6 characters long."));
  189. setComplete(false);
  190. return;
  191. }
  192. m_ui->status->clear();
  193. setComplete(true);
  194. }
  195. void BlackBerrySetupWizardCertificatePage::checkBoxChanged(int state)
  196. {
  197. if (state == Qt::Checked) {
  198. m_ui->password->setEchoMode(QLineEdit::Normal);
  199. m_ui->password2->setEchoMode(QLineEdit::Normal);
  200. } else {
  201. m_ui->password->setEchoMode(QLineEdit::Password);
  202. m_ui->password2->setEchoMode(QLineEdit::Password);
  203. }
  204. }
  205. void BlackBerrySetupWizardCertificatePage::setComplete(bool complete)
  206. {
  207. if (m_complete != complete) {
  208. m_complete = complete;
  209. emit completeChanged();
  210. }
  211. }
  212. void BlackBerrySetupWizardCertificatePage::initUi()
  213. {
  214. m_ui = new Ui::BlackBerrySetupWizardCertificatePage;
  215. m_ui->setupUi(this);
  216. m_ui->status->clear();
  217. connect(m_ui->author, SIGNAL(textChanged(QString)),
  218. this, SLOT(validate()));
  219. connect(m_ui->password, SIGNAL(textChanged(QString)),
  220. this, SLOT(validate()));
  221. connect(m_ui->password2, SIGNAL(textChanged(QString)),
  222. this, SLOT(validate()));
  223. connect(m_ui->showPassword, SIGNAL(stateChanged(int)),
  224. this, SLOT(checkBoxChanged(int)));
  225. registerField(QLatin1String(AuthorField) + QLatin1Char('*'), m_ui->author);
  226. registerField(QLatin1String(PasswordField) + QLatin1Char('*'), m_ui->password);
  227. registerField(QLatin1String(PasswordField2) + QLatin1Char('*'), m_ui->password2);
  228. }
  229. //-----------------------------------------------------------------------------
  230. const char BlackBerrySetupWizardDevicePage::NameField[] = "DevicePage::Name";
  231. const char BlackBerrySetupWizardDevicePage::IpAddressField[] = "DevicePage::IpAddress";
  232. const char BlackBerrySetupWizardDevicePage::PasswordField[] = "DevicePage::PasswordField";
  233. const char BlackBerrySetupWizardDevicePage::PhysicalDeviceField[] = "DevicePage::PhysicalDeviceField";
  234. BlackBerrySetupWizardDevicePage::BlackBerrySetupWizardDevicePage(QWidget *parent)
  235. : QWizardPage(parent),
  236. m_ui(0)
  237. {
  238. setTitle(tr("Configure BlackBerry Device Connection"));
  239. m_ui = new Ui::BlackBerrySetupWizardDevicePage;
  240. m_ui->setupUi(this);
  241. m_ui->deviceName->setText(tr("BlackBerry Device"));
  242. m_ui->ipAddress->setText(QLatin1String("169.254.0.1"));
  243. connect(m_ui->deviceName, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
  244. connect(m_ui->ipAddress, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
  245. connect(m_ui->password, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
  246. connect(m_ui->physicalDevice, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));
  247. registerField(QLatin1String(NameField) + QLatin1Char('*'), m_ui->deviceName);
  248. registerField(QLatin1String(IpAddressField) + QLatin1Char('*'), m_ui->ipAddress);
  249. registerField(QLatin1String(PasswordField), m_ui->password);
  250. registerField(QLatin1String(PhysicalDeviceField), m_ui->physicalDevice);
  251. }
  252. bool BlackBerrySetupWizardDevicePage::isComplete() const
  253. {
  254. if (m_ui->deviceName->text().isEmpty() || m_ui->ipAddress->text().isEmpty())
  255. return false;
  256. const bool passwordMandatory = m_ui->physicalDevice->isChecked();
  257. if (passwordMandatory && m_ui->password->text().isEmpty())
  258. return false;
  259. return true;
  260. }
  261. //-----------------------------------------------------------------------------
  262. BlackBerrySetupWizardFinishPage::BlackBerrySetupWizardFinishPage(QWidget *parent)
  263. : QWizardPage(parent),
  264. m_ui(0)
  265. {
  266. setTitle(tr("Your environment is ready to be configured."));
  267. m_ui = new Ui::BlackBerrySetupWizardFinishPage;
  268. m_ui->setupUi(this);
  269. setProgress(QString(), -1);
  270. }
  271. void BlackBerrySetupWizardFinishPage::setProgress(const QString &status, int progress)
  272. {
  273. if (progress < 0) {
  274. m_ui->progressBar->hide();
  275. m_ui->statusLabel->clear();
  276. return;
  277. } else if (!m_ui->progressBar->isVisible()) {
  278. m_ui->progressBar->show();
  279. }
  280. m_ui->statusLabel->setText(status);
  281. m_ui->progressBar->setValue(progress);
  282. }