2010-04-20 17:02:31 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
#include "maemodeployablelistmodel.h"
|
2010-04-20 17:02:31 +02:00
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
#include "maemoprofilewrapper.h"
|
2010-05-04 11:38:03 +02:00
|
|
|
|
2010-07-07 14:50:37 +02:00
|
|
|
#include <qt4projectmanager/qt4nodes.h>
|
2010-05-04 11:38:03 +02:00
|
|
|
|
2010-06-16 08:57:13 +02:00
|
|
|
#include <QtCore/QCryptographicHash>
|
2010-07-27 17:27:04 +02:00
|
|
|
#include <QtCore/QFile>
|
2010-05-04 11:38:03 +02:00
|
|
|
#include <QtCore/QFileInfo>
|
2010-04-20 17:02:31 +02:00
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-07-07 14:50:37 +02:00
|
|
|
MaemoDeployableListModel::MaemoDeployableListModel(const Qt4ProFileNode *proFileNode,
|
2010-07-27 17:27:04 +02:00
|
|
|
const QSharedPointer<ProFileOption> &proFileOption, QObject *parent)
|
2010-07-07 16:49:39 +02:00
|
|
|
: QAbstractTableModel(parent),
|
|
|
|
|
m_proFileNode(proFileNode),
|
|
|
|
|
m_modified(false),
|
2010-07-28 09:36:30 +02:00
|
|
|
m_proFileWrapper(new MaemoProFileWrapper(m_proFileNode->path(), proFileOption))
|
2010-06-16 08:57:13 +02:00
|
|
|
{
|
2010-07-07 14:50:37 +02:00
|
|
|
buildModel();
|
2010-06-16 08:57:13 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
MaemoDeployableListModel::~MaemoDeployableListModel() {}
|
2010-06-16 08:57:13 +02:00
|
|
|
|
2010-07-07 14:50:37 +02:00
|
|
|
bool MaemoDeployableListModel::buildModel()
|
2010-04-20 17:02:31 +02:00
|
|
|
{
|
2010-06-29 14:10:01 +02:00
|
|
|
m_deployables.clear();
|
2010-07-06 12:04:53 +02:00
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
const MaemoProFileWrapper::InstallsList &installs = m_proFileWrapper->installs();
|
2010-06-30 14:44:41 +02:00
|
|
|
if (installs.targetPath.isEmpty()) {
|
2010-07-07 14:50:37 +02:00
|
|
|
const QString remoteDir = m_proFileNode->projectType() == LibraryTemplate
|
2010-06-16 08:57:13 +02:00
|
|
|
? QLatin1String("/usr/local/lib")
|
|
|
|
|
: QLatin1String("/usr/local/bin");
|
2010-07-06 12:04:53 +02:00
|
|
|
m_deployables.prepend(MaemoDeployable(localExecutableFilePath(),
|
2010-06-16 08:57:13 +02:00
|
|
|
remoteDir));
|
2010-07-27 17:27:04 +02:00
|
|
|
QFile projectFile(m_proFileNode->path());
|
|
|
|
|
if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
2010-06-29 14:10:01 +02:00
|
|
|
qWarning("Error updating .pro file.");
|
2010-07-27 17:27:04 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString installsString
|
2010-08-16 17:07:09 +02:00
|
|
|
= QLatin1String("\nmaemo5|maemo6 {\n target.path = ")
|
2010-07-27 17:27:04 +02:00
|
|
|
+ remoteDir + QLatin1String("\n INSTALLS += target\n}\n");
|
|
|
|
|
if (!projectFile.write(installsString.toLocal8Bit())) {
|
|
|
|
|
qWarning("Error updating .pro file.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-06-30 14:44:41 +02:00
|
|
|
} else {
|
2010-07-06 12:04:53 +02:00
|
|
|
m_deployables.prepend(MaemoDeployable(localExecutableFilePath(),
|
2010-06-30 14:44:41 +02:00
|
|
|
installs.targetPath));
|
|
|
|
|
}
|
2010-07-28 09:36:30 +02:00
|
|
|
foreach (const MaemoProFileWrapper::InstallsElem &elem, installs.normalElems) {
|
2010-08-06 15:03:38 +02:00
|
|
|
foreach (const QString &file, elem.files)
|
|
|
|
|
m_deployables << MaemoDeployable(file, elem.path);
|
2010-06-16 08:57:13 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-30 14:44:41 +02:00
|
|
|
m_modified = true; // ???
|
2010-06-16 08:57:13 +02:00
|
|
|
return true;
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
MaemoDeployable MaemoDeployableListModel::deployableAt(int row) const
|
2010-04-20 17:02:31 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(row >= 0 && row < rowCount());
|
2010-06-16 08:57:13 +02:00
|
|
|
return m_deployables.at(row);
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
bool MaemoDeployableListModel::addDeployable(const MaemoDeployable &deployable,
|
2010-06-16 08:57:13 +02:00
|
|
|
QString *error)
|
2010-05-03 14:47:40 +02:00
|
|
|
{
|
2010-06-29 14:10:01 +02:00
|
|
|
if (m_deployables.contains(deployable)) {
|
|
|
|
|
*error = tr("File already in list.");
|
2010-06-16 08:57:13 +02:00
|
|
|
return false;
|
2010-06-29 14:10:01 +02:00
|
|
|
}
|
2010-06-30 14:44:41 +02:00
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
if (!m_proFileWrapper->addInstallsElem(deployable.remoteDir,
|
2010-06-30 14:44:41 +02:00
|
|
|
deployable.localFilePath)) {
|
|
|
|
|
*error = tr("Failed to update .pro file.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-06-16 08:57:13 +02:00
|
|
|
|
2010-05-03 14:47:40 +02:00
|
|
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
|
|
|
|
m_deployables << deployable;
|
|
|
|
|
endInsertRows();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
bool MaemoDeployableListModel::removeDeployableAt(int row, QString *error)
|
2010-05-03 14:47:40 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(row > 0 && row < rowCount());
|
2010-06-16 08:57:13 +02:00
|
|
|
|
2010-06-24 11:40:22 +02:00
|
|
|
const MaemoDeployable &deployable = deployableAt(row);
|
2010-07-06 12:04:53 +02:00
|
|
|
if (!m_proFileWrapper->removeInstallsElem(deployable.remoteDir,
|
|
|
|
|
deployable.localFilePath)) {
|
2010-06-30 14:44:41 +02:00
|
|
|
*error = tr("Could not update .pro file.");
|
2010-06-16 08:57:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-03 14:47:40 +02:00
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
2010-06-30 14:44:41 +02:00
|
|
|
m_deployables.removeAt(row);
|
2010-05-03 14:47:40 +02:00
|
|
|
endRemoveRows();
|
2010-06-16 08:57:13 +02:00
|
|
|
return true;
|
2010-05-03 14:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
int MaemoDeployableListModel::rowCount(const QModelIndex &parent) const
|
2010-04-20 17:02:31 +02:00
|
|
|
{
|
2010-06-16 08:57:13 +02:00
|
|
|
return parent.isValid() ? 0 : m_deployables.count();
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
int MaemoDeployableListModel::columnCount(const QModelIndex &parent) const
|
2010-04-20 17:02:31 +02:00
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : 2;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
QVariant MaemoDeployableListModel::data(const QModelIndex &index, int role) const
|
2010-04-20 17:02:31 +02:00
|
|
|
{
|
2010-05-04 11:38:03 +02:00
|
|
|
if (!index.isValid() || index.row() >= rowCount())
|
2010-04-20 17:02:31 +02:00
|
|
|
return QVariant();
|
|
|
|
|
|
2010-06-22 14:40:08 +02:00
|
|
|
const MaemoDeployable &d = deployableAt(index.row());
|
2010-05-04 11:38:03 +02:00
|
|
|
if (index.column() == 0 && role == Qt::DisplayRole)
|
|
|
|
|
return d.localFilePath;
|
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
2010-06-07 17:13:11 +02:00
|
|
|
return d.remoteDir;
|
2010-05-04 11:38:03 +02:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
Qt::ItemFlags MaemoDeployableListModel::flags(const QModelIndex &index) const
|
2010-05-04 11:38:03 +02:00
|
|
|
{
|
|
|
|
|
Qt::ItemFlags parentFlags = QAbstractTableModel::flags(index);
|
2010-07-08 13:44:56 +02:00
|
|
|
// if (index.column() == 1)
|
|
|
|
|
// return parentFlags | Qt::ItemIsEditable;
|
2010-05-04 11:38:03 +02:00
|
|
|
return parentFlags;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
bool MaemoDeployableListModel::setData(const QModelIndex &index,
|
2010-05-04 11:38:03 +02:00
|
|
|
const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid() || index.row() >= rowCount() || index.column() != 1
|
|
|
|
|
|| role != Qt::EditRole)
|
|
|
|
|
return false;
|
|
|
|
|
|
2010-06-24 11:40:22 +02:00
|
|
|
MaemoDeployable &deployable = m_deployables[index.row()];
|
2010-06-29 14:10:01 +02:00
|
|
|
const QString &newRemoteDir = value.toString();
|
2010-07-06 12:04:53 +02:00
|
|
|
if (!m_proFileWrapper->replaceInstallPath(deployable.remoteDir,
|
2010-06-30 14:44:41 +02:00
|
|
|
deployable.localFilePath, newRemoteDir)) {
|
|
|
|
|
qWarning("Error: Could not update .pro file");
|
2010-06-16 08:57:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deployable.remoteDir = newRemoteDir;
|
2010-05-04 11:38:03 +02:00
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
return true;
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
QVariant MaemoDeployableListModel::headerData(int section,
|
2010-04-26 14:10:26 +02:00
|
|
|
Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
|
|
|
|
|
return QVariant();
|
2010-06-07 17:13:11 +02:00
|
|
|
return section == 0 ? tr("Local File Path") : tr("Remote Directory");
|
2010-04-26 14:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
QString MaemoDeployableListModel::localExecutableFilePath() const
|
|
|
|
|
{
|
2010-07-07 14:50:37 +02:00
|
|
|
const TargetInformation &ti = m_proFileNode->targetInformation();
|
|
|
|
|
if (!ti.valid)
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
const bool isLib = m_proFileNode->projectType() == LibraryTemplate;
|
|
|
|
|
bool isStatic;
|
|
|
|
|
QString fileName;
|
|
|
|
|
if (isLib) {
|
|
|
|
|
fileName += QLatin1String("lib");
|
|
|
|
|
const QStringList &config
|
|
|
|
|
= m_proFileWrapper->varValues(QLatin1String("CONFIG"));
|
|
|
|
|
isStatic = config.contains(QLatin1String("static"))
|
|
|
|
|
|| config.contains(QLatin1String("staticlib"))
|
|
|
|
|
|| config.contains(QLatin1String("plugin"));
|
|
|
|
|
}
|
|
|
|
|
fileName += ti.target;
|
|
|
|
|
if (isLib)
|
|
|
|
|
fileName += QLatin1String(isStatic ? ".a" : ".so");
|
2010-08-09 16:42:20 +02:00
|
|
|
return QDir::cleanPath(ti.buildDir + '/' + fileName);
|
2010-07-06 12:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoDeployableListModel::remoteExecutableFilePath() const
|
2010-06-16 08:57:13 +02:00
|
|
|
{
|
2010-07-07 14:50:37 +02:00
|
|
|
return deployableAt(0).remoteDir + '/'
|
|
|
|
|
+ QFileInfo(localExecutableFilePath()).fileName();
|
2010-06-16 08:57:13 +02:00
|
|
|
}
|
2010-05-31 12:28:02 +02:00
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
QString MaemoDeployableListModel::projectName() const
|
|
|
|
|
{
|
2010-07-07 14:50:37 +02:00
|
|
|
return m_proFileNode->displayName();
|
2010-07-06 12:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoDeployableListModel::projectDir() const
|
|
|
|
|
{
|
2010-07-08 12:17:54 +02:00
|
|
|
return QFileInfo(m_proFileNode->path()).dir().path();
|
2010-07-06 12:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:02:31 +02:00
|
|
|
} // namespace Qt4ProjectManager
|
|
|
|
|
} // namespace Internal
|