s60createpackagestep.cpp 24.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "s60createpackagestep.h"

#include "qt4projectmanagerconstants.h"
#include "qt4buildconfiguration.h"
dt's avatar
dt committed
34
35
#include "qt4nodes.h"
#include "qt4project.h"
36
#include "abldparser.h"
37
#include "sbsv2parser.h"
38
39
#include "signsisparser.h"
#include "passphraseforkeydialog.h"
40
41

#include <projectexplorer/buildconfiguration.h>
Tobias Hunger's avatar
Tobias Hunger committed
42
43
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectexplorerconstants.h>
44
#include <projectexplorer/target.h>
dt's avatar
dt committed
45
#include <projectexplorer/project.h>
46
#include <projectexplorer/gnumakeparser.h>
dt's avatar
dt committed
47
#include <projectexplorer/task.h>
48

49
#include <QtCore/QDir>
dt's avatar
dt committed
50
#include <QtCore/QTimer>
51
52
53
54
#include <QtCore/QCryptographicHash>

#include <QSettings>
#include <QMessageBox>
55

56
57
58
59
60
61
62
using namespace Qt4ProjectManager::Internal;

namespace {
    const char * const SIGN_BS_ID = "Qt4ProjectManager.S60SignBuildStep";
    const char * const SIGNMODE_KEY("Qt4ProjectManager.S60CreatePackageStep.SignMode");
    const char * const CERTIFICATE_KEY("Qt4ProjectManager.S60CreatePackageStep.Certificate");
    const char * const KEYFILE_KEY("Qt4ProjectManager.S60CreatePackageStep.Keyfile");
con's avatar
con committed
63
    const char * const SMART_INSTALLER_KEY("Qt4ProjectManager.S60CreatorPackageStep.SmartInstaller");
64
65
66
67

    const char * const MAKE_PASSPHRASE_ARGUMENT("QT_SIS_PASSPHRASE=");
    const char * const MAKE_KEY_ARGUMENT("QT_SIS_KEY=");
    const char * const MAKE_CERTIFICATE_ARGUMENT("QT_SIS_CERTIFICATE=");
68
69
}

Tobias Hunger's avatar
Tobias Hunger committed
70
71
S60CreatePackageStep::S60CreatePackageStep(ProjectExplorer::BuildStepList *bsl) :
    BuildStep(bsl, QLatin1String(SIGN_BS_ID)),
con's avatar
con committed
72
    m_signingMode(SignSelf),
dt's avatar
dt committed
73
74
75
76
77
    m_createSmartInstaller(false),
    m_outputParserChain(0),
    m_process(0),
    m_timer(0),
    m_eventLoop(0),
78
79
80
    m_futureInterface(0),
    m_errorType(ErrorNone),
    m_settings(0)
81
82
83
84
{
    ctor_package();
}

Tobias Hunger's avatar
Tobias Hunger committed
85
86
S60CreatePackageStep::S60CreatePackageStep(ProjectExplorer::BuildStepList *bsl, S60CreatePackageStep *bs) :
    BuildStep(bsl, bs),
87
88
    m_signingMode(bs->m_signingMode),
    m_customSignaturePath(bs->m_customSignaturePath),
con's avatar
con committed
89
    m_customKeyPath(bs->m_customKeyPath),
90
    m_passphrase(bs->m_passphrase),
dt's avatar
dt committed
91
92
93
94
    m_createSmartInstaller(bs->m_createSmartInstaller),
    m_outputParserChain(0),
    m_timer(0),
    m_eventLoop(0),
95
96
97
    m_futureInterface(0),
    m_errorType(ErrorNone),
    m_settings(0)
98
99
100
101
{
    ctor_package();
}

Tobias Hunger's avatar
Tobias Hunger committed
102
103
S60CreatePackageStep::S60CreatePackageStep(ProjectExplorer::BuildStepList *bsl, const QString &id) :
    BuildStep(bsl, id),
con's avatar
con committed
104
    m_signingMode(SignSelf),
dt's avatar
dt committed
105
106
107
108
    m_createSmartInstaller(false),
    m_outputParserChain(0),
    m_timer(0),
    m_eventLoop(0),
109
110
111
    m_futureInterface(0),
    m_errorType(ErrorNone),
    m_settings(0)
112
113
114
115
116
117
{
    ctor_package();
}

