Commit ce0da603 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Make use of new Qt4MaemoTarget class.

This allows us to get rid of MaemoTemplatesManager, which was a bit of
a crutch from the beginning.
parent 684f8725
......@@ -42,7 +42,6 @@
#include "maemoqemumanager.h"
#include "maemorunfactories.h"
#include "maemosettingspages.h"
#include "maemotemplatesmanager.h"
#include "maemotoolchain.h"
#include "qt4maemotargetfactory.h"
......@@ -77,7 +76,6 @@ MaemoManager::MaemoManager()
m_instance = this;
MaemoQemuManager::instance(this);
MaemoDeviceConfigurations::instance(this);
MaemoTemplatesManager::instance(this);
PluginManager *pluginManager = PluginManager::instance();
pluginManager->addObject(m_runControlFactory);
......
......@@ -46,7 +46,7 @@
#include "maemodeploystep.h"
#include "maemoglobal.h"
#include "maemopackagecreationwidget.h"
#include "maemotemplatesmanager.h"
#include "qt4maemotarget.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectexplorerconstants.h>
......@@ -203,11 +203,11 @@ bool MaemoPackageCreationStep::createPackage(QProcess *buildProc)
// Workaround for non-working dh_builddeb --destdir=.
if (!QDir(buildDirectory()).isRoot()) {
const ProjectExplorer::Project * const project
= buildConfiguration()->target()->project();
const Qt4MaemoTarget * const target = maemoTarget();
const ProjectExplorer::Project * const project = target->project();
QString error;
const QString pkgFileName = packageFileName(project,
MaemoTemplatesManager::instance()->version(project, &error));
target->projectVersion(&error));
if (!error.isEmpty())
raiseError(tr("Packaging failed."), error);
const QString changesFileName = QFileInfo(pkgFileName)
......@@ -268,8 +268,7 @@ bool MaemoPackageCreationStep::copyDebianFiles(bool inSourceBuild)
.arg(debianDirPath));
return false;
}
const QString templatesDirPath = MaemoTemplatesManager::instance()
->debianDirPath(buildConfiguration()->target()->project());
const QString templatesDirPath = maemoTarget()->debianDirPath();
QDir templatesDir(templatesDirPath);
const QStringList &files = templatesDir.entryList(QDir::Files);
foreach (const QString &fileName, files) {
......@@ -330,6 +329,11 @@ const Qt4BuildConfiguration *MaemoPackageCreationStep::qt4BuildConfiguration() c
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
}
Qt4MaemoTarget *MaemoPackageCreationStep::maemoTarget() const
{
return qobject_cast<Qt4MaemoTarget *>(buildConfiguration()->target());
}
QString MaemoPackageCreationStep::buildDirectory() const
{
return qt4BuildConfiguration()->buildDirectory();
......@@ -365,13 +369,10 @@ bool MaemoPackageCreationStep::packagingNeeded() const
return true;
}
const ProjectExplorer::Project * const project = target()->project();
const MaemoTemplatesManager * const templatesManager
= MaemoTemplatesManager::instance();
const QString debianPath = templatesManager->debianDirPath(project);
const QString debianPath = maemoTarget()->debianDirPath();
if (packageInfo.lastModified() <= QFileInfo(debianPath).lastModified())
return true;
const QStringList debianFiles = templatesManager->debianFiles(project);
const QStringList debianFiles = maemoTarget()->debianFiles();
foreach (const QString &debianFile, debianFiles) {
const QString absFilePath = debianPath + QLatin1Char('/') + debianFile;
if (packageInfo.lastModified() <= QFileInfo(absFilePath).lastModified())
......@@ -418,16 +419,13 @@ bool MaemoPackageCreationStep::isPackagingEnabled() const
QString MaemoPackageCreationStep::versionString(QString *error) const
{
return MaemoTemplatesManager::instance()
->version(buildConfiguration()->target()->project(), error);
return maemoTarget()->projectVersion(error);
}
bool MaemoPackageCreationStep::setVersionString(const QString &version,
QString *error)
{
const bool success = MaemoTemplatesManager::instance()
->setVersion(buildConfiguration()->target()->project(), version, error);
const bool success = maemoTarget()->setProjectVersion(version, error);
if (success)
emit packageFilePathChanged();
return success;
......
......@@ -56,6 +56,7 @@ class Qt4BuildConfiguration;
namespace Internal {
class MaemoDeployStep;
class MaemoDeployableListModel;
class Qt4MaemoTarget;
class MaemoPackageCreationStep : public ProjectExplorer::BuildStep
{
......@@ -84,6 +85,7 @@ public:
QString projectName() const;
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
Qt4MaemoTarget *maemoTarget() const;
static const QLatin1String DefaultVersionNumber;
......
......@@ -44,7 +44,7 @@
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemotemplatesmanager.h"
#include "qt4maemotarget.h"
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/project.h>
......@@ -84,47 +84,40 @@ void MaemoPackageCreationWidget::init()
void MaemoPackageCreationWidget::initGui()
{
updateDebianFileList(thisProject());
updateVersionInfo(thisProject());
handleControlFileUpdate(thisProject());
updateDebianFileList();
updateVersionInfo();
handleControlFileUpdate();
connect(m_step, SIGNAL(packageFilePathChanged()), this,
SIGNAL(updateSummary()));
connect(m_step, SIGNAL(qtVersionChanged()), this,
SLOT(handleToolchainChanged()));
handleToolchainChanged();
versionInfoChanged();
connect(MaemoTemplatesManager::instance(),
SIGNAL(debianDirContentsChanged(const ProjectExplorer::Project*)),
this, SLOT(updateDebianFileList(const ProjectExplorer::Project*)));
connect(MaemoTemplatesManager::instance(),
SIGNAL(changeLogChanged(const ProjectExplorer::Project*)), this,
SLOT(updateVersionInfo(const ProjectExplorer::Project*)));
connect(MaemoTemplatesManager::instance(),
SIGNAL(controlChanged(const ProjectExplorer::Project*)), this,
SLOT(handleControlFileUpdate(const ProjectExplorer::Project*)));
connect(m_step->maemoTarget(), SIGNAL(debianDirContentsChanged()),
SLOT(updateDebianFileList()));
connect(m_step->maemoTarget(), SIGNAL(changeLogChanged()),
SLOT(updateVersionInfo()));
connect(m_step->maemoTarget(), SIGNAL(controlChanged()),
SLOT(handleControlFileUpdate()));
connect(m_ui->nameLineEdit, SIGNAL(editingFinished()), SLOT(setName()));
m_ui->shortDescriptionLineEdit->setMaxLength(60);
connect(m_ui->shortDescriptionLineEdit, SIGNAL(editingFinished()),
SLOT(setShortDescription()));
}
void MaemoPackageCreationWidget::updateDebianFileList(const ProjectExplorer::Project *project)
void MaemoPackageCreationWidget::updateDebianFileList()
{
if (thisProject() == project)
m_ui->debianFilesComboBox->clear();
const QStringList &debianFiles = MaemoTemplatesManager::instance()
->debianFiles(project);
foreach (const QString &fileName, debianFiles) {
if (fileName != QLatin1String("compat"))
m_ui->debianFilesComboBox->addItem(fileName);
}
m_ui->debianFilesComboBox->clear();
const QStringList &debianFiles = m_step->maemoTarget()->debianFiles();
foreach (const QString &fileName, debianFiles) {
if (fileName != QLatin1String("compat")
&& !fileName.endsWith(QLatin1Char('~')))
m_ui->debianFilesComboBox->addItem(fileName);
}
}
void MaemoPackageCreationWidget::updateVersionInfo(const ProjectExplorer::Project *project)
void MaemoPackageCreationWidget::updateVersionInfo()
{
if (project != thisProject())
return;
QString error;
QString versionString = m_step->versionString(&error);
if (versionString.isEmpty()) {
......@@ -138,20 +131,17 @@ void MaemoPackageCreationWidget::updateVersionInfo(const ProjectExplorer::Projec
m_ui->patch->setValue(list.value(2, QLatin1String("0")).toInt());
}
void MaemoPackageCreationWidget::handleControlFileUpdate(const Project *project)
void MaemoPackageCreationWidget::handleControlFileUpdate()
{
if (project != thisProject())
return;
updatePackageManagerIcon(project);
updateName(project);
updateShortDescription(project);
updatePackageManagerIcon();
updateName();
updateShortDescription();
}
void MaemoPackageCreationWidget::updatePackageManagerIcon(const Project *project)
void MaemoPackageCreationWidget::updatePackageManagerIcon()
{
QString error;
const QIcon &icon
= MaemoTemplatesManager::instance()->packageManagerIcon(project, &error);
const QIcon &icon = m_step->maemoTarget()->packageManagerIcon(&error);
if (!error.isEmpty()) {
QMessageBox::critical(this, tr("Could not read icon"), error);
} else {
......@@ -160,15 +150,14 @@ void MaemoPackageCreationWidget::updatePackageManagerIcon(const Project *project
}
}
void MaemoPackageCreationWidget::updateName(const Project *project)
void MaemoPackageCreationWidget::updateName()
{
m_ui->nameLineEdit->setText(MaemoTemplatesManager::instance()->name(project));
m_ui->nameLineEdit->setText(m_step->maemoTarget()->name());
}
void MaemoPackageCreationWidget::updateShortDescription(const Project *project)
void MaemoPackageCreationWidget::updateShortDescription()
{
m_ui->shortDescriptionLineEdit
->setText(MaemoTemplatesManager::instance()->shortDescription(project));
m_ui->shortDescriptionLineEdit->setText(m_step->maemoTarget()->shortDescription());
}
void MaemoPackageCreationWidget::setPackageManagerIcon()
......@@ -183,16 +172,14 @@ void MaemoPackageCreationWidget::setPackageManagerIcon()
QString(), imageFilter);
if (!iconFileName.isEmpty()) {
QString error;
if (!MaemoTemplatesManager::instance()->setPackageManagerIcon(thisProject(),
iconFileName, &error))
if (!m_step->maemoTarget()->setPackageManagerIcon(iconFileName, &error))
QMessageBox::critical(this, tr("Could Not Set New Icon"), error);
}
}
void MaemoPackageCreationWidget::setName()
{
if (!MaemoTemplatesManager::instance()->setName(thisProject(),
m_ui->nameLineEdit->text())) {
if (!m_step->maemoTarget()->setName(m_ui->nameLineEdit->text())) {
QMessageBox::critical(this, tr("File Error"),
tr("Could not set project name."));
}
......@@ -200,13 +187,13 @@ void MaemoPackageCreationWidget::setName()
void MaemoPackageCreationWidget::setShortDescription()
{
if (!MaemoTemplatesManager::instance()->setShortDescription(thisProject(),
m_ui->shortDescriptionLineEdit->text())) {
if (!m_step->maemoTarget()->setShortDescription(m_ui->shortDescriptionLineEdit->text())) {
QMessageBox::critical(this, tr("File Error"),
tr("Could not set project description."));
}
}
// TODO: Can go when a target has only one possible type of toolchain
void MaemoPackageCreationWidget::handleToolchainChanged()
{
const Qt4BuildConfiguration * const bc = m_step->qt4BuildConfiguration();
......@@ -258,17 +245,10 @@ void MaemoPackageCreationWidget::versionInfoChanged()
void MaemoPackageCreationWidget::editDebianFile()
{
const QString debianFilePath
= MaemoTemplatesManager::instance()->debianDirPath(thisProject())
+ QLatin1Char('/') + m_ui->debianFilesComboBox->currentText();
Core::EditorManager::instance()->openEditor(debianFilePath,
QString(),
Core::EditorManager::ModeSwitch);
}
Project *MaemoPackageCreationWidget::thisProject() const
{
return m_step->buildConfiguration()->target()->project();
const QString debianFilePath = m_step->maemoTarget()->debianDirPath()
+ QLatin1Char('/') + m_ui->debianFilesComboBox->currentText();
Core::EditorManager::instance()->openEditor(debianFilePath, QString(),
Core::EditorManager::ModeSwitch);
}
} // namespace Internal
......
......@@ -68,19 +68,18 @@ private slots:
void editDebianFile();
void versionInfoChanged();
void initGui();
void updateDebianFileList(const ProjectExplorer::Project *thisProject);
void updateVersionInfo(const ProjectExplorer::Project *thisProject);
void handleControlFileUpdate(const ProjectExplorer::Project *thisProject);
void updateDebianFileList();
void updateVersionInfo();
void handleControlFileUpdate();
void setPackageManagerIcon();
void setName();
void setShortDescription();
void handleToolchainChanged();
private:
void updatePackageManagerIcon(const ProjectExplorer::Project *thisProject);
void updateName(const ProjectExplorer::Project *thisProject);
void updateShortDescription(const ProjectExplorer::Project *thisProject);
ProjectExplorer::Project *thisProject() const;
void updatePackageManagerIcon();
void updateName();
void updateShortDescription();
MaemoPackageCreationStep * const m_step;
Ui::MaemoPackageCreationWidget * const m_ui;
......
......@@ -37,7 +37,7 @@
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemopublishingfileselectiondialog.h"
#include "maemotemplatesmanager.h"
#include "qt4maemotarget.h"
#include <coreplugin/ifile.h>
#include <projectexplorer/project.h>
......@@ -587,9 +587,9 @@ bool MaemoPublisherFremantleFree::addOrReplaceDesktopFileValue(QByteArray &fileC
QStringList MaemoPublisherFremantleFree::findProblems() const
{
QStringList problems;
const MaemoTemplatesManager * const templatesManager
= MaemoTemplatesManager::instance();
const QString &description = templatesManager->shortDescription(m_project);
const Qt4MaemoTarget * const target
= qobject_cast<Qt4MaemoTarget *>(m_buildConfig->target());
const QString &description = target->shortDescription();
if (description.trimmed().isEmpty()) {
problems << tr("The package description is empty.");
} else if (description.contains(QLatin1String("insert up to"))) {
......@@ -597,7 +597,7 @@ QStringList MaemoPublisherFremantleFree::findProblems() const
"not what you want.").arg(description);
}
QString dummy;
if (templatesManager->packageManagerIcon(m_project, &dummy).isNull())
if (target->packageManagerIcon(&dummy).isNull())
problems << tr("You have not set an icon for the package manager.");
return problems;
}
......
/**************************************************************************
**
** 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.
**
**************************************************************************/
#ifndef MAEMOTEMPLATESCREATOR_H
#define MAEMOTEMPLATESCREATOR_H
#include <QtCore/QFile>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtGui/QIcon>
QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher)
namespace ProjectExplorer {
class Project;
class ProjectNode;
class Target;
}
namespace Qt4ProjectManager {
class Qt4Project;
namespace Internal {
class Qt4ProFileNode;
class Qt4MaemoTarget;
class MaemoTemplatesManager : public QObject
{
Q_OBJECT
public:
static MaemoTemplatesManager *instance(QObject *parent = 0);
QString version(const ProjectExplorer::Project *project,
QString *error) const;
bool setVersion(const ProjectExplorer::Project *project,
const QString &version, QString *error) const;
QString debianDirPath(const ProjectExplorer::Project *project) const;
QStringList debianFiles(const ProjectExplorer::Project *project) const;
QIcon packageManagerIcon(const ProjectExplorer::Project *project,
QString *error) const;
bool setPackageManagerIcon(const ProjectExplorer::Project *project,
const QString &iconFilePath, QString *error) const;
QString name(const ProjectExplorer::Project *project) const;
bool setName(const ProjectExplorer::Project *project,
const QString &name);
QString shortDescription(const ProjectExplorer::Project *project) const;
bool setShortDescription(const ProjectExplorer::Project *project,
const QString &description);
signals:
void debianDirContentsChanged(const ProjectExplorer::Project *project);
void changeLogChanged(const ProjectExplorer::Project *project);
void controlChanged(const ProjectExplorer::Project *project);
private slots:
void handleActiveProjectChanged(ProjectExplorer::Project *project);
bool handleTarget(ProjectExplorer::Target *target);
void handleDebianDirContentsChanged();
void handleDebianFileChanged(const QString &filePath);
void handleProjectToBeRemoved(ProjectExplorer::Project *project);
void handleProFileUpdated();
void handleTargetRemoved(ProjectExplorer::Target *target);
private:
explicit MaemoTemplatesManager(QObject *parent);
void raiseError(const QString &reason);
QString changeLogFilePath(const ProjectExplorer::Project *project) const;
QString controlFilePath(const ProjectExplorer::Project *project) const;
bool createDebianTemplatesIfNecessary(const ProjectExplorer::Target *target);
bool updateDesktopFiles(const Qt4MaemoTarget *target);
bool updateDesktopFile(const Qt4MaemoTarget *target,
Qt4ProFileNode *proFileNode);
ProjectExplorer::Project *findProject(const QFileSystemWatcher *fsWatcher) const;
void findLine(const QByteArray &string, QByteArray &document,
int &lineEndPos, int &valuePos);
bool adaptRulesFile(const ProjectExplorer::Project *project);
bool adaptControlFile(const ProjectExplorer::Project *project);
bool adaptControlFileField(QByteArray &document, const QByteArray &fieldName,
const QByteArray &newFieldValue);
QSharedPointer<QFile> openFile(const QString &filePath,
QIODevice::OpenMode mode, QString *error) const;
bool setFieldValue(const ProjectExplorer::Project *project,
const QByteArray &fieldName, const QByteArray &fieldValue);
QByteArray controlFileFieldValue(const ProjectExplorer::Project *project,
const QString &key, bool multiLine) const;
static MaemoTemplatesManager *m_instance;
typedef QMap<ProjectExplorer::Project *, QFileSystemWatcher *> MaemoProjectMap;
MaemoProjectMap m_maemoProjects;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // MAEMOTEMPLATESCREATOR_H
......@@ -26,7 +26,6 @@ HEADERS += \
$$PWD/maemodebugsupport.h \
$$PWD/maemoremotemountsmodel.h \
$$PWD/maemodeviceenvreader.h \
$$PWD/maemotemplatesmanager.h \
$$PWD/maemomountspecification.h \
$$PWD/maemoremotemounter.h \
$$PWD/maemoprofilesupdatedialog.h \
......@@ -75,7 +74,6 @@ SOURCES += \
$$PWD/maemodebugsupport.cpp \
$$PWD/maemoremotemountsmodel.cpp \
$$PWD/maemodeviceenvreader.cpp \
$$PWD/maemotemplatesmanager.cpp \
$$PWD/maemomountspecification.cpp \
$$PWD/maemoremotemounter.cpp \
$$PWD/maemoprofilesupdatedialog.cpp \
......
......@@ -27,26 +27,46 @@
**
**************************************************************************/
#include "qt4maemotarget.h"
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemorunconfiguration.h"
#include "qt4project.h"
#include "qt4maemotarget.h"
#include "qt4maemodeployconfiguration.h"
#include <projectexplorer/customexecutablerunconfiguration.h>
#include <qt4projectmanager/qt4project.h>
#include <QtGui/QApplication>
#include <QtCore/QBuffer>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtGui/QIcon>
#include <QtGui/QMessageBox>
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
namespace {
const QByteArray IconFieldName("XB-Maemo-Icon-26");
const QByteArray NameFieldName("XB-Maemo-Display-Name");
const QByteArray ShortDescriptionFieldName("Description");
const QLatin1String PackagingDirName("qtc_packaging");
const QLatin1String DebianDirNameFremantle("debian_fremantle");
} // anonymous namespace
Qt4MaemoTarget::Qt4MaemoTarget(Qt4Project *parent, const QString &id) :
Qt4BaseTarget(parent, id),
m_buildConfigurationFactory(new Qt4BuildConfigurationFactory(this)),
m_deployConfigurationFactory(new Qt4MaemoDeployConfigurationFactory(this))
m_deployConfigurationFactory(new Qt4MaemoDeployConfigurationFactory(this)),
m_debianFilesWatcher(new QFileSystemWatcher(this))
{
setDisplayName(defaultDisplayName());
setIcon(QIcon(":/projectexplorer/images/MaemoDevice.png"));
connect(parent, SIGNAL(addedTarget(ProjectExplorer::Target*)),
this, SLOT(handleTargetAdded(ProjectExplorer::Target*)));
}
Qt4MaemoTarget::~Qt4MaemoTarget()
......@@ -100,3 +120,474 @@ void Qt4MaemoTarget::createApplicationProFiles()
addRunConfiguration(new ProjectExplorer::CustomExecutableRunConfiguration(this));
}
}
QString Qt4MaemoTarget::projectVersion(QString *error) const
{
QSharedPointer<QFile> changeLog = openFile(changeLogFilePath(),
QIODevice::ReadOnly, error);
if (!changeLog)
return QString();
const QByteArray &firstLine = changeLog->readLine();
const int openParenPos = firstLine.indexOf('(');
if (openParenPos == -1) {
if (error) {
*error = tr("Debian changelog file '%1' has unexpected format.")
.arg(QDir::toNativeSeparators(changeLog->fileName()));
}
return QString();
}
const int closeParenPos = firstLine.indexOf(')', openParenPos);
if (closeParenPos == -1) {
if (error) {
*error = tr("Debian changelog file '%1' has unexpected format.")
.arg(QDir::toNativeSeparators(changeLog->fileName()));
}
return QString();
}
return QString::fromUtf8(firstLine.mid(openParenPos + 1,
closeParenPos - openParenPos - 1).data());
}
bool Qt4MaemoTarget::setProjectVersion(const QString &version, QString *error) const
{
const QString filePath = changeLogFilePath();