aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qt4projectmanager/qt-s60/s60publisherovi.cpp
blob: efd08e525b60c03f5dc306da5a945b588c25c86d (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "s60publisherovi.h"

#include "qt4symbiantarget.h"
#include "s60certificateinfo.h"
#include "s60manager.h"

#include "qt4buildconfiguration.h"
#include "qmakestep.h"
#include "makestep.h"
#include "qt4project.h"
#include "qtversionmanager.h"

#include "profilereader.h"
#include "prowriter.h"

#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildstep.h>

#include <utils/qtcassert.h>

#include <QtCore/QProcess>

namespace Qt4ProjectManager {
namespace Internal {

S60PublisherOvi::S60PublisherOvi(QObject *parent) :
    QObject(parent),
    m_reader(0)
{
    // build m_rejectedVendorNames
    m_rejectedVendorNames.append(Constants::REJECTED_VENDOR_NAMES_NOKIA);
    m_rejectedVendorNames.append(Constants::REJECTED_VENDOR_NAMES_VENDOR);
    m_rejectedVendorNames.append(Constants::REJECTED_VENDOR_NAMES_VENDOR_EN);
    m_rejectedVendorNames.append(Constants::REJECTED_VENDOR_NAMES_EMPTY);

    // build m_capabilitiesForCertifiedSigned
    m_capabilitiesForCertifiedSigned.append(Constants::CERTIFIED_SIGNED_CAPABILITY_COMM_DD);
    m_capabilitiesForCertifiedSigned.append(Constants::CERTIFIED_SIGNED_CAPABILITY_DISK_ADMIN);
    m_capabilitiesForCertifiedSigned.append(Constants::CERTIFIED_SIGNED_CAPABILITY_MULTIMEDIA_DD);
    m_capabilitiesForCertifiedSigned.append(Constants::CERTIFIED_SIGNED_CAPABILITY_NETWORK_CONTROL);

    // build m_capabilitesForManufacturerApproved
    m_capabilitesForManufacturerApproved.append(Constants::MANUFACTURER_APPROVED_CAPABILITY_ALL_FILES);
    m_capabilitesForManufacturerApproved.append(Constants::MANUFACTURER_APPROVED_CAPABILITY_DRM);
    m_capabilitesForManufacturerApproved.append(Constants::MANUFACTURER_APPROVED_CAPABILITY_TCB);

    // set up colours for progress reports
    m_errorColor = Qt::red;
    m_commandColor = Qt::blue;
    m_okColor = Qt::darkGreen;
    m_normalColor = Qt::black;

    m_finishedAndSuccessful = false;

    m_qmakeProc = new QProcess(this);
    m_buildProc = new QProcess(this);
    m_createSisProc = new QProcess(this);
    connect(m_qmakeProc,SIGNAL(finished(int)), SLOT(runBuild(int)));
    connect(m_buildProc,SIGNAL(finished(int)), SLOT(runCreateSis(int)));
    connect(m_createSisProc,SIGNAL(finished(int)), SLOT(endBuild(int)));
}

S60PublisherOvi::~S60PublisherOvi()
{
    cleanUp();
}

void S60PublisherOvi::setBuildConfiguration(Qt4BuildConfiguration *qt4bc)
{
    // set build configuration
    m_qt4bc = qt4bc;
}

void S60PublisherOvi::setVendorName(const QString &vendorName)
{
    m_vendorName = vendorName;
}

void S60PublisherOvi::setLocalVendorNames(const QString &localVendorNames)
{
    m_localVendorNames = localVendorNames;
}

void S60PublisherOvi::setAppUid(const QString &appuid)
{
    m_appUid = appuid;
}

void S60PublisherOvi::cleanUp()
{
    if (m_qt4project && m_reader) {
        m_qt4project->destroyProFileReader(m_reader);
        m_reader = 0;
    }
}

void S60PublisherOvi::completeCreation()
{
    // set active target
    m_activeTargetOfProject = qobject_cast<Qt4SymbianTarget *>(m_qt4bc->target());
    QTC_ASSERT(m_activeTargetOfProject, return);

    //set up project
    m_qt4project = m_activeTargetOfProject->qt4Project();

    // set up pro file reader
    m_reader = m_qt4project->createProFileReader(m_qt4project->rootProjectNode(), m_qt4bc);
    //m_reader->setCumulative(false); // todo need to reenable that, after fixing parsing for symbian scopes

    ProFile *profile = m_reader->parsedProFile(m_qt4project->rootProjectNode()->path());
    m_reader->accept(profile, ProFileEvaluator::LoadProOnly);
    profile->deref();

    // set up process for creating the resulting sis files
    m_qmakeProc->setEnvironment(m_qt4bc->environment().toStringList());
    m_qmakeProc->setWorkingDirectory(m_qt4bc->buildDirectory());

    m_buildProc->setEnvironment(m_qt4bc->environment().toStringList());
    m_buildProc->setWorkingDirectory(m_qt4bc->buildDirectory());

    m_createSisProc->setEnvironment(m_qt4bc->environment().toStringList());
    m_createSisProc->setWorkingDirectory(m_qt4bc->buildDirectory());
}

QString S60PublisherOvi::globalVendorName() const
{
    QStringList vendorinfos = m_reader->values("vendorinfo");

    foreach (QString vendorinfo, vendorinfos) {
        if (vendorinfo.startsWith(':')) {
            return vendorinfo.remove(':').remove("\"").trimmed();
        }
    }
    return QString();
}

QString S60PublisherOvi::localisedVendorNames() const
{
    QStringList vendorinfos = m_reader->values("vendorinfo");
    QString result;

    QStringList localisedVendorNames;
    foreach (QString vendorinfo, vendorinfos) {
        if (vendorinfo.startsWith('%')) {
            localisedVendorNames = vendorinfo.remove("%{").remove('}').split(',');
            foreach (QString localisedVendorName, localisedVendorNames) {
                if (!result.isEmpty())
                    result.append(", ");
                result.append(localisedVendorName.remove("\"").trimmed());
            }
            return result;
        }
    }
    return QString();
}

bool S60PublisherOvi::isVendorNameValid(const QString &vendorName) const
{
    // vendorName cannot containg "Nokia"
    if (vendorName.trimmed().contains(Constants::REJECTED_VENDOR_NAMES_NOKIA, Qt::CaseInsensitive))
        return false;

    // vendorName cannot be any of the rejected vendor names
    foreach (const QString &rejectedVendorName, m_rejectedVendorNames)
        if (vendorName.trimmed().compare(rejectedVendorName, Qt::CaseInsensitive) == 0)
            return false;

    return true;
}

QString S60PublisherOvi::qtVersion() const
{
    return m_qt4bc->qtVersion()->displayName();
}

QString S60PublisherOvi::uid3() const
{
    return m_reader->value("TARGET.UID3");
}

bool S60PublisherOvi::isUID3Valid(const QString &uid3) const
{
    bool ok;
    ulong hex = uid3.trimmed().toULong(&ok, 0);

    return ok && (hex >= AssignedRestrictedStart && hex <= AssignedRestrictedEnd);
}

bool S60PublisherOvi::isTestUID3(const QString &uid3) const
{
    bool ok;
    ulong hex = uid3.trimmed().toULong(&ok, 0);
    return ok && (hex >= TestStart && hex <=TestEnd);
}

bool S60PublisherOvi::isKnownSymbianSignedUID3(const QString &uid3) const
{
    bool ok;
    ulong hex = uid3.trimmed().toULong(&ok, 0);
    return ok && (hex >= SymbianSignedUnprotectedStart && hex <= SymbianSignedUnprotectedEnd);
}

QString S60PublisherOvi::capabilities() const
{
    return m_reader->values("TARGET.CAPABILITY").join(", ");
}

bool S60PublisherOvi::isCapabilityOneOf(const QString &capability, CapabilityLevel level) const
{
    QStringList capabilitiesInLevel;
    if (level == CertifiedSigned)
        capabilitiesInLevel = m_capabilitiesForCertifiedSigned;
    else if (level == ManufacturerApproved)
        capabilitiesInLevel = m_capabilitesForManufacturerApproved;

    return capabilitiesInLevel.contains(capability.trimmed());
}

void S60PublisherOvi::updateProFile(const QString &var, const QString &values)
{
    QStringList lines;
    ProFile *profile = m_reader->parsedProFile(m_qt4project->rootProjectNode()->path());

    QFile qfile(m_qt4project->rootProjectNode()->path());
    if (qfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        lines = QString::fromLocal8Bit(qfile.readAll()).split(QLatin1Char('\n'));
        qfile.close();
        while (!lines.isEmpty() && lines.last().isEmpty())
            lines.removeLast();
    } else {
        m_qt4project->proFileParseError(tr("Error while reading .pro file %1: %2").arg(m_qt4project->rootProjectNode()->path(), qfile.errorString()));
        return;
    }

    ProWriter::putVarValues(profile, &lines, QStringList() << values, var,
                            ProWriter::ReplaceValues | ProWriter::OneLine | ProWriter::AssignOperator,
                            "symbian");

    if (qfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
        qfile.write(lines.join("\n").toLocal8Bit());
        qfile.close();
    }
}

void S60PublisherOvi::updateProFile()
{
    updateProFile("vendorinfo", "\"%{\\\"" + m_localVendorNames + "\\\"}\" \":\\\"" + m_vendorName + "\\\"\"" );
    updateProFile("TARGET.UID3", m_appUid);
}

void S60PublisherOvi::buildSis()
{
    updateProFile();
    runQMake();
}

void S60PublisherOvi::runQMake()
{
    m_finishedAndSuccessful = false;

    ProjectExplorer::AbstractProcessStep *qmakeStep = m_qt4bc->qmakeStep();
    qmakeStep->init();
    const ProjectExplorer::ProcessParameters * const qmakepp = qmakeStep->processParameters();
    runStep(QProcess::NormalExit,
            "Running QMake",
            qmakepp->effectiveCommand() + ' ' + qmakepp->arguments(),
            m_qmakeProc,
            0);
}

void S60PublisherOvi::runBuild(int result)
{
    ProjectExplorer::AbstractProcessStep * makeStep = m_qt4bc->makeStep();
    makeStep->init();
    const ProjectExplorer::ProcessParameters * const makepp = makeStep->processParameters();
    runStep(result,
            "Running Build Steps",
            makepp->effectiveCommand() + ' ' + makepp->arguments(),
            m_buildProc,
            m_qmakeProc);
}

void S60PublisherOvi::runCreateSis(int result)
{
    ProjectExplorer::AbstractProcessStep * makeStep = m_qt4bc->makeStep();
    makeStep->init();
    const ProjectExplorer::ProcessParameters * const makepp = makeStep->processParameters();
    QString makeTarget =  QLatin1String(" unsigned_installer_sis");

    if (m_qt4bc->qtVersion()->qtVersion() == QtVersionNumber(4,6,3) )
        makeTarget =  QLatin1String(" installer_sis");
    runStep(result,
            "Making Sis File",
            makepp->effectiveCommand() + makeTarget,
            m_createSisProc,
            m_buildProc);
}

void S60PublisherOvi::endBuild(int result)
{
    // show what happened in last step
    emit progressReport(QString(m_createSisProc->readAllStandardOutput() + '\n'), m_okColor);
    emit progressReport(QString(m_createSisProc->readAllStandardError() + '\n'), m_errorColor);

    QString fileNamePostFix =  QLatin1String("_installer_unsigned.sis");
    if (m_qt4bc->qtVersion()->qtVersion() == QtVersionNumber(4,6,3) )
        fileNamePostFix =  QLatin1String("_installer.sis");

    QString resultFile = m_qt4bc->buildDirectory() + "/" + m_qt4project->displayName() + fileNamePostFix;



    QFileInfo fi(resultFile);
    if (result == QProcess::NormalExit && fi.exists()) {
        emit progressReport(tr("Created %1\n").arg(QDir::toNativeSeparators(resultFile)), m_normalColor);
        m_finishedAndSuccessful = true;
        emit succeeded();
    } else {
        emit progressReport(tr(" Sis file not created due to previous errors\n"), m_errorColor);
    }
    emit progressReport(tr("Done!\n"), m_commandColor);
}

QString S60PublisherOvi::createdSisFileContainingFolder()
{
    QString fileNamePostFix =  QLatin1String("_installer_unsigned.sis");
    if (m_qt4bc->qtVersion()->qtVersion() == QtVersionNumber(4,6,3) )
        fileNamePostFix =  QLatin1String("_installer.sis");

    QString resultFile = m_qt4bc->buildDirectory() + "/" + m_qt4project->displayName() + fileNamePostFix;
    QFileInfo fi(resultFile);

    return fi.exists() ? QDir::toNativeSeparators(m_qt4bc->buildDirectory()) : QString();
}

QString S60PublisherOvi::createdSisFilePath()
{
    QString fileNamePostFix =  QLatin1String("_installer_unsigned.sis");
    if (m_qt4bc->qtVersion()->qtVersion() == QtVersionNumber(4,6,3) )
        fileNamePostFix =  QLatin1String("_installer.sis");

    QString resultFile = m_qt4bc->buildDirectory() + "/" + m_qt4project->displayName() + fileNamePostFix;
    QFileInfo fi(resultFile);

    return fi.exists() ? QDir::toNativeSeparators(m_qt4bc->buildDirectory()+ '/' + m_qt4project->displayName() + fileNamePostFix) : QString();
}

bool S60PublisherOvi::hasSucceeded()
{
    return m_finishedAndSuccessful;
}

void S60PublisherOvi::runStep(int result, const QString& buildStep, const QString& command, QProcess* currProc, QProcess* prevProc)
{
    // todo react to readyRead() instead of reading all at the end
    // show what happened in last step
    if (prevProc) {
        emit progressReport(QString(prevProc->readAllStandardOutput() + '\n'), m_okColor);
        emit progressReport(QString(prevProc->readAllStandardError() + '\n'), m_errorColor);
    }

    // if the last state finished ok then run the build.
    if (result == QProcess::NormalExit) {
         emit progressReport(buildStep + '\n', m_commandColor);
         emit progressReport(command + '\n', m_commandColor);

         currProc->start(command);
    } else {
        emit progressReport(tr("Sis file not created due to previous errors\n") , m_errorColor);
    }
}

} // namespace Internal
} // namespace Qt4ProjectManager