aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-01-03 16:39:32 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-01-03 16:39:32 +0100
commit85d9f14aa8bac16ab341662c770b64a15c21628b (patch)
tree422db18e798646cd4bc98abf342f25c09c0bdf1d /lib
parentDownload items' width should no longer exceed the list width (diff)
downloadsmolbote-85d9f14aa8bac16ab341662c770b64a15c21628b.tar.xz
Changed from qbs to cmake
Diffstat (limited to 'lib')
-rw-r--r--lib/bookmarks/CMakeLists.txt10
-rw-r--r--lib/bookmarks/bookmarksform.ui104
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp112
-rw-r--r--lib/bookmarks/bookmarkswidget.h49
-rw-r--r--lib/bookmarks/xbel.cpp193
-rw-r--r--lib/bookmarks/xbel.h45
-rw-r--r--lib/downloads/CMakeLists.txt13
-rw-r--r--lib/downloads/downloadsform.ui24
-rw-r--r--lib/downloads/downloadswidget.cpp91
-rw-r--r--lib/downloads/downloadswidget.h38
-rw-r--r--lib/downloads/widgets/downloaditemform.ui74
-rw-r--r--lib/downloads/widgets/downloaditemwidget.cpp103
-rw-r--r--lib/downloads/widgets/downloaditemwidget.h43
-rw-r--r--lib/downloads/widgets/elidedlabel.cpp85
-rw-r--r--lib/downloads/widgets/elidedlabel.h85
-rw-r--r--lib/navigation/CMakeLists.txt11
-rw-r--r--lib/navigation/navigationbutton.cpp141
-rw-r--r--lib/navigation/navigationbutton.h49
-rw-r--r--lib/navigation/urlcompleter.cpp26
-rw-r--r--lib/navigation/urlcompleter.h25
-rw-r--r--lib/navigation/urllineedit.cpp136
-rw-r--r--lib/navigation/urllineedit.h59
-rw-r--r--lib/settings/CMakeLists.txt10
-rw-r--r--lib/settings/configuration.cpp4
-rw-r--r--lib/settings/settings.qbs38
25 files changed, 1530 insertions, 38 deletions
diff --git a/lib/bookmarks/CMakeLists.txt b/lib/bookmarks/CMakeLists.txt
new file mode 100644
index 0000000..8fb7f45
--- /dev/null
+++ b/lib/bookmarks/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1.0)
+
+add_library(bookmarks
+ bookmarksform.ui
+ bookmarkswidget.cpp
+ bookmarkswidget.h
+ xbel.cpp
+ xbel.h)
+
+target_link_libraries(bookmarks Qt5::Widgets) \ No newline at end of file
diff --git a/lib/bookmarks/bookmarksform.ui b/lib/bookmarks/bookmarksform.ui
new file mode 100644
index 0000000..2df0c4b
--- /dev/null
+++ b/lib/bookmarks/bookmarksform.ui
@@ -0,0 +1,104 @@
+<?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="minimumSize">
+ <size>
+ <width>420</width>
+ <height>600</height>
+ </size>
+ </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="addFolder_toolButton">
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="addBookmark_toolButton">
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="addSeparator_toolButton">
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="deleteItem_toolButton">
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTreeWidget" name="treeWidget">
+ <property name="dragEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::InternalMove</enum>
+ </property>
+ <property name="defaultDropAction">
+ <enum>Qt::MoveAction</enum>
+ </property>
+ <column>
+ <property name="text">
+ <string notr="true">Title</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>href</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Details</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="1" column="0">
+ <widget class="QLabel" name="href_label">
+ <property name="text">
+ <string>href</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="href_lineEdit"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="title_lineEdit"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
new file mode 100644
index 0000000..cb191c7
--- /dev/null
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -0,0 +1,112 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "bookmarkswidget.h"
+#include "ui_bookmarksform.h"
+#include <QTreeWidget>
+#include <QUrl>
+
+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);
+ setWindowTitle(tr("Bookmarks"));
+
+ ui->setupUi(this);
+ ui->treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch);
+
+ QStyle *style = ui->treeWidget->style();
+ 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));
+
+ 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);
+
+ m_path = path;
+ xbel = new Xbel(ui->treeWidget);
+ 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());
+ });
+ connect(ui->addBookmark_toolButton, &QToolButton::clicked, this, [&]() {
+ xbel->addBookmark(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()
+{
+ delete xbel;
+ delete ui;
+}
+
+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;
+}
+
+QAbstractItemModel *BookmarksWidget::model() const
+{
+ return ui->treeWidget->model();
+}
+
+QStringList BookmarksWidget::searchItem(QTreeWidgetItem *item, const QString &term)
+{
+ 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)
+{
+ Q_UNUSED(column)
+ emit openUrl(QUrl::fromUserInput(item->text(1)));
+}
+
+void BookmarksWidget::showItemDetails()
+{
+ QTreeWidgetItem *item = ui->treeWidget->currentItem();
+ if(!item) {
+ ui->title_lineEdit->setText("");
+ ui->href_label->setText("");
+ return;
+ }
+ ui->title_lineEdit->setText(item->text(0));
+ ui->href_lineEdit->setText(item->text(1));
+}
diff --git a/lib/bookmarks/bookmarkswidget.h b/lib/bookmarks/bookmarkswidget.h
new file mode 100644
index 0000000..aa188b2
--- /dev/null
+++ b/lib/bookmarks/bookmarkswidget.h
@@ -0,0 +1,49 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef BOOKMARKSDIALOG_H
+#define BOOKMARKSDIALOG_H
+
+#include <QWidget>
+#include "xbel.h"
+#include <QAbstractItemModel>
+
+namespace Ui {
+class BookmarksDialog;
+}
+
+class BookmarksWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit BookmarksWidget(const QString &path, QWidget *parent = 0);
+ ~BookmarksWidget();
+
+ void save();
+
+signals:
+ void openUrl(const QUrl &url);
+
+public slots:
+ QStringList bookmarksFor(const QString &term);
+ QAbstractItemModel *model() const;
+
+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;
+};
+
+#endif // BOOKMARKSDIALOG_H
diff --git a/lib/bookmarks/xbel.cpp b/lib/bookmarks/xbel.cpp
new file mode 100644
index 0000000..523ed99
--- /dev/null
+++ b/lib/bookmarks/xbel.cpp
@@ -0,0 +1,193 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "xbel.h"
+#include <QFile>
+
+#include <QTreeWidgetItem>
+
+Xbel::Xbel(QTreeWidget *widget)
+{
+ treeWidget = widget;
+
+ QStyle *style = treeWidget->style();
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On);
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off);
+ bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon));
+}
+
+bool Xbel::read(const QString &xbel)
+{
+ // no file specified
+ if(xbel.isEmpty()) {
+ return false;
+ }
+
+ QFile file(xbel);
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ // file cannot be opened
+ return false;
+ }
+
+ xmlReader.setDevice(&file);
+
+ if(xmlReader.readNextStartElement()) {
+ if(xmlReader.name() == "xbel" && xmlReader.attributes().value("version") == "1.0") {
+ qDebug("valid xbel");
+ readChildElements(0);
+ } else {
+ qDebug("invalid xbel");
+ return false;
+ }
+
+ }
+ return true;
+}
+
+bool Xbel::write(const QString &xbel)
+{
+ // no file specified
+ if(xbel.isEmpty()) {
+ return false;
+ }
+
+ QFile file(xbel);
+ if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ // file cannot be opened
+ qDebug("Cannot open xbel: %s", qUtf8Printable(xbel));
+ return false;
+ }
+
+ xmlWriter.setAutoFormatting(true);
+ xmlWriter.setDevice(&file);
+
+ xmlWriter.writeStartDocument();
+ xmlWriter.writeDTD("<!DOCTYPE xbel>");
+ xmlWriter.writeStartElement("xbel");
+ xmlWriter.writeAttribute("version", "1.0");
+
+ for(int i=0; i<treeWidget->topLevelItemCount(); i++) {
+ writeItem(treeWidget->topLevelItem(i));
+ }
+
+ xmlWriter.writeEndDocument();
+
+ file.flush();
+ file.close();
+ return true;
+}
+
+void Xbel::readChildElements(QTreeWidgetItem *parentItem)
+{
+ while(xmlReader.readNextStartElement()) {
+ if(xmlReader.name() == "title") {
+ readTitle(parentItem);
+ } else if(xmlReader.name() == "folder") {
+ QTreeWidgetItem *item = addFolder(parentItem);
+ item->setText(1, xmlReader.attributes().value("href").toString());
+ readChildElements(item);
+ } else if(xmlReader.name() == "bookmark") {
+ QTreeWidgetItem *item = addBookmark(parentItem);
+ item->setText(1, xmlReader.attributes().value("href").toString());
+ readChildElements(item);
+ } else if(xmlReader.name() == "separator") {
+ addSeparator(parentItem);
+ xmlReader.skipCurrentElement();
+ } else {
+ xmlReader.skipCurrentElement();
+ }
+ }
+}
+
+void Xbel::readTitle(QTreeWidgetItem *item)
+{
+ item->setText(0, xmlReader.readElementText());
+}
+
+QTreeWidgetItem *Xbel::addFolder(QTreeWidgetItem *parentItem)
+{
+ QTreeWidgetItem *folderItem = createChildItem(parentFolder(parentItem), "folder");
+ //folderItem->setExpanded(xmlReader.attributes().value("folded") != "no");
+ treeWidget->setItemExpanded(folderItem, xmlReader.attributes().value("folded") != "yes");
+ folderItem->setFlags(folderItem->flags() | Qt::ItemIsEditable);
+ folderItem->setIcon(0, folderIcon);
+
+ return folderItem;
+}
+
+QTreeWidgetItem *Xbel::addBookmark(QTreeWidgetItem *parentItem)
+{
+ QTreeWidgetItem *bookmarkItem = createChildItem(parentFolder(parentItem), "bookmark");
+ bookmarkItem->setFlags((bookmarkItem->flags() | Qt::ItemIsEditable) & ~Qt::ItemIsDropEnabled);
+ bookmarkItem->setIcon(0, bookmarkIcon);
+ bookmarkItem->setText(0, "Unknown Title");
+ bookmarkItem->setText(1, "Unknown Address");
+
+ return bookmarkItem;
+}
+
+void Xbel::addSeparator(QTreeWidgetItem *parentItem)
+{
+ QTreeWidgetItem *separatorItem = createChildItem(parentFolder(parentItem), "separator");
+ separatorItem->setFlags(separatorItem->flags() & ~Qt::ItemIsDropEnabled);
+ separatorItem->setText(0, "-----");
+}
+
+QTreeWidgetItem *Xbel::parentFolder(QTreeWidgetItem *item)
+{
+ QTreeWidgetItem *parentItem = item;
+
+ if(parentItem) {
+ while(parentItem->data(0, Qt::UserRole) != "folder") {
+ parentItem = parentItem->parent();
+ if(parentItem == 0) {
+ break;
+ }
+ }
+ }
+
+ return parentItem;
+}
+
+QTreeWidgetItem *Xbel::createChildItem(QTreeWidgetItem *item, const QString &type)
+{
+ QTreeWidgetItem *childItem;
+ if(item) {
+ childItem = new QTreeWidgetItem(item);
+ } else {
+ childItem = new QTreeWidgetItem(treeWidget);
+ }
+ childItem->setData(0, Qt::UserRole, type);
+ return childItem;
+}
+
+void Xbel::writeItem(QTreeWidgetItem *item)
+{
+ QString tagName = item->data(0, Qt::UserRole).toString();
+ if (tagName == "folder") {
+ xmlWriter.writeStartElement(tagName);
+ if(!item->text(1).isEmpty()) {
+ xmlWriter.writeAttribute("href", item->text(1));
+ }
+ xmlWriter.writeAttribute("folded", treeWidget->isItemExpanded(item) ? "no" : "yes");
+ xmlWriter.writeTextElement("title", item->text(0));
+ for (int i = 0; i < item->childCount(); ++i) {
+ writeItem(item->child(i));
+ }
+ xmlWriter.writeEndElement();
+ } else if (tagName == "bookmark") {
+ xmlWriter.writeStartElement(tagName);
+ if (!item->text(1).isEmpty()) {
+ xmlWriter.writeAttribute("href", item->text(1));
+ }
+ xmlWriter.writeTextElement("title", item->text(0));
+ xmlWriter.writeEndElement();
+ } else if (tagName == "separator") {
+ xmlWriter.writeEmptyElement(tagName);
+ }
+}
diff --git a/lib/bookmarks/xbel.h b/lib/bookmarks/xbel.h
new file mode 100644
index 0000000..ed0a256
--- /dev/null
+++ b/lib/bookmarks/xbel.h
@@ -0,0 +1,45 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef XBELREADER_H
+#define XBELREADER_H
+
+#include <QXmlStreamReader>
+#include <QIcon>
+
+class QTreeWidget;
+class QTreeWidgetItem;
+class Xbel
+{
+public:
+ explicit Xbel(QTreeWidget *widget);
+ bool read(const QString &xbel);
+ bool write(const QString &xbel);
+
+ QTreeWidgetItem *addFolder(QTreeWidgetItem *parentItem);
+ QTreeWidgetItem *addBookmark(QTreeWidgetItem *parentItem);
+ void addSeparator(QTreeWidgetItem *parentItem);
+
+private:
+ void readChildElements(QTreeWidgetItem *parentItem);
+ void readTitle(QTreeWidgetItem *item);
+
+ QTreeWidgetItem *parentFolder(QTreeWidgetItem *item);
+ QTreeWidgetItem *createChildItem(QTreeWidgetItem *item, const QString &type);
+
+ void writeItem(QTreeWidgetItem *item);
+
+ QIcon folderIcon;
+ QIcon bookmarkIcon;
+
+ QTreeWidget *treeWidget;
+ QXmlStreamReader xmlReader;
+ QXmlStreamWriter xmlWriter;
+};
+
+#endif // XBELREADER_H
diff --git a/lib/downloads/CMakeLists.txt b/lib/downloads/CMakeLists.txt
new file mode 100644
index 0000000..ca67f0a
--- /dev/null
+++ b/lib/downloads/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.1.0)
+
+add_library(downloads
+ downloadsform.ui
+ downloadswidget.cpp
+ downloadswidget.h
+ widgets/downloaditemform.ui
+ widgets/downloaditemwidget.cpp
+ widgets/downloaditemwidget.h
+ widgets/elidedlabel.cpp
+ widgets/elidedlabel.h)
+
+target_link_libraries(downloads Qt5::Widgets Qt5::WebEngineWidgets) \ No newline at end of file
diff --git a/lib/downloads/downloadsform.ui b/lib/downloads/downloadsform.ui
new file mode 100644
index 0000000..43a0d49
--- /dev/null
+++ b/lib/downloads/downloadsform.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DownloadDialog</class>
+ <widget class="QWidget" name="DownloadDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>420</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Downloads</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QListWidget" name="listWidget"/>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/lib/downloads/downloadswidget.cpp b/lib/downloads/downloadswidget.cpp
new file mode 100644
index 0000000..f9a8f34
--- /dev/null
+++ b/lib/downloads/downloadswidget.cpp
@@ -0,0 +1,91 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "downloadswidget.h"
+#include "ui_downloadsform.h"
+
+#include <QWebEngineDownloadItem>
+#include <QUrl>
+#include <QFileDialog>
+#include <QListWidget>
+#include <QLabel>
+#include "widgets/downloaditemwidget.h"
+
+DownloadsWidget::DownloadsWidget(const QString &downloadPath, QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::DownloadDialog)
+{
+ // make sure this dialog does not get deleted on close
+ setAttribute(Qt::WA_DeleteOnClose, false);
+ setWindowTitle(tr("Downloads"));
+
+ ui->setupUi(this);
+
+ m_downloadPath = downloadPath;
+
+ connect(ui->listWidget, &QListWidget::currentItemChanged, this, [this](QListWidgetItem *current, QListWidgetItem *previous) {
+ DownloadItemWidget *currentWidget = qobject_cast<DownloadItemWidget*>(ui->listWidget->itemWidget(current));
+ currentWidget->showDetails();
+ currentWidget->setFixedWidth(ui->listWidget->viewport()->width());
+ currentWidget->adjustSize();
+ current->setSizeHint(currentWidget->size());
+
+ DownloadItemWidget *previousWidget = qobject_cast<DownloadItemWidget*>(ui->listWidget->itemWidget(previous));
+ if(previousWidget != nullptr) {
+ previousWidget->hideDetails();
+ previousWidget->setFixedWidth(ui->listWidget->viewport()->width());
+ previousWidget->adjustSize();
+ previous->setSizeHint(previousWidget->size());
+ }
+ });
+}
+
+DownloadsWidget::~DownloadsWidget()
+{
+ delete ui;
+}
+
+void DownloadsWidget::addDownload(QWebEngineDownloadItem *item)
+{
+ this->show();
+
+ QString filepath = QFileDialog::getSaveFileName(this,
+ tr("Save"),
+ m_downloadPath + "/" + QFileInfo(item->path()).fileName());
+
+ if(filepath.isEmpty()) {
+ // user cancelled the save dialog
+ item->cancel();
+ return;
+ }
+
+ item->setPath(filepath);
+
+ QListWidgetItem *listItem = new QListWidgetItem();
+ int rowIndex = ui->listWidget->count();
+ ui->listWidget->insertItem(rowIndex, listItem);
+
+ DownloadItemWidget *form = new DownloadItemWidget(item, this);
+ ui->listWidget->setItemWidget(listItem, form);
+
+ item->accept();
+
+ ui->listWidget->setCurrentRow(rowIndex);
+}
+
+void DownloadsWidget::resizeEvent(QResizeEvent *event)
+{
+ QWidget::resizeEvent(event);
+
+ for(int i = 0; i < ui->listWidget->count(); ++i) {
+ QWidget *w = ui->listWidget->itemWidget(ui->listWidget->item(i));
+ w->setFixedWidth(ui->listWidget->viewport()->width());
+ w->adjustSize();
+ ui->listWidget->item(i)->setSizeHint(w->size());
+ }
+}
diff --git a/lib/downloads/downloadswidget.h b/lib/downloads/downloadswidget.h
new file mode 100644
index 0000000..8c9ea21
--- /dev/null
+++ b/lib/downloads/downloadswidget.h
@@ -0,0 +1,38 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef DOWNLOADDIALOG_H
+#define DOWNLOADDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class DownloadDialog;
+}
+
+class QWebEngineDownloadItem;
+class DownloadsWidget : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit DownloadsWidget(const QString &downloadPath, QWidget *parent = nullptr);
+ ~DownloadsWidget();
+
+public slots:
+ void addDownload(QWebEngineDownloadItem *item);
+
+protected:
+ void resizeEvent(QResizeEvent *event) override;
+
+private:
+ Ui::DownloadDialog *ui;
+ QString m_downloadPath;
+};
+
+#endif // DOWNLOADDIALOG_H
diff --git a/lib/downloads/widgets/downloaditemform.ui b/lib/downloads/widgets/downloaditemform.ui
new file mode 100644
index 0000000..17f1d6a
--- /dev/null
+++ b/lib/downloads/widgets/downloaditemform.ui
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DownloadItemForm</class>
+ <widget class="QWidget" name="DownloadItemForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>500</width>
+ <height>122</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="ElidedLabel" name="url_label">
+ <property name="text">
+ <string>[url]</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="value">
+ <number>24</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="detailsWidget" native="true">
+ <layout class="QVBoxLayout" name="detailsLayout">
+ <item>
+ <widget class="QLabel" name="status_label">
+ <property name="text">
+ <string>status_label</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="path_label">
+ <property name="text">
+ <string>path_label</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>ElidedLabel</class>
+ <extends>QLabel</extends>
+ <header>widgets/elidedlabel.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp
new file mode 100644
index 0000000..fff3cfc
--- /dev/null
+++ b/lib/downloads/widgets/downloaditemwidget.cpp
@@ -0,0 +1,103 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "downloaditemwidget.h"
+#include "ui_downloaditemform.h"
+
+#include <QUrl>
+#include <QLabel>
+
+DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::DownloadItemForm)
+{
+ m_item = item;
+
+ ui->setupUi(this);
+
+ ui->url_label->setContent(item->url().toString());
+ ui->detailsWidget->hide();
+
+ ui->path_label->setText(item->path());
+
+ connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState);
+ connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress);
+ connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished);
+}
+
+DownloadItemWidget::~DownloadItemWidget()
+{
+ delete ui;
+}
+
+void DownloadItemWidget::showDetails()
+{
+ ui->detailsWidget->show();
+}
+
+void DownloadItemWidget::hideDetails()
+{
+ ui->detailsWidget->hide();
+}
+
+QWebEngineDownloadItem *DownloadItemWidget::item() const
+{
+ return m_item;
+}
+
+QString DownloadItemWidget::sizeString(int size) const
+{
+ if(size < 1024) {
+ return QString("%1 bytes").arg(size);
+ }
+ // KiB
+ if(size < 1024 * 1024) {
+ return QString("%1 kB").arg(size / 1024);
+ }
+ // MiB
+ if(size < 1024 * 1024 * 1024) {
+ return QString("%1 MB").arg(size / (1024 * 1024));
+ }
+ // GiB
+ return QString("%1 GB").arg(size / (1024 * 1024 * 1024));
+}
+
+void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state)
+{
+ switch (state) {
+ case QWebEngineDownloadItem::DownloadRequested:
+ ui->status_label->setText(tr("Requested"));
+ break;
+ case QWebEngineDownloadItem::DownloadInProgress:
+ ui->status_label->setText(tr("In progress"));
+ break;
+ case QWebEngineDownloadItem::DownloadCompleted:
+ ui->status_label->setText(tr("Completed"));
+ break;
+ case QWebEngineDownloadItem::DownloadCancelled:
+ ui->status_label->setText(tr("Cancelled"));
+ break;
+ case QWebEngineDownloadItem::DownloadInterrupted:
+ ui->status_label->setText(tr("Interrupted"));
+ break;
+ default:
+ break;
+ }
+}
+
+void DownloadItemWidget::updateProgress(qint64 value, qint64 total)
+{
+ ui->progressBar->setMaximum(total);
+ ui->progressBar->setValue(value);
+ ui->progressBar->setFormat(QString("%1 / %2").arg(sizeString(value), sizeString(total)));
+}
+
+void DownloadItemWidget::updateFinished()
+{
+ ui->progressBar->setValue(ui->progressBar->maximum());
+}
diff --git a/lib/downloads/widgets/downloaditemwidget.h b/lib/downloads/widgets/downloaditemwidget.h
new file mode 100644
index 0000000..c6246da
--- /dev/null
+++ b/lib/downloads/widgets/downloaditemwidget.h
@@ -0,0 +1,43 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef DOWNLOADITEMFORM_H
+#define DOWNLOADITEMFORM_H
+
+#include <QWidget>
+#include <QWebEngineDownloadItem>
+
+namespace Ui {
+class DownloadItemForm;
+}
+
+class DownloadItemWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0);
+ ~DownloadItemWidget();
+
+ void showDetails();
+ void hideDetails();
+
+ QWebEngineDownloadItem *item() const;
+ QString sizeString(int size) const;
+
+private slots:
+ void updateState(QWebEngineDownloadItem::DownloadState state);
+ void updateProgress(qint64 value, qint64 total);
+ void updateFinished();
+
+private:
+ Ui::DownloadItemForm *ui;
+ QWebEngineDownloadItem *m_item;
+};
+
+#endif // DOWNLOADITEMFORM_H
diff --git a/lib/downloads/widgets/elidedlabel.cpp b/lib/downloads/widgets/elidedlabel.cpp
new file mode 100644
index 0000000..dc17d32
--- /dev/null
+++ b/lib/downloads/widgets/elidedlabel.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "elidedlabel.h"
+
+#include <QPainter>
+#include <QTextLayout>
+#include <QDebug>
+
+ElidedLabel::ElidedLabel(QWidget *parent)
+ : QLabel(parent)
+ , elided(false)
+ , content("elided_label")
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+}
+
+void ElidedLabel::setContent(const QString &newText)
+{
+ content = newText;
+ setText(newText);
+}
+
+void ElidedLabel::resizeEvent(QResizeEvent *event)
+{
+ QLabel::resizeEvent(event);
+
+ QFontMetrics font = this->fontMetrics();
+ QString elidedLine = font.elidedText(content, Qt::ElideRight, width());
+ setText(elidedLine);
+}
diff --git a/lib/downloads/widgets/elidedlabel.h b/lib/downloads/widgets/elidedlabel.h
new file mode 100644
index 0000000..d0f6221
--- /dev/null
+++ b/lib/downloads/widgets/elidedlabel.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef ELIDEDLABEL_H
+#define ELIDEDLABEL_H
+
+#include <QLabel>
+
+class ElidedLabel : public QLabel
+{
+
+public:
+ explicit ElidedLabel(QWidget *parent = nullptr);
+
+ void setContent(const QString &text);
+ const QString & text() const {
+ return content;
+ }
+ bool isElided() const {
+ return elided;
+ }
+
+protected:
+ void resizeEvent(QResizeEvent *event) override;
+
+private:
+ bool elided;
+ QString content;
+};
+
+#endif // ELIDEDLABEL_H
diff --git a/lib/navigation/CMakeLists.txt b/lib/navigation/CMakeLists.txt
new file mode 100644
index 0000000..4a4cf94
--- /dev/null
+++ b/lib/navigation/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.1.0)
+
+add_library(navigation
+ navigationbutton.cpp
+ navigationbutton.h
+ urlcompleter.cpp
+ urlcompleter.h
+ urllineedit.cpp
+ urllineedit.h)
+
+target_link_libraries(navigation Qt5::Widgets Qt5::WebEngineWidgets) \ No newline at end of file
diff --git a/lib/navigation/navigationbutton.cpp b/lib/navigation/navigationbutton.cpp
new file mode 100644
index 0000000..13daebc
--- /dev/null
+++ b/lib/navigation/navigationbutton.cpp
@@ -0,0 +1,141 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "navigationbutton.h"
+
+#include <QStyle>
+#include <QWebEngineHistory>
+#include <QMenu>
+
+NavigationButton::NavigationButton(Type type, QWidget *parent) :
+ QToolButton(parent)
+{
+ m_type = type;
+ menu = new QMenu(this);
+
+ switch (type) {
+ case BackButton:
+ setIcon(style()->standardIcon(QStyle::SP_ArrowBack));
+ setMenu(menu);
+ connect(menu, &QMenu::aboutToShow, this, &NavigationButton::prepareMenu);
+ break;
+ case ForwardButton:
+ setIcon(style()->standardIcon(QStyle::SP_ArrowForward));
+ setMenu(menu);
+ connect(menu, &QMenu::aboutToShow, this, &NavigationButton::prepareMenu);
+ break;
+ case ReloadButton:
+ setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
+ break;
+ case StopButton:
+ setIcon(style()->standardIcon(QStyle::SP_BrowserStop));
+ break;
+ }
+
+ connect(this, &NavigationButton::clicked, this, &NavigationButton::doAction);
+
+}
+
+
+void NavigationButton::setView(WebView *view)
+{
+ disconnect(loadStartedConnection);
+ disconnect(loadFinishedConnection);
+
+ m_view = view;
+ if(m_type == BackButton || m_type == ForwardButton) {
+ updateOnLoadFinished();
+ }
+
+ loadStartedConnection = connect(view, &WebView::loadStarted, this, &NavigationButton::updateOnLoadStarted);
+ loadFinishedConnection = connect(view, &WebView::loadFinished, this, &NavigationButton::updateOnLoadFinished);
+}
+
+void NavigationButton::updateOnLoadStarted()
+{
+ switch (m_type) {
+ case BackButton:
+ break;
+ case ForwardButton:
+ break;
+ case ReloadButton:
+ m_type = StopButton;
+ setIcon(style()->standardIcon(QStyle::SP_BrowserStop));
+ break;
+ case StopButton:
+ break;
+ }
+}
+
+void NavigationButton::updateOnLoadFinished()
+{
+ switch (m_type) {
+ case BackButton:
+ if(m_view->history()->canGoBack()) {
+ setEnabled(true);
+ } else {
+ setEnabled(false);
+ }
+ break;
+ case ForwardButton:
+ if(m_view->history()->canGoForward()) {
+ setEnabled(true);
+ } else {
+ setEnabled(false);
+ }
+ break;
+ case ReloadButton:
+ break;
+ case StopButton:
+ m_type = ReloadButton;
+ setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
+ break;
+ }
+}
+
+void NavigationButton::doAction()
+{
+ switch (m_type) {
+ case BackButton:
+ m_view->history()->back();
+ break;
+ case ForwardButton:
+ m_view->history()->forward();
+ break;
+ case ReloadButton:
+ m_view->reload();
+ break;
+ case StopButton:
+ m_view->stop();
+ break;
+ }
+}
+
+void NavigationButton::prepareMenu()
+{
+ menu->clear();
+
+ QList<QWebEngineHistoryItem> items;
+ switch (m_type) {
+ case BackButton:
+ items = m_view->history()->backItems(10);
+ break;
+ case ForwardButton:
+ items = m_view->history()->forwardItems(10);
+ break;
+ default:
+ break;
+ }
+
+ for(QWebEngineHistoryItem i : items) {
+ QAction *a = menu->addAction(i.title());
+ connect(a, &QAction::triggered, [i, this]() {
+ m_view->history()->goToItem(i);
+ });
+ }
+}
diff --git a/lib/navigation/navigationbutton.h b/lib/navigation/navigationbutton.h
new file mode 100644
index 0000000..7c76b9c
--- /dev/null
+++ b/lib/navigation/navigationbutton.h
@@ -0,0 +1,49 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef NAVIGATIONBUTTON_H
+#define NAVIGATIONBUTTON_H
+
+#include <QToolButton>
+#include "../../src/webengine/webview.h"
+
+class QMenu;
+
+class NavigationButton : public QToolButton
+{
+ Q_OBJECT
+public:
+
+ enum Type {
+ BackButton,
+ ForwardButton,
+ ReloadButton,
+ StopButton
+ };
+
+ explicit NavigationButton(Type type, QWidget *parent = nullptr);
+
+ void setView(WebView *view);
+
+signals:
+
+private slots:
+ void updateOnLoadStarted();
+ void updateOnLoadFinished();
+ void doAction();
+ void prepareMenu();
+
+private:
+ Type m_type;
+ QMenu *menu;
+ WebView *m_view;
+
+ QMetaObject::Connection loadStartedConnection, loadFinishedConnection;
+};
+
+#endif // NAVIGATIONBUTTON_H
diff --git a/lib/navigation/urlcompleter.cpp b/lib/navigation/urlcompleter.cpp
new file mode 100644
index 0000000..bbde297
--- /dev/null
+++ b/lib/navigation/urlcompleter.cpp
@@ -0,0 +1,26 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "urlcompleter.h"
+
+UrlCompleter::UrlCompleter(QAbstractItemModel *model, QObject *parent) :
+ QCompleter(model, parent)
+{
+ setCompletionMode(QCompleter::PopupCompletion);
+ setFilterMode(Qt::MatchContains);
+}
+
+QStringList UrlCompleter::splitPath(const QString &path) const
+{
+ return path.split('.');
+}
+
+QString UrlCompleter::pathFromIndex(const QModelIndex &index) const
+{
+ return model()->data(index, completionRole()).toString();
+}
diff --git a/lib/navigation/urlcompleter.h b/lib/navigation/urlcompleter.h
new file mode 100644
index 0000000..f2c52ff
--- /dev/null
+++ b/lib/navigation/urlcompleter.h
@@ -0,0 +1,25 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef URLCOMPLETER_H
+#define URLCOMPLETER_H
+
+#include <QCompleter>
+
+class UrlCompleter : public QCompleter
+{
+ Q_OBJECT
+public:
+ explicit UrlCompleter(QAbstractItemModel *model, QObject *parent = nullptr);
+
+protected:
+ QStringList splitPath(const QString &path) const override;
+ QString pathFromIndex(const QModelIndex &index) const override;
+};
+
+#endif // URLCOMPLETER_H
diff --git a/lib/navigation/urllineedit.cpp b/lib/navigation/urllineedit.cpp
new file mode 100644
index 0000000..24924bb
--- /dev/null
+++ b/lib/navigation/urllineedit.cpp
@@ -0,0 +1,136 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "urllineedit.h"
+#include <QUrl>
+#include <QTimer>
+#include <QMenu>
+#include <QAction>
+#include <QStyle>
+
+#include <QWidgetAction>
+
+// ssl menu
+#include <QLabel>
+
+#include "../bookmarks/bookmarkswidget.h"
+
+#include <QCompleter>
+
+UrlLineEdit::UrlLineEdit(QWidget *parent) :
+ QLineEdit(parent)
+{
+ setPlaceholderText(tr("Enter address"));
+
+ // ssl menu
+ m_sslMenu = new QMenu(this);
+ m_sslLabel = new QLabel(m_sslMenu);
+ QWidgetAction *sslErrorAction = new QWidgetAction(m_sslMenu);
+ sslErrorAction->setDefaultWidget(m_sslLabel);
+ m_sslMenu->addAction(sslErrorAction);
+
+ m_sslAction = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
+ m_sslAction->setToolTip(tr("TODO: Display SSL Status popup here"));
+ m_sslAction->setMenu(m_sslMenu);
+
+ connect(m_sslAction, &QAction::triggered, this, [this]() {
+ m_sslMenu->exec(this->mapToGlobal(QPoint(0, height())));
+ });
+
+ m_pageAction = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
+ m_pageAction->setShortcut(QKeySequence("F10"));
+ m_pageAction->setToolTip(tr("Page Actions"));
+ connect(m_pageAction, &QAction::triggered, m_pageAction, [&]() {
+ //this->deselect();
+ if(m_pageAction->menu() != nullptr) {
+ m_pageAction->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
+ }
+ });
+
+ QTextCharFormat hostnameFormat;
+ hostnameFormat.setFontWeight(QFont::Bold);
+ m_hostFormat.format = hostnameFormat;
+
+ // connect signals
+ connect(this, &QLineEdit::returnPressed, [this]() {
+ if(this->text().startsWith('#')) {
+ emit searchTermEntered(this->text().mid(1));
+ } else {
+ emit addressEntered(QUrl::fromUserInput(this->text()));
+ }
+ this->clearFocus();
+ });
+
+}
+
+QAction *UrlLineEdit::sslAction()
+{
+ Q_CHECK_PTR(m_sslAction);
+ return m_sslAction;
+}
+
+QAction *UrlLineEdit::pageAction()
+{
+ Q_CHECK_PTR(m_pageAction);
+ return m_pageAction;
+}
+
+void UrlLineEdit::setCompleterModel(QAbstractItemModel *model)
+{
+ Q_CHECK_PTR(model);
+ m_completer = new UrlCompleter(model, this);
+ m_completer->setCompletionColumn(1);
+ this->setCompleter(m_completer);
+}
+
+void UrlLineEdit::setUrl(const QUrl &url)
+{
+ QString urlText = url.toString();
+ QString domain = url.host();
+
+ m_hostFormat.start = urlText.indexOf(domain);
+ m_hostFormat.length = domain.length();
+
+ clear();
+ clearTextFormat();
+ setTextFormat(m_hostFormat);
+ setText(urlText);
+}
+
+void UrlLineEdit::showSslError(const QString &message)
+{
+ m_sslLabel->setText(message);
+ m_sslAction->trigger();
+}
+
+void UrlLineEdit::focusInEvent(QFocusEvent *event)
+{
+ clearTextFormat();
+
+ QLineEdit::focusInEvent(event);
+
+ // select the contents when receiving focus
+ // http://stackoverflow.com/a/35725950/1054406
+ // mousePressEvent triggers right after focusInEvent so text selected in focusInEvent unselects by mousePressEvent
+ //QTimer::singleShot(0, this, SLOT(selectAll()));
+}
+
+// formatting taken from: https://forum.qt.io/topic/60962/setting-qlineedit-text-bold
+void UrlLineEdit::setTextFormat(const QTextLayout::FormatRange &format)
+{
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, format.start, format.length, format.format));
+ QInputMethodEvent ev(QString(), attributes);
+ event(&ev);
+
+}
+
+void UrlLineEdit::clearTextFormat()
+{
+ setTextFormat(QTextLayout::FormatRange());
+}
diff --git a/lib/navigation/urllineedit.h b/lib/navigation/urllineedit.h
new file mode 100644
index 0000000..46366a7
--- /dev/null
+++ b/lib/navigation/urllineedit.h
@@ -0,0 +1,59 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef URLLINEEDIT_H
+#define URLLINEEDIT_H
+
+#include <QLineEdit>
+#include <QTextLayout>
+#include <QAction>
+
+#include "urlcompleter.h"
+
+class QAbstractItemModel;
+class QMenu;
+class QLabel;
+class UrlLineEdit : public QLineEdit
+{
+ Q_OBJECT
+public:
+ explicit UrlLineEdit(QWidget *parent = nullptr);
+
+ QAction *sslAction();
+ QAction *pageAction();
+
+ void setCompleterModel(QAbstractItemModel *model);
+
+signals:
+ void addressEntered(const QUrl &url);
+ void searchTermEntered(const QString &term);
+
+public slots:
+ void setUrl(const QUrl &url);
+ void showSslError(const QString &message);
+
+protected:
+ void focusInEvent(QFocusEvent *event);
+
+private:
+ void setTextFormat(const QTextLayout::FormatRange &format);
+ void clearTextFormat();
+
+ QTextLayout::FormatRange m_hostFormat;
+
+ QAction *m_sslAction = nullptr;
+ QAction *m_pageAction = nullptr;
+
+ // ssl menu
+ QMenu *m_sslMenu;
+ QLabel *m_sslLabel;
+
+ UrlCompleter *m_completer;
+};
+
+#endif // URLLINEEDIT_H
diff --git a/lib/settings/CMakeLists.txt b/lib/settings/CMakeLists.txt
new file mode 100644
index 0000000..704c40f
--- /dev/null
+++ b/lib/settings/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1.0)
+
+add_library(configuration
+ configuration.cpp
+ configuration.h
+ settingsdialog.cpp
+ settingsdialog.h
+ settingsdialog.ui)
+
+target_link_libraries(configuration Qt5::Widgets) \ No newline at end of file
diff --git a/lib/settings/configuration.cpp b/lib/settings/configuration.cpp
index 34d50db..4603779 100644
--- a/lib/settings/configuration.cpp
+++ b/lib/settings/configuration.cpp
@@ -214,6 +214,8 @@ void Configuration::setValue(std::string path, const T &val)
// compiler complained about operator= not taking unsinged ints, longs and long longs
if constexpr(std::is_unsigned_v<T> && !std::is_same_v<T, bool>) {
setting = static_cast<typename std::make_signed_t<T>>(val);
+ } else if constexpr(std::is_same_v<T, std::string>) {
+ setting = static_cast<std::string>(val).c_str();
} else {
setting = val;
}
@@ -240,6 +242,8 @@ void Configuration::setValue(std::string path, const T &val)
if constexpr(std::is_unsigned_v<T> && !std::is_same_v<T, bool>) {
*userSetting = static_cast<typename std::make_signed_t<T>>(val);
+ } else if constexpr(std::is_same_v<T, std::string>) {
+ *userSetting = static_cast<std::string>(val).c_str();
} else {
*userSetting = val;
}
diff --git a/lib/settings/settings.qbs b/lib/settings/settings.qbs
deleted file mode 100644
index 0559daa..0000000
--- a/lib/settings/settings.qbs
+++ /dev/null
@@ -1,38 +0,0 @@
-import qbs
-
-Project {
- name: "Settings"
-
- StaticLibrary {
- name: "settings"
-
- Depends { name: "cpp" }
-
- cpp.defines: "C_LIKE_CONFIG"
- cpp.cxxLanguageVersion: "c++17"
-
- files: [
- "configuration.cpp",
- "configuration.h"
- ]
- }
-
- StaticLibrary {
- name: "settingsDialog"
-
- Depends { name: "cpp" }
-
- Depends {
- name: "Qt"
- submodules: ["core", "widgets"]
- }
-
- cpp.cxxLanguageVersion: "c++17"
-
- files: [
- "settingsdialog.cpp",
- "settingsdialog.h",
- "settingsdialog.ui",
- ]
- }
-}