From c8980d95e8dcec0f4014adb7e81a29aa0ee9ed62 Mon Sep 17 00:00:00 2001 From: aqua Date: Tue, 13 Sep 2022 09:20:44 +0300 Subject: bugfix: don't wipe bookmarks if they're not modified --- src/application.cpp | 14 ++++++++++++-- src/bookmarks/bookmarkstreemodel.cpp | 8 +++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index efc1c2af..910e0bb5 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -102,7 +102,7 @@ struct BookmarksModelPrivate { BookmarksModelPrivate() { model = new BookmarkModel; - const auto path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/bookmarks.xbel"; + const auto path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/bookmarks.xbel"; spdlog::debug("Loading bookmarks from {}", qUtf8Printable(path)); QFile f(path); if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -110,7 +110,17 @@ struct BookmarksModelPrivate { f.close(); } } - ~BookmarksModelPrivate() noexcept { delete model; } + ~BookmarksModelPrivate() noexcept + { + const auto path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/bookmarks.xbel"; + spdlog::debug("Storing bookmarks in {}", qUtf8Printable(path)); + QFile f(path); + if (f.open(QIODevice::WriteOnly | QIODevice::Text)) { + model->save(&f); + f.close(); + } + delete model; + } BookmarkModel *model; }; diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp index 8086ff64..a4f322b8 100644 --- a/src/bookmarks/bookmarkstreemodel.cpp +++ b/src/bookmarks/bookmarkstreemodel.cpp @@ -193,7 +193,8 @@ QMimeData *BookmarkModel::mimeData(const QModelIndexList &indexes) const for (const QModelIndex &index : indexes) { if (index.isValid() && index.column() == 0) items.append(item(index)); } - xbel::write(&buffer, items); + const auto write_result = xbel::write(&buffer, items); + Q_ASSERT(write_result == false); auto *mimeData = new QMimeData; mimeData->setData(mimeType, data); @@ -212,7 +213,8 @@ bool BookmarkModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction actio buffer.open(QIODevice::ReadOnly | QIODevice::Text); auto *fake_root = new BookmarksTreeItem(BookmarksTreeItem::Root, {}, nullptr); - xbel::read(&buffer, fake_root); + const auto read_result = xbel::read(&buffer, fake_root); + Q_ASSERT(read_result.isEmpty()); const auto childCount = static_cast(fake_root->childCount()); auto *parentItem = item(parent); @@ -232,5 +234,5 @@ QList BookmarkModel::load(QIODevice *buffer) { return readFns[Formats:: void BookmarkModel::save(QIODevice *buffer) { if (!buffer->isOpen() || !buffer->isWritable()) return; - if (m_isModified) m_isModified = !writeFns[Formats::FormatXbel](buffer, {rootItem}); + m_isModified = !writeFns[Formats::FormatXbel](buffer, {rootItem}); } -- cgit v1.2.1