diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-04-01 13:19:55 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-04-01 13:19:55 +0200 |
commit | 67d1767533a8bfa87cc0744db469b890177307b7 (patch) | |
tree | ac02a535ff794f8141e4691cddc227c3a2757dd7 /src | |
parent | Added cookie widget (diff) | |
download | smolbote-67d1767533a8bfa87cc0744db469b890177307b7.tar.xz |
Moved CookiesForm into the ProfileDialog
Diffstat (limited to 'src')
-rw-r--r-- | src/forms/cookiesform.cpp | 47 | ||||
-rw-r--r-- | src/forms/cookiesform.h | 15 | ||||
-rw-r--r-- | src/forms/cookiesform.ui | 102 | ||||
-rw-r--r-- | src/forms/profiledialog.cpp | 19 | ||||
-rw-r--r-- | src/forms/profiledialog.h | 12 | ||||
-rw-r--r-- | src/mainwindow.cpp | 5 | ||||
-rw-r--r-- | src/mainwindow.h | 1 | ||||
-rw-r--r-- | src/webengine/webengineprofile.cpp | 10 | ||||
-rw-r--r-- | 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 <QTreeWidget> #include <QDateTime> -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 @@ <rect> <x>0</x> <y>0</y> - <width>535</width> - <height>479</height> + <width>480</width> + <height>640</height> </rect> </property> <property name="windowTitle"> - <string>Form</string> + <string>Cookies</string> </property> - <layout class="QVBoxLayout" name="verticalLayout"> + <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QTreeWidget" name="treeWidget"> <property name="headerHidden"> <bool>false</bool> </property> - <attribute name="headerVisible"> - <bool>true</bool> - </attribute> <column> <property name="text"> <string notr="true">Name</string> @@ -32,23 +29,88 @@ <string>Expiration</string> </property> </column> - <column> - <property name="text"> - <string>Is HTTP only</string> - </property> - </column> - <column> - <property name="text"> - <string>Is Secure</string> - </property> - </column> </widget> </item> <item> - <widget class="QPlainTextEdit" name="value"> - <property name="readOnly"> - <bool>true</bool> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Details</string> </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="httponly_label"> + <property name="text"> + <string>Is HTTP Only</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="secure_label"> + <property name="text"> + <string>Is Secure</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="session_label"> + <property name="text"> + <string>Is Session Cookie</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="httponly"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="secure"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLabel" name="session"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="path_label"> + <property name="text"> + <string>Path</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLabel" name="path"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QPlainTextEdit" name="value"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> </widget> </item> </layout> 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 <QPlainTextEdit> #include <QComboBox> #include <QPushButton> +#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 <QDialog> -#include <QWebEngineProfile> 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 <QWebEngineView> #include "webengine/webengineprofile.h" -#include "forms/profiledialog.h" #include <QUrl> #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 <QWebEngineProfile> -#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 |