Skip to content

Commit 56165e7

Browse files
committed
fullpath filesystem dialogs for localhost
1 parent 71ed9fe commit 56165e7

File tree

5 files changed

+54
-48
lines changed

5 files changed

+54
-48
lines changed

doc/SETTINGS.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,31 @@ The ``pebSettings`` JavaScript object may have the following properties:
5858

5959
## Perl Scripts API
6060

61-
Every Perl script run by PEB has a JavaScript settings object with an arbitrary name and fixed object properties. The name of the JavaScript settings object with a ``.script`` extension forms settings pseudo filename used to start the Perl script.
61+
Every Perl script run by PEB has a JavaScript settings object with an arbitrary name and fixed object properties. The name of the JavaScript settings object with a ``.script`` extension forms settings pseudo link used to start the Perl script.
6262

6363
There are three methods to start a local Perl script:
6464

65-
* **Clicking a link to a script settings pseudo filename:**
65+
* **Clicking a link to a script settings pseudo link:**
6666

6767
```html
6868
<a href="test.script">Start Perl script</a>
6969
```
7070

71-
* **Submitting a form to a script settings pseudo filename:**
71+
* **Submitting a form to a script settings pseudo link:**
7272

7373
```html
7474
<form action="test.script">
7575
<input type="submit" value="Start Perl script">
7676
</form>
7777
```
7878

79-
* **Calling a JavaScript function with a script settings pseudo filename:**
79+
* **Calling a JavaScript function with a script settings pseudo link:**
8080

8181
```javascript
8282
peb.startScript('test.script');
8383
```
8484

85-
This method creates an invisible form and submits it to the script settings pseudo filename.
85+
This method creates an invisible form and submits it to the script settings pseudo link.
8686

8787
A minimal example of a JavaScript settings object for a Perl script run by PEB:
8888

@@ -262,7 +262,9 @@ The ``#PORT#`` keyword within the command-line arguments is substituted with the
262262

263263
## Selecting Files and Folders
264264

265-
Selecting files or folders with their full paths is performed by clicking a link to a pseudo filename composed of the name of a JavaScript settings object for the wanted dialog and a ``.dialog`` extension.
265+
Selecting files or folders with their full paths is performed by clicking a pseudo link composed of the name of a JavaScript settings object and a ``.dialog`` extension.
266+
267+
Selecting files or folders with their full paths is possible only from local HTML files or localhost pages.
266268

267269
A JavaScript settings object for a filesystem dialog has only two object properties:
268270

src/webengine-main-window.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public slots:
6060
localServerBaseUrl = "http://localhost:" +
6161
qApp->property("port").toString() + "/";
6262
webViewWidget->load(QUrl(localServerBaseUrl));
63-
6463
showMaximized();
6564
}
6665

@@ -70,12 +69,14 @@ public slots:
7069
localServerTester->stop();
7170

7271
qDisplayError(QString("Local server timed out."));
72+
showMaximized();
7373
}
7474
}
7575

7676
void setMainWindowTitleSlot(QString title)
7777
{
7878
setWindowTitle(title);
79+
showMaximized();
7980
}
8081

