From fb7586f3c5458bb0a0796fd8f7d207246a9f692c Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 20 Mar 2017 14:32:31 +0100 Subject: Dockable bookmarks dialog Fixed bugs in bookmarks dialog --- data/bookmarks.xbel | 13 +++ data/poi.conf | 2 +- smolbote.qbs | 16 ++-- src/forms/bookmarksdialog.cpp | 26 ++++-- src/forms/bookmarksdialog.h | 6 +- src/forms/bookmarksdialog.ui | 45 +--------- src/mainwindow.cpp | 2 + src/settings.cpp | 8 +- src/xbel.cpp | 198 ++++++++++++++++++++++++++++++++++++++++++ src/xbel.h | 57 ++++++++++++ src/xbel/xbel.cpp | 197 ----------------------------------------- src/xbel/xbel.h | 57 ------------ test/bookmarks.xbel | 41 +-------- 13 files changed, 314 insertions(+), 354 deletions(-) create mode 100644 data/bookmarks.xbel create mode 100644 src/xbel.cpp create mode 100644 src/xbel.h delete mode 100644 src/xbel/xbel.cpp delete mode 100644 src/xbel/xbel.h mode change 100644 => 120000 test/bookmarks.xbel diff --git a/data/bookmarks.xbel b/data/bookmarks.xbel new file mode 100644 index 0000000..5aab255 --- /dev/null +++ b/data/bookmarks.xbel @@ -0,0 +1,13 @@ + + + + + smolbote + + Repository + + + Qt Documentation + + + diff --git a/data/poi.conf b/data/poi.conf index b9c1aee..1e4965f 100644 --- a/data/poi.conf +++ b/data/poi.conf @@ -52,7 +52,7 @@ subscriptions=[ # Bookmark manager [bookmarks] dialogShortcut="Ctrl+Shift+B" -path="bookmarks.xbel" +path="~settings/bookmarks.xbel" # Download manager [downloads] diff --git a/smolbote.qbs b/smolbote.qbs index c4112de..21e0165 100644 --- a/smolbote.qbs +++ b/smolbote.qbs @@ -76,6 +76,17 @@ Project { ] } + Group { + name: "bookmarks" + files: [ + "src/forms/bookmarksdialog.cpp", + "src/forms/bookmarksdialog.h", + "src/forms/bookmarksdialog.ui", + "src/xbel.cpp", + "src/xbel.h", + ] + } + files: [ "data/resources.qrc", "src/blocker/blockermanager.cpp", @@ -88,9 +99,6 @@ Project { "src/blocker/regexp.h", "src/blocker/subscriptiondialog.ui", "src/blocker/subscriptionform.ui", - "src/forms/bookmarksdialog.cpp", - "src/forms/bookmarksdialog.h", - "src/forms/bookmarksdialog.ui", "src/forms/downloaddialog.cpp", "src/forms/downloaddialog.h", "src/forms/downloaddialog.ui", @@ -114,8 +122,6 @@ Project { "src/widgets/urllineedit.h", "src/widgets/webviewtabbar.cpp", "src/widgets/webviewtabbar.h", - "src/xbel/xbel.cpp", - "src/xbel/xbel.h", ] Group { diff --git a/src/forms/bookmarksdialog.cpp b/src/forms/bookmarksdialog.cpp index c088fd8..becac56 100644 --- a/src/forms/bookmarksdialog.cpp +++ b/src/forms/bookmarksdialog.cpp @@ -20,14 +20,17 @@ #include "bookmarksdialog.h" #include "ui_bookmarksdialog.h" +#include "browser.h" #include -#include "xbel/xbel.h" -#include "mainwindow.h" +#include BookmarksDialog::BookmarksDialog(QWidget *parent) : QDialog(parent), ui(new Ui::BookmarksDialog) { + // make sure this dialog does not get deleted on close + setAttribute(Qt::WA_DeleteOnClose, false); + ui->setupUi(this); ui->treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch); @@ -44,7 +47,7 @@ BookmarksDialog::BookmarksDialog(QWidget *parent) : connect(ui->deleteItem_toolButton, SIGNAL(clicked(bool)), this, SLOT(deleteCurrentItem())); xbel = new Xbel(ui->treeWidget); - xbel->read("bookmarks.xbel"); + xbel->read(sSettings->value("bookmarks.path").toString()); connect(ui->addFolder_toolButton, &QToolButton::clicked, [this]() { xbel->addFolder(ui->treeWidget->currentItem()); @@ -59,17 +62,28 @@ BookmarksDialog::BookmarksDialog(QWidget *parent) : BookmarksDialog::~BookmarksDialog() { + qDebug("Destroying BookmarksManager"); + if(ui->treeWidget->topLevelItemCount() > 0) { - xbel->write("bookmarks.xbel"); + xbel->write(sSettings->value("bookmarks.path").toString()); } delete xbel; delete ui; } -void BookmarksDialog::show(MainWindow *window) +void BookmarksDialog::show() { - w = window; + // show() is called by a QAction in MainWindow + w = qobject_cast(sender()->parent()); + + // dockable widgets + QDockWidget *bookmarksDock = new QDockWidget(tr("Bookmarks"), w); + bookmarksDock->setWidget(this); + bookmarksDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + w->addDockWidget(Qt::RightDockWidgetArea, bookmarksDock); + bookmarksDock->setFloating(true); + QDialog::show(); } diff --git a/src/forms/bookmarksdialog.h b/src/forms/bookmarksdialog.h index 17f4df7..0fcab42 100644 --- a/src/forms/bookmarksdialog.h +++ b/src/forms/bookmarksdialog.h @@ -22,13 +22,13 @@ #define BOOKMARKSDIALOG_H #include -#include "xbel/xbel.h" +#include "xbel.h" +#include "mainwindow.h" namespace Ui { class BookmarksDialog; } -class MainWindow; class BookmarksDialog : public QDialog { Q_OBJECT @@ -41,7 +41,7 @@ signals: void openUrl(const QUrl &url); public slots: - void show(MainWindow *window); + void show(); // void addFolder(const QString &title); // void addBookmark(const QString &title, const QString &href); // void addSeparator(); diff --git a/src/forms/bookmarksdialog.ui b/src/forms/bookmarksdialog.ui index a0e4316..f528528 100644 --- a/src/forms/bookmarksdialog.ui +++ b/src/forms/bookmarksdialog.ui @@ -111,51 +111,8 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - buttonBox - accepted() - BookmarksDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - BookmarksDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8eb5462..5cf9590 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -61,6 +61,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : QAction *downloadsAction = toolsMenu->addAction(tr("Downloads"), Browser::instance()->downloads(), SLOT(show())); downloadsAction->setShortcut(QKeySequence::fromString(sSettings->value("downloads.dialogShortcut").toString())); QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks"), Browser::instance()->bookmarks(), SLOT(show())); + bookmarksAction->setParent(this); bookmarksAction->setShortcut(QKeySequence(sSettings->value("bookmarks.dialogShortcut").toString())); toolsMenu->addSeparator(); toolsMenu->addAction(tr("Blocker"), blocklistManager, SLOT(show()), QKeySequence::fromString(sSettings->value("blocker.shortcut").toString())); @@ -124,6 +125,7 @@ MainWindow::MainWindow(const QStringList urlList, QWidget *parent) : MainWindow::~MainWindow() { + qApp->bookmarks()->setParent(0); delete ui; } diff --git a/src/settings.cpp b/src/settings.cpp index 7a08061..aee0eb5 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -21,6 +21,8 @@ #include "settings.h" #include #include +#include +#include Settings::Settings(const QString &configFile) { @@ -43,7 +45,11 @@ Settings::Settings(const QString &configFile) path = configFile; homeLocation = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); - settingsLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); + settingsLocation = QFileInfo(configFile).dir().absolutePath(); + + qDebug("Read configuration: [%s]", qUtf8Printable(configFile)); + qDebug("~ => '%s'", qUtf8Printable(homeLocation)); + qDebug("~settings => '%s'", qUtf8Printable(settingsLocation)); } Settings::~Settings() diff --git a/src/xbel.cpp b/src/xbel.cpp new file mode 100644 index 0000000..59204d8 --- /dev/null +++ b/src/xbel.cpp @@ -0,0 +1,198 @@ +/** LICENSE ******************************************************************** + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#include "xbel.h" +#include + +#include + +Xbel::Xbel(QTreeWidget *widget) +{ + treeWidget = widget; + + QStyle *style = treeWidget->style(); + folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); + folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); + bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); +} + +bool Xbel::read(const QString &xbel) +{ + // no file specified + if(xbel.isEmpty()) { + return false; + } + + QFile file(xbel); + if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + // file cannot be opened + qDebug("Cannot open xbel: %s", qUtf8Printable(xbel)); + return false; + } + + xmlReader.setDevice(&file); + + if(xmlReader.readNextStartElement()) { + if(xmlReader.name() == "xbel" && xmlReader.attributes().value("version") == "1.0") { + qDebug("valid xbel"); + readChildElements(0); + } else { + qDebug("invalid xbel"); + return false; + } + + } + return true; +} + +bool Xbel::write(const QString &xbel) +{ + // no file specified + if(xbel.isEmpty()) { + return false; + } + + QFile file(xbel); + if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + // file cannot be opened + qDebug("Cannot open xbel: %s", qUtf8Printable(xbel)); + return false; + } + + xmlWriter.setAutoFormatting(true); + xmlWriter.setDevice(&file); + + xmlWriter.writeStartDocument(); + xmlWriter.writeDTD(""); + xmlWriter.writeStartElement("xbel"); + xmlWriter.writeAttribute("version", "1.0"); + + for(int i=0; itopLevelItemCount(); i++) { + writeItem(treeWidget->topLevelItem(i)); + } + + xmlWriter.writeEndDocument(); + return true; +} + +void Xbel::readChildElements(QTreeWidgetItem *parentItem) +{ + while(xmlReader.readNextStartElement()) { + if(xmlReader.name() == "title") { + readTitle(parentItem); + } else if(xmlReader.name() == "folder") { + readChildElements(addFolder(parentItem)); + } else if(xmlReader.name() == "bookmark") { + QTreeWidgetItem *item = addBookmark(parentItem); + item->setText(1, xmlReader.attributes().value("href").toString()); + readChildElements(item); + } else if(xmlReader.name() == "separator") { + addSeparator(parentItem); + xmlReader.skipCurrentElement(); + } else { + xmlReader.skipCurrentElement(); + } + } +} + +void Xbel::readTitle(QTreeWidgetItem *item) +{ + item->setText(0, xmlReader.readElementText()); +} + +QTreeWidgetItem *Xbel::addFolder(QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *folderItem = createChildItem(parentFolder(parentItem), "folder"); + //folderItem->setExpanded(xmlReader.attributes().value("folded") != "no"); + treeWidget->setItemExpanded(folderItem, xmlReader.attributes().value("folded") != "yes"); + folderItem->setFlags(folderItem->flags() | Qt::ItemIsEditable); + folderItem->setIcon(0, folderIcon); + + return folderItem; +} + +QTreeWidgetItem *Xbel::addBookmark(QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *bookmarkItem = createChildItem(parentFolder(parentItem), "bookmark"); + bookmarkItem->setFlags((bookmarkItem->flags() | Qt::ItemIsEditable) & ~Qt::ItemIsDropEnabled); + bookmarkItem->setIcon(0, bookmarkIcon); + bookmarkItem->setText(0, "Unknown Title"); + bookmarkItem->setText(1, "Unknown Address"); + + return bookmarkItem; +} + +void Xbel::addSeparator(QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *separatorItem = createChildItem(parentFolder(parentItem), "separator"); + separatorItem->setFlags(separatorItem->flags() & ~Qt::ItemIsDropEnabled); + separatorItem->setText(0, "-----"); +} + +QTreeWidgetItem *Xbel::parentFolder(QTreeWidgetItem *item) +{ + QTreeWidgetItem *parentItem = item; + + if(parentItem) { + while(parentItem->data(0, Qt::UserRole) != "folder") { + parentItem = parentItem->parent(); + if(parentItem == 0) { + break; + } + } + } + + return parentItem; +} + +QTreeWidgetItem *Xbel::createChildItem(QTreeWidgetItem *item, const QString &type) +{ + QTreeWidgetItem *childItem; + if(item) { + childItem = new QTreeWidgetItem(item); + } else { + childItem = new QTreeWidgetItem(treeWidget); + } + childItem->setData(0, Qt::UserRole, type); + return childItem; +} + +void Xbel::writeItem(QTreeWidgetItem *item) +{ + QString tagName = item->data(0, Qt::UserRole).toString(); + if (tagName == "folder") { + xmlWriter.writeStartElement(tagName); + xmlWriter.writeAttribute("folded", treeWidget->isItemExpanded(item) ? "no" : "yes"); + xmlWriter.writeTextElement("title", item->text(0)); + for (int i = 0; i < item->childCount(); ++i) { + writeItem(item->child(i)); + } + xmlWriter.writeEndElement(); + } else if (tagName == "bookmark") { + xmlWriter.writeStartElement(tagName); + if (!item->text(1).isEmpty()) { + xmlWriter.writeAttribute("href", item->text(1)); + } + xmlWriter.writeTextElement("title", item->text(0)); + xmlWriter.writeEndElement(); + } else if (tagName == "separator") { + xmlWriter.writeEmptyElement(tagName); + } +} diff --git a/src/xbel.h b/src/xbel.h new file mode 100644 index 0000000..6ffafb1 --- /dev/null +++ b/src/xbel.h @@ -0,0 +1,57 @@ +/** LICENSE ******************************************************************** + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#ifndef XBELREADER_H +#define XBELREADER_H + +#include +#include + +class QTreeWidget; +class QTreeWidgetItem; +class Xbel +{ +public: + Xbel(QTreeWidget *widget); + bool read(const QString &xbel); + bool write(const QString &xbel); + + QTreeWidgetItem *addFolder(QTreeWidgetItem *parentItem); + QTreeWidgetItem *addBookmark(QTreeWidgetItem *parentItem); + void addSeparator(QTreeWidgetItem *parentItem); + +private: + void readChildElements(QTreeWidgetItem *parentItem); + void readTitle(QTreeWidgetItem *item); + + QTreeWidgetItem *parentFolder(QTreeWidgetItem *item); + QTreeWidgetItem *createChildItem(QTreeWidgetItem *item, const QString &type); + + void writeItem(QTreeWidgetItem *item); + + QIcon folderIcon; + QIcon bookmarkIcon; + + QTreeWidget *treeWidget; + QXmlStreamReader xmlReader; + QXmlStreamWriter xmlWriter; +}; + +#endif // XBELREADER_H diff --git a/src/xbel/xbel.cpp b/src/xbel/xbel.cpp deleted file mode 100644 index 2047e99..0000000 --- a/src/xbel/xbel.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/** LICENSE ******************************************************************** - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#include "xbel.h" -#include - -#include - -Xbel::Xbel(QTreeWidget *widget) -{ - treeWidget = widget; - - QStyle *style = treeWidget->style(); - folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); - folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); - bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); -} - -bool Xbel::read(const QString &xbel) -{ - // no file specified - if(xbel.isEmpty()) { - return false; - } - - QFile file(xbel); - if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - // file cannot be opened - qDebug("Cannot open xbel: %s", qUtf8Printable(xbel)); - return false; - } - - xmlReader.setDevice(&file); - - if(xmlReader.readNextStartElement()) { - if(xmlReader.name() == "xbel" && xmlReader.attributes().value("version") == "1.0") { - qDebug("valid xbel"); - readChildElements(0); - } else { - qDebug("invalid xbel"); - return false; - } - - } - return true; -} - -bool Xbel::write(const QString &xbel) -{ - // no file specified - if(xbel.isEmpty()) { - return false; - } - - QFile file(xbel); - if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - // file cannot be opened - qDebug("Cannot open xbel: %s", qUtf8Printable(xbel)); - return false; - } - - xmlWriter.setAutoFormatting(true); - xmlWriter.setDevice(&file); - - xmlWriter.writeStartDocument(); - xmlWriter.writeDTD(""); - xmlWriter.writeStartElement("xbel"); - xmlWriter.writeAttribute("version", "1.0"); - - for(int i=0; itopLevelItemCount(); i++) { - writeItem(treeWidget->topLevelItem(i)); - } - - xmlWriter.writeEndDocument(); - return true; -} - -void Xbel::readChildElements(QTreeWidgetItem *parentItem) -{ - while(xmlReader.readNextStartElement()) { - if(xmlReader.name() == "title") { - readTitle(parentItem); - } else if(xmlReader.name() == "folder") { - readChildElements(addFolder(parentItem)); - } else if(xmlReader.name() == "bookmark") { - QTreeWidgetItem *item = addBookmark(parentItem); - item->setText(1, xmlReader.attributes().value("href").toString()); - readChildElements(item); - } else if(xmlReader.name() == "separator") { - addSeparator(parentItem); - xmlReader.skipCurrentElement(); - } else { - xmlReader.skipCurrentElement(); - } - } -} - -void Xbel::readTitle(QTreeWidgetItem *item) -{ - item->setText(0, xmlReader.readElementText()); -} - -QTreeWidgetItem *Xbel::addFolder(QTreeWidgetItem *parentItem) -{ - QTreeWidgetItem *folderItem = createChildItem(parentFolder(parentItem), "folder"); - folderItem->setExpanded(xmlReader.attributes().value("folded") != "no"); - folderItem->setFlags(folderItem->flags() | Qt::ItemIsEditable); - folderItem->setIcon(0, folderIcon); - - return folderItem; -} - -QTreeWidgetItem *Xbel::addBookmark(QTreeWidgetItem *parentItem) -{ - QTreeWidgetItem *bookmarkItem = createChildItem(parentFolder(parentItem), "bookmark"); - bookmarkItem->setFlags((bookmarkItem->flags() | Qt::ItemIsEditable) & ~Qt::ItemIsDropEnabled); - bookmarkItem->setIcon(0, bookmarkIcon); - bookmarkItem->setText(0, "Unknown Title"); - bookmarkItem->setText(1, "Unknown Address"); - - return bookmarkItem; -} - -void Xbel::addSeparator(QTreeWidgetItem *parentItem) -{ - QTreeWidgetItem *separatorItem = createChildItem(parentFolder(parentItem), "separator"); - separatorItem->setFlags(separatorItem->flags() & ~Qt::ItemIsDropEnabled); - separatorItem->setText(0, "-----"); -} - -QTreeWidgetItem *Xbel::parentFolder(QTreeWidgetItem *item) -{ - QTreeWidgetItem *parentItem = item; - - if(parentItem) { - while(parentItem->data(0, Qt::UserRole) != "folder") { - parentItem = parentItem->parent(); - if(parentItem == 0) { - break; - } - } - } - - return parentItem; -} - -QTreeWidgetItem *Xbel::createChildItem(QTreeWidgetItem *item, const QString &type) -{ - QTreeWidgetItem *childItem; - if(item) { - childItem = new QTreeWidgetItem(item); - } else { - childItem = new QTreeWidgetItem(treeWidget); - } - childItem->setData(0, Qt::UserRole, type); - return childItem; -} - -void Xbel::writeItem(QTreeWidgetItem *item) -{ - QString tagName = item->data(0, Qt::UserRole).toString(); - if (tagName == "folder") { - xmlWriter.writeStartElement(tagName); - xmlWriter.writeAttribute("folded", treeWidget->isItemExpanded(item) ? "no" : "yes"); - xmlWriter.writeTextElement("title", item->text(0)); - for (int i = 0; i < item->childCount(); ++i) { - writeItem(item->child(i)); - } - xmlWriter.writeEndElement(); - } else if (tagName == "bookmark") { - xmlWriter.writeStartElement(tagName); - if (!item->text(1).isEmpty()) { - xmlWriter.writeAttribute("href", item->text(1)); - } - xmlWriter.writeTextElement("title", item->text(0)); - xmlWriter.writeEndElement(); - } else if (tagName == "separator") { - xmlWriter.writeEmptyElement(tagName); - } -} diff --git a/src/xbel/xbel.h b/src/xbel/xbel.h deleted file mode 100644 index 6ffafb1..0000000 --- a/src/xbel/xbel.h +++ /dev/null @@ -1,57 +0,0 @@ -/** LICENSE ******************************************************************** - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#ifndef XBELREADER_H -#define XBELREADER_H - -#include -#include - -class QTreeWidget; -class QTreeWidgetItem; -class Xbel -{ -public: - Xbel(QTreeWidget *widget); - bool read(const QString &xbel); - bool write(const QString &xbel); - - QTreeWidgetItem *addFolder(QTreeWidgetItem *parentItem); - QTreeWidgetItem *addBookmark(QTreeWidgetItem *parentItem); - void addSeparator(QTreeWidgetItem *parentItem); - -private: - void readChildElements(QTreeWidgetItem *parentItem); - void readTitle(QTreeWidgetItem *item); - - QTreeWidgetItem *parentFolder(QTreeWidgetItem *item); - QTreeWidgetItem *createChildItem(QTreeWidgetItem *item, const QString &type); - - void writeItem(QTreeWidgetItem *item); - - QIcon folderIcon; - QIcon bookmarkIcon; - - QTreeWidget *treeWidget; - QXmlStreamReader xmlReader; - QXmlStreamWriter xmlWriter; -}; - -#endif // XBELREADER_H diff --git a/test/bookmarks.xbel b/test/bookmarks.xbel deleted file mode 100644 index 66fbc25..0000000 --- a/test/bookmarks.xbel +++ /dev/null @@ -1,40 +0,0 @@ - - - - - Bookmarks Bar - - Qt Home Page - - - Qt Documentation - - - Qt Blog - - - Qt Centre - - - Qt-Apps.org - - - Online Communities - - - The Chromium Projects - - - xkcd - - - Twitter - - - - Bookmarks Menu - - reddit.com: what's new online! - - - diff --git a/test/bookmarks.xbel b/test/bookmarks.xbel new file mode 120000 index 0000000..8644c64 --- /dev/null +++ b/test/bookmarks.xbel @@ -0,0 +1 @@ +../data/bookmarks.xbel \ No newline at end of file -- cgit v1.2.1