void S60CreatePackageStep::ctor_package()
{
118
119
    //: default create SIS package build step display name
    setDefaultDisplayName(tr("Create SIS Package"));
120
121
122
123
124
    connect(this, SIGNAL(badPassphrase()),
            this, SLOT(definePassphrase()), Qt::QueuedConnection);

    m_settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
                                 QLatin1String("Nokia"), QLatin1String("QtCreatorKeys"), this);
125
126
127
128
129
130
131
132
}

S60CreatePackageStep::~S60CreatePackageStep()
{
}

QVariantMap S60CreatePackageStep::toMap() const
{
dt's avatar
dt committed
133
    QVariantMap map(BuildStep::toMap());
134
135
136
    map.insert(QLatin1String(SIGNMODE_KEY), (int)m_signingMode);
    map.insert(QLatin1String(CERTIFICATE_KEY), m_customSignaturePath);
    map.insert(QLatin1String(KEYFILE_KEY), m_customKeyPath);
con's avatar
con committed
137
    map.insert(QLatin1String(SMART_INSTALLER_KEY), m_createSmartInstaller);
138
139
140
141
142
    return map;
}

bool S60CreatePackageStep::fromMap(const QVariantMap &map)
{
143
    m_signingMode = static_cast<SigningMode>(map.value(QLatin1String(SIGNMODE_KEY), static_cast<int>(SignSelf)).toInt());
144
    m_customSignaturePath = map.value(QLatin1String(CERTIFICATE_KEY)).toString();
145
    setCustomKeyPath(map.value(QLatin1String(KEYFILE_KEY)).toString());
con's avatar
con committed
146
    m_createSmartInstaller = map.value(QLatin1String(SMART_INSTALLER_KEY), false).toBool();
dt's avatar
dt committed
147
148
149
150
151
152
    return BuildStep::fromMap(map);
}

Qt4BuildConfiguration *S60CreatePackageStep::qt4BuildConfiguration() const
{
    return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
153
154
155
156
}

bool S60CreatePackageStep::init()
{
dt's avatar
dt committed
157
158
159
160
161
162
163
164
165
166
167
168
169
    Qt4Project *pro = qobject_cast<Qt4Project *>(buildConfiguration()->target()->project());

    QList<Qt4ProFileNode *> nodes = pro->leafProFiles();

    m_workingDirectories.clear();
    foreach (Qt4ProFileNode *node, nodes)
        m_workingDirectories << node->buildDir();

    m_makeCmd = qt4BuildConfiguration()->makeCommand();
    if (!QFileInfo(m_makeCmd).isAbsolute()) {
        // Try to detect command in environment
        const QString tmp = buildConfiguration()->environment().searchInPath(m_makeCmd);
        if (tmp.isEmpty()) {
170
            emit addOutput(tr("Could not find make command '%1' in the build environment").arg(m_makeCmd), BuildStep::ErrorOutput);
dt's avatar
dt committed
171
172
173
174
175
176
177
178
            return false;
        }
        m_makeCmd = tmp;
    }

    m_environment = qt4BuildConfiguration()->environment();

    m_args.clear();
179
180
181
182
183
184
185
    if (m_createSmartInstaller) {
        if(signingMode() == NotSigned)
            m_args << QLatin1String("unsigned_installer_sis");
        else
            m_args << QLatin1String("installer_sis");
    } else if (signingMode() == NotSigned)
        m_args << QLatin1String("unsigned_sis");
con's avatar
con committed
186
    else
dt's avatar
dt committed
187
        m_args << QLatin1String("sis");
Pawel Polanski's avatar
Pawel Polanski committed
188

189
    if (signingMode() == SignCustom) {
190
191
192
193
194
195
196
197
        m_args << QLatin1String(MAKE_CERTIFICATE_ARGUMENT) + QDir::toNativeSeparators(customSignaturePath())
               << QLatin1String(MAKE_KEY_ARGUMENT) + QDir::toNativeSeparators(customKeyPath());

        setPassphrase(loadPassphraseForKey(m_keyId));

        if (!passphrase().isEmpty()) {
            m_args << QLatin1String(MAKE_PASSPHRASE_ARGUMENT) + passphrase();
        }
dt's avatar
dt committed
198
199
200
    }

    delete m_outputParserChain;
201
202
203
204
205
    if (qt4BuildConfiguration()->qtVersion()->isBuildWithSymbianSbsV2())
        m_outputParserChain = new Qt4ProjectManager::SbsV2Parser;
    else
        m_outputParserChain = new Qt4ProjectManager::AbldParser;
    m_outputParserChain->appendOutputParser(new ProjectExplorer::GnuMakeParser);
206
207
    m_outputParserChain->appendOutputParser(new Qt4ProjectManager::SignsisParser);

dt's avatar
dt committed
208
209
210
    connect(m_outputParserChain, SIGNAL(addOutput(QString, ProjectExplorer::BuildStep::OutputFormat)),
            this, SLOT(outputAdded(QString, ProjectExplorer::BuildStep::OutputFormat)));
    connect(m_outputParserChain, SIGNAL(addTask(ProjectExplorer::Task)),
211
            this, SLOT(taskAdded(ProjectExplorer::Task)), Qt::DirectConnection);
dt's avatar
dt committed
212
213
214
215

    return true;
}

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
void S60CreatePackageStep::definePassphrase()
{
    PassphraseForKeyDialog *passwordDialog
            = new PassphraseForKeyDialog(QFileInfo(customKeyPath()).fileName());
    if (passwordDialog->exec()) {
        setPassphrase(passwordDialog->passphrase());
        if (passwordDialog->savePassphrase())
            savePassphraseForKey(m_keyId, passphrase());
    } else
        m_errorType = ErrorUndefined;
    delete passwordDialog;
    passwordDialog = 0;

    m_waitCondition.wakeAll();
}

