*/
// 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 <KLocalizedString>
-// The Qt toolkit headers.
+// Qt toolkit headers.
#include <QDateTime>
#include <QMessageBox>
+#include <QUrl>
CookiesDialog::CookiesDialog(QList<QNetworkCookie> *originalCookieListPointer) : QDialog(nullptr), cookieListPointer(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;
// 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("<font size=\"+1\"><b>" + cookie.domain() + "</b></font>");
- nameLabelPointer->setText("<font size=\"+1\"><b>" + cookie.name() + "</b></font>");
- expirationDateLabelPointer->setText("<b>" + cookie.expirationDate().toString() + "</b>");
- pathLabelPointer->setText("<b>" + cookie.path() + "</b>");
- httpOnlyCheckBoxPointer->setChecked(cookie.isHttpOnly());
- secureCheckBoxPointer->setChecked(cookie.isSecure());
- valueLabelPointer->setText("<b>" + cookie.value() + "</b>");
-
- // 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);
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.
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("<font size=\"+1\"><b>" + cookie.domain() + "</b></font>");
+ nameLabelPointer->setText("<font size=\"+1\"><b>" + cookie.name() + "</b></font>");
+ expirationDateLabelPointer->setText("<b>" + cookie.expirationDate().toString() + "</b>");
+ pathLabelPointer->setText("<b>" + cookie.path() + "</b>");
+ httpOnlyCheckBoxPointer->setChecked(cookie.isHttpOnly());
+ secureCheckBoxPointer->setChecked(cookie.isSecure());
+ valueLabelPointer->setText("<b>" + cookie.value() + "</b>");
+
+ // 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.