X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fdialogs%2FCookiesDialog.cpp;fp=src%2Fdialogs%2FCookiesDialog.cpp;h=972bc67d1d49b132a9fb4634f9631ff22804012c;hp=3321c6569f9f069f582f7f8c3e04f8fdae97fec8;hb=9b6cee96126484925bec4f4ab30c2b880df687fe;hpb=8933c941521c591a962034ecf3486c9143bf1f80 diff --git a/src/dialogs/CookiesDialog.cpp b/src/dialogs/CookiesDialog.cpp index 3321c65..972bc67 100644 --- a/src/dialogs/CookiesDialog.cpp +++ b/src/dialogs/CookiesDialog.cpp @@ -18,16 +18,18 @@ */ // Application headers. +#include "AddCookieDialog.h" #include "CookiesDialog.h" +#include "ui_CookieDisplayWidget.h" #include "ui_CookiesDialog.h" -#include "ui_CookieWidget.h" -// The KDE Frameworks headers. +// KDE Frameworks headers. #include -// The Qt toolkit headers. +// Qt toolkit headers. #include #include +#include CookiesDialog::CookiesDialog(QList *originalCookieListPointer) : QDialog(nullptr), cookieListPointer(originalCookieListPointer) { @@ -35,7 +37,7 @@ CookiesDialog::CookiesDialog(QList *originalCookieListPointer) : setWindowTitle(i18nc("The cookies dialog window title", "Cookies")); // Set the window modality. - setWindowModality(Qt::WindowModality::WindowModal); + setWindowModality(Qt::WindowModality::ApplicationModal); // Instantiate the cookie settings dialog UI. Ui::CookiesDialog cookiesDialogUi; @@ -43,66 +45,37 @@ CookiesDialog::CookiesDialog(QList *originalCookieListPointer) : // Setup the UI. cookiesDialogUi.setupUi(this); + // Get a handle for the scroll area. + QScrollArea *scrollAreaPointer = cookiesDialogUi.scrollArea; + // Create the scroll area widget. QWidget *scrollAreaWidgetPointer = new QWidget(); + // Set the scroll area widget. + scrollAreaPointer->setWidget(scrollAreaWidgetPointer); + + // Create a scroll area VBox layout. + QVBoxLayout *scrollAreaVBoxLayoutPointer = new QVBoxLayout(); + + // Set the scroll area widget layout. + scrollAreaWidgetPointer->setLayout(scrollAreaVBoxLayoutPointer); + // Create the cookies VBox layout. cookiesVBoxLayoutPointer = new QVBoxLayout(); + // Populate the scroll area VBox layout. The stretch prevents the cookies from expanding vertically if they are smaller than the dialog. + scrollAreaVBoxLayoutPointer->addLayout(cookiesVBoxLayoutPointer); + scrollAreaVBoxLayoutPointer->addStretch(); + // Populate the VBoxLayout. for (QNetworkCookie cookie : *cookieListPointer) { - // Create a cookie display widget. - QWidget *cookieDisplayWidgetPointer = new QWidget(); - - // Instantiate the cookie widget dialog UI. - Ui::CookieWidget cookieWidgetUi; - - // Setup the UI. - cookieWidgetUi.setupUi(cookieDisplayWidgetPointer); - - // Get handles for the views. - QLabel *domainLabelPointer = cookieWidgetUi.domainLabel; - QLabel *nameLabelPointer = cookieWidgetUi.nameLabel; - QLabel *expirationDateLabelPointer = cookieWidgetUi.expirationDateLabel; - QLabel *pathLabelPointer = cookieWidgetUi.pathLabel; - QCheckBox *httpOnlyCheckBoxPointer = cookieWidgetUi.httpOnlyCheckBox; - QCheckBox *secureCheckBoxPointer = cookieWidgetUi.secureCheckBox; - QLabel *valueLabelPointer = cookieWidgetUi.valueLabel; - - // Populate the views. - domainLabelPointer->setText("" + cookie.domain() + ""); - nameLabelPointer->setText("" + cookie.name() + ""); - expirationDateLabelPointer->setText("" + cookie.expirationDate().toString() + ""); - pathLabelPointer->setText("" + cookie.path() + ""); - httpOnlyCheckBoxPointer->setChecked(cookie.isHttpOnly()); - secureCheckBoxPointer->setChecked(cookie.isSecure()); - valueLabelPointer->setText("" + cookie.value() + ""); - - // Add the widget to the cookies VBox layout. - cookiesVBoxLayoutPointer->addWidget(cookieDisplayWidgetPointer); - - // Create a line. - QFrame *lineFrame = new QFrame(); - - // Format the line. - lineFrame->setFrameShape(QFrame::HLine); - lineFrame->setFrameShadow(QFrame::Sunken); - - // Add the line to the cookies VBox layout. - cookiesVBoxLayoutPointer->addWidget(lineFrame); + // Add the cookie to the layout. + addCookieToLayout(cookie); } - // Set the scroll area widget layout. - scrollAreaWidgetPointer->setLayout(cookiesVBoxLayoutPointer); - - // Get a handle for the scroll area. - QScrollArea *scrollAreaPointer = cookiesDialogUi.scrollArea; - - // Set the scroll area widget. - scrollAreaPointer->setWidget(scrollAreaWidgetPointer); - // Get handles for the buttons. + addCookieButtonPointer = cookiesDialogUi.addCookieButton; QDialogButtonBox *dialogButtonBoxPointer = cookiesDialogUi.dialogButtonBox; QPushButton *cancelButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::Close); @@ -113,7 +86,8 @@ CookiesDialog::CookiesDialog(QList *originalCookieListPointer) : deleteAllButtonPointer->setIcon(QIcon::fromTheme("delete")); // Connect the buttons. - connect(deleteAllButtonPointer, SIGNAL(released()), this, SLOT(showDeleteAllMessageBox())); + connect(addCookieButtonPointer, SIGNAL(clicked()), this, SLOT(showAddCookieMessageBox())); + connect(deleteAllButtonPointer, SIGNAL(clicked()), this, SLOT(showDeleteAllMessageBox())); connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject())); // Set the cancel button to be the default. @@ -123,6 +97,70 @@ CookiesDialog::CookiesDialog(QList *originalCookieListPointer) : updateUi(); }; +void CookiesDialog::addCookieFromDialog(const QNetworkCookie &cookie) const +{ + // Add the cookie to the cookie list and the cookie store. + emit addCookie(cookie); + + // Add the cookie to the VBox layout. + addCookieToLayout(cookie); +} + +void CookiesDialog::addCookieToLayout(const QNetworkCookie &cookie) const +{ + // Create a cookie display widget. + QWidget *cookieDisplayWidgetPointer = new QWidget(); + + // Instantiate the cookie widget dialog UI. + Ui::CookieDisplayWidget cookieDisplayWidgetUi; + + // Setup the UI. + cookieDisplayWidgetUi.setupUi(cookieDisplayWidgetPointer); + + // Get handles for the views. + QLabel *domainLabelPointer = cookieDisplayWidgetUi.domainLabel; + QLabel *nameLabelPointer = cookieDisplayWidgetUi.nameLabel; + QLabel *expirationDateLabelPointer = cookieDisplayWidgetUi.expirationDateLabel; + QLabel *pathLabelPointer = cookieDisplayWidgetUi.pathLabel; + QCheckBox *httpOnlyCheckBoxPointer = cookieDisplayWidgetUi.httpOnlyCheckBox; + QCheckBox *secureCheckBoxPointer = cookieDisplayWidgetUi.secureCheckBox; + QLabel *valueLabelPointer = cookieDisplayWidgetUi.valueLabel; + + // Populate the views. + domainLabelPointer->setText("" + cookie.domain() + ""); + nameLabelPointer->setText("" + cookie.name() + ""); + expirationDateLabelPointer->setText("" + cookie.expirationDate().toString() + ""); + pathLabelPointer->setText("" + cookie.path() + ""); + httpOnlyCheckBoxPointer->setChecked(cookie.isHttpOnly()); + secureCheckBoxPointer->setChecked(cookie.isSecure()); + valueLabelPointer->setText("" + cookie.value() + ""); + + // Add the cookie display widget to the cookies VBox layout. + cookiesVBoxLayoutPointer->addWidget(cookieDisplayWidgetPointer); + + // Create a line. + QFrame *lineFrame = new QFrame(); + + // Format the line. + lineFrame->setFrameShape(QFrame::HLine); + lineFrame->setFrameShadow(QFrame::Sunken); + + // Add the line to the cookies VBox layout. + cookiesVBoxLayoutPointer->addWidget(lineFrame); +} + +void CookiesDialog::showAddCookieMessageBox() const +{ + // Instantiate an add cookie dialog. + QDialog *addCookieDialogPointer = new AddCookieDialog(); + + // Show the dialog. + addCookieDialogPointer->show(); + + // Add the cookie if directed. + connect(addCookieDialogPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookieFromDialog(QNetworkCookie))); +} + void CookiesDialog::showDeleteAllMessageBox() const { // Instantiate a delete all message box.