/** 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()); }