From 67d1767533a8bfa87cc0744db469b890177307b7 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 1 Apr 2017 13:19:55 +0200 Subject: Moved CookiesForm into the ProfileDialog --- src/forms/cookiesform.cpp | 47 ++++++++++------- src/forms/cookiesform.h | 15 ++++-- src/forms/cookiesform.ui | 102 +++++++++++++++++++++++++++++-------- src/forms/profiledialog.cpp | 19 ++++++- src/forms/profiledialog.h | 12 +++-- src/mainwindow.cpp | 5 +- src/mainwindow.h | 1 - src/webengine/webengineprofile.cpp | 10 ++-- src/webengine/webengineprofile.h | 6 +-- 9 files changed, 160 insertions(+), 57 deletions(-) diff --git a/src/forms/cookiesform.cpp b/src/forms/cookiesform.cpp index 44a9e44..7dfeb26 100644 --- a/src/forms/cookiesform.cpp +++ b/src/forms/cookiesform.cpp @@ -24,52 +24,65 @@ #include #include -CookiesWidget::CookiesWidget(QWebEngineCookieStore *store, QWidget *parent) : +CookiesForm::CookiesForm(QWebEngineCookieStore *store, QWidget *parent) : QWidget(parent), ui(new Ui::CookiesForm) { setAttribute(Qt::WA_DeleteOnClose, false); ui->setupUi(this); + ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); connect(store, SIGNAL(cookieAdded(QNetworkCookie)), this, SLOT(addCookie(QNetworkCookie))); connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(showDetails(QTreeWidgetItem*,QTreeWidgetItem*))); - connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(showDetails(QTreeWidgetItem*,int))); } -CookiesWidget::~CookiesWidget() +CookiesForm::~CookiesForm() { delete ui; } -void CookiesWidget::addCookie(const QNetworkCookie &cookie) +void CookiesForm::addCookie(const QNetworkCookie &cookie) { + // find topLevelItem to which to add the cookie + QTreeWidgetItem *domainItem = nullptr; + + // loop through all top level items and check if one matches the domain for(int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) { QTreeWidgetItem *parentItem = ui->treeWidget->topLevelItem(i); if(parentItem->text(0) == cookie.domain()) { - QTreeWidgetItem *item = new QTreeWidgetItem(parentItem); - item->setText(0, cookie.name()); - item->setText(1, cookie.expirationDate().toString(Qt::RFC2822Date)); - item->setText(2, cookie.isHttpOnly() ? tr("yes") : tr("no")); - item->setText(3, cookie.isSecure() ? tr("yes") : tr("no")); - - item->setData(0, Qt::UserRole, cookie.value()); - return; + domainItem = parentItem; + break; } } // no topLevelItem matches - QTreeWidgetItem *parentItem = new QTreeWidgetItem(ui->treeWidget); - parentItem->setText(0, cookie.domain()); - addCookie(cookie); + if(!domainItem) { + domainItem = new QTreeWidgetItem(ui->treeWidget); + domainItem->setText(0, cookie.domain()); + } + + QTreeWidgetItem *item = new QTreeWidgetItem(domainItem); + item->setText(0, cookie.name()); + item->setText(1, cookie.expirationDate().toString(Qt::RFC2822Date)); + + item->setData(0, ValueRole, cookie.value()); + item->setData(0, IsHttpOnlyRole, cookie.isHttpOnly() ? tr("yes") : tr("no")); + item->setData(0, IsSecureRole, cookie.isSecure() ? tr("yes") : tr("no")); + item->setData(0, IsSessionCookieRole, cookie.isSessionCookie() ? tr("yes") : tr("no")); + item->setData(0, PathRole, cookie.path()); } -void CookiesWidget::showDetails(QTreeWidgetItem *current, QTreeWidgetItem *previous) +void CookiesForm::showDetails(QTreeWidgetItem *current, QTreeWidgetItem *previous) { Q_UNUSED(previous) if(!current) { return; } - ui->value->setPlainText(current->data(0, Qt::UserRole).toString()); + ui->value->setPlainText(current->data(0, ValueRole).toString()); + ui->httponly->setText(current->data(0, IsHttpOnlyRole).toString()); + ui->secure->setText(current->data(0, IsSecureRole).toString()); + ui->session->setText(current->data(0, IsSessionCookieRole).toString()); + ui->path->setText(current->data(0, PathRole).toString()); } diff --git a/src/forms/cookiesform.h b/src/forms/cookiesform.h index c395941..0b3386a 100644 --- a/src/forms/cookiesform.h +++ b/src/forms/cookiesform.h @@ -29,13 +29,22 @@ namespace Ui { class CookiesForm; } -class CookiesWidget : public QWidget +class CookiesForm : public QWidget { Q_OBJECT public: - explicit CookiesWidget(QWebEngineCookieStore *store, QWidget *parent = 0); - ~CookiesWidget(); + enum DetailsRoles { + ValueRole = Qt::UserRole, + + IsHttpOnlyRole = Qt::UserRole + 1, + IsSecureRole = Qt::UserRole + 2, + IsSessionCookieRole = Qt::UserRole + 3, + PathRole = Qt::UserRole + 4 + }; + + explicit CookiesForm(QWebEngineCookieStore *store, QWidget *parent = 0); + ~CookiesForm(); private slots: void addCookie(const QNetworkCookie &cookie); diff --git a/src/forms/cookiesform.ui b/src/forms/cookiesform.ui index 2662a9d..f5546bd 100644 --- a/src/forms/cookiesform.ui +++ b/src/forms/cookiesform.ui @@ -6,22 +6,19 @@ 0 0 - 535 - 479 + 480 + 640 - Form + Cookies - + false - - true - Name @@ -32,23 +29,88 @@ Expiration - - - Is HTTP only - - - - - Is Secure - - - - - true + + + Details + + + + + + + Is HTTP Only + + + + + + + Is Secure + + + + + + + Is Session Cookie + + + + + + + + + + + + + + + + + + + + + + + + + + + + Path + + + + + + + + + + + + + + + + + 0 + 0 + + + + true + + + + diff --git a/src/forms/profiledialog.cpp b/src/forms/profiledialog.cpp index 057dc7d..047f51b 100644 --- a/src/forms/profiledialog.cpp +++ b/src/forms/profiledialog.cpp @@ -25,8 +25,10 @@ #include #include #include +#include "webengine/webengineprofile.h" +#include "forms/cookiesform.h" -ProfileDialog::ProfileDialog(QWebEngineProfile *profile, QWidget *parent) : +ProfileDialog::ProfileDialog(WebEngineProfile *profile, QWidget *parent) : QDialog(parent), ui(new Ui::ProfileDialog) { @@ -39,6 +41,9 @@ ProfileDialog::ProfileDialog(QWebEngineProfile *profile, QWidget *parent) : setWindowTitle(tr("Off-the-record")); } + m_cookiesForm = new CookiesForm(_profile->cookieStore(), this); + ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle()); + // http ui->userAgent->setPlainText(_profile->httpUserAgent()); ui->acceptLanguage->setPlainText(_profile->httpAcceptLanguage()); @@ -68,6 +73,18 @@ ProfileDialog::~ProfileDialog() delete ui; } +void ProfileDialog::showProfile() +{ + ui->tabWidget->setCurrentIndex(0); + show(); +} + +void ProfileDialog::showCookies() +{ + ui->tabWidget->setCurrentIndex(4); + show(); +} + void ProfileDialog::updateProfile() { qDebug("Updating profile..."); diff --git a/src/forms/profiledialog.h b/src/forms/profiledialog.h index ab367d8..79f85b1 100644 --- a/src/forms/profiledialog.h +++ b/src/forms/profiledialog.h @@ -22,26 +22,32 @@ #define PROFILEDIALOG_H #include -#include namespace Ui { class ProfileDialog; } +class WebEngineProfile; +class CookiesForm; class ProfileDialog : public QDialog { Q_OBJECT public: - explicit ProfileDialog(QWebEngineProfile *profile, QWidget *parent = 0); + explicit ProfileDialog(WebEngineProfile *profile, QWidget *parent = 0); ~ProfileDialog(); +public slots: + void showProfile(); + void showCookies(); + private slots: void updateProfile(); private: - QWebEngineProfile *_profile; + WebEngineProfile *_profile; Ui::ProfileDialog *ui; + CookiesForm *m_cookiesForm; }; #endif // PROFILEDIALOG_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bebab63..465d02a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -258,11 +258,10 @@ void MainWindow::handleTitleUpdated(const QString &title) void MainWindow::execProfileEditor() { - ProfileDialog *dialog = new ProfileDialog(m_profile, this); - dialog->exec(); + m_profile->dialog()->showProfile(); } void MainWindow::cookiesAction() { - m_profile->cookieUI()->show(); + m_profile->dialog()->showCookies(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 2e81509..9d858f5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -26,7 +26,6 @@ #include "widgets/urllineedit.h" #include #include "webengine/webengineprofile.h" -#include "forms/profiledialog.h" #include #include "widgets/webviewtabbar.h" #include "webengine/urlinterceptor.h" diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index a72f3cf..1ff27dc 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -28,7 +28,7 @@ WebEngineProfile::WebEngineProfile(QObject *parent) : { // Off-the-record constructor - m_cookiesForm = new CookiesWidget(cookieStore()); + m_profileDialog = new ProfileDialog(this); } WebEngineProfile::WebEngineProfile(const QString &storageName, QObject *parent) : @@ -37,7 +37,7 @@ WebEngineProfile::WebEngineProfile(const QString &storageName, QObject *parent) setPersistentStoragePath(sSettings->value("browser.profile.path").toString() + storageName); setCachePath(sSettings->value("browser.profile.path").toString() + storageName); - m_cookiesForm = new CookiesWidget(cookieStore()); + m_profileDialog = new ProfileDialog(this); QString profilePath = persistentStoragePath() + "/profile.ini"; qDebug("Reading profile from [%s]", qUtf8Printable(profilePath)); @@ -110,13 +110,11 @@ WebEngineProfile::~WebEngineProfile() if(!isOffTheRecord()) { saveProfile(); } - - m_cookiesForm->deleteLater(); } -CookiesWidget *WebEngineProfile::cookieUI() +ProfileDialog *WebEngineProfile::dialog() { - return m_cookiesForm; + return m_profileDialog; } void WebEngineProfile::saveProfile() diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h index c93ae52..421ff0e 100644 --- a/src/webengine/webengineprofile.h +++ b/src/webengine/webengineprofile.h @@ -22,7 +22,7 @@ #define WEBENGINEPROFILE_H #include -#include "forms/cookiesform.h" +#include "forms/profiledialog.h" class WebEngineProfile : public QWebEngineProfile { @@ -33,7 +33,7 @@ public: ~WebEngineProfile(); - CookiesWidget *cookieUI(); + ProfileDialog *dialog(); signals: @@ -41,7 +41,7 @@ public slots: void saveProfile(); private: - CookiesWidget *m_cookiesForm; + ProfileDialog *m_profileDialog; }; #endif // WEBENGINEPROFILE_H -- cgit v1.2.1