Skip to content

Commit c104113

Browse files
committed
better handling of page and filesystem dialog settings
1 parent e17c60c commit c104113

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/webengine-page.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,25 @@ public slots:
8585
}
8686

8787
// ==============================
88-
// Page settings handling:
88+
// Page settings:
8989
// ==============================
9090
void qGetPageSettings(QVariant settingsJsResult) {
9191
QJsonDocument settingsJsonDocument =
9292
QJsonDocument::fromJson(settingsJsResult.toString().toUtf8());
93-
QJsonObject settingsJsonObject = settingsJsonDocument.object();
9493

95-
// Get auto-start scripts:
96-
QJsonArray autoStartScripts =
97-
settingsJsonObject["autoStartScripts"].toArray();
94+
if (!settingsJsonDocument.isEmpty()) {
95+
QJsonObject settingsJsonObject = settingsJsonDocument.object();
9896

99-
foreach (const QJsonValue &value, autoStartScripts) {
100-
QString autoStartScript = value.toString();
101-
qHandleScripts(autoStartScript);
102-
}
97+
// Get auto-start scripts:
98+
QJsonArray autoStartScripts =
99+
settingsJsonObject["autoStartScripts"].toArray();
100+
101+
foreach (const QJsonValue &value, autoStartScripts) {
102+
QString autoStartScript = value.toString();
103+
qHandleScripts(autoStartScript);
104+
}
103105

104-
// Get dialog and context menu labels:
105-
if (settingsJsonObject.length() > 0) {
106+
// Get dialog and context menu labels:
106107
if (settingsJsonObject["okLabel"].toString().length() > 0) {
107108
okLabel = settingsJsonObject["okLabel"].toString();
108109
}
@@ -143,7 +144,7 @@ public slots:
143144
}
144145

145146
// ==============================
146-
// Filesystem dialogs handling:
147+
// Filesystem dialogs:
147148
// ==============================
148149
void qHandleDialogs(QString dialogObjectName)
149150
{
@@ -155,11 +156,12 @@ public slots:
155156
QJsonDocument dialogJsonDocument =
156157
QJsonDocument::fromJson(
157158
dialogSettings.toString().toUtf8());
158-
QJsonObject dialogJsonObject = dialogJsonDocument.object();
159159

160-
dialogJsonObject["id"] = dialogObjectName;
161-
162-
qReadDialogSettings(dialogJsonObject);
160+
if (!dialogJsonDocument.isEmpty()) {
161+
QJsonObject dialogJsonObject = dialogJsonDocument.object();
162+
dialogJsonObject["id"] = dialogObjectName;
163+
qReadDialogSettings(dialogJsonObject);
164+
}
163165
});
164166
}
165167

@@ -217,7 +219,7 @@ public slots:
217219
}
218220

219221
// ==============================
220-
// Scripts handling:
222+
// Perl scripts:
221223
// ==============================
222224
void qHandleScripts(QString scriptObjectName)
223225
{

src/webkit-page.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,26 @@ public slots:
9393
}
9494

9595
// ==============================
96-
// Page settings handling:
96+
// Page settings:
9797
// ==============================
9898

9999
void qGetPageSettings(QVariant settingsJsResult) {
100100
QJsonDocument settingsJsonDocument =
101101
QJsonDocument::fromJson(settingsJsResult.toString().toUtf8());
102-
QJsonObject settingsJsonObject = settingsJsonDocument.object();
103102

104-
// Get auto-start scripts:
105-
QJsonArray autoStartScripts =
106-
settingsJsonObject["autoStartScripts"].toArray();
103+
if (!settingsJsonDocument.isEmpty()) {
104+
QJsonObject settingsJsonObject = settingsJsonDocument.object();
107105

108-
foreach (const QJsonValue &value, autoStartScripts) {
109-
QString autoStartScript = value.toString();
110-
qHandleScripts(autoStartScript);
111-
}
106+
// Get auto-start scripts:
107+
QJsonArray autoStartScripts =
108+
settingsJsonObject["autoStartScripts"].toArray();
109+
110+
foreach (const QJsonValue &value, autoStartScripts) {
111+
QString autoStartScript = value.toString();
112+
qHandleScripts(autoStartScript);
113+
}
112114

113-
// Get dialog and context menu labels:
114-
if (settingsJsonObject.length() > 0) {
115+
// Get dialog and context menu labels:
115116
if (settingsJsonObject["okLabel"].toString().length() > 0) {
116117
okLabel = settingsJsonObject["okLabel"].toString();
117118
}
@@ -152,7 +153,7 @@ public slots:
152153
}
153154

154155
// ==============================
155-
// Filesystem dialogs handling:
156+
// Filesystem dialogs:
156157
// ==============================
157158
void qHandleDialogs(QString dialogObjectName)
158159
{
@@ -163,11 +164,12 @@ public slots:
163164

164165
QJsonDocument dialogJsonDocument =
165166
QJsonDocument::fromJson(dialogSettings.toString().toUtf8());
166-
QJsonObject dialogJsonObject = dialogJsonDocument.object();
167167

168-
dialogJsonObject["id"] = dialogObjectName;
169-
170-
qReadDialogSettings(dialogJsonObject);
168+
if (!dialogJsonDocument.isEmpty()) {
169+
QJsonObject dialogJsonObject = dialogJsonDocument.object();
170+
dialogJsonObject["id"] = dialogObjectName;
171+
qReadDialogSettings(dialogJsonObject);
172+
}
171173
}
172174
}
173175

@@ -225,7 +227,7 @@ public slots:
225227
}
226228

227229
// ==============================
228-
// Scripts handling:
230+
// Perl scripts:
229231
// ==============================
230232
void qHandleScripts(QString scriptObjectName)
231233
{
@@ -434,7 +436,7 @@ public slots:
434436

435437
protected:
436438
// ==============================
437-
// Special URLs handling:
439+
// Special URLs:
438440
// ==============================
439441
bool acceptNavigationRequest(QWebFrame *frame,
440442
const QNetworkRequest &request,

0 commit comments

Comments
 (0)