From 4c71c8571ceb10b29e6550cd0d8eb928049e6851 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 14 Jan 2020 23:34:13 +0200 Subject: Move/rename files for readability - add BookmarkFormat <<|>> BookmarkModel operators --- lib/bookmarks/formats/xbel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/bookmarks/formats/xbel.cpp') diff --git a/lib/bookmarks/formats/xbel.cpp b/lib/bookmarks/formats/xbel.cpp index 1cb5756..174995d 100644 --- a/lib/bookmarks/formats/xbel.cpp +++ b/lib/bookmarks/formats/xbel.cpp @@ -7,7 +7,7 @@ */ #include "xbel.h" -#include "model/bookmarkitem.h" +#include "bookmarkitem.h" #include #include -- cgit v1.2.1 From 5f708d4618d739d14442b85c466fdbac84a74cc8 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 17 Jan 2020 10:25:27 +0200 Subject: BookmarkItem::DateAdded and LastModified fields - add read support in FFJson for DateAdded and LastModified fields - add read/write support in Xbel for DateAdded and LastModified fields - BookmarkModel: set DateAdded on appendBookmark and appendFolder - EditBookmarkDialog: set LastModified field when saving changes --- lib/bookmarks/formats/xbel.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'lib/bookmarks/formats/xbel.cpp') diff --git a/lib/bookmarks/formats/xbel.cpp b/lib/bookmarks/formats/xbel.cpp index 174995d..bac2bc8 100644 --- a/lib/bookmarks/formats/xbel.cpp +++ b/lib/bookmarks/formats/xbel.cpp @@ -10,6 +10,7 @@ #include "bookmarkitem.h" #include #include +#include inline void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent) { @@ -17,6 +18,12 @@ inline void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent) if(reader.name() == "title") { parent->setData(BookmarkItem::Title, reader.readElementText()); + } else if(reader.name() == "dateAdded") { + parent->setData(BookmarkItem::DateAdded, QDateTime::fromString(reader.readElementText(), Qt::RFC2822Date)); + + } else if(reader.name() == "lastModified") { + parent->setData(BookmarkItem::LastModified, QDateTime::fromString(reader.readElementText(), Qt::RFC2822Date)); + } else if(reader.name() == "tags") { parent->setData(BookmarkItem::Tags, reader.readElementText().split(";")); @@ -54,6 +61,19 @@ void Xbel::read(QIODevice *device, BookmarkItem *item) } } +inline void writeCommon(QXmlStreamWriter &writer, const BookmarkItem *item) +{ + writer.writeTextElement("title", item->data(BookmarkItem::Title).toString()); + + const auto dateAdded = item->data(BookmarkItem::DateAdded); + if(!dateAdded.isNull()) + writer.writeTextElement("dateAdded", dateAdded.toDateTime().toString(Qt::RFC2822Date)); + + const auto lastModified = item->data(BookmarkItem::LastModified); + if(!lastModified.isNull()) + writer.writeTextElement("lastModified", lastModified.toDateTime().toString(Qt::RFC2822Date)); +} + inline void writeChildElements(QXmlStreamWriter &writer, const BookmarkItem *item) { switch(item->type()) { @@ -66,7 +86,7 @@ inline void writeChildElements(QXmlStreamWriter &writer, const BookmarkItem *ite case BookmarkItem::Folder: writer.writeStartElement("folder"); writer.writeAttribute("folded", !item->isExpanded() ? "yes" : "no"); - writer.writeTextElement("title", item->data(BookmarkItem::Title).toString()); + writeCommon(writer, item); if(!item->data(BookmarkItem::Tags).isNull()) writer.writeTextElement("tags", item->data(BookmarkItem::Tags).toStringList().join(";")); if(!item->data(BookmarkItem::Description).isNull()) @@ -82,7 +102,7 @@ inline void writeChildElements(QXmlStreamWriter &writer, const BookmarkItem *ite case BookmarkItem::Bookmark: writer.writeStartElement("bookmark"); writer.writeAttribute("href", item->data(BookmarkItem::Href).toString()); - writer.writeTextElement("title", item->data(BookmarkItem::Title).toString()); + writeCommon(writer, item); if(!item->data(BookmarkItem::Tags).isNull()) writer.writeTextElement("tags", item->data(BookmarkItem::Tags).toStringList().join(";")); if(!item->data(BookmarkItem::Description).isNull()) -- cgit v1.2.1