1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*******************************************************************************
**
** 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>
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*)));
}
CookiesForm::~CookiesForm()
{
delete ui;
}
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()) {
domainItem = parentItem;
break;
}
}
// no topLevelItem matches
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 CookiesForm::showDetails(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous)
if(!current) {
return;
}
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());
}
|