diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-07-21 13:04:14 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-07-21 13:04:14 +0200 |
commit | 644c7c8c062228c760b490838748c5f14547ff1c (patch) | |
tree | 624769f17e4a250712776eaeb095ac3585877066 /src | |
parent | Don't hide the bookmarks toolbar by default (diff) | |
download | rekonq-644c7c8c062228c760b490838748c5f14547ff1c.tar.xz |
Moving download history management from HistoryManager to Application class
It's actually the same, but probably a bit more coherent.
More over, we are going to change a lot of things in the HistoryManager class...
Diffstat (limited to 'src')
-rw-r--r-- | src/application.cpp | 59 | ||||
-rw-r--r-- | src/application.h | 37 | ||||
-rw-r--r-- | src/history/historymanager.cpp | 56 | ||||
-rw-r--r-- | src/history/historymanager.h | 28 | ||||
-rw-r--r-- | src/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/newtabpage.cpp | 2 | ||||
-rw-r--r-- | src/webpage.cpp | 4 |
7 files changed, 100 insertions, 88 deletions
diff --git a/src/application.cpp b/src/application.cpp index 5b98fafa..07a3067b 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -548,3 +548,62 @@ void Application::updateConfiguration() defaultSettings = 0; } + + + + +void Application::addDownload(const QString &srcUrl, const QString &destUrl) +{ + QWebSettings *globalSettings = QWebSettings::globalSettings(); + if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) + return; + QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads"); + QFile downloadFile(downloadFilePath); + if (!downloadFile.open(QFile::WriteOnly | QFile::Append)) + { + kDebug() << "Unable to open download file (WRITE mode).."; + return; + } + QDataStream out(&downloadFile); + out << srcUrl; + out << destUrl; + out << QDateTime::currentDateTime(); + downloadFile.close(); +} + + +DownloadList Application::downloads() +{ + DownloadList list; + + QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads"); + QFile downloadFile(downloadFilePath); + if (!downloadFile.open(QFile::ReadOnly)) + { + kDebug() << "Unable to open download file (READ mode).."; + return list; + } + + QDataStream in(&downloadFile); + while (!in.atEnd()) + { + QString srcUrl; + in >> srcUrl; + QString destUrl; + in >> destUrl; + QDateTime dt; + in >> dt; + DownloadItem item(srcUrl, destUrl, dt); + list << item; + } + return list; +} + + +bool Application::clearDownloadsHistory() +{ + QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads"); + QFile downloadFile(downloadFilePath); + return downloadFile.remove(); +} + diff --git a/src/application.h b/src/application.h index 7b58ab18..18c99afb 100644 --- a/src/application.h +++ b/src/application.h @@ -56,6 +56,38 @@ class WebView; typedef QList< QWeakPointer<MainWindow> > MainWindowList; +// --------------------------------------------------------------------------------------------------------------- + + +#include <QDateTime> + + +class DownloadItem +{ +public: + DownloadItem() {} + explicit DownloadItem(const QString &srcUrl, + const QString &destUrl, + const QDateTime &d + ) + : srcUrlString(srcUrl) + , destUrlString(destUrl) + , dateTime(d) + {} + + QString srcUrlString; + QString destUrlString; + QDateTime dateTime; +}; + + +typedef QList<DownloadItem> DownloadList; + + +// --------------------------------------------------------------------------------------------------------------- + + + /** * */ @@ -80,6 +112,11 @@ public: static SessionManager *sessionManager(); static AdBlockManager *adblockManager(); + // DOWNLOADS MANAGEMENT METHODS + void addDownload(const QString &srcUrl, const QString &destUrl); + DownloadList downloads(); + bool clearDownloadsHistory(); + public slots: /** * Save application's configuration diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp index d531c189..b1c5e7cc 100644 --- a/src/history/historymanager.cpp +++ b/src/history/historymanager.cpp @@ -464,62 +464,6 @@ AwesomeUrlCompletion * HistoryManager::completionObject() const } -void HistoryManager::addDownload(const QString &srcUrl, const QString &destUrl) -{ - QWebSettings *globalSettings = QWebSettings::globalSettings(); - if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) - return; - QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads"); - QFile downloadFile(downloadFilePath); - if (!downloadFile.open(QFile::WriteOnly | QFile::Append)) - { - kDebug() << "Unable to open download file (WRITE mode).."; - return; - } - QDataStream out(&downloadFile); - out << srcUrl; - out << destUrl; - out << QDateTime::currentDateTime(); - downloadFile.close(); -} - - -DownloadList HistoryManager::downloads() -{ - DownloadList list; - - QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads"); - QFile downloadFile(downloadFilePath); - if (!downloadFile.open(QFile::ReadOnly)) - { - kDebug() << "Unable to open download file (READ mode).."; - return list; - } - - QDataStream in(&downloadFile); - while (!in.atEnd()) - { - QString srcUrl; - in >> srcUrl; - QString destUrl; - in >> destUrl; - QDateTime dt; - in >> dt; - DownloadItem item(srcUrl, destUrl, dt); - list << item; - } - return list; -} - - -bool HistoryManager::clearDownloadsHistory() -{ - QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads"); - QFile downloadFile(downloadFilePath); - return downloadFile.remove(); -} - - QString HistoryManager::titleForHistoryUrl(QString url) { return history().at(m_historyFilterModel->historyLocation(url)).title; diff --git a/src/history/historymanager.h b/src/history/historymanager.h index 7b82579d..6b73cac0 100644 --- a/src/history/historymanager.h +++ b/src/history/historymanager.h @@ -84,30 +84,6 @@ public: // --------------------------------------------------------------------------------------------------------------- -class DownloadItem -{ -public: - DownloadItem() {} - explicit DownloadItem(const QString &srcUrl, - const QString &destUrl, - const QDateTime &d - ) - : srcUrlString(srcUrl) - , destUrlString(destUrl) - , dateTime(d) - {} - - QString srcUrlString; - QString destUrlString; - QDateTime dateTime; -}; - - -typedef QList<DownloadItem> DownloadList; - -// --------------------------------------------------------------------------------------------------------------- - - // Forward Declarations class AutoSaver; class HistoryModel; @@ -157,10 +133,6 @@ public: */ AwesomeUrlCompletion *completionObject() const; - void addDownload(const QString &srcUrl, const QString &destUrl); - DownloadList downloads(); - bool clearDownloadsHistory(); - public slots: void clear(); void loadSettings(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b58f4fac..55cc7a69 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1206,7 +1206,7 @@ void MainWindow::clearPrivateData() if (clearWidget.clearDownloads->isChecked()) { - Application::historyManager()->clearDownloadsHistory(); + Application::instance()->clearDownloadsHistory(); } if (clearWidget.clearCookies->isChecked()) diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index cbdbe306..bbf6714e 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -549,7 +549,7 @@ void NewTabPage::downloadsPage() clearData.findFirst("span").appendInside(i18n("Clear Private Data")); m_root.document().findFirst("#actions").appendInside(clearData); - DownloadList list = Application::historyManager()->downloads(); + DownloadList list = Application::instance()->downloads(); if (list.isEmpty()) { diff --git a/src/webpage.cpp b/src/webpage.cpp index 939d7128..a63940b0 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -136,8 +136,8 @@ static bool downloadResource (const KUrl& srcUrl, const KIO::MetaData& metaData } while (result == KIO::R_CANCEL && destUrl.isValid()); - // Save download on history manager - Application::historyManager()->addDownload(srcUrl.pathOrUrl() , destUrl.pathOrUrl()); + // Save download history + Application::instance()->addDownload(srcUrl.pathOrUrl() , destUrl.pathOrUrl()); if (ReKonfig::kgetDownload()) { |