Maemo: Make package contents user-editable.

Reviewed-by: kh1
This commit is contained in:
ck
2010-05-03 14:47:40 +02:00
parent 7a8cf80976
commit 7140288c40
7 changed files with 261 additions and 45 deletions

View File

@@ -50,6 +50,27 @@ MaemoPackageContents::Deployable MaemoPackageContents::deployableAt(int row) con
: m_deployables.at(row - 1); : 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 int MaemoPackageContents::rowCount(const QModelIndex &parent) const
{ {
return parent.isValid() ? 0 : m_deployables.count() + 1; return parent.isValid() ? 0 : m_deployables.count() + 1;

View File

@@ -47,15 +47,24 @@ public:
{ {
Deployable(const QString &localFilePath, const QString &remoteFilePath) Deployable(const QString &localFilePath, const QString &remoteFilePath)
: localFilePath(localFilePath), remoteFilePath(remoteFilePath) {} : localFilePath(localFilePath), remoteFilePath(remoteFilePath) {}
bool operator==(const Deployable &other) const
{
return localFilePath == other.localFilePath
&& remoteFilePath == other.remoteFilePath;
}
QString localFilePath; QString localFilePath;
QString remoteFilePath; QString remoteFilePath;
}; };
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
MaemoPackageContents(MaemoPackageCreationStep *packageStep); MaemoPackageContents(MaemoPackageCreationStep *packageStep);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
Deployable deployableAt(int row) const; Deployable deployableAt(int row) const;
bool addDeployable(const Deployable &deployable);
void removeDeployableAt(int row);
bool isModified() const { return m_modified; } bool isModified() const { return m_modified; }
void setUnModified() { m_modified = false; } void setUnModified() { m_modified = false; }

View File

@@ -123,8 +123,8 @@ bool MaemoPackageCreationStep::createPackage()
env.insert(key, path % QLatin1String("madbin") % colon % env.value(key)); env.insert(key, path % QLatin1String("madbin") % colon % env.value(key));
env.insert(QLatin1String("PERL5LIB"), path % QLatin1String("madlib/perl5")); env.insert(QLatin1String("PERL5LIB"), path % QLatin1String("madlib/perl5"));
const QString projectDir = QFileInfo(localExecutableFilePath()).absolutePath(); const QString buildDir = QFileInfo(localExecutableFilePath()).absolutePath();
env.insert(QLatin1String("PWD"), projectDir); env.insert(QLatin1String("PWD"), buildDir);
const QRegExp envPattern(QLatin1String("([^=]+)=[\"']?([^;\"']+)[\"']? ;.*")); const QRegExp envPattern(QLatin1String("([^=]+)=[\"']?([^;\"']+)[\"']? ;.*"));
QByteArray line; QByteArray line;
@@ -136,14 +136,14 @@ bool MaemoPackageCreationStep::createPackage()
QProcess buildProc; QProcess buildProc;
buildProc.setProcessEnvironment(env); 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 ") const QString command = QLatin1String("dh_make -s -n -p ")
% executableFileName().toLower() % versionString(); % executableFileName().toLower() % versionString();
if (!runCommand(buildProc, command)) if (!runCommand(buildProc, command))
return false; return false;
QFile rulesFile(projectDir + QLatin1String("/debian/rules")); QFile rulesFile(buildDir + QLatin1String("/debian/rules"));
if (!rulesFile.open(QIODevice::ReadWrite)) { if (!rulesFile.open(QIODevice::ReadWrite)) {
raiseError(tr("Packaging Error: Cannot open file '%1'.") raiseError(tr("Packaging Error: Cannot open file '%1'.")
.arg(nativePath(rulesFile))); .arg(nativePath(rulesFile)));
@@ -164,21 +164,33 @@ bool MaemoPackageCreationStep::createPackage()
if (!runCommand(buildProc, QLatin1String("dh_installdirs"))) if (!runCommand(buildProc, QLatin1String("dh_installdirs")))
return false; return false;
const QString targetFile(projectDir % QLatin1String("/debian/") const QDir debianRoot = QDir(buildDir % QLatin1String("/debian/")
% executableFileName().toLower() % remoteExecutableFilePath()); % executableFileName().toLower());
if (QFile::exists(targetFile)) { for (int i = 0; i < m_packageContents->rowCount(); ++i) {
if (!QFile::remove(targetFile)) { 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'.") raiseError(tr("Packaging Error: Could not replace file '%1'.")
.arg(QDir::toNativeSeparators(targetFile))); .arg(QDir::toNativeSeparators(targetFile)));
return false; return false;
} }
}
if (!QFile::copy(localExecutableFilePath(), targetFile)) { if (!QFile::copy(d.localFilePath, targetFile)) {
raiseError(tr("Packaging Error: Could not copy '%1' to '%2'.") raiseError(tr("Packaging Error: Could not copy '%1' to '%2'.")
.arg(QDir::toNativeSeparators(localExecutableFilePath())) .arg(QDir::toNativeSeparators(d.localFilePath))
.arg(QDir::toNativeSeparators(targetFile))); .arg(QDir::toNativeSeparators(targetFile)));
return false; return false;
} }
}
const QStringList commands = QStringList() << QLatin1String("dh_link") const QStringList commands = QStringList() << QLatin1String("dh_link")
<< QLatin1String("dh_fixperms") << QLatin1String("dh_installdeb") << QLatin1String("dh_fixperms") << QLatin1String("dh_installdeb")
@@ -280,7 +292,7 @@ QString MaemoPackageCreationStep::packageFilePath() const
QString MaemoPackageCreationStep::remoteExecutableFilePath() const QString MaemoPackageCreationStep::remoteExecutableFilePath() const
{ {
return QLatin1String("/usr/bin/") % executableFileName(); return QLatin1String("/usr/local/bin/") % executableFileName();
} }
QString MaemoPackageCreationStep::versionString() const QString MaemoPackageCreationStep::versionString() const

View File

@@ -44,6 +44,16 @@
#include "maemopackagecontents.h" #include "maemopackagecontents.h"
#include "maemopackagecreationstep.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 Qt4ProjectManager {
namespace Internal { namespace Internal {
@@ -60,8 +70,12 @@ MaemoPackageCreationWidget::MaemoPackageCreationWidget(MaemoPackageCreationStep
m_ui->packageContentsView, SLOT(resizeColumnsToContents())); m_ui->packageContentsView, SLOT(resizeColumnsToContents()));
connect(step->packageContents(), SIGNAL(rowsInserted(QModelIndex, int, int)), connect(step->packageContents(), SIGNAL(rowsInserted(QModelIndex, int, int)),
m_ui->packageContentsView, SLOT(resizeColumnsToContents())); m_ui->packageContentsView, SLOT(resizeColumnsToContents()));
connect(m_ui->packageContentsView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,
SLOT(enableOrDisableRemoveButton()));
m_ui->packageContentsView->resizeColumnsToContents(); m_ui->packageContentsView->resizeColumnsToContents();
m_ui->packageContentsView->horizontalHeader()->setStretchLastSection(true); m_ui->packageContentsView->horizontalHeader()->setStretchLastSection(true);
enableOrDisableRemoveButton();
} }
void MaemoPackageCreationWidget::init() void MaemoPackageCreationWidget::init()
@@ -78,5 +92,68 @@ QString MaemoPackageCreationWidget::displayName() const
return m_step->displayName(); 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 Internal
} // namespace Qt4ProjectManager } // namespace Qt4ProjectManager

