Skip to content

Commit f274f4d

Browse files
committed
better title for QtWebKit dialogs
1 parent 5f728f6 commit f274f4d

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

CREDITS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Special thanks to the staff of the
1313
where much of the development effort took place!
1414

1515
Special thanks to Stack Overflow users peppe, Piotr Dobrogost and Fèlix Galindo Allué.
16-
Their example code is no more used in Perl Executing Browser,
16+
Their example code is no longer used in Perl Executing Browser,
1717
but their expertise and good will to help others are not forgotten!
1818

1919
Thanks to Jennifer Maher-Bontrager, author of the Camel icon.
@@ -84,6 +84,7 @@ https://wiki.qt.io/Open_Web_Page_in_QWebView
8484
https://forum.qt.io/topic/18879/relative-path-on-qmake-pro-file
8585
https://forum.qt.io/topic/551/get-filename-without-extension
8686
https://forum.qt.io/topic/45982/solved-is-there-a-problem-with-the-following-non-blocking-sleep-function
87+
https://forum.qt.io/topic/3314/qwebelement-set-and-get-attribute
8788

8889
http://www.qtcentre.org/threads/25880-QWebView-prints-PDF-file-OK-with-QPrintDialog-only
8990
http://www.qtcentre.org/threads/46016-Place-QMessageBox-on-middle-of-screen

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,12 @@ pebSettings.closeConfirmation =
325325
* **About Qt dialog:** ``about-qt.function``
326326

327327
## Specific Keyboard Shortcuts
328-
* <kbd>Ctrl</kbd> + <kbd>I</kbd> - start QWebInspector (QtWebKit builds only)
329-
* <kbd>Ctrl</kbd> + <kbd>P</kbd> - print (QtWebKit builds only)
328+
All specific keyboard shortcuts are available only in the QtWebKit builds of PEB.
329+
* <kbd>Ctrl</kbd> + <kbd>I</kbd> - start QWebInspector
330+
* <kbd>Ctrl</kbd> + <kbd>P</kbd> - print
330331
Printing is started after a native printer selection dialog is displayed.
331332
If no printer is configured, no dialog is displayed and no action is taken.
332-
* <kbd>Ctrl</kbd> + <kbd>R</kbd> - get print preview (QtWebKit builds only)
333+
* <kbd>Ctrl</kbd> + <kbd>R</kbd> - get print preview
333334

334335
## What PEB Is Not
335336
* PEB is not a general purpose web browser and does not have all traditional features of general purpose web browsers.

resources/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
pebSettings.noLabel = 'NO';
2222
pebSettings.closeConfirmation =
2323
'Text was entered in a form and it is going to be lost!\n' +
24-
'Are you sure you want to close the window?';
24+
'Are you sure you want to close the application?';
2525

2626
// Settings objects for the Perl scripts:
2727
var interactive_one = {};

src/webkit-page.h

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QRegularExpression>
2929
#include <QTimer>
3030
#include <QUrl>
31+
#include <QWebElement>
3132
#include <QWebFrame>
3233
#include <QWebPage>
3334

@@ -51,20 +52,26 @@ public slots:
5152
{
5253
if (ok) {
5354
if (QPage::mainFrame()->url().scheme() == "file") {
54-
// Inject all browser-specific Javascript:
55-
QFileReader *resourceReader =
56-
new QFileReader(QString(":/peb.js"));
57-
QString pebJavaScript = resourceReader->fileContents;
58-
59-
mainFrame()->evaluateJavaScript(pebJavaScript);
60-
61-
QVariant result =
62-
mainFrame()->
63-
evaluateJavaScript("peb.getPageSettings()");
64-
qGetPageSettings(result);
65-
66-
// Send signal to the html-viewing class that a page is loaded:
67-
emit pageLoadedSignal();
55+
// Inject all browser-specific Javascript:
56+
QFileReader *resourceReader =
57+
new QFileReader(QString(":/peb.js"));
58+
QString pebJavaScript = resourceReader->fileContents;
59+
60+
mainFrame()->evaluateJavaScript(pebJavaScript);
61+
62+
// Start getting the page settings:
63+
QVariant result = mainFrame()->
64+
evaluateJavaScript("peb.getPageSettings()");
65+
qGetPageSettings(result);
66+
67+
// Get the title of the page for use in dialog boxes:
68+
QWebElement titleDomElement =
69+
QPage::currentFrame()->documentElement()
70+
.findFirst("title");
71+
title = titleDomElement.toInnerXml().toLatin1();
72+
73+
// Send signal to the html-viewing class that a page is loaded:
74+
emit pageLoadedSignal();
6875
}
6976
}
7077
}
@@ -483,7 +490,7 @@ public slots:
483490

484491
QMessageBox javaScriptAlertMessageBox (qApp->activeWindow());
485492
javaScriptAlertMessageBox.setWindowModality(Qt::WindowModal);
486-
javaScriptAlertMessageBox.setWindowTitle("Alert");
493+
javaScriptAlertMessageBox.setWindowTitle(title);
487494
javaScriptAlertMessageBox.setText(msg);
488495
javaScriptAlertMessageBox.setButtonText(QMessageBox::Ok, okLabel);
489496
javaScriptAlertMessageBox.setDefaultButton(QMessageBox::Ok);
@@ -499,10 +506,11 @@ public slots:
499506

500507
QMessageBox javaScriptConfirmMessageBox (qApp->activeWindow());
501508
javaScriptConfirmMessageBox.setWindowModality(Qt::WindowModal);
502-
javaScriptConfirmMessageBox.setWindowTitle("Confirm");
509+
javaScriptConfirmMessageBox.setWindowTitle(title);
503510
javaScriptConfirmMessageBox.setText(msg);
504511
javaScriptConfirmMessageBox
505512
.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
513+
javaScriptConfirmMessageBox.setDefaultButton(QMessageBox::No);
506514
javaScriptConfirmMessageBox.setButtonText(QMessageBox::Yes, yesLabel);
507515
javaScriptConfirmMessageBox.setButtonText(QMessageBox::No, noLabel);
508516
return QMessageBox::Yes == javaScriptConfirmMessageBox.exec();
@@ -522,7 +530,7 @@ public slots:
522530

523531
QInputDialog dialog;
524532
dialog.setModal(true);
525-
dialog.setWindowTitle("Prompt");
533+
dialog.setWindowTitle(title);
526534
dialog.setLabelText(msg);
527535
dialog.setInputMode(QInputDialog::TextInput);
528536
dialog.setTextValue(defaultValue);
@@ -539,6 +547,8 @@ public slots:
539547
}
540548

541549
private:
550+
QString title;
551+
542552
QString okLabel;
543553
QString cancelLabel;
544554
QString yesLabel;

0 commit comments

Comments
 (0)