diff options
Diffstat (limited to 'lib/bookmarks/xbel.cpp')
-rw-r--r-- | lib/bookmarks/xbel.cpp | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/lib/bookmarks/xbel.cpp b/lib/bookmarks/xbel.cpp index 1be9c7e..47d855b 100644 --- a/lib/bookmarks/xbel.cpp +++ b/lib/bookmarks/xbel.cpp @@ -9,37 +9,24 @@ #include "xbel.h" #include <QFile> -Xbel::Xbel(const QString &path) +Xbel::Xbel(QIODevice *file) { - m_path = path; + Q_CHECK_PTR(file); + m_file = file; } bool Xbel::read(BookmarkItem *root) { - // if the path is empty, there is nothing to load - if(m_path.isEmpty()) { - return false; - } - - QFile file(m_path); - if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - // file cannot be opened for reading - return false; - } - - QXmlStreamReader xmlReader(&file); + QXmlStreamReader xmlReader(m_file); if(xmlReader.readNextStartElement()) { if(!(xmlReader.name() == "xbel" && xmlReader.attributes().value("version") == "1.0")) { - // invalid xbel - qWarning("Error parsing %s", qUtf8Printable(m_path)); return false; } readChildElements(xmlReader, root); } - file.close(); return true; } @@ -67,18 +54,7 @@ void Xbel::readChildElements(QXmlStreamReader &reader, BookmarkItem *parentItem) bool Xbel::write(BookmarkItem *root) { - - // if the path is empty, there is nothing to save to - if(m_path.isEmpty()) - return false; - - QFile file(m_path); - if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - // file cannot be opened for writing - return false; - } - - QXmlStreamWriter xmlWriter(&file); + QXmlStreamWriter xmlWriter(m_file); xmlWriter.setAutoFormatting(true); xmlWriter.writeStartDocument(); @@ -91,7 +67,6 @@ bool Xbel::write(BookmarkItem *root) xmlWriter.writeEndDocument(); - file.close(); return true; } |