aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/colorscheme.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-03-30 15:15:15 +0200
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-04-18 14:10:14 +0200
commit45c9cf7a1298feed925d18596c30ac9c6cd1dac5 (patch)
tree6f484122011b76a5f3a2f1915b7b308b1f5058ea /src/plugins/texteditor/colorscheme.cpp
parentfae7dc9584b4e2f2192f8b7a71c428fcaa2ddb70 (diff)
add/unify i/o error handling
lots of use of Utils::FileSaver and Utils::FileReader Task-number: QTCREATORBUG-1619
Diffstat (limited to 'src/plugins/texteditor/colorscheme.cpp')
-rw-r--r--src/plugins/texteditor/colorscheme.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/plugins/texteditor/colorscheme.cpp b/src/plugins/texteditor/colorscheme.cpp
index 5ba5061b02b..b2179deb35d 100644
--- a/src/plugins/texteditor/colorscheme.cpp
+++ b/src/plugins/texteditor/colorscheme.cpp
@@ -34,6 +34,8 @@
#include "texteditorconstants.h"
+#include <utils/fileutils.h>
+
#include <QtCore/QFile>
#include <QtCore/QCoreApplication>
#include <QtXml/QXmlStreamWriter>
@@ -132,42 +134,42 @@ void ColorScheme::clear()
m_formats.clear();
}
-bool ColorScheme::save(const QString &fileName) const
+bool ColorScheme::save(const QString &fileName, QWidget *parent) const
{
- QFile file(fileName);
- if (!file.open(QIODevice::WriteOnly))
- return false;
+ Utils::FileSaver saver(fileName);
+ if (!saver.hasError()) {
+ QXmlStreamWriter w(saver.file());
+ w.setAutoFormatting(true);
+ w.setAutoFormattingIndent(2);
+
+ w.writeStartDocument();
+ w.writeStartElement(QLatin1String("style-scheme"));
+ w.writeAttribute(QLatin1String("version"), QLatin1String("1.0"));
+ if (!m_displayName.isEmpty())
+ w.writeAttribute(QLatin1String("name"), m_displayName);
+
+ QMapIterator<QString, Format> i(m_formats);
+ while (i.hasNext()) {
+ const Format &format = i.next().value();
+ w.writeStartElement(QLatin1String("style"));
+ w.writeAttribute(QLatin1String("name"), i.key());
+ if (format.foreground().isValid())
+ w.writeAttribute(QLatin1String("foreground"), format.foreground().name().toLower());
+ if (format.background().isValid())
+ w.writeAttribute(QLatin1String("background"), format.background().name().toLower());
+ if (format.bold())
+ w.writeAttribute(QLatin1String("bold"), QLatin1String(trueString));
+ if (format.italic())
+ w.writeAttribute(QLatin1String("italic"), QLatin1String(trueString));
+ w.writeEndElement();
+ }
- QXmlStreamWriter w(&file);
- w.setAutoFormatting(true);
- w.setAutoFormattingIndent(2);
-
- w.writeStartDocument();
- w.writeStartElement(QLatin1String("style-scheme"));
- w.writeAttribute(QLatin1String("version"), QLatin1String("1.0"));
- if (!m_displayName.isEmpty())
- w.writeAttribute(QLatin1String("name"), m_displayName);
-
- QMapIterator<QString, Format> i(m_formats);
- while (i.hasNext()) {
- const Format &format = i.next().value();
- w.writeStartElement(QLatin1String("style"));
- w.writeAttribute(QLatin1String("name"), i.key());
- if (format.foreground().isValid())
- w.writeAttribute(QLatin1String("foreground"), format.foreground().name().toLower());
- if (format.background().isValid())
- w.writeAttribute(QLatin1String("background"), format.background().name().toLower());
- if (format.bold())
- w.writeAttribute(QLatin1String("bold"), QLatin1String(trueString));
- if (format.italic())
- w.writeAttribute(QLatin1String("italic"), QLatin1String(trueString));
w.writeEndElement();
- }
+ w.writeEndDocument();
- w.writeEndElement();
- w.writeEndDocument();
-
- return true;
+ saver.setResult(&w);
+ }
+ return saver.finalize(parent);
}
namespace {