From a6ef003dd4c1b6ad08eca4f5adaa4679bbc20bce Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 20 Mar 2010 22:54:21 +0100 Subject: Downloads Page This commit implements the downloads history page. While it is in an horrible shape, its slots seem working well It needs just some love.. --- src/webpage.cpp | 105 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 39 deletions(-) (limited to 'src/webpage.cpp') diff --git a/src/webpage.cpp b/src/webpage.cpp index 42193ed0..0e7b3d8a 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -71,6 +71,9 @@ #include #include +// Defines +#define QL1S(x) QLatin1String(x) + WebPage::WebPage(QWidget *parent) : KWebPage(parent, KWalletIntegration) @@ -292,55 +295,76 @@ QString WebPage::errorPage(QNetworkReply *reply) } +// WARNING +// this code is actually copied from KWebPage::downloadRequest to save +// downloads data before. If you have some better ideas about, +// feel free to let us know about :) void WebPage::downloadRequest(const QNetworkRequest &request) { - if (ReKonfig::kgetDownload()) - { - //*Copy of kwebpage code (Shouldn't be done in kwebpage ?) - - KUrl destUrl; - KUrl srcUrl (request.url()); - int result = KIO::R_OVERWRITE; - - do - { - destUrl = KFileDialog::getSaveFileName(srcUrl.fileName(), QString(), view()); - - if (destUrl.isLocalFile()) - { - QFileInfo finfo (destUrl.toLocalFile()); - if (finfo.exists()) - { - QDateTime now = QDateTime::currentDateTime(); - QPointer dlg = new KIO::RenameDialog( view(), i18n("Overwrite File?"), srcUrl, destUrl, - KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP), - -1, finfo.size(), - now.toTime_t(), finfo.created().toTime_t(), - now.toTime_t(), finfo.lastModified().toTime_t()); - result = dlg->exec(); - delete dlg; - } - } - } - while (result == KIO::R_CANCEL && destUrl.isValid()); - - if (result == KIO::R_OVERWRITE && destUrl.isValid()) + KUrl destUrl; + KUrl srcUrl (request.url()); + int result = KIO::R_OVERWRITE; + + do + { + destUrl = KFileDialog::getSaveFileName(srcUrl.fileName(), QString(), view()); + + if (destUrl.isLocalFile()) + { + QFileInfo finfo( destUrl.toLocalFile() ); + if ( finfo.exists() ) + { + QDateTime now = QDateTime::currentDateTime(); + QPointer dlg = new KIO::RenameDialog( view(), + i18n("Overwrite File?"), + srcUrl, + destUrl, + KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP), + -1, + finfo.size(), + now.toTime_t(), + finfo.created().toTime_t(), + now.toTime_t(), + finfo.lastModified().toTime_t() + ); + result = dlg->exec(); + delete dlg; + } + } + } + while ( result == KIO::R_CANCEL && destUrl.isValid() ); + + // now store data + // now, destUrl, srcUrl + Application::historyManager()->addDownload( srcUrl.pathOrUrl() , destUrl.pathOrUrl() ); + + if ( result == KIO::R_OVERWRITE && destUrl.isValid() ) + { + if ( ReKonfig::kgetDownload() ) { - //*End of copy code - //KGet integration: if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) { KToolInvocation::kdeinitExecWait("kget"); } QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); - kget.call("addTransfer", srcUrl.prettyUrl(), destUrl.prettyUrl(), true); + if( kget.isValid() ) + { + kget.call("addTransfer", srcUrl.prettyUrl(), destUrl.prettyUrl(), true); + return; + } } - return; - } - - KWebPage::downloadRequest(request); + // else, use KIO or fallback to it + KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite); + QVariant attr = request.attribute(static_cast(KIO::AccessManager::MetaData)); + if (attr.isValid() && attr.type() == QVariant::Map) + job->setMetaData(KIO::MetaData(attr.toMap())); + + job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. + job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. + job->uiDelegate()->setAutoErrorHandlingEnabled(true); + } } @@ -369,5 +393,8 @@ void WebPage::downloadAllContentsWithKGet() KToolInvocation::kdeinitExecWait("kget"); } QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); - kget.call("importLinks", QVariant(contents.toList())); + if( kget.isValid() ) + { + kget.call("importLinks", QVariant(contents.toList())); + } } -- cgit v1.2.1