aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-01-28 18:55:02 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-01-28 18:55:02 +0200
commit241f6e04dc9b5cbfc7503a544b16d7b5452f1acb (patch)
treeea87c413506aff0794250bb861b1005db5a8c2a6
parentAdd bookmarks toolbar (diff)
downloadsmolbote-241f6e04dc9b5cbfc7503a544b16d7b5452f1acb.tar.xz
Remove non-const BookmarkItem::icon
Default BookmarkItem icons will be created when creating the item, if a QApplication (and subsequently, qApp->style()) is present. - added a poi-bookmarks test
-rw-r--r--lib/bookmarks/bookmarkitem.cpp20
-rw-r--r--lib/bookmarks/bookmarkitem.h1
-rw-r--r--meson.build2
-rw-r--r--src/bookmarks/builtins.cpp12
-rw-r--r--test/bookmarks.xbel13
5 files changed, 33 insertions, 15 deletions
diff --git a/lib/bookmarks/bookmarkitem.cpp b/lib/bookmarks/bookmarkitem.cpp
index 242ab57..b2ee78b 100644
--- a/lib/bookmarks/bookmarkitem.cpp
+++ b/lib/bookmarks/bookmarkitem.cpp
@@ -19,6 +19,15 @@ BookmarkItem::BookmarkItem(const QVector<QVariant> &data, Type type, BookmarkIte
for(int i = 0; i < FieldCount; ++i) {
m_data[i] = data.value(i, QVariant());
}
+
+ // set a default style if any can be set
+ if(qApp) {
+ if(m_type == Folder) {
+ m_icon.addPixmap(qApp->style()->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off);
+ m_icon.addPixmap(qApp->style()->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On);
+ } else if(m_type == Bookmark)
+ m_icon.addPixmap(qApp->style()->standardPixmap(QStyle::SP_FileIcon));
+ }
}
BookmarkItem::~BookmarkItem()
@@ -98,17 +107,6 @@ bool BookmarkItem::setData(Fields column, const QVariant &data)
return true;
}
-QIcon BookmarkItem::icon()
-{
- if(m_icon.isNull() && m_type == Folder) {
- m_icon.addPixmap(qApp->style()->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off);
- m_icon.addPixmap(qApp->style()->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On);
- } else if(m_icon.isNull() && m_type == Bookmark)
- m_icon.addPixmap(qApp->style()->standardPixmap(QStyle::SP_FileIcon));
-
- return m_icon;
-}
-
QIcon BookmarkItem::icon() const
{
return m_icon;
diff --git a/lib/bookmarks/bookmarkitem.h b/lib/bookmarks/bookmarkitem.h
index 310d263..6751526 100644
--- a/lib/bookmarks/bookmarkitem.h
+++ b/lib/bookmarks/bookmarkitem.h
@@ -48,7 +48,6 @@ public:
QVariant data(Fields column) const;
bool setData(Fields column, const QVariant &data);
- QIcon icon();
QIcon icon() const;
bool isExpanded() const;
void setExpanded(bool expanded);
diff --git a/meson.build b/meson.build
index 2e7ec72..5e10db7 100644
--- a/meson.build
+++ b/meson.build
@@ -101,6 +101,8 @@ poi_exe = executable(get_option('poi'),
install: true,
)
+test('poi-bookmarks: xbel', poi_exe, args: [ 'bookmarks', '-x', files('test/bookmarks.xbel'), '--export=stdout' ])
+
subdir(host_machine.system())
# cppcheck target
diff --git a/src/bookmarks/builtins.cpp b/src/bookmarks/builtins.cpp
index 2e97e1a..f7b6f3f 100644
--- a/src/bookmarks/builtins.cpp
+++ b/src/bookmarks/builtins.cpp
@@ -54,8 +54,10 @@ int builtins::bookmarks(const std::string &progname, std::vector<std::string>::c
if(f.open(QIODevice::ReadOnly | QIODevice::Text)) {
BookmarkFormat<XbelFormat>(&f) >> model;
f.close();
- } else
+ } else {
spdlog::error("Could not open %s", i);
+ return -1;
+ }
}
for(const auto &i : args::get(import_json)) {
@@ -63,8 +65,10 @@ int builtins::bookmarks(const std::string &progname, std::vector<std::string>::c
if(f.open(QIODevice::ReadOnly | QIODevice::Text)) {
BookmarkFormat<FirefoxJsonFormat>(&f) >> model;
f.close();
- } else
+ } else {
spdlog::error("Could not open %s", i);
+ return -1;
+ }
}
QIODevice *output = nullptr;
@@ -85,8 +89,10 @@ int builtins::bookmarks(const std::string &progname, std::vector<std::string>::c
}
if(!output->isOpen()) {
- if(!output->open(QIODevice::ReadWrite | QIODevice::Text))
+ if(!output->open(QIODevice::ReadWrite | QIODevice::Text)) {
spdlog::error("Could not open output");
+ return -1;
+ }
}
BookmarkFormat<XbelFormat> format(output);
diff --git a/test/bookmarks.xbel b/test/bookmarks.xbel
new file mode 100644
index 0000000..487fc5b
--- /dev/null
+++ b/test/bookmarks.xbel
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xbel>
+<xbel version="1.0">
+ <bookmark href="https://some.url">
+ <title>some website</title>
+ </bookmark>
+ <folder folded="no">
+ <title>a folder</title>
+ <bookmark href="https://another.website">
+ <title>another website</title>
+ </bookmark>
+ </folder>
+</xbel>