]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/dialogs/RequestDetailDialog.cpp
Block all CSP requests. https://redmine.stoutner.com/issues/1193
[PrivacyBrowserPC.git] / src / dialogs / RequestDetailDialog.cpp
1 /* SPDX-License-Identifier: GPL-3.0-or-later
2  * SPDX-FileCopyrightText: 2024-2025 Soren Stoutner <soren@stoutner.com>
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc/>.
5  *
6  * This program is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License as published by the Free Software
8  * Foundation, either version 3 of the License, or (at your option) any later
9  * version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19
20 // Application headers.
21 #include "RequestDetailDialog.h"
22 #include "GlobalVariables.h"
23 #include "ui_RequestDetailDialog.h"
24
25 // KDE Frameworks headers.
26 #include <KActionCollection>
27 #include <KColorScheme>
28
29 // Qt toolkit headers.
30 #include <QShortcut>
31
32 // Construct the class.
33 RequestDetailDialog::RequestDetailDialog(QWidget *parentWidgetPointer, QTableWidget *tableWidgetPointer, const int initialRow) :
34                                          QDialog(parentWidgetPointer), currentRow(initialRow), tableWidgetPointer(tableWidgetPointer)
35 {
36     // Set the window modality.
37     setWindowModality(Qt::WindowModality::ApplicationModal);
38
39     // Instantiate the request detail dialog UI.
40     Ui::RequestDetailDialog requestDetailDialogUi;
41
42     // Setup the UI.
43     requestDetailDialogUi.setupUi(this);
44
45     // Get handles for the views.
46     dispositionLineEditPointer = requestDetailDialogUi.dispositionLineEdit;
47     webPageUrlLineEditPointer = requestDetailDialogUi.webPageUrlLineEdit;
48     requestUrlLineEditPointer = requestDetailDialogUi.requestUrlLineEdit;
49     requestUrlWithSeparatorsLineEditPointer = requestDetailDialogUi.requestUrlWithSeparatorsLineEdit;
50     truncatedRequestUrlLineEditPointer = requestDetailDialogUi.truncatedRequestUrlLineEdit;
51     truncatedRequestUrlWithSeparatorsLineEditPointer = requestDetailDialogUi.truncatedRequestUrlWithSeparatorsLineEdit;
52     requestMethodLineEditPointer = requestDetailDialogUi.requestMethodLineEdit;
53     navigationTypeLineEditPointer = requestDetailDialogUi.navigationTypeLineEdit;
54     thirdPartyRequestLineEditPointer = requestDetailDialogUi.thirdPartyRequestLineEdit;
55     resourceTypeLineEditPointer = requestDetailDialogUi.resourceTypeLineEdit;
56     filterListEntryWidget = requestDetailDialogUi.filterListEntryWidget;
57     filterListLineEditPointer = requestDetailDialogUi.filterListLineEdit;
58     sublistLineEditPointer = requestDetailDialogUi.sublistListLineEdit;
59     appliedEntryListLineEditPointer = requestDetailDialogUi.appliedEntryListLineEdit;
60     domainLineEditPointer = requestDetailDialogUi.domainLineEdit;
61     thirdPartyFilterLineEditPointer = requestDetailDialogUi.thirdPartyFilterLineEdit;
62     initialMatchLineEditPointer = requestDetailDialogUi.initialMatchLineEdit;
63     finalMatchLineEditPointer = requestDetailDialogUi.finalMatchLineEdit;
64     domainListLineEditPointer = requestDetailDialogUi.domainListLineEdit;
65     hasRequestOptionsCheckBoxPointer = requestDetailDialogUi.hasRequestOptionsCheckBox;
66     fontLineEditPointer = requestDetailDialogUi.fontLineEdit;
67     imageLineEditPointer = requestDetailDialogUi.imageLineEdit;
68     mainFrameLineEditPointer = requestDetailDialogUi.mainFrameLineEdit;
69     mediaLineEditPointer = requestDetailDialogUi.mediaLineEdit;
70     objectLineEditPointer = requestDetailDialogUi.objectLineEdit;
71     otherLineEditPointer = requestDetailDialogUi.otherLineEdit;
72     pingLineEditPointer = requestDetailDialogUi.pingLineEdit;
73     scriptLineEditPointer = requestDetailDialogUi.scriptLineEdit;
74     styleSheetLineEditPointer = requestDetailDialogUi.styleSheetLineEdit;
75     subFrameLineEditPointer = requestDetailDialogUi.subFrameLineEdit;
76     webSocketLineEditPointer = requestDetailDialogUi.webSocketLineEdit;
77     xmlHttpRequestLineEditPointer = requestDetailDialogUi.xmlHttpRequestLineEdit;
78     appliedFilterOptionsLineEditPointer = requestDetailDialogUi.appliedFilterOptionsLineEdit;
79     originalFilterOptionsLineEditPointer = requestDetailDialogUi.originalFilterOptionsLineEdit;
80     originalEntryLineEditPointer = requestDetailDialogUi.originalEntryLineEdit;
81     previousButtonPointer = requestDetailDialogUi.previousButton;
82     nextButtonPointer = requestDetailDialogUi.nextButton;
83     QDialogButtonBox *dialogButtonBoxPointer = requestDetailDialogUi.dialogButtonBox;
84     QPushButton *closeButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Close);
85
86     // Disable changing the checkbox checked status.
87     hasRequestOptionsCheckBoxPointer->setAttribute(Qt::WA_TransparentForMouseEvents);
88
89     // Make the close button the default.
90     closeButtonPointer->setDefault(true);
91
92     // Get the disposition line edit palettes.
93     normalBackgroundPalette = dispositionLineEditPointer->palette();
94     negativeBackgroundPalette = normalBackgroundPalette;
95     positiveBackgroundPalette = normalBackgroundPalette;
96
97     // Modify the palettes.
98     KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
99     KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
100
101     // Connect the buttons.
102     connect(previousButtonPointer, SIGNAL(clicked()), this, SLOT(previous()));
103     connect(nextButtonPointer, SIGNAL(clicked()), this, SLOT(next()));
104     connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(close()));
105
106     // Create the keyboard shortcuts.
107     QShortcut *previousShortcutPointer = new QShortcut(Qt::Key_Left, this);
108     QShortcut *nextShortcutPointer = new QShortcut(Qt::Key_Right, this);
109
110     // Connect the keyboard shortcuts to the buttons.
111     connect(previousShortcutPointer, SIGNAL(activated()), previousButtonPointer, SLOT(click()));
112     connect(nextShortcutPointer, SIGNAL(activated()), nextButtonPointer, SLOT(click()));
113
114     // Populate the dialog.
115     populateDialog(currentRow);
116 }
117
118 void RequestDetailDialog::populateDialog(const int row)
119 {
120     // Set the window title.
121     setWindowTitle(i18nc("The request detail dialog window title", "Request %1 Detail", row + 1));
122
123     // Select the row in the table widget (this displays the correct row highlighted in the background of the dialog).
124     tableWidgetPointer->selectRow(row);
125
126     // Get the first table widget item in the row.
127     QTableWidgetItem *rowFirstTableWidgetItemPointer = tableWidgetPointer->item(row, 0);
128
129     // Get the data variant.
130     QVariant dataVariant = rowFirstTableWidgetItemPointer->data(Qt::UserRole);
131
132     // Get the request struct byte array from the data variant.
133     QByteArray requestStructByteArray = dataVariant.toByteArray();
134
135     // Determine if previous should be enabled.
136     bool previousEnabled = (row > 0);
137
138     // Determine if next should be enabled.
139     bool nextEnabled = (row < (tableWidgetPointer->rowCount() - 1));
140
141     // Create a request struct data stream reader.
142     QDataStream requestStructDataStreamReader(requestStructByteArray);
143
144     // Create a new request struct.
145     RequestStruct *requestStructPointer = new RequestStruct();
146
147     // Populate the new request struct.  The order needs to match how the data stream is populated in RequestsDialog.cpp.
148     requestStructDataStreamReader >> requestStructPointer->dispositionInt;
149     requestStructDataStreamReader >> requestStructPointer->entryStruct.originalEntry;
150     requestStructDataStreamReader >> requestStructPointer->entryStruct.originalFilterOptions;
151     requestStructDataStreamReader >> requestStructPointer->entryStruct.appliedEntryList;
152     requestStructDataStreamReader >> requestStructPointer->entryStruct.appliedFilterOptionsList;
153     requestStructDataStreamReader >> requestStructPointer->entryStruct.domainList;
154     requestStructDataStreamReader >> requestStructPointer->entryStruct.finalMatch;
155     requestStructDataStreamReader >> requestStructPointer->entryStruct.hasRequestOptions;
156     requestStructDataStreamReader >> requestStructPointer->entryStruct.initialMatch;
157     requestStructDataStreamReader >> requestStructPointer->entryStruct.domain;
158     requestStructDataStreamReader >> requestStructPointer->entryStruct.font;
159     requestStructDataStreamReader >> requestStructPointer->entryStruct.image;
160     requestStructDataStreamReader >> requestStructPointer->entryStruct.mainFrame;
161     requestStructDataStreamReader >> requestStructPointer->entryStruct.media;
162     requestStructDataStreamReader >> requestStructPointer->entryStruct.object;
163     requestStructDataStreamReader >> requestStructPointer->entryStruct.other;
164     requestStructDataStreamReader >> requestStructPointer->entryStruct.ping;
165     requestStructDataStreamReader >> requestStructPointer->entryStruct.script;
166     requestStructDataStreamReader >> requestStructPointer->entryStruct.styleSheet;
167     requestStructDataStreamReader >> requestStructPointer->entryStruct.subFrame;
168     requestStructDataStreamReader >> requestStructPointer->entryStruct.thirdParty;
169     requestStructDataStreamReader >> requestStructPointer->entryStruct.webSocket;
170     requestStructDataStreamReader >> requestStructPointer->entryStruct.xmlHttpRequest;
171     requestStructDataStreamReader >> requestStructPointer->filterListTitle;
172     requestStructDataStreamReader >> requestStructPointer->isThirdPartyRequest;
173     requestStructDataStreamReader >> requestStructPointer->matchedUrlType;
174     requestStructDataStreamReader >> requestStructPointer->navigationTypeInt;
175     requestStructDataStreamReader >> requestStructPointer->requestMethodString;
176     requestStructDataStreamReader >> requestStructPointer->resourceTypeInt;
177     requestStructDataStreamReader >> requestStructPointer->sublistInt;
178     requestStructDataStreamReader >> requestStructPointer->truncatedUrlString;
179     requestStructDataStreamReader >> requestStructPointer->truncatedUrlStringWithSeparators;
180     requestStructDataStreamReader >> requestStructPointer->urlString;
181     requestStructDataStreamReader >> requestStructPointer->urlStringWithSeparators;
182     requestStructDataStreamReader >> requestStructPointer->webPageUrlString;
183
184     // Make a local copy of the has request options boolean.
185     bool hasRequestOptions = requestStructPointer->entryStruct.hasRequestOptions;
186
187     // Populate the views.
188     dispositionLineEditPointer->setText(globalFilterListHelperPointer->getDispositionString(requestStructPointer->dispositionInt));
189     webPageUrlLineEditPointer->setText(requestStructPointer->webPageUrlString);
190     requestUrlLineEditPointer->setText(requestStructPointer->urlString);
191     requestUrlWithSeparatorsLineEditPointer->setText(requestStructPointer->urlStringWithSeparators);
192     truncatedRequestUrlLineEditPointer->setText(requestStructPointer->truncatedUrlString);
193     truncatedRequestUrlWithSeparatorsLineEditPointer->setText(requestStructPointer->truncatedUrlStringWithSeparators);
194     requestMethodLineEditPointer->setText(requestStructPointer->requestMethodString);
195     thirdPartyRequestLineEditPointer->setText(requestStructPointer->isThirdPartyRequest ? i18n("Yes") : QLatin1String());
196     navigationTypeLineEditPointer->setText(globalFilterListHelperPointer->getNavigationTypeString(requestStructPointer->navigationTypeInt));
197     resourceTypeLineEditPointer->setText(globalFilterListHelperPointer->getResourceTypeString(requestStructPointer->resourceTypeInt));
198     filterListLineEditPointer->setText(requestStructPointer->filterListTitle);
199     sublistLineEditPointer->setText(globalFilterListHelperPointer->getSublistName(requestStructPointer->sublistInt));
200     appliedEntryListLineEditPointer->setText(requestStructPointer->entryStruct.appliedEntryList.join(QLatin1String(" * ")));
201     domainLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.domain));
202     thirdPartyFilterLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.thirdParty));
203     initialMatchLineEditPointer->setText(requestStructPointer->entryStruct.initialMatch ? i18n("Yes") : QLatin1String());
204     finalMatchLineEditPointer->setText(requestStructPointer->entryStruct.finalMatch ? i18n("Yes") : QLatin1String());
205     domainListLineEditPointer->setText(requestStructPointer->entryStruct.domainList.join(QLatin1String(" | ")));
206     hasRequestOptionsCheckBoxPointer->setChecked(hasRequestOptions);
207     fontLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.font));
208     imageLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.image));
209     mainFrameLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.mainFrame));
210     mediaLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.media));
211     objectLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.object));
212     otherLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.other));
213     pingLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.ping));
214     scriptLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.script));
215     styleSheetLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.styleSheet));
216     subFrameLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.subFrame));
217     webSocketLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.webSocket));
218     xmlHttpRequestLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.xmlHttpRequest));
219     appliedFilterOptionsLineEditPointer->setText(requestStructPointer->entryStruct.appliedFilterOptionsList.join(QLatin1String(" , ")));
220     originalFilterOptionsLineEditPointer->setText(requestStructPointer->entryStruct.originalFilterOptions);
221     originalEntryLineEditPointer->setText(requestStructPointer->entryStruct.originalEntry);
222
223     // Determine if this is an allow list, which have a sublist int of of 0-2.
224     isAllowList = (requestStructPointer->sublistInt <= 2);
225
226     // Set the third-party request background palette.
227     if (requestStructPointer->isThirdPartyRequest)
228         thirdPartyRequestLineEditPointer->setPalette(negativeBackgroundPalette);
229     else
230         thirdPartyRequestLineEditPointer->setPalette(normalBackgroundPalette);
231
232     // Set the initial and final background palettes.
233     setInitialOrFinalBackgroundPalette(initialMatchLineEditPointer);
234     setInitialOrFinalBackgroundPalette(finalMatchLineEditPointer);
235
236     // Set the request option background palettes.
237     setFilterOptionBackgroundPalette(domainLineEditPointer);
238     setFilterOptionBackgroundPalette(thirdPartyFilterLineEditPointer);
239     setFilterOptionBackgroundPalette(fontLineEditPointer);
240     setFilterOptionBackgroundPalette(imageLineEditPointer);
241     setFilterOptionBackgroundPalette(mainFrameLineEditPointer);
242     setFilterOptionBackgroundPalette(mediaLineEditPointer);
243     setFilterOptionBackgroundPalette(objectLineEditPointer);
244     setFilterOptionBackgroundPalette(otherLineEditPointer);
245     setFilterOptionBackgroundPalette(pingLineEditPointer);
246     setFilterOptionBackgroundPalette(scriptLineEditPointer);
247     setFilterOptionBackgroundPalette(styleSheetLineEditPointer);
248     setFilterOptionBackgroundPalette(subFrameLineEditPointer);
249     setFilterOptionBackgroundPalette(webSocketLineEditPointer);
250     setFilterOptionBackgroundPalette(xmlHttpRequestLineEditPointer);
251
252     // Set the request option status.
253     fontLineEditPointer->setEnabled(hasRequestOptions);
254     imageLineEditPointer->setEnabled(hasRequestOptions);
255     mainFrameLineEditPointer->setEnabled(hasRequestOptions);
256     mediaLineEditPointer->setEnabled(hasRequestOptions);
257     objectLineEditPointer->setEnabled(hasRequestOptions);
258     otherLineEditPointer->setEnabled(hasRequestOptions);
259     pingLineEditPointer->setEnabled(hasRequestOptions);
260     scriptLineEditPointer->setEnabled(hasRequestOptions);
261     styleSheetLineEditPointer->setEnabled(hasRequestOptions);
262     subFrameLineEditPointer->setEnabled(hasRequestOptions);
263     webSocketLineEditPointer->setEnabled(hasRequestOptions);
264     xmlHttpRequestLineEditPointer->setEnabled(hasRequestOptions);
265
266     // Set the domain list line edit to have the same palette as the domain line edit.
267     domainListLineEditPointer->setPalette(domainLineEditPointer->palette());
268
269     // Set the button status.
270     previousButtonPointer->setEnabled(previousEnabled);
271     nextButtonPointer->setEnabled(nextEnabled);
272
273     // Set the sublist background palette.
274     switch (requestStructPointer->sublistInt)
275     {
276         case FilterListHelper::MAIN_ALLOWLIST:
277         case FilterListHelper::INITIAL_DOMAIN_ALLOWLIST:
278         case FilterListHelper::REGULAR_EXPRESSION_ALLOWLIST:
279             sublistLineEditPointer->setPalette(positiveBackgroundPalette);
280             break;
281
282         case FilterListHelper::MAIN_BLOCKLIST:
283         case FilterListHelper::INITIAL_DOMAIN_BLOCKLIST:
284         case FilterListHelper::REGULAR_EXPRESSION_BLOCKLIST:
285             sublistLineEditPointer->setPalette(negativeBackgroundPalette);
286             break;
287     }
288
289     // Set the applied entry background palette to be the same as the sublist.
290     appliedEntryListLineEditPointer->setPalette(sublistLineEditPointer->palette());
291
292     // Set the resource type background palette.
293     if (hasRequestOptions)  // There are request options.
294     {
295         switch (requestStructPointer->resourceTypeInt)
296         {
297             // Font
298             case QWebEngineUrlRequestInfo::ResourceTypeFontResource:
299             {
300                 resourceTypeLineEditPointer->setPalette(fontLineEditPointer->palette());
301                 break;
302             }
303
304             // Image.
305             case QWebEngineUrlRequestInfo::ResourceTypeImage:
306             {
307                 resourceTypeLineEditPointer->setPalette(imageLineEditPointer->palette());
308                 break;
309             }
310
311             // Main Frame.
312             case QWebEngineUrlRequestInfo::ResourceTypeMainFrame:
313             case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame:
314             {
315                 resourceTypeLineEditPointer->setPalette(mainFrameLineEditPointer->palette());
316                 break;
317             }
318
319             // Media.
320             case QWebEngineUrlRequestInfo::ResourceTypeMedia:
321             {
322                 resourceTypeLineEditPointer->setPalette(mediaLineEditPointer->palette());
323                 break;
324             }
325
326             // Object.
327             case QWebEngineUrlRequestInfo::ResourceTypeObject:
328             {
329                 resourceTypeLineEditPointer->setPalette(objectLineEditPointer->palette());
330                 break;
331             }
332
333             // Other.
334             case QWebEngineUrlRequestInfo::ResourceTypeSubResource:
335             case QWebEngineUrlRequestInfo::ResourceTypeWorker:
336             case QWebEngineUrlRequestInfo::ResourceTypeSharedWorker:
337             case QWebEngineUrlRequestInfo::ResourceTypePrefetch:
338             case QWebEngineUrlRequestInfo::ResourceTypeFavicon:
339             case QWebEngineUrlRequestInfo::ResourceTypeServiceWorker:
340             case QWebEngineUrlRequestInfo::ResourceTypeCspReport:
341             case QWebEngineUrlRequestInfo::ResourceTypePluginResource:
342             case QWebEngineUrlRequestInfo::ResourceTypeJson:
343             case QWebEngineUrlRequestInfo::ResourceTypeUnknown:
344             {
345                 resourceTypeLineEditPointer->setPalette(otherLineEditPointer->palette());
346                 break;
347             }
348
349             // Ping.
350             case QWebEngineUrlRequestInfo::ResourceTypePing:
351             {
352                 resourceTypeLineEditPointer->setPalette(pingLineEditPointer->palette());
353                 break;
354             }
355
356             // Script.
357             case QWebEngineUrlRequestInfo::ResourceTypeScript:
358             {
359                 resourceTypeLineEditPointer->setPalette(scriptLineEditPointer->palette());
360                 break;
361             }
362
363             // Style Sheet.
364             case QWebEngineUrlRequestInfo::ResourceTypeStylesheet:
365             {
366                 resourceTypeLineEditPointer->setPalette(styleSheetLineEditPointer->palette());
367                 break;
368             }
369
370             // Sub Frame.
371             case QWebEngineUrlRequestInfo::ResourceTypeSubFrame:
372             case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame:
373             {
374                 resourceTypeLineEditPointer->setPalette(subFrameLineEditPointer->palette());
375                 break;
376             }
377
378             // Web Socket.
379             case QWebEngineUrlRequestInfo::ResourceTypeWebSocket:
380             {
381                 resourceTypeLineEditPointer->setPalette(webSocketLineEditPointer->palette());
382                 break;
383             }
384
385             // XML HTTP Request.
386             case QWebEngineUrlRequestInfo::ResourceTypeXhr:
387             {
388                 resourceTypeLineEditPointer->setPalette(xmlHttpRequestLineEditPointer->palette());
389                 break;
390             }
391         }
392     }
393     else  // There are no request options.
394     {
395         // Reset the resource type background palette.
396         resourceTypeLineEditPointer->setPalette(normalBackgroundPalette);
397     }
398
399     // Modify the interface based on the disposition.
400     switch (requestStructPointer->dispositionInt)
401     {
402         case FilterListHelper::DEFAULT:
403         {
404             // Reset the disposition line edit background.
405             dispositionLineEditPointer->setPalette(normalBackgroundPalette);
406
407             // Reset the request URL palettes.
408             requestUrlLineEditPointer->setPalette(normalBackgroundPalette);
409             requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
410             truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette);
411             truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
412
413             // Hide the filter list entry views.
414             filterListEntryWidget->hide();
415
416             break;
417         }
418
419         case FilterListHelper::ALLOWED:
420         {
421             // Colorize the disposition line edit background.
422             dispositionLineEditPointer->setPalette(positiveBackgroundPalette);
423
424             // Colorize the request URLs.
425             setRequestUrlBackgroundPalettes(requestStructPointer->matchedUrlType);
426
427             // Show the filter list entry views.
428             filterListEntryWidget->show();
429
430             break;
431         }
432
433         case FilterListHelper::BLOCKED:
434         {
435             // Colorize the disposition line edit background.
436             dispositionLineEditPointer->setPalette(negativeBackgroundPalette);
437
438             // Colorize the request URLs.
439             setRequestUrlBackgroundPalettes(requestStructPointer->matchedUrlType);
440
441             // Show the filter list entry views.
442             filterListEntryWidget->show();
443
444             break;
445         }
446     }
447 }
448
449 void RequestDetailDialog::previous()
450 {
451     // Update the current row.
452     --currentRow;
453
454     // Populate the dialog.
455     populateDialog(currentRow);
456 }
457
458 void RequestDetailDialog::next()
459 {
460     // Update the current row.
461     ++currentRow;
462
463     // Populate the dialog.
464     populateDialog(currentRow);
465 }
466
467 void RequestDetailDialog::setFilterOptionBackgroundPalette(QLineEdit *lineEditPointer)
468 {
469     // Set the background palette according to the text.
470     if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionDisposition::Null))  // Not text is displayed.
471     {
472         // Set the normal background palette.
473         lineEditPointer->setPalette(normalBackgroundPalette);
474     }
475     else if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionDisposition::Apply))  // `Apply` is displayed.
476     {
477         // Set the background palette according to the sublist type.
478         if (isAllowList)
479             lineEditPointer->setPalette(positiveBackgroundPalette);
480         else
481             lineEditPointer->setPalette(negativeBackgroundPalette);
482     }
483     else  // `Override` is displayed.
484     {
485         // Set the background palette according to the sublist type.
486         if (isAllowList)
487             lineEditPointer->setPalette(negativeBackgroundPalette);
488         else
489             lineEditPointer->setPalette(positiveBackgroundPalette);
490     }
491 }
492
493 void RequestDetailDialog::setInitialOrFinalBackgroundPalette(QLineEdit *lineEditPointer)
494 {
495     // Set the background palette according to the text.
496     if (lineEditPointer->text() == i18n("Yes"))  // `Yes` is displayed.
497     {
498         // Set the background palette according to the sublist type.
499         if (isAllowList)
500             lineEditPointer->setPalette(positiveBackgroundPalette);
501         else
502             lineEditPointer->setPalette(negativeBackgroundPalette);
503     }
504     else  // No text is displayed.
505     {
506         // Set the normal background palette.
507         lineEditPointer->setPalette(normalBackgroundPalette);
508     }
509 }
510
511 void RequestDetailDialog::setRequestUrlBackgroundPalettes(RequestUrlType matchedUrlType)
512 {
513     // Colorize the request URL strings according to the matched URL.
514     switch (matchedUrlType)
515     {
516         case RequestUrlType::Url:  // URL.
517         {
518             // Set the request URL palette to match the disposition line edit.
519             requestUrlLineEditPointer->setPalette(dispositionLineEditPointer->palette());
520
521             // Reset the other palettes.
522             requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
523             truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette);
524             truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
525
526             break;
527         }
528
529         case RequestUrlType::UrlWithSeparators:  // URL with separators.
530         {
531             // Set the request URL with separators palette to match the disposition line edit.
532             requestUrlWithSeparatorsLineEditPointer->setPalette(dispositionLineEditPointer->palette());
533
534             // Reset the other palettes.
535             requestUrlLineEditPointer->setPalette(normalBackgroundPalette);
536             truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette);
537             truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
538
539             break;
540         }
541
542         case RequestUrlType::TruncatedUrl:  // Truncated URL.
543         {
544             // Set the truncated request URL palette to match the disposition line edit.
545             truncatedRequestUrlLineEditPointer->setPalette(dispositionLineEditPointer->palette());
546
547             // Reset the other palettes.
548             requestUrlLineEditPointer->setPalette(normalBackgroundPalette);
549             requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
550             truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
551
552             break;
553         }
554
555         case RequestUrlType::TruncatedUrlWithSeparators:  // Truncated URL with separators.
556         {
557             // Set the truncated request URL with separators palette to match the disposition line edit.
558             truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(dispositionLineEditPointer->palette());
559
560             // Reset the other palettes.
561             requestUrlLineEditPointer->setPalette(normalBackgroundPalette);
562             requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette);
563             truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette);
564
565             break;
566         }
567     }
568 }