10#include <QtCore/QDate>
11#include <QtCore/QModelIndex>
15using namespace Qt::StringLiterals;
28 setAutoFormatting(
true);
37 writeDTD(
"<!DOCTYPE xbel>"_L1);
38 writeStartElement(
"xbel"_L1);
39 writeAttribute(
"version"_L1,
"1.0"_L1);
41 const QModelIndex root;
42 for (
int i = 0; i < bookmarkModel->rowCount(root); ++i)
43 writeData(bookmarkModel->index(i, 0, root));
47void XbelWriter::writeData(
const QModelIndex &index)
50 if (index.isValid()) {
52 entry.title = index.data().toString();
56 writeStartElement(
"folder"_L1);
58 writeAttribute(
"folded"_L1, entry.folded ?
"yes"_L1 :
"no"_L1);
59 writeTextElement(
"title"_L1, entry.title);
60 for (
int i = 0; i < bookmarkModel->rowCount(index); ++i)
61 writeData(bookmarkModel->index(i, 0 , index));
64 writeStartElement(
"bookmark"_L1);
65 writeAttribute(
"href"_L1, entry.url);
66 writeTextElement(
"title"_L1, entry.title);
89 if (isStartElement()) {
90 if (name() ==
"xbel"_L1 && attributes().value(
"version"_L1) ==
"1.0"_L1) {
91 const QModelIndex root;
92 parents.append(bookmarkModel->addItem(root,
true));
94 bookmarkModel->setData(parents.first(),
95 QDate::currentDate().toString(Qt::ISODate), Qt::EditRole);
97 raiseError(
"The file is not an XBEL version 1.0 file."_L1);
114 if (isStartElement()) {
115 if (name() ==
"folder"_L1)
117 else if (name() ==
"bookmark"_L1)
120 readUnknownElement();
128 parents.append(bookmarkModel->addItem(parents.last(),
true));
129 bookmarkModel->setData(parents.last(), attributes().value(
"folded"_L1) ==
"no"_L1,
138 if (isStartElement()) {
139 if (name() ==
"title"_L1)
140 bookmarkModel->setData(parents.last(), readElementText(), Qt::EditRole);
141 else if (name() ==
"folder"_L1)
143 else if (name() ==
"bookmark"_L1)
146 readUnknownElement();
150 parents.removeLast();
156 const QModelIndex &index = bookmarkModel->addItem(parents.last(),
false);
157 if (BookmarkItem* item = bookmarkModel->itemFromIndex(index))
158 item->setData(UserRoleUrl, attributes().value(
"href"_L1).toString());
166 if (isStartElement()) {
167 if (name() ==
"title"_L1)
168 bookmarkModel->setData(index, readElementText(), Qt::EditRole);
170 readUnknownElement();
184 if (isStartElement())
185 readUnknownElement();
bool readFromFile(QIODevice *device)
XbelReader(BookmarkModel *model)
void writeToFile(QIODevice *device)
XbelWriter(BookmarkModel *model)
Combined button and popup list for selecting options.