Commit f43095ce authored by ck's avatar ck
Browse files

Maemo: Prepare infrastructure for proper subdirs support.

No difference in functionality yet.

Reviewed-by: kh1
parent fd9b74db
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef MAEMODEPLOYABLE_H
#define MAEMODEPLOYABLE_H
#include <QtCore/QHash>
#include <QtCore/QString>
namespace Qt4ProjectManager {
namespace Internal {
struct MaemoDeployable
{
MaemoDeployable(const QString &localFilePath, const QString &remoteDir)
: localFilePath(localFilePath), remoteDir(remoteDir) {}
bool operator==(const MaemoDeployable &other) const
{
return localFilePath == other.localFilePath
&& remoteDir == other.remoteDir;
}
QString localFilePath;
QString remoteDir;
};
inline uint qHash(const MaemoDeployable &d)
{
return qHash(qMakePair(d.localFilePath, d.remoteDir));
}
} // namespace Qt4ProjectManager
} // namespace Internal
#endif // MAEMODEPLOYABLE_H
......@@ -27,7 +27,7 @@
**
**************************************************************************/
#include "maemopackagecontents.h"
#include "maemodeployablelistmodel.h"
#include "maemopackagecreationstep.h"
#include "maemotoolchain.h"
......@@ -44,7 +44,7 @@
namespace Qt4ProjectManager {
namespace Internal {
MaemoPackageContents::MaemoPackageContents(MaemoPackageCreationStep *packageStep)
MaemoDeployableListModel::MaemoDeployableListModel(MaemoPackageCreationStep *packageStep)
: QAbstractTableModel(packageStep),
m_packageStep(packageStep),
m_modified(false),
......@@ -52,17 +52,23 @@ MaemoPackageContents::MaemoPackageContents(MaemoPackageCreationStep *packageStep
{
}
MaemoPackageContents::~MaemoPackageContents() {}
MaemoDeployableListModel::~MaemoDeployableListModel() {}
bool MaemoPackageContents::buildModel() const
bool MaemoDeployableListModel::buildModel() const
{
if (m_initialized)
return true;
m_deployables.clear();
QSharedPointer<ProFileWrapper> proFileWrapper
= m_packageStep->proFileWrapper();
const ProFileWrapper::InstallsList &installs = proFileWrapper->installs();
// TODO: The pro file path comes from the outside.
if (!m_proFileWrapper) {
const Qt4ProFileNode * const proFileNode = m_packageStep
->qt4BuildConfiguration()->qt4Target()->qt4Project()
->rootProjectNode();
m_proFileWrapper.reset(new ProFileWrapper(proFileNode->path()));
}
const ProFileWrapper::InstallsList &installs = m_proFileWrapper->installs();
if (installs.targetPath.isEmpty()) {
const Qt4ProFileNode * const proFileNode
= m_packageStep->qt4BuildConfiguration()->qt4Target()
......@@ -70,19 +76,19 @@ bool MaemoPackageContents::buildModel() const
const QString remoteDir = proFileNode->projectType() == LibraryTemplate
? QLatin1String("/usr/local/lib")
: QLatin1String("/usr/local/bin");
m_deployables.prepend(MaemoDeployable(m_packageStep->localExecutableFilePath(),
m_deployables.prepend(MaemoDeployable(localExecutableFilePath(),
remoteDir));
if (!proFileWrapper->addInstallsTarget(remoteDir)) {
if (!m_proFileWrapper->addInstallsTarget(remoteDir)) {
qWarning("Error updating .pro file.");
return false;
}
} else {
m_deployables.prepend(MaemoDeployable(m_packageStep->localExecutableFilePath(),
m_deployables.prepend(MaemoDeployable(localExecutableFilePath(),
installs.targetPath));
}
foreach (const ProFileWrapper::InstallsElem &elem, installs.normalElems) {
foreach (const QString &file, elem.files) {
m_deployables << MaemoDeployable(proFileWrapper->absFilePath(file),
m_deployables << MaemoDeployable(m_proFileWrapper->absFilePath(file),
elem.path);
}
}
......@@ -92,13 +98,13 @@ bool MaemoPackageContents::buildModel() const
return true;
}
MaemoDeployable MaemoPackageContents::deployableAt(int row) const
MaemoDeployable MaemoDeployableListModel::deployableAt(int row) const
{
Q_ASSERT(row >= 0 && row < rowCount());
return m_deployables.at(row);
}
bool MaemoPackageContents::addDeployable(const MaemoDeployable &deployable,
bool MaemoDeployableListModel::addDeployable(const MaemoDeployable &deployable,
QString *error)
{
if (m_deployables.contains(deployable)) {
......@@ -106,7 +112,7 @@ bool MaemoPackageContents::addDeployable(const MaemoDeployable &deployable,
return false;
}
if (!m_packageStep->proFileWrapper()->addInstallsElem(deployable.remoteDir,
if (!m_proFileWrapper->addInstallsElem(deployable.remoteDir,
deployable.localFilePath)) {
*error = tr("Failed to update .pro file.");
return false;
......@@ -118,13 +124,13 @@ bool MaemoPackageContents::addDeployable(const MaemoDeployable &deployable,
return true;
}
bool MaemoPackageContents::removeDeployableAt(int row, QString *error)
bool MaemoDeployableListModel::removeDeployableAt(int row, QString *error)
{
Q_ASSERT(row > 0 && row < rowCount());
const MaemoDeployable &deployable = deployableAt(row);
if (!m_packageStep->proFileWrapper()
->removeInstallsElem(deployable.remoteDir, deployable.localFilePath)) {
if (!m_proFileWrapper->removeInstallsElem(deployable.remoteDir,
deployable.localFilePath)) {
*error = tr("Could not update .pro file.");
return false;
}
......@@ -135,18 +141,18 @@ bool MaemoPackageContents::removeDeployableAt(int row, QString *error)
return true;
}
int MaemoPackageContents::rowCount(const QModelIndex &parent) const
int MaemoDeployableListModel::rowCount(const QModelIndex &parent) const
{
buildModel();
return parent.isValid() ? 0 : m_deployables.count();
}
int MaemoPackageContents::columnCount(const QModelIndex &parent) const
int MaemoDeployableListModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : 2;
}
QVariant MaemoPackageContents::data(const QModelIndex &index, int role) const
QVariant MaemoDeployableListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= rowCount())
return QVariant();
......@@ -159,7 +165,7 @@ QVariant MaemoPackageContents::data(const QModelIndex &index, int role) const
return QVariant();
}
Qt::ItemFlags MaemoPackageContents::flags(const QModelIndex &index) const
Qt::ItemFlags MaemoDeployableListModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags parentFlags = QAbstractTableModel::flags(index);
if (index.column() == 1)
......@@ -167,7 +173,7 @@ Qt::ItemFlags MaemoPackageContents::flags(const QModelIndex &index) const
return parentFlags;
}
bool MaemoPackageContents::setData(const QModelIndex &index,
bool MaemoDeployableListModel::setData(const QModelIndex &index,
const QVariant &value, int role)
{
if (!index.isValid() || index.row() >= rowCount() || index.column() != 1
......@@ -176,7 +182,7 @@ bool MaemoPackageContents::setData(const QModelIndex &index,
MaemoDeployable &deployable = m_deployables[index.row()];
const QString &newRemoteDir = value.toString();
if (!m_packageStep->proFileWrapper()->replaceInstallPath(deployable.remoteDir,
if (!m_proFileWrapper->replaceInstallPath(deployable.remoteDir,
deployable.localFilePath, newRemoteDir)) {
qWarning("Error: Could not update .pro file");
return false;
......@@ -187,7 +193,7 @@ bool MaemoPackageContents::setData(const QModelIndex &index,
return true;
}
QVariant MaemoPackageContents::headerData(int section,
QVariant MaemoDeployableListModel::headerData(int section,
Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
......@@ -195,11 +201,29 @@ QVariant MaemoPackageContents::headerData(int section,
return section == 0 ? tr("Local File Path") : tr("Remote Directory");
}
QString MaemoPackageContents::remoteExecutableFilePath() const
QString MaemoDeployableListModel::localExecutableFilePath() const
{
// TODO: This information belongs to this class.
return m_packageStep->localExecutableFilePath();
}
QString MaemoDeployableListModel::remoteExecutableFilePath() const
{
return buildModel() ? deployableAt(0).remoteDir + '/'
+ m_packageStep->executableFileName() : QString();
}
QString MaemoDeployableListModel::projectName() const
{
// TODO: This must return our own sub project name.
return m_packageStep->qt4BuildConfiguration()->qt4Target()->qt4Project()
->rootProjectNode()->displayName();
}
QString MaemoDeployableListModel::projectDir() const
{
return m_proFileWrapper->projectDir();
}
} // namespace Qt4ProjectManager
} // namespace Internal
......@@ -30,42 +30,25 @@
#ifndef MAEMOPACKAGECONTENTS_H
#define MAEMOPACKAGECONTENTS_H
#include "maemodeployable.h"
#include <QtCore/QAbstractTableModel>
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtCore/QScopedPointer>
#include <QtCore/QString>
namespace Qt4ProjectManager {
namespace Internal {
struct MaemoDeployable
{
MaemoDeployable(const QString &localFilePath, const QString &remoteDir)
: localFilePath(localFilePath), remoteDir(remoteDir) {}
bool operator==(const MaemoDeployable &other) const
{
return localFilePath == other.localFilePath
&& remoteDir == other.remoteDir;
}
QString localFilePath;
QString remoteDir;
};
inline uint qHash(const MaemoDeployable &d)
{
return qHash(qMakePair(d.localFilePath, d.remoteDir));
}
class MaemoPackageCreationStep;
class ProFileReader;
class ProFileWrapper;
class MaemoPackageContents : public QAbstractTableModel
class MaemoDeployableListModel : public QAbstractTableModel
{
Q_OBJECT
public:
MaemoPackageContents(MaemoPackageCreationStep *packageStep);
~MaemoPackageContents();
MaemoDeployableListModel(MaemoPackageCreationStep *packageStep);
~MaemoDeployableListModel();
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
......@@ -74,7 +57,10 @@ public:
bool removeDeployableAt(int row, QString *error);
bool isModified() const { return m_modified; }
void setUnModified() { m_modified = false; }
QString localExecutableFilePath() const;
QString remoteExecutableFilePath() const;
QString projectName() const;
QString projectDir() const;
private:
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
......@@ -92,6 +78,7 @@ private:
mutable QList<MaemoDeployable> m_deployables;
mutable bool m_modified;
mutable bool m_initialized;
mutable QScopedPointer<ProFileWrapper> m_proFileWrapper;
};
} // namespace Qt4ProjectManager
......
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemodeployablelistwidget.h"
#include "ui_maemodeployablelistwidget.h"
#include "maemodeployablelistmodel.h"
#include <utils/qtcassert.h>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
namespace Qt4ProjectManager {
namespace Internal {
MaemoDeployableListWidget::MaemoDeployableListWidget(QWidget *parent,
MaemoDeployableListModel *model)
: QWidget(parent), m_ui(new Ui::MaemoDeployableListWidget), m_model(model)
{
m_ui->setupUi(this);
m_ui->deployablesView->setWordWrap(false);
m_ui->deployablesView->setModel(m_model);
connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
m_ui->deployablesView, SLOT(resizeColumnsToContents()));
connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)),
m_ui->deployablesView, SLOT(resizeColumnsToContents()));
connect(m_ui->deployablesView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,
SLOT(enableOrDisableRemoveButton()));
m_ui->deployablesView->resizeColumnsToContents();
m_ui->deployablesView->horizontalHeader()->setStretchLastSection(true);
enableOrDisableRemoveButton();
}
MaemoDeployableListWidget::~MaemoDeployableListWidget()
{
delete m_ui;
}
void MaemoDeployableListWidget::addFile()
{
// TODO: Make all this stuff subproject-specific.
const QString title = tr("Choose a local file");
const QString localFile = QFileDialog::getOpenFileName(this, title, m_model->projectDir()); // TODO: Support directories.
if (localFile.isEmpty())
return;
const MaemoDeployable
deployable(QDir::toNativeSeparators(QFileInfo(localFile).absoluteFilePath()),
"/");
QString errorString;
if (!m_model->addDeployable(deployable, &errorString)) {
QMessageBox::information(this, tr("Error adding file"), errorString);
} else {
const QModelIndex newIndex
= m_model->index(m_model->rowCount() - 1, 1);
m_ui->deployablesView->selectionModel()->clear();
m_ui->deployablesView->scrollTo(newIndex);
m_ui->deployablesView->edit(newIndex);
}
}
void MaemoDeployableListWidget::removeFile()
{
const QModelIndexList selectedRows
= m_ui->deployablesView->selectionModel()->selectedRows();
if (selectedRows.isEmpty())
return;
const int row = selectedRows.first().row();
if (row != 0) {
QString errorString;
if (!m_model->removeDeployableAt(row, &errorString)) {
QMessageBox::information(this, tr("Error removing file"),
errorString);
}
}
}
void MaemoDeployableListWidget::enableOrDisableRemoveButton()
{
const QModelIndexList selectedRows
= m_ui->deployablesView->selectionModel()->selectedRows();
m_ui->removeFileButton->setEnabled(!selectedRows.isEmpty()
&& selectedRows.first().row() != 0);
}
} // namespace Internal
} // namespace Qt4ProjectManager
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MAEMODEPLOYABLELISTWIDGET_H
#define MAEMODEPLOYABLELISTWIDGET_H
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
namespace Ui {
class MaemoDeployableListWidget;
}
QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeployableListModel;
class MaemoDeployableListWidget : public QWidget
{
Q_OBJECT
public:
MaemoDeployableListWidget(QWidget *parent, MaemoDeployableListModel *model);
~MaemoDeployableListWidget();
private slots:
void addFile();
void removeFile();
void enableOrDisableRemoveButton();
private:
Ui::MaemoDeployableListWidget *m_ui;
MaemoDeployableListModel * const m_model;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // MAEMODEPLOYABLELISTWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MaemoDeployableListWidget</class>
<widget class="QWidget" name="MaemoDeployableListWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>491</width>
<height>289</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableView" name="deployablesView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>200</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QToolButton" name="addFileButton">