Commit c734a818 authored by ck's avatar ck
Browse files

Maemo: Make remote path field editable in package widget.

Reviewed-by: kh1
parent 2be1f9c6
......@@ -30,6 +30,12 @@
#include "maemopackagecontents.h"
#include "maemopackagecreationstep.h"
#include "maemotoolchain.h"
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
namespace {
const char * const MODIFIED_KEY
......@@ -63,7 +69,7 @@ MaemoPackageContents::Deployable MaemoPackageContents::deployableAt(int row) con
bool MaemoPackageContents::addDeployable(const Deployable &deployable)
{
if (m_deployables.contains(deployable))
if (m_deployables.contains(deployable) || deployableAt(0) == deployable)
return false;
beginInsertRows(QModelIndex(), rowCount(), rowCount());
......@@ -77,7 +83,7 @@ void MaemoPackageContents::removeDeployableAt(int row)
{
Q_ASSERT(row > 0 && row < rowCount());
beginRemoveRows(QModelIndex(), row, row);
m_deployables.removeAt(row);
m_deployables.removeAt(row - 1);
endRemoveRows();
m_modified = true;
}
......@@ -94,12 +100,40 @@ int MaemoPackageContents::columnCount(const QModelIndex &parent) const
QVariant MaemoPackageContents::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || role != Qt::DisplayRole
|| index.row() >= rowCount())
if (!index.isValid() || index.row() >= rowCount())
return QVariant();
const Deployable &d = deployableAt(index.row());
return index.column() == 0 ? d.localFilePath : d.remoteFilePath;
if (index.column() == 0 && role == Qt::DisplayRole)
return d.localFilePath;
if (role == Qt::DisplayRole || role == Qt::EditRole)
return d.remoteFilePath;
return QVariant();
}
Qt::ItemFlags MaemoPackageContents::flags(const QModelIndex &index) const
{
Qt::ItemFlags parentFlags = QAbstractTableModel::flags(index);
if (index.column() == 1)
return parentFlags | Qt::ItemIsEditable;
return parentFlags;
}
bool MaemoPackageContents::setData(const QModelIndex &index,
const QVariant &value, int role)
{
if (!index.isValid() || index.row() >= rowCount() || index.column() != 1
|| role != Qt::EditRole)
return false;
const QString &remoteFilePath = value.toString();
if (index.row() == 0)
m_remoteExecutableFilePath = remoteFilePath;
else
m_deployables[index.row() - 1].remoteFilePath = remoteFilePath;
m_modified = true;
emit dataChanged(index, index);
return true;
}
QVariant MaemoPackageContents::headerData(int section,
......
......@@ -79,9 +79,9 @@ private:
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
// TODO: setData
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole);
private:
const MaemoPackageCreationStep * const m_packageStep;
......
......@@ -97,42 +97,23 @@ void MaemoPackageCreationWidget::addFile()
const Qt4BuildConfiguration * const bc
= static_cast<Qt4BuildConfiguration *>(m_step->buildConfiguration());
QTC_ASSERT(bc, return);
QString title = tr("Choose a local file");
QString baseDir = bc->target()->project()->projectDirectory();
const QString title = tr("Choose a local file");
const QString baseDir = bc->target()->project()->projectDirectory();
const QString localFile = QFileDialog::getOpenFileName(this, title, baseDir);
if (localFile.isEmpty())
return;
title = tr("Choose a remote file path");
QTC_ASSERT(bc->toolChainType() == ProjectExplorer::ToolChain::GCC_MAEMO, return);
baseDir = static_cast<MaemoToolChain *>(bc->toolChain())->sysrootRoot();
QString remoteFile;
const QString canonicalSysRoot = QFileInfo(baseDir).canonicalFilePath();
do {
QFileDialog d(this, title, baseDir);
d.setFileMode(QFileDialog::AnyFile);
d.selectFile(QFileInfo(localFile).fileName());
if (!d.exec())
return;
remoteFile = d.selectedFiles().first();
if (remoteFile.isEmpty())
return;
const QFileInfo remoteFileInfo(remoteFile);
QString remoteDir = remoteFileInfo.dir().canonicalPath();
if (!remoteDir.startsWith(canonicalSysRoot)) {
QMessageBox::warning(this, tr("Invalid path"),
tr("Please choose a location inside your sysroot directory."));
remoteFile.clear();
} else {
remoteDir.remove(canonicalSysRoot);
remoteFile = remoteDir + '/' + remoteFileInfo.fileName();
}
} while (remoteFile.isEmpty());
const MaemoPackageContents::Deployable
deployable(QFileInfo(localFile).absoluteFilePath(), remoteFile);
if (!m_step->packageContents()->addDeployable(deployable)) {
deployable(QFileInfo(localFile).absoluteFilePath(), "/");
MaemoPackageContents * const contents = m_step->packageContents();
if (!contents->addDeployable(deployable)) {
QMessageBox::information(this, tr("File already in package"),
tr("You have already added this file."));
} else {
const QModelIndex newIndex
= contents->index(contents->rowCount() - 1, 1);
m_ui->packageContentsView->selectionModel()->clear();
m_ui->packageContentsView->scrollTo(newIndex);
m_ui->packageContentsView->edit(newIndex);
}
}
......
......@@ -40,6 +40,12 @@
<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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment