2 * Copyright 2024 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc/>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
21 #include "RequestDetailDialog.h"
22 #include "GlobalVariables.h"
23 #include "ui_RequestDetailDialog.h"
24 #include "structs/RequestStruct.h"
26 // Qt toolkit headers.
29 // KDE Frameworks headers.
30 #include <KActionCollection>
31 #include <KColorScheme>
33 // Construct the class.
34 RequestDetailDialog::RequestDetailDialog(QWidget *parentWidgetPointer, QByteArray &requestStructByteArray) : QDialog(parentWidgetPointer)
36 // Create a request struct data stream reader.
37 QDataStream requestStructDataStreamReader(requestStructByteArray);
39 // Create a new request struct.
40 RequestStruct *requestStructPointer = new RequestStruct();
42 // Populate the new request struct.
43 requestStructDataStreamReader >> requestStructPointer->dispositionInt;
44 requestStructDataStreamReader >> requestStructPointer->entryStruct.appliedEntry;
45 requestStructDataStreamReader >> requestStructPointer->entryStruct.originalEntry;
46 requestStructDataStreamReader >> requestStructPointer->filterListTitle;
47 requestStructDataStreamReader >> requestStructPointer->navigationTypeInt;
48 requestStructDataStreamReader >> requestStructPointer->requestMethodString;
49 requestStructDataStreamReader >> requestStructPointer->resourceTypeInt;
50 requestStructDataStreamReader >> requestStructPointer->sublistInt;
51 requestStructDataStreamReader >> requestStructPointer->urlString;
53 qDebug().noquote().nospace() << "Disposition: " << requestStructPointer->dispositionInt;
54 qDebug().noquote().nospace() << "Applied Entry: " << requestStructPointer->entryStruct.appliedEntry;
55 qDebug().noquote().nospace() << "Original Entry: " << requestStructPointer->entryStruct.originalEntry;
56 qDebug().noquote().nospace() << "Filter List: " << requestStructPointer->filterListTitle;
57 qDebug().noquote().nospace() << "Request Method: " << requestStructPointer->requestMethodString;
58 qDebug().noquote().nospace() << "Navigation Type: " << requestStructPointer->navigationTypeInt;
59 qDebug().noquote().nospace() << "Resource Type: " << requestStructPointer->resourceTypeInt;
60 qDebug().noquote().nospace() << "Sublist: " << requestStructPointer->sublistInt;
61 qDebug().noquote().nospace() << "URL: " << requestStructPointer->urlString;
63 // Set the window title.
64 setWindowTitle(i18nc("The request detail dialog window title", "Request Detail"));
66 // Set the window modality.
67 setWindowModality(Qt::WindowModality::ApplicationModal);
69 // Instantiate the request detail dialog UI.
70 Ui::RequestDetailDialog requestDetailDialogUi;
73 requestDetailDialogUi.setupUi(this);
75 // Get handles for the views.
76 QLineEdit *dispositionLineEditPointer = requestDetailDialogUi.dispositionLineEdit;
77 QLineEdit *urlLineEditPointer = requestDetailDialogUi.urlLineEdit;
78 QLineEdit *requestMethodLineEditPointer = requestDetailDialogUi.requestMethodLineEdit;
79 QLineEdit *navigationTypeLineEditPointer = requestDetailDialogUi.navigationTypeLineEdit;
80 QLineEdit *resourceTypeLineEditPointer = requestDetailDialogUi.resourceTypeLineEdit;
81 QFrame *horizontalLinePointer = requestDetailDialogUi.horizontalLine;
82 QLabel *filterListLabelPointer = requestDetailDialogUi.filterListLabel;
83 QLineEdit *filterListLineEditPointer = requestDetailDialogUi.filterListLineEdit;
84 QLabel *sublistLabelPointer = requestDetailDialogUi.sublistLabel;
85 QLineEdit *sublistLineEditPointer = requestDetailDialogUi.sublistListLineEdit;
86 QLabel *appliedEntryLabelPointer = requestDetailDialogUi.appliedEntryLabel;
87 QLineEdit *appliedEntryLineEditPointer = requestDetailDialogUi.appliedEntryLineEdit;
88 QLabel *originalEntryLabelPointer = requestDetailDialogUi.originalEntryLabel;
89 QLineEdit *originalEntryLineEditPointer = requestDetailDialogUi.originalEntryLineEdit;
90 QDialogButtonBox *dialogButtonBoxPointer = requestDetailDialogUi.dialogButtonBox;
92 // Populate the views.
93 dispositionLineEditPointer->setText(globalFilterListHelperPointer->getDispositionString(requestStructPointer->dispositionInt));
94 urlLineEditPointer->setText(requestStructPointer->urlString);
95 requestMethodLineEditPointer->setText(requestStructPointer->requestMethodString);
96 navigationTypeLineEditPointer->setText(globalFilterListHelperPointer->getNavigationTypeString(requestStructPointer->navigationTypeInt));
97 resourceTypeLineEditPointer->setText(globalFilterListHelperPointer->getResourceTypeString(requestStructPointer->resourceTypeInt));
98 filterListLineEditPointer->setText(requestStructPointer->filterListTitle);
99 sublistLineEditPointer->setText(globalFilterListHelperPointer->getSublistName(requestStructPointer->sublistInt));
100 appliedEntryLineEditPointer->setText(requestStructPointer->entryStruct.appliedEntry);
101 originalEntryLineEditPointer->setText(requestStructPointer->entryStruct.originalEntry);
103 // Get the disposition line edit palettes.
104 QPalette normalBackgroundPalette = dispositionLineEditPointer->palette();
105 QPalette negativeBackgroundPalette = normalBackgroundPalette;
106 QPalette positiveBackgroundPalette = normalBackgroundPalette;
108 // Modify the palettes.
109 KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
110 KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
112 // Modify the interface based on the disposition.
113 switch (requestStructPointer->dispositionInt)
115 case FilterListHelper::DEFAULT:
117 // Hide the filter list views.
118 horizontalLinePointer->hide();
119 filterListLabelPointer->hide();
120 filterListLineEditPointer->hide();
121 sublistLabelPointer->hide();
122 sublistLineEditPointer->hide();
123 appliedEntryLabelPointer->hide();
124 appliedEntryLineEditPointer->hide();
125 originalEntryLabelPointer->hide();
126 originalEntryLineEditPointer->hide();
131 case FilterListHelper::ALLOWED:
133 // Colorize the disposition line edit background.
134 dispositionLineEditPointer->setPalette(positiveBackgroundPalette);
139 case FilterListHelper::BLOCKED:
141 // Colorize the disposition line edit background.
142 dispositionLineEditPointer->setPalette(negativeBackgroundPalette);
148 // Connect the buttons.
149 connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(close()));