~ubuntu-sdk-team/qtcreator-plugin-remotelinux/trunk

« back to all changes in this revision

Viewing changes to src/qnx/blackberrydeployqtlibrariesdialog.cpp

  • Committer: CI bot
  • Author(s): Benjamin Zeller
  • Date: 2014-06-16 10:28:43 UTC
  • mfrom: (4.2.4 remotelinux)
  • Revision ID: ps-jenkins@lists.canonical.com-20140616102843-8juvmjvzwlzsboyw
Migrating to Qt5.3 and QtC 3.1 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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://qt.digia.com/licensing.  For further information
 
16
** use the contact form at http://qt.digia.com/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 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.
 
25
**
 
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.
 
29
**
 
30
****************************************************************************/
 
31
 
 
32
#include "blackberrydeployqtlibrariesdialog.h"
 
33
#include "ui_blackberrydeployqtlibrariesdialog.h"
 
34
 
 
35
#include "blackberryqtversion.h"
 
36
 
 
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>
 
42
 
 
43
#include <QDir>
 
44
#include <QMessageBox>
 
45
 
 
46
using namespace Qnx;
 
47
using namespace Qnx::Internal;
 
48
 
 
49
BlackBerryDeployQtLibrariesDialog::BlackBerryDeployQtLibrariesDialog(
 
50
        const ProjectExplorer::IDevice::ConstPtr &device, QWidget *parent)
 
51
    : QDialog(parent)
 
52
    , m_ui(new Ui::BlackBerryDeployQtLibrariesDialog)
 
53
    , m_device(device)
 
54
    , m_progressCount(0)
 
55
    , m_state(Inactive)
 
56
{
 
57
    m_ui->setupUi(this);
 
58
 
 
59
    QList<QtSupport::BaseQtVersion*> qtVersions = QtSupport::QtVersionManager::validVersions();
 
60
    foreach (QtSupport::BaseQtVersion *qtVersion, qtVersions) {
 
61
        BlackBerryQtVersion *blackBerryQt = dynamic_cast<BlackBerryQtVersion *>(qtVersion);
 
62
        if (!blackBerryQt)
 
63
            continue;
 
64
 
 
65
        m_ui->qtLibraryCombo->addItem(blackBerryQt->displayName(), blackBerryQt->uniqueId());
 
66
    }
 
67
 
 
68
    m_uploadService = new RemoteLinux::GenericDirectUploadService(this);
 
69
    m_uploadService->setDevice(m_device);
 
70
 
 
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()));
 
83
 
 
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()));
 
89
 
 
90
    connect(m_ui->deployButton, SIGNAL(clicked()), this, SLOT(deployLibraries()));
 
91
    connect(m_ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
 
92
}
 
93
 
 
94
BlackBerryDeployQtLibrariesDialog::~BlackBerryDeployQtLibrariesDialog()
 
95
{
 
96
    delete m_ui;
 
97
}
 
98
 
 
99
int BlackBerryDeployQtLibrariesDialog::execAndDeploy(int qtVersionId, const QString &remoteDirectory)
 
100
{
 
101
    m_ui->remoteDirectory->setText(remoteDirectory);
 
102
    m_ui->qtLibraryCombo->setCurrentIndex(m_ui->qtLibraryCombo->findData(qtVersionId));
 
103
 
 
104
    deployLibraries();
 
105
    return exec();
 
106
}
 
107
 
 
108
void BlackBerryDeployQtLibrariesDialog::closeEvent(QCloseEvent *event)
 
109
{
 
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)
 
117
            event->ignore();
 
118
        else if (answer == QMessageBox::Yes)
 
119
            m_uploadService->stop();
 
120
    }
 
121
}
 
122
 
 
123
void BlackBerryDeployQtLibrariesDialog::deployLibraries()
 
124
{
 
125
    QTC_ASSERT(m_state == Inactive, return);
 
126
 
 
127
    if (m_ui->remoteDirectory->text().isEmpty()) {
 
128
        QMessageBox::warning(this, windowTitle(),
 
129
                             tr("Please input a remote directory to deploy to."));
 
130
        return;
 
131
    }
 
132
 
 
133
    QTC_ASSERT(!m_device.isNull(), return);
 
134
 
 
135
    m_progressCount = 0;
 
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();
 
141
 
 
142
    checkRemoteDirectoryExistance();
 
143
}
 
144
 
 
145
void BlackBerryDeployQtLibrariesDialog::startUpload()
 
146
{
 
147
    QTC_CHECK(m_state == CheckingRemoteDirectory || m_state == RemovingRemoteDirectory);
 
148
 
 
149
    m_state = Uploading;
 
150
 
 
151
    QList<ProjectExplorer::DeployableFile> filesToUpload = gatherFiles();
 
152
 
 
153
    m_ui->deployProgress->setRange(0, filesToUpload.count());
 
154
 
 
155
    m_uploadService->setDeployableFiles(filesToUpload);
 
156
    m_uploadService->start();
 
157
}
 
158
 
 
159
void BlackBerryDeployQtLibrariesDialog::updateProgress(const QString &progressMessage)
 