void S60CreatePackageStep::savePassphraseForKey(const QString &keyId, const QString &passphrase)
{
    m_settings->beginGroup("keys");
    if (passphrase.isEmpty())
        m_settings->remove(keyId);
    else
        m_settings->setValue(keyId, obfuscatePassphrase(passphrase, keyId));
    m_settings->endGroup();
}

QString S60CreatePackageStep::loadPassphraseForKey(const QString &keyId)
{
    m_settings->beginGroup("keys");
    QString passphrase = elucidatePassphrase(m_settings->value(keyId, QByteArray()).toByteArray(), keyId);
    m_settings->endGroup();
    return passphrase;
}

QByteArray S60CreatePackageStep::obfuscatePassphrase(const QString &passphrase, const QString &key) const
{
    QByteArray byteArray = passphrase.toUtf8();
    char *data = byteArray.data();
    const QChar *keyData = key.data();
    int keyDataSize = key.size();
    for (int i = 0; i <byteArray.size(); ++i)
        data[i] = data[i]^keyData[i%keyDataSize].toAscii();
    return byteArray.toBase64();
}

QString S60CreatePackageStep::elucidatePassphrase(QByteArray obfuscatedPassphrase, const QString &key) const
{
    QByteArray byteArray = QByteArray::fromBase64(obfuscatedPassphrase);
    char *data = byteArray.data();
    const QChar *keyData = key.data();
    int keyDataSize = key.size();
    for (int i = 0; i < byteArray.size(); ++i)
        data[i] = data[i]^keyData[i%keyDataSize].toAscii();
    return byteArray.data();
}

dt's avatar
dt committed
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
void S60CreatePackageStep::run(QFutureInterface<bool> &fi)
{
    m_futureInterface = &fi;

    if (m_workingDirectories.isEmpty()) {
        fi.reportResult(true);
        return;
    }

    // Setup everything...
    m_process = new QProcess();
    m_process->setEnvironment(m_environment.toStringList());

    connect(m_process, SIGNAL(readyReadStandardOutput()),
            this, SLOT(processReadyReadStdOutput()),
            Qt::DirectConnection);
    connect(m_process, SIGNAL(readyReadStandardError()),
            this, SLOT(processReadyReadStdError()),
            Qt::DirectConnection);

    connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
            this, SLOT(slotProcessFinished(int, QProcess::ExitStatus)),
            Qt::DirectConnection);

    m_timer = new QTimer();
    connect(m_timer, SIGNAL(timeout()), this, SLOT(checkForCancel()), Qt::DirectConnection);
    m_timer->start(500);
    m_eventLoop = new QEventLoop;

    bool returnValue = false;
    if (startProcess())
        returnValue = m_eventLoop->exec();

    // Finished
    m_timer->stop();
    delete m_timer;
    m_timer = 0;

    delete m_process;
    m_process = 0;
    delete m_eventLoop;
    m_eventLoop = 0;
    fi.reportResult(returnValue);
    m_futureInterface = 0;

    return;
}

