diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bookmarks/bookmarksform.ui | 129 | ||||
-rw-r--r-- | lib/bookmarks/bookmarkswidget.cpp | 138 | ||||
-rw-r--r-- | lib/bookmarks/bookmarkswidget.h | 50 | ||||
-rw-r--r-- | lib/bookmarks/forms/editbookmarkdialog.cpp | 70 | ||||
-rw-r--r-- | lib/bookmarks/forms/editbookmarkdialog.h | 44 | ||||
-rw-r--r-- | lib/bookmarks/forms/editbookmarkdialog.ui | 108 | ||||
-rw-r--r-- | lib/bookmarks/meson.build | 13 |
7 files changed, 5 insertions, 547 deletions
diff --git a/lib/bookmarks/bookmarksform.ui b/lib/bookmarks/bookmarksform.ui deleted file mode 100644 index a003e53..0000000 --- a/lib/bookmarks/bookmarksform.ui +++ /dev/null @@ -1,129 +0,0 @@ -<?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> - <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="headerDefaultSectionSize"> - <number>200</number> - </attribute> - <attribute name="headerMinimumSectionSize"> - <number>50</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/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp deleted file mode 100644 index 29e388c..0000000 --- a/lib/bookmarks/bookmarkswidget.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 "forms/editbookmarkdialog.h" -#include "ui_bookmarksform.h" -#include "bookmarkformat.h" -#include <QTreeView> -#include <QUrl> - -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); - } -} - -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; - QFile bookmarksFile(m_bookmarksPath); - if(bookmarksFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - BookmarkFormat<XbelFormat>(&bookmarksFile) >> model; - } - model->resetModified(); - - ui->treeView->setModel(model); - expandChildren(ui->treeView, model, QModelIndex()); - - // 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()); - }); -} - -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/lib/bookmarks/bookmarkswidget.h b/lib/bookmarks/bookmarkswidget.h deleted file mode 100644 index 149d2a6..0000000 --- a/lib/bookmarks/bookmarkswidget.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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/lib/bookmarks/forms/editbookmarkdialog.cpp b/lib/bookmarks/forms/editbookmarkdialog.cpp deleted file mode 100644 index 7df90b8..0000000 --- a/lib/bookmarks/forms/editbookmarkdialog.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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" - -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); - } -} diff --git a/lib/bookmarks/forms/editbookmarkdialog.h b/lib/bookmarks/forms/editbookmarkdialog.h deleted file mode 100644 index fb53239..0000000 --- a/lib/bookmarks/forms/editbookmarkdialog.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/lib/bookmarks/forms/editbookmarkdialog.ui b/lib/bookmarks/forms/editbookmarkdialog.ui deleted file mode 100644 index b988394..0000000 --- a/lib/bookmarks/forms/editbookmarkdialog.ui +++ /dev/null @@ -1,108 +0,0 @@ -<?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/lib/bookmarks/meson.build b/lib/bookmarks/meson.build index 78d0510..a7f603b 100644 --- a/lib/bookmarks/meson.build +++ b/lib/bookmarks/meson.build @@ -1,19 +1,16 @@ -bookmarks_inc = include_directories('.') bookmarks_moc = mod_qt5.preprocess( - moc_headers: ['bookmarkswidget.h', 'bookmarkmodel.h', 'forms/editbookmarkdialog.h'], - ui_files: ['bookmarksform.ui', 'forms/editbookmarkdialog.ui'], + moc_headers: [ 'bookmarkmodel.h' ], dependencies: dep_qt5 ) bookmarks_lib = static_library('bookmarks', - ['bookmarkswidget.cpp', bookmarks_moc, - 'bookmarksloader.cpp', 'formats/xbel.cpp', - 'bookmarkitem.cpp', 'bookmarkmodel.cpp', - 'forms/editbookmarkdialog.cpp'], + [ bookmarks_moc, + 'bookmarkformat.cpp', 'formats/xbel.cpp', + 'bookmarkitem.cpp', 'bookmarkmodel.cpp' ], dependencies: dep_qt5 ) dep_bookmarks = declare_dependency( - include_directories: bookmarks_inc, + include_directories: include_directories('.'), link_with: bookmarks_lib ) |