forked from qt-creator/qt-creator
unify i/o error reporting in the model
- use Utils::FileSaver
- as a side effect, don't rewrite the desktop file with the same content
if it already exists
- pop up message boxes on errors - this is likely to be more visible
than qWarning()s/nothing
- this is implemented in a somewhat strange way with the model itself
doing the gui interaction, but that seems to be the simplest
solution given the qt class design
This commit is contained in:
@@ -35,17 +35,20 @@
|
|||||||
#include "maemoglobal.h"
|
#include "maemoglobal.h"
|
||||||
#include "qt4maemotarget.h"
|
#include "qt4maemotarget.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
#include <qt4projectmanager/qt4buildconfiguration.h>
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
||||||
#include <qt4projectmanager/qt4target.h>
|
#include <qt4projectmanager/qt4target.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtGui/QBrush>
|
#include <QtGui/QBrush>
|
||||||
#include <QtGui/QImageReader>
|
#include <QtGui/QImageReader>
|
||||||
|
#include <QtGui/QMainWindow>
|
||||||
|
|
||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -224,35 +227,21 @@ QString MaemoDeployableListModel::localDesktopFilePath() const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaemoDeployableListModel::addDesktopFile(QString &error)
|
bool MaemoDeployableListModel::addDesktopFile()
|
||||||
{
|
{
|
||||||
if (!canAddDesktopFile())
|
if (!canAddDesktopFile())
|
||||||
return true;
|
return true;
|
||||||
const QString desktopFilePath = QFileInfo(m_proFilePath).path()
|
const QString desktopFilePath = QFileInfo(m_proFilePath).path()
|
||||||
+ QLatin1Char('/') + m_projectName + QLatin1String(".desktop");
|
+ QLatin1Char('/') + m_projectName + QLatin1String(".desktop");
|
||||||
MaemoGlobal::FileUpdate update(desktopFilePath);
|
if (!QFile::exists(desktopFilePath)) {
|
||||||
QFile desktopFile(desktopFilePath);
|
const QByteArray desktopTemplate("[Desktop Entry]\nEncoding=UTF-8\n"
|
||||||
const bool existsAlready = desktopFile.exists();
|
"Version=1.0\nType=Application\nTerminal=false\nName=%1\nExec=%2\n"
|
||||||
if (!desktopFile.open(QIODevice::ReadWrite)) {
|
"Icon=%1\nX-Window-Icon=\nX-HildonDesk-ShowInToolbar=true\n"
|
||||||
error = tr("Failed to open '%1': %2")
|
"X-Osso-Type=application/x-executable\n");
|
||||||
.arg(desktopFilePath, desktopFile.errorString());
|
Utils::FileSaver saver(desktopFilePath);
|
||||||
return false;
|
saver.write(QString::fromLatin1(desktopTemplate)
|
||||||
}
|
.arg(m_projectName, remoteExecutableFilePath()).toUtf8());
|
||||||
|
if (!saver.finalize(Core::ICore::instance()->mainWindow()))
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,10 +254,8 @@ bool MaemoDeployableListModel::addDesktopFile(QString &error)
|
|||||||
const QString pathLine = QLatin1String("desktopfile.path = ") + remoteDir;
|
const QString pathLine = QLatin1String("desktopfile.path = ") + remoteDir;
|
||||||
const QLatin1String installsLine("INSTALLS += desktopfile");
|
const QLatin1String installsLine("INSTALLS += desktopfile");
|
||||||
if (!addLinesToProFile(QStringList() << filesLine << pathLine
|
if (!addLinesToProFile(QStringList() << filesLine << pathLine
|
||||||
<< installsLine)) {
|
<< installsLine))
|
||||||
error = tr("Error writing project file.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
m_deployables << MaemoDeployable(desktopFilePath, remoteDir);
|
m_deployables << MaemoDeployable(desktopFilePath, remoteDir);
|
||||||
@@ -276,7 +263,7 @@ bool MaemoDeployableListModel::addDesktopFile(QString &error)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaemoDeployableListModel::addIcon(const QString &fileName, QString &error)
|
bool MaemoDeployableListModel::addIcon(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!canAddIcon())
|
if (!canAddIcon())
|
||||||
return true;
|
return true;
|
||||||
@@ -285,10 +272,8 @@ bool MaemoDeployableListModel::addIcon(const QString &fileName, QString &error)
|
|||||||
const QString pathLine = QLatin1String("icon.path = ") + RemoteIconPath;
|
const QString pathLine = QLatin1String("icon.path = ") + RemoteIconPath;
|
||||||
const QLatin1String installsLine("INSTALLS += icon");
|
const QLatin1String installsLine("INSTALLS += icon");
|
||||||
if (!addLinesToProFile(QStringList() << filesLine << pathLine
|
if (!addLinesToProFile(QStringList() << filesLine << pathLine
|
||||||
<< installsLine)) {
|
<< installsLine))
|
||||||
error = tr("Error writing project file.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
const QString filePath = QFileInfo(m_proFilePath).path()
|
const QString filePath = QFileInfo(m_proFilePath).path()
|
||||||
@@ -316,23 +301,15 @@ QString MaemoDeployableListModel::remoteIconFilePath() const
|
|||||||
|
|
||||||
bool MaemoDeployableListModel::addLinesToProFile(const QStringList &lines)
|
bool MaemoDeployableListModel::addLinesToProFile(const QStringList &lines)
|
||||||
{
|
{
|
||||||
QFile projectFile(m_proFilePath);
|
|
||||||
MaemoGlobal::FileUpdate update(m_proFilePath);
|
MaemoGlobal::FileUpdate update(m_proFilePath);
|
||||||
if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
|
||||||
qWarning("Error opening .pro file for writing.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const QLatin1String separator("\n ");
|
const QLatin1String separator("\n ");
|
||||||
const QString proFileString = QString(QLatin1Char('\n') + proFileScope()
|
const QString proFileString = QString(QLatin1Char('\n') + proFileScope()
|
||||||
+ QLatin1String(" {") + separator + lines.join(separator)
|
+ QLatin1String(" {") + separator + lines.join(separator)
|
||||||
+ QLatin1String("\n}\n"));
|
+ QLatin1String("\n}\n"));
|
||||||
const QByteArray &proFileByteArray = proFileString.toLocal8Bit();
|
Utils::FileSaver saver(m_proFilePath, QIODevice::Append);
|
||||||
if (projectFile.write(proFileByteArray) != proFileByteArray.count()
|
saver.write(proFileString.toLocal8Bit());
|
||||||
|| !projectFile.flush()) {
|
return saver.finalize(Core::ICore::instance()->mainWindow());
|
||||||
qWarning("Error updating .pro file.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QtVersion *MaemoDeployableListModel::qtVersion() const
|
const QtVersion *MaemoDeployableListModel::qtVersion() const
|
||||||
|
|||||||
@@ -75,9 +75,9 @@ public:
|
|||||||
bool canAddDesktopFile() const { return isApplicationProject() && !hasDesktopFile(); }
|
bool canAddDesktopFile() const { return isApplicationProject() && !hasDesktopFile(); }
|
||||||
QString localDesktopFilePath() const;
|
QString localDesktopFilePath() const;
|
||||||
bool hasDesktopFile() const { return !localDesktopFilePath().isEmpty(); }
|
bool hasDesktopFile() const { return !localDesktopFilePath().isEmpty(); }
|
||||||
bool addDesktopFile(QString &error);
|
bool addDesktopFile();
|
||||||
bool canAddIcon() const { return isApplicationProject() && remoteIconFilePath().isEmpty(); }
|
bool canAddIcon() const { return isApplicationProject() && remoteIconFilePath().isEmpty(); }
|
||||||
bool addIcon(const QString &fileName, QString &error);
|
bool addIcon(const QString &fileName);
|
||||||
QString remoteIconFilePath() const;
|
QString remoteIconFilePath() const;
|
||||||
ProFileUpdateSetting proFileUpdateSetting() const {
|
ProFileUpdateSetting proFileUpdateSetting() const {
|
||||||
return m_proFileUpdateSetting;
|
return m_proFileUpdateSetting;
|
||||||
|
|||||||
@@ -120,11 +120,7 @@ void MaemoDeployConfigurationWidget::addDesktopFile()
|
|||||||
return;
|
return;
|
||||||
MaemoDeployableListModel *const model
|
MaemoDeployableListModel *const model
|
||||||
= m_deployConfig->deployables()->modelAt(modelRow);
|
= m_deployConfig->deployables()->modelAt(modelRow);
|
||||||
QString error;
|
model->addDesktopFile();
|
||||||
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->addDesktopFileButton->setEnabled(model->canAddDesktopFile());
|
||||||
ui->tableView->resizeRowsToContents();
|
ui->tableView->resizeRowsToContents();
|
||||||
}
|
}
|
||||||
@@ -161,11 +157,7 @@ void MaemoDeployConfigurationWidget::addIcon()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString error;
|
model->addIcon(newFileName);
|
||||||
if (!model->addIcon(newFileName, error)) {
|
|
||||||
QMessageBox::critical(this, tr("Could Not Add Icon"),
|
|
||||||
tr("Error adding icon: %1").arg(error));
|
|
||||||
}
|
|
||||||
ui->addIconButton->setEnabled(model->canAddIcon());
|
ui->addIconButton->setEnabled(model->canAddIcon());
|
||||||
ui->tableView->resizeRowsToContents();
|
ui->tableView->resizeRowsToContents();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user