diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-06 12:13:44 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-06 12:13:44 +0200 |
commit | 77fa83cee8453b60ae3cc190c49d69710eb4e9fa (patch) | |
tree | c97d8a7bf13579b73f69d19b4edf7af85a034cb0 /lib | |
parent | Fix clazy warnings in WebProfile (diff) | |
download | smolbote-77fa83cee8453b60ae3cc190c49d69710eb4e9fa.tar.xz |
Check URL validity before searching
Diffstat (limited to 'lib')
-rw-r--r-- | lib/addressbar/addressbar.cpp | 7 | ||||
-rw-r--r-- | lib/addressbar/urllineedit.cpp | 15 |
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/addressbar/addressbar.cpp b/lib/addressbar/addressbar.cpp index 2215c0e..3768aeb 100644 --- a/lib/addressbar/addressbar.cpp +++ b/lib/addressbar/addressbar.cpp @@ -67,10 +67,11 @@ void AddressBar::setView(QWebEngineView *view) urlBar->setUrl(view->url()); urlChangedConnection = connect(view, &QWebEngineView::urlChanged, urlBar, &UrlLineEdit::setUrl); loadUrlConnection = connect(urlBar, &UrlLineEdit::returnPressed, [=]() { - if(urlBar->text().startsWith('#')) { - emit search(urlBar->text().mid(1)); + const QUrl url = QUrl::fromUserInput(urlBar->text()); + if(url.isValid()) { + view->load(url); } else { - view->load(QUrl::fromUserInput(urlBar->text())); + emit search(urlBar->text()); } view->setFocus(); }); diff --git a/lib/addressbar/urllineedit.cpp b/lib/addressbar/urllineedit.cpp index ac311b3..79d7bf8 100644 --- a/lib/addressbar/urllineedit.cpp +++ b/lib/addressbar/urllineedit.cpp @@ -12,6 +12,8 @@ #include <QApplication> #include <QClipboard> +#include "addressbar.h" + UrlLineEdit::UrlLineEdit(QWidget *parent) : QLineEdit(parent) , m_listView(new Completer(this)) @@ -20,6 +22,8 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) setPlaceholderText(tr("Enter address")); m_listView->setVisible(false); + auto *addressbar = qobject_cast<AddressBar *>(parent); + Q_CHECK_PTR(addressbar); auto *copyAction = new QAction(tr("Copy URL"), this); connect(copyAction, &QAction::triggered, this, [this]() { @@ -42,9 +46,8 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) actions.append(loadAction); auto *searchAction = new QAction(tr("Paste and search"), this); - connect(searchAction, &QAction::triggered, this, [this]() { - this->setText("#" + qApp->clipboard()->text()); - emit returnPressed(); + connect(searchAction, &QAction::triggered, this, [=]() { + emit addressbar->search(qApp->clipboard()->text()); }); actions.append(searchAction); @@ -106,8 +109,10 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event) void UrlLineEdit::focusOutEvent(QFocusEvent *event) { - if(!text().startsWith('#')) - setUrl(QUrl::fromUserInput(text())); + const QUrl url = QUrl::fromUserInput(text()); + if(url.isValid()) + setUrl(url); + QLineEdit::focusOutEvent(event); } |