mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Fixing crash in cookie manager introduced in previous commit.
This commit is contained in:
parent
62294fee26
commit
55ff3beb30
@ -22,8 +22,6 @@
|
|||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "globalfunctions.h"
|
#include "globalfunctions.h"
|
||||||
|
|
||||||
//TODO: Refactor whole cookie manager tree
|
|
||||||
|
|
||||||
CookieManager::CookieManager(QWidget* parent)
|
CookieManager::CookieManager(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, ui(new Ui::CookieManager)
|
, ui(new Ui::CookieManager)
|
||||||
@ -43,8 +41,10 @@ CookieManager::CookieManager(QWidget* parent)
|
|||||||
|
|
||||||
ui->search->setInactiveText(tr("Search"));
|
ui->search->setInactiveText(tr("Search"));
|
||||||
ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
|
ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
|
||||||
|
|
||||||
ui->cookieTree->sortItems(0, Qt::AscendingOrder);
|
ui->cookieTree->sortItems(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
|
QShortcut* removeShortcut = new QShortcut(QKeySequence("Del"), this);
|
||||||
|
connect(removeShortcut, SIGNAL(activated()), this, SLOT(removeCookie()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CookieManager::removeAll()
|
void CookieManager::removeAll()
|
||||||
@ -55,8 +55,8 @@ void CookieManager::removeAll()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cookies.clear();
|
QList<QNetworkCookie> emptyList;
|
||||||
mApp->cookieJar()->setAllCookies(m_cookies);
|
mApp->cookieJar()->setAllCookies(emptyList);
|
||||||
ui->cookieTree->clear();
|
ui->cookieTree->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,29 +67,30 @@ void CookieManager::removeCookie()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QNetworkCookie> allCookies = mApp->cookieJar()->getAllCookies();
|
||||||
|
|
||||||
int indexToNavigate = -1;
|
int indexToNavigate = -1;
|
||||||
|
|
||||||
if (current->text(1).isEmpty()) { //Remove whole cookie group
|
if (current->text(1).isEmpty()) { //Remove whole cookie group
|
||||||
QString domain = current->whatsThis(0);
|
QString domain = current->whatsThis(0);
|
||||||
foreach(const QNetworkCookie & cok, m_cookies) {
|
foreach(const QNetworkCookie & cookie, allCookies) {
|
||||||
if (cok.domain() == domain || cok.domain() == domain.mid(1)) {
|
if (cookie.domain() == domain || cookie.domain() == domain.mid(1)) {
|
||||||
m_cookies.removeOne(cok);
|
allCookies.removeOne(cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current) - 1;
|
indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current) - 1;
|
||||||
|
|
||||||
ui->cookieTree->deleteItem(current);
|
ui->cookieTree->deleteItem(current);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current->parent());
|
const QNetworkCookie &cookie = qvariant_cast<QNetworkCookie>(current->data(0, Qt::UserRole + 10));
|
||||||
int index = current->whatsThis(1).toInt();
|
allCookies.removeOne(cookie);
|
||||||
m_cookies.removeAt(index);
|
|
||||||
|
|
||||||
|
indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current->parent());
|
||||||
ui->cookieTree->deleteItem(current);
|
ui->cookieTree->deleteItem(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
mApp->cookieJar()->setAllCookies(m_cookies);
|
mApp->cookieJar()->setAllCookies(allCookies);
|
||||||
|
|
||||||
if (indexToNavigate > 0 && ui->cookieTree->topLevelItemCount() >= indexToNavigate) {
|
if (indexToNavigate > 0 && ui->cookieTree->topLevelItemCount() >= indexToNavigate) {
|
||||||
QTreeWidgetItem* scrollItem = ui->cookieTree->topLevelItem(indexToNavigate);
|
QTreeWidgetItem* scrollItem = ui->cookieTree->topLevelItem(indexToNavigate);
|
||||||
@ -119,71 +120,61 @@ void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem
|
|||||||
ui->secure->setText(tr("<cookie not selected>"));
|
ui->secure->setText(tr("<cookie not selected>"));
|
||||||
ui->expiration->setText(tr("<cookie not selected>"));
|
ui->expiration->setText(tr("<cookie not selected>"));
|
||||||
|
|
||||||
// Changing Text on QPushButton also removes shortcut?
|
|
||||||
ui->removeOne->setText(tr("Remove cookies"));
|
ui->removeOne->setText(tr("Remove cookies"));
|
||||||
ui->removeOne->setShortcut(QKeySequence("Del"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changing Text on QPushButton also removes shortcut?
|
const QNetworkCookie &cookie = qvariant_cast<QNetworkCookie>(current->data(0, Qt::UserRole + 10));
|
||||||
|
|
||||||
|
ui->name->setText(cookie.name());
|
||||||
|
ui->value->setText(cookie.value());
|
||||||
|
ui->server->setText(cookie.domain());
|
||||||
|
ui->path->setText(cookie.path());
|
||||||
|
cookie.isSecure() ? ui->secure->setText(tr("Secure only")) : ui->secure->setText(tr("All connections"));
|
||||||
|
cookie.isSessionCookie() ? ui->expiration->setText(tr("Session cookie")) : ui->expiration->setText(QDateTime(cookie.expirationDate()).toString("hh:mm:ss dddd d. MMMM yyyy"));
|
||||||
|
|
||||||
ui->removeOne->setText(tr("Remove cookie"));
|
ui->removeOne->setText(tr("Remove cookie"));
|
||||||
ui->removeOne->setShortcut(QKeySequence("Del"));
|
|
||||||
|
|
||||||
int index = current->whatsThis(1).toInt();
|
|
||||||
QNetworkCookie cok = m_cookies.at(index);
|
|
||||||
|
|
||||||
ui->name->setText(cok.name());
|
|
||||||
ui->value->setText(cok.value());
|
|
||||||
ui->server->setText(cok.domain());
|
|
||||||
ui->path->setText(cok.path());
|
|
||||||
cok.isSecure() ? ui->secure->setText(tr("Secure only")) : ui->secure->setText(tr("All connections"));
|
|
||||||
cok.isSessionCookie() ? ui->expiration->setText(tr("Session cookie")) : ui->expiration->setText(QDateTime(cok.expirationDate()).toString("hh:mm:ss dddd d. MMMM yyyy"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CookieManager::refreshTable(bool refreshCookieJar)
|
void CookieManager::refreshTable()
|
||||||
{
|
{
|
||||||
m_refreshCookieJar = refreshCookieJar;
|
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(slotRefreshTable()));
|
QTimer::singleShot(0, this, SLOT(slotRefreshTable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CookieManager::slotRefreshTable()
|
void CookieManager::slotRefreshTable()
|
||||||
{
|
{
|
||||||
if (m_refreshCookieJar) {
|
const QList<QNetworkCookie>& allCookies = mApp->cookieJar()->getAllCookies();
|
||||||
m_cookies = mApp->cookieJar()->getAllCookies();
|
|
||||||
}
|
|
||||||
|
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
ui->cookieTree->clear();
|
ui->cookieTree->clear();
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
QString cookServer;
|
QString cookieDomain;
|
||||||
for (int i = 0; i < m_cookies.count(); ++i) {
|
for (int i = 0; i < allCookies.count(); ++i) {
|
||||||
QNetworkCookie cok = m_cookies.at(i);
|
const QNetworkCookie& cookie = allCookies.at(i);
|
||||||
QTreeWidgetItem* item;
|
QTreeWidgetItem* item;
|
||||||
|
|
||||||
cookServer = cok.domain();
|
cookieDomain = cookie.domain();
|
||||||
if (cookServer.startsWith(".")) {
|
if (cookieDomain.startsWith(".")) {
|
||||||
cookServer = cookServer.mid(1);
|
cookieDomain = cookieDomain.mid(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QTreeWidgetItem*> findParent = ui->cookieTree->findItems(cookServer, 0);
|
const QList<QTreeWidgetItem*>& findParent = ui->cookieTree->findItems(cookieDomain, 0);
|
||||||
if (findParent.count() == 1) {
|
if (findParent.count() == 1) {
|
||||||
item = new QTreeWidgetItem(findParent.at(0));
|
item = new QTreeWidgetItem(findParent.at(0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->cookieTree);
|
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->cookieTree);
|
||||||
newParent->setText(0, cookServer);
|
newParent->setText(0, cookieDomain);
|
||||||
newParent->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
newParent->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
newParent->setWhatsThis(0, cok.domain());
|
newParent->setWhatsThis(0, cookie.domain());
|
||||||
ui->cookieTree->addTopLevelItem(newParent);
|
ui->cookieTree->addTopLevelItem(newParent);
|
||||||
item = new QTreeWidgetItem(newParent);
|
item = new QTreeWidgetItem(newParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
item->setText(0, "." + cookServer);
|
item->setText(0, "." + cookieDomain);
|
||||||
item->setText(1, cok.name());
|
item->setText(1, cookie.name());
|
||||||
item->setWhatsThis(1, QString::number(i));
|
item->setData(0, Qt::UserRole + 10, qVariantFromValue(cookie));
|
||||||
ui->cookieTree->addTopLevelItem(item);
|
ui->cookieTree->addTopLevelItem(item);
|
||||||
|
|
||||||
++counter;
|
++counter;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QNetworkCookie>
|
#include <QNetworkCookie>
|
||||||
#include <QTreeWidgetItem>
|
#include <QTreeWidgetItem>
|
||||||
|
#include <QShortcut>
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -37,7 +38,7 @@ public:
|
|||||||
explicit CookieManager(QWidget* parent = 0);
|
explicit CookieManager(QWidget* parent = 0);
|
||||||
~CookieManager();
|
~CookieManager();
|
||||||
|
|
||||||
void refreshTable(bool refreshCookieJar = true);
|
void refreshTable();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent);
|
void currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent);
|
||||||
@ -50,7 +51,6 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
Ui::CookieManager* ui;
|
Ui::CookieManager* ui;
|
||||||
|
|
||||||
QList<QNetworkCookie> m_cookies;
|
|
||||||
bool m_refreshCookieJar;
|
bool m_refreshCookieJar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -243,10 +243,10 @@ void HistoryManager::slotRefreshTable()
|
|||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while (query.next()) {
|
while (query.next()) {
|
||||||
QString title = query.value(0).toString();
|
const QString &title = query.value(0).toString();
|
||||||
QUrl url = query.value(1).toUrl();
|
const QUrl &url = query.value(1).toUrl();
|
||||||
int id = query.value(2).toInt();
|
int id = query.value(2).toInt();
|
||||||
QDate date = QDateTime::fromMSecsSinceEpoch(query.value(3).toLongLong()).date();
|
const QDate &date = QDateTime::fromMSecsSinceEpoch(query.value(3).toLongLong()).date();
|
||||||
QString localDate;
|
QString localDate;
|
||||||
|
|
||||||
if (date == todayDate) {
|
if (date == todayDate) {
|
||||||
@ -263,7 +263,7 @@ void HistoryManager::slotRefreshTable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem* item = new QTreeWidgetItem();
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
||||||
QList<QTreeWidgetItem*> findParent = ui->historyTree->findItems(localDate, 0);
|
const QList<QTreeWidgetItem*>& findParent = ui->historyTree->findItems(localDate, 0);
|
||||||
if (findParent.count() == 1) {
|
if (findParent.count() == 1) {
|
||||||
item = new QTreeWidgetItem(findParent.at(0));
|
item = new QTreeWidgetItem(findParent.at(0));
|
||||||
}
|
}
|
||||||
|
@ -178,10 +178,10 @@ void HistorySideBar::slotRefreshTable()
|
|||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while (query.next()) {
|
while (query.next()) {
|
||||||
QString title = query.value(0).toString();
|
const QString &title = query.value(0).toString();
|
||||||
QUrl url = query.value(1).toUrl();
|
const QUrl &url = query.value(1).toUrl();
|
||||||
int id = query.value(2).toInt();
|
int id = query.value(2).toInt();
|
||||||
QDate date = QDateTime::fromMSecsSinceEpoch(query.value(3).toLongLong()).date();
|
const QDate &date = QDateTime::fromMSecsSinceEpoch(query.value(3).toLongLong()).date();
|
||||||
QString localDate;
|
QString localDate;
|
||||||
|
|
||||||
if (date == todayDate) {
|
if (date == todayDate) {
|
||||||
@ -198,7 +198,7 @@ void HistorySideBar::slotRefreshTable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem* item;
|
QTreeWidgetItem* item;
|
||||||
QList<QTreeWidgetItem*> findParent = ui->historyTree->findItems(localDate, 0);
|
const QList<QTreeWidgetItem*>& findParent = ui->historyTree->findItems(localDate, 0);
|
||||||
if (findParent.count() == 1) {
|
if (findParent.count() == 1) {
|
||||||
item = new QTreeWidgetItem(findParent.at(0));
|
item = new QTreeWidgetItem(findParent.at(0));
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ HtmlHighlighter::HtmlHighlighter(QTextDocument* parent)
|
|||||||
tagFormat.setForeground(Qt::darkBlue);
|
tagFormat.setForeground(Qt::darkBlue);
|
||||||
tagFormat.setFontWeight(QFont::Bold);
|
tagFormat.setFontWeight(QFont::Bold);
|
||||||
QStringList keywordPatterns;
|
QStringList keywordPatterns;
|
||||||
keywordPatterns << "</?(\[A-Za-z:0-9]{1,20})/?(>| )?" << ">" << "(<!DOCTYPE html>|<!DOCTYPE html PUBLIC)";
|
keywordPatterns << "</?([A-Za-z:0-9]{1,20})/?(>| )?" << ">" << "(<!DOCTYPE html>|<!DOCTYPE html PUBLIC)";
|
||||||
foreach(const QString & pattern, keywordPatterns) {
|
foreach(const QString & pattern, keywordPatterns) {
|
||||||
rule.pattern = QRegExp(pattern);
|
rule.pattern = QRegExp(pattern);
|
||||||
rule.format = tagFormat;
|
rule.format = tagFormat;
|
||||||
|
Loading…
Reference in New Issue
Block a user