From 644c7c8c062228c760b490838748c5f14547ff1c Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 21 Jul 2010 13:04:14 +0200 Subject: 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... --- src/application.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/application.cpp') 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(); +} + -- cgit v1.2.1