mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -04:00
Open external links in the system browser.
This commit is contained in:
parent
7900c1a4e1
commit
07e80eefa5
@ -41,7 +41,8 @@ SOURCES += \
|
||||
src/tabwidget.cpp \
|
||||
src/webview.cpp \
|
||||
src/searchbar.cpp \
|
||||
src/mainmenu.cpp
|
||||
src/mainmenu.cpp \
|
||||
src/webpage.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/mainwindow.h \
|
||||
@ -55,7 +56,8 @@ HEADERS += \
|
||||
src/tabwidget.h \
|
||||
src/webview.h \
|
||||
src/searchbar.h \
|
||||
src/mainmenu.h
|
||||
src/mainmenu.h \
|
||||
src/webpage.h
|
||||
|
||||
FORMS += \
|
||||
ui/mainwindow.ui
|
||||
|
19
src/webpage.cpp
Normal file
19
src/webpage.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "webpage.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
||||
WebPage::WebPage(QObject *parent) :
|
||||
QWebEnginePage(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
|
||||
{
|
||||
if (url.scheme() != "zim") {
|
||||
QDesktopServices::openUrl(url);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
20
src/webpage.h
Normal file
20
src/webpage.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef WEBPAGE_H
|
||||
#define WEBPAGE_H
|
||||
|
||||
#include <QWebEnginePage>
|
||||
|
||||
class WebPage : public QWebEnginePage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WebPage(QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // WEBPAGE_H
|
@ -4,10 +4,12 @@
|
||||
#include <QWebEngineProfile>
|
||||
#include <iostream>
|
||||
#include "kiwixapp.h"
|
||||
#include "webpage.h"
|
||||
|
||||
WebView::WebView(QWidget *parent)
|
||||
: QWebEngineView(parent)
|
||||
{
|
||||
setPage(new WebPage(this));
|
||||
auto profile = page()->profile();
|
||||
auto app = KiwixApp::instance();
|
||||
profile->installUrlSchemeHandler("zim", app->getSchemeHandler());
|
||||
|
Loading…
x
Reference in New Issue
Block a user