X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fdialogs%2FAddCookieDialog.cpp;fp=src%2Fdialogs%2FAddCookieDialog.cpp;h=0000000000000000000000000000000000000000;hp=a81d4338bd4df79567b3b485e043c43ce3fb3d72;hb=cba9a47f00b59f59f76f1b5195086285ca0cdb59;hpb=9b6cee96126484925bec4f4ab30c2b880df687fe diff --git a/src/dialogs/AddCookieDialog.cpp b/src/dialogs/AddCookieDialog.cpp deleted file mode 100644 index a81d433..0000000 --- a/src/dialogs/AddCookieDialog.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright © 2022 Soren Stoutner . - * - * This file is part of Privacy Browser PC . - * - * Privacy Browser PC is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privacy Browser PC is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . - */ - -// Application headers. -#include "AddCookieDialog.h" -#include "ui_AddCookieDialog.h" - -// KDE Framework headers. -#include - -// Qt toolkit header. -#include -#include - -AddCookieDialog::AddCookieDialog() : QDialog(nullptr) -{ - // Set the dialog window title. - setWindowTitle(i18nc("The add cookie dialog window title", "Add Cookie")); - - // Set the window modality. - setWindowModality(Qt::WindowModality::ApplicationModal); - - // Instantiate the cookie settings dialog UI. - Ui::AddCookieDialog addCookieDialogUi; - - // Setup the UI. - addCookieDialogUi.setupUi(this); - - // Get handles for the views. - domainLineEditPointer = addCookieDialogUi.domainLineEdit; - nameLineEditPointer = addCookieDialogUi.nameLineEdit; - expirationCheckBoxPointer = addCookieDialogUi.expirationCheckBox; - expirationDateTimeEditPointer = addCookieDialogUi.expirationDateTimeEdit; - pathLineEditPointer = addCookieDialogUi.pathLineEdit; - httpOnlyCheckBoxPointer = addCookieDialogUi.httpOnlyCheckBox; - secureCheckBoxPointer = addCookieDialogUi.secureCheckBox; - valueLineEditPointer = addCookieDialogUi.valueLineEdit; - QDialogButtonBox *dialogButtonBoxPointer = addCookieDialogUi.dialogButtonBox; - saveButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::Save); - - // Connect the line edits. - connect(domainLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(updateUi())); - connect(nameLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(updateUi())); - connect(pathLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(updateUi())); - connect(valueLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(updateUi())); - - // Connect the check boxes. - connect(expirationCheckBoxPointer, SIGNAL(stateChanged(int)), this, SLOT(updateExpirationDateTimeState(int))); - - // Connect the buttons. - connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(saveCookie())); - connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject())); - - // Update the UI. - updateUi(); -} - -void AddCookieDialog::saveCookie() -{ - // Create the variables. - QNetworkCookie cookie; - - // Populate the cookie. - cookie.setDomain(domainLineEditPointer->text()); - cookie.setName(nameLineEditPointer->text().toUtf8()); - cookie.setPath(pathLineEditPointer->text()); - cookie.setHttpOnly(httpOnlyCheckBoxPointer->isChecked()); - cookie.setSecure(secureCheckBoxPointer->isChecked()); - cookie.setValue(valueLineEditPointer->text().toUtf8()); - - // Populate the expiration date if it is specified. - if (expirationCheckBoxPointer->isChecked()) cookie.setExpirationDate(expirationDateTimeEditPointer->dateTime()); - - // Add the cookie. - emit addCookie(cookie); - - // Close the dialog. - reject(); -} - -void AddCookieDialog::updateExpirationDateTimeState(const int &newState) const -{ - // Update the state of the of the expiration date time edit. - switch (newState) - { - case Qt::Unchecked: - // Disable the expiration date time. - expirationDateTimeEditPointer->setEnabled(false); - - break; - - case Qt::Checked: - // Enable the expiration date time edit. - expirationDateTimeEditPointer->setEnabled(true); - - break; - } -} - -void AddCookieDialog::updateUi() const -{ - // Update the state of the save button based on all the required fields containing text. - saveButtonPointer->setDisabled(domainLineEditPointer->text().isEmpty() || nameLineEditPointer->text().isEmpty() || pathLineEditPointer->text().isEmpty() || - valueLineEditPointer->text().isEmpty()); -}