aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/bookmarkswidget.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-01-11 17:30:38 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-01-11 17:30:38 +0100
commit5d0adf426a33440542eb88eca83c804dcec58475 (patch)
tree34358c8039c2f6cb2a121a169374dc4a7a21b614 /lib/bookmarks/bookmarkswidget.cpp
parentRemoved docs (moved to site) (diff)
downloadsmolbote-5d0adf426a33440542eb88eca83c804dcec58475.tar.xz
Writing BookmarksModel to xbel
Diffstat (limited to 'lib/bookmarks/bookmarkswidget.cpp')
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp27
1 files changed, 4 insertions, 23 deletions
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
index 27f00c3..575f52f 100644
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -32,10 +32,8 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
ui->treeView->setModel(m_model);
xbel = new Xbel(path);
- BookmarkItem *rootNode = xbel->read();
- m_model->setRoot(rootNode);
- expandNodes(rootNode);
- //qDebug("Reading bookmarks [%s] %s", qUtf8Printable(m_path), xbel->read(m_path) ? "ok" : "failed");
+ qDebug("Reading bookmarks [%s] %s", qUtf8Printable(path), m_model->read(xbel) ? "ok" : "failed");
+ m_model->expandItems(ui->treeView);
connect(ui->treeView, &QTreeView::activated, this, [this](const QModelIndex &index) {
if(ui->treeView->isPersistentEditorOpen(index))
@@ -67,8 +65,8 @@ BookmarksWidget::~BookmarksWidget()
void BookmarksWidget::save()
{
- // TODO: check if saving is needed
- //qDebug("Writing bookmarks [%s] %s", qUtf8Printable(m_path), xbel->write(m_path) ? "ok" : "failed");
+ if(m_model->isModified())
+ qDebug("Writing bookmarks %s", m_model->write(xbel) ? "ok" : "failed");
}
QAbstractItemModel *BookmarksWidget::model() const
@@ -77,23 +75,6 @@ QAbstractItemModel *BookmarksWidget::model() const
return m_model;
}
-void BookmarksWidget::expandNodes(BookmarkItem *node)
-{
- // iterate through children
- for(int i = 0; i < node->childCount(); ++i) {
- BookmarkItem *childNode = node->child(i);
-
- // and if it's a folder
- if(childNode->type() == BookmarkItem::Folder) {
- QModelIndex index = m_model->index(childNode);
- ui->treeView->setExpanded(index, !childNode->folded);
-
- // only folders have children, so go through them
- expandNodes(childNode);
- }
- }
-}
-
void BookmarksWidget::closeOthers()
{
emit closeOthersSignal();