From e990840b71a0d122627125a6223f576816d8ecda Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 18 May 2009 10:24:57 +0200 Subject: 1st commit on cookie branch. Refactoring Ui classes --- src/CMakeLists.txt | 1 + src/cookiedialogs.cpp | 187 +++++++++++++++++++++++++++++++++++++++++++++++ src/cookiedialogs.h | 78 ++++++++++++++++++++ src/cookiejar.cpp | 150 +------------------------------------ src/cookiejar.h | 55 +++----------- src/cookies.ui | 92 +++++++++++------------ src/cookiesexceptions.ui | 171 +++++++++++++++++++++---------------------- src/settings.cpp | 2 +- 8 files changed, 404 insertions(+), 332 deletions(-) create mode 100644 src/cookiedialogs.cpp create mode 100644 src/cookiedialogs.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b9af51f..16494f41 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ SET( rekonq_SRCS lineedit.cpp stackedurlbar.cpp webpage.cpp + cookiedialogs.cpp ) KDE4_ADD_UI_FILES( rekonq_SRCS diff --git a/src/cookiedialogs.cpp b/src/cookiedialogs.cpp new file mode 100644 index 00000000..9b768f6a --- /dev/null +++ b/src/cookiedialogs.cpp @@ -0,0 +1,187 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* 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 2, 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. +* +* ============================================================ */ + + +// Local Includes +#include "cookiedialogs.h" +#include "cookiejar.h" + +#include "ui_cookies.h" + +#include + +CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) + : KDialog(parent) +{ + Ui::CookiesWidget cookieWidget; + QWidget widget; + cookieWidget.setupUi(&widget); + setMainWidget(&widget); + + setWindowFlags(Qt::Sheet); + + CookieModel *model = new CookieModel(cookieJar, this); + m_proxyModel = new QSortFilterProxyModel(this); + + // connecting signals and slots + connect(cookieWidget.search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); + connect(cookieWidget.removeButton, SIGNAL(clicked()), cookieWidget.cookiesTable, SLOT(removeOne())); + connect(cookieWidget.removeAllButton, SIGNAL(clicked()), cookieWidget.cookiesTable, SLOT(removeAll())); + + m_proxyModel->setSourceModel(model); + + cookieWidget.cookiesTable->verticalHeader()->hide(); + cookieWidget.cookiesTable->setSelectionBehavior(QAbstractItemView::SelectRows); + cookieWidget.cookiesTable->setModel(m_proxyModel); + cookieWidget.cookiesTable->setAlternatingRowColors(true); + cookieWidget.cookiesTable->setTextElideMode(Qt::ElideMiddle); + cookieWidget.cookiesTable->setShowGrid(false); + cookieWidget.cookiesTable->setSortingEnabled(true); + + QFont f = font(); + f.setPointSize(10); + QFontMetrics fm(f); + int height = fm.height() + fm.height() / 3; + cookieWidget.cookiesTable->verticalHeader()->setDefaultSectionSize(height); + cookieWidget.cookiesTable->verticalHeader()->setMinimumSectionSize(-1); + + for (int i = 0; i < model->columnCount(); ++i) + { + int header = cookieWidget.cookiesTable->horizontalHeader()->sectionSizeHint(i); + switch (i) + { + case 0: + header = fm.width(QLatin1String("averagehost.domain.com")); + break; + case 1: + header = fm.width(QLatin1String("_session_id")); + break; + case 4: + header = fm.width(QDateTime::currentDateTime().toString(Qt::LocalDate)); + break; + } + int buffer = fm.width(QLatin1String("xx")); + header += buffer; + cookieWidget.cookiesTable->horizontalHeader()->resizeSection(i, header); + } + cookieWidget.cookiesTable->horizontalHeader()->setStretchLastSection(true); +} + + +// ---------------------------------------------------------------------------------------------------------------- + + +CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) + : KDialog(parent) + , m_cookieJar(cookieJar) + , exceptionsWidget(new Ui::CookiesExceptionsWidget) +{ + QWidget widget; + exceptionsWidget->setupUi(&widget); + setMainWidget(&widget); + + setWindowFlags(Qt::Sheet); + + connect(exceptionsWidget->removeButton, SIGNAL(clicked()), exceptionsWidget->exceptionTable, SLOT(removeOne())); + connect(exceptionsWidget->removeAllButton, SIGNAL(clicked()), exceptionsWidget->exceptionTable, SLOT(removeAll())); + + exceptionsWidget->exceptionTable->verticalHeader()->hide(); + exceptionsWidget->exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); + exceptionsWidget->exceptionTable->setAlternatingRowColors(true); + exceptionsWidget->exceptionTable->setTextElideMode(Qt::ElideMiddle); + exceptionsWidget->exceptionTable->setShowGrid(false); + exceptionsWidget->exceptionTable->setSortingEnabled(true); + m_exceptionsModel = new CookieExceptionsModel(cookieJar, this); + m_proxyModel = new QSortFilterProxyModel(this); + m_proxyModel->setSourceModel(m_exceptionsModel); + + connect(exceptionsWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); + + exceptionsWidget->exceptionTable->setModel(m_proxyModel); + + CookieModel *cookieModel = new CookieModel(cookieJar, this); + exceptionsWidget->domainLineEdit->setCompleter(new QCompleter(cookieModel, exceptionsWidget->domainLineEdit)); + + connect(exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); + connect(exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); + connect(exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); + connect(exceptionsWidget->allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); + + QFont f = font(); + f.setPointSize(10); + QFontMetrics fm(f); + int height = fm.height() + fm.height() / 3; + exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); + exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); + for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) + { + int header = exceptionsWidget->exceptionTable->horizontalHeader()->sectionSizeHint(i); + switch (i) + { + case 0: + header = fm.width(QLatin1String("averagebiglonghost.domain.com")); + break; + case 1: + header = fm.width(QLatin1String("Allow For Session")); + break; + } + int buffer = fm.width(QLatin1String("xx")); + header += buffer; + exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); + } +} + + +void CookiesExceptionsDialog::textChanged(const QString &text) +{ + bool enabled = !text.isEmpty(); + exceptionsWidget->blockButton->setEnabled(enabled); + exceptionsWidget->allowButton->setEnabled(enabled); + exceptionsWidget->allowForSessionButton->setEnabled(enabled); +} + + +void CookiesExceptionsDialog::block() +{ + if (exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_blockedCookies.append(exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setBlockedCookies(m_exceptionsModel->m_blockedCookies); + m_exceptionsModel->reset(); +} + + +void CookiesExceptionsDialog::allow() +{ + if (exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_allowedCookies.append(exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setAllowedCookies(m_exceptionsModel->m_allowedCookies); + m_exceptionsModel->reset(); +} + + +void CookiesExceptionsDialog::allowForSession() +{ + if (exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_sessionCookies.append(exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies); + m_exceptionsModel->reset(); +} diff --git a/src/cookiedialogs.h b/src/cookiedialogs.h new file mode 100644 index 00000000..0f7b8036 --- /dev/null +++ b/src/cookiedialogs.h @@ -0,0 +1,78 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* 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 2, 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. +* +* ============================================================ */ + + + +#ifndef COOKIEDIALOGS_H +#define COOKIEDIALOGS_H + + +#include + +// Qt Includes +#include +#include +#include +#include +#include + +class CookieJar; +class CookieExceptionsModel; + +class CookiesDialog : public KDialog +{ + Q_OBJECT + +public: + explicit CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0); + +private: + QSortFilterProxyModel *m_proxyModel; +}; + + +// ----------------------------------------------------------------------------------------------------------------- + + +#include "ui_cookiesexceptions.h" + + +class CookiesExceptionsDialog : public KDialog +{ + Q_OBJECT + +public: + explicit CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent = 0); + +private slots: + void block(); + void allow(); + void allowForSession(); + void textChanged(const QString &text); + +private: + CookieExceptionsModel *m_exceptionsModel; + QSortFilterProxyModel *m_proxyModel; + CookieJar *m_cookieJar; + + Ui::CookiesExceptionsWidget *exceptionsWidget; +}; + + +#endif diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp index fd823553..99399471 100644 --- a/src/cookiejar.cpp +++ b/src/cookiejar.cpp @@ -79,7 +79,7 @@ QDataStream &operator>>(QDataStream &stream, QList &list) QList newCookies = QNetworkCookie::parseCookies(value); if (newCookies.count() == 0 && value.length() != 0) { - kWarning() << "CookieJar: Unable to parse saved cookie:" << value; + kDebug() << "CookieJar: Unable to parse saved cookie:" << value; } for (int j = 0; j < newCookies.count(); ++j) list.append(newCookies.at(j)); @@ -559,57 +559,6 @@ void CookieModel::cookiesChanged() // ------------------------------------------------------------------------------------------------ -CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) - : QDialog(parent) -{ - setupUi(this); - setWindowFlags(Qt::Sheet); - CookieModel *model = new CookieModel(cookieJar, this); - m_proxyModel = new QSortFilterProxyModel(this); - connect(search, SIGNAL(textChanged(QString)), - m_proxyModel, SLOT(setFilterFixedString(QString))); - connect(removeButton, SIGNAL(clicked()), cookiesTable, SLOT(removeOne())); - connect(removeAllButton, SIGNAL(clicked()), cookiesTable, SLOT(removeAll())); - m_proxyModel->setSourceModel(model); - cookiesTable->verticalHeader()->hide(); - cookiesTable->setSelectionBehavior(QAbstractItemView::SelectRows); - cookiesTable->setModel(m_proxyModel); - cookiesTable->setAlternatingRowColors(true); - cookiesTable->setTextElideMode(Qt::ElideMiddle); - cookiesTable->setShowGrid(false); - cookiesTable->setSortingEnabled(true); - QFont f = font(); - f.setPointSize(10); - QFontMetrics fm(f); - int height = fm.height() + fm.height() / 3; - cookiesTable->verticalHeader()->setDefaultSectionSize(height); - cookiesTable->verticalHeader()->setMinimumSectionSize(-1); - for (int i = 0; i < model->columnCount(); ++i) - { - int header = cookiesTable->horizontalHeader()->sectionSizeHint(i); - switch (i) - { - case 0: - header = fm.width(QLatin1String("averagehost.domain.com")); - break; - case 1: - header = fm.width(QLatin1String("_session_id")); - break; - case 4: - header = fm.width(QDateTime::currentDateTime().toString(Qt::LocalDate)); - break; - } - int buffer = fm.width(QLatin1String("xx")); - header += buffer; - cookiesTable->horizontalHeader()->resizeSection(i, header); - } - cookiesTable->horizontalHeader()->setStretchLastSection(true); -} - - -// --------------------------------------------------------------------------------------------------- - - CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent) : QAbstractTableModel(parent) , m_cookieJar(cookiejar) @@ -747,100 +696,3 @@ bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &pa endRemoveRows(); return true; } - - -// ---------------------------------------------------------------------------------------------------------------- - - -CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) - : QDialog(parent) - , m_cookieJar(cookieJar) -{ - setupUi(this); - setWindowFlags(Qt::Sheet); - connect(removeButton, SIGNAL(clicked()), exceptionTable, SLOT(removeOne())); - connect(removeAllButton, SIGNAL(clicked()), exceptionTable, SLOT(removeAll())); - exceptionTable->verticalHeader()->hide(); - exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); - exceptionTable->setAlternatingRowColors(true); - exceptionTable->setTextElideMode(Qt::ElideMiddle); - exceptionTable->setShowGrid(false); - exceptionTable->setSortingEnabled(true); - m_exceptionsModel = new CookieExceptionsModel(cookieJar, this); - m_proxyModel = new QSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_exceptionsModel); - connect(search, SIGNAL(textChanged(QString)), - m_proxyModel, SLOT(setFilterFixedString(QString))); - exceptionTable->setModel(m_proxyModel); - - CookieModel *cookieModel = new CookieModel(cookieJar, this); - domainLineEdit->setCompleter(new QCompleter(cookieModel, domainLineEdit)); - - connect(domainLineEdit, SIGNAL(textChanged(const QString &)), - this, SLOT(textChanged(const QString &))); - connect(blockButton, SIGNAL(clicked()), this, SLOT(block())); - connect(allowButton, SIGNAL(clicked()), this, SLOT(allow())); - connect(allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); - - QFont f = font(); - f.setPointSize(10); - QFontMetrics fm(f); - int height = fm.height() + fm.height() / 3; - exceptionTable->verticalHeader()->setDefaultSectionSize(height); - exceptionTable->verticalHeader()->setMinimumSectionSize(-1); - for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) - { - int header = exceptionTable->horizontalHeader()->sectionSizeHint(i); - switch (i) - { - case 0: - header = fm.width(QLatin1String("averagebiglonghost.domain.com")); - break; - case 1: - header = fm.width(QLatin1String("Allow For Session")); - break; - } - int buffer = fm.width(QLatin1String("xx")); - header += buffer; - exceptionTable->horizontalHeader()->resizeSection(i, header); - } -} - - -void CookiesExceptionsDialog::textChanged(const QString &text) -{ - bool enabled = !text.isEmpty(); - blockButton->setEnabled(enabled); - allowButton->setEnabled(enabled); - allowForSessionButton->setEnabled(enabled); -} - - -void CookiesExceptionsDialog::block() -{ - if (domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_blockedCookies.append(domainLineEdit->text()); - m_cookieJar->setBlockedCookies(m_exceptionsModel->m_blockedCookies); - m_exceptionsModel->reset(); -} - - -void CookiesExceptionsDialog::allow() -{ - if (domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_allowedCookies.append(domainLineEdit->text()); - m_cookieJar->setAllowedCookies(m_exceptionsModel->m_allowedCookies); - m_exceptionsModel->reset(); -} - - -void CookiesExceptionsDialog::allowForSession() -{ - if (domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_sessionCookies.append(domainLineEdit->text()); - m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies); - m_exceptionsModel->reset(); -} diff --git a/src/cookiejar.h b/src/cookiejar.h index 03802df1..81d3ce64 100644 --- a/src/cookiejar.h +++ b/src/cookiejar.h @@ -24,11 +24,16 @@ #define COOKIEJAR_H +// Local Includes +#include "cookiedialogs.h" + // Qt Includes -#include -#include -#include -#include +#include +#include +#include +#include + + // Forward Declarations class QSortFilterProxyModel; @@ -136,23 +141,6 @@ private: // ---------------------------------------------------------------------------------------------------------------------- -#include "ui_cookies.h" - -class CookiesDialog : public QDialog, public Ui_CookiesDialog -{ - Q_OBJECT - -public: - explicit CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0); - -private: - QSortFilterProxyModel *m_proxyModel; -}; - - -// ---------------------------------------------------------------------------------------------------------------------- - - class CookieExceptionsModel : public QAbstractTableModel { Q_OBJECT @@ -177,29 +165,4 @@ private: }; -// ----------------------------------------------------------------------------------------------------------------- - - -#include "ui_cookiesexceptions.h" - -class CookiesExceptionsDialog : public QDialog, public Ui_CookiesExceptionsDialog -{ - Q_OBJECT - -public: - explicit CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent = 0); - -private slots: - void block(); - void allow(); - void allowForSession(); - void textChanged(const QString &text); - -private: - CookieExceptionsModel *m_exceptionsModel; - QSortFilterProxyModel *m_proxyModel; - CookieJar *m_cookieJar; -}; - #endif // COOKIEJAR_H - diff --git a/src/cookies.ui b/src/cookies.ui index 49ad3a96..8c9abc55 100644 --- a/src/cookies.ui +++ b/src/cookies.ui @@ -1,39 +1,59 @@ - CookiesDialog - + CookiesWidget + 0 0 - 550 - 370 + 499 + 400 - Cookies + Form - - - - - Qt::Horizontal - - - - 252 - 20 - - - - - - + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 252 + 20 + + + + + + + + + 0 + 0 + + + + Search: + + + + + + + - + - + @@ -62,13 +82,6 @@ - - - - QDialogButtonBox::Ok - - - @@ -86,22 +99,5 @@ - - - buttonBox - accepted() - CookiesDialog - accept() - - - 472 - 329 - - - 461 - 356 - - - - + diff --git a/src/cookiesexceptions.ui b/src/cookiesexceptions.ui index de59eee0..ef8d0705 100644 --- a/src/cookiesexceptions.ui +++ b/src/cookiesexceptions.ui @@ -1,46 +1,47 @@ - - CookiesExceptionsDialog - - + + + CookiesExceptionsWidget + + 0 0 - 466 - 446 + 457 + 495 - - Cookie Exceptions + + Form - + - - + + New Exception - - - + + + - - + + Domain: - + - - + + - + Qt::Horizontal - + 81 25 @@ -49,31 +50,31 @@ - - + + false - + Block - - + + false - + Allow For Session - - + + false - + Allow @@ -84,50 +85,50 @@ - - + + Exceptions - - - - - Qt::Horizontal - - - - 252 - 20 - - - + + + - - - - - - - - - + + + &Remove - - - + + + Remove &All - + - + + Qt::Horizontal + + + + 40 + 20 + + + + + + + Qt::Horizontal - + + QSizePolicy::Minimum + + 40 20 @@ -135,22 +136,33 @@ + + + + + 0 + 0 + + + + Search: + + + + + + - - - - Qt::Horizontal - - - QDialogButtonBox::Ok - - - + + KLineEdit + QLineEdit +
klineedit.h
+
EditTableView QTableView @@ -158,22 +170,5 @@
- - - buttonBox - accepted() - CookiesExceptionsDialog - accept() - - - 381 - 428 - - - 336 - 443 - - - - +
diff --git a/src/settings.cpp b/src/settings.cpp index fb68fb64..9ec5ad7a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -30,7 +30,7 @@ // Local Includes #include "application.h" #include "mainwindow.h" -#include "cookiejar.h" +#include "cookiedialogs.h" #include "history.h" #include "networkaccessmanager.h" #include "webview.h" -- cgit v1.2.1