forked from qt-creator/qt-creator
Maemo: Implement on-demand adding of desktop files.
Task-number: QTCREATORBUG-2704
This commit is contained in:
@@ -199,7 +199,9 @@ bool MaemoDeployableListModel::setData(const QModelIndex &index,
|
|||||||
if (!isEditable(index) || role != Qt::EditRole)
|
if (!isEditable(index) || role != Qt::EditRole)
|
||||||
return false;
|
return false;
|
||||||
const QString &remoteDir = value.toString();
|
const QString &remoteDir = value.toString();
|
||||||
if (!addTargetPath(remoteDir))
|
if (!addLinesToProFile(QStringList()
|
||||||
|
<< QString::fromLocal8Bit("target.path = %1").arg(remoteDir)
|
||||||
|
<< QLatin1String("INSTALLS += target")))
|
||||||
return false;
|
return false;
|
||||||
m_deployables.first().remoteDir = remoteDir;
|
m_deployables.first().remoteDir = remoteDir;
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
@@ -262,13 +264,97 @@ bool MaemoDeployableListModel::isEditable(const QModelIndex &index) const
|
|||||||
&& m_deployables.first().remoteDir.isEmpty();
|
&& m_deployables.first().remoteDir.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaemoDeployableListModel::addTargetPath(const QString &remoteDir)
|
bool MaemoDeployableListModel::canAddDesktopFile() const
|
||||||
|
{
|
||||||
|
if (m_projectType == LibraryTemplate)
|
||||||
|
return false;
|
||||||
|
foreach (const MaemoDeployable &d, m_deployables) {
|
||||||
|
if (QFileInfo(d.localFilePath).fileName() == m_projectName + QLatin1String(".desktop"))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MaemoDeployableListModel::addDesktopFile(QString &error)
|
||||||
|
{
|
||||||
|
if (!canAddDesktopFile())
|
||||||
|
return true;
|
||||||
|
const QString desktopFilePath = QFileInfo(m_proFilePath).path()
|
||||||
|
+ QLatin1Char('/') + m_projectName + QLatin1String(".desktop");
|
||||||
|
QFile desktopFile(desktopFilePath);
|
||||||
|
const bool existsAlready = desktopFile.exists();
|
||||||
|
if (!desktopFile.open(QIODevice::ReadWrite)) {
|
||||||
|
error = tr("Failed to open '%1': %2")
|
||||||
|
.arg(desktopFilePath, desktopFile.errorString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QByteArray desktopTemplate("[Desktop Entry]\nEncoding=UTF-8\n"
|
||||||
|
"Version=1.0\nType=Application\nTerminal=false\nName=%1\nExec=%2\n"
|
||||||
|
"Icon=%1\nX-Window-Icon=\nX-HildonDesk-ShowInToolbar=true\n"
|
||||||
|
"X-Osso-Type=application/x-executable\n");
|
||||||
|
const QString contents = existsAlready
|
||||||
|
? QString::fromUtf8(desktopFile.readAll())
|
||||||
|
: QString::fromLocal8Bit(desktopTemplate)
|
||||||
|
.arg(m_projectName, remoteExecutableFilePath());
|
||||||
|
desktopFile.resize(0);
|
||||||
|
const QByteArray &contentsAsByteArray = contents.toUtf8();
|
||||||
|
if (desktopFile.write(contentsAsByteArray) != contentsAsByteArray.count()
|
||||||
|
|| !desktopFile.flush()) {
|
||||||
|
error = tr("Could not write '%1': %2")
|
||||||
|
.arg(desktopFilePath, desktopFile.errorString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MaemoToolChain *const tc = maemoToolchain();
|
||||||
|
QTC_ASSERT(tc, return false);
|
||||||
|
QString remoteDir = QLatin1String("/usr/share/applications");
|
||||||
|
if (tc->version() == MaemoToolChain::Maemo5)
|
||||||
|
remoteDir += QLatin1String("/hildon");
|
||||||
|
const QLatin1String filesLine("desktopfile.files = $${TARGET}.desktop");
|
||||||
|
const QString pathLine = QLatin1String("desktopfile.path = ") + remoteDir;
|
||||||
|
const QLatin1String installsLine("INSTALLS += desktopfile");
|
||||||
|
if (!addLinesToProFile(QStringList() << filesLine << pathLine
|
||||||
|
<< installsLine)) {
|
||||||
|
error = tr("Error writing project file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
|
m_deployables << MaemoDeployable(desktopFilePath, remoteDir);
|
||||||
|
endInsertRows();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MaemoDeployableListModel::addLinesToProFile(const QStringList &lines)
|
||||||
{
|
{
|
||||||
QFile projectFile(m_proFilePath);
|
QFile projectFile(m_proFilePath);
|
||||||
if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||||||
qWarning("Error opening .pro file for writing.");
|
qWarning("Error opening .pro file for writing.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
QString proFileScope;
|
||||||
|
const MaemoToolChain *const tc = maemoToolchain();
|
||||||
|
QTC_ASSERT(tc, return false);
|
||||||
|
if (tc->version() == MaemoToolChain::Maemo5)
|
||||||
|
proFileScope = QLatin1String("maemo5");
|
||||||
|
else
|
||||||
|
proFileScope = QLatin1String("unix:!symbian:!maemo5");
|
||||||
|
const QLatin1String separator("\n ");
|
||||||
|
const QString proFileString = QString(QLatin1Char('\n') + proFileScope
|
||||||
|
+ QLatin1String(" {") + separator + lines.join(separator)
|
||||||
|
+ QLatin1String("\n}\n"));
|
||||||
|
const QByteArray &proFileByteArray = proFileString.toLocal8Bit();
|
||||||
|
if (projectFile.write(proFileByteArray) != proFileByteArray.count()
|
||||||
|
|| !projectFile.flush()) {
|
||||||
|
qWarning("Error updating .pro file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MaemoToolChain *MaemoDeployableListModel::maemoToolchain() const
|
||||||
|
{
|
||||||
const ProjectExplorer::Project *const activeProject
|
const ProjectExplorer::Project *const activeProject
|
||||||
= ProjectExplorer::ProjectExplorerPlugin::instance()->session()->startupProject();
|
= ProjectExplorer::ProjectExplorerPlugin::instance()->session()->startupProject();
|
||||||
QTC_ASSERT(activeProject, return false);
|
QTC_ASSERT(activeProject, return false);
|
||||||
@@ -281,20 +367,7 @@ bool MaemoDeployableListModel::addTargetPath(const QString &remoteDir)
|
|||||||
const MaemoToolChain *const tc
|
const MaemoToolChain *const tc
|
||||||
= dynamic_cast<MaemoToolChain *>(bc->toolChain());
|
= dynamic_cast<MaemoToolChain *>(bc->toolChain());
|
||||||
QTC_ASSERT(tc, return false);
|
QTC_ASSERT(tc, return false);
|
||||||
QString proFileScope;
|
return tc;
|
||||||
if (tc->version() == MaemoToolChain::Maemo5)
|
|
||||||
proFileScope = QLatin1String("maemo5");
|
|
||||||
else
|
|
||||||
proFileScope = QLatin1String("unix:!symbian:!maemo5");
|
|
||||||
const QString proFileString = QString(QLatin1Char('\n') + proFileScope
|
|
||||||
+ QLatin1String(" {\n target.path = %1\n INSTALLS += target\n}\n"))
|
|
||||||
.arg(remoteDir);
|
|
||||||
if (!projectFile.write(proFileString.toLocal8Bit())
|
|
||||||
|| !projectFile.flush()) {
|
|
||||||
qWarning("Error updating .pro file.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Qt4ProjectManager
|
} // namespace Qt4ProjectManager
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ QT_END_NAMESPACE
|
|||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class MaemoProFileWrapper;
|
class MaemoProFileWrapper;
|
||||||
|
class MaemoToolChain;
|
||||||
|
|
||||||
class MaemoDeployableListModel : public QAbstractTableModel
|
class MaemoDeployableListModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
@@ -75,6 +76,8 @@ public:
|
|||||||
QString projectDir() const;
|
QString projectDir() const;
|
||||||
QString proFilePath() const { return m_proFilePath; }
|
QString proFilePath() const { return m_proFilePath; }
|
||||||
bool hasTargetPath() const { return m_hasTargetPath; }
|
bool hasTargetPath() const { return m_hasTargetPath; }
|
||||||
|
bool canAddDesktopFile() const;
|
||||||
|
bool addDesktopFile(QString &error);
|
||||||
ProFileUpdateSetting proFileUpdateSetting() const {
|
ProFileUpdateSetting proFileUpdateSetting() const {
|
||||||
return m_proFileUpdateSetting;
|
return m_proFileUpdateSetting;
|
||||||
}
|
}
|
||||||
@@ -92,7 +95,8 @@ private:
|
|||||||
|
|
||||||
bool isEditable(const QModelIndex &index) const;
|
bool isEditable(const QModelIndex &index) const;
|
||||||
bool buildModel();
|
bool buildModel();
|
||||||
bool addTargetPath(const QString &remoteDir);
|
bool addLinesToProFile(const QStringList &lines);
|
||||||
|
const MaemoToolChain *maemoToolchain() const;
|
||||||
|
|
||||||
const Qt4ProjectType m_projectType;
|
const Qt4ProjectType m_projectType;
|
||||||
const QString m_proFilePath;
|
const QString m_proFilePath;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -32,6 +34,8 @@ MaemoDeployStepWidget::MaemoDeployStepWidget(MaemoDeployStep *step) :
|
|||||||
|
|
||||||
connect(ui->modelComboBox, SIGNAL(currentIndexChanged(int)),
|
connect(ui->modelComboBox, SIGNAL(currentIndexChanged(int)),
|
||||||
SLOT(setModel(int)));
|
SLOT(setModel(int)));
|
||||||
|
connect(ui->addDesktopFileButton, SIGNAL(clicked()),
|
||||||
|
SLOT(addDesktopFile()));
|
||||||
handleModelListReset();
|
handleModelListReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +104,7 @@ void MaemoDeployStepWidget::handleModelListToBeReset()
|
|||||||
{
|
{
|
||||||
ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
|
ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
|
||||||
ui->tableView->setModel(0);
|
ui->tableView->setModel(0);
|
||||||
|
ui->addDesktopFileButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoDeployStepWidget::handleModelListReset()
|
void MaemoDeployStepWidget::handleModelListReset()
|
||||||
@@ -115,10 +120,31 @@ void MaemoDeployStepWidget::handleModelListReset()
|
|||||||
|
|
||||||
void MaemoDeployStepWidget::setModel(int row)
|
void MaemoDeployStepWidget::setModel(int row)
|
||||||
{
|
{
|
||||||
|
bool canAddDesktopFile = false;
|
||||||
if (row != -1) {
|
if (row != -1) {
|
||||||
ui->tableView->setModel(m_step->deployables()->modelAt(row));
|
MaemoDeployableListModel *const model
|
||||||
|
= m_step->deployables()->modelAt(row);
|
||||||
|
ui->tableView->setModel(model);
|
||||||
ui->tableView->resizeRowsToContents();
|
ui->tableView->resizeRowsToContents();
|
||||||
|
canAddDesktopFile = model->canAddDesktopFile();
|
||||||
}
|
}
|
||||||
|
ui->addDesktopFileButton->setEnabled(canAddDesktopFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MaemoDeployStepWidget::addDesktopFile()
|
||||||
|
{
|
||||||
|
const int modelRow = ui->modelComboBox->currentIndex();
|
||||||
|
if (modelRow == -1)
|
||||||
|
return;
|
||||||
|
MaemoDeployableListModel *const model
|
||||||
|
= m_step->deployables()->modelAt(modelRow);
|
||||||
|
QString error;
|
||||||
|
if (!model->addDesktopFile(error)) {
|
||||||
|
QMessageBox::warning(this, tr("Could not create desktop file"),
|
||||||
|
tr("Error creating desktop file: %1").arg(error));
|
||||||
|
}
|
||||||
|
ui->addDesktopFileButton->setEnabled(model->canAddDesktopFile());
|
||||||
|
ui->tableView->resizeRowsToContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ private:
|
|||||||
Q_SLOT void setModel(int row);
|
Q_SLOT void setModel(int row);
|
||||||
Q_SLOT void handleModelListToBeReset();
|
Q_SLOT void handleModelListToBeReset();
|
||||||
Q_SLOT void handleModelListReset();
|
Q_SLOT void handleModelListReset();
|
||||||
|
Q_SLOT void addDesktopFile();
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
virtual QString summaryText() const;
|
virtual QString summaryText() const;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
@@ -106,6 +106,8 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="tableView">
|
<widget class="QTableView" name="tableView">
|
||||||
<property name="showGrid">
|
<property name="showGrid">
|
||||||
@@ -128,6 +130,32 @@
|
|||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="addDesktopFileButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add Desktop File</string>
|
||||||
|
</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/>
|
||||||
|
|||||||
Reference in New Issue
Block a user