diff options
| author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-03-31 22:02:59 +0200 | 
|---|---|---|
| committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-03-31 22:02:59 +0200 | 
| commit | 549741018ef5a18d9ad7a51092438d764149b758 (patch) | |
| tree | 0fbe74b8569004c0a4ddb24d25cedaabeab36f82 /src/forms | |
| parent | Rewrote the pre-commit hook into Ruby (diff) | |
| download | smolbote-549741018ef5a18d9ad7a51092438d764149b758.tar.xz | |
Added cookie widget
Diffstat (limited to 'src/forms')
| -rw-r--r-- | src/forms/cookiesform.cpp | 75 | ||||
| -rw-r--r-- | src/forms/cookiesform.h | 48 | ||||
| -rw-r--r-- | src/forms/cookiesform.ui | 58 | 
3 files changed, 181 insertions, 0 deletions
| 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 <http://www.gnu.org/licenses/>. + ** + ******************************************************************************/ + +#include "cookiesform.h" +#include "ui_cookiesform.h" + +#include <QTreeWidget> +#include <QDateTime> + +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 <http://www.gnu.org/licenses/>. + ** + ******************************************************************************/ + +#ifndef COOKIESFORM_H +#define COOKIESFORM_H + +#include <QWidget> +#include <QWebEngineCookieStore> +#include <QTreeWidgetItem> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CookiesForm</class> + <widget class="QWidget" name="CookiesForm"> +  <property name="geometry"> +   <rect> +    <x>0</x> +    <y>0</y> +    <width>535</width> +    <height>479</height> +   </rect> +  </property> +  <property name="windowTitle"> +   <string>Form</string> +  </property> +  <layout class="QVBoxLayout" name="verticalLayout"> +   <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> +      </property> +     </column> +     <column> +      <property name="text"> +       <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> +     </property> +    </widget> +   </item> +  </layout> + </widget> + <resources/> + <connections/> +</ui> | 
