From 85d9f14aa8bac16ab341662c770b64a15c21628b Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 3 Jan 2018 16:39:32 +0100 Subject: Changed from qbs to cmake --- src/forms/aboutdialog.cpp | 37 +++-- src/forms/aboutdialog.h | 2 - src/interfaces.h | 41 ----- src/lib/bookmarks/bookmarks.qbs | 25 --- src/lib/bookmarks/bookmarksform.ui | 104 ------------ src/lib/bookmarks/bookmarkswidget.cpp | 112 ------------- src/lib/bookmarks/bookmarkswidget.h | 49 ------ src/lib/bookmarks/xbel.cpp | 193 ----------------------- src/lib/bookmarks/xbel.h | 45 ------ src/lib/downloads/downloads.qbs | 28 ---- src/lib/downloads/downloadsform.ui | 24 --- src/lib/downloads/downloadswidget.cpp | 91 ----------- src/lib/downloads/downloadswidget.h | 38 ----- src/lib/downloads/widgets/downloaditemform.ui | 74 --------- src/lib/downloads/widgets/downloaditemwidget.cpp | 103 ------------ src/lib/downloads/widgets/downloaditemwidget.h | 43 ----- src/lib/downloads/widgets/elidedlabel.cpp | 85 ---------- src/lib/downloads/widgets/elidedlabel.h | 85 ---------- src/lib/navigation/navigation.qbs | 26 --- src/lib/navigation/navigationbutton.cpp | 141 ----------------- src/lib/navigation/navigationbutton.h | 49 ------ src/lib/navigation/urlcompleter.cpp | 26 --- src/lib/navigation/urlcompleter.h | 25 --- src/lib/navigation/urllineedit.cpp | 136 ---------------- src/lib/navigation/urllineedit.h | 59 ------- src/main.cpp | 1 + src/settings.cpp | 182 --------------------- src/settings.h | 47 ------ src/version.h.in | 7 + src/webengine/webview.h | 2 +- 30 files changed, 33 insertions(+), 1847 deletions(-) delete mode 100644 src/interfaces.h delete mode 100644 src/lib/bookmarks/bookmarks.qbs delete mode 100644 src/lib/bookmarks/bookmarksform.ui delete mode 100644 src/lib/bookmarks/bookmarkswidget.cpp delete mode 100644 src/lib/bookmarks/bookmarkswidget.h delete mode 100644 src/lib/bookmarks/xbel.cpp delete mode 100644 src/lib/bookmarks/xbel.h delete mode 100644 src/lib/downloads/downloads.qbs delete mode 100644 src/lib/downloads/downloadsform.ui delete mode 100644 src/lib/downloads/downloadswidget.cpp delete mode 100644 src/lib/downloads/downloadswidget.h delete mode 100644 src/lib/downloads/widgets/downloaditemform.ui delete mode 100644 src/lib/downloads/widgets/downloaditemwidget.cpp delete mode 100644 src/lib/downloads/widgets/downloaditemwidget.h delete mode 100644 src/lib/downloads/widgets/elidedlabel.cpp delete mode 100644 src/lib/downloads/widgets/elidedlabel.h delete mode 100644 src/lib/navigation/navigation.qbs delete mode 100644 src/lib/navigation/navigationbutton.cpp delete mode 100644 src/lib/navigation/navigationbutton.h delete mode 100644 src/lib/navigation/urlcompleter.cpp delete mode 100644 src/lib/navigation/urlcompleter.h delete mode 100644 src/lib/navigation/urllineedit.cpp delete mode 100644 src/lib/navigation/urllineedit.h delete mode 100644 src/settings.cpp delete mode 100644 src/settings.h create mode 100644 src/version.h.in (limited to 'src') diff --git a/src/forms/aboutdialog.cpp b/src/forms/aboutdialog.cpp index 25c5384..3f89118 100644 --- a/src/forms/aboutdialog.cpp +++ b/src/forms/aboutdialog.cpp @@ -8,6 +8,28 @@ #include "aboutdialog.h" #include "ui_aboutdialog.h" +#include "version.h" + +constexpr const char *getCompiler() +{ + // clang also defines __GNUC__, so we need to check for clang first +#if defined(__clang__) + return "Clang " __clang_version__; +#elif defined(__GNUC__) + return "GCC " __VERSION__; +#else + return "unknown compiler"; +#endif +} + +inline const QString getLongVersion() +{ +#ifdef GIT_DESCRIBE + return QString(GIT_DESCRIBE); +#else + return qApp->applicationVersion(); +#endif +} AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), @@ -22,7 +44,7 @@ AboutDialog::AboutDialog(QWidget *parent) : aboutLabel->setWordWrap(true); aboutLabel->setText(tr("

