diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp index 9b9d5df6b72..99e4e4b6303 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp @@ -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; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h index 00daf8dcfec..8dd0728e6ce 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h @@ -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; } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp index b873f66b7e6..e99a708e644 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp @@ -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 diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp index 97cc1057cc6..7dd0d2fd4f4 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp @@ -44,6 +44,16 @@ #include "maemopackagecontents.h" #include "maemopackagecreationstep.h" +#include "maemotoolchain.h" + +#include +#include +#include +#include + +#include +#include +#include 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(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(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 diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.h b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.h index 9b01b1fa298..3c8d10d79c1 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.h @@ -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; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui index 024b4333c95..ef741e38156 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui @@ -16,7 +16,7 @@ 1 - + @@ -31,32 +31,123 @@ - - - - 1 - 1 - - - - QAbstractItemView::SelectRows - - - false - - - true - - - false - - - false - - + + + + + + 1 + 1 + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + true + + + false + + + false + + + + + + + + + Add File to Package + + + + + + + :/core/images/plus.png:/core/images/plus.png + + + + + + + Remove File from Package + + + + + + + :/core/images/minus.png:/core/images/minus.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + - - + + + + + + addFileButton + clicked() + MaemoPackageCreationWidget + addFile() + + + 712 + 44 + + + 732 + 525 + + + + + removeFileButton + clicked() + MaemoPackageCreationWidget + removeFile() + + + 723 + 77 + + + 735 + 145 + + + + + + addFile() + removeFile() +