From 334be268bf75b863f7c912ae28bab46f7bbc325a Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 4 Feb 2018 17:27:58 +0100 Subject: Bookmarks drag and drop --- lib/bookmarks/xbel.cpp | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'lib/bookmarks/xbel.cpp') 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 -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; } -- cgit v1.2.1