diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp index a2cfdf3cb1ac9d238f225aca8e1fef0b27735b59..b993f3f3ae8157cad9b1fe7bf273cc9394580ecb 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp @@ -209,15 +209,15 @@ bool MaemoDeployableListModel::isEditable(const QModelIndex &index) const && m_deployables.first().remoteDir.isEmpty(); } -bool MaemoDeployableListModel::hasDesktopFile() const +QString MaemoDeployableListModel::localDesktopFilePath() const { if (m_projectType == LibraryTemplate) - return false; + return QString(); foreach (const MaemoDeployable &d, m_deployables) { if (QFileInfo(d.localFilePath).fileName() == m_projectName + QLatin1String(".desktop")) - return true; + return d.localFilePath; } - return false; + return QString(); } bool MaemoDeployableListModel::addDesktopFile(QString &error) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h index 30466cb9cae8380108ef7b16b67edd90adb45c5f..e6f61210fe24fd367e76aecf4f845cececd51306 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h @@ -70,7 +70,8 @@ public: QString applicationName() const { return m_targetInfo.target; } bool hasTargetPath() const { return m_hasTargetPath; } bool canAddDesktopFile() const { return isApplicationProject() && !hasDesktopFile(); } - bool hasDesktopFile() const; + QString localDesktopFilePath() const; + bool hasDesktopFile() const { return !localDesktopFilePath().isEmpty(); } bool addDesktopFile(QString &error); bool canAddIcon() const { return isApplicationProject() && remoteIconFilePath().isEmpty(); } bool addIcon(const QString &fileName, QString &error); diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp index 1e1e534317e4b31a3872f3032266235b2171c13e..1b220619e05cd76173d60c76fec7e766f6a156c2 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp @@ -28,6 +28,8 @@ **************************************************************************/ #include "maemopublisherfremantlefree.h" +#include "maemodeployablelistmodel.h" +#include "maemodeploystep.h" #include "maemoglobal.h" #include "maemopackagecreationstep.h" #include "maemopublishingfileselectiondialog.h" @@ -35,6 +37,7 @@ #include <coreplugin/ifile.h> #include <projectexplorer/project.h> +#include <projectexplorer/target.h> #include <qt4projectmanager/qmakestep.h> #include <qt4projectmanager/qt4buildconfiguration.h> @@ -125,8 +128,14 @@ void MaemoPublisherFremantleFree::createPackage() return; } - emit progressReport(tr("Cleaning up temporary directory ...")); QString error; + if (!updateDesktopFiles(&error)) { + finishWithFailure(error, + tr("Publishing failed: Could not create package.")); + return; + } + + emit progressReport(tr("Cleaning up temporary directory ...")); if (!MaemoPackageCreationStep::preparePackagingProcess(m_process, m_buildConfig, m_tmpProjectDir, &error)) { finishWithFailure(tr("Error preparing packaging process: %1").arg(error), @@ -474,6 +483,67 @@ void MaemoPublisherFremantleFree::finishWithFailure(const QString &progressMsg, setState(Inactive); } +bool MaemoPublisherFremantleFree::updateDesktopFiles(QString *error) const +{ + bool success = true; + MaemoDeployStep * const deployStep + = MaemoGlobal::buildStep<MaemoDeployStep>(m_buildConfig->target() + ->activeDeployConfiguration()); + for (int i = 0; i < deployStep->deployables()->modelCount(); ++i) { + const MaemoDeployableListModel * const model + = deployStep->deployables()->modelAt(i); + QString desktopFilePath = model->localDesktopFilePath(); + if (desktopFilePath.isEmpty()) + continue; + desktopFilePath.replace(model->projectDir(), m_tmpProjectDir); + QFile desktopFile(desktopFilePath); + const QString executableFilePath = model->remoteExecutableFilePath(); + if (executableFilePath.isEmpty()) { + qDebug("%s: Skipping subproject %s with missing deployment information.", + Q_FUNC_INFO, qPrintable(model->proFilePath())); + continue; + } + if (!desktopFile.exists() || !desktopFile.open(QIODevice::ReadWrite)) { + success = false; + if (error) { + *error = tr("Failed to adapt desktop file '%1'.") + .arg(desktopFilePath); + } + continue; + } + QByteArray desktopFileContents = desktopFile.readAll(); + bool fileNeedsUpdate = addOrReplaceDesktopFileValue(desktopFileContents, + "Exec", executableFilePath.toUtf8()); + if (fileNeedsUpdate) { + desktopFile.resize(0); + desktopFile.write(desktopFileContents); + } + } + return success; +} + +bool MaemoPublisherFremantleFree::addOrReplaceDesktopFileValue(QByteArray &fileContent, + const QByteArray &key, const QByteArray &newValue) const +{ + const int keyPos = fileContent.indexOf(key + '='); + if (keyPos == -1) { + if (!fileContent.endsWith('\n')) + fileContent += '\n'; + fileContent += key + '=' + newValue + '\n'; + return true; + } + int nextNewlinePos = fileContent.indexOf('\n', keyPos); + if (nextNewlinePos == -1) + nextNewlinePos = fileContent.count(); + const int replacePos = keyPos + key.count() + 1; + const int replaceCount = nextNewlinePos - replacePos; + const QByteArray &oldValue = fileContent.mid(replacePos, replaceCount); + if (oldValue == newValue) + return false; + fileContent.replace(replacePos, replaceCount, newValue); + return true; +} + void MaemoPublisherFremantleFree::setState(State newState) { if (m_state == newState) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.h b/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.h index d911a241a9ee277bef7f362096b8460b15aaad71..fe043c07c1e330272333d0a6670b188b6cfd0ba4 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.h @@ -96,6 +96,9 @@ private: void prepareToSendFile(); void sendFile(); void finishWithFailure(const QString &progressMsg, const QString &resultMsg); + bool updateDesktopFiles(QString *error = 0) const; + bool addOrReplaceDesktopFileValue(QByteArray &fileContent, + const QByteArray &key, const QByteArray &newValue) const; const ProjectExplorer::Project * const m_project; bool m_doUpload;