void S60CreatePackageStep::slotProcessFinished(int, QProcess::ExitStatus)
{
    QString line = QString::fromLocal8Bit(m_process->readAllStandardError());
    if (!line.isEmpty())
        stdError(line);

    line = QString::fromLocal8Bit(m_process->readAllStandardOutput());
    if (!line.isEmpty())
        stdOutput(line);

    bool returnValue = false;
    if (m_process->exitStatus() == QProcess::NormalExit && m_process->exitCode() == 0) {
        emit addOutput(tr("The process \"%1\" exited normally.")
                       .arg(QDir::toNativeSeparators(m_makeCmd)),
                       BuildStep::MessageOutput);
        returnValue = true;
    } else if (m_process->exitStatus() == QProcess::NormalExit) {
        emit addOutput(tr("The process \"%1\" exited with code %2.")
                       .arg(QDir::toNativeSeparators(m_makeCmd), QString::number(m_process->exitCode())),
                       BuildStep::ErrorMessageOutput);
    } else {
        emit addOutput(tr("The process \"%1\" crashed.").arg(QDir::toNativeSeparators(m_makeCmd)), BuildStep::ErrorMessageOutput);
342
    }
343

344
345
346
347
348
349
350
351
352
353
    switch (m_errorType) {
    case ErrorUndefined:
        m_eventLoop->exit(false);
        return;
    case ErrorBadPassphrase: {
        emit badPassphrase();
        QMutexLocker locker(&m_mutex);
        //waiting for the user to input new passphrase or to abort
        m_waitCondition.wait(&m_mutex);
        if( m_errorType == ErrorUndefined ) {
354
            m_eventLoop->exit(false);
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
            return;
        } else {
            QRegExp passphraseRegExp("^"+QLatin1String(MAKE_PASSPHRASE_ARGUMENT)+"(.+)$");
            int index = m_args.indexOf(passphraseRegExp);
            if (index>=0)
                m_args.removeAt(index);
            if (!passphrase().isEmpty())
                m_args << QLatin1String(MAKE_PASSPHRASE_ARGUMENT) + passphrase();
        }
        break;
    }
    default:
        m_workingDirectories.removeFirst();
        break;
    }

dt's avatar
dt committed
371
372
373
374
375
376
377
378
379
380
381
    if (m_workingDirectories.isEmpty() || !returnValue) {
        m_eventLoop->exit(returnValue);
    } else {
        // Success, do next
        if (!startProcess())
            m_eventLoop->exit(returnValue);
    }
}

bool S60CreatePackageStep::startProcess()
{
382
383
    m_errorType = ErrorNone;
    QString workingDirectory = m_workingDirectories.first();
dt's avatar
dt committed
384
385
386
387
388
    QDir wd(workingDirectory);
    if (!wd.exists())
        wd.mkpath(wd.absolutePath());

    m_process->setWorkingDirectory(workingDirectory);
389

dt's avatar
dt committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
    // Go for it!
    m_process->start(m_makeCmd, m_args);
    if (!m_process->waitForStarted()) {
        emit addOutput(tr("Could not start process \"%1\" in %2")
                       .arg(QDir::toNativeSeparators(m_makeCmd),
                            workingDirectory),
                       BuildStep::ErrorMessageOutput);
        return false;
    }
    emit addOutput(tr("Starting: \"%1\" %2 in %3\n")
                   .arg(QDir::toNativeSeparators(m_makeCmd),
                        m_args.join(" "),
                        workingDirectory),
                   BuildStep::MessageOutput);
404
405
406
    return true;
}

dt's avatar
dt committed
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
void S60CreatePackageStep::processReadyReadStdOutput()
{
    m_process->setReadChannel(QProcess::StandardOutput);
    while (m_process->canReadLine()) {
        QString line = QString::fromLocal8Bit(m_process->readLine());
        stdOutput(line);
    }
}

void S60CreatePackageStep::stdOutput(const QString &line)
{
    if (m_outputParserChain)
        m_outputParserChain->stdOutput(line);
    emit addOutput(line, BuildStep::NormalOutput);
}