160
{
 
161
    QTC_CHECK(m_state == Uploading);
 
162
 
 
163
    if (!progressMessage.startsWith(QLatin1String("Uploading file")))
 
164
        return;
 
165
 
 
166
    ++m_progressCount;
 
167
 
 
168
    m_ui->deployProgress->setValue(m_progressCount);
 
169
}
 
170
 
 
171
void BlackBerryDeployQtLibrariesDialog::handleUploadFinished()
 
172
{
 
173
    m_ui->remoteDirectory->setEnabled(true);
 
174
    m_ui->deployButton->setEnabled(true);
 
175
    m_ui->qtLibraryCombo->setEnabled(true);
 
176
 
 
177
    m_state = Inactive;
 
178
}
 
179
 
 
180
void BlackBerryDeployQtLibrariesDialog::handleRemoteProcessError()
 
181
{
 
182
    QTC_CHECK(m_state == CheckingRemoteDirectory || m_state == RemovingRemoteDirectory);
 
183
 
 
184
    m_ui->deployLogWindow->appendPlainText(
 
185
                tr("Connection failed: %1")
 
186
                .arg(m_processRunner->lastConnectionErrorString()));
 
187
    handleUploadFinished();
 
188
}
 
189
 
 
190
void BlackBerryDeployQtLibrariesDialog::handleRemoteProcessCompleted()
 
191
{
 
192
    QTC_CHECK(m_state == CheckingRemoteDirectory || m_state == RemovingRemoteDirectory);
 
193
 
 
194
    if (m_state == CheckingRemoteDirectory) {
 
195
        // Directory exists
 
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();
 
206
            else
 
207
                handleUploadFinished();
 
208
        } else {
 
209
            startUpload();
 
210
        }
 
211
    } else if (m_state == RemovingRemoteDirectory) {
 
212
        QTC_ASSERT(m_processRunner->processExitCode() == 0, return);
 
213
 
 
214
        startUpload();
 
215
    }
 
216
}
 
217
 
 
218
QList<ProjectExplorer::DeployableFile> BlackBerryDeployQtLibrariesDialog::gatherFiles()
 
219
{
 
220
    QList<ProjectExplorer::DeployableFile> result;
 
221
 
 
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));
 
226
 
 
227
    QTC_ASSERT(qtVersion, return result);
 
228
 
 
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"))));
 
233
 
 
234
    return result;
 
235
}
 
236
 
 
237
QList<ProjectExplorer::DeployableFile> BlackBerryDeployQtLibrariesDialog::gatherFiles(
 
238
        const QString &dirPath, const QString &baseDirPath)
 
239
{
 
240
    QList<ProjectExplorer::DeployableFile> result;
 
241
    if (dirPath.isEmpty())
 
242
        return result;
 
243
 
 
244
    QDir dir(dirPath);
 
245
    QFileInfoList list = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
 
246
 
 
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));
 
252
        } else {
 
253
            QString remoteDir;
 
254
            if (baseDirPath.isEmpty()) {
 
255
                remoteDir = fullRemoteDirectory() + QLatin1Char('/') +
 
256
                        QFileInfo(dirPath).baseName();
 
257
            } else {
 
258
                QDir baseDir(baseDirPath);
 
259
                baseDir.cdUp();
 
260
                remoteDir = fullRemoteDirectory() + QLatin1Char('/') +
 
261
                        baseDir.relativeFilePath(dirPath);
 
262
            }
 
263
            result.append(ProjectExplorer::DeployableFile(fileInfo.absoluteFilePath(), remoteDir));
 
264
        }
 
265
    }
 
266
 
 
267
    return result;
 
268
}
 
269
 
 
270
QString BlackBerryDeployQtLibrariesDialog::fullRemoteDirectory() const
 
271
{
 
272
    return QLatin1String(Constants::QNX_BLACKBERRY_DEFAULT_DEPLOY_QT_BASEPATH) + m_ui->remoteDirectory->text();
 
273
}
 
274
 
 
275
void BlackBerryDeployQtLibrariesDialog::checkRemoteDirectoryExistance()
 
276
{
 
277
    QTC_CHECK(m_state == Inactive);
 
278
 
 
279
    m_state = CheckingRemoteDirectory;
 
280
 
 
281
    m_ui->deployLogWindow->appendPlainText(tr("Checking existence of '%1'")
 
282
                                           .arg(fullRemoteDirectory()));
 
283
 
 
284
    const QByteArray cmd = "test -d " + fullRemoteDirectory().toLatin1();
 
285
    m_processRunner->run(cmd, m_device->sshParameters());
 
286
}
 
287
 
 
288
void BlackBerryDeployQtLibrariesDialog::removeRemoteDirectory()
 
289
{
 
290
    QTC_CHECK(m_state == CheckingRemoteDirectory);
 
291
 
 
292
    m_state = RemovingRemoteDirectory;
 
293
 
 
294
    m_ui->deployLogWindow->appendPlainText(tr("Removing '%1'").arg(fullRemoteDirectory()));
 
295
 
 
296
    const QByteArray cmd = "rm -rf " + fullRemoteDirectory().toLatin1();
 
297
    m_processRunner->run(cmd, m_device->sshParameters());
 
298
}