1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Fixing crash in cookie manager introduced in previous commit.

This commit is contained in:
nowrep 2012-02-13 18:22:24 +01:00
parent 62294fee26
commit 55ff3beb30
5 changed files with 48 additions and 57 deletions

View File

@ -22,8 +22,6 @@
#include "mainapplication.h"
#include "globalfunctions.h"
//TODO: Refactor whole cookie manager tree
CookieManager::CookieManager(QWidget* parent)
: QWidget(parent)
, ui(new Ui::CookieManager)
@ -43,8 +41,10 @@ CookieManager::CookieManager(QWidget* parent)
ui->search->setInactiveText(tr("Search"));
ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
ui->cookieTree->sortItems(0, Qt::AscendingOrder);
QShortcut* removeShortcut = new QShortcut(QKeySequence("Del"), this);
connect(removeShortcut, SIGNAL(activated()), this, SLOT(removeCookie()));
}
void CookieManager::removeAll()
@ -55,8 +55,8 @@ void CookieManager::removeAll()
return;
}
m_cookies.clear();
mApp->cookieJar()->setAllCookies(m_cookies);
QList<QNetworkCookie> emptyList;
mApp->cookieJar()->setAllCookies(emptyList);
ui->cookieTree->clear();
}
@ -67,29 +67,30 @@ void CookieManager::removeCookie()
return;
}
QList<QNetworkCookie> allCookies = mApp->cookieJar()->getAllCookies();
int indexToNavigate = -1;
if (current->text(1).isEmpty()) { //Remove whole cookie group
QString domain = current->whatsThis(0);
foreach(const QNetworkCookie & cok, m_cookies) {
if (cok.domain() == domain || cok.domain() == domain.mid(1)) {
m_cookies.removeOne(cok);
foreach(const QNetworkCookie & cookie, allCookies) {
if (cookie.domain() == domain || cookie.domain() == domain.mid(1)) {
allCookies.removeOne(cookie);
}
}
indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current) - 1;
ui->cookieTree->deleteItem(current);
}
else {
indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current->parent());
int index = current->whatsThis(1).toInt();
m_cookies.removeAt(index);
const QNetworkCookie &cookie = qvariant_cast<QNetworkCookie>(current->data(0, Qt::UserRole + 10));
allCookies.removeOne(cookie);
indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current->parent());
ui->cookieTree->deleteItem(current);
}
mApp->cookieJar()->setAllCookies(m_cookies);
mApp->cookieJar()->setAllCookies(allCookies);
if (indexToNavigate > 0 && ui->cookieTree->topLevelItemCount() >= 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->expiration->setText(tr("<cookie not selected>"));
// Changing Text on QPushButton also removes shortcut?
ui->removeOne->setText(tr("Remove cookies"));
ui->removeOne->setShortcut(QKeySequence("Del"));
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->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()));
}
void CookieManager::slotRefreshTable()
{
if (m_refreshCookieJar) {
m_cookies = mApp->cookieJar()->getAllCookies();
}
const QList<QNetworkCookie>& allCookies = mApp->cookieJar()->getAllCookies();
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->cookieTree->clear();
int counter = 0;
QString cookServer;
for (int i = 0; i < m_cookies.count(); ++i) {
QNetworkCookie cok = m_cookies.at(i);
QString cookieDomain;
for (int i = 0; i < allCookies.count(); ++i) {
const QNetworkCookie& cookie = allCookies.at(i);
QTreeWidgetItem* item;
cookServer = cok.domain();
if (cookServer.startsWith(".")) {
cookServer = cookServer.mid(1);
cookieDomain = cookie.domain();
if (cookieDomain.startsWith(".")) {
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) {
item = new QTreeWidgetItem(findParent.at(0));
}
else {
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->cookieTree);
newParent->setText(0, cookServer);
newParent->setText(0, cookieDomain);
newParent->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
newParent->setWhatsThis(0, cok.domain());
newParent->setWhatsThis(0, cookie.domain());
ui->cookieTree->addTopLevelItem(newParent);
item = new QTreeWidgetItem(newParent);
}
item->setText(0, "." + cookServer);
item->setText(1, cok.name());
item->setWhatsThis(1, QString::number(i));
item->setText(0, "." + cookieDomain);
item->setText(1, cookie.name());
item->setData(0, Qt::UserRole + 10, qVariantFromValue(cookie));
ui->cookieTree->addTopLevelItem(item);
++counter;

View File

@ -22,6 +22,7 @@
#include <QTimer>
#include <QNetworkCookie>
#include <QTreeWidgetItem>
#include <QShortcut>
namespace Ui
{
@ -37,7 +38,7 @@ public:
explicit CookieManager(QWidget* parent = 0);
~CookieManager();
void refreshTable(bool refreshCookieJar = true);
void refreshTable();
private slots:
void currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent);
@ -50,7 +51,6 @@ private slots:
private:
Ui::CookieManager* ui;
QList<QNetworkCookie> m_cookies;
bool m_refreshCookieJar;
};

View File

@ -243,10 +243,10 @@ void HistoryManager::slotRefreshTable()
int counter = 0;
while (query.next()) {
QString title = query.value(0).toString();
QUrl url = query.value(1).toUrl();
const QString &title = query.value(0).toString();
const QUrl &url = query.value(1).toUrl();
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;
if (date == todayDate) {
@ -263,7 +263,7 @@ void HistoryManager::slotRefreshTable()
}
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) {
item = new QTreeWidgetItem(findParent.at(0));
}

View File

@ -178,10 +178,10 @@ void HistorySideBar::slotRefreshTable()
int counter = 0;
while (query.next()) {
QString title = query.value(0).toString();
QUrl url = query.value(1).toUrl();
const QString &title = query.value(0).toString();
const QUrl &url = query.value(1).toUrl();
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;
if (date == todayDate) {
@ -198,7 +198,7 @@ void HistorySideBar::slotRefreshTable()
}
QTreeWidgetItem* item;
QList<QTreeWidgetItem*> findParent = ui->historyTree->findItems(localDate, 0);
const QList<QTreeWidgetItem*>& findParent = ui->historyTree->findItems(localDate, 0);
if (findParent.count() == 1) {
item = new QTreeWidgetItem(findParent.at(0));
}

View File

@ -65,7 +65,7 @@ HtmlHighlighter::HtmlHighlighter(QTextDocument* parent)
tagFormat.setForeground(Qt::darkBlue);
tagFormat.setFontWeight(QFont::Bold);
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) {
rule.pattern = QRegExp(pattern);
rule.format = tagFormat;