From 5ee96ec9a97b67717b0fe70fe72986fa1ede29fa Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 24 May 2009 00:23:09 +0200 Subject: Some string fixes to ensure compatibility with the KDE Human Interface Guidelines --- src/settings_webkit.ui | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/settings_webkit.ui b/src/settings_webkit.ui index 32a9c0c9..a28ce915 100644 --- a/src/settings_webkit.ui +++ b/src/settings_webkit.ui @@ -20,7 +20,7 @@ - Autoload Images + Autoload images @@ -41,14 +41,14 @@ - Javascript support + JavaScript support - Zoom Text Only + Zoom text only @@ -62,7 +62,7 @@ - Print element Backgrounds + Print element backgrounds @@ -76,28 +76,28 @@ - Offline storage Database + Offline storage database - Javascript can open windows + JavaScript can open windows - Offline Web Application Cache + Offline web application cache - Javascript can access clipboard + JavaScript can access clipboard -- cgit v1.2.1 From 1eb43a3b4526521df8544e8f79c7994769eb6e9d Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 24 May 2009 02:26:12 +0200 Subject: More KDE HIG related string fixes --- src/settings_fonts.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/settings_fonts.ui b/src/settings_fonts.ui index de258cad..3a00358d 100644 --- a/src/settings_fonts.ui +++ b/src/settings_fonts.ui @@ -25,14 +25,14 @@ - Standard Font + Standard font - Fixed Font + Fixed font @@ -58,7 +58,7 @@ - Font Size + Font size -- cgit v1.2.1 From d1b1498e92bfe379f11ae931a15e99284de7a0f8 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 24 May 2009 02:28:13 +0200 Subject: More KDE HIG related string changes --- src/settings_general.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/settings_general.ui b/src/settings_general.ui index f9d272c6..95723e78 100644 --- a/src/settings_general.ui +++ b/src/settings_general.ui @@ -45,7 +45,7 @@ - Set to current page + Set to Current Page @@ -80,7 +80,7 @@ - ask where to save downloads + Ask where to save downloads -- cgit v1.2.1 From 09dc3b012ff6304ab8ed8ccbac9011d5f2e871d3 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 24 May 2009 02:28:50 +0200 Subject: More KDE HIG related string changes --- src/settings_privacy.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings_privacy.ui b/src/settings_privacy.ui index 78202688..114743dd 100644 --- a/src/settings_privacy.ui +++ b/src/settings_privacy.ui @@ -76,7 +76,7 @@ - Accept Cookies: + Accept cookies: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter -- cgit v1.2.1 From 56ee6c2a96f285c795d85965d65070eeac8c2ade Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 24 May 2009 02:59:37 +0200 Subject: Changed a bit the description of rekonq --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 600961c5..1c07c819 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ static const char description[] = - I18N_NOOP("Webkit Based Browser for KDE"); + I18N_NOOP("WebKit-based Web Browser for KDE"); static const char version[] = "0.1"; -- cgit v1.2.1 From 66d6f4261e23774ade86b9f472a53cd1ffadc538 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 24 May 2009 03:01:42 +0200 Subject: Changed the description of rekonq a bit and added a German translation of the description --- data/rekonq.desktop | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/rekonq.desktop b/data/rekonq.desktop index 6411c493..ec93ba38 100644 --- a/data/rekonq.desktop +++ b/data/rekonq.desktop @@ -1,11 +1,12 @@ [Desktop Entry] Name=rekonq Name[sv]=Rekonq -GenericName=Webkit KDE Browser +GenericName=WebKit-based Web Browser for KDE +GenericName[de]=WebKit-basierter Web-Browser für KDE GenericName[et]=KDE Webkiti veebibrauser GenericName[pt]=Navegador Web com WebKit GenericName[pt_BR]=Navegador Webkit do KDE -GenericName[sv]=Webkit webbläsare för KDE +GenericName[sv]=WebKit webbläsare för KDE GenericName[uk]=Переглядач мережі на WebKit для KDE Icon=rekonq Type=Application -- cgit v1.2.1 From fea1367456d4e9f348cede4a1926f8668e7deb05 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 24 May 2009 03:04:00 +0200 Subject: Webkit -> WebKit --- src/settings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index 198ab3e0..fb68fb64 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -102,7 +102,7 @@ Private::Private(SettingsDialog *parent) widget = new QWidget; webkitUi.setupUi(widget); widget->layout()->setMargin(0); - pageItem = parent->addPage(widget , i18n("Webkit")); + pageItem = parent->addPage(widget , i18n("WebKit")); QString webkitIconPath = KStandardDirs::locate("appdata", "pics/webkit-icon.png"); kWarning() << webkitIconPath; KIcon webkitIcon = KIcon(QIcon(webkitIconPath)); @@ -120,7 +120,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) setFaceType(KPageDialog::List); showButtonSeparator(true); - setWindowTitle(i18n("rekonfig..")); + setWindowTitle(i18n("rekonfig...")); setModal(true); readConfig(); -- cgit v1.2.1 From bf0640100e8d637d08a6188b0091efda42f921e0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 1 Jun 2009 16:05:06 +0200 Subject: Revert "Changed the description of rekonq a bit and added a German translation of the" As explained in IRC, we cannot modify .desktop file directly This reverts commit 66d6f4261e23774ade86b9f472a53cd1ffadc538. --- data/rekonq.desktop | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/data/rekonq.desktop b/data/rekonq.desktop index ec93ba38..6411c493 100644 --- a/data/rekonq.desktop +++ b/data/rekonq.desktop @@ -1,12 +1,11 @@ [Desktop Entry] Name=rekonq Name[sv]=Rekonq -GenericName=WebKit-based Web Browser for KDE -GenericName[de]=WebKit-basierter Web-Browser für KDE +GenericName=Webkit KDE Browser GenericName[et]=KDE Webkiti veebibrauser GenericName[pt]=Navegador Web com WebKit GenericName[pt_BR]=Navegador Webkit do KDE -GenericName[sv]=WebKit webbläsare för KDE +GenericName[sv]=Webkit webbläsare för KDE GenericName[uk]=Переглядач мережі на WebKit для KDE Icon=rekonq Type=Application -- cgit v1.2.1 From 45d8abb15061ffb6a5c2f4b9ec643234eccc452a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 1 Jun 2009 00:58:58 +0200 Subject: Removed unuseful download classes --- TODO | 1 + src/CMakeLists.txt | 1 - src/application.cpp | 13 --- src/application.h | 3 - src/download.cpp | 225 ---------------------------------------------------- src/download.h | 141 -------------------------------- src/mainwindow.cpp | 3 +- src/webpage.cpp | 1 - src/webview.cpp | 1 - 9 files changed, 2 insertions(+), 387 deletions(-) delete mode 100644 src/download.cpp delete mode 100644 src/download.h diff --git a/TODO b/TODO index a7055fea..40ccda35 100644 --- a/TODO +++ b/TODO @@ -20,4 +20,5 @@ TO 0.2 release - bookmarks panel - MimeType Manager - BETTER KDE INTEGRATION (What else to be done??) +- error pages diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 064fc0e6..d271cb6e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,6 @@ SET( rekonq_SRCS edittableview.cpp edittreeview.cpp history.cpp - download.cpp bookmarks.cpp modelmenu.cpp networkaccessmanager.cpp diff --git a/src/application.cpp b/src/application.cpp index 5f7892c4..06947e22 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -34,7 +34,6 @@ #include "networkaccessmanager.h" #include "mainview.h" #include "webview.h" -#include "download.h" // KDE Includes #include @@ -52,7 +51,6 @@ QPointer Application::s_historyManager; QPointer Application::s_networkAccessManager; -QPointer Application::s_downloadManager; QPointer Application::s_bookmarkProvider; @@ -176,16 +174,6 @@ HistoryManager *Application::historyManager() } -DownloadManager *Application::downloadManager() -{ - if (!s_downloadManager) - { - s_downloadManager = new DownloadManager(); - } - return s_downloadManager; -} - - BookmarkProvider *Application::bookmarkProvider() { if (!s_bookmarkProvider) @@ -205,4 +193,3 @@ KIcon Application::icon(const KUrl &url) const } return icon; } - diff --git a/src/application.h b/src/application.h index e0c7a21c..dd26ef9c 100644 --- a/src/application.h +++ b/src/application.h @@ -40,7 +40,6 @@ class KIcon; class KUrl; class BookmarkProvider; class CookieJar; -class DownloadManager; class HistoryManager; class MainWindow; class NetworkAccessManager; @@ -83,7 +82,6 @@ public: static HistoryManager *historyManager(); static CookieJar *cookieJar(); static NetworkAccessManager *networkAccessManager(); - static DownloadManager *downloadManager(); static BookmarkProvider *bookmarkProvider(); public slots: @@ -105,7 +103,6 @@ private slots: private: static QPointer s_historyManager; static QPointer s_networkAccessManager; - static QPointer s_downloadManager; static QPointer s_bookmarkProvider; QPointer m_mainWindow; diff --git a/src/download.cpp b/src/download.cpp deleted file mode 100644 index c365d3c5..00000000 --- a/src/download.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007 Lukas Appelhans -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Domrachev Alexandr -* -* -* 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 "download.h" -#include "download.moc" - -// KDE Includes -#include -#include -#include -#include -#include -#include - -// Qt Includes -#include -#include - -// Local Includes -#include "application.h" -#include "mainwindow.h" - - -DownloadManager::DownloadManager() - : QObject() -{ -} - - -DownloadManager::~DownloadManager() -{ - foreach(Download *download, m_downloads) - { - // cancel all unfinished downloads - download->cancel(); - delete download; - } -} - - -void DownloadManager::newDownload(const KUrl &srcUrl, const KUrl &destUrl) -{ - KUrl destination = destUrl; - Download::DownloadType type; - - KSharedPtr mimeType = KMimeType::findByPath(srcUrl.prettyUrl()); - - QString typeText = KMimeType::extractKnownExtension(srcUrl.fileName()); - typeText += " (" + mimeType->name() + ')'; - - int answer = KMessageBox::questionYesNoCancel( - NULL, - i18n("Download '%1'?\n""Type: %2", srcUrl.prettyUrl(), typeText), - i18n("Download '%1'...", srcUrl.fileName()), - KStandardGuiItem::save(), - KStandardGuiItem::open(), - KStandardGuiItem::cancel() - ); - - switch (answer) - { - case KMessageBox::Cancel: - return; - break; - - case KMessageBox::Yes: // ----- SAVE - // if destination is empty than ask for download path (if showOpenSaveDownloadDialog setting enabled) - if (destination.isEmpty()) - { - destination = downloadDestination(srcUrl.fileName()); - } - type = Download::Save; - break; - - case KMessageBox::No: // ----- OPEN - // Download file to tmp dir - destination.setDirectory(KStandardDirs::locateLocal("tmp", "", true)); - destination.addPath(srcUrl.fileName()); - type = Download::Open; - break; - - default: - // impossible - break; - }; - - // if user canceled download than abort - if (destination.isEmpty()) - return; - - Download *download = new Download(srcUrl, destination, type); - connect(download, SIGNAL(downloadFinished(int)), this, SLOT(slotDownloadFinished(int))); - m_downloads.append(download); -} - - -const QList &DownloadManager::downloads() const -{ - return m_downloads; -} - - -KUrl DownloadManager::downloadDestination(const QString &filename) -{ - KUrl destination = ReKonfig::downloadDir(); - if (destination.isEmpty()) - destination = KGlobalSettings::downloadPath(); - destination.addPath(filename); - - if (!ReKonfig::downloadToDefaultDir()) - { - destination = KFileDialog::getSaveUrl(destination); - // if user canceled the download return empty url - if (destination.isEmpty()) - return KUrl(); - } - return destination; -} - - -void DownloadManager::slotDownloadFinished(int errorCode) -{ - Q_UNUSED(errorCode) - - // if sender exists and list contains it - (open and) delete it - Download *download = qobject_cast(sender()); - if (download && m_downloads.contains(download)) - { - if (download->type() == Download::Open) - { - KSharedPtr mimeType = KMimeType::findByPath(download->destUrl().prettyUrl()); - KRun::runUrl(download->destUrl(), mimeType->name(), NULL, true); - } - disconnect(download, SIGNAL(downloadFinished(int)), this, SLOT(slotDownloadFinished(int))); - int index = m_downloads.indexOf(download); - delete m_downloads.takeAt(index); - return; - } - kWarning() << "Could not find download or invalid sender. Sender:" << sender(); -} - - -//---- - -#include -#include -#include - - -Download::Download(const KUrl &srcUrl, const KUrl &destUrl, DownloadType type) - : QObject() - , m_srcUrl(srcUrl) - , m_destUrl(destUrl) - , m_type(type) -{ - Q_ASSERT(!m_srcUrl.isEmpty()); - Q_ASSERT(!m_destUrl.isEmpty()); - kDebug() << "DownloadFile: " << m_srcUrl.url() << " to dest: " << m_destUrl.url(); - - m_copyJob = KIO::file_copy(m_srcUrl, m_destUrl); - connect(m_copyJob, SIGNAL(result(KJob *)), SLOT(slotResult(KJob *))); -} - - -Download::~Download() -{ -} - - -void Download::cancel() -{ - bool result = m_copyJob->kill(KJob::EmitResult); - Q_ASSERT(result); -} - - -void Download::slotResult(KJob *job) -{ - switch (job->error()) - { - case 0: //The download has finished - { - kDebug() << "Downloading successfully finished: " << m_destUrl.url(); - break; - } - case KIO::ERR_FILE_ALREADY_EXIST: - { - kWarning() << "ERROR - File already exists"; - break; - } - case KIO::ERR_USER_CANCELED: - { - kWarning() << "ERROR - User canceled the downlaod"; - break; - } - default: - kWarning() << "We are sorry to say you, that there were errors while downloading :("; - break; - } - - // inform the world - emit downloadFinished(job->error()); -} - diff --git a/src/download.h b/src/download.h deleted file mode 100644 index 0502d500..00000000 --- a/src/download.h +++ /dev/null @@ -1,141 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007 Lukas Appelhans -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Domrachev Alexandr -* -* -* 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 DOWNLOAD_H -#define DOWNLOAD_H - -// Auto Includes -#include "rekonq.h" - -// KDE Includes -#include - -// Qt Includes -#include - -// Forward Declarations -class KJob; - -namespace KIO -{ -class Job; -} - - -/** - * This class lets rekonq to download an object from the network. - * Creating a new object, you can continue downloading a file also - * when rekonq is closed. - * - */ -class Download : public QObject -{ - Q_OBJECT - -public: - enum DownloadType { Save, Open }; - - /** - * Class constructor. This is the unique method we need to - * use this class. In fact Download class needs to know just - * "where" catch the file to download and where it has to put it - * - * @param srcUrl the source url - * @param destUrl the destination url - * - */ - Download(const KUrl &srcUrl, const KUrl &destUrl, DownloadType type); - - /** - * class destructor - */ - ~Download(); - - KUrl srcUrl() const - { - return m_srcUrl; - } - KUrl destUrl() const - { - return m_destUrl; - } - DownloadType type() const - { - return m_type; - } - void cancel(); - -signals: - void downloadFinished(int errorCode); - -private slots: - void slotResult(KJob *job); - -private: - KIO::FileCopyJob *m_copyJob; - KUrl m_srcUrl; - KUrl m_destUrl; - KUrl m_destFile; - QByteArray m_data; - DownloadType m_type; -}; - - -// ---------------------- - - -class DownloadManager : public QObject -{ - Q_OBJECT - -public: - DownloadManager(); - ~DownloadManager(); - - /** - * @short Creates new download job. - * This method lets you to download a file from a remote source url - * to a local destination url. - * - * @param srcUrl the source url - * @param destUrl the destination url (default value is your default download destination setting) - * - */ - void newDownload(const KUrl &srcUrl, const KUrl &destUrl = KUrl()); - - const QList &downloads() const; - -public slots: - void slotDownloadFinished(int errorCode); - -private: - KUrl downloadDestination(const QString &filename); - - QList m_downloads; -}; - - -//-- - - -#endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 73ec3d6d..f47c6677 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -37,7 +37,6 @@ #include "webview.h" #include "mainview.h" #include "bookmarks.h" -#include "download.h" #include "findbar.h" #include "sidepanel.h" #include "urlbar.h" @@ -485,7 +484,7 @@ void MainWindow::slotOpenLocation() void MainWindow::slotFileSaveAs() { KUrl srcUrl = currentTab()->url(); - Application::downloadManager()->newDownload(srcUrl); + // FIXME implement download file } diff --git a/src/webpage.cpp b/src/webpage.cpp index cfbc32cf..193f2a82 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -32,7 +32,6 @@ #include "mainview.h" #include "cookiejar.h" #include "networkaccessmanager.h" -#include "download.h" #include "history.h" #include "webview.h" diff --git a/src/webview.cpp b/src/webview.cpp index 216c2bd1..0ba33682 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -34,7 +34,6 @@ #include "mainview.h" #include "cookiejar.h" #include "networkaccessmanager.h" -#include "download.h" #include "history.h" #include "webpage.h" -- cgit v1.2.1 From 0f96a0ae5d93853d56ad723557fc58ca51b7cef0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 1 Jun 2009 01:43:03 +0200 Subject: Moving guessUrlFromString function to Application class --- src/application.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/application.h | 4 +++- src/mainview.cpp | 6 ++--- src/mainwindow.cpp | 61 +-------------------------------------------------- src/mainwindow.h | 1 - 5 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index 06947e22..09a8a087 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -91,7 +91,7 @@ int Application::newInstance() { for (int i = 0; i < args->count(); ++i) { - KUrl url = MainWindow::guessUrlFromString(args->arg(i)); + KUrl url = guessUrlFromString(args->arg(i)); newWebView(); mainWindow()->loadUrl(url); } @@ -148,7 +148,7 @@ WebView *Application::newWebView(Rekonq::OpenType type) CookieJar *Application::cookieJar() { - return (CookieJar*)networkAccessManager()->cookieJar(); + return (CookieJar *)networkAccessManager()->cookieJar(); } @@ -193,3 +193,62 @@ KIcon Application::icon(const KUrl &url) const } return icon; } + + +KUrl Application::guessUrlFromString(const QString &string) +{ + QString urlStr = string.trimmed(); + QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*")); + + // Check if it looks like a qualified URL. Try parsing it and see. + bool hasSchema = test.exactMatch(urlStr); + + if (hasSchema) + { + QUrl qurl(urlStr, QUrl::TolerantMode); + KUrl url(qurl); + + if (url.isValid()) + { + return url; + } + } + + // Might be a file. + if (QFile::exists(urlStr)) + { + QFileInfo info(urlStr); + return KUrl::fromPath(info.absoluteFilePath()); + } + + // Might be a shorturl - try to detect the schema. + if (!hasSchema) + { + int dotIndex = urlStr.indexOf(QLatin1Char('.')); + + if (dotIndex != -1) + { + QString prefix = urlStr.left(dotIndex).toLower(); + QString schema = (prefix == QLatin1String("ftp")) ? prefix : QLatin1String("http"); + QUrl qurl(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode); + KUrl url(qurl); + + if (url.isValid()) + { + return url; + } + } + } + + // Fall back to QUrl's own tolerant parser. + QUrl qurl = QUrl(string, QUrl::TolerantMode); + KUrl url(qurl); + + // finally for cases where the user just types in a hostname add http + if (qurl.scheme().isEmpty()) + { + qurl = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode); + url = KUrl(qurl); + } + return url; +} diff --git a/src/application.h b/src/application.h index dd26ef9c..e61b2a31 100644 --- a/src/application.h +++ b/src/application.h @@ -75,10 +75,12 @@ public: static Application *instance(); MainWindow *mainWindow(); - WebView* newWebView(Rekonq::OpenType type = Rekonq::Default); + WebView *newWebView(Rekonq::OpenType type = Rekonq::Default); KIcon icon(const KUrl &url) const; + static KUrl guessUrlFromString(const QString &url); + static HistoryManager *historyManager(); static CookieJar *cookieJar(); static NetworkAccessManager *networkAccessManager(); diff --git a/src/mainview.cpp b/src/mainview.cpp index d8d1c2b5..ea56527d 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -362,10 +362,8 @@ WebView *MainView::newWebView(Rekonq::OpenType type) connect(webView, SIGNAL(shiftCtrlTabPressed()), this, SLOT(previousTab())); // connecting webPage signals with mainview - connect(webView->page(), SIGNAL(windowCloseRequested()), - this, SLOT(windowCloseRequested())); - connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), - this, SIGNAL(printRequested(QWebFrame *))); + connect(webView->page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested())); + connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), this, SIGNAL(printRequested(QWebFrame *))); addTab(webView, i18n("(Untitled)")); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f47c6677..287d423d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -409,65 +409,6 @@ void MainWindow::slotUpdateBrowser() } -KUrl MainWindow::guessUrlFromString(const QString &string) -{ - QString urlStr = string.trimmed(); - QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*")); - - // Check if it looks like a qualified URL. Try parsing it and see. - bool hasSchema = test.exactMatch(urlStr); - - if (hasSchema) - { - QUrl qurl(urlStr, QUrl::TolerantMode); - KUrl url(qurl); - - if (url.isValid()) - { - return url; - } - } - - // Might be a file. - if (QFile::exists(urlStr)) - { - QFileInfo info(urlStr); - return KUrl::fromPath(info.absoluteFilePath()); - } - - // Might be a shorturl - try to detect the schema. - if (!hasSchema) - { - int dotIndex = urlStr.indexOf(QLatin1Char('.')); - - if (dotIndex != -1) - { - QString prefix = urlStr.left(dotIndex).toLower(); - QString schema = (prefix == QLatin1String("ftp")) ? prefix : QLatin1String("http"); - QUrl qurl(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode); - KUrl url(qurl); - - if (url.isValid()) - { - return url; - } - } - } - - // Fall back to QUrl's own tolerant parser. - QUrl qurl = QUrl(string, QUrl::TolerantMode); - KUrl url(qurl); - - // finally for cases where the user just types in a hostname add http - if (qurl.scheme().isEmpty()) - { - qurl = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode); - url = KUrl(qurl); - } - return url; -} - - void MainWindow::loadUrl(const KUrl &url) { m_view->loadUrl(url); @@ -543,7 +484,7 @@ void MainWindow::slotFileOpen() if (filePath.isEmpty()) return; - loadUrl(guessUrlFromString(filePath)); + loadUrl(Application::guessUrlFromString(filePath)); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 7d0b2e5c..cc0aa2e8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -62,7 +62,6 @@ public: MainWindow(); ~MainWindow(); - static KUrl guessUrlFromString(const QString &url); MainView *mainView() const; WebView *currentTab() const; QAction *actionByName(const QString name); -- cgit v1.2.1 From 0081a4fff5e3de0dedfa74134fc7ee221b106a5e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 2 Jun 2009 01:50:28 +0200 Subject: Porting history Ui to KDE.. --- src/CMakeLists.txt | 2 + src/history.cpp | 140 +------------------------------------------------- src/history.h | 57 -------------------- src/history.ui | 90 ++++++++++++-------------------- src/historydialog.cpp | 116 +++++++++++++++++++++++++++++++++++++++++ src/historydialog.h | 56 ++++++++++++++++++++ src/historymenu.cpp | 95 ++++++++++++++++++++++++++++++++++ src/historymenu.h | 65 +++++++++++++++++++++++ src/mainwindow.cpp | 2 +- src/panelhistory.cpp | 6 ++- src/panelhistory.h | 6 +-- 11 files changed, 376 insertions(+), 259 deletions(-) create mode 100644 src/historydialog.cpp create mode 100644 src/historydialog.h create mode 100644 src/historymenu.cpp create mode 100644 src/historymenu.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 064fc0e6..4a3f5fed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,8 @@ SET( rekonq_SRCS edittableview.cpp edittreeview.cpp history.cpp + historydialog.cpp + historymenu.cpp download.cpp bookmarks.cpp modelmenu.cpp diff --git a/src/history.cpp b/src/history.cpp index fac13b48..795bc14e 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -669,74 +669,6 @@ QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const } -// ------------------------------------------------------------------------------------------------------------- - - -HistoryMenu::HistoryMenu(QWidget *parent) - : ModelMenu(parent) - , m_history(0) -{ - connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &))); - setHoverRole(HistoryModel::UrlStringRole); -} - - -void HistoryMenu::activated(const QModelIndex &index) -{ - emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); -} - - -bool HistoryMenu::prePopulated() -{ - if (!m_history) - { - m_history = Application::historyManager(); - m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); - setModel(m_historyMenuModel); - } - // initial actions - for (int i = 0; i < m_initialActions.count(); ++i) - addAction(m_initialActions.at(i)); - if (!m_initialActions.isEmpty()) - addSeparator(); - setFirstSeparator(m_historyMenuModel->bumpedRows()); - - return false; -} - - -void HistoryMenu::postPopulated() -{ - if (m_history->history().count() > 0) - addSeparator(); - - KAction *showAllAction = new KAction(i18n("Show All History"), this); - connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); - addAction(showAllAction); - - KAction *clearAction = new KAction(i18n("Clear History"), this); - connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear())); - addAction(clearAction); -} - - -void HistoryMenu::showHistoryDialog() -{ - HistoryDialog *dialog = new HistoryDialog(this); - connect(dialog, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); - dialog->show(); -} - - -void HistoryMenu::setInitialActions(QList actions) -{ - m_initialActions = actions; - for (int i = 0; i < m_initialActions.count(); ++i) - addAction(m_initialActions.at(i)); -} - - // -------------------------------------------------------------------------------------------------------------- @@ -755,78 +687,8 @@ bool TreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_ } -// ----------------------------------------------------------------------------------------------------- - - -HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDialog(parent) -{ - HistoryManager *history = setHistory; - if (!history) - history = Application::historyManager(); - setupUi(this); - tree->setUniformRowHeights(true); - tree->setSelectionBehavior(QAbstractItemView::SelectRows); - tree->setTextElideMode(Qt::ElideMiddle); - QAbstractItemModel *model = history->historyTreeModel(); - TreeProxyModel *proxyModel = new TreeProxyModel(this); - connect(search, SIGNAL(textChanged(QString)), - proxyModel, SLOT(setFilterFixedString(QString))); - connect(removeButton, SIGNAL(clicked()), tree, SLOT(removeOne())); - connect(removeAllButton, SIGNAL(clicked()), history, SLOT(clear())); - proxyModel->setSourceModel(model); - tree->setModel(proxyModel); - tree->setExpanded(proxyModel->index(0, 0), true); - tree->setAlternatingRowColors(true); - QFontMetrics fm(font()); - int header = fm.width(QLatin1Char('m')) * 40; - tree->header()->resizeSection(0, header); - tree->header()->setStretchLastSection(true); - connect(tree, SIGNAL(activated(const QModelIndex&)), - this, SLOT(open())); - tree->setContextMenuPolicy(Qt::CustomContextMenu); - connect(tree, SIGNAL(customContextMenuRequested(const QPoint &)), - this, SLOT(customContextMenuRequested(const QPoint &))); -} - - -void HistoryDialog::customContextMenuRequested(const QPoint &pos) -{ - QMenu menu; - QModelIndex index = tree->indexAt(pos); - index = index.sibling(index.row(), 0); - if (index.isValid() && !tree->model()->hasChildren(index)) - { - menu.addAction(i18n("Open"), this, SLOT(open())); - menu.addSeparator(); - menu.addAction(i18n("Copy"), this, SLOT(copy())); - } - menu.addAction(i18n("Delete"), tree, SLOT(removeOne())); - menu.exec(QCursor::pos()); -} - - -void HistoryDialog::open() -{ - QModelIndex index = tree->currentIndex(); - if (!index.parent().isValid()) - return; - emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); -} - - -void HistoryDialog::copy() -{ - QModelIndex index = tree->currentIndex(); - if (!index.parent().isValid()) - return; - QString url = index.data(HistoryModel::UrlStringRole).toString(); - - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(url); -} - +// ------------------------------------------------------------------------------------------------------------- -// --------------------------------------------------------------------------------------------------------------- HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) : QAbstractProxyModel(parent), diff --git a/src/history.h b/src/history.h index 7b3cbec9..7586ff9d 100644 --- a/src/history.h +++ b/src/history.h @@ -27,7 +27,6 @@ #include "modelmenu.h" // KDE Includes -#include #include // Qt Includes @@ -256,39 +255,6 @@ private: }; -// --------------------------------------------------------------------------------------------- - -/** - * Menu that is dynamically populated from the history - * - */ - -class HistoryMenu : public ModelMenu -{ - Q_OBJECT - -signals: - void openUrl(const KUrl &url); - -public: - HistoryMenu(QWidget *parent = 0); - void setInitialActions(QList actions); - -protected: - bool prePopulated(); - void postPopulated(); - -private slots: - void activated(const QModelIndex &index); - void showHistoryDialog(); - -private: - HistoryManager *m_history; - HistoryMenuModel *m_historyMenuModel; - QList m_initialActions; -}; - - // ---------------------------------------------------------------------------------------- /** @@ -383,27 +349,4 @@ protected: }; -// ------------------------------------------------------------------------------------------ - - -// Ui includes -#include "ui_history.h" - -class HistoryDialog : public QDialog, public Ui_HistoryDialog -{ - Q_OBJECT - -signals: - void openUrl(const KUrl &url); - -public: - explicit HistoryDialog(QWidget *parent = 0, HistoryManager *history = 0); - -private slots: - void customContextMenuRequested(const QPoint &pos); - void open(); - void copy(); - -}; - #endif // HISTORY_H diff --git a/src/history.ui b/src/history.ui index 806bc9ad..fb694f8f 100644 --- a/src/history.ui +++ b/src/history.ui @@ -1,59 +1,41 @@ - - HistoryDialog - - + + + historyWidget + + 0 0 - 758 - 450 + 584 + 381 - - History + + Form - - - - - Qt::Horizontal - - - - 252 - 20 - - - - - - - - - - - - + + + - - + + &Remove - - + + Remove &All - + Qt::Horizontal - + 40 20 @@ -62,17 +44,28 @@ - - - QDialogButtonBox::Ok + + + Search: + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
EditTreeView QTreeView @@ -80,22 +73,5 @@
- - - buttonBox - accepted() - HistoryDialog - accept() - - - 472 - 329 - - - 461 - 356 - - - - +
diff --git a/src/historydialog.cpp b/src/historydialog.cpp new file mode 100644 index 00000000..da1c5858 --- /dev/null +++ b/src/historydialog.cpp @@ -0,0 +1,116 @@ +/* ============================================================ +* +* 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. +* +* ============================================================ */ + + +// Auto Includes +#include "historydialog.h" +#include "historydialog.moc" + +// Local Includes +#include "history.h" +#include "application.h" + +// KDE Includes +#include +#include + +// Qt Includes +#include + +#include +#include + + +HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) + : KDialog(parent) + , m_historyWidg(new Ui::historyWidget) +{ + HistoryManager *history = setHistory; + if (!history) + history = Application::historyManager(); + + setCaption( i18n("History") ); + setButtons( KDialog::Close ); + + QWidget *widget = new QWidget; + m_historyWidg->setupUi(widget); + setMainWidget(widget); + + m_historyWidg->tree->setUniformRowHeights(true); + m_historyWidg->tree->setSelectionBehavior(QAbstractItemView::SelectRows); + m_historyWidg->tree->setTextElideMode(Qt::ElideMiddle); + + QAbstractItemModel *model = history->historyTreeModel(); + TreeProxyModel *proxyModel = new TreeProxyModel(this); + + connect(m_historyWidg->search, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString))); + connect(m_historyWidg->removeButton, SIGNAL(clicked()), m_historyWidg->tree, SLOT(removeOne())); + connect(m_historyWidg->removeAllButton, SIGNAL(clicked()), history, SLOT(clear())); + + proxyModel->setSourceModel(model); + m_historyWidg->tree->setModel(proxyModel); + m_historyWidg->tree->setExpanded(proxyModel->index(0, 0), true); + m_historyWidg->tree->setAlternatingRowColors(true); + + QFontMetrics fm(font()); + int header = fm.width(QLatin1Char('m')) * 40; + m_historyWidg->tree->header()->resizeSection(0, header); + m_historyWidg->tree->header()->setStretchLastSection(true); + connect(m_historyWidg->tree, SIGNAL(activated(const QModelIndex&)), this, SLOT(open())); + m_historyWidg->tree->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_historyWidg->tree, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(customContextMenuRequested(const QPoint &))); +} + + +void HistoryDialog::customContextMenuRequested(const QPoint &pos) +{ + KMenu menu; + QModelIndex index = m_historyWidg->tree->indexAt(pos); + index = index.sibling(index.row(), 0); + if (index.isValid() && !m_historyWidg->tree->model()->hasChildren(index)) + { + menu.addAction(i18n("Open"), this, SLOT(open())); + menu.addSeparator(); + menu.addAction(i18n("Copy"), this, SLOT(copy())); + } + menu.addAction(i18n("Delete"), m_historyWidg->tree, SLOT(removeOne())); + menu.exec(QCursor::pos()); +} + + +void HistoryDialog::open() +{ + QModelIndex index = m_historyWidg->tree->currentIndex(); + if (!index.parent().isValid()) + return; + emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); +} + + +void HistoryDialog::copy() +{ + QModelIndex index = m_historyWidg->tree->currentIndex(); + if (!index.parent().isValid()) + return; + QString url = index.data(HistoryModel::UrlStringRole).toString(); + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(url); +} diff --git a/src/historydialog.h b/src/historydialog.h new file mode 100644 index 00000000..1f592cdd --- /dev/null +++ b/src/historydialog.h @@ -0,0 +1,56 @@ +/* ============================================================ +* +* 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 HISTORYDIALOG_H +#define HISTORYDIALOG_H + + +// Ui includes +#include "ui_history.h" + +// KDE Includes +#include + +class KUrl; +class QPoint; +class QWidget; +class HistoryManager; + +class HistoryDialog : public KDialog +{ + Q_OBJECT + +signals: + void openUrl(const KUrl &url); + +public: + explicit HistoryDialog(QWidget *parent = 0, HistoryManager *history = 0); + +private slots: + void customContextMenuRequested(const QPoint &pos); + void open(); + void copy(); + +private: + Ui::historyWidget *m_historyWidg; +}; + +#endif diff --git a/src/historymenu.cpp b/src/historymenu.cpp new file mode 100644 index 00000000..74b37db0 --- /dev/null +++ b/src/historymenu.cpp @@ -0,0 +1,95 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-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. +* +* ============================================================ */ + + +#include "historymenu.h" +#include "historymenu.moc" + +#include "application.h" +#include "historydialog.h" + +#include +#include + +#include + +HistoryMenu::HistoryMenu(QWidget *parent) + : ModelMenu(parent) + , m_history(0) +{ + connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &))); + setHoverRole(HistoryModel::UrlStringRole); +} + + +void HistoryMenu::activated(const QModelIndex &index) +{ + emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); +} + + +bool HistoryMenu::prePopulated() +{ + if (!m_history) + { + m_history = Application::historyManager(); + m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); + setModel(m_historyMenuModel); + } + // initial actions + for (int i = 0; i < m_initialActions.count(); ++i) + addAction(m_initialActions.at(i)); + if (!m_initialActions.isEmpty()) + addSeparator(); + setFirstSeparator(m_historyMenuModel->bumpedRows()); + + return false; +} + + +void HistoryMenu::postPopulated() +{ + if (m_history->history().count() > 0) + addSeparator(); + + KAction *showAllAction = new KAction(i18n("Show All History"), this); + connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); + addAction(showAllAction); + + KAction *clearAction = new KAction(i18n("Clear History"), this); + connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear())); + addAction(clearAction); +} + + +void HistoryMenu::showHistoryDialog() +{ + HistoryDialog *dialog = new HistoryDialog(this); + connect(dialog, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); + dialog->show(); +} + + +void HistoryMenu::setInitialActions(QList actions) +{ + m_initialActions = actions; + for (int i = 0; i < m_initialActions.count(); ++i) + addAction(m_initialActions.at(i)); +} diff --git a/src/historymenu.h b/src/historymenu.h new file mode 100644 index 00000000..06d85ffa --- /dev/null +++ b/src/historymenu.h @@ -0,0 +1,65 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-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 HISTORYMENU_H +#define HISTORYMENU_H + +#include "history.h" + +#include +#include + +class ModelMenu; +class QWidget; +class QModelIndex; +class KUrl; + +/** + * Menu that is dynamically populated from the history + * + */ + +class HistoryMenu : public ModelMenu +{ + Q_OBJECT + +signals: + void openUrl(const KUrl &url); + +public: + HistoryMenu(QWidget *parent = 0); + void setInitialActions(QList actions); + +protected: + bool prePopulated(); + void postPopulated(); + +private slots: + void activated(const QModelIndex &index); + void showHistoryDialog(); + +private: + HistoryManager *m_history; + HistoryMenuModel *m_historyMenuModel; + QList m_initialActions; +}; + +#endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 73ec3d6d..0c7a0984 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,7 +30,7 @@ // Local Includes #include "application.h" #include "settings.h" -#include "history.h" +#include "historymenu.h" #include "cookiejar.h" #include "networkaccessmanager.h" #include "bookmarks.h" diff --git a/src/panelhistory.cpp b/src/panelhistory.cpp index 72507663..8b736074 100644 --- a/src/panelhistory.cpp +++ b/src/panelhistory.cpp @@ -22,8 +22,10 @@ #include "panelhistory.h" #include "panelhistory.moc" -// QT Includes -#include +// Qt Includes +#include +#include +#include // KDE Includes #include diff --git a/src/panelhistory.h b/src/panelhistory.h index c6fe1380..20152c64 100644 --- a/src/panelhistory.h +++ b/src/panelhistory.h @@ -22,14 +22,14 @@ // Local Includes #include "application.h" +#include "history.h" // Qt Includes -#include +#include +#include // Forward Declarations -class QTreeView; class KUrl; -class TreeProxyModel; class PanelHistory : public QWidget -- cgit v1.2.1 From 6add9bedab227a2a5bde2c5fb0dd4a5c1bedc679 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 2 Jun 2009 19:23:30 +0200 Subject: History Dialog UI fixes --- src/historydialog.cpp | 12 +++++++++++- src/historydialog.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/historydialog.cpp b/src/historydialog.cpp index f4aea3bb..7b0d6bc0 100644 --- a/src/historydialog.cpp +++ b/src/historydialog.cpp @@ -35,6 +35,7 @@ #include #include +#include HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) @@ -52,6 +53,8 @@ HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) m_historyWidg->setupUi(widget); setMainWidget(widget); + m_historyWidg->search->setClearButtonShown(true); + m_historyWidg->tree->setUniformRowHeights(true); m_historyWidg->tree->setSelectionBehavior(QAbstractItemView::SelectRows); m_historyWidg->tree->setTextElideMode(Qt::ElideMiddle); @@ -69,7 +72,7 @@ HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) m_historyWidg->tree->setAlternatingRowColors(true); QFontMetrics fm(font()); - int header = fm.width(QLatin1Char('m')) * 30; + int header = fm.width(QLatin1Char('m')) * 25; m_historyWidg->tree->header()->resizeSection(0, header); m_historyWidg->tree->header()->setStretchLastSection(true); @@ -117,3 +120,10 @@ void HistoryDialog::copy() QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(url); } + +QSize HistoryDialog::sizeHint() const +{ + QRect desktopRect = Application::desktop()->screenGeometry(); + QSize size = desktopRect.size() * 0.7; + return size; +} diff --git a/src/historydialog.h b/src/historydialog.h index 1f592cdd..6436eda3 100644 --- a/src/historydialog.h +++ b/src/historydialog.h @@ -43,6 +43,7 @@ signals: public: explicit HistoryDialog(QWidget *parent = 0, HistoryManager *history = 0); + QSize sizeHint() const; private slots: void customContextMenuRequested(const QPoint &pos); -- cgit v1.2.1 From ee8586be6e5dd2ace02a1778c59e18d2be3f3e1f Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 3 Jun 2009 00:00:19 +0200 Subject: updating .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5d84c45a..f4cc75e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -qtdemobrowser releases src/.ctagsdb *.*~ @@ -6,6 +5,5 @@ src/.ctagsdb .directory *.tmp build/ -qtcreator-build/ CMakeLists.txt.user CMakeCache.txt -- cgit v1.2.1 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 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 From 02755ffc374633144414f75865741d77bbcd6f46 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 18 May 2009 10:40:58 +0200 Subject: header fixing --- src/bookmarks.cpp | 5 +- src/cookiedialogs.cpp | 10 ++- src/download.cpp | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/edittableview.cpp | 1 + src/edittreeview.cpp | 1 + src/lineedit.cpp | 3 - src/main.cpp | 2 + src/modelmenu.cpp | 1 + src/panelhistory.cpp | 3 - src/searchbar.cpp | 1 - src/stackedurlbar.cpp | 6 +- 11 files changed, 244 insertions(+), 14 deletions(-) create mode 100644 src/download.cpp diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp index 9490ed0f..bddacab4 100644 --- a/src/bookmarks.cpp +++ b/src/bookmarks.cpp @@ -44,8 +44,9 @@ #include // Qt Includes -#include -#include +#include +#include + BookmarkOwner::BookmarkOwner(QObject *parent) diff --git a/src/cookiedialogs.cpp b/src/cookiedialogs.cpp index 9b768f6a..43cbed81 100644 --- a/src/cookiedialogs.cpp +++ b/src/cookiedialogs.cpp @@ -18,14 +18,20 @@ * ============================================================ */ -// Local Includes +// Self Includes #include "cookiedialogs.h" -#include "cookiejar.h" +#include "cookiedialogs.moc" +// Ui Includes #include "ui_cookies.h" +// Local Includes +#include "cookiejar.h" + +// Qt Includes #include + CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) : KDialog(parent) { diff --git a/src/download.cpp b/src/download.cpp new file mode 100644 index 00000000..2f98d5a4 --- /dev/null +++ b/src/download.cpp @@ -0,0 +1,225 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007 Lukas Appelhans +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* Copyright (C) 2009 by Domrachev Alexandr +* +* +* 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. +* +* ============================================================ */ + + +// Self Includes +#include "download.h" +#include "download.moc" + +// KDE Includes +#include +#include +#include +#include +#include +#include + +// Qt Includes +#include +#include + +// Local Includes +#include "application.h" +#include "mainwindow.h" + + +DownloadManager::DownloadManager() + : QObject() +{ +} + + +DownloadManager::~DownloadManager() +{ + foreach(Download *download, m_downloads) + { + // cancel all unfinished downloads + download->cancel(); + delete download; + } +} + + +void DownloadManager::newDownload(const KUrl &srcUrl, const KUrl &destUrl) +{ + KUrl destination = destUrl; + Download::DownloadType type; + + KSharedPtr mimeType = KMimeType::findByPath(srcUrl.prettyUrl()); + + QString typeText = KMimeType::extractKnownExtension(srcUrl.fileName()); + typeText += " (" + mimeType->name() + ')'; + + int answer = KMessageBox::questionYesNoCancel( + NULL, + i18n("Download '%1'?\n""Type: %2", srcUrl.prettyUrl(), typeText), + i18n("Download '%1'...", srcUrl.fileName()), + KStandardGuiItem::save(), + KStandardGuiItem::open(), + KStandardGuiItem::cancel() + ); + + switch (answer) + { + case KMessageBox::Cancel: + return; + break; + + case KMessageBox::Yes: // ----- SAVE + // if destination is empty than ask for download path (if showOpenSaveDownloadDialog setting enabled) + if (destination.isEmpty()) + { + destination = downloadDestination(srcUrl.fileName()); + } + type = Download::Save; + break; + + case KMessageBox::No: // ----- OPEN + // Download file to tmp dir + destination.setDirectory(KStandardDirs::locateLocal("tmp", "", true)); + destination.addPath(srcUrl.fileName()); + type = Download::Open; + break; + + default: + // impossible + break; + }; + + // if user canceled download than abort + if (destination.isEmpty()) + return; + + Download *download = new Download(srcUrl, destination, type); + connect(download, SIGNAL(downloadFinished(int)), this, SLOT(slotDownloadFinished(int))); + m_downloads.append(download); +} + + +const QList &DownloadManager::downloads() const +{ + return m_downloads; +} + + +KUrl DownloadManager::downloadDestination(const QString &filename) +{ + KUrl destination = ReKonfig::downloadDir(); + if (destination.isEmpty()) + destination = KGlobalSettings::downloadPath(); + destination.addPath(filename); + + if (!ReKonfig::downloadToDefaultDir()) + { + destination = KFileDialog::getSaveUrl(destination); + // if user canceled the download return empty url + if (destination.isEmpty()) + return KUrl(); + } + return destination; +} + + +void DownloadManager::slotDownloadFinished(int errorCode) +{ + Q_UNUSED(errorCode) + + // if sender exists and list contains it - (open and) delete it + Download *download = qobject_cast(sender()); + if (download && m_downloads.contains(download)) + { + if (download->type() == Download::Open) + { + KSharedPtr mimeType = KMimeType::findByPath(download->destUrl().prettyUrl()); + KRun::runUrl(download->destUrl(), mimeType->name(), NULL, true); + } + disconnect(download, SIGNAL(downloadFinished(int)), this, SLOT(slotDownloadFinished(int))); + int index = m_downloads.indexOf(download); + delete m_downloads.takeAt(index); + return; + } + kWarning() << "Could not find download or invalid sender. Sender:" << sender(); +} + + +//---- + +#include +#include +#include + + +Download::Download(const KUrl &srcUrl, const KUrl &destUrl, DownloadType type) + : QObject() + , m_srcUrl(srcUrl) + , m_destUrl(destUrl) + , m_type(type) +{ + Q_ASSERT(!m_srcUrl.isEmpty()); + Q_ASSERT(!m_destUrl.isEmpty()); + kDebug() << "DownloadFile: " << m_srcUrl.url() << " to dest: " << m_destUrl.url(); + + m_copyJob = KIO::file_copy(m_srcUrl, m_destUrl); + connect(m_copyJob, SIGNAL(result(KJob *)), SLOT(slotResult(KJob *))); +} + + +Download::~Download() +{ +} + + +void Download::cancel() +{ + bool result = m_copyJob->kill(KJob::EmitResult); + Q_ASSERT(result); +} + + +void Download::slotResult(KJob *job) +{ + switch (job->error()) + { + case 0: //The download has finished + { + kDebug() << "Downloading successfully finished: " << m_destUrl.url(); + break; + } + case KIO::ERR_FILE_ALREADY_EXIST: + { + kWarning() << "ERROR - File already exists"; + break; + } + case KIO::ERR_USER_CANCELED: + { + kWarning() << "ERROR - User canceled the downlaod"; + break; + } + default: + kWarning() << "We are sorry to say you, that there were errors while downloading :("; + break; + } + + // inform the world + emit downloadFinished(job->error()); +} + diff --git a/src/edittableview.cpp b/src/edittableview.cpp index 8b9bb12d..9ecf8958 100644 --- a/src/edittableview.cpp +++ b/src/edittableview.cpp @@ -21,6 +21,7 @@ // Self Includes #include "edittableview.h" +#include "edittableview.moc" // Qt Includes #include diff --git a/src/edittreeview.cpp b/src/edittreeview.cpp index 5547cdb0..8ca18d13 100644 --- a/src/edittreeview.cpp +++ b/src/edittreeview.cpp @@ -21,6 +21,7 @@ // Self Includes #include "edittreeview.h" +#include "edittreeview.moc" // Qt includes #include diff --git a/src/lineedit.cpp b/src/lineedit.cpp index dd90ce5a..e3185fc2 100644 --- a/src/lineedit.cpp +++ b/src/lineedit.cpp @@ -79,6 +79,3 @@ void LineEdit::focusOutEvent(QFocusEvent *event) setCursorPosition(0); deselect(); } - - - diff --git a/src/main.cpp b/src/main.cpp index 4a87ae53..009fc4b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,10 @@ * ============================================================ */ +// Local Includes #include "application.h" +// KDE Includes #include #include #include diff --git a/src/modelmenu.cpp b/src/modelmenu.cpp index 57b094ab..9ac9c512 100644 --- a/src/modelmenu.cpp +++ b/src/modelmenu.cpp @@ -21,6 +21,7 @@ // Self Includes #include "modelmenu.h" +#include "modelmenu.moc" ModelMenu::ModelMenu(QWidget * parent) diff --git a/src/panelhistory.cpp b/src/panelhistory.cpp index 8b736074..1282454a 100644 --- a/src/panelhistory.cpp +++ b/src/panelhistory.cpp @@ -32,9 +32,6 @@ #include #include -// Local Includes -#include "history.h" - PanelHistory::PanelHistory(QWidget *parent) : QWidget(parent) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 48e9290a..6d118a7d 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -129,4 +129,3 @@ void SearchBar::handleNetworkData(QNetworkReply *networkReply) networkReply->deleteLater(); } - diff --git a/src/stackedurlbar.cpp b/src/stackedurlbar.cpp index 113c8769..53a974fe 100644 --- a/src/stackedurlbar.cpp +++ b/src/stackedurlbar.cpp @@ -22,14 +22,14 @@ #include "stackedurlbar.h" #include "stackedurlbar.moc" -// KDE Includes -#include "kdebug.h" - // Local Includes #include "application.h" #include "history.h" #include "urlbar.h" +// KDE Includes +#include + StackedUrlBar::StackedUrlBar(QWidget *parent) : QStackedWidget(parent) -- cgit v1.2.1 From 06aebc3fb8032f38045370751bb053b1b4c8fed0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 18 May 2009 10:44:15 +0200 Subject: header fixing 2 --- src/cookiedialogs.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cookiedialogs.h b/src/cookiedialogs.h index 0f7b8036..9f1a69df 100644 --- a/src/cookiedialogs.h +++ b/src/cookiedialogs.h @@ -23,18 +23,23 @@ #define COOKIEDIALOGS_H +// KDE Includes #include // Qt Includes #include #include + #include -#include #include +#include + +// Forward Declarations class CookieJar; class CookieExceptionsModel; + class CookiesDialog : public KDialog { Q_OBJECT @@ -50,6 +55,7 @@ private: // ----------------------------------------------------------------------------------------------------------------- +// Ui Includes #include "ui_cookiesexceptions.h" -- cgit v1.2.1 From f6399177aa239657f7f8ebf37e8ccdfd9db574e6 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 18 May 2009 11:00:08 +0200 Subject: Ui Fixed. Go to next step.. --- src/cookiedialogs.cpp | 108 ++++++++++++++++++++++++++------------------------ src/cookiedialogs.h | 2 +- 2 files changed, 58 insertions(+), 52 deletions(-) diff --git a/src/cookiedialogs.cpp b/src/cookiedialogs.cpp index 43cbed81..b4e043aa 100644 --- a/src/cookiedialogs.cpp +++ b/src/cookiedialogs.cpp @@ -35,10 +35,13 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) : KDialog(parent) { - Ui::CookiesWidget cookieWidget; - QWidget widget; - cookieWidget.setupUi(&widget); - setMainWidget(&widget); + setCaption("Cookies"); + setButtons( KDialog::Ok ); + + Ui::CookiesWidget *cookieWidget = new Ui::CookiesWidget; + QWidget *widget = new QWidget(this); + cookieWidget->setupUi(widget); + setMainWidget(widget); setWindowFlags(Qt::Sheet); @@ -46,30 +49,30 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) 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())); + 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); + 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); + 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); + int header = cookieWidget->cookiesTable->horizontalHeader()->sectionSizeHint(i); switch (i) { case 0: @@ -84,9 +87,9 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) } int buffer = fm.width(QLatin1String("xx")); header += buffer; - cookieWidget.cookiesTable->horizontalHeader()->resizeSection(i, header); + cookieWidget->cookiesTable->horizontalHeader()->resizeSection(i, header); } - cookieWidget.cookiesTable->horizontalHeader()->setStretchLastSection(true); + cookieWidget->cookiesTable->horizontalHeader()->setStretchLastSection(true); } @@ -96,48 +99,51 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) : KDialog(parent) , m_cookieJar(cookieJar) - , exceptionsWidget(new Ui::CookiesExceptionsWidget) + , m_exceptionsWidget(new Ui::CookiesExceptionsWidget) { - QWidget widget; - exceptionsWidget->setupUi(&widget); - setMainWidget(&widget); + setCaption("Cookies Exceptions"); + setButtons( KDialog::Ok ); + + QWidget *widget = new QWidget(this); + m_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())); + connect(m_exceptionsWidget->removeButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeOne())); + connect(m_exceptionsWidget->removeAllButton, SIGNAL(clicked()), m_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_exceptionsWidget->exceptionTable->verticalHeader()->hide(); + m_exceptionsWidget->exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); + m_exceptionsWidget->exceptionTable->setAlternatingRowColors(true); + m_exceptionsWidget->exceptionTable->setTextElideMode(Qt::ElideMiddle); + m_exceptionsWidget->exceptionTable->setShowGrid(false); + m_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))); + connect(m_exceptionsWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); - exceptionsWidget->exceptionTable->setModel(m_proxyModel); + m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); CookieModel *cookieModel = new CookieModel(cookieJar, this); - exceptionsWidget->domainLineEdit->setCompleter(new QCompleter(cookieModel, exceptionsWidget->domainLineEdit)); + m_exceptionsWidget->domainLineEdit->setCompleter(new QCompleter(cookieModel, m_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())); + connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); + connect(m_exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); + connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); + connect(m_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); + m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); + m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) { - int header = exceptionsWidget->exceptionTable->horizontalHeader()->sectionSizeHint(i); + int header = m_exceptionsWidget->exceptionTable->horizontalHeader()->sectionSizeHint(i); switch (i) { case 0: @@ -149,7 +155,7 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * } int buffer = fm.width(QLatin1String("xx")); header += buffer; - exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); + m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); } } @@ -157,17 +163,17 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * void CookiesExceptionsDialog::textChanged(const QString &text) { bool enabled = !text.isEmpty(); - exceptionsWidget->blockButton->setEnabled(enabled); - exceptionsWidget->allowButton->setEnabled(enabled); - exceptionsWidget->allowForSessionButton->setEnabled(enabled); + m_exceptionsWidget->blockButton->setEnabled(enabled); + m_exceptionsWidget->allowButton->setEnabled(enabled); + m_exceptionsWidget->allowForSessionButton->setEnabled(enabled); } void CookiesExceptionsDialog::block() { - if (exceptionsWidget->domainLineEdit->text().isEmpty()) + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) return; - m_exceptionsModel->m_blockedCookies.append(exceptionsWidget->domainLineEdit->text()); + m_exceptionsModel->m_blockedCookies.append(m_exceptionsWidget->domainLineEdit->text()); m_cookieJar->setBlockedCookies(m_exceptionsModel->m_blockedCookies); m_exceptionsModel->reset(); } @@ -175,9 +181,9 @@ void CookiesExceptionsDialog::block() void CookiesExceptionsDialog::allow() { - if (exceptionsWidget->domainLineEdit->text().isEmpty()) + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) return; - m_exceptionsModel->m_allowedCookies.append(exceptionsWidget->domainLineEdit->text()); + m_exceptionsModel->m_allowedCookies.append(m_exceptionsWidget->domainLineEdit->text()); m_cookieJar->setAllowedCookies(m_exceptionsModel->m_allowedCookies); m_exceptionsModel->reset(); } @@ -185,9 +191,9 @@ void CookiesExceptionsDialog::allow() void CookiesExceptionsDialog::allowForSession() { - if (exceptionsWidget->domainLineEdit->text().isEmpty()) + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) return; - m_exceptionsModel->m_sessionCookies.append(exceptionsWidget->domainLineEdit->text()); + m_exceptionsModel->m_sessionCookies.append(m_exceptionsWidget->domainLineEdit->text()); m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies); m_exceptionsModel->reset(); } diff --git a/src/cookiedialogs.h b/src/cookiedialogs.h index 9f1a69df..4331ae83 100644 --- a/src/cookiedialogs.h +++ b/src/cookiedialogs.h @@ -77,7 +77,7 @@ private: QSortFilterProxyModel *m_proxyModel; CookieJar *m_cookieJar; - Ui::CookiesExceptionsWidget *exceptionsWidget; + Ui::CookiesExceptionsWidget *m_exceptionsWidget; }; -- cgit v1.2.1 From 9169bb7a80bb9e3e443b6baaeb6e18794d287fa5 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 18 May 2009 12:03:25 +0200 Subject: (hopefully) last Ui fixes --- src/cookiedialogs.cpp | 4 +- src/cookies.ui | 8 ++- src/cookiesexceptions.ui | 146 ++++++++++++++++++++++++++--------------------- 3 files changed, 89 insertions(+), 69 deletions(-) diff --git a/src/cookiedialogs.cpp b/src/cookiedialogs.cpp index b4e043aa..3b918c8b 100644 --- a/src/cookiedialogs.cpp +++ b/src/cookiedialogs.cpp @@ -127,8 +127,8 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); - CookieModel *cookieModel = new CookieModel(cookieJar, this); - m_exceptionsWidget->domainLineEdit->setCompleter(new QCompleter(cookieModel, m_exceptionsWidget->domainLineEdit)); +// CookieModel *cookieModel = new CookieModel(cookieJar, this); +// m_exceptionsWidget->domainLineEdit->setCompleter(new QCompleter(cookieModel, m_exceptionsWidget->domainLineEdit)); connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); connect(m_exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); diff --git a/src/cookies.ui b/src/cookies.ui index 8c9abc55..16e0f4ea 100644 --- a/src/cookies.ui +++ b/src/cookies.ui @@ -1,7 +1,7 @@ CookiesWidget - + 0 @@ -46,7 +46,11 @@ - + + + true + + diff --git a/src/cookiesexceptions.ui b/src/cookiesexceptions.ui index ef8d0705..b4ce54a0 100644 --- a/src/cookiesexceptions.ui +++ b/src/cookiesexceptions.ui @@ -1,19 +1,19 @@ CookiesExceptionsWidget - + 0 0 - 457 - 495 + 377 + 405 Form - + @@ -30,7 +30,11 @@ - + + + true + + @@ -89,68 +93,80 @@ Exceptions - - - - - - - - &Remove - - - - - - - Remove &All - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 40 - 20 - - - + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Search: + + + + + + + true + + + + - - - - - 0 - 0 - - - - Search: - - + + - - + + + + + + &Remove + + + + + + + Remove &All + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + -- cgit v1.2.1 From 8a32ca569530f51b69602d3209f43d9c81635592 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 19 May 2009 12:14:51 +0200 Subject: removed unuseful comments --- src/cookiedialogs.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/cookiedialogs.cpp b/src/cookiedialogs.cpp index 3b918c8b..1d120666 100644 --- a/src/cookiedialogs.cpp +++ b/src/cookiedialogs.cpp @@ -28,9 +28,6 @@ // Local Includes #include "cookiejar.h" -// Qt Includes -#include - CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) : KDialog(parent) @@ -127,9 +124,6 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); -// CookieModel *cookieModel = new CookieModel(cookieJar, this); -// m_exceptionsWidget->domainLineEdit->setCompleter(new QCompleter(cookieModel, m_exceptionsWidget->domainLineEdit)); - connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); connect(m_exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); -- cgit v1.2.1 From d0ecd4c042b81f0eb732a6702f9d1a83d6f4144e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 19 May 2009 12:29:32 +0200 Subject: Cookie System Refactoring. Step 1.. --- src/cookiedialog.cpp | 218 +++++++++++++++++++++++++++++++++ src/cookiedialog.h | 81 +++++++++++++ src/cookiedialogs.cpp | 193 ------------------------------ src/cookiedialogs.h | 84 ------------- src/cookieexcaptiondialog.cpp | 271 ++++++++++++++++++++++++++++++++++++++++++ src/cookieexcaptiondialog.h | 89 ++++++++++++++ src/cookiejar.cpp | 271 ------------------------------------------ src/cookiejar.h | 61 ---------- 8 files changed, 659 insertions(+), 609 deletions(-) create mode 100644 src/cookiedialog.cpp create mode 100644 src/cookiedialog.h delete mode 100644 src/cookiedialogs.cpp delete mode 100644 src/cookiedialogs.h create mode 100644 src/cookieexcaptiondialog.cpp create mode 100644 src/cookieexcaptiondialog.h diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp new file mode 100644 index 00000000..1628a0c6 --- /dev/null +++ b/src/cookiedialog.cpp @@ -0,0 +1,218 @@ +/* ============================================================ +* +* 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. +* +* ============================================================ */ + + +// Self Includes +#include "cookiedialog.h" +#include "cookiedialog.moc" + +// Local Includes +#include "cookiejar.h" + + +CookieModel::CookieModel(CookieJar *cookieJar, QObject *parent) + : QAbstractTableModel(parent) + , m_cookieJar(cookieJar) +{ + connect(m_cookieJar, SIGNAL(cookiesChanged()), this, SLOT(cookiesChanged())); + m_cookieJar->load(); +} + + +QVariant CookieModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::SizeHintRole) + { + QFont font; + font.setPointSize(10); + QFontMetrics fm(font); + int height = fm.height() + fm.height() / 3; + int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString()); + return QSize(width, height); + } + + if (orientation == Qt::Horizontal) + { + if (role != Qt::DisplayRole) + return QVariant(); + + switch (section) + { + case 0: + return i18n("Website"); + case 1: + return i18n("Name"); + case 2: + return i18n("Path"); + case 3: + return i18n("Secure"); + case 4: + return i18n("Expires"); + case 5: + return i18n("Contents"); + default: + return QVariant(); + } + } + return QAbstractTableModel::headerData(section, orientation, role); +} + + +QVariant CookieModel::data(const QModelIndex &index, int role) const +{ + QList lst; + if (m_cookieJar) + lst = m_cookieJar->allCookies(); + if (index.row() < 0 || index.row() >= lst.size()) + return QVariant(); + + switch (role) + { + case Qt::DisplayRole: + case Qt::EditRole: + { + QNetworkCookie cookie = lst.at(index.row()); + switch (index.column()) + { + case 0: + return cookie.domain(); + case 1: + return cookie.name(); + case 2: + return cookie.path(); + case 3: + return cookie.isSecure(); + case 4: + return cookie.expirationDate(); + case 5: + return cookie.value(); + } + } + case Qt::FontRole: + { + QFont font; + font.setPointSize(10); + return font; + } + } + + return QVariant(); +} + + +int CookieModel::columnCount(const QModelIndex &parent) const +{ + return (parent.isValid()) ? 0 : 6; +} + + +int CookieModel::rowCount(const QModelIndex &parent) const +{ + return (parent.isValid() || !m_cookieJar) ? 0 : m_cookieJar->allCookies().count(); +} + + +bool CookieModel::removeRows(int row, int count, const QModelIndex &parent) +{ + if (parent.isValid() || !m_cookieJar) + return false; + int lastRow = row + count - 1; + beginRemoveRows(parent, row, lastRow); + QList lst = m_cookieJar->allCookies(); + for (int i = lastRow; i >= row; --i) + { + lst.removeAt(i); + } + m_cookieJar->setAllCookies(lst); + endRemoveRows(); + return true; +} + + +void CookieModel::cookiesChanged() +{ + reset(); +} + + +// --------------------------------------------------------------------------------------- + + +// Ui Includes +#include "ui_cookies.h" + + +CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) + : KDialog(parent) +{ + setWindowFlags(Qt::Sheet); + setCaption("Cookies"); + setButtons( KDialog::Ok ); + + Ui::CookiesWidget *cookieWidget = new Ui::CookiesWidget; + QWidget *widget = new QWidget(this); + cookieWidget->setupUi(widget); + setMainWidget(widget); + + 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); +} diff --git a/src/cookiedialog.h b/src/cookiedialog.h new file mode 100644 index 00000000..be8b9236 --- /dev/null +++ b/src/cookiedialog.h @@ -0,0 +1,81 @@ +/* ============================================================ +* +* 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 COOKIEDIALOG_H +#define COOKIEDIALOG_H + + +// KDE Includes +#include + + +// Qt Includes +#include +#include + +#include +#include + +#include + + +// Forward Declarations +class CookieJar; +class CookieExceptionsModel; + + +class CookieModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + explicit CookieModel(CookieJar *jar, QObject *parent = 0); + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + +private slots: + void cookiesChanged(); + +private: + CookieJar *m_cookieJar; +}; + + + +// ----------------------------------------------------------------------------------------------------------------- + + +class CookiesDialog : public KDialog +{ + Q_OBJECT + +public: + explicit CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0); + +private: + QSortFilterProxyModel *m_proxyModel; +}; + +#endif diff --git a/src/cookiedialogs.cpp b/src/cookiedialogs.cpp deleted file mode 100644 index 1d120666..00000000 --- a/src/cookiedialogs.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* ============================================================ -* -* 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. -* -* ============================================================ */ - - -// Self Includes -#include "cookiedialogs.h" -#include "cookiedialogs.moc" - -// Ui Includes -#include "ui_cookies.h" - -// Local Includes -#include "cookiejar.h" - - -CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) - : KDialog(parent) -{ - setCaption("Cookies"); - setButtons( KDialog::Ok ); - - Ui::CookiesWidget *cookieWidget = new Ui::CookiesWidget; - QWidget *widget = new QWidget(this); - 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) - , m_exceptionsWidget(new Ui::CookiesExceptionsWidget) -{ - setCaption("Cookies Exceptions"); - setButtons( KDialog::Ok ); - - QWidget *widget = new QWidget(this); - m_exceptionsWidget->setupUi(widget); - setMainWidget(widget); - - setWindowFlags(Qt::Sheet); - - connect(m_exceptionsWidget->removeButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeOne())); - connect(m_exceptionsWidget->removeAllButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeAll())); - - m_exceptionsWidget->exceptionTable->verticalHeader()->hide(); - m_exceptionsWidget->exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); - m_exceptionsWidget->exceptionTable->setAlternatingRowColors(true); - m_exceptionsWidget->exceptionTable->setTextElideMode(Qt::ElideMiddle); - m_exceptionsWidget->exceptionTable->setShowGrid(false); - m_exceptionsWidget->exceptionTable->setSortingEnabled(true); - m_exceptionsModel = new CookieExceptionsModel(cookieJar, this); - m_proxyModel = new QSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_exceptionsModel); - - connect(m_exceptionsWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); - - m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); - - connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); - connect(m_exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); - connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); - connect(m_exceptionsWidget->allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); - - QFont f = font(); - f.setPointSize(10); - QFontMetrics fm(f); - int height = fm.height() + fm.height() / 3; - m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); - m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); - for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) - { - int header = m_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; - m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); - } -} - - -void CookiesExceptionsDialog::textChanged(const QString &text) -{ - bool enabled = !text.isEmpty(); - m_exceptionsWidget->blockButton->setEnabled(enabled); - m_exceptionsWidget->allowButton->setEnabled(enabled); - m_exceptionsWidget->allowForSessionButton->setEnabled(enabled); -} - - -void CookiesExceptionsDialog::block() -{ - if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_blockedCookies.append(m_exceptionsWidget->domainLineEdit->text()); - m_cookieJar->setBlockedCookies(m_exceptionsModel->m_blockedCookies); - m_exceptionsModel->reset(); -} - - -void CookiesExceptionsDialog::allow() -{ - if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_allowedCookies.append(m_exceptionsWidget->domainLineEdit->text()); - m_cookieJar->setAllowedCookies(m_exceptionsModel->m_allowedCookies); - m_exceptionsModel->reset(); -} - - -void CookiesExceptionsDialog::allowForSession() -{ - if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_sessionCookies.append(m_exceptionsWidget->domainLineEdit->text()); - m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies); - m_exceptionsModel->reset(); -} diff --git a/src/cookiedialogs.h b/src/cookiedialogs.h deleted file mode 100644 index 4331ae83..00000000 --- a/src/cookiedialogs.h +++ /dev/null @@ -1,84 +0,0 @@ -/* ============================================================ -* -* 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 - - -// KDE Includes -#include - -// Qt Includes -#include -#include - -#include -#include - -#include - -// Forward Declarations -class CookieJar; -class CookieExceptionsModel; - - -class CookiesDialog : public KDialog -{ - Q_OBJECT - -public: - explicit CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0); - -private: - QSortFilterProxyModel *m_proxyModel; -}; - - -// ----------------------------------------------------------------------------------------------------------------- - - -// Ui Includes -#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 *m_exceptionsWidget; -}; - - -#endif diff --git a/src/cookieexcaptiondialog.cpp b/src/cookieexcaptiondialog.cpp new file mode 100644 index 00000000..c349c885 --- /dev/null +++ b/src/cookieexcaptiondialog.cpp @@ -0,0 +1,271 @@ +/* ============================================================ +* +* 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. +* +* ============================================================ */ + + +// Self Includes +#include "cookieexceptiondialog.h" +#include "cookieexceptiondialog.moc" + +// Local Includes + + + +CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent) + : QAbstractTableModel(parent) + , m_cookieJar(cookiejar) +{ + m_allowedCookies = m_cookieJar->allowedCookies(); + m_blockedCookies = m_cookieJar->blockedCookies(); + m_sessionCookies = m_cookieJar->allowForSessionCookies(); +} + + +QVariant CookieExceptionsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::SizeHintRole) + { + QFont font; + font.setPointSize(10); + QFontMetrics fm(font); + int height = fm.height() + fm.height() / 3; + int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString()); + return QSize(width, height); + } + + if (orientation == Qt::Horizontal + && role == Qt::DisplayRole) + { + switch (section) + { + case 0: + return i18n("Website"); + case 1: + return i18n("Status"); + } + } + return QAbstractTableModel::headerData(section, orientation, role); +} + + +QVariant CookieExceptionsModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < 0 || index.row() >= rowCount()) + return QVariant(); + + switch (role) + { + case Qt::DisplayRole: + case Qt::EditRole: + { + int row = index.row(); + if (row < m_allowedCookies.count()) + { + switch (index.column()) + { + case 0: + return m_allowedCookies.at(row); + case 1: + return i18n("Allow"); + } + } + row = row - m_allowedCookies.count(); + if (row < m_blockedCookies.count()) + { + switch (index.column()) + { + case 0: + return m_blockedCookies.at(row); + case 1: + return i18n("Block"); + } + } + row = row - m_blockedCookies.count(); + if (row < m_sessionCookies.count()) + { + switch (index.column()) + { + case 0: + return m_sessionCookies.at(row); + case 1: + return i18n("Allow For Session"); + } + } + } + case Qt::FontRole: + { + QFont font; + font.setPointSize(10); + return font; + } + } + return QVariant(); +} + + +int CookieExceptionsModel::columnCount(const QModelIndex &parent) const +{ + return (parent.isValid()) ? 0 : 2; +} + + +int CookieExceptionsModel::rowCount(const QModelIndex &parent) const +{ + return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.count() + m_blockedCookies.count() + m_sessionCookies.count(); +} + + +bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &parent) +{ + if (parent.isValid() || !m_cookieJar) + return false; + + int lastRow = row + count - 1; + beginRemoveRows(parent, row, lastRow); + for (int i = lastRow; i >= row; --i) + { + if (i < m_allowedCookies.count()) + { + m_allowedCookies.removeAt(row); + continue; + } + i = i - m_allowedCookies.count(); + if (i < m_blockedCookies.count()) + { + m_blockedCookies.removeAt(row); + continue; + } + i = i - m_blockedCookies.count(); + if (i < m_sessionCookies.count()) + { + m_sessionCookies.removeAt(row); + continue; + } + } + m_cookieJar->setAllowedCookies(m_allowedCookies); + m_cookieJar->setBlockedCookies(m_blockedCookies); + m_cookieJar->setAllowForSessionCookies(m_sessionCookies); + endRemoveRows(); + return true; +} + + + + +// ---------------------------------------------------------------------------------------------------------------- + + +CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) + : KDialog(parent) + , m_cookieJar(cookieJar) + , m_exceptionsWidget(new Ui::CookiesExceptionsWidget) +{ + setCaption("Cookies Exceptions"); + setButtons( KDialog::Ok ); + + QWidget *widget = new QWidget(this); + m_exceptionsWidget->setupUi(widget); + setMainWidget(widget); + + setWindowFlags(Qt::Sheet); + + connect(m_exceptionsWidget->removeButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeOne())); + connect(m_exceptionsWidget->removeAllButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeAll())); + + m_exceptionsWidget->exceptionTable->verticalHeader()->hide(); + m_exceptionsWidget->exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); + m_exceptionsWidget->exceptionTable->setAlternatingRowColors(true); + m_exceptionsWidget->exceptionTable->setTextElideMode(Qt::ElideMiddle); + m_exceptionsWidget->exceptionTable->setShowGrid(false); + m_exceptionsWidget->exceptionTable->setSortingEnabled(true); + m_exceptionsModel = new CookieExceptionsModel(cookieJar, this); + m_proxyModel = new QSortFilterProxyModel(this); + m_proxyModel->setSourceModel(m_exceptionsModel); + + connect(m_exceptionsWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); + + m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); + + connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); + connect(m_exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); + connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); + connect(m_exceptionsWidget->allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); + + QFont f = font(); + f.setPointSize(10); + QFontMetrics fm(f); + int height = fm.height() + fm.height() / 3; + m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); + m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); + for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) + { + int header = m_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; + m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); + } +} + + +void CookiesExceptionsDialog::textChanged(const QString &text) +{ + bool enabled = !text.isEmpty(); + m_exceptionsWidget->blockButton->setEnabled(enabled); + m_exceptionsWidget->allowButton->setEnabled(enabled); + m_exceptionsWidget->allowForSessionButton->setEnabled(enabled); +} + + +void CookiesExceptionsDialog::block() +{ + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_blockedCookies.append(m_exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setBlockedCookies(m_exceptionsModel->m_blockedCookies); + m_exceptionsModel->reset(); +} + + +void CookiesExceptionsDialog::allow() +{ + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_allowedCookies.append(m_exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setAllowedCookies(m_exceptionsModel->m_allowedCookies); + m_exceptionsModel->reset(); +} + + +void CookiesExceptionsDialog::allowForSession() +{ + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_sessionCookies.append(m_exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies); + m_exceptionsModel->reset(); +} + diff --git a/src/cookieexcaptiondialog.h b/src/cookieexcaptiondialog.h new file mode 100644 index 00000000..f68c119e --- /dev/null +++ b/src/cookieexcaptiondialog.h @@ -0,0 +1,89 @@ +/* ============================================================ +* +* 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 COOKIEEXCEPTIONDIALOG_H +#define COOKIEEXCEPTIONDIALOG_H + +// Qt Includes +#include + +// Forward Declarations +class CookieJar; +class QString; +class QStringList; +class QModelIndex; +class QVariant; + +class CookieExceptionsModel : public QAbstractTableModel +{ + Q_OBJECT + friend class CookiesExceptionsDialog; + +public: + explicit CookieExceptionsModel(CookieJar *cookieJar, QObject *parent = 0); + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + +private: + CookieJar *m_cookieJar; + + // Domains we allow, Domains we block, Domains we allow for this session + QStringList m_allowedCookies; + QStringList m_blockedCookies; + QStringList m_sessionCookies; +}; + + +// ----------------------------------------------------------------------------------------------- + + +// Ui Includes +#include "ui_cookiesexceptions.h" + +//Forward Declarations +class QSortFilterProxyModel; + + +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 *m_exceptionsWidget; +}; + +#endif diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp index 99399471..1b0c0051 100644 --- a/src/cookiejar.cpp +++ b/src/cookiejar.cpp @@ -425,274 +425,3 @@ void CookieJar::setAllowForSessionCookies(const QStringList &list) qSort(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end()); m_saveTimer->changeOccurred(); } - - -// ------------------------------------------------------------------------------------------- - - -CookieModel::CookieModel(CookieJar *cookieJar, QObject *parent) - : QAbstractTableModel(parent) - , m_cookieJar(cookieJar) -{ - connect(m_cookieJar, SIGNAL(cookiesChanged()), this, SLOT(cookiesChanged())); - m_cookieJar->load(); -} - - -QVariant CookieModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role == Qt::SizeHintRole) - { - QFont font; - font.setPointSize(10); - QFontMetrics fm(font); - int height = fm.height() + fm.height() / 3; - int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString()); - return QSize(width, height); - } - - if (orientation == Qt::Horizontal) - { - if (role != Qt::DisplayRole) - return QVariant(); - - switch (section) - { - case 0: - return i18n("Website"); - case 1: - return i18n("Name"); - case 2: - return i18n("Path"); - case 3: - return i18n("Secure"); - case 4: - return i18n("Expires"); - case 5: - return i18n("Contents"); - default: - return QVariant(); - } - } - return QAbstractTableModel::headerData(section, orientation, role); -} - - -QVariant CookieModel::data(const QModelIndex &index, int role) const -{ - QList lst; - if (m_cookieJar) - lst = m_cookieJar->allCookies(); - if (index.row() < 0 || index.row() >= lst.size()) - return QVariant(); - - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - { - QNetworkCookie cookie = lst.at(index.row()); - switch (index.column()) - { - case 0: - return cookie.domain(); - case 1: - return cookie.name(); - case 2: - return cookie.path(); - case 3: - return cookie.isSecure(); - case 4: - return cookie.expirationDate(); - case 5: - return cookie.value(); - } - } - case Qt::FontRole: - { - QFont font; - font.setPointSize(10); - return font; - } - } - - return QVariant(); -} - - -int CookieModel::columnCount(const QModelIndex &parent) const -{ - return (parent.isValid()) ? 0 : 6; -} - - -int CookieModel::rowCount(const QModelIndex &parent) const -{ - return (parent.isValid() || !m_cookieJar) ? 0 : m_cookieJar->allCookies().count(); -} - - -bool CookieModel::removeRows(int row, int count, const QModelIndex &parent) -{ - if (parent.isValid() || !m_cookieJar) - return false; - int lastRow = row + count - 1; - beginRemoveRows(parent, row, lastRow); - QList lst = m_cookieJar->allCookies(); - for (int i = lastRow; i >= row; --i) - { - lst.removeAt(i); - } - m_cookieJar->setAllCookies(lst); - endRemoveRows(); - return true; -} - - -void CookieModel::cookiesChanged() -{ - reset(); -} - - - -// ------------------------------------------------------------------------------------------------ - - -CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent) - : QAbstractTableModel(parent) - , m_cookieJar(cookiejar) -{ - m_allowedCookies = m_cookieJar->allowedCookies(); - m_blockedCookies = m_cookieJar->blockedCookies(); - m_sessionCookies = m_cookieJar->allowForSessionCookies(); -} - - -QVariant CookieExceptionsModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role == Qt::SizeHintRole) - { - QFont font; - font.setPointSize(10); - QFontMetrics fm(font); - int height = fm.height() + fm.height() / 3; - int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString()); - return QSize(width, height); - } - - if (orientation == Qt::Horizontal - && role == Qt::DisplayRole) - { - switch (section) - { - case 0: - return i18n("Website"); - case 1: - return i18n("Status"); - } - } - return QAbstractTableModel::headerData(section, orientation, role); -} - - -QVariant CookieExceptionsModel::data(const QModelIndex &index, int role) const -{ - if (index.row() < 0 || index.row() >= rowCount()) - return QVariant(); - - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - { - int row = index.row(); - if (row < m_allowedCookies.count()) - { - switch (index.column()) - { - case 0: - return m_allowedCookies.at(row); - case 1: - return i18n("Allow"); - } - } - row = row - m_allowedCookies.count(); - if (row < m_blockedCookies.count()) - { - switch (index.column()) - { - case 0: - return m_blockedCookies.at(row); - case 1: - return i18n("Block"); - } - } - row = row - m_blockedCookies.count(); - if (row < m_sessionCookies.count()) - { - switch (index.column()) - { - case 0: - return m_sessionCookies.at(row); - case 1: - return i18n("Allow For Session"); - } - } - } - case Qt::FontRole: - { - QFont font; - font.setPointSize(10); - return font; - } - } - return QVariant(); -} - - -int CookieExceptionsModel::columnCount(const QModelIndex &parent) const -{ - return (parent.isValid()) ? 0 : 2; -} - - -int CookieExceptionsModel::rowCount(const QModelIndex &parent) const -{ - return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.count() + m_blockedCookies.count() + m_sessionCookies.count(); -} - - -bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &parent) -{ - if (parent.isValid() || !m_cookieJar) - return false; - - int lastRow = row + count - 1; - beginRemoveRows(parent, row, lastRow); - for (int i = lastRow; i >= row; --i) - { - if (i < m_allowedCookies.count()) - { - m_allowedCookies.removeAt(row); - continue; - } - i = i - m_allowedCookies.count(); - if (i < m_blockedCookies.count()) - { - m_blockedCookies.removeAt(row); - continue; - } - i = i - m_blockedCookies.count(); - if (i < m_sessionCookies.count()) - { - m_sessionCookies.removeAt(row); - continue; - } - } - m_cookieJar->setAllowedCookies(m_allowedCookies); - m_cookieJar->setBlockedCookies(m_blockedCookies); - m_cookieJar->setAllowForSessionCookies(m_sessionCookies); - endRemoveRows(); - return true; -} diff --git a/src/cookiejar.h b/src/cookiejar.h index 81d3ce64..4d60d658 100644 --- a/src/cookiejar.h +++ b/src/cookiejar.h @@ -24,20 +24,11 @@ #define COOKIEJAR_H -// Local Includes -#include "cookiedialogs.h" - // Qt Includes #include -#include -#include #include - - // Forward Declarations -class QSortFilterProxyModel; -class QKeyEvent; class AutoSaver; class QUrl; @@ -113,56 +104,4 @@ private: QStringList m_exceptions_allowForSession; }; - -// ------------------------------------------------------------------------------------------------------------- - - -class CookieModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - explicit CookieModel(CookieJar *jar, QObject *parent = 0); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - -private slots: - void cookiesChanged(); - -private: - CookieJar *m_cookieJar; -}; - - -// ---------------------------------------------------------------------------------------------------------------------- - - -class CookieExceptionsModel : public QAbstractTableModel -{ - Q_OBJECT - friend class CookiesExceptionsDialog; - -public: - explicit CookieExceptionsModel(CookieJar *cookieJar, QObject *parent = 0); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - -private: - CookieJar *m_cookieJar; - - // Domains we allow, Domains we block, Domains we allow for this session - QStringList m_allowedCookies; - QStringList m_blockedCookies; - QStringList m_sessionCookies; -}; - - #endif // COOKIEJAR_H -- cgit v1.2.1 From 23e5d302cbd90580a1b70718bf079ab54b2eca03 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 19 May 2009 12:31:12 +0200 Subject: wrong file name.. --- src/cookieexcaptiondialog.cpp | 271 ------------------------------------------ src/cookieexcaptiondialog.h | 89 -------------- src/cookieexceptiondialog.cpp | 271 ++++++++++++++++++++++++++++++++++++++++++ src/cookieexceptiondialog.h | 89 ++++++++++++++ 4 files changed, 360 insertions(+), 360 deletions(-) delete mode 100644 src/cookieexcaptiondialog.cpp delete mode 100644 src/cookieexcaptiondialog.h create mode 100644 src/cookieexceptiondialog.cpp create mode 100644 src/cookieexceptiondialog.h diff --git a/src/cookieexcaptiondialog.cpp b/src/cookieexcaptiondialog.cpp deleted file mode 100644 index c349c885..00000000 --- a/src/cookieexcaptiondialog.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* ============================================================ -* -* 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. -* -* ============================================================ */ - - -// Self Includes -#include "cookieexceptiondialog.h" -#include "cookieexceptiondialog.moc" - -// Local Includes - - - -CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent) - : QAbstractTableModel(parent) - , m_cookieJar(cookiejar) -{ - m_allowedCookies = m_cookieJar->allowedCookies(); - m_blockedCookies = m_cookieJar->blockedCookies(); - m_sessionCookies = m_cookieJar->allowForSessionCookies(); -} - - -QVariant CookieExceptionsModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role == Qt::SizeHintRole) - { - QFont font; - font.setPointSize(10); - QFontMetrics fm(font); - int height = fm.height() + fm.height() / 3; - int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString()); - return QSize(width, height); - } - - if (orientation == Qt::Horizontal - && role == Qt::DisplayRole) - { - switch (section) - { - case 0: - return i18n("Website"); - case 1: - return i18n("Status"); - } - } - return QAbstractTableModel::headerData(section, orientation, role); -} - - -QVariant CookieExceptionsModel::data(const QModelIndex &index, int role) const -{ - if (index.row() < 0 || index.row() >= rowCount()) - return QVariant(); - - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - { - int row = index.row(); - if (row < m_allowedCookies.count()) - { - switch (index.column()) - { - case 0: - return m_allowedCookies.at(row); - case 1: - return i18n("Allow"); - } - } - row = row - m_allowedCookies.count(); - if (row < m_blockedCookies.count()) - { - switch (index.column()) - { - case 0: - return m_blockedCookies.at(row); - case 1: - return i18n("Block"); - } - } - row = row - m_blockedCookies.count(); - if (row < m_sessionCookies.count()) - { - switch (index.column()) - { - case 0: - return m_sessionCookies.at(row); - case 1: - return i18n("Allow For Session"); - } - } - } - case Qt::FontRole: - { - QFont font; - font.setPointSize(10); - return font; - } - } - return QVariant(); -} - - -int CookieExceptionsModel::columnCount(const QModelIndex &parent) const -{ - return (parent.isValid()) ? 0 : 2; -} - - -int CookieExceptionsModel::rowCount(const QModelIndex &parent) const -{ - return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.count() + m_blockedCookies.count() + m_sessionCookies.count(); -} - - -bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &parent) -{ - if (parent.isValid() || !m_cookieJar) - return false; - - int lastRow = row + count - 1; - beginRemoveRows(parent, row, lastRow); - for (int i = lastRow; i >= row; --i) - { - if (i < m_allowedCookies.count()) - { - m_allowedCookies.removeAt(row); - continue; - } - i = i - m_allowedCookies.count(); - if (i < m_blockedCookies.count()) - { - m_blockedCookies.removeAt(row); - continue; - } - i = i - m_blockedCookies.count(); - if (i < m_sessionCookies.count()) - { - m_sessionCookies.removeAt(row); - continue; - } - } - m_cookieJar->setAllowedCookies(m_allowedCookies); - m_cookieJar->setBlockedCookies(m_blockedCookies); - m_cookieJar->setAllowForSessionCookies(m_sessionCookies); - endRemoveRows(); - return true; -} - - - - -// ---------------------------------------------------------------------------------------------------------------- - - -CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) - : KDialog(parent) - , m_cookieJar(cookieJar) - , m_exceptionsWidget(new Ui::CookiesExceptionsWidget) -{ - setCaption("Cookies Exceptions"); - setButtons( KDialog::Ok ); - - QWidget *widget = new QWidget(this); - m_exceptionsWidget->setupUi(widget); - setMainWidget(widget); - - setWindowFlags(Qt::Sheet); - - connect(m_exceptionsWidget->removeButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeOne())); - connect(m_exceptionsWidget->removeAllButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeAll())); - - m_exceptionsWidget->exceptionTable->verticalHeader()->hide(); - m_exceptionsWidget->exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); - m_exceptionsWidget->exceptionTable->setAlternatingRowColors(true); - m_exceptionsWidget->exceptionTable->setTextElideMode(Qt::ElideMiddle); - m_exceptionsWidget->exceptionTable->setShowGrid(false); - m_exceptionsWidget->exceptionTable->setSortingEnabled(true); - m_exceptionsModel = new CookieExceptionsModel(cookieJar, this); - m_proxyModel = new QSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_exceptionsModel); - - connect(m_exceptionsWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); - - m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); - - connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); - connect(m_exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); - connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); - connect(m_exceptionsWidget->allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); - - QFont f = font(); - f.setPointSize(10); - QFontMetrics fm(f); - int height = fm.height() + fm.height() / 3; - m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); - m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); - for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) - { - int header = m_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; - m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); - } -} - - -void CookiesExceptionsDialog::textChanged(const QString &text) -{ - bool enabled = !text.isEmpty(); - m_exceptionsWidget->blockButton->setEnabled(enabled); - m_exceptionsWidget->allowButton->setEnabled(enabled); - m_exceptionsWidget->allowForSessionButton->setEnabled(enabled); -} - - -void CookiesExceptionsDialog::block() -{ - if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_blockedCookies.append(m_exceptionsWidget->domainLineEdit->text()); - m_cookieJar->setBlockedCookies(m_exceptionsModel->m_blockedCookies); - m_exceptionsModel->reset(); -} - - -void CookiesExceptionsDialog::allow() -{ - if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_allowedCookies.append(m_exceptionsWidget->domainLineEdit->text()); - m_cookieJar->setAllowedCookies(m_exceptionsModel->m_allowedCookies); - m_exceptionsModel->reset(); -} - - -void CookiesExceptionsDialog::allowForSession() -{ - if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) - return; - m_exceptionsModel->m_sessionCookies.append(m_exceptionsWidget->domainLineEdit->text()); - m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies); - m_exceptionsModel->reset(); -} - diff --git a/src/cookieexcaptiondialog.h b/src/cookieexcaptiondialog.h deleted file mode 100644 index f68c119e..00000000 --- a/src/cookieexcaptiondialog.h +++ /dev/null @@ -1,89 +0,0 @@ -/* ============================================================ -* -* 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 COOKIEEXCEPTIONDIALOG_H -#define COOKIEEXCEPTIONDIALOG_H - -// Qt Includes -#include - -// Forward Declarations -class CookieJar; -class QString; -class QStringList; -class QModelIndex; -class QVariant; - -class CookieExceptionsModel : public QAbstractTableModel -{ - Q_OBJECT - friend class CookiesExceptionsDialog; - -public: - explicit CookieExceptionsModel(CookieJar *cookieJar, QObject *parent = 0); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - -private: - CookieJar *m_cookieJar; - - // Domains we allow, Domains we block, Domains we allow for this session - QStringList m_allowedCookies; - QStringList m_blockedCookies; - QStringList m_sessionCookies; -}; - - -// ----------------------------------------------------------------------------------------------- - - -// Ui Includes -#include "ui_cookiesexceptions.h" - -//Forward Declarations -class QSortFilterProxyModel; - - -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 *m_exceptionsWidget; -}; - -#endif diff --git a/src/cookieexceptiondialog.cpp b/src/cookieexceptiondialog.cpp new file mode 100644 index 00000000..c349c885 --- /dev/null +++ b/src/cookieexceptiondialog.cpp @@ -0,0 +1,271 @@ +/* ============================================================ +* +* 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. +* +* ============================================================ */ + + +// Self Includes +#include "cookieexceptiondialog.h" +#include "cookieexceptiondialog.moc" + +// Local Includes + + + +CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent) + : QAbstractTableModel(parent) + , m_cookieJar(cookiejar) +{ + m_allowedCookies = m_cookieJar->allowedCookies(); + m_blockedCookies = m_cookieJar->blockedCookies(); + m_sessionCookies = m_cookieJar->allowForSessionCookies(); +} + + +QVariant CookieExceptionsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::SizeHintRole) + { + QFont font; + font.setPointSize(10); + QFontMetrics fm(font); + int height = fm.height() + fm.height() / 3; + int width = fm.width(headerData(section, orientation, Qt::DisplayRole).toString()); + return QSize(width, height); + } + + if (orientation == Qt::Horizontal + && role == Qt::DisplayRole) + { + switch (section) + { + case 0: + return i18n("Website"); + case 1: + return i18n("Status"); + } + } + return QAbstractTableModel::headerData(section, orientation, role); +} + + +QVariant CookieExceptionsModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < 0 || index.row() >= rowCount()) + return QVariant(); + + switch (role) + { + case Qt::DisplayRole: + case Qt::EditRole: + { + int row = index.row(); + if (row < m_allowedCookies.count()) + { + switch (index.column()) + { + case 0: + return m_allowedCookies.at(row); + case 1: + return i18n("Allow"); + } + } + row = row - m_allowedCookies.count(); + if (row < m_blockedCookies.count()) + { + switch (index.column()) + { + case 0: + return m_blockedCookies.at(row); + case 1: + return i18n("Block"); + } + } + row = row - m_blockedCookies.count(); + if (row < m_sessionCookies.count()) + { + switch (index.column()) + { + case 0: + return m_sessionCookies.at(row); + case 1: + return i18n("Allow For Session"); + } + } + } + case Qt::FontRole: + { + QFont font; + font.setPointSize(10); + return font; + } + } + return QVariant(); +} + + +int CookieExceptionsModel::columnCount(const QModelIndex &parent) const +{ + return (parent.isValid()) ? 0 : 2; +} + + +int CookieExceptionsModel::rowCount(const QModelIndex &parent) const +{ + return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.count() + m_blockedCookies.count() + m_sessionCookies.count(); +} + + +bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &parent) +{ + if (parent.isValid() || !m_cookieJar) + return false; + + int lastRow = row + count - 1; + beginRemoveRows(parent, row, lastRow); + for (int i = lastRow; i >= row; --i) + { + if (i < m_allowedCookies.count()) + { + m_allowedCookies.removeAt(row); + continue; + } + i = i - m_allowedCookies.count(); + if (i < m_blockedCookies.count()) + { + m_blockedCookies.removeAt(row); + continue; + } + i = i - m_blockedCookies.count(); + if (i < m_sessionCookies.count()) + { + m_sessionCookies.removeAt(row); + continue; + } + } + m_cookieJar->setAllowedCookies(m_allowedCookies); + m_cookieJar->setBlockedCookies(m_blockedCookies); + m_cookieJar->setAllowForSessionCookies(m_sessionCookies); + endRemoveRows(); + return true; +} + + + + +// ---------------------------------------------------------------------------------------------------------------- + + +CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) + : KDialog(parent) + , m_cookieJar(cookieJar) + , m_exceptionsWidget(new Ui::CookiesExceptionsWidget) +{ + setCaption("Cookies Exceptions"); + setButtons( KDialog::Ok ); + + QWidget *widget = new QWidget(this); + m_exceptionsWidget->setupUi(widget); + setMainWidget(widget); + + setWindowFlags(Qt::Sheet); + + connect(m_exceptionsWidget->removeButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeOne())); + connect(m_exceptionsWidget->removeAllButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeAll())); + + m_exceptionsWidget->exceptionTable->verticalHeader()->hide(); + m_exceptionsWidget->exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); + m_exceptionsWidget->exceptionTable->setAlternatingRowColors(true); + m_exceptionsWidget->exceptionTable->setTextElideMode(Qt::ElideMiddle); + m_exceptionsWidget->exceptionTable->setShowGrid(false); + m_exceptionsWidget->exceptionTable->setSortingEnabled(true); + m_exceptionsModel = new CookieExceptionsModel(cookieJar, this); + m_proxyModel = new QSortFilterProxyModel(this); + m_proxyModel->setSourceModel(m_exceptionsModel); + + connect(m_exceptionsWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); + + m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); + + connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); + connect(m_exceptionsWidget->blockButton, SIGNAL(clicked()), this, SLOT(block())); + connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); + connect(m_exceptionsWidget->allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); + + QFont f = font(); + f.setPointSize(10); + QFontMetrics fm(f); + int height = fm.height() + fm.height() / 3; + m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); + m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); + for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) + { + int header = m_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; + m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); + } +} + + +void CookiesExceptionsDialog::textChanged(const QString &text) +{ + bool enabled = !text.isEmpty(); + m_exceptionsWidget->blockButton->setEnabled(enabled); + m_exceptionsWidget->allowButton->setEnabled(enabled); + m_exceptionsWidget->allowForSessionButton->setEnabled(enabled); +} + + +void CookiesExceptionsDialog::block() +{ + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_blockedCookies.append(m_exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setBlockedCookies(m_exceptionsModel->m_blockedCookies); + m_exceptionsModel->reset(); +} + + +void CookiesExceptionsDialog::allow() +{ + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_allowedCookies.append(m_exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setAllowedCookies(m_exceptionsModel->m_allowedCookies); + m_exceptionsModel->reset(); +} + + +void CookiesExceptionsDialog::allowForSession() +{ + if (m_exceptionsWidget->domainLineEdit->text().isEmpty()) + return; + m_exceptionsModel->m_sessionCookies.append(m_exceptionsWidget->domainLineEdit->text()); + m_cookieJar->setAllowForSessionCookies(m_exceptionsModel->m_sessionCookies); + m_exceptionsModel->reset(); +} + diff --git a/src/cookieexceptiondialog.h b/src/cookieexceptiondialog.h new file mode 100644 index 00000000..f68c119e --- /dev/null +++ b/src/cookieexceptiondialog.h @@ -0,0 +1,89 @@ +/* ============================================================ +* +* 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 COOKIEEXCEPTIONDIALOG_H +#define COOKIEEXCEPTIONDIALOG_H + +// Qt Includes +#include + +// Forward Declarations +class CookieJar; +class QString; +class QStringList; +class QModelIndex; +class QVariant; + +class CookieExceptionsModel : public QAbstractTableModel +{ + Q_OBJECT + friend class CookiesExceptionsDialog; + +public: + explicit CookieExceptionsModel(CookieJar *cookieJar, QObject *parent = 0); + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + +private: + CookieJar *m_cookieJar; + + // Domains we allow, Domains we block, Domains we allow for this session + QStringList m_allowedCookies; + QStringList m_blockedCookies; + QStringList m_sessionCookies; +}; + + +// ----------------------------------------------------------------------------------------------- + + +// Ui Includes +#include "ui_cookiesexceptions.h" + +//Forward Declarations +class QSortFilterProxyModel; + + +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 *m_exceptionsWidget; +}; + +#endif -- cgit v1.2.1 From 67ac2452917657a4035d93c9a19cc02bdd2333d3 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 19 May 2009 12:42:42 +0200 Subject: Fixing Compilation. Going to feature improvements --- src/cookiedialog.cpp | 3 +++ src/cookiedialog.h | 8 ++------ src/cookieexceptiondialog.cpp | 2 ++ src/cookieexceptiondialog.h | 7 +++++-- src/cookies.ui | 20 ++------------------ src/cookiesexceptions.ui | 20 ++------------------ src/settings.cpp | 3 ++- 7 files changed, 18 insertions(+), 45 deletions(-) diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp index 1628a0c6..e9399e51 100644 --- a/src/cookiedialog.cpp +++ b/src/cookiedialog.cpp @@ -25,6 +25,9 @@ // Local Includes #include "cookiejar.h" +// KDE Includes +#include + CookieModel::CookieModel(CookieJar *cookieJar, QObject *parent) : QAbstractTableModel(parent) diff --git a/src/cookiedialog.h b/src/cookiedialog.h index be8b9236..fa78100c 100644 --- a/src/cookiedialog.h +++ b/src/cookiedialog.h @@ -22,11 +22,12 @@ #ifndef COOKIEDIALOG_H #define COOKIEDIALOG_H +// Local Includes +#include "cookiejar.h" // KDE Includes #include - // Qt Includes #include #include @@ -37,11 +38,6 @@ #include -// Forward Declarations -class CookieJar; -class CookieExceptionsModel; - - class CookieModel : public QAbstractTableModel { Q_OBJECT diff --git a/src/cookieexceptiondialog.cpp b/src/cookieexceptiondialog.cpp index c349c885..dba47787 100644 --- a/src/cookieexceptiondialog.cpp +++ b/src/cookieexceptiondialog.cpp @@ -24,6 +24,8 @@ // Local Includes +// Qt Includes +#include CookieExceptionsModel::CookieExceptionsModel(CookieJar *cookiejar, QObject *parent) diff --git a/src/cookieexceptiondialog.h b/src/cookieexceptiondialog.h index f68c119e..43afb58e 100644 --- a/src/cookieexceptiondialog.h +++ b/src/cookieexceptiondialog.h @@ -21,11 +21,14 @@ #ifndef COOKIEEXCEPTIONDIALOG_H #define COOKIEEXCEPTIONDIALOG_H + +// Local Includes +#include "cookiejar.h" + // Qt Includes -#include +#include // Forward Declarations -class CookieJar; class QString; class QStringList; class QModelIndex; diff --git a/src/cookies.ui b/src/cookies.ui index 16e0f4ea..6a654a97 100644 --- a/src/cookies.ui +++ b/src/cookies.ui @@ -6,8 +6,8 @@ 0 0 - 499 - 400 + 636 + 383
@@ -16,22 +16,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 252 - 20 - - - - diff --git a/src/cookiesexceptions.ui b/src/cookiesexceptions.ui index b4ce54a0..0a756f56 100644 --- a/src/cookiesexceptions.ui +++ b/src/cookiesexceptions.ui @@ -6,8 +6,8 @@ 0 0 - 377 - 405 + 635 + 416 @@ -96,22 +96,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 40 - 20 - - - - diff --git a/src/settings.cpp b/src/settings.cpp index 9ec5ad7a..d8de1441 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -30,7 +30,8 @@ // Local Includes #include "application.h" #include "mainwindow.h" -#include "cookiedialogs.h" +#include "cookiedialog.h" +#include "cookieexceptiondialog.h" #include "history.h" #include "networkaccessmanager.h" #include "webview.h" -- cgit v1.2.1 From de173857a95933a3de8ef446bde8a1a004d21d65 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 19 May 2009 17:26:02 +0200 Subject: Fixing Ui cookies dim --- src/cookiedialog.cpp | 67 ++++++++++++++++++++++++++----------------- src/cookiedialog.h | 2 ++ src/cookieexceptiondialog.cpp | 64 +++++++++++++++++++++++++---------------- src/cookieexceptiondialog.h | 2 ++ src/cookies.ui | 10 +++++-- src/cookiesexceptions.ui | 4 +-- 6 files changed, 95 insertions(+), 54 deletions(-) diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp index e9399e51..bc704f0b 100644 --- a/src/cookiedialog.cpp +++ b/src/cookiedialog.cpp @@ -160,6 +160,12 @@ void CookieModel::cookiesChanged() // Ui Includes #include "ui_cookies.h" +// Qt Includes +#include +#include + +#include + CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) : KDialog(parent) @@ -183,6 +189,7 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) m_proxyModel->setSourceModel(model); + cookieWidget->cookiesTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); cookieWidget->cookiesTable->verticalHeader()->hide(); cookieWidget->cookiesTable->setSelectionBehavior(QAbstractItemView::SelectRows); cookieWidget->cookiesTable->setModel(m_proxyModel); @@ -191,31 +198,39 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) 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); +// 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); +} - 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); + +QSize CookiesDialog::sizeHint() const +{ + QRect desktopRect = QApplication::desktop()->screenGeometry(); + QSize size = desktopRect.size() * 0.8; + return size; } diff --git a/src/cookiedialog.h b/src/cookiedialog.h index fa78100c..e1b17356 100644 --- a/src/cookiedialog.h +++ b/src/cookiedialog.h @@ -70,6 +70,8 @@ class CookiesDialog : public KDialog public: explicit CookiesDialog(CookieJar *cookieJar, QWidget *parent = 0); + QSize sizeHint() const; + private: QSortFilterProxyModel *m_proxyModel; }; diff --git a/src/cookieexceptiondialog.cpp b/src/cookieexceptiondialog.cpp index dba47787..9cf95017 100644 --- a/src/cookieexceptiondialog.cpp +++ b/src/cookieexceptiondialog.cpp @@ -172,11 +172,19 @@ bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &pa // ---------------------------------------------------------------------------------------------------------------- +// Qt Includes +#include +#include + +#include + + CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) : KDialog(parent) , m_cookieJar(cookieJar) , m_exceptionsWidget(new Ui::CookiesExceptionsWidget) { + setWindowFlags(Qt::Sheet); setCaption("Cookies Exceptions"); setButtons( KDialog::Ok ); @@ -184,11 +192,10 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * m_exceptionsWidget->setupUi(widget); setMainWidget(widget); - setWindowFlags(Qt::Sheet); - connect(m_exceptionsWidget->removeButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeOne())); connect(m_exceptionsWidget->removeAllButton, SIGNAL(clicked()), m_exceptionsWidget->exceptionTable, SLOT(removeAll())); + m_exceptionsWidget->exceptionTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_exceptionsWidget->exceptionTable->verticalHeader()->hide(); m_exceptionsWidget->exceptionTable->setSelectionBehavior(QAbstractItemView::SelectRows); m_exceptionsWidget->exceptionTable->setAlternatingRowColors(true); @@ -201,6 +208,7 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * connect(m_exceptionsWidget->search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); + m_exceptionsWidget->exceptionTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_exceptionsWidget->exceptionTable->setModel(m_proxyModel); connect(m_exceptionsWidget->domainLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); @@ -208,28 +216,28 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); connect(m_exceptionsWidget->allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); - QFont f = font(); - f.setPointSize(10); - QFontMetrics fm(f); - int height = fm.height() + fm.height() / 3; - m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); - m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); - for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) - { - int header = m_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; - m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); - } +// QFont f = font(); +// f.setPointSize(10); +// QFontMetrics fm(f); +// int height = fm.height() + fm.height() / 3; +// m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); +// m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); +// for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) +// { +// int header = m_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; +// m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); +// } } @@ -271,3 +279,11 @@ void CookiesExceptionsDialog::allowForSession() m_exceptionsModel->reset(); } + +QSize CookiesExceptionsDialog::sizeHint() const +{ + QRect desktopRect = QApplication::desktop()->screenGeometry(); + QSize size = desktopRect.size() * 0.6; + return size; +} + diff --git a/src/cookieexceptiondialog.h b/src/cookieexceptiondialog.h index 43afb58e..eb0608d1 100644 --- a/src/cookieexceptiondialog.h +++ b/src/cookieexceptiondialog.h @@ -75,6 +75,8 @@ class CookiesExceptionsDialog : public KDialog public: explicit CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent = 0); + QSize sizeHint() const; + private slots: void block(); void allow(); diff --git a/src/cookies.ui b/src/cookies.ui index 6a654a97..ae1c4a2b 100644 --- a/src/cookies.ui +++ b/src/cookies.ui @@ -6,10 +6,16 @@ 0 0 - 636 - 383 + 859 + 478 + + + 0 + 0 + + Form diff --git a/src/cookiesexceptions.ui b/src/cookiesexceptions.ui index 0a756f56..3e28b42a 100644 --- a/src/cookiesexceptions.ui +++ b/src/cookiesexceptions.ui @@ -6,8 +6,8 @@ 0 0 - 635 - 416 + 1000 + 400 -- cgit v1.2.1 From dc981e4cb1dc06596c801299f7c34e63d6762150 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 20 May 2009 00:42:41 +0200 Subject: Fixing Ui dimension --- src/cookiedialog.cpp | 30 +++--------------------------- src/cookieexceptiondialog.cpp | 26 ++++---------------------- 2 files changed, 7 insertions(+), 49 deletions(-) diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp index bc704f0b..ea9555eb 100644 --- a/src/cookiedialog.cpp +++ b/src/cookiedialog.cpp @@ -198,33 +198,9 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) 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); + // Fixing header dimension + QHeaderView *headerView = cookieWidget->cookiesTable->horizontalHeader(); + headerView->setResizeMode(QHeaderView::ResizeToContents); } diff --git a/src/cookieexceptiondialog.cpp b/src/cookieexceptiondialog.cpp index 9cf95017..77445d0b 100644 --- a/src/cookieexceptiondialog.cpp +++ b/src/cookieexceptiondialog.cpp @@ -177,6 +177,7 @@ bool CookieExceptionsModel::removeRows(int row, int count, const QModelIndex &pa #include #include +#include CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget *parent) @@ -216,28 +217,9 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * connect(m_exceptionsWidget->allowButton, SIGNAL(clicked()), this, SLOT(allow())); connect(m_exceptionsWidget->allowForSessionButton, SIGNAL(clicked()), this, SLOT(allowForSession())); -// QFont f = font(); -// f.setPointSize(10); -// QFontMetrics fm(f); -// int height = fm.height() + fm.height() / 3; -// m_exceptionsWidget->exceptionTable->verticalHeader()->setDefaultSectionSize(height); -// m_exceptionsWidget->exceptionTable->verticalHeader()->setMinimumSectionSize(-1); -// for (int i = 0; i < m_exceptionsModel->columnCount(); ++i) -// { -// int header = m_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; -// m_exceptionsWidget->exceptionTable->horizontalHeader()->resizeSection(i, header); -// } + // Fixing header dimension + QHeaderView *headerView = m_exceptionsWidget->exceptionTable->horizontalHeader(); + headerView->setResizeMode(QHeaderView::Stretch); } -- cgit v1.2.1 From fac14a34968fab79f535b98cb74bf3a329d29f23 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 20 May 2009 00:57:41 +0200 Subject: Added FILES file --- FILES | 43 +++++++++++++++++++++++++++++++++++++++++++ src/cookiedialog.cpp | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 FILES diff --git a/FILES b/FILES new file mode 100644 index 00000000..dcb36c54 --- /dev/null +++ b/FILES @@ -0,0 +1,43 @@ +REKONQ FILES && CLASSES: + +cookies: + cookiedialog + cookieexceptiondialog + cookiejar + edittableview + edittreeview + +Ui: + mainwindow + mainview + tabbar + findbar + searchbar + +urlbar: + lineedit + stackedurlbar + urlbar + +webkit: + webview + +network: + networkaccessmanager + +panel: + panelhistory + sidepanel + +history: + history + modelmenu + +bookmarks: + bookmarks + +misc: + download + autosaver + application + settings diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp index ea9555eb..9f22b29b 100644 --- a/src/cookiedialog.cpp +++ b/src/cookiedialog.cpp @@ -200,7 +200,7 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) // Fixing header dimension QHeaderView *headerView = cookieWidget->cookiesTable->horizontalHeader(); - headerView->setResizeMode(QHeaderView::ResizeToContents); + headerView->setResizeMode(QHeaderView::Stretch); } -- cgit v1.2.1 From b4a66615165ab07949b1b62253e8df18ecc8c42d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 20 May 2009 02:05:33 +0200 Subject: Porting to KDE classes. It doesn't work well, for now.. --- src/cookiejar.cpp | 133 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 56 deletions(-) diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp index 1b0c0051..a2b08ffe 100644 --- a/src/cookiejar.cpp +++ b/src/cookiejar.cpp @@ -50,44 +50,44 @@ static const unsigned int JAR_VERSION = 23; -QDataStream &operator<<(QDataStream &stream, const QList &list) -{ - stream << JAR_VERSION; - stream << quint32(list.size()); - for (int i = 0; i < list.size(); ++i) - stream << list.at(i).toRawForm(); - return stream; -} - - -QDataStream &operator>>(QDataStream &stream, QList &list) -{ - list.clear(); - - quint32 version; - stream >> version; - - if (version != JAR_VERSION) - return stream; - - quint32 count; - stream >> count; - for (quint32 i = 0; i < count; ++i) - { - QByteArray value; - stream >> value; - QList newCookies = QNetworkCookie::parseCookies(value); - if (newCookies.count() == 0 && value.length() != 0) - { - kDebug() << "CookieJar: Unable to parse saved cookie:" << value; - } - for (int j = 0; j < newCookies.count(); ++j) - list.append(newCookies.at(j)); - if (stream.atEnd()) - break; - } - return stream; -} +// QDataStream &operator<<(QDataStream &stream, const QList &list) +// { +// stream << JAR_VERSION; +// stream << quint32(list.size()); +// for (int i = 0; i < list.size(); ++i) +// stream << list.at(i).toRawForm(); +// return stream; +// } +// +// +// QDataStream &operator>>(QDataStream &stream, QList &list) +// { +// list.clear(); +// +// quint32 version; +// stream >> version; +// +// if (version != JAR_VERSION) +// return stream; +// +// quint32 count; +// stream >> count; +// for (quint32 i = 0; i < count; ++i) +// { +// QByteArray value; +// stream >> value; +// QList newCookies = QNetworkCookie::parseCookies(value); +// if (newCookies.count() == 0 && value.length() != 0) +// { +// kDebug() << "CookieJar: Unable to parse saved cookie:" << value; +// } +// for (int j = 0; j < newCookies.count(); ++j) +// list.append(newCookies.at(j)); +// if (stream.atEnd()) +// break; +// } +// return stream; +// } CookieJar::CookieJar(QObject *parent) @@ -122,17 +122,30 @@ void CookieJar::load() return; // load cookies and exceptions - QString filepath = KStandardDirs::locateLocal("appdata", "cookies.ini"); - qRegisterMetaTypeStreamOperators >("QList"); - QSettings cookieSettings(filepath, QSettings::IniFormat); - setAllCookies(qvariant_cast >(cookieSettings.value(QLatin1String("cookies")))); - cookieSettings.beginGroup(QLatin1String("Exceptions")); - m_exceptions_block = cookieSettings.value(QLatin1String("block")).toStringList(); - m_exceptions_allow = cookieSettings.value(QLatin1String("allow")).toStringList(); - m_exceptions_allowForSession = cookieSettings.value(QLatin1String("allowForSession")).toStringList(); - qSort(m_exceptions_block.begin(), m_exceptions_block.end()); - qSort(m_exceptions_allow.begin(), m_exceptions_allow.end()); - qSort(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end()); + QString filepath = KStandardDirs::locateLocal("appdata", "cookies.ini.NEW"); + KConfig iniconfig(filepath); + +// commented out to try managing cookies my way.. +// qRegisterMetaTypeStreamOperators >("QList"); + + KConfigGroup inigroup1 = iniconfig.group("general"); + + QStringList cookieStringList = inigroup1.readEntry( QString("cookies"), QStringList() ); + QList cookieNetworkList; + foreach( QString str, cookieStringList ) + { + cookieNetworkList << QNetworkCookie( str.toLocal8Bit() ); + } + setAllCookies( cookieNetworkList ); + + KConfigGroup inigroup2 = iniconfig.group("exceptions"); + m_exceptions_block = inigroup2.readEntry( QString("block") , QStringList() ); + m_exceptions_allow = inigroup2.readEntry( QString("allow"), QStringList() ); + m_exceptions_allowForSession = inigroup2.readEntry( QString("allowForSession"), QStringList() ); + + qSort( m_exceptions_block.begin(), m_exceptions_block.end() ); + qSort( m_exceptions_allow.begin(), m_exceptions_allow.end() ); + qSort( m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end() ); loadSettings(); @@ -186,8 +199,10 @@ void CookieJar::save() return; purgeOldCookies(); - QString filepath = KStandardDirs::locateLocal("appdata", "cookies.ini"); - QSettings cookieSettings(filepath, QSettings::IniFormat); + QString filepath = KStandardDirs::locateLocal("appdata", "cookies.ini.NEW"); + KConfig iniconfig( filepath ); + + KConfigGroup inigroup1 = iniconfig.group("general"); QList cookies = allCookies(); for (int i = cookies.count() - 1; i >= 0; --i) { @@ -195,11 +210,17 @@ void CookieJar::save() cookies.removeAt(i); } - cookieSettings.setValue(QLatin1String("cookies"), qVariantFromValue >(cookies)); - cookieSettings.beginGroup(QLatin1String("Exceptions")); - cookieSettings.setValue(QLatin1String("block"), m_exceptions_block); - cookieSettings.setValue(QLatin1String("allow"), m_exceptions_allow); - cookieSettings.setValue(QLatin1String("allowForSession"), m_exceptions_allowForSession); + QStringList cookieStringList; + foreach( QNetworkCookie cook, cookies ) + { + cookieStringList << QString( cook.toRawForm() ); + } + inigroup1.writeEntry( QString("cookies"), cookieStringList ); + + KConfigGroup inigroup2 = iniconfig.group("exceptions"); + inigroup2.writeEntry( QString("block"), m_exceptions_block ); + inigroup2.writeEntry( QString("allow"), m_exceptions_allow ); + inigroup2.writeEntry( QString("allowForSession"), m_exceptions_allowForSession ); // save cookie settings int n; -- cgit v1.2.1 From 915ef47d96260a55914dec5c5b1fb28e01f93028 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 20 May 2009 13:47:41 +0200 Subject: const char[] --- src/cookiejar.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp index a2b08ffe..1e9ce3f2 100644 --- a/src/cookiejar.cpp +++ b/src/cookiejar.cpp @@ -49,6 +49,7 @@ static const unsigned int JAR_VERSION = 23; +static const char cookieFileName[] = "cookies.ini.NEW"; // QDataStream &operator<<(QDataStream &stream, const QList &list) // { @@ -122,7 +123,7 @@ void CookieJar::load() return; // load cookies and exceptions - QString filepath = KStandardDirs::locateLocal("appdata", "cookies.ini.NEW"); + QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName); KConfig iniconfig(filepath); // commented out to try managing cookies my way.. @@ -199,7 +200,7 @@ void CookieJar::save() return; purgeOldCookies(); - QString filepath = KStandardDirs::locateLocal("appdata", "cookies.ini.NEW"); + QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName); KConfig iniconfig( filepath ); KConfigGroup inigroup1 = iniconfig.group("general"); -- cgit v1.2.1 From 0a8ad22850a60c6e42b359952a7aa208b3689f13 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 3 Jun 2009 00:09:57 +0200 Subject: Fixing CMakelists and close buttons --- src/CMakeLists.txt | 3 ++- src/cookiedialog.cpp | 2 +- src/cookieexceptiondialog.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 16494f41..2ddf1117 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,7 +24,8 @@ SET( rekonq_SRCS lineedit.cpp stackedurlbar.cpp webpage.cpp - cookiedialogs.cpp + cookiedialog.cpp + cookieexceptiondialog.cpp ) KDE4_ADD_UI_FILES( rekonq_SRCS diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp index 9f22b29b..36379e58 100644 --- a/src/cookiedialog.cpp +++ b/src/cookiedialog.cpp @@ -172,7 +172,7 @@ CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) { setWindowFlags(Qt::Sheet); setCaption("Cookies"); - setButtons( KDialog::Ok ); + setButtons( KDialog::Close ); Ui::CookiesWidget *cookieWidget = new Ui::CookiesWidget; QWidget *widget = new QWidget(this); diff --git a/src/cookieexceptiondialog.cpp b/src/cookieexceptiondialog.cpp index 77445d0b..0a88b378 100644 --- a/src/cookieexceptiondialog.cpp +++ b/src/cookieexceptiondialog.cpp @@ -187,7 +187,7 @@ CookiesExceptionsDialog::CookiesExceptionsDialog(CookieJar *cookieJar, QWidget * { setWindowFlags(Qt::Sheet); setCaption("Cookies Exceptions"); - setButtons( KDialog::Ok ); + setButtons( KDialog::Close ); QWidget *widget = new QWidget(this); m_exceptionsWidget->setupUi(widget); -- cgit v1.2.1 From 7ea16e97740ee21660d7130c83ff6af5fb3b1563 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 3 Jun 2009 00:40:28 +0200 Subject: new cookie management system. That (hopefully) works well..;) --- src/cookiedialog.cpp | 1 - src/cookieexceptiondialog.cpp | 1 - src/cookiejar.cpp | 148 ++++++++++-------------------------------- src/cookiejar.h | 5 +- src/settings.cpp | 1 - 5 files changed, 36 insertions(+), 120 deletions(-) diff --git a/src/cookiedialog.cpp b/src/cookiedialog.cpp index 36379e58..e48d9c02 100644 --- a/src/cookiedialog.cpp +++ b/src/cookiedialog.cpp @@ -34,7 +34,6 @@ CookieModel::CookieModel(CookieJar *cookieJar, QObject *parent) , m_cookieJar(cookieJar) { connect(m_cookieJar, SIGNAL(cookiesChanged()), this, SLOT(cookiesChanged())); - m_cookieJar->load(); } diff --git a/src/cookieexceptiondialog.cpp b/src/cookieexceptiondialog.cpp index 0a88b378..b4ad555f 100644 --- a/src/cookieexceptiondialog.cpp +++ b/src/cookieexceptiondialog.cpp @@ -268,4 +268,3 @@ QSize CookiesExceptionsDialog::sizeHint() const QSize size = desktopRect.size() * 0.6; return size; } - diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp index 1e9ce3f2..4e4ef2c2 100644 --- a/src/cookiejar.cpp +++ b/src/cookiejar.cpp @@ -49,87 +49,18 @@ static const unsigned int JAR_VERSION = 23; -static const char cookieFileName[] = "cookies.ini.NEW"; - -// QDataStream &operator<<(QDataStream &stream, const QList &list) -// { -// stream << JAR_VERSION; -// stream << quint32(list.size()); -// for (int i = 0; i < list.size(); ++i) -// stream << list.at(i).toRawForm(); -// return stream; -// } -// -// -// QDataStream &operator>>(QDataStream &stream, QList &list) -// { -// list.clear(); -// -// quint32 version; -// stream >> version; -// -// if (version != JAR_VERSION) -// return stream; -// -// quint32 count; -// stream >> count; -// for (quint32 i = 0; i < count; ++i) -// { -// QByteArray value; -// stream >> value; -// QList newCookies = QNetworkCookie::parseCookies(value); -// if (newCookies.count() == 0 && value.length() != 0) -// { -// kDebug() << "CookieJar: Unable to parse saved cookie:" << value; -// } -// for (int j = 0; j < newCookies.count(); ++j) -// list.append(newCookies.at(j)); -// if (stream.atEnd()) -// break; -// } -// return stream; -// } +static const char cookieFileName[] = "cookies"; CookieJar::CookieJar(QObject *parent) : QNetworkCookieJar(parent) - , m_loaded(false) - , m_saveTimer(new AutoSaver(this)) , m_acceptCookies(AcceptOnlyFromSitesNavigatedTo) { - load(); -} - - -CookieJar::~CookieJar() -{ - if (m_keepCookies == KeepUntilExit) - clear(); - m_saveTimer->saveIfNeccessary(); -} - - -void CookieJar::clear() -{ - setAllCookies(QList()); - m_saveTimer->changeOccurred(); - emit cookiesChanged(); -} - - -void CookieJar::load() -{ - if (m_loaded) - return; - // load cookies and exceptions QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName); KConfig iniconfig(filepath); -// commented out to try managing cookies my way.. -// qRegisterMetaTypeStreamOperators >("QList"); - - KConfigGroup inigroup1 = iniconfig.group("general"); + KConfigGroup inigroup1 = iniconfig.group("cookielist"); QStringList cookieStringList = inigroup1.readEntry( QString("cookies"), QStringList() ); QList cookieNetworkList; @@ -149,11 +80,28 @@ void CookieJar::load() qSort( m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end() ); loadSettings(); +} + + +CookieJar::~CookieJar() +{ + if (m_keepCookies == KeepUntilExit) + clear(); save(); } +void CookieJar::clear() +{ + setAllCookies(QList()); + + save(); + + emit cookiesChanged(); +} + + void CookieJar::loadSettings() { int canAcceptCookies = ReKonfig::acceptCookies(); @@ -189,21 +137,18 @@ void CookieJar::loadSettings() break; } - m_loaded = true; emit cookiesChanged(); } void CookieJar::save() { - if (!m_loaded) - return; purgeOldCookies(); QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName); KConfig iniconfig( filepath ); - KConfigGroup inigroup1 = iniconfig.group("general"); + KConfigGroup inigroup1 = iniconfig.group("cookielist"); QList cookies = allCookies(); for (int i = cookies.count() - 1; i >= 0; --i) { @@ -212,9 +157,9 @@ void CookieJar::save() } QStringList cookieStringList; - foreach( QNetworkCookie cook, cookies ) + foreach( QNetworkCookie cookie, cookies ) { - cookieStringList << QString( cook.toRawForm() ); + cookieStringList << QString( cookie.toRawForm() ); } inigroup1.writeEntry( QString("cookies"), cookieStringList ); @@ -273,16 +218,13 @@ void CookieJar::purgeOldCookies() if (oldCount == cookies.count()) return; setAllCookies(cookies); + emit cookiesChanged(); } QList CookieJar::cookiesForUrl(const QUrl &url) const { - CookieJar *that = const_cast(this); - if (!m_loaded) - that->load(); - QWebSettings *globalSettings = QWebSettings::globalSettings(); if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { @@ -296,9 +238,6 @@ QList CookieJar::cookiesForUrl(const QUrl &url) const bool CookieJar::setCookiesFromUrl(const QList &cookieList, const QUrl &url) { - if (!m_loaded) - load(); - QWebSettings *globalSettings = QWebSettings::globalSettings(); if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) return false; @@ -340,17 +279,13 @@ bool CookieJar::setCookiesFromUrl(const QList &cookieList, const setAllCookies(cookies); addedCookies = true; } -#if 0 - else - kWarning() << "setCookiesFromUrl failed" << url << cookieList.value(0).toRawForm(); -#endif } } } if (addedCookies) { - m_saveTimer->changeOccurred(); + save(); emit cookiesChanged(); } return addedCookies; @@ -359,91 +294,76 @@ bool CookieJar::setCookiesFromUrl(const QList &cookieList, const CookieJar::AcceptPolicy CookieJar::acceptPolicy() const { - if (!m_loaded) - (const_cast(this))->load(); return m_acceptCookies; } void CookieJar::setAcceptPolicy(AcceptPolicy policy) { - if (!m_loaded) - load(); if (policy == m_acceptCookies) return; m_acceptCookies = policy; - m_saveTimer->changeOccurred(); + + save(); } CookieJar::KeepPolicy CookieJar::keepPolicy() const { - if (!m_loaded) - (const_cast(this))->load(); return m_keepCookies; } void CookieJar::setKeepPolicy(KeepPolicy policy) { - if (!m_loaded) - load(); if (policy == m_keepCookies) return; m_keepCookies = policy; - m_saveTimer->changeOccurred(); + + save(); } QStringList CookieJar::blockedCookies() const { - if (!m_loaded) - (const_cast(this))->load(); return m_exceptions_block; } QStringList CookieJar::allowedCookies() const { - if (!m_loaded) - (const_cast(this))->load(); return m_exceptions_allow; } QStringList CookieJar::allowForSessionCookies() const { - if (!m_loaded) - (const_cast(this))->load(); return m_exceptions_allowForSession; } void CookieJar::setBlockedCookies(const QStringList &list) { - if (!m_loaded) - load(); m_exceptions_block = list; qSort(m_exceptions_block.begin(), m_exceptions_block.end()); - m_saveTimer->changeOccurred(); + + save(); } void CookieJar::setAllowedCookies(const QStringList &list) { - if (!m_loaded) - load(); m_exceptions_allow = list; qSort(m_exceptions_allow.begin(), m_exceptions_allow.end()); - m_saveTimer->changeOccurred(); + + save(); } void CookieJar::setAllowForSessionCookies(const QStringList &list) { - if (!m_loaded) - load(); m_exceptions_allowForSession = list; qSort(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end()); - m_saveTimer->changeOccurred(); + + save(); } diff --git a/src/cookiejar.h b/src/cookiejar.h index 4d60d658..08c65218 100644 --- a/src/cookiejar.h +++ b/src/cookiejar.h @@ -37,11 +37,13 @@ class CookieJar : public QNetworkCookieJar { friend class CookieModel; Q_OBJECT + Q_PROPERTY(AcceptPolicy acceptPolicy READ acceptPolicy WRITE setAcceptPolicy) Q_PROPERTY(KeepPolicy keepPolicy READ keepPolicy WRITE setKeepPolicy) Q_PROPERTY(QStringList blockedCookies READ blockedCookies WRITE setBlockedCookies) Q_PROPERTY(QStringList allowedCookies READ allowedCookies WRITE setAllowedCookies) Q_PROPERTY(QStringList allowForSessionCookies READ allowForSessionCookies WRITE setAllowForSessionCookies) + Q_ENUMS(KeepPolicy) Q_ENUMS(AcceptPolicy) @@ -92,9 +94,6 @@ private slots: private: void purgeOldCookies(); - void load(); - bool m_loaded; - AutoSaver *m_saveTimer; AcceptPolicy m_acceptCookies; KeepPolicy m_keepCookies; diff --git a/src/settings.cpp b/src/settings.cpp index d8de1441..f6e73412 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -215,4 +215,3 @@ void SettingsDialog::setHomeToCurrentPage() d->generalUi.kcfg_homePage->setText(webView->url().prettyUrl()); } } - -- cgit v1.2.1