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-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-10-11 15:40:25 +02:00
|
|
|
const QSharedPointer<ProFileOption> &proFileOption,
|
|
|
|
|
ProFileUpdateSetting updateSetting, QObject *parent)
|
2010-07-07 16:49:39 +02:00
|
|
|
: QAbstractTableModel(parent),
|
2010-10-11 16:43:28 +02:00
|
|
|
m_projectType(proFileNode->projectType()),
|
|
|
|
|
m_proFilePath(proFileNode->path()),
|
|
|
|
|
m_projectName(proFileNode->displayName()),
|
|
|
|
|
m_targetInfo(proFileNode->targetInformation()),
|
2010-07-07 16:49:39 +02:00
|
|
|
m_modified(false),
|
2010-10-11 16:43:28 +02:00
|
|
|
m_proFileWrapper(new MaemoProFileWrapper(m_proFilePath,
|
|
|
|
|
proFileNode->buildDir(), proFileOption)),
|
|
|
|
|
m_proFileUpdateSetting(updateSetting),
|
|
|
|
|
m_hasTargetPath(false)
|
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-10-11 15:40:25 +02:00
|
|
|
m_hasTargetPath = !installs.targetPath.isEmpty();
|
|
|
|
|
if (!m_hasTargetPath && m_proFileUpdateSetting == UpdateProFile) {
|
2010-09-09 10:36:59 +02:00
|
|
|
const QString remoteDirSuffix
|
2010-10-11 16:43:28 +02:00
|
|
|
= QLatin1String(m_projectType == LibraryTemplate
|
2010-09-09 10:36:59 +02:00
|
|
|
? "/lib" : "/bin");
|
|
|
|
|
const QString remoteDirMaemo5
|
|
|
|
|
= QLatin1String("/opt/usr") + remoteDirSuffix;
|
|
|
|
|
const QString remoteDirMaemo6
|
|
|
|
|
= QLatin1String("/usr/local") + remoteDirSuffix;
|
2010-07-06 12:04:53 +02:00
|
|
|
m_deployables.prepend(MaemoDeployable(localExecutableFilePath(),
|
2010-09-09 10:36:59 +02:00
|
|
|
remoteDirMaemo5));
|
2010-10-11 16:43:28 +02:00
|
|
|
QFile projectFile(m_proFilePath);
|
2010-07-27 17:27:04 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2010-09-09 10:36:59 +02:00
|
|
|
QString proFileTemplate = QLatin1String("\nunix:!symbian {\n"
|
|
|
|
|
" maemo5 {\n target.path = maemo5path\n } else {\n"
|
|
|
|
|
" target.path = maemo6path\n }\n"
|
|
|
|
|
" INSTALLS += target\n}");
|
|
|
|
|
proFileTemplate.replace(QLatin1String("maemo5path"), remoteDirMaemo5);
|
|
|
|
|
proFileTemplate.replace(QLatin1String("maemo6path"), remoteDirMaemo6);
|
|
|
|
|
if (!projectFile.write(proFileTemplate.toLocal8Bit())) {
|
2010-07-27 17:27:04 +02:00
|
|
|
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)
|
2010-10-14 14:05:59 +02:00
|
|
|
return QDir::toNativeSeparators(d.localFilePath);
|
2010-05-04 11:38:03 +02:00
|
|
|
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-10-11 16:43:28 +02:00
|
|
|
if (!m_targetInfo.valid)
|
2010-07-07 14:50:37 +02:00
|
|
|
return QString();
|
|
|
|
|
|
2010-10-11 16:43:28 +02:00
|
|
|
const bool isLib = m_projectType == LibraryTemplate;
|
2010-09-08 16:23:56 +02:00
|
|
|
bool isStatic = false; // Nonsense init for stupid compilers.
|
2010-07-07 14:50:37 +02:00
|
|
|
QString fileName;
|
|
|
|
|
if (isLib) {
|
|
|
|
|
fileName += QLatin1String("lib");
|
|
|
|
|
const QStringList &config
|
|
|
|
|
= m_proFileWrapper->varValues(QLatin1String("CONFIG"));
|
|
|
|
|
isStatic = config.contains(QLatin1String("static"))
|
2010-11-08 14:10:43 +01:00
|
|
|
|| config.contains(QLatin1String("staticlib"));
|
2010-07-07 14:50:37 +02:00
|
|
|
}
|
2010-10-11 16:43:28 +02:00
|
|
|
fileName += m_targetInfo.target;
|
2010-07-07 14:50:37 +02:00
|
|
|
if (isLib)
|
|
|
|
|
fileName += QLatin1String(isStatic ? ".a" : ".so");
|
2010-10-11 16:43:28 +02:00
|
|
|
return QDir::cleanPath(m_targetInfo.workingDir + '/' + fileName);
|
2010-07-06 12:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoDeployableListModel::remoteExecutableFilePath() const
|
2010-06-16 08:57:13 +02:00
|
|
|
{
|
2010-10-11 15:40:25 +02:00
|
|
|
return m_hasTargetPath
|
|
|
|
|
? deployableAt(0).remoteDir + '/'
|
|
|
|
|
+ QFileInfo(localExecutableFilePath()).fileName()
|
|
|
|
|
: QString();
|
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::projectDir() const
|
|
|
|
|
{
|
2010-10-11 16:43:28 +02:00
|
|
|
return QFileInfo(m_proFilePath).dir().path();
|
2010-07-06 12:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 15:40:25 +02:00
|
|
|
void MaemoDeployableListModel::setProFileUpdateSetting(ProFileUpdateSetting updateSetting)
|
|
|
|
|
{
|
|
|
|
|
m_proFileUpdateSetting = updateSetting;
|
|
|
|
|
if (updateSetting == UpdateProFile)
|
|
|
|
|
buildModel();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:02:31 +02:00
|
|
|
} // namespace Qt4ProjectManager
|
|
|
|
|
} // namespace Internal
|