void S60CreatePackageStep::processReadyReadStdError()
{
    m_process->setReadChannel(QProcess::StandardError);
    while (m_process->canReadLine()) {
        QString line = QString::fromLocal8Bit(m_process->readLine());
        stdError(line);
    }
}

void S60CreatePackageStep::stdError(const QString &line)
{
    if (m_outputParserChain)
        m_outputParserChain->stdError(line);
    emit addOutput(line, BuildStep::ErrorOutput);
}

void S60CreatePackageStep::checkForCancel()
{
    if (m_futureInterface->isCanceled() && m_timer->isActive()) {
        m_timer->stop();
        m_process->terminate();
        m_process->waitForFinished(5000);
        m_process->kill();
    }
}

void S60CreatePackageStep::taskAdded(const ProjectExplorer::Task &task)
{
    ProjectExplorer::Task editable(task);
    QString filePath = QDir::cleanPath(task.file.trimmed());
    if (!filePath.isEmpty() && !QDir::isAbsolutePath(filePath)) {
        // TODO which kind of tasks do we get from package building?
        // No absoulte path
    }
457
458
459
460
461
462
463
    if (task.type == ProjectExplorer::Task::Error) {
        if (task.description.contains(QLatin1String("bad password"))
                || task.description.contains(QLatin1String("bad decrypt")))
            m_errorType = ErrorBadPassphrase;
        else if (m_errorType == ErrorNone)
            m_errorType = ErrorUndefined;
    }
dt's avatar
dt committed
464
465
466
    emit addTask(editable);
}

467
468
469
470
471
472
473
474
475
476
477
478
479
480
QString S60CreatePackageStep::generateKeyId(const QString &keyPath) const
{
    if (keyPath.isEmpty())
        return QString();

    QFile file(keyPath);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return QString();

    //key file is quite small in size
    return QCryptographicHash::hash(file.readAll(),
                                    QCryptographicHash::Md5).toHex();
}

dt's avatar
dt committed
481
482
483
484
485
void S60CreatePackageStep::outputAdded(const QString &string, ProjectExplorer::BuildStep::OutputFormat format)
{
    emit addOutput(string, format);
}

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
bool S60CreatePackageStep::immutable() const
{
    return false;
}

ProjectExplorer::BuildStepConfigWidget *S60CreatePackageStep::createConfigWidget()
{
    return new S60CreatePackageStepConfigWidget(this);
}

S60CreatePackageStep::SigningMode S60CreatePackageStep::signingMode() const
{
    return m_signingMode;
}

void S60CreatePackageStep::setSigningMode(SigningMode mode)
{
    m_signingMode = mode;
}

QString S60CreatePackageStep::customSignaturePath() const
{
    return m_customSignaturePath;
}

void S60CreatePackageStep::setCustomSignaturePath(const QString &path)
{
    m_customSignaturePath = path;
}

QString S60CreatePackageStep::customKeyPath() const
{
    return m_customKeyPath;
}

void S60CreatePackageStep::setCustomKeyPath(const QString &path)
{
    m_customKeyPath = path;
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
    m_keyId = generateKeyId(m_customKeyPath);
}

QString S60CreatePackageStep::passphrase() const
{
    return m_passphrase;
}

void S60CreatePackageStep::setPassphrase(const QString &passphrase)
{
    m_passphrase = passphrase;
}

QString S60CreatePackageStep::keyId() const
{
    return m_keyId;
}

void S60CreatePackageStep::setKeyId(const QString &keyId)
{
    m_keyId = keyId;
545
546
}

547
bool S60CreatePackageStep::createsSmartInstaller() const
con's avatar
con committed
548
549
550
551
{
    return m_createSmartInstaller;
}

552
void S60CreatePackageStep::setCreatesSmartInstaller(bool value)
con's avatar
con committed
553
554
{
    m_createSmartInstaller = value;
555
    static_cast<Qt4BuildConfiguration *>(buildConfiguration())->emitS60CreatesSmartInstallerChanged();
con's avatar
con committed
556
557
}

558
559
560
561
562
563
564
565
566
567
568
void S60CreatePackageStep::resetPassphrases()
{
    m_settings->beginGroup("keys");
    QStringList keys = m_settings->allKeys();
    foreach (QString key, keys) {
        m_settings->setValue(key, "");
    }
    m_settings->remove("");
    m_settings->endGroup();
}

569
570
571
572
573
574
575
576
577
578
579
// #pragma mark -- S60SignBuildStepFactory