8182
void qGoFullscreen(QWebEngineFullScreenRequest request) {

src/webengine-page.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,18 @@ bool QPage::acceptNavigationRequest(const QUrl &url,
7373
QWebEnginePage::NavigationType type,
7474
bool isMainFrame)
7575
{
76+
// Handle filesystem dialogs:
77+
if ((url.scheme() == "file" or url.authority() == "localhost") and
78+
type == QWebEnginePage::NavigationTypeLinkClicked and
79+
url.fileName().contains(".dialog") and
80+
isMainFrame == true) {
81+
qHandleDialogs(url.fileName().replace(".dialog", ""));
82+
return false;
83+
}
84+
85+
// Handle local Perl scripts and functional pseudo filenames:
7686
if (url.scheme() == "file" and isMainFrame == true) {
77-
// Local forms submission:
87+
// Submitting special forms is a method to start local Perl scripts:
7888
if (type == QWebEnginePage::NavigationTypeFormSubmitted) {
7989
if (url.fileName().contains(".script")) {
8090
qHandleScripts(url.fileName().replace(".script", ""));
@@ -85,13 +95,8 @@ bool QPage::acceptNavigationRequest(const QUrl &url,
8595
}
8696

8797
if (type == QWebEnginePage::NavigationTypeLinkClicked) {
88-
// Handle filesystem dialogs:
89-
if (url.fileName().contains(".dialog")) {
90-
qHandleDialogs(url.fileName().replace(".dialog", ""));
91-
return false;
92-
}
93-
94-
// Handle local Perl scripts:
98+
// Clicking special links is
99+
// another method to start local Perl scripts:
95100
if (url.fileName().contains(".script")) {
96101
qHandleScripts(url.fileName().replace(".script", ""));
97102
return false;

src/webengine-page.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,20 @@ public slots:
147147
// ==============================
148148
void qHandleDialogs(QString dialogObjectName)
149149
{
150-
if (QPage::url().scheme() == "file") {
151-
QPage::runJavaScript(
152-
QString("peb.getDialogSettings(" +
153-
dialogObjectName + ")"),
154-
[dialogObjectName, this](QVariant dialogSettings)
155-
{
156-
QJsonDocument dialogJsonDocument =
157-
QJsonDocument::fromJson(
158-
dialogSettings.toString().toUtf8());
159-
QJsonObject dialogJsonObject = dialogJsonDocument.object();
160-
161-
dialogJsonObject["id"] = dialogObjectName;
162-
163-
qReadDialogSettings(dialogJsonObject);
164-
});
165-
}
150+
QPage::runJavaScript(
151+
QString("peb.getDialogSettings(" +
152+
dialogObjectName + ")"),
153+
[dialogObjectName, this](QVariant dialogSettings)
154+
{
155+
QJsonDocument dialogJsonDocument =
156+
QJsonDocument::fromJson(
157+
dialogSettings.toString().toUtf8());
158+
QJsonObject dialogJsonObject = dialogJsonDocument.object();
159+
160+
dialogJsonObject["id"] = dialogObjectName;
161+
162+
qReadDialogSettings(dialogJsonObject);
163+
});
166164
}
167165

168166
void qReadDialogSettings(QJsonObject dialogJsonObject)

src/webkit-page.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -438,27 +438,27 @@ public slots:
438438
{
439439
Q_UNUSED(frame);
440440

441+
// Handle filesystem dialogs:
442+
if ((request.url().scheme() == "file" or
443+
request.url().authority() == "localhost") and
444+
navigationType == QWebPage::NavigationTypeLinkClicked and
445+
request.url().fileName().contains(".dialog")) {
446+
qHandleDialogs(request.url().fileName().replace(".dialog", ""));
447+
return false;
448+
}
449+
450+
// Handle local Perl scripts and functional pseudo filenames:
441451
if (request.url().scheme() == "file") {
442-
// Local forms submission:
443-
if (navigationType == QWebPage::NavigationTypeFormSubmitted) {
444-
if (request.url().fileName().contains(".script")) {
445-
qHandleScripts(request.url().fileName()
446-
.replace(".script", ""));
447-
return false;
448-
} else {
449-
return false;
450-
}
452+
// Submitting special forms is a method to start local Perl scripts:
453+
if (navigationType == QWebPage::NavigationTypeFormSubmitted and
454+
request.url().fileName().contains(".script")) {
455+
qHandleScripts(request.url().fileName().replace(".script", ""));
456+
return false;
451457
}
452458

453459
if (navigationType == QWebPage::NavigationTypeLinkClicked) {
454-
// Handle filesystem dialogs:
455-
if (request.url().fileName().contains(".dialog")) {
456-
qHandleDialogs(request.url().fileName()
457-
.replace(".dialog", ""));
458-
return false;
459-
}
460-
461-
// Handle local Perl scripts:
460+
// Clicking special links is
461+
// another method to start local Perl scripts:
462462
if (request.url().fileName().contains(".script")) {
463463
qHandleScripts(request.url().fileName()
464464
.replace(".script", ""));

0 commit comments

Comments
 (0)