add/unify i/o error handling

lots of use of Utils::FileSaver and Utils::FileReader

Task-number: QTCREATORBUG-1619
This commit is contained in:
Oswald Buddenhagen
2011-03-30 15:15:15 +02:00
parent fae7dc9584
commit 45c9cf7a12
70 changed files with 632 additions and 710 deletions

View File

@@ -41,6 +41,8 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/fileutils.h>
#include <QtCore/QSettings>
#include <QtCore/QDebug>
#include <QtCore/QFile>
@@ -301,25 +303,18 @@ void CppFileSettingsWidget::setSettings(const CppFileSettings &s)
void CppFileSettingsWidget::slotEdit()
{
QString path = licenseTemplatePath();
// Edit existing file with C++
if (!path.isEmpty()) {
Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID),
Core::EditorManager::ModeSwitch);
return;
if (path.isEmpty()) {
// Pick a file name and write new template, edit with C++
path = QFileDialog::getSaveFileName(this, tr("Choose Location for New License Template File"));
if (path.isEmpty())
return;
Utils::FileSaver saver(path, QIODevice::Text);
saver.write(tr(licenseTemplateTemplate).toUtf8());
if (!saver.finalize(this))
return;
setLicenseTemplatePath(path);
}
// Pick a file name and write new template, edit with C++
path = QFileDialog::getSaveFileName(this, tr("Choose Location for New License Template File"));
if (path.isEmpty())
return;
QFile file(path);
if (!file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate)) {
QMessageBox::warning(this, tr("Template write error"),
tr("Cannot write to %1: %2").arg(path, file.errorString()));
return;
}
file.write(tr(licenseTemplateTemplate).toUtf8());
file.close();
setLicenseTemplatePath(path);
// Edit (now) existing file with C++
Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID),
Core::EditorManager::ModeSwitch);
}

View File

@@ -38,6 +38,7 @@
#include <find/searchresultwindow.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/filesearch.h>
#include <utils/fileutils.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/progressmanager/futureprogress.h>
#include <coreplugin/editormanager/editormanager.h>
@@ -76,11 +77,11 @@ static QString getSource(const QString &fileName,
if (workingCopy.contains(fileName)) {
return workingCopy.source(fileName);
} else {
QFile file(fileName);
if (! file.open(QFile::ReadOnly))
Utils::FileReader reader;
if (!reader.fetch(fileName)) // ### FIXME error reporting
return QString();
return QTextStream(&file).readAll(); // ### FIXME
return QString::fromLocal8Bit(reader.data()); // ### FIXME encoding
}
}