From bb0eccac8d006e03e29f7b5a849994bf819405ed Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 8 Feb 2018 16:16:41 +0100 Subject: Connected WebView::newBookmark signal --- src/mainwindow/mainwindow.cpp | 13 ++++++++++++- src/mainwindow/mainwindow.h | 3 +++ src/webengine/webview.cpp | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 5ee0a78..2d7ba09 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -16,6 +16,7 @@ #include #include #include +#include //#include MainWindow::MainWindow(std::shared_ptr config, QWidget *parent) @@ -247,6 +248,9 @@ void MainWindow::handleTabChanged(WebView *view) { Q_CHECK_PTR(view); + disconnect(titleChangedConnection); + disconnect(newBookmarkConnection); + m_currentView = view; // centralWidget can be a nullptr @@ -266,7 +270,14 @@ void MainWindow::handleTabChanged(WebView *view) m_addressBar->connectWebView(view); - connect(view, &WebView::titleChanged, this, &MainWindow::handleTitleUpdated); + titleChangedConnection = connect(view, &WebView::titleChanged, this, &MainWindow::handleTitleUpdated); + newBookmarkConnection = connect(view, &WebView::newBookmark, this, [this](const QString &title, const QUrl &url) { + if(m_bookmarksWidget) { + auto *bookmark = m_bookmarksWidget->model()->createBookmark(nullptr); + bookmark->setText(0, title); + bookmark->setText(1, url.toString()); + } + }); m_progressBar->connectWebView(view); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index f9e0515..84b408b 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -92,6 +92,9 @@ private: std::shared_ptr m_config; std::shared_ptr m_bookmarksWidget; std::shared_ptr m_downloadsWidget; + + QMetaObject::Connection titleChangedConnection; + QMetaObject::Connection newBookmarkConnection; }; #endif // MAINWINDOW_H diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index 5f7fc35..9cf0157 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -62,7 +62,7 @@ WebView::WebView(MainWindow *parentMainWindow, QWidget *parent) qApp->clipboard()->setText(this->url().toString()); }); - QAction *bookmarkAction = m_pageMenu->addAction(tr("TODO: Bookmark page")); + QAction *bookmarkAction = m_pageMenu->addAction(tr("Bookmark page")); connect(bookmarkAction, &QAction::triggered, this, [this]() { emit newBookmark(this->title(), this->url()); }); @@ -105,7 +105,7 @@ WebView::WebView(MainWindow *parentMainWindow, QWidget *parent) m_pageMenu->addSeparator(); - QAction *savePageAction = m_pageMenu->addAction(tr("TODO: Save Page")); + QAction *savePageAction = m_pageMenu->addAction(tr("Save Page")); connect(savePageAction, &QAction::triggered, this, [this]() { this->triggerPageAction(QWebEnginePage::SavePage); }); -- cgit v1.2.1