smolbote %1

" "

yet another Qute browser

") - .arg(qApp->applicationVersion().left(qApp->applicationVersion().indexOf('-')))); + .arg(qApp->applicationVersion())); ui->toolBox->addItem(aboutLabel, tr("About")); QLabel *licenseLabel = new QLabel(this); @@ -50,7 +72,7 @@ AboutDialog::AboutDialog(QWidget *parent) : "
  • Qt %3
  • " "
  • libconfig
  • " "

    ") - .arg(qApp->applicationVersion(), getCompiler(), qVersion())); + .arg(getLongVersion(), getCompiler(), qVersion())); ui->toolBox->addItem(libsLabel, tr("Details")); } @@ -58,14 +80,3 @@ AboutDialog::~AboutDialog() { delete ui; } - -constexpr const char *getCompiler() -{ -#if defined(__clang__) - return "Clang " __clang_version__; -#elif defined(__GNUC__) - return "GCC " __VERSION__; -#else - return "unknown compiler"; -#endif -} diff --git a/src/forms/aboutdialog.h b/src/forms/aboutdialog.h index ba848e7..9f2189e 100644 --- a/src/forms/aboutdialog.h +++ b/src/forms/aboutdialog.h @@ -27,6 +27,4 @@ private: Ui::AboutDialog *ui; }; -constexpr const char* getCompiler(); - #endif // ABOUTDIALOG_H diff --git a/src/interfaces.h b/src/interfaces.h deleted file mode 100644 index f42b513..0000000 --- a/src/interfaces.h +++ /dev/null @@ -1,41 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef INTERFACES_H -#define INTERFACES_H - -#include - -class QString; -class QWidget; -class QAction; - -class PluginInterface -{ -public: - virtual QString name() const = 0; -}; - -class GuiInterface -{ -public: - // The widget that should be displayed for this plugin - virtual QWidget *widget() = 0; - // The action that should trigger displaying the widget - virtual QAction *action() = 0; -}; - -#define PluginInterface_iid "net.iserlohn-fortress.poi.PluginInterface" - -Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid) - -#define GuiInterface_iid "net.iserlohn-fortress.poi.GuiInterface" - -Q_DECLARE_INTERFACE(GuiInterface, GuiInterface_iid) - -#endif // INTERFACES_H diff --git a/src/lib/bookmarks/bookmarks.qbs b/src/lib/bookmarks/bookmarks.qbs deleted file mode 100644 index 211b017..0000000 --- a/src/lib/bookmarks/bookmarks.qbs +++ /dev/null @@ -1,25 +0,0 @@ -import qbs 1.0 - -Project { - name: "bookmarks" - - StaticLibrary { - id: bookmarks - name: "bookmarks" - - cpp.includePaths: ['../..'] - - Depends { - name: "Qt" - submodules: ["core", "widgets"] - } - - files: [ - "bookmarksform.ui", - "bookmarkswidget.cpp", - "bookmarkswidget.h", - "xbel.cpp", - "xbel.h", - ] - } -} diff --git a/src/lib/bookmarks/bookmarksform.ui b/src/lib/bookmarks/bookmarksform.ui deleted file mode 100644 index 2df0c4b..0000000 --- a/src/lib/bookmarks/bookmarksform.ui +++ /dev/null @@ -1,104 +0,0 @@ - - - BookmarksDialog - - - - 0 - 0 - 420 - 600 - - - - - 420 - 600 - - - - Bookmarks - - - - - - - - ... - - - - - - - ... - - - - - - - ... - - - - - - - ... - - - - - - - - - true - - - QAbstractItemView::InternalMove - - - Qt::MoveAction - - - - Title - - - - - href - - - - - - - - Details - - - - - - href - - - - - - - - - - - - - - - - - diff --git a/src/lib/bookmarks/bookmarkswidget.cpp b/src/lib/bookmarks/bookmarkswidget.cpp deleted file mode 100644 index cb191c7..0000000 --- a/src/lib/bookmarks/bookmarkswidget.cpp +++ /dev/null @@ -1,112 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "bookmarkswidget.h" -#include "ui_bookmarksform.h" -#include -#include - -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/src/lib/bookmarks/bookmarkswidget.h b/src/lib/bookmarks/bookmarkswidget.h deleted file mode 100644 index aa188b2..0000000 --- a/src/lib/bookmarks/bookmarkswidget.h +++ /dev/null @@ -1,49 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef BOOKMARKSDIALOG_H -#define BOOKMARKSDIALOG_H - -#include -#include "xbel.h" -#include - -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/src/lib/bookmarks/xbel.cpp b/src/lib/bookmarks/xbel.cpp deleted file mode 100644 index 523ed99..0000000 --- a/src/lib/bookmarks/xbel.cpp +++ /dev/null @@ -1,193 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "xbel.h" -#include - -#include - -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(""); - xmlWriter.writeStartElement("xbel"); - xmlWriter.writeAttribute("version", "1.0"); - - for(int i=0; itopLevelItemCount(); 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/src/lib/bookmarks/xbel.h b/src/lib/bookmarks/xbel.h deleted file mode 100644 index ed0a256..0000000 --- a/src/lib/bookmarks/xbel.h +++ /dev/null @@ -1,45 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef XBELREADER_H -#define XBELREADER_H - -#include -#include - -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/src/lib/downloads/downloads.qbs b/src/lib/downloads/downloads.qbs deleted file mode 100644 index bdb18ad..0000000 --- a/src/lib/downloads/downloads.qbs +++ /dev/null @@ -1,28 +0,0 @@ -import qbs 1.0 - -Project { - name: "downloads" - - StaticLibrary { - id: downloads - name: "downloads" - - cpp.includePaths: ['.', '../..'] - - Depends { - name: "Qt" - submodules: ["core", "widgets", "webenginewidgets"] - } - - files: [ - "downloadsform.ui", - "downloadswidget.cpp", - "downloadswidget.h", - "widgets/downloaditemform.ui", - "widgets/downloaditemwidget.cpp", - "widgets/downloaditemwidget.h", - "widgets/elidedlabel.cpp", - "widgets/elidedlabel.h", - ] - } -} diff --git a/src/lib/downloads/downloadsform.ui b/src/lib/downloads/downloadsform.ui deleted file mode 100644 index 43a0d49..0000000 --- a/src/lib/downloads/downloadsform.ui +++ /dev/null @@ -1,24 +0,0 @@ - - - DownloadDialog - - - - 0 - 0 - 600 - 420 - - - - Downloads - - - - - - - - - - diff --git a/src/lib/downloads/downloadswidget.cpp b/src/lib/downloads/downloadswidget.cpp deleted file mode 100644 index f9a8f34..0000000 --- a/src/lib/downloads/downloadswidget.cpp +++ /dev/null @@ -1,91 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "downloadswidget.h" -#include "ui_downloadsform.h" - -#include -#include -#include -#include -#include -#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(ui->listWidget->itemWidget(current)); - currentWidget->showDetails(); - currentWidget->setFixedWidth(ui->listWidget->viewport()->width()); - currentWidget->adjustSize(); - current->setSizeHint(currentWidget->size()); - - DownloadItemWidget *previousWidget = qobject_cast(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/src/lib/downloads/downloadswidget.h b/src/lib/downloads/downloadswidget.h deleted file mode 100644 index 8c9ea21..0000000 --- a/src/lib/downloads/downloadswidget.h +++ /dev/null @@ -1,38 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef DOWNLOADDIALOG_H -#define DOWNLOADDIALOG_H - -#include - -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/src/lib/downloads/widgets/downloaditemform.ui b/src/lib/downloads/widgets/downloaditemform.ui deleted file mode 100644 index 17f1d6a..0000000 --- a/src/lib/downloads/widgets/downloaditemform.ui +++ /dev/null @@ -1,74 +0,0 @@ - - - DownloadItemForm - - - - 0 - 0 - 500 - 122 - - - - - 0 - 0 - - - - Form - - - - 0 - - - - - [url] - - - - - - - 24 - - - - - - - - - - status_label - - - - - - - path_label - - - true - - - - - - - - - - - ElidedLabel - QLabel -
    widgets/elidedlabel.h
    -
    -
    - - -
    diff --git a/src/lib/downloads/widgets/downloaditemwidget.cpp b/src/lib/downloads/widgets/downloaditemwidget.cpp deleted file mode 100644 index fff3cfc..0000000 --- a/src/lib/downloads/widgets/downloaditemwidget.cpp +++ /dev/null @@ -1,103 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "downloaditemwidget.h" -#include "ui_downloaditemform.h" - -#include -#include - -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/src/lib/downloads/widgets/downloaditemwidget.h b/src/lib/downloads/widgets/downloaditemwidget.h deleted file mode 100644 index c6246da..0000000 --- a/src/lib/downloads/widgets/downloaditemwidget.h +++ /dev/null @@ -1,43 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef DOWNLOADITEMFORM_H -#define DOWNLOADITEMFORM_H - -#include -#include - -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/src/lib/downloads/widgets/elidedlabel.cpp b/src/lib/downloads/widgets/elidedlabel.cpp deleted file mode 100644 index dc17d32..0000000 --- a/src/lib/downloads/widgets/elidedlabel.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include - -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/src/lib/downloads/widgets/elidedlabel.h b/src/lib/downloads/widgets/elidedlabel.h deleted file mode 100644 index d0f6221..0000000 --- a/src/lib/downloads/widgets/elidedlabel.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** 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 - -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/src/lib/navigation/navigation.qbs b/src/lib/navigation/navigation.qbs deleted file mode 100644 index 7719fbc..0000000 --- a/src/lib/navigation/navigation.qbs +++ /dev/null @@ -1,26 +0,0 @@ -import qbs 1.0 - -Project { - name: "navigation" - - StaticLibrary { - id: navigation - name: "navigation" - - cpp.includePaths: ['../..'] - - Depends { - name: "Qt" - submodules: ["core", "widgets", "webengine", "webenginewidgets"] - } - - files: [ - "navigationbutton.cpp", - "navigationbutton.h", - "urlcompleter.cpp", - "urlcompleter.h", - "urllineedit.cpp", - "urllineedit.h", - ] - } -} diff --git a/src/lib/navigation/navigationbutton.cpp b/src/lib/navigation/navigationbutton.cpp deleted file mode 100644 index 13daebc..0000000 --- a/src/lib/navigation/navigationbutton.cpp +++ /dev/null @@ -1,141 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "navigationbutton.h" - -#include -#include -#include - -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 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/src/lib/navigation/navigationbutton.h b/src/lib/navigation/navigationbutton.h deleted file mode 100644 index ec39efa..0000000 --- a/src/lib/navigation/navigationbutton.h +++ /dev/null @@ -1,49 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef NAVIGATIONBUTTON_H -#define NAVIGATIONBUTTON_H - -#include -#include - -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/src/lib/navigation/urlcompleter.cpp b/src/lib/navigation/urlcompleter.cpp deleted file mode 100644 index bbde297..0000000 --- a/src/lib/navigation/urlcompleter.cpp +++ /dev/null @@ -1,26 +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: 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/src/lib/navigation/urlcompleter.h b/src/lib/navigation/urlcompleter.h deleted file mode 100644 index f2c52ff..0000000 --- a/src/lib/navigation/urlcompleter.h +++ /dev/null @@ -1,25 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef URLCOMPLETER_H -#define URLCOMPLETER_H - -#include - -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/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp deleted file mode 100644 index 4dc6b39..0000000 --- a/src/lib/navigation/urllineedit.cpp +++ /dev/null @@ -1,136 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "urllineedit.h" -#include -#include -#include -#include -#include - -#include - -// ssl menu -#include - -#include "lib/bookmarks/bookmarkswidget.h" - -#include - -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 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/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h deleted file mode 100644 index 46366a7..0000000 --- a/src/lib/navigation/urllineedit.h +++ /dev/null @@ -1,59 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef URLLINEEDIT_H -#define URLLINEEDIT_H - -#include -#include -#include - -#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/src/main.cpp b/src/main.cpp index 23dfa68..ffb7a4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ */ #include +#include "version.h" #include "browser.h" #include #include diff --git a/src/settings.cpp b/src/settings.cpp deleted file mode 100644 index 7f867f7..0000000 --- a/src/settings.cpp +++ /dev/null @@ -1,182 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "settings.h" -#include -#include -#include -#include -#include -#include -#include - -Settings::Settings(const QString &configFile, const QString &defaultsFile) -{ - m_configurationPath = configFile; - m_defaultsPath = defaultsFile; - - // homeLocation is the user's home folder - homeLocation = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); - - // settingsLocation is the location of the configFile - if(QFile::exists(configFile)) { - settingsLocation = QFileInfo(configFile).dir().absolutePath(); - } else { - // if file doesn't exist, use the generic location - settingsLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); - } - - // cacheLocation - cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); - - userValues = parse(m_configurationPath); - defaultValues = parse(m_defaultsPath); - - m_watcher = new QFileSystemWatcher(); - m_watcher->addPath(configFile); - QObject::connect(m_watcher, &QFileSystemWatcher::fileChanged, [this](const QString &path) { - if(path == m_configurationPath) { -#ifdef QT_DEBUG - qDebug("Reloading user configuration"); -#endif - userValues = parse(m_configurationPath); - } - }); - -#ifdef QT_DEBUG - qDebug(">> Configuration"); - qDebug("- userconf: [%s]", qUtf8Printable(m_configurationPath)); - qDebug("- defaults: [%s]", qUtf8Printable(m_defaultsPath)); - qDebug("- $home [%s]", qUtf8Printable(homeLocation)); - qDebug("- $settings [%s]", qUtf8Printable(settingsLocation)); - qDebug("- $cache [%s]", qUtf8Printable(cacheLocation)); -#endif -} - -Settings::~Settings() -{ - m_watcher->deleteLater(); -} - -QString Settings::configurationPath() const -{ - return m_configurationPath; -} - -QString Settings::defaultsPath() const -{ - return m_defaultsPath; -} - -bool Settings::isEmpty() const -{ - return userValues.empty(); -} - -QVariant Settings::value(const QString &key) const -{ - const toml::Value *cValue = userValues.find(key.toStdString()); - const toml::Value *dValue = defaultValues.find(key.toStdString()); - - QVariant r; - - if(userValues.has(key.toStdString())) { - r = valueToVariant(cValue); - } else { - if(defaultValues.has(key.toStdString())) { - r = valueToVariant(dValue); - } - } - - // check if key is a path, in which case replace '~' with the home location - if(key.endsWith(QLatin1String("path"), Qt::CaseInsensitive)) { - QString value = r.toString(); - while(value.contains('$')) { - value.replace("$settings", settingsLocation); - value.replace("$cache", cacheLocation); - value.replace("$home", homeLocation); - } - r = QVariant(value); - } - - return r; -} - -toml::Value Settings::parse(const QString &filename) -{ - toml::Value r; - - if(filename.isEmpty()) { - qWarning("Empty configuration path."); - - } else { - QFile file(filename); - if(file.open(QIODevice::ReadOnly)) { - std::stringstream d(file.readAll().toStdString()); - file.close(); - - toml::ParseResult result = toml::parse(d); - if(!result.valid()) { - qWarning("Invalid configuration: %s", result.errorReason.c_str()); - } - r = result.value; - - } else { - qWarning("Cannot open configuration: %s", qUtf8Printable(filename)); - } - } - - return r; -} - -QVariant Settings::fromList(const toml::Value *list) const -{ - QStringList l; - - for(const toml::Value &v : list->as()) { - // TODO check value type - l.append(QString::fromStdString(v.as())); - } - - return QVariant(l); -} - -QVariant Settings::valueToVariant(const toml::Value *value) const -{ - QVariant r; - switch (value->type()) { - case toml::Value::NULL_TYPE: - break; - - case toml::Value::BOOL_TYPE: - r = QVariant(value->as()); - break; - - case toml::Value::INT_TYPE: - r = QVariant(value->as()); - break; - - case toml::Value::DOUBLE_TYPE: - r = QVariant(value->as()); - break; - - case toml::Value::STRING_TYPE: - r = QVariant(QString::fromStdString(value->as())); - break; - - case toml::Value::ARRAY_TYPE: - r = fromList(value); - break; - - default: - qWarning("Unhandled type in configuration"); - break; - } - - return r; -} diff --git a/src/settings.h b/src/settings.h deleted file mode 100644 index ec25eb4..0000000 --- a/src/settings.h +++ /dev/null @@ -1,47 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef SETTINGS_H -#define SETTINGS_H - -#include -#include - -class QFileSystemWatcher; -class Settings -{ -public: - explicit Settings(const QString &configFile, const QString &defaultsFile = QString()); - ~Settings(); - - QString configurationPath() const; - QString defaultsPath() const; - - bool isEmpty() const; - QVariant value(const QString &key) const; - -private: - toml::Value parse(const QString &filename); - - QVariant fromList(const toml::Value *list) const; - QVariant valueToVariant(const toml::Value *value) const; - - toml::Value userValues; - toml::Value defaultValues; - - QString m_configurationPath; - QString m_defaultsPath; - - QString homeLocation; - QString settingsLocation; - QString cacheLocation; - - QFileSystemWatcher *m_watcher; -}; - -#endif // SETTINGS_H diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..1ec633a --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,7 @@ +#ifndef VERSION_H +#define VERSION_H + +#define GIT_VERSION "@GitVersion@" +#define GIT_DESCRIBE "@GitDescribe@" + +#endif //VERSION_H \ No newline at end of file diff --git a/src/webengine/webview.h b/src/webengine/webview.h index bf5b1a6..9951630 100644 --- a/src/webengine/webview.h +++ b/src/webengine/webview.h @@ -11,7 +11,7 @@ #include #include -#include "webengine/webpage.h" +#include "webpage.h" class MainWindow; class WebView : public QWebEngineView -- cgit v1.2.1