-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubview.cpp
40 lines (32 loc) · 1.19 KB
/
githubview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <QWebEnginePage>
#include <QWebEngineNavigationRequest>
#include <QWebEngineNewWindowRequest>
#include "githubview.h"
#include "constants.h"
#include "settings.h"
GithubView::GithubView(QWidget* parent): QWebEngineView(Constants::webProfile(), parent) {
connect(page(), &QWebEnginePage::newWindowRequested,this, &GithubView::handleNewWindowRequest);
connect(page(), &QWebEnginePage::navigationRequested,this, &GithubView::handleNavigationRequest);
page()->load(Settings::githubUrl());
}
bool GithubView::handleUrlAndEmitSignals(const QUrl& url) {
if(url.host() == Settings::githubUrl().host())
return true;
emit externalNavigationRequested(url);
return false;
}
void GithubView::handleNavigationRequest(QWebEngineNavigationRequest& request){
if(!request.isMainFrame()) {
// github is fetching resources, rich image diffs, the like
request.accept();
return;
}
if(handleUrlAndEmitSignals(request.url()))
request.accept();
else
request.reject();
}
void GithubView::handleNewWindowRequest(QWebEngineNewWindowRequest& request){
if(handleUrlAndEmitSignals(request.requestedUrl()))
request.openIn(page());
}