-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page.cpp
34 lines (30 loc) · 1.08 KB
/
Page.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
#include "Page.h"
#include <QProcess>
Page::Page(QString defaultDir, QObject *parent):QWebEnginePage(parent),_defaultDir(defaultDir) {
if(!_defaultDir.endsWith('/'))
_defaultDir.append('/');
}
bool Page::acceptNavigationRequest(QUrl const &url, NavigationType type, bool isMainFrame) {
if(url.isLocalFile()) {
open(url.path());
return false;
}
return true;
}
void Page::open(QString file) {
if(!file.contains("://") && !file.startsWith("/"))
file=_defaultDir + file;
if(file.startsWith('/') && (file.endsWith(".sh.htm") || file.endsWith(".sh.html"))) {
QProcess p(this);
p.setWorkingDirectory(file.section('/', 0, -2));
p.start("/bin/bash", QStringList() << "-c" << file, QProcess::ReadOnly);
p.waitForFinished(60000);
QByteArray page=p.readAllStandardOutput();
// Workaround for a difference from the old python based version
page.replace("target=\"hidden\" ", "");
setHtml(QString::fromLocal8Bit(page), QUrl("file://" + file));
} else if(file.endsWith(".run")) {
QProcess::startDetached("/bin/bash", QStringList() << "-c" << file);
} else
QWebEnginePage::load(file);
}