From 549741018ef5a18d9ad7a51092438d764149b758 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 31 Mar 2017 22:02:59 +0200 Subject: Added cookie widget --- smolbote.qbs | 21 ++++++++--- src/forms/cookiesform.cpp | 75 ++++++++++++++++++++++++++++++++++++++ src/forms/cookiesform.h | 48 ++++++++++++++++++++++++ src/forms/cookiesform.ui | 58 +++++++++++++++++++++++++++++ src/mainwindow.cpp | 7 +++- src/mainwindow.h | 1 + src/webengine/webengineprofile.cpp | 11 ++++++ src/webengine/webengineprofile.h | 6 +++ 8 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 src/forms/cookiesform.cpp create mode 100644 src/forms/cookiesform.h create mode 100644 src/forms/cookiesform.ui diff --git a/smolbote.qbs b/smolbote.qbs index e58bb1c..e03f692 100644 --- a/smolbote.qbs +++ b/smolbote.qbs @@ -65,7 +65,7 @@ Project { } Group { - name: "window" + name: "Main Window" files: [ "src/mainwindow.cpp", "src/mainwindow.h", @@ -123,15 +123,24 @@ Project { } } + Group { + name: "Profile" + files: [ + "src/forms/cookiesform.cpp", + "src/forms/cookiesform.h", + "src/forms/cookiesform.ui", + "src/forms/profiledialog.cpp", + "src/forms/profiledialog.h", + "src/forms/profiledialog.ui", + "src/webengine/webengineprofile.cpp", + "src/webengine/webengineprofile.h", + ] + } + files: [ "data/resources.qrc", - "src/forms/profiledialog.cpp", - "src/forms/profiledialog.h", - "src/forms/profiledialog.ui", "src/settings.cpp", "src/settings.h", - "src/webengine/webengineprofile.cpp", - "src/webengine/webengineprofile.h", "src/webengine/webview.cpp", "src/webengine/webview.h", "src/widgets/dockingwidget.cpp", diff --git a/src/forms/cookiesform.cpp b/src/forms/cookiesform.cpp new file mode 100644 index 0000000..44a9e44 --- /dev/null +++ b/src/forms/cookiesform.cpp @@ -0,0 +1,75 @@ +/** LICENSE ******************************************************************** + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program 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. + ** + ** This program 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 this program. If not, see . + ** + ******************************************************************************/ + +#include "cookiesform.h" +#include "ui_cookiesform.h" + +#include +#include + +CookiesWidget::CookiesWidget(QWebEngineCookieStore *store, QWidget *parent) : + QWidget(parent), + ui(new Ui::CookiesForm) +{ + setAttribute(Qt::WA_DeleteOnClose, false); + ui->setupUi(this); + + 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() +{ + delete ui; +} + +void CookiesWidget::addCookie(const QNetworkCookie &cookie) +{ + 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; + } + } + + // no topLevelItem matches + QTreeWidgetItem *parentItem = new QTreeWidgetItem(ui->treeWidget); + parentItem->setText(0, cookie.domain()); + addCookie(cookie); + +} + +void CookiesWidget::showDetails(QTreeWidgetItem *current, QTreeWidgetItem *previous) +{ + Q_UNUSED(previous) + if(!current) { + return; + } + + ui->value->setPlainText(current->data(0, Qt::UserRole).toString()); +} diff --git a/src/forms/cookiesform.h b/src/forms/cookiesform.h new file mode 100644 index 0000000..c395941 --- /dev/null +++ b/src/forms/cookiesform.h @@ -0,0 +1,48 @@ +/** LICENSE ******************************************************************** + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program 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. + ** + ** This program 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 this program. If not, see . + ** + ******************************************************************************/ + +#ifndef COOKIESFORM_H +#define COOKIESFORM_H + +#include +#include +#include + +namespace Ui { +class CookiesForm; +} + +class CookiesWidget : public QWidget +{ + Q_OBJECT + +public: + explicit CookiesWidget(QWebEngineCookieStore *store, QWidget *parent = 0); + ~CookiesWidget(); + +private slots: + void addCookie(const QNetworkCookie &cookie); + void showDetails(QTreeWidgetItem *current, QTreeWidgetItem *previous); + +private: + Ui::CookiesForm *ui; +}; + +#endif // COOKIESFORM_H diff --git a/src/forms/cookiesform.ui b/src/forms/cookiesform.ui new file mode 100644 index 0000000..2662a9d --- /dev/null +++ b/src/forms/cookiesform.ui @@ -0,0 +1,58 @@ + + + CookiesForm + + + + 0 + 0 + 535 + 479 + + + + Form + + + + + + false + + + true + + + + Name + + + + + Expiration + + + + + Is HTTP only + + + + + Is Secure + + + + + + + + true + + + + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5620bb3..bebab63 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -76,7 +76,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : profileMenu->addAction(tr("View profile"), this, SLOT(execProfileEditor())); profileMenu->addAction(tr("Load profile"), this, SLOT(loadProfileGUI())); //profileMenu->addAction(tr("Settings")); - //profileMenu->addAction(tr("Cookies")); + profileMenu->addAction(tr("Cookies"), this, SLOT(cookiesAction())); // Add the toolbars // tabToolBar: main menu and tab list @@ -261,3 +261,8 @@ void MainWindow::execProfileEditor() ProfileDialog *dialog = new ProfileDialog(m_profile, this); dialog->exec(); } + +void MainWindow::cookiesAction() +{ + m_profile->cookieUI()->show(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index c032d5a..2e81509 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -62,6 +62,7 @@ private slots: void loadProfileGUI(); void execProfileEditor(); + void cookiesAction(); void handleNewWindow(const QUrl &url = QUrl("")); void handleTabChanged(WebView *view); diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index cd6291f..a72f3cf 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -27,6 +27,8 @@ WebEngineProfile::WebEngineProfile(QObject *parent) : QWebEngineProfile(parent) { // Off-the-record constructor + + m_cookiesForm = new CookiesWidget(cookieStore()); } WebEngineProfile::WebEngineProfile(const QString &storageName, QObject *parent) : @@ -35,6 +37,8 @@ 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()); + QString profilePath = persistentStoragePath() + "/profile.ini"; qDebug("Reading profile from [%s]", qUtf8Printable(profilePath)); QSettings config(profilePath, QSettings::IniFormat); @@ -106,6 +110,13 @@ WebEngineProfile::~WebEngineProfile() if(!isOffTheRecord()) { saveProfile(); } + + m_cookiesForm->deleteLater(); +} + +CookiesWidget *WebEngineProfile::cookieUI() +{ + return m_cookiesForm; } void WebEngineProfile::saveProfile() diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h index 1845c99..c93ae52 100644 --- a/src/webengine/webengineprofile.h +++ b/src/webengine/webengineprofile.h @@ -22,6 +22,7 @@ #define WEBENGINEPROFILE_H #include +#include "forms/cookiesform.h" class WebEngineProfile : public QWebEngineProfile { @@ -32,10 +33,15 @@ public: ~WebEngineProfile(); + CookiesWidget *cookieUI(); + signals: public slots: void saveProfile(); + +private: + CookiesWidget *m_cookiesForm; }; #endif // WEBENGINEPROFILE_H -- cgit v1.2.1