aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/bookmarksform.ui136
-rw-r--r--src/bookmarks/bookmarkswidget.cpp163
-rw-r--r--src/bookmarks/bookmarkswidget.h50
-rw-r--r--src/bookmarks/editbookmarkdialog.cpp74
-rw-r--r--src/bookmarks/editbookmarkdialog.h44
-rw-r--r--src/bookmarks/editbookmarkdialog.ui108
-rw-r--r--src/browser.cpp2
-rw-r--r--src/mainwindow/menubar.cpp2
-rw-r--r--src/meson.build8
9 files changed, 584 insertions, 3 deletions
diff --git a/src/bookmarks/bookmarksform.ui b/src/bookmarks/bookmarksform.ui
new file mode 100644
index 0000000..2dfebf4
--- /dev/null
+++ b/src/bookmarks/bookmarksform.ui
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>BookmarksDialog</class>
+ <widget class="QWidget" name="BookmarksDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>420</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Bookmarks</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QToolButton" name="import_toolButton">
+ <property name="text">
+ <string>Import</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QToolButton" name="addFolder_toolButton">
+ <property name="text">
+ <string>Add Folder</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="addBookmark_toolButton">
+ <property name="text">
+ <string>Add Bookmark</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="deleteItem_toolButton">
+ <property name="text">
+ <string>Delete Item</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTreeView" name="treeView">
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <property name="dragEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::DragDrop</enum>
+ </property>
+ <property name="defaultDropAction">
+ <enum>Qt::MoveAction</enum>
+ </property>
+ <attribute name="headerMinimumSectionSize">
+ <number>50</number>
+ </attribute>
+ <attribute name="headerDefaultSectionSize">
+ <number>200</number>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="bookmark_groupBox">
+ <property name="title">
+ <string>Edit Bookmark</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="bookmarkTitle_label">
+ <property name="text">
+ <string>Title</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="bookmarkHref_label">
+ <property name="text">
+ <string>Address</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="bookmarkTitle"/>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="bookmarkHref"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="folder_groupBox">
+ <property name="title">
+ <string>Edit Folder</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="folderTitle_label">
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="folderTitle"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/bookmarks/bookmarkswidget.cpp b/src/bookmarks/bookmarkswidget.cpp
new file mode 100644
index 0000000..bd2d607
--- /dev/null
+++ b/src/bookmarks/bookmarkswidget.cpp
@@ -0,0 +1,163 @@
+/*
+ * 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 "bookmarkswidget.h"
+#include "editbookmarkdialog.h"
+#include "ui_bookmarksform.h"
+#include "bookmarkformat.h"
+#include <QTreeView>
+#include <QUrl>
+#include <QFileDialog>
+
+inline void expandChildren(QTreeView *view, BookmarkModel *model, const QModelIndex &rootIndex)
+{
+ for(int i = 0; i < model->rowCount(rootIndex); ++i) {
+ QModelIndex idx = model->index(i, 0, rootIndex);
+ if(model->isItemExpanded(idx))
+ view->expand(idx);
+
+ // check if index has children
+ if(model->rowCount(idx) > 0)
+ expandChildren(view, model, idx);
+ }
+}
+
+inline void loadModel(const QString &path, BookmarkModel *model, QTreeView *view)
+{
+ view->setModel(nullptr);
+
+ if(path.endsWith(".xbel")) {
+ QFile f(path);
+ if(f.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ BookmarkFormat<XbelFormat>(&f) >> model;
+ f.close();
+ }
+
+ } else if(path.endsWith(".json")) {
+ QFile f(path);
+ if(f.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ BookmarkFormat<FirefoxJsonFormat>(&f) >> model;
+ f.close();
+ }
+ }
+
+ view->setModel(model);
+ expandChildren(view, model, QModelIndex());
+}
+
+BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::BookmarksDialog)
+{
+ // make sure this dialog does not get deleted on close
+ setAttribute(Qt::WA_DeleteOnClose, false);
+
+ ui->setupUi(this);
+ ui->bookmark_groupBox->setVisible(false);
+ ui->folder_groupBox->setVisible(false);
+
+ ui->addFolder_toolButton->setIcon(style()->standardPixmap(QStyle::SP_DirIcon));
+ ui->addBookmark_toolButton->setIcon(style()->standardPixmap(QStyle::SP_FileIcon));
+ ui->deleteItem_toolButton->setIcon(style()->standardPixmap(QStyle::SP_TrashIcon));
+ ui->deleteItem_toolButton->setShortcut(QKeySequence::Delete);
+
+ model = new BookmarkModel(this);
+ m_bookmarksPath = path;
+ loadModel(path, model, ui->treeView);
+
+ // item activated
+ connect(ui->treeView, &QTreeView::activated, this, [this](const QModelIndex &index) {
+ if(index.column() == 1)
+ emit openUrl(index.data(Qt::DisplayRole).toUrl());
+ else
+ editBookmark(index);
+ });
+
+ connect(ui->treeView, &QTreeView::expanded, this, [this](const QModelIndex &index) {
+ model->setItemExpanded(index, true);
+ });
+ connect(ui->treeView, &QTreeView::collapsed, this, [this](const QModelIndex &index) {
+ model->setItemExpanded(index, false);
+ });
+
+ ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(ui->treeView, &QTreeView::customContextMenuRequested, this, [this](const QPoint &pos) {
+ const QModelIndex idx = ui->treeView->indexAt(pos);
+ if(idx.isValid()) {
+ const QUrl url = model->data(idx, 1, Qt::DisplayRole).toUrl();
+ const QPoint _pos = ui->treeView->viewport()->mapToGlobal(pos);
+
+ emit showContextMenu(url, _pos);
+ }
+ });
+
+ // addBookmark
+ connect(ui->addBookmark_toolButton, &QToolButton::clicked, this, [this]() {
+ const QModelIndex idx = model->parentFolder(ui->treeView->currentIndex());
+ const QModelIndex childIdx = model->appendBookmark(tr("Title"), QString(), idx);
+ ui->treeView->setCurrentIndex(childIdx);
+ editBookmark(childIdx);
+ });
+
+ // addFolder
+ connect(ui->addFolder_toolButton, &QToolButton::clicked, this, [this]() {
+ const QModelIndex idx = model->parentFolder(ui->treeView->currentIndex());
+ const QModelIndex childIdx = model->appendFolder(tr("Title"), idx);
+ ui->treeView->setCurrentIndex(childIdx);
+ editBookmark(childIdx);
+ });
+
+ // deleteItem
+ connect(ui->deleteItem_toolButton, &QToolButton::clicked, this, [this]() {
+ const QModelIndex idx = ui->treeView->currentIndex();
+ model->removeRow(idx.row(), idx.parent());
+ });
+
+ // import button
+ connect(ui->import_toolButton, &QToolButton::clicked, this, [this]() {
+ const auto path = QFileDialog::getOpenFileName(this, tr("Open bookmarks file"), QDir::homePath(), tr("Firefox bookmarks backup (*.json)"));
+ if(!path.isEmpty()) {
+ loadModel(path, model, ui->treeView);
+ }
+ });
+}
+
+BookmarksWidget::~BookmarksWidget()
+{
+ delete ui;
+}
+
+void BookmarksWidget::editBookmark(const QModelIndex &index)
+{
+ auto *dlg = new EditBookmarkDialog(model, index, this);
+ dlg->exec();
+}
+
+void BookmarksWidget::save()
+{
+ if(!model->isModified())
+ return;
+
+ QFile bookmarksFile(m_bookmarksPath);
+ if(bookmarksFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ BookmarkFormat<XbelFormat> f(&bookmarksFile);
+ model >> f;
+ bookmarksFile.flush();
+ }
+}
+
+void BookmarksWidget::addBookmark(const QString &title, const QString &url)
+{
+ model->appendBookmark(title, url, QModelIndex());
+}
+
+void BookmarksWidget::search(const QString &term, const std::function<void(QStringList &)> &callback) const
+{
+ QStringList ret = model->search(term);
+ callback(ret);
+}
diff --git a/src/bookmarks/bookmarkswidget.h b/src/bookmarks/bookmarkswidget.h
new file mode 100644
index 0000000..149d2a6
--- /dev/null
+++ b/src/bookmarks/bookmarkswidget.h
@@ -0,0 +1,50 @@
+/*
+ * 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 BOOKMARKSDIALOG_H
+#define BOOKMARKSDIALOG_H
+
+#include <QFile>
+#include <QShortcut>
+#include <QWidget>
+#include <functional>
+
+namespace Ui
+{
+class BookmarksDialog;
+}
+
+class BookmarksView;
+class BookmarkModel;
+class BookmarksWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit BookmarksWidget(const QString &path, QWidget *parent = nullptr);
+ ~BookmarksWidget() override;
+
+protected:
+ void editBookmark(const QModelIndex &index);
+
+signals:
+ void showContextMenu(const QUrl &url, const QPoint &pos);
+ void openUrl(const QUrl &url);
+
+public slots:
+ void save();
+ void addBookmark(const QString &title, const QString &url);
+ void search(const QString &term, const std::function<void(QStringList &)> &callback) const;
+
+private:
+ Ui::BookmarksDialog *ui;
+ QString m_bookmarksPath;
+ BookmarkModel *model;
+};
+
+#endif // BOOKMARKSDIALOG_H
diff --git a/src/bookmarks/editbookmarkdialog.cpp b/src/bookmarks/editbookmarkdialog.cpp
new file mode 100644
index 0000000..4461840
--- /dev/null
+++ b/src/bookmarks/editbookmarkdialog.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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 "editbookmarkdialog.h"
+#include "bookmarkitem.h"
+#include "bookmarkmodel.h"
+#include "ui_editbookmarkdialog.h"
+#include <QDateTime>
+
+EditBookmarkDialog::EditBookmarkDialog(BookmarkModel *model, const QModelIndex &index, QWidget *parent)
+ : QDialog(parent)
+ , ui(new Ui::EditBookmarkDialog)
+{
+ ui->setupUi(this);
+ setAttribute(Qt::WA_DeleteOnClose, true);
+
+ Q_CHECK_PTR(model);
+ m_model = model;
+ m_index = index;
+
+ ui->title->setText(model->data(index, BookmarkItem::Title, Qt::DisplayRole).toString());
+ connect(ui->title, &QLineEdit::editingFinished, this, [this]() {
+ titleChanged = true;
+ });
+
+ ui->address->setText(model->data(index, BookmarkItem::Href, Qt::DisplayRole).toString());
+ connect(ui->address, &QLineEdit::editingFinished, this, [this]() {
+ hrefChanged = true;
+ });
+
+ ui->tags->setText(model->data(index, BookmarkItem::Tags, Qt::DisplayRole).toStringList().join(", "));
+ connect(ui->tags, &QLineEdit::editingFinished, this, [this]() {
+ tagsChanged = true;
+ });
+
+ ui->description->setPlainText(model->data(index, BookmarkItem::Description, Qt::DisplayRole).toString());
+ connect(ui->description, &QPlainTextEdit::textChanged, this, [this]() {
+ descriptionChanged = true;
+ });
+
+ connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &EditBookmarkDialog::saveChanges);
+}
+
+EditBookmarkDialog::~EditBookmarkDialog()
+{
+ delete ui;
+}
+
+void EditBookmarkDialog::saveChanges()
+{
+ if(titleChanged) {
+ m_model->setData(m_index, ui->title->text(), BookmarkItem::Title, Qt::DisplayRole);
+ }
+
+ if(hrefChanged) {
+ m_model->setData(m_index, ui->address->text(), BookmarkItem::Href, Qt::DisplayRole);
+ }
+
+ if(tagsChanged) {
+ m_model->setData(m_index, ui->tags->text().split(", "), BookmarkItem::Tags, Qt::DisplayRole);
+ }
+
+ if(descriptionChanged) {
+ m_model->setData(m_index, ui->description->toPlainText(), BookmarkItem::Description, Qt::DisplayRole);
+ }
+
+ if(titleChanged || hrefChanged || tagsChanged || descriptionChanged)
+ m_model->setData(m_index, QDateTime::currentDateTime(), BookmarkItem::LastModified, Qt::DisplayRole);
+}
diff --git a/src/bookmarks/editbookmarkdialog.h b/src/bookmarks/editbookmarkdialog.h
new file mode 100644
index 0000000..fb53239
--- /dev/null
+++ b/src/bookmarks/editbookmarkdialog.h
@@ -0,0 +1,44 @@
+/*
+ * 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 SMOLBOTE_EDITBOOKMARKDIALOG_H
+#define SMOLBOTE_EDITBOOKMARKDIALOG_H
+
+#include <QDialog>
+#include <QModelIndex>
+
+namespace Ui
+{
+class EditBookmarkDialog;
+}
+
+class BookmarkModel;
+class EditBookmarkDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit EditBookmarkDialog(BookmarkModel *model, const QModelIndex &index, QWidget *parent = nullptr);
+ ~EditBookmarkDialog() override;
+
+public slots:
+ void saveChanges();
+
+private:
+ Ui::EditBookmarkDialog *ui;
+
+ BookmarkModel *m_model;
+ QModelIndex m_index;
+
+ bool titleChanged = false;
+ bool hrefChanged = false;
+ bool tagsChanged = false;
+ bool descriptionChanged = false;
+};
+
+#endif // SMOLBOTE_EDITBOOKMARKDIALOG_H
diff --git a/src/bookmarks/editbookmarkdialog.ui b/src/bookmarks/editbookmarkdialog.ui
new file mode 100644
index 0000000..b988394
--- /dev/null
+++ b/src/bookmarks/editbookmarkdialog.ui
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>EditBookmarkDialog</class>
+ <widget class="QDialog" name="EditBookmarkDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>320</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Edit Bookmark</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="title_label">
+ <property name="text">
+ <string>Title</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="title"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="address_label">
+ <property name="text">
+ <string>Address</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="address"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="tags_label">
+ <property name="text">
+ <string>Tags</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="tags"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="description_label">
+ <property name="text">
+ <string>Description</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QPlainTextEdit" name="description"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>EditBookmarkDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>EditBookmarkDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/browser.cpp b/src/browser.cpp
index 42cde5e..488131e 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -10,7 +10,7 @@
#include "aboutdialog.h"
#include "aboutplugin.h"
#include "adblock/adblocklist.h"
-#include "bookmarkswidget.h"
+#include "bookmarks/bookmarkswidget.h"
#include "configuration.h"
#include "downloadswidget.h"
#include "hostlist/hostlist.h"
diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp
index 7fdad24..a8d0590 100644
--- a/src/mainwindow/menubar.cpp
+++ b/src/mainwindow/menubar.cpp
@@ -7,7 +7,7 @@
*/
#include "menubar.h"
-#include "bookmarkswidget.h"
+#include "bookmarks/bookmarkswidget.h"
#include "browser.h"
#include "configuration.h"
#include "downloadswidget.h"
diff --git a/src/meson.build b/src/meson.build
index 6d6a1aa..1783455 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -10,10 +10,14 @@ poi_settings_h = custom_target('default_config_value',
poi_sourceset.add(mod_qt5.preprocess(
moc_headers: ['browser.h',
'mainwindow/mainwindow.h', 'mainwindow/addressbar.h', 'mainwindow/menubar.h', 'mainwindow/widgets/completer.h', 'mainwindow/widgets/urllineedit.h', 'mainwindow/widgets/dockwidget.h', 'mainwindow/widgets/menusearch.h', 'mainwindow/widgets/navigationbar.h', 'mainwindow/widgets/searchform.h',
+ 'bookmarks/bookmarkswidget.h', 'bookmarks/editbookmarkdialog.h',
'session/savesessiondialog.h', 'session/sessiondialog.h', 'session/sessionform.h',
'subwindow/subwindow.h', 'subwindow/tabwidget.h',
'webengine/urlinterceptor.h', 'webengine/webpage.h', 'webengine/webview.h', 'webengine/webprofilemanager.h', 'webengine/webprofile.h'],
- ui_files: ['mainwindow/addressbar.ui', 'mainwindow/widgets/searchform.ui', 'session/savesessiondialog.ui', 'session/sessiondialog.ui', 'session/sessionform.ui'],
+ ui_files: [
+ 'mainwindow/addressbar.ui', 'mainwindow/widgets/searchform.ui',
+ 'bookmarks/bookmarksform.ui', 'bookmarks/editbookmarkdialog.ui',
+ 'session/savesessiondialog.ui', 'session/sessiondialog.ui', 'session/sessionform.ui'],
qresources: '../data/resources.qrc',
rcc_extra_arguments: ['--format-version=1'],
dependencies: dep_qt5
@@ -34,6 +38,8 @@ poi_sourceset.add(files(
'mainwindow/widgets/navigationbar.cpp',
'mainwindow/widgets/searchform.cpp',
+ 'bookmarks/bookmarkswidget.cpp', 'bookmarks/editbookmarkdialog.cpp',
+
'session/session.cpp',
'session/savesessiondialog.cpp',
'session/sessiondialog.cpp',