// Application headers.
#include "AddOrEditCookieDialog.h"
#include "CookiesDialog.h"
+#include "DurableCookiesDialog.h"
#include "ui_CookiesDialog.h"
#include "databases/CookiesDatabase.h"
#include <QShortcut>
#include <QUrl>
-// Construct the class.
+// Define the cookie sort predicate.
bool cookieSortPredicate(const QNetworkCookie &leftHandCookie, const QNetworkCookie &rightHandCookie)
{
// Check to see if the domains are identical.
// Sort the cookies by the top level domain.
return (leftHandTopLevelDomain < rightHandTopLevelDomain);
}
-
}
}
+// Construct the class.
CookiesDialog::CookiesDialog(std::list<QNetworkCookie> *originalCookieListPointer) : QDialog(nullptr), cookieListPointer(originalCookieListPointer)
{
// Set the dialog window title.
// Indicate that all the rows are the same height, wich improves performance.
treeViewPointer->setUniformRowHeights(true);
- // Disable editing.
+ // Disable editing in the tree view.
treeViewPointer->setEditTriggers(QAbstractItemView::NoEditTriggers);
// Set the tree model.
addCookieButtonPointer = cookiesDialogUi.addCookieButton;
editCookieButtonPointer = cookiesDialogUi.editCookieButton;
deleteCookieButtonPointer = cookiesDialogUi.deleteCookieButton;
+ deleteAllButtonPointer = cookiesDialogUi.deleteAllCookiesButton;
QDialogButtonBox *dialogButtonBoxPointer = cookiesDialogUi.dialogButtonBox;
QPushButton *closeButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::Close);
- // Add a delete all button to the dialog button box.
- deleteAllButtonPointer = dialogButtonBoxPointer->addButton(i18nc("Delete all cookies button", "Delete all"), QDialogButtonBox::ActionRole);
+ // Add buttons to the dialog button box.
+ durableCookiesButtonPointer = dialogButtonBoxPointer->addButton(i18nc("View the durable cookies button", "Durable cookies - %1", CookiesDatabase::cookieCount()),
+ QDialogButtonBox::ActionRole);
- // Set the delete all button icon.
- deleteAllButtonPointer->setIcon(QIcon::fromTheme("delete"));
+ // Set the button icons.
+ durableCookiesButtonPointer->setIcon(QIcon::fromTheme("view-visible"));
// Connect the buttons.
connect(addCookieButtonPointer, SIGNAL(clicked()), this, SLOT(showAddCookieDialog()));
connect(editCookieButtonPointer, SIGNAL(clicked()), this, SLOT(showEditCookieDialog()));
connect(deleteCookieButtonPointer, SIGNAL(clicked()), this, SLOT(showDeleteCookieMessageBox()));
+ connect(durableCookiesButtonPointer, SIGNAL(clicked()), this, SLOT(showDurableCookiesDialog()));
connect(deleteAllButtonPointer, SIGNAL(clicked()), this, SLOT(showDeleteAllMessageBox()));
connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
- // Set the cancel button to be the default.
+ // Set the close button to be the default.
closeButtonPointer->setDefault(true);
// Create the keyboard shortcuts.
treeModelPointer->removeRow(modelIndex.row(), parentIndex);
}
+void CookiesDialog::deleteCookieFromDatabase(const QNetworkCookie &cookie) const
+{
+ // Get a list of the matching domains. There should only be one item in this list
+ QList<QStandardItem *> domainList = treeModelPointer->findItems(cookie.domain());
+
+ // Find any matching cookies.
+ for (QStandardItem *domainItemPointer : domainList)
+ {
+ // Get the number of cookies in the domain.
+ int numberOfCookies = domainItemPointer->rowCount();
+
+ // Initialize the tracking variables.
+ bool cookieFound = false;
+ int currentRow = 0;
+
+ // Find the cookie in the tree model.
+ while (!cookieFound && (currentRow < numberOfCookies))
+ {
+ // Get the name item.
+ QStandardItem *nameItemPointer = domainItemPointer->child(currentRow);
+
+ // Get the name model index.
+ QModelIndex nameModelIndex = nameItemPointer->index();
+
+ // Check to see if the name and the path match.
+ if ((nameModelIndex.data().toString() == cookie.name()) && (nameModelIndex.siblingAtColumn(2).data().toString() == cookie.path()))
+ {
+ // Set the current index.
+ treeSelectionModelPointer->setCurrentIndex(nameModelIndex, QItemSelectionModel::ClearAndSelect);
+
+ // Delete the cookie.
+ deleteCookieFromDialog(cookie);
+
+ // Mark the cookie as found.
+ cookieFound = true;
+ }
+
+ // Move to the next row.
+ ++currentRow;
+ }
+ }
+}
void CookiesDialog::deleteCookieFromDialog(const QNetworkCookie &cookie) const
{
}
}
+void CookiesDialog::showDurableCookiesDialog() const
+{
+ // Instantiate a durable cookies dialog.
+ QDialog *durableCookiesDialogPointer = new DurableCookiesDialog();
+
+ // Show the dialog.
+ durableCookiesDialogPointer->show();
+
+ // Process cookie changes.
+ connect(durableCookiesDialogPointer, SIGNAL(addingCookie(QNetworkCookie, bool)), this, SLOT(addCookieFromDialog(QNetworkCookie, bool)));
+ connect(durableCookiesDialogPointer, SIGNAL(deletingCookie(QNetworkCookie)), this, SLOT(deleteCookieFromDatabase(QNetworkCookie)));
+ connect(durableCookiesDialogPointer, SIGNAL(updateParentUi()), this, SLOT(updateUi()));
+}
+
void CookiesDialog::showEditCookieDialog() const
{
// Get the current model index.
// Reset the button text.
deleteCookieButtonPointer->setText(i18nc("Delete cookie button.", "&Delete cookie"));
}
+
+ // Update the text of the durable cookies button.
+ durableCookiesButtonPointer->setText(i18nc("View the durable cookies button", "Durable cookies - %1", CookiesDatabase::cookieCount()));
}