2010-09-16 14:11:15 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-09-16 14:11:15 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-09-16 14:11:15 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-09-16 14:11:15 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-09-16 14:11:15 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "abstractmobileapp.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
|
|
|
|
|
#ifndef CREATORLESSTEST
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#endif // CREATORLESSTEST
|
|
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
2010-09-16 14:11:15 +02:00
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
|
|
|
|
|
AbstractGeneratedFileInfo::AbstractGeneratedFileInfo()
|
|
|
|
|
: fileType(ExtendedFile)
|
2011-02-03 19:46:41 +01:00
|
|
|
, currentVersion(-1)
|
2010-09-16 14:11:15 +02:00
|
|
|
, version(-1)
|
|
|
|
|
, dataChecksum(0)
|
|
|
|
|
, statedChecksum(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString AbstractMobileApp::CFileComment(QLatin1String("//"));
|
|
|
|
|
const QString AbstractMobileApp::ProFileComment(QLatin1String("#"));
|
|
|
|
|
const QString AbstractMobileApp::DeploymentPriFileName(QLatin1String("deployment.pri"));
|
|
|
|
|
const QString AbstractMobileApp::FileChecksum(QLatin1String("checksum"));
|
|
|
|
|
const QString AbstractMobileApp::FileStubVersion(QLatin1String("version"));
|
2011-03-30 21:22:20 +02:00
|
|
|
const int AbstractMobileApp::StubVersion = 4;
|
2010-09-16 14:11:15 +02:00
|
|
|
|
|
|
|
|
AbstractMobileApp::AbstractMobileApp()
|
2011-01-27 13:31:22 +01:00
|
|
|
: m_orientation(ScreenOrientationAuto)
|
|
|
|
|
, m_networkEnabled(true)
|
2010-09-16 14:11:15 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractMobileApp::~AbstractMobileApp() { }
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::symbianUidForPath(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
quint32 hash = 5381;
|
|
|
|
|
for (int i = 0; i < path.size(); ++i) {
|
|
|
|
|
const char c = path.at(i).toAscii();
|
|
|
|
|
hash ^= c + ((c - i) << i % 20) + ((c + i) << (i + 5) % 20) + ((c - 2 * i) << (i + 10) % 20) + ((c + 2 * i) << (i + 15) % 20);
|
|
|
|
|
}
|
|
|
|
|
return QString::fromLatin1("0xE")
|
2010-09-24 16:26:24 +02:00
|
|
|
+ QString::fromLatin1("%1").arg(hash, 7, 16, QLatin1Char('0')).right(7).toUpper();
|
2010-09-16 14:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-01 17:03:46 +01:00
|
|
|
void AbstractMobileApp::setOrientation(ScreenOrientation orientation)
|
2010-09-16 14:11:15 +02:00
|
|
|
{
|
|
|
|
|
m_orientation = orientation;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 17:03:46 +01:00
|
|
|
AbstractMobileApp::ScreenOrientation AbstractMobileApp::orientation() const
|
2010-09-16 14:11:15 +02:00
|
|
|
{
|
|
|
|
|
return m_orientation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractMobileApp::setProjectName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
m_projectName = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::projectName() const
|
|
|
|
|
{
|
|
|
|
|
return m_projectName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractMobileApp::setProjectPath(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
m_projectPath.setFile(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractMobileApp::setSymbianSvgIcon(const QString &icon)
|
|
|
|
|
{
|
|
|
|
|
m_symbianSvgIcon = icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::symbianSvgIcon() const
|
|
|
|
|
{
|
|
|
|
|
return path(SymbianSvgIconOrigin);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-28 15:11:42 +02:00
|
|
|
void AbstractMobileApp::setMaemoPngIcon64(const QString &icon)
|
2010-09-16 14:11:15 +02:00
|
|
|
{
|
2011-04-28 15:11:42 +02:00
|
|
|
m_maemoPngIcon64 = icon;
|
2010-09-16 14:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-28 15:11:42 +02:00
|
|
|
QString AbstractMobileApp::maemoPngIcon64() const
|
2010-09-16 14:11:15 +02:00
|
|
|
{
|
2011-04-28 15:11:42 +02:00
|
|
|
return path(MaemoPngIconOrigin64);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractMobileApp::setMaemoPngIcon80(const QString &icon)
|
|
|
|
|
{
|
|
|
|
|
m_maemoPngIcon80 = icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::maemoPngIcon80() const
|
|
|
|
|
{
|
|
|
|
|
return path(MaemoPngIconOrigin80);
|
2010-09-16 14:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractMobileApp::setSymbianTargetUid(const QString &uid)
|
|
|
|
|
{
|
|
|
|
|
m_symbianTargetUid = uid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::symbianTargetUid() const
|
|
|
|
|
{
|
|
|
|
|
return !m_symbianTargetUid.isEmpty() ? m_symbianTargetUid
|
|
|
|
|
: symbianUidForPath(path(AppPro));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractMobileApp::setNetworkEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_networkEnabled = enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractMobileApp::networkEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return m_networkEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::path(int fileType) const
|
|
|
|
|
{
|
|
|
|
|
const QString originsRootApp = originsRoot();
|
|
|
|
|
const QString originsRootShared = templatesRoot() + QLatin1String("shared/");
|
|
|
|
|
const QString mainCppFileName = QLatin1String("main.cpp");
|
|
|
|
|
const QString symbianIconFileName = QLatin1String("symbianicon.svg");
|
2010-11-16 20:56:01 +01:00
|
|
|
QString cleanProjectName = m_projectName;
|
|
|
|
|
cleanProjectName.replace(QLatin1Char('-'), QString());
|
2010-09-16 14:11:15 +02:00
|
|
|
switch (fileType) {
|
|
|
|
|
case MainCpp: return outputPathBase() + mainCppFileName;
|
|
|
|
|
case MainCppOrigin: return originsRootApp + mainCppFileName;
|
2010-11-16 20:56:01 +01:00
|
|
|
case AppPro: return outputPathBase() + cleanProjectName + QLatin1String(".pro");
|
2010-09-16 14:11:15 +02:00
|
|
|
case AppProOrigin: return originsRootApp + QLatin1String("app.pro");
|
|
|
|
|
case AppProPath: return outputPathBase();
|
2010-11-16 20:56:01 +01:00
|
|
|
case Desktop: return outputPathBase() + cleanProjectName + QLatin1String(".desktop");
|
2010-09-16 14:11:15 +02:00
|
|
|
case DesktopOrigin: return originsRootShared + QLatin1String("app.desktop");
|
|
|
|
|
case DeploymentPri: return outputPathBase() + DeploymentPriFileName;
|
|
|
|
|
case DeploymentPriOrigin: return originsRootShared + DeploymentPriFileName;
|
2010-11-16 20:56:01 +01:00
|
|
|
case SymbianSvgIcon: return outputPathBase() + cleanProjectName + QLatin1String(".svg");
|
2010-09-16 14:11:15 +02:00
|
|
|
case SymbianSvgIconOrigin: return !m_symbianSvgIcon.isEmpty() ? m_symbianSvgIcon
|
|
|
|
|
: originsRootShared + symbianIconFileName;
|
2011-04-28 15:11:42 +02:00
|
|
|
case MaemoPngIcon64: return outputPathBase() + cleanProjectName + QLatin1String("64.png");
|
|
|
|
|
case MaemoPngIconOrigin64: return !m_maemoPngIcon64.isEmpty() ? m_maemoPngIcon64
|
|
|
|
|
: originsRootShared + QLatin1String("maemoicon64.png");
|
|
|
|
|
case MaemoPngIcon80: return outputPathBase() + cleanProjectName + QLatin1String("80.png");
|
|
|
|
|
case MaemoPngIconOrigin80: return !m_maemoPngIcon80.isEmpty() ? m_maemoPngIcon80
|
|
|
|
|
: originsRootShared + QLatin1String("maemoicon80.png");
|
2010-09-16 14:11:15 +02:00
|
|
|
default: return pathExtended(fileType);
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
bool AbstractMobileApp::readTemplate(int fileType, QByteArray *data, QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
Utils::FileReader reader;
|
|
|
|
|
if (!reader.fetch(path(fileType), errorMessage))
|
|
|
|
|
return false;
|
|
|
|
|
*data = reader.data();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 14:11:15 +02:00
|
|
|
QByteArray AbstractMobileApp::generateDesktopFile(QString *errorMessage) const
|
|
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
QByteArray desktopFileContent;
|
|
|
|
|
if (!readTemplate(DesktopOrigin, &desktopFileContent, errorMessage))
|
2010-09-16 14:11:15 +02:00
|
|
|
return QByteArray();
|
2011-04-28 15:11:42 +02:00
|
|
|
desktopFileContent.replace("Icon=thisApp",
|
|
|
|
|
"Icon=" + projectName().toUtf8() + "64");
|
2010-09-16 14:11:15 +02:00
|
|
|
return desktopFileContent.replace("thisApp", projectName().toUtf8());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray AbstractMobileApp::generateMainCpp(QString *errorMessage) const
|
|
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
QByteArray mainCppInput;
|
|
|
|
|
if (!readTemplate(MainCppOrigin, &mainCppInput, errorMessage))
|
2010-09-16 14:11:15 +02:00
|
|
|
return QByteArray();
|
2011-03-30 15:15:15 +02:00
|
|
|
QTextStream in(&mainCppInput);
|
2010-09-16 14:11:15 +02:00
|
|
|
|
|
|
|
|
QByteArray mainCppContent;
|
|
|
|
|
QTextStream out(&mainCppContent, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
|
|
QString line;
|
|
|
|
|
while (!(line = in.readLine()).isNull()) {
|
|
|
|
|
bool adaptLine = true;
|
|
|
|
|
if (line.contains(QLatin1String("// ORIENTATION"))) {
|
|
|
|
|
const char *orientationString;
|
|
|
|
|
switch (orientation()) {
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationLockLandscape:
|
|
|
|
|
orientationString = "ScreenOrientationLockLandscape";
|
2010-09-16 14:11:15 +02:00
|
|
|
break;
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationLockPortrait:
|
|
|
|
|
orientationString = "ScreenOrientationLockPortrait";
|
2010-09-16 14:11:15 +02:00
|
|
|
break;
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationAuto:
|
|
|
|
|
orientationString = "ScreenOrientationAuto";
|
2010-09-16 14:11:15 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
insertParameter(line, mainWindowClassName() + QLatin1String("::")
|
|
|
|
|
+ QLatin1String(orientationString));
|
2011-02-09 16:23:35 +01:00
|
|
|
} else if (line.contains(QLatin1String("// DELETE_LINE"))) {
|
|
|
|
|
continue; // omit this line in the output
|
2010-09-16 14:11:15 +02:00
|
|
|
} else {
|
|
|
|
|
adaptLine = adaptCurrentMainCppTemplateLine(line);
|
|
|
|
|
}
|
|
|
|
|
if (adaptLine) {
|
|
|
|
|
const int commentIndex = line.indexOf(QLatin1String(" //"));
|
|
|
|
|
if (commentIndex != -1)
|
|
|
|
|
line.truncate(commentIndex);
|
|
|
|
|
out << line << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mainCppContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray AbstractMobileApp::generateProFile(QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
const QChar comment = QLatin1Char('#');
|
2011-03-30 15:15:15 +02:00
|
|
|
QByteArray proFileInput;
|
|
|
|
|
if (!readTemplate(AppProOrigin, &proFileInput, errorMessage))
|
2010-09-16 14:11:15 +02:00
|
|
|
return QByteArray();
|
2011-03-30 15:15:15 +02:00
|
|
|
QTextStream in(&proFileInput);
|
2010-09-16 14:11:15 +02:00
|
|
|
|
|
|
|
|
QByteArray proFileContent;
|
|
|
|
|
QTextStream out(&proFileContent, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
|
|
QString valueOnNextLine;
|
2011-02-06 19:27:57 +01:00
|
|
|
bool commentOutNextLine = false;
|
2010-09-16 14:11:15 +02:00
|
|
|
QString line;
|
|
|
|
|
while (!(line = in.readLine()).isNull()) {
|
|
|
|
|
if (line.contains(QLatin1String("# TARGETUID3"))) {
|
|
|
|
|
valueOnNextLine = symbianTargetUid();
|
|
|
|
|
} else if (line.contains(QLatin1String("# NETWORKACCESS"))
|
|
|
|
|
&& !networkEnabled()) {
|
2011-02-06 19:27:57 +01:00
|
|
|
commentOutNextLine = true;
|
2011-02-07 17:49:50 +01:00
|
|
|
} else if (line.contains(QLatin1String("# DEPLOYMENTFOLDERS"))) {
|
|
|
|
|
// Eat lines
|
|
|
|
|
QString nextLine;
|
|
|
|
|
while (!(nextLine = in.readLine()).isNull()
|
|
|
|
|
&& !nextLine.contains(QLatin1String("# DEPLOYMENTFOLDERS_END")))
|
|
|
|
|
{ }
|
|
|
|
|
if (nextLine.isNull())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int foldersCount = 0;
|
|
|
|
|
QStringList folders;
|
|
|
|
|
foreach (const DeploymentFolder &folder, deploymentFolders()) {
|
|
|
|
|
foldersCount++;
|
|
|
|
|
const QString folderName =
|
|
|
|
|
QString::fromLatin1("folder_%1").arg(foldersCount, 2, 10, QLatin1Char('0'));
|
|
|
|
|
out << folderName << ".source = " << folder.first << endl;
|
|
|
|
|
if (!folder.second.isEmpty())
|
|
|
|
|
out << folderName << ".target = " << folder.second << endl;
|
|
|
|
|
folders.append(folderName);
|
|
|
|
|
}
|
|
|
|
|
if (foldersCount > 0)
|
|
|
|
|
out << "DEPLOYMENTFOLDERS = " << folders.join(QLatin1String(" ")) << endl;
|
2011-04-17 09:55:17 +02:00
|
|
|
} else if (line.contains(QLatin1String("# REMOVE_NEXT_LINE"))) {
|
|
|
|
|
in.readLine(); // eats the following line
|
2010-09-16 14:11:15 +02:00
|
|
|
} else {
|
2011-02-06 19:27:57 +01:00
|
|
|
handleCurrentProFileTemplateLine(line, in, out, commentOutNextLine);
|
2010-09-16 14:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove all marker comments
|
|
|
|
|
if (line.trimmed().startsWith(comment)
|
|
|
|
|
&& line.trimmed().endsWith(comment))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!valueOnNextLine.isEmpty()) {
|
|
|
|
|
out << line.left(line.indexOf(QLatin1Char('=')) + 2)
|
|
|
|
|
<< QDir::fromNativeSeparators(valueOnNextLine) << endl;
|
|
|
|
|
valueOnNextLine.clear();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-06 19:27:57 +01:00
|
|
|
if (commentOutNextLine) {
|
2010-09-16 14:11:15 +02:00
|
|
|
out << comment << line << endl;
|
2011-02-06 19:27:57 +01:00
|
|
|
commentOutNextLine = false;
|
2010-09-16 14:11:15 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
out << line << endl;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
proFileContent.replace("../shared/" + DeploymentPriFileName.toAscii(),
|
|
|
|
|
DeploymentPriFileName.toAscii());
|
|
|
|
|
return proFileContent;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 19:46:41 +01:00
|
|
|
QList<AbstractGeneratedFileInfo> AbstractMobileApp::fileUpdates(const QString &mainProFile) const
|
|
|
|
|
{
|
|
|
|
|
QList<AbstractGeneratedFileInfo> result;
|
|
|
|
|
foreach (const AbstractGeneratedFileInfo &file, updateableFiles(mainProFile)) {
|
|
|
|
|
AbstractGeneratedFileInfo newFile = file;
|
|
|
|
|
QFile readFile(newFile.fileInfo.absoluteFilePath());
|
|
|
|
|
if (!readFile.open(QIODevice::ReadOnly))
|
|
|
|
|
continue;
|
|
|
|
|
const QString firstLine = readFile.readLine();
|
|
|
|
|
const QStringList elements = firstLine.split(QLatin1Char(' '));
|
|
|
|
|
if (elements.count() != 5 || elements.at(1) != FileChecksum
|
|
|
|
|
|| elements.at(3) != FileStubVersion)
|
|
|
|
|
continue;
|
|
|
|
|
const QString versionString = elements.at(4);
|
|
|
|
|
newFile.version = versionString.startsWith(QLatin1String("0x"))
|
|
|
|
|
? versionString.toInt(0, 16) : 0;
|
|
|
|
|
newFile.statedChecksum = elements.at(2).toUShort(0, 16);
|
|
|
|
|
QByteArray data = readFile.readAll();
|
|
|
|
|
data.replace('\x0D', "");
|
|
|
|
|
data.replace('\x0A', "");
|
|
|
|
|
newFile.dataChecksum = qChecksum(data.constData(), data.length());
|
|
|
|
|
if (newFile.dataChecksum != newFile.statedChecksum
|
|
|
|
|
|| newFile.version < newFile.currentVersion)
|
|
|
|
|
result.append(newFile);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AbstractMobileApp::updateFiles(const QList<AbstractGeneratedFileInfo> &list, QString &error) const
|
|
|
|
|
{
|
|
|
|
|
error.clear();
|
|
|
|
|
foreach (const AbstractGeneratedFileInfo &info, list) {
|
|
|
|
|
const QByteArray data = generateFile(info.fileType, &error);
|
|
|
|
|
if (!error.isEmpty())
|
|
|
|
|
return false;
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileSaver saver(QDir::cleanPath(info.fileInfo.absoluteFilePath()));
|
|
|
|
|
saver.write(data);
|
|
|
|
|
if (!saver.finalize(&error))
|
2011-02-03 19:46:41 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 14:11:15 +02:00
|
|
|
#ifndef CREATORLESSTEST
|
2011-02-06 16:23:02 +01:00
|
|
|
// The definition of QtQuickApp::templatesRoot() for
|
|
|
|
|
// CREATORLESSTEST is in tests/manual/appwizards/helpers.cpp
|
2010-09-16 14:11:15 +02:00
|
|
|
QString AbstractMobileApp::templatesRoot()
|
|
|
|
|
{
|
|
|
|
|
return Core::ICore::instance()->resourcePath()
|
|
|
|
|
+ QLatin1String("/templates/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::GeneratedFile AbstractMobileApp::file(const QByteArray &data,
|
|
|
|
|
const QString &targetFile)
|
|
|
|
|
{
|
|
|
|
|
Core::GeneratedFile generatedFile(targetFile);
|
|
|
|
|
generatedFile.setBinary(true);
|
|
|
|
|
generatedFile.setBinaryContents(data);
|
|
|
|
|
return generatedFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::GeneratedFiles AbstractMobileApp::generateFiles(QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
Core::GeneratedFiles files;
|
|
|
|
|
files << file(generateFile(AbstractGeneratedFileInfo::AppProFile, errorMessage), path(AppPro));
|
|
|
|
|
files.last().setAttributes(Core::GeneratedFile::OpenProjectAttribute);
|
|
|
|
|
files << file(generateFile(AbstractGeneratedFileInfo::MainCppFile, errorMessage), path(MainCpp));
|
|
|
|
|
files << file(generateFile(AbstractGeneratedFileInfo::SymbianSvgIconFile, errorMessage), path(SymbianSvgIcon));
|
2011-04-28 15:11:42 +02:00
|
|
|
files << file(generateFile(AbstractGeneratedFileInfo::MaemoPngIconFile64, errorMessage), path(MaemoPngIcon64));
|
|
|
|
|
files << file(generateFile(AbstractGeneratedFileInfo::MaemoPngIconFile80, errorMessage), path(MaemoPngIcon80));
|
2010-09-16 14:11:15 +02:00
|
|
|
files << file(generateFile(AbstractGeneratedFileInfo::DesktopFile, errorMessage), path(Desktop));
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
#endif // CREATORLESSTEST
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::error() const
|
|
|
|
|
{
|
|
|
|
|
return m_error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray AbstractMobileApp::readBlob(const QString &filePath,
|
|
|
|
|
QString *errorMsg) const
|
|
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileReader reader;
|
|
|
|
|
if (!reader.fetch(filePath, errorMsg))
|
2010-09-16 14:11:15 +02:00
|
|
|
return QByteArray();
|
2011-03-30 15:15:15 +02:00
|
|
|
return reader.data();
|
2010-09-16 14:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray AbstractMobileApp::generateFile(int fileType,
|
|
|
|
|
QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
QByteArray data;
|
|
|
|
|
QString comment = CFileComment;
|
|
|
|
|
bool versionAndChecksum = false;
|
|
|
|
|
switch (fileType) {
|
|
|
|
|
case AbstractGeneratedFileInfo::MainCppFile:
|
|
|
|
|
data = generateMainCpp(errorMessage);
|
|
|
|
|
break;
|
|
|
|
|
case AbstractGeneratedFileInfo::AppProFile:
|
|
|
|
|
data = generateProFile(errorMessage);
|
|
|
|
|
comment = ProFileComment;
|
|
|
|
|
break;
|
|
|
|
|
case AbstractGeneratedFileInfo::SymbianSvgIconFile:
|
|
|
|
|
data = readBlob(path(SymbianSvgIconOrigin), errorMessage);
|
|
|
|
|
break;
|
2011-04-28 15:11:42 +02:00
|
|
|
case AbstractGeneratedFileInfo::MaemoPngIconFile64:
|
|
|
|
|
data = readBlob(path(MaemoPngIconOrigin64), errorMessage);
|
|
|
|
|
break;
|
|
|
|
|
case AbstractGeneratedFileInfo::MaemoPngIconFile80:
|
|
|
|
|
data = readBlob(path(MaemoPngIconOrigin80), errorMessage);
|
2010-09-16 14:11:15 +02:00
|
|
|
break;
|
|
|
|
|
case AbstractGeneratedFileInfo::DesktopFile:
|
|
|
|
|
data = generateDesktopFile(errorMessage);
|
|
|
|
|
break;
|
|
|
|
|
case AbstractGeneratedFileInfo::DeploymentPriFile:
|
|
|
|
|
data = readBlob(path(DeploymentPriOrigin), errorMessage);
|
|
|
|
|
comment = ProFileComment;
|
|
|
|
|
versionAndChecksum = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
data = generateFileExtended(fileType, &versionAndChecksum,
|
|
|
|
|
&comment, errorMessage);
|
|
|
|
|
}
|
|
|
|
|
if (!versionAndChecksum)
|
|
|
|
|
return data;
|
|
|
|
|
QByteArray versioned = data;
|
|
|
|
|
versioned.replace('\x0D', "");
|
|
|
|
|
versioned.replace('\x0A', "");
|
2010-09-20 09:34:52 +02:00
|
|
|
const QLatin1String hexPrefix("0x");
|
2010-09-16 14:11:15 +02:00
|
|
|
const quint16 checkSum = qChecksum(versioned.constData(), versioned.length());
|
2010-09-20 09:34:52 +02:00
|
|
|
const QString checkSumString = hexPrefix + QString::number(checkSum, 16);
|
2010-09-17 15:10:21 +02:00
|
|
|
const QString versionString
|
2010-09-20 09:34:52 +02:00
|
|
|
= hexPrefix + QString::number(makeStubVersion(stubVersionMinor()), 16);
|
2010-09-16 14:11:15 +02:00
|
|
|
const QChar sep = QLatin1Char(' ');
|
|
|
|
|
const QString versionLine =
|
2010-09-20 09:34:52 +02:00
|
|
|
comment + sep + FileChecksum + sep + checkSumString
|
2010-09-16 14:11:15 +02:00
|
|
|
+ sep + FileStubVersion + sep + versionString + QLatin1Char('\x0A');
|
|
|
|
|
return versionLine.toAscii() + data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AbstractMobileApp::makeStubVersion(int minor)
|
|
|
|
|
{
|
|
|
|
|
return StubVersion << 16 | minor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractMobileApp::outputPathBase() const
|
|
|
|
|
{
|
2011-01-24 14:59:39 +01:00
|
|
|
QString path = m_projectPath.absoluteFilePath();
|
|
|
|
|
if (!path.endsWith(QLatin1Char('/')))
|
|
|
|
|
path.append(QLatin1Char('/'));
|
|
|
|
|
return path + projectName() + QLatin1Char('/');
|
2010-09-16 14:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractMobileApp::insertParameter(QString &line, const QString ¶meter)
|
|
|
|
|
{
|
|
|
|
|
line.replace(QRegExp(QLatin1String("\\([^()]+\\)")),
|
|
|
|
|
QLatin1Char('(') + parameter + QLatin1Char(')'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Qt4ProjectManager
|