aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-24 17:16:23 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-24 17:16:23 +0100
commit426151664c6d81a1db0b95bb61a6e30feb2c9df3 (patch)
treed759d7dd0302d45bd0beb827e0e9d5a011ad246c /src
parentRequest filter now properly takes hostlists (diff)
downloadsmolbote-426151664c6d81a1db0b95bb61a6e30feb2c9df3.tar.xz
Address bar menu now reads entries from the bookmarks
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp3
-rw-r--r--src/lib/bookmarks/bookmarkswidget.cpp48
-rw-r--r--src/lib/bookmarks/bookmarkswidget.h9
-rw-r--r--src/lib/bookmarks/xbel.cpp4
-rw-r--r--src/lib/navigation/urllineedit.cpp17
-rw-r--r--src/lib/navigation/urllineedit.h4
-rw-r--r--src/mainwindow.h3
7 files changed, 62 insertions, 26 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index c21fced..f8f80f2 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -26,8 +26,7 @@ Browser::Browser(int &argc, char *argv[]) :
Browser::~Browser()
{
- // TODO: make sure all windows have saved their settings
- // TODO: save session
+ m_bookmarksManager->save();
}
void Browser::setConfiguration(std::shared_ptr<Configuration> &config)
diff --git a/src/lib/bookmarks/bookmarkswidget.cpp b/src/lib/bookmarks/bookmarkswidget.cpp
index d42732d..ce1e855 100644
--- a/src/lib/bookmarks/bookmarkswidget.cpp
+++ b/src/lib/bookmarks/bookmarkswidget.cpp
@@ -25,18 +25,16 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) :
QStyle *style = ui->treeWidget->style();
ui->addFolder_toolButton->setIcon(style->standardPixmap(QStyle::SP_DirIcon));
ui->addBookmark_toolButton->setIcon(style->standardPixmap(QStyle::SP_FileIcon));
- ui->addSeparator_toolButton->setText("---");
ui->deleteItem_toolButton->setIcon(style->standardPixmap(QStyle::SP_TrashIcon));
connect(ui->treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(showItemDetails()));
connect(ui->treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(openItem(QTreeWidgetItem*,int)));
ui->deleteItem_toolButton->setShortcut(QKeySequence::Delete);
- connect(ui->deleteItem_toolButton, SIGNAL(clicked(bool)), this, SLOT(deleteCurrentItem()));
m_path = path;
xbel = new Xbel(ui->treeWidget);
- xbel->read(m_path);
+ qDebug("Reading bookmarks [%s] %s", qUtf8Printable(m_path), xbel->read(m_path) ? "ok" : "failed");
connect(ui->addFolder_toolButton, &QToolButton::clicked, this, [&]() {
xbel->addFolder(ui->treeWidget->currentItem());
@@ -44,26 +42,50 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) :
connect(ui->addBookmark_toolButton, &QToolButton::clicked, this, [&]() {
xbel->addBookmark(ui->treeWidget->currentItem());
});
- connect(ui->addSeparator_toolButton, &QToolButton::clicked, this, [&]() {
- xbel->addSeparator(ui->treeWidget->currentItem());
+ connect(ui->deleteItem_toolButton, &QToolButton::clicked, this, [&]() {
+ delete ui->treeWidget->currentItem();
+ });
+
+ // editing bookmarks
+ connect(ui->title_lineEdit, &QLineEdit::returnPressed, this, [&]() {
+ ui->treeWidget->currentItem()->setText(0, ui->title_lineEdit->text());
+ });
+ connect(ui->href_lineEdit, &QLineEdit::returnPressed, this, [&]() {
+ ui->treeWidget->currentItem()->setText(1, ui->href_lineEdit->text());
});
}
BookmarksWidget::~BookmarksWidget()
{
- qDebug("Destroying BookmarksManager");
-
- if(ui->treeWidget->topLevelItemCount() > 0) {
- xbel->write(m_path);
- }
-
delete xbel;
delete ui;
}
-void BookmarksWidget::deleteCurrentItem()
+void BookmarksWidget::save()
+{
+ qDebug("Writing bookmarks [%s] %s", qUtf8Printable(m_path), xbel->write(m_path) ? "ok" : "failed");
+}
+
+QStringList BookmarksWidget::bookmarksFor(const QString &term)
+{
+ QStringList ret;
+ for(int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) {
+ ret += searchItem(ui->treeWidget->topLevelItem(i), term);
+ }
+ return ret;
+}
+
+QStringList BookmarksWidget::searchItem(QTreeWidgetItem *item, const QString &term)
{
- delete ui->treeWidget->currentItem();
+ if(item->text(1).contains(term)) {
+ return { item->text(1) };
+ }
+
+ QStringList ret;
+ for(int i = 0; i < item->childCount(); ++i) {
+ ret += searchItem(item->child(i), term);
+ }
+ return ret;
}
void BookmarksWidget::openItem(QTreeWidgetItem *item, int column)
diff --git a/src/lib/bookmarks/bookmarkswidget.h b/src/lib/bookmarks/bookmarkswidget.h
index 86852ff..da66cd0 100644
--- a/src/lib/bookmarks/bookmarkswidget.h
+++ b/src/lib/bookmarks/bookmarkswidget.h
@@ -24,20 +24,21 @@ public:
explicit BookmarksWidget(const QString &path, QWidget *parent = 0);
~BookmarksWidget();
+ void save();
+
signals:
void openUrl(const QUrl &url);
public slots:
- // void addFolder(const QString &title);
- // void addBookmark(const QString &title, const QString &href);
- // void addSeparator();
- void deleteCurrentItem();
+ QStringList bookmarksFor(const QString &term);
private slots:
void openItem(QTreeWidgetItem *item, int column);
void showItemDetails();
private:
+ QStringList searchItem(QTreeWidgetItem *item, const QString &term);
+
QString m_path;
Ui::BookmarksDialog *ui;
Xbel *xbel;
diff --git a/src/lib/bookmarks/xbel.cpp b/src/lib/bookmarks/xbel.cpp
index 8a5d857..24bdf5e 100644
--- a/src/lib/bookmarks/xbel.cpp
+++ b/src/lib/bookmarks/xbel.cpp
@@ -31,7 +31,6 @@ bool Xbel::read(const QString &xbel)
QFile file(xbel);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// file cannot be opened
- qDebug("Cannot open xbel: %s", qUtf8Printable(xbel));
return false;
}
@@ -77,6 +76,9 @@ bool Xbel::write(const QString &xbel)
}
xmlWriter.writeEndDocument();
+
+ file.flush();
+ file.close();
return true;
}
diff --git a/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp
index 5d20cef..03e0c0f 100644
--- a/src/lib/navigation/urllineedit.cpp
+++ b/src/lib/navigation/urllineedit.cpp
@@ -18,9 +18,15 @@
// ssl menu
#include <QLabel>
-UrlLineEdit::UrlLineEdit(QWidget *parent) :
+#include "mainwindow.h"
+#include "lib/bookmarks/bookmarkswidget.h"
+
+UrlLineEdit::UrlLineEdit(MainWindow *window, QWidget *parent) :
QLineEdit(parent)
{
+ Q_CHECK_PTR(window);
+ m_window = window;
+
setPlaceholderText(tr("Enter address"));
// ssl menu
@@ -58,8 +64,8 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
m_menu->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
listWidget = new QListWidget();
- listWidget->addItem("start.duckduckgo.com");
- listWidget->addItem("neueland.iserlohn-fortress.net");
+// listWidget->addItem("start.duckduckgo.com");
+// listWidget->addItem("neueland.iserlohn-fortress.net");
connect(listWidget, &QListWidget::itemSelectionChanged, this, [&]() {
setText(listWidget->currentItem()->text());
@@ -189,6 +195,9 @@ void UrlLineEdit::clearTextFormat()
void UrlLineEdit::showCompleter(const QString &text)
{
m_menu->move(mapToGlobal(QPoint(0, height())));
- //listWidget->setCurrentRow(0, QItemSelectionModel::SelectCurrent);
+ listWidget->clear();
+ for(const QString &url : m_window->m_bookmarksWidget->bookmarksFor(text)) {
+ listWidget->addItem(url);
+ }
m_menu->exec();
}
diff --git a/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h
index cef0830..1eea1ef 100644
--- a/src/lib/navigation/urllineedit.h
+++ b/src/lib/navigation/urllineedit.h
@@ -16,11 +16,12 @@
class QMenu;
class QLabel;
+class MainWindow;
class UrlLineEdit : public QLineEdit
{
Q_OBJECT
public:
- explicit UrlLineEdit(QWidget *parent = nullptr);
+ explicit UrlLineEdit(MainWindow *window, QWidget *parent = nullptr);
QAction *sslAction();
QAction *pageAction();
@@ -47,6 +48,7 @@ private:
QTextLayout::FormatRange m_hostFormat;
+ MainWindow *m_window;
QAction *m_sslAction = nullptr;
QAction *m_pageAction = nullptr;
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 7f5686f..01cdae0 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -15,7 +15,7 @@
#include "widgets/mainwindowtabbar.h"
#include "widgets/loadingbar.h"
-#include "navigation/navigationbutton.h"
+#include "lib/navigation/navigationbutton.h"
#include <memory>
@@ -38,6 +38,7 @@ class MainWindow : public QMainWindow
friend class WebView;
friend class SearchForm;
+ friend class UrlLineEdit;
public:
MainWindow(std::shared_ptr<Configuration> config, QWidget *parent = nullptr);