Skip to content
Snippets Groups Projects
Commit 278730dd authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Fix path to exectuable in desktop file when publishing.

parent f9d796e1
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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);
......
......@@ -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)
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment