Browse Source

Bookmarks: move xbel implementation to formats/

master
Aqua-sama 4 weeks ago
parent
commit
6e89bf2307
Signed by: Aqua-sama <aqua@iserlohn-fortress.net> GPG Key ID: 81A99984EABC02D1
7 changed files with 69 additions and 5 deletions
  1. +5
    -3
      lib/bookmarks/bookmarkswidget.cpp
  2. +26
    -0
      lib/bookmarks/formats/format.cpp
  3. +36
    -0
      lib/bookmarks/formats/format.h
  4. +0
    -0
      lib/bookmarks/formats/xbel.cpp
  5. +0
    -0
      lib/bookmarks/formats/xbel.h
  6. +1
    -1
      lib/bookmarks/meson.build
  7. +1
    -1
      lib/bookmarks/model/bookmarkmodel.cpp

+ 5
- 3
lib/bookmarks/bookmarkswidget.cpp View File

@@ -11,7 +11,7 @@
#include "model/bookmarkitem.h"
#include "model/bookmarkmodel.h"
#include "ui_bookmarksform.h"
#include "xbel.h"
#include "formats/format.h"
#include <QTreeView>
#include <QUrl>

@@ -48,7 +48,8 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
m_bookmarksPath = path;
QFile bookmarksFile(m_bookmarksPath);
if(bookmarksFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
Xbel::read(&bookmarksFile, model->root());
BookmarksFormat<XbelFormat> format(&bookmarksFile);
format.read(model->root());
bookmarksFile.close();
}
model->resetModified();
@@ -123,7 +124,8 @@ void BookmarksWidget::save()

QFile bookmarksFile(m_bookmarksPath);
if(bookmarksFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
Xbel::write(&bookmarksFile, model->root());
BookmarksFormat<XbelFormat> format(&bookmarksFile);
format.write(model->root());
bookmarksFile.flush();
bookmarksFile.close();
model->resetModified();

+ 26
- 0
lib/bookmarks/formats/format.cpp View File

@@ -0,0 +1,26 @@
/*
* This file is part of smolbote. It's copyrighted by the contributors recorded
* in the version control history of the file, available from its original
* location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
*
* SPDX-License-Identifier: GPL-3.0
*/

#include "format.h"
#include "xbel.h"
#include <QIODevice>

template<>
void BookmarksFormat<BookmarksFormats::XbelFormat>::read(BookmarkItem *root)
{
Q_CHECK_PTR(m_device);
Xbel::read(m_device, root);
}

template<>
void BookmarksFormat<BookmarksFormats::XbelFormat>::write(BookmarkItem *root)
{
Q_CHECK_PTR(m_device);
Xbel::write(m_device, root);
}


+ 36
- 0
lib/bookmarks/formats/format.h View File

@@ -0,0 +1,36 @@
/*
* This file is part of smolbote. It's copyrighted by the contributors recorded
* in the version control history of the file, available from its original
* location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
*
* SPDX-License-Identifier: GPL-3.0
*/

#ifndef BOOKMARKSFORMAT_H
#define BOOKMARKSFORMAT_H

class QIODevice;
class BookmarkItem;

enum BookmarksFormats {
XbelFormat
};

template<BookmarksFormats format>
class BookmarksFormat
{
public:
explicit BookmarksFormat(QIODevice *device)
{
m_device = device;
}

void read(BookmarkItem *root);
void write(BookmarkItem *root);

protected:
QIODevice *m_device;
};

#endif // BOOKMARKSFORMAT_H


lib/bookmarks/xbel.cpp → lib/bookmarks/formats/xbel.cpp View File


lib/bookmarks/xbel.h → lib/bookmarks/formats/xbel.h View File


+ 1
- 1
lib/bookmarks/meson.build View File

@@ -7,7 +7,7 @@ bookmarks_moc = mod_qt5.preprocess(

bookmarks_lib = static_library('bookmarks',
['bookmarkswidget.cpp', bookmarks_moc,
'xbel.cpp', 'xbel.h',
'formats/format.cpp', 'formats/xbel.cpp',
'model/bookmarkitem.cpp', 'model/bookmarkmodel.cpp',
'forms/editbookmarkdialog.cpp'],
dependencies: dep_qt5

+ 1
- 1
lib/bookmarks/model/bookmarkmodel.cpp View File

@@ -8,7 +8,7 @@

#include "bookmarkmodel.h"
#include "bookmarkitem.h"
#include "xbel.h"
#include "formats/xbel.h"
#include <QBuffer>
#include <QMimeData>
#include <QRegularExpression>

Loading…
Cancel
Save