aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/bookmarkswidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bookmarks/bookmarkswidget.cpp')
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
index 5e0e391..8711b35 100644
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -35,10 +35,18 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
ui->treeView->setDragDropMode(QAbstractItemView::InternalMove);
ui->treeView->setDropIndicatorShown(true);
- m_bookmarksFile.setFileName(path);
- m_bookmarksFile.open(QIODevice::ReadWrite | QIODevice::Text);
- xbel = new Xbel(&m_bookmarksFile);
- qDebug("Reading bookmarks [%s] %s", qUtf8Printable(path), m_model->read(xbel) ? "ok" : "failed");
+ m_bookmarksPath = path;
+
+ // read bookmarks
+ {
+ QFile bookmarksFile(m_bookmarksPath);
+ if (bookmarksFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ Xbel xbel(&bookmarksFile);
+ qDebug("Reading bookmarks [%s] %s", qUtf8Printable(path), m_model->read(&xbel) ? "ok" : "failed");
+ bookmarksFile.close();
+ }
+ }
+
m_model->expandItems(ui->treeView);
// open bookmark action
@@ -58,6 +66,14 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
m_model->insertItem(BookmarkItem::Folder, idx);
});
+ connect(ui->deleteItem_toolButton, &QToolButton::clicked, this, [this]() {
+ QModelIndex idx = ui->treeView->currentIndex();
+ ui->treeView->clearSelection();
+ ui->folder_groupBox->setVisible(false);
+ ui->bookmark_groupBox->setVisible(false);
+ m_model->removeItem(idx);
+ });
+
// set folder title action
connect(ui->folderTitle, &QLineEdit::returnPressed, this, [this]() {
QModelIndex idx = ui->treeView->currentIndex();
@@ -82,7 +98,7 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
// set item action
connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this](const QModelIndex &current, const QModelIndex &previous) {
// save the previous item
- if(previous.isValid()) {
+ if(previous.isValid() && (ui->folder_groupBox->isVisible() || ui->bookmark_groupBox->isVisible())) {
if(m_model->type(previous) == BookmarkItem::Folder) {
m_model->setData(previous, ui->folderTitle->text(), BookmarksModel::TitleRole);
ui->folder_groupBox->setVisible(false);
@@ -108,17 +124,23 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
BookmarksWidget::~BookmarksWidget()
{
- m_bookmarksFile.close();
- delete xbel;
delete ui;
}
void BookmarksWidget::save()
{
- if(m_model->isModified())
- qDebug("Writing bookmarks %s", m_model->write(xbel) ? "ok" : "failed");
- else
+ if(!m_model->isModified()) {
qDebug("Writing bookmarks skipped");
+ return;
+ }
+
+ QFile bookmarksFile(m_bookmarksPath);
+ if(bookmarksFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ Xbel xbel(&bookmarksFile);
+ qDebug("Writing bookmarks %s", m_model->write(&xbel) ? "ok" : "failed");
+ bookmarksFile.flush();
+ bookmarksFile.close();
+ }
}
QAbstractItemModel *BookmarksWidget::model() const