1
/**************************************************************************
3
** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
5
** Contact: BlackBerry (qt@blackberry.com)
6
** Contact: KDAB (info@kdab.com)
8
** This file is part of Qt Creator.
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://qt.digia.com/licensing. For further information
16
** use the contact form at http://qt.digia.com/contact-us.
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 as published by the Free Software
21
** Foundation and appearing in the file LICENSE.LGPL included in the
22
** packaging of this file. Please review the following information to
23
** ensure the GNU Lesser General Public License version 2.1 requirements
24
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26
** In addition, as a special exception, Digia gives you certain additional
27
** rights. These rights are described in the Digia Qt LGPL Exception
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30
****************************************************************************/
32
#include "blackberrydeployqtlibrariesdialog.h"
33
#include "ui_blackberrydeployqtlibrariesdialog.h"
35
#include "blackberryqtversion.h"
37
#include <projectexplorer/deployablefile.h>
38
#include <qtsupport/qtversionmanager.h>
39
#include <remotelinux/genericdirectuploadservice.h>
40
#include <ssh/sshremoteprocessrunner.h>
41
#include <utils/qtcassert.h>
44
#include <QMessageBox>
47
using namespace Qnx::Internal;
49
BlackBerryDeployQtLibrariesDialog::BlackBerryDeployQtLibrariesDialog(
50
const ProjectExplorer::IDevice::ConstPtr &device, QWidget *parent)
52
, m_ui(new Ui::BlackBerryDeployQtLibrariesDialog)
59
QList<QtSupport::BaseQtVersion*> qtVersions = QtSupport::QtVersionManager::validVersions();
60
foreach (QtSupport::BaseQtVersion *qtVersion, qtVersions) {
61
BlackBerryQtVersion *blackBerryQt = dynamic_cast<BlackBerryQtVersion *>(qtVersion);
65
m_ui->qtLibraryCombo->addItem(blackBerryQt->displayName(), blackBerryQt->uniqueId());
68
m_uploadService = new RemoteLinux::GenericDirectUploadService(this);
69
m_uploadService->setDevice(m_device);
71
connect(m_uploadService, SIGNAL(progressMessage(QString)), this, SLOT(updateProgress(QString)));
72
connect(m_uploadService, SIGNAL(progressMessage(QString)),
73
m_ui->deployLogWindow, SLOT(appendPlainText(QString)));
74
connect(m_uploadService, SIGNAL(errorMessage(QString)),
75
m_ui->deployLogWindow, SLOT(appendPlainText(QString)));
76
connect(m_uploadService, SIGNAL(warningMessage(QString)),
77
m_ui->deployLogWindow, SLOT(appendPlainText(QString)));
78
connect(m_uploadService, SIGNAL(stdOutData(QString)),
79
m_ui->deployLogWindow, SLOT(appendPlainText(QString)));
80
connect(m_uploadService, SIGNAL(stdErrData(QString)),
81
m_ui->deployLogWindow, SLOT(appendPlainText(QString)));
82
connect(m_uploadService, SIGNAL(finished()), this, SLOT(handleUploadFinished()));
84
m_processRunner = new QSsh::SshRemoteProcessRunner(this);
85
connect(m_processRunner, SIGNAL(connectionError()),
86
this, SLOT(handleRemoteProcessError()));
87
connect(m_processRunner, SIGNAL(processClosed(int)),
88
this, SLOT(handleRemoteProcessCompleted()));
90
connect(m_ui->deployButton, SIGNAL(clicked()), this, SLOT(deployLibraries()));
91
connect(m_ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
94
BlackBerryDeployQtLibrariesDialog::~BlackBerryDeployQtLibrariesDialog()
99
int BlackBerryDeployQtLibrariesDialog::execAndDeploy(int qtVersionId, const QString &remoteDirectory)
101
m_ui->remoteDirectory->setText(remoteDirectory);
102
m_ui->qtLibraryCombo->setCurrentIndex(m_ui->qtLibraryCombo->findData(qtVersionId));
108
void BlackBerryDeployQtLibrariesDialog::closeEvent(QCloseEvent *event)
110
// A disabled Deploy button indicates the upload is still running
111
if (!m_ui->deployButton->isEnabled()) {
112
int answer = QMessageBox::question(this, windowTitle(),
113
tr("Closing the dialog will stop the deployment. "
114
"Are you sure you want to do this?"),
115
QMessageBox::Yes | QMessageBox::No);
116
if (answer == QMessageBox::No)
118
else if (answer == QMessageBox::Yes)
119
m_uploadService->stop();
123
void BlackBerryDeployQtLibrariesDialog::deployLibraries()
125
QTC_ASSERT(m_state == Inactive, return);
127
if (m_ui->remoteDirectory->text().isEmpty()) {
128
QMessageBox::warning(this, windowTitle(),
129
tr("Please input a remote directory to deploy to."));
133
QTC_ASSERT(!m_device.isNull(), return);
136
m_ui->deployProgress->setValue(0);
137
m_ui->remoteDirectory->setEnabled(false);
138
m_ui->deployButton->setEnabled(false);
139
m_ui->qtLibraryCombo->setEnabled(false);
140
m_ui->deployLogWindow->clear();
142
checkRemoteDirectoryExistance();
145
void BlackBerryDeployQtLibrariesDialog::startUpload()
147
QTC_CHECK(m_state == CheckingRemoteDirectory || m_state == RemovingRemoteDirectory);
151
QList<ProjectExplorer::DeployableFile> filesToUpload = gatherFiles();
153
m_ui->deployProgress->setRange(0, filesToUpload.count());
155
m_uploadService->setDeployableFiles(filesToUpload);
156
m_uploadService->start();
159
void BlackBerryDeployQtLibrariesDialog::updateProgress(const QString &progressMessage)
161
QTC_CHECK(m_state == Uploading);
163
if (!progressMessage.startsWith(QLatin1String("Uploading file")))
168
m_ui->deployProgress->setValue(m_progressCount);
171
void BlackBerryDeployQtLibrariesDialog::handleUploadFinished()
173
m_ui->remoteDirectory->setEnabled(true);
174
m_ui->deployButton->setEnabled(true);
175
m_ui->qtLibraryCombo->setEnabled(true);
180
void BlackBerryDeployQtLibrariesDialog::handleRemoteProcessError()
182
QTC_CHECK(m_state == CheckingRemoteDirectory || m_state == RemovingRemoteDirectory);
184
m_ui->deployLogWindow->appendPlainText(
185
tr("Connection failed: %1")
186
.arg(m_processRunner->lastConnectionErrorString()));
187
handleUploadFinished();
190
void BlackBerryDeployQtLibrariesDialog::handleRemoteProcessCompleted()
192
QTC_CHECK(m_state == CheckingRemoteDirectory || m_state == RemovingRemoteDirectory);
194
if (m_state == CheckingRemoteDirectory) {
196
if (m_processRunner->processExitCode() == 0) {
197
int answer = QMessageBox::question(this, windowTitle(),
198
tr("The remote directory '%1' already exists. "
199
"Deploying to that directory will remove any files "
200
"already present.\n\n"
201
"Are you sure you want to continue?")
202
.arg(fullRemoteDirectory()),
203
QMessageBox::Yes | QMessageBox::No);
204
if (answer == QMessageBox::Yes)
205
removeRemoteDirectory();
207
handleUploadFinished();
211
} else if (m_state == RemovingRemoteDirectory) {
212
QTC_ASSERT(m_processRunner->processExitCode() == 0, return);
218
QList<ProjectExplorer::DeployableFile> BlackBerryDeployQtLibrariesDialog::gatherFiles()
220
QList<ProjectExplorer::DeployableFile> result;
222
const int qtVersionId =
223
m_ui->qtLibraryCombo->itemData(m_ui->qtLibraryCombo->currentIndex()).toInt();
224
BlackBerryQtVersion *qtVersion =
225
dynamic_cast<BlackBerryQtVersion *>(QtSupport::QtVersionManager::version(qtVersionId));
227
QTC_ASSERT(qtVersion, return result);
229
result.append(gatherFiles(qtVersion->versionInfo().value(QLatin1String("QT_INSTALL_LIBS"))));
230
result.append(gatherFiles(qtVersion->versionInfo().value(QLatin1String("QT_INSTALL_PLUGINS"))));
231
result.append(gatherFiles(qtVersion->versionInfo().value(QLatin1String("QT_INSTALL_IMPORTS"))));
232
result.append(gatherFiles(qtVersion->versionInfo().value(QLatin1String("QT_INSTALL_QML"))));
237
QList<ProjectExplorer::DeployableFile> BlackBerryDeployQtLibrariesDialog::gatherFiles(
238
const QString &dirPath, const QString &baseDirPath)
240
QList<ProjectExplorer::DeployableFile> result;
241
if (dirPath.isEmpty())
245
QFileInfoList list = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
247
for (int i = 0; i < list.size(); ++i) {
248
QFileInfo fileInfo = list.at(i);
249
if (fileInfo.isDir()) {
250
result.append(gatherFiles(fileInfo.absoluteFilePath(), baseDirPath.isEmpty() ?
251
dirPath : baseDirPath));
254
if (baseDirPath.isEmpty()) {
255
remoteDir = fullRemoteDirectory() + QLatin1Char('/') +
256
QFileInfo(dirPath).baseName();
258
QDir baseDir(baseDirPath);
260
remoteDir = fullRemoteDirectory() + QLatin1Char('/') +
261
baseDir.relativeFilePath(dirPath);
263
result.append(ProjectExplorer::DeployableFile(fileInfo.absoluteFilePath(), remoteDir));
270
QString BlackBerryDeployQtLibrariesDialog::fullRemoteDirectory() const
272
return QLatin1String(Constants::QNX_BLACKBERRY_DEFAULT_DEPLOY_QT_BASEPATH) + m_ui->remoteDirectory->text();
275
void BlackBerryDeployQtLibrariesDialog::checkRemoteDirectoryExistance()
277
QTC_CHECK(m_state == Inactive);
279
m_state = CheckingRemoteDirectory;
281
m_ui->deployLogWindow->appendPlainText(tr("Checking existence of '%1'")
282
.arg(fullRemoteDirectory()));
284
const QByteArray cmd = "test -d " + fullRemoteDirectory().toLatin1();
285
m_processRunner->run(cmd, m_device->sshParameters());
288
void BlackBerryDeployQtLibrariesDialog::removeRemoteDirectory()
290
QTC_CHECK(m_state == CheckingRemoteDirectory);
292
m_state = RemovingRemoteDirectory;
294
m_ui->deployLogWindow->appendPlainText(tr("Removing '%1'").arg(fullRemoteDirectory()));
296
const QByteArray cmd = "rm -rf " + fullRemoteDirectory().toLatin1();
297
m_processRunner->run(cmd, m_device->sshParameters());