S60CreatePackageStepFactory::S60CreatePackageStepFactory(QObject *parent) :
    ProjectExplorer::IBuildStepFactory(parent)
{
}

S60CreatePackageStepFactory::~S60CreatePackageStepFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
580
bool S60CreatePackageStepFactory::canCreate(ProjectExplorer::BuildStepList *parent, const QString &id) const
581
{
Tobias Hunger's avatar
Tobias Hunger committed
582
    if (parent->id() != QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY))
583
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
584
    if (parent->target()->id() != QLatin1String(Constants::S60_DEVICE_TARGET_ID))
585
586
587
588
        return false;
    return (id == QLatin1String(SIGN_BS_ID));
}

Tobias Hunger's avatar
Tobias Hunger committed
589
ProjectExplorer::BuildStep *S60CreatePackageStepFactory::create(ProjectExplorer::BuildStepList *parent, const QString &id)
590
{
Tobias Hunger's avatar
Tobias Hunger committed
591
    if (!canCreate(parent, id))
592
593
594
595
        return 0;
    return new S60CreatePackageStep(parent);
}

Tobias Hunger's avatar
Tobias Hunger committed
596
bool S60CreatePackageStepFactory::canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) const
597
{
Tobias Hunger's avatar
Tobias Hunger committed
598
    return canCreate(parent, source->id());
599
600
}

Tobias Hunger's avatar
Tobias Hunger committed
601
ProjectExplorer::BuildStep *S60CreatePackageStepFactory::clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source)
602
{
Tobias Hunger's avatar
Tobias Hunger committed
603
    if (!canClone(parent, source))
604
605
606
607
        return 0;
    return new S60CreatePackageStep(parent, static_cast<S60CreatePackageStep *>(source));
}

Tobias Hunger's avatar
Tobias Hunger committed
608
bool S60CreatePackageStepFactory::canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const
609
610
{
    QString id(ProjectExplorer::idFromMap(map));
Tobias Hunger's avatar
Tobias Hunger committed
611
    return canCreate(parent, id);
612
613
}

Tobias Hunger's avatar
Tobias Hunger committed
614
ProjectExplorer::BuildStep *S60CreatePackageStepFactory::restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map)
615
{
Tobias Hunger's avatar
Tobias Hunger committed
616
    if (!canRestore(parent, map))
617
618
619
620
621
622
623
624
        return 0;
    S60CreatePackageStep *bs(new S60CreatePackageStep(parent));
    if (bs->fromMap(map))
        return bs;
    delete bs;
    return 0;
}

Tobias Hunger's avatar
Tobias Hunger committed
625
QStringList S60CreatePackageStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
626
{
Tobias Hunger's avatar
Tobias Hunger committed
627
    if (parent->id() != QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY))
628
        return QStringList();
Tobias Hunger's avatar
Tobias Hunger committed
629
    if (parent->target()->id() == QLatin1String(Constants::S60_DEVICE_TARGET_ID))
630
631
632
633
634
635
636
        return QStringList() << QLatin1String(SIGN_BS_ID);
    return QStringList();
}

QString S60CreatePackageStepFactory::displayNameForId(const QString &id) const
{
    if (id == QLatin1String(SIGN_BS_ID))
637
        return tr("Create SIS Package");
638
639
640
641
642
643
644
645
646
    return QString();
}

// #pragma mark -- S60SignBuildStepConfigWidget

S60CreatePackageStepConfigWidget::S60CreatePackageStepConfigWidget(S60CreatePackageStep *signStep)
    : BuildStepConfigWidget(), m_signStep(signStep)
{
    m_ui.setupUi(this);
647
648
    m_ui.signaturePath->setExpectedKind(Utils::PathChooser::File);
    m_ui.keyFilePath->setExpectedKind(Utils::PathChooser::File);
649
650
651
652
653
    updateUi();
    connect(m_ui.customCertificateButton, SIGNAL(clicked()),
            this, SLOT(updateFromUi()));
    connect(m_ui.selfSignedButton, SIGNAL(clicked()),
            this, SLOT(updateFromUi()));
654
655
    connect(m_ui.notSignedButton, SIGNAL(clicked()),
            this, SLOT(updateFromUi()));
656
657
658
659
    connect(m_ui.signaturePath, SIGNAL(changed(QString)),
            this, SLOT(updateFromUi()));
    connect(m_ui.keyFilePath, SIGNAL(changed(QString)),
            this, SLOT(updateFromUi()));
con's avatar
con committed
660
661
    connect(m_ui.smartInstaller, SIGNAL(clicked()),
            this, SLOT(updateFromUi()));
662
663
    connect(m_ui.resetPassphrasesButton, SIGNAL(clicked()),
            this, SLOT(resetPassphrases()));
664
665
666
667
}

