Commit b367cffa authored by ck's avatar ck
Browse files

Maemo: Make package contents user-editable.

Reviewed-by: kh1
parent 2277a82f
......@@ -50,6 +50,27 @@ MaemoPackageContents::Deployable MaemoPackageContents::deployableAt(int row) con
: m_deployables.at(row - 1);
}
bool MaemoPackageContents::addDeployable(const Deployable &deployable)
{
if (m_deployables.contains(deployable))
return false;
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_deployables << deployable;
endInsertRows();
m_modified = true;
return true;
}
void MaemoPackageContents::removeDeployableAt(int row)
{
Q_ASSERT(row > 0 && row < rowCount());
beginRemoveRows(QModelIndex(), row, row);
m_deployables.removeAt(row);
endRemoveRows();
m_modified = true;
}
int MaemoPackageContents::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_deployables.count() + 1;
......
......@@ -47,15 +47,24 @@ public:
{
Deployable(const QString &localFilePath, const QString &remoteFilePath)
: localFilePath(localFilePath), remoteFilePath(remoteFilePath) {}
bool operator==(const Deployable &other) const
{
return localFilePath == other.localFilePath
&& remoteFilePath == other.remoteFilePath;
}
QString localFilePath;
QString remoteFilePath;
};
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
MaemoPackageContents(MaemoPackageCreationStep *packageStep);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
Deployable deployableAt(int row) const;
bool addDeployable(const Deployable &deployable);
void removeDeployableAt(int row);
bool isModified() const { return m_modified; }
void setUnModified() { m_modified = false; }
......
......@@ -123,8 +123,8 @@ bool MaemoPackageCreationStep::createPackage()
env.insert(key, path % QLatin1String("madbin") % colon % env.value(key));
env.insert(QLatin1String("PERL5LIB"), path % QLatin1String("madlib/perl5"));
const QString projectDir = QFileInfo(localExecutableFilePath()).absolutePath();
env.insert(QLatin1String("PWD"), projectDir);
const QString buildDir = QFileInfo(localExecutableFilePath()).absolutePath();
env.insert(QLatin1String("PWD"), buildDir);
const QRegExp envPattern(QLatin1String("([^=]+)=[\"']?([^;\"']+)[\"']? ;.*"));
QByteArray line;
......@@ -136,14 +136,14 @@ bool MaemoPackageCreationStep::createPackage()
QProcess buildProc;
buildProc.setProcessEnvironment(env);
buildProc.setWorkingDirectory(projectDir);
buildProc.setWorkingDirectory(buildDir);
if (!QFileInfo(projectDir + QLatin1String("/debian")).exists()) {
if (!QFileInfo(buildDir + QLatin1String("/debian")).exists()) {
const QString command = QLatin1String("dh_make -s -n -p ")
% executableFileName().toLower() % versionString();
if (!runCommand(buildProc, command))
return false;
QFile rulesFile(projectDir + QLatin1String("/debian/rules"));
QFile rulesFile(buildDir + QLatin1String("/debian/rules"));
if (!rulesFile.open(QIODevice::ReadWrite)) {
raiseError(tr("Packaging Error: Cannot open file '%1'.")
.arg(nativePath(rulesFile)));
......@@ -164,20 +164,32 @@ bool MaemoPackageCreationStep::createPackage()
if (!runCommand(buildProc, QLatin1String("dh_installdirs")))
return false;
const QString targetFile(projectDir % QLatin1String("/debian/")
% executableFileName().toLower() % remoteExecutableFilePath());
if (QFile::exists(targetFile)) {
if (!QFile::remove(targetFile)) {
const QDir debianRoot = QDir(buildDir % QLatin1String("/debian/")
% executableFileName().toLower());
for (int i = 0; i < m_packageContents->rowCount(); ++i) {
const MaemoPackageContents::Deployable &d
= m_packageContents->deployableAt(i);
const QString targetFile = debianRoot.path() + '/' + d.remoteFilePath;
const QString absTargetDir = QFileInfo(targetFile).dir().path();
const QString relTargetDir = debianRoot.relativeFilePath(absTargetDir);
if (!debianRoot.exists(relTargetDir)
&& !debianRoot.mkpath(relTargetDir)) {
raiseError(tr("Packaging Error: Could not create directory '%1'.")
.arg(QDir::toNativeSeparators(absTargetDir)));
return false;
}
if (QFile::exists(targetFile) && !QFile::remove(targetFile)) {
raiseError(tr("Packaging Error: Could not replace file '%1'.")
.arg(QDir::toNativeSeparators(targetFile)));
return false;
}
}
if (!QFile::copy(localExecutableFilePath(), targetFile)) {
raiseError(tr("Packaging Error: Could not copy '%1' to '%2'.")
.arg(QDir::toNativeSeparators(localExecutableFilePath()))
.arg(QDir::toNativeSeparators(targetFile)));
return false;
if (!QFile::copy(d.localFilePath, targetFile)) {
raiseError(tr("Packaging Error: Could not copy '%1' to '%2'.")
.arg(QDir::toNativeSeparators(d.localFilePath))
.arg(QDir::toNativeSeparators(targetFile)));
return false;
}
}
const QStringList commands = QStringList() << QLatin1String("dh_link")
......@@ -280,7 +292,7 @@ QString MaemoPackageCreationStep::packageFilePath() const
QString MaemoPackageCreationStep::remoteExecutableFilePath() const
{
return QLatin1String("/usr/bin/") % executableFileName();
return QLatin1String("/usr/local/bin/") % executableFileName();
}
QString MaemoPackageCreationStep::versionString() const
......
......@@ -44,6 +44,16 @@
#include "maemopackagecontents.h"
#include "maemopackagecreationstep.h"
#include "maemotoolchain.h"
#include <utils/qtcassert.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <QtCore/QFileInfo>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
namespace Qt4ProjectManager {
namespace Internal {
......@@ -60,8 +70,12 @@ MaemoPackageCreationWidget::MaemoPackageCreationWidget(MaemoPackageCreationStep
m_ui->packageContentsView, SLOT(resizeColumnsToContents()));
connect(step->packageContents(), SIGNAL(rowsInserted(QModelIndex, int, int)),
m_ui->packageContentsView, SLOT(resizeColumnsToContents()));
connect(m_ui->packageContentsView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,
SLOT(enableOrDisableRemoveButton()));
m_ui->packageContentsView->resizeColumnsToContents();
m_ui->packageContentsView->horizontalHeader()->setStretchLastSection(true);
enableOrDisableRemoveButton();
}
void MaemoPackageCreationWidget::init()
......@@ -78,5 +92,68 @@ QString MaemoPackageCreationWidget::displayName() const
return m_step->displayName();
}
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 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)) {
QMessageBox::information(this, tr("File already in package"),
tr("You have already added this file."));
}
}
void MaemoPackageCreationWidget::removeFile()
{
const QModelIndexList selectedRows
= m_ui->packageContentsView->selectionModel()->selectedRows();
if (selectedRows.isEmpty())
return;
const int row = selectedRows.first().row();
if (row != 0)
m_step->packageContents()->removeDeployableAt(row);
}
void MaemoPackageCreationWidget::enableOrDisableRemoveButton()
{
const QModelIndexList selectedRows
= m_ui->packageContentsView->selectionModel()->selectedRows();
m_ui->removeFileButton->setEnabled(!selectedRows.isEmpty()
&& selectedRows.first().row() != 0);
}
} // namespace Internal
} // namespace Qt4ProjectManager
......@@ -62,6 +62,12 @@ public:
virtual void init();
virtual QString summaryText() const;
virtual QString displayName() const;
private slots:
void addFile();
void removeFile();
void enableOrDisableRemoveButton();
private:
MaemoPackageCreationStep * const m_step;
Ui::MaemoPackageCreationWidget * const m_ui;
......
......@@ -16,7 +16,7 @@
<verstretch>1</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="contentsLabel">
<property name="font">
......@@ -31,32 +31,123 @@
</widget>
</item>
<item>
<widget class="QTableView" name="packageContentsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableView" name="packageContentsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</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">
<property name="toolTip">
<string>Add File to Package</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../coreplugin/core.qrc">
<normaloff>:/core/images/plus.png</normaloff>:/core/images/plus.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="removeFileButton">
<property name="toolTip">
<string>Remove File from Package</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../coreplugin/core.qrc">
<normaloff>:/core/images/minus.png</normaloff>:/core/images/minus.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
<resources>
<include location="../../coreplugin/core.qrc"/>
</resources>
<connections>
<connection>
<sender>addFileButton</sender>
<signal>clicked()</signal>
<receiver>MaemoPackageCreationWidget</receiver>
<slot>addFile()</slot>
<hints>
<hint type="sourcelabel">
<x>712</x>
<y>44</y>
</hint>
<hint type="destinationlabel">
<x>732</x>
<y>525</y>
</hint>
</hints>
</connection>
<connection>
<sender>removeFileButton</sender>
<signal>clicked()</signal>
<receiver>MaemoPackageCreationWidget</receiver>
<slot>removeFile()</slot>
<hints>
<hint type="sourcelabel">
<x>723</x>
<y>77</y>
</hint>
<hint type="destinationlabel">
<x>735</x>
<y>145</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>addFile()</slot>
<slot>removeFile()</slot>
</slots>
</ui>
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