View File

@@ -62,6 +62,12 @@ public:
virtual void init(); virtual void init();
virtual QString summaryText() const; virtual QString summaryText() const;
virtual QString displayName() const; virtual QString displayName() const;
private slots:
void addFile();
void removeFile();
void enableOrDisableRemoveButton();
private: private:
MaemoPackageCreationStep * const m_step; MaemoPackageCreationStep * const m_step;
Ui::MaemoPackageCreationWidget * const m_ui; Ui::MaemoPackageCreationWidget * const m_ui;

View File

@@ -16,7 +16,7 @@
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QLabel" name="contentsLabel"> <widget class="QLabel" name="contentsLabel">
<property name="font"> <property name="font">
@@ -30,6 +30,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QTableView" name="packageContentsView"> <widget class="QTableView" name="packageContentsView">
<property name="sizePolicy"> <property name="sizePolicy">
@@ -38,6 +40,9 @@
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior"> <property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum> <enum>QAbstractItemView::SelectRows</enum>
</property> </property>
@@ -55,8 +60,94 @@
</attribute> </attribute>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<resources/> <resources>
<connections/> <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> </ui>

View File

@@ -327,7 +327,7 @@ const QString AbstractMaemoRunControl::targetCmdLinePrefix() const
const QString &installPrefix = m_needsInstall const QString &installPrefix = m_needsInstall
? remoteInstallCommand() + QLatin1String(" && ") ? remoteInstallCommand() + QLatin1String(" && ")
: QString(); : QString();
return QString::fromLocal8Bit("%1%2 chmod u+x %3 && source /etc/profile && ") return QString::fromLocal8Bit("%1%2 chmod a+x %3 && source /etc/profile && ")
.arg(installPrefix).arg(remoteSudo()).arg(executableFilePathOnTarget()); .arg(installPrefix).arg(remoteSudo()).arg(executableFilePathOnTarget());
} }