void S60CreatePackageStepConfigWidget::updateUi()
{
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688

    switch(m_signStep->signingMode()) {
    case S60CreatePackageStep::SignCustom:
        m_ui.selfSignedButton->setChecked(false);
        m_ui.customCertificateButton->setChecked(true);
        m_ui.notSignedButton->setChecked(false);
        break;
    case S60CreatePackageStep::NotSigned:
        m_ui.selfSignedButton->setChecked(false);
        m_ui.customCertificateButton->setChecked(false);
        m_ui.notSignedButton->setChecked(true);
        break;
    default:
        m_ui.selfSignedButton->setChecked(true);
        m_ui.customCertificateButton->setChecked(false);
        m_ui.notSignedButton->setChecked(false);
        break;
    }
    bool customSigned = m_signStep->signingMode() == S60CreatePackageStep::SignCustom;
    m_ui.signaturePath->setEnabled(customSigned);
    m_ui.keyFilePath->setEnabled(customSigned);
689
690
    m_ui.signaturePath->setPath(m_signStep->customSignaturePath());
    m_ui.keyFilePath->setPath(m_signStep->customKeyPath());
691
    m_ui.smartInstaller->setChecked(m_signStep->createsSmartInstaller());
692
693
694
695
696
    emit updateSummary();
}

void S60CreatePackageStepConfigWidget::updateFromUi()
{
697
698
699
700
701
702
703
704
705
    S60CreatePackageStep::SigningMode signingMode(S60CreatePackageStep::SignSelf);
    if (m_ui.selfSignedButton->isChecked())
        signingMode = S60CreatePackageStep::SignSelf;
    else if (m_ui.customCertificateButton->isChecked())
        signingMode = S60CreatePackageStep::SignCustom;
    else if (m_ui.notSignedButton->isChecked())
        signingMode = S60CreatePackageStep::NotSigned;

    m_signStep->setSigningMode(signingMode);
706
707
    m_signStep->setCustomSignaturePath(m_ui.signaturePath->path());
    m_signStep->setCustomKeyPath(m_ui.keyFilePath->path());
708
    m_signStep->setCreatesSmartInstaller(m_ui.smartInstaller->isChecked());
709
710
711
    updateUi();
}

712
713
void S60CreatePackageStepConfigWidget::resetPassphrases()
{
Leena Miettinen's avatar
Leena Miettinen committed
714
715
    QMessageBox msgBox(QMessageBox::Question, tr("Reset Passphrases"),
                       tr("Do you want to reset all passphrases saved for keys used?"),
Friedemann Kleint's avatar
Friedemann Kleint committed
716
717
                       QMessageBox::Reset|QMessageBox::Cancel, this);
    if (msgBox.exec() == QMessageBox::Reset)
718
719
720
        m_signStep->resetPassphrases();
}

721
722
723
QString S60CreatePackageStepConfigWidget::summaryText() const
{
    QString text;
724
725
    switch(m_signStep->signingMode()) {
    case S60CreatePackageStep::SignCustom:
726
        text = tr("signed with certificate %1 and key file %2")
Friedemann Kleint's avatar
Friedemann Kleint committed
727
               .arg(m_signStep->customSignaturePath(), m_signStep->customKeyPath());
728
729
730
731
732
733
734
        break;
    case S60CreatePackageStep::NotSigned:
        text = tr("not signed");
        break;
    default:
        text = tr("self-signed");
        break;
735
    }
736
    if (m_signStep->createsSmartInstaller())
con's avatar
con committed
737
        return tr("<b>Create SIS Package:</b> %1, using Smart Installer").arg(text);
738
    return tr("<b>Create SIS Package:</b> %1").arg(text);
739
740
741
742
743
744
745
746
747
748
}

QString S60CreatePackageStepConfigWidget::displayName() const
{
    return m_signStep->displayName();
}

void S60CreatePackageStepConfigWidget::init()
{
}