From b040cbdd315cf09a8a3f889f4f1d6b0cd20a90c7 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 25 May 2010 02:23:40 +0200 Subject: cleaning handleUnsupportedContent slot --- src/webpage.cpp | 179 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 90 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/webpage.cpp b/src/webpage.cpp index a9558b32..6264febb 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -246,111 +246,112 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) if (_protHandler.postHandling(reply->request(), mainFrame())) return; - if (reply->error() == QNetworkReply::NoError) - { - KUrl replyUrl = reply->url(); + if (reply->error() != QNetworkReply::NoError) + return; + + KUrl replyUrl = reply->url(); - // HACK ------------------------------------------- - QString mimeType; - QString suggestedFileName; - - QString app = reply->header(QNetworkRequest::ContentTypeHeader).toString(); - QStringList headerList = app.split( ';' ); - - if(headerList.count() > 0) + // HACK ------------------------------------------- + QString mimeType; + QString suggestedFileName; + + QString app = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + QStringList headerList = app.split( ';' ); + + if(headerList.count() > 0) + { + mimeType = headerList.takeFirst().trimmed(); + Q_FOREACH(const QString &head, headerList) { - mimeType = headerList.takeFirst().trimmed(); - Q_FOREACH(const QString &head, headerList) + if( head.contains( QL1S("name") ) ) { - if( head.contains( QL1S("name") ) ) - { - // this is not so sure.. :) - suggestedFileName = head; - suggestedFileName = suggestedFileName.remove( QL1S("name=") ); - suggestedFileName = suggestedFileName.remove( '"' ); - suggestedFileName = suggestedFileName.trimmed(); - break; - } + // this is not so sure.. :) + suggestedFileName = head; + suggestedFileName = suggestedFileName.remove( QL1S("name=") ); + suggestedFileName = suggestedFileName.remove( '"' ); + suggestedFileName = suggestedFileName.trimmed(); + break; } } - else - { - mimeType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); - } - // ------------------------------------------------ - - KService::Ptr appService = KMimeTypeTrader::self()->preferredService(mimeType); - - bool isLocal = replyUrl.isLocalFile(); + } + else + { + mimeType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + } + kDebug() << "Detected MimeType = " << mimeType; + // ------------------------------------------------ + + KService::Ptr appService = KMimeTypeTrader::self()->preferredService(mimeType); - if (appService.isNull()) // no service can handle this. We can just download it.. - { - kDebug() << "no service can handle this. We can just download it.."; + bool isLocal = replyUrl.isLocalFile(); - isLocal - ? KMessageBox::sorry(view(), i18n("No service can handle this :(")) - : downloadThings(reply->request(), suggestedFileName); + if (appService.isNull()) // no service can handle this. We can just download it.. + { + kDebug() << "no service can handle this. We can just download it.."; - return; - } + isLocal + ? KMessageBox::sorry(view(), i18n("No service can handle this :(")) + : downloadThings(reply->request(), suggestedFileName); - if (!isLocal) - { + return; + } - KParts::BrowserOpenOrSaveQuestion dlg(Application::instance()->mainWindow(), replyUrl, mimeType); - if(!suggestedFileName.isEmpty()) - dlg.setSuggestedFileName(suggestedFileName); - - switch (dlg.askEmbedOrSave()) - { - case KParts::BrowserOpenOrSaveQuestion::Save: - kDebug() << "user choice: no services, just download!"; - downloadThings(reply->request(), suggestedFileName); - return; + if (!isLocal) + { - case KParts::BrowserOpenOrSaveQuestion::Cancel: - return; + KParts::BrowserOpenOrSaveQuestion dlg(Application::instance()->mainWindow(), replyUrl, mimeType); + if(!suggestedFileName.isEmpty()) + dlg.setSuggestedFileName(suggestedFileName); + + switch (dlg.askEmbedOrSave()) + { + case KParts::BrowserOpenOrSaveQuestion::Save: + kDebug() << "user choice: no services, just download!"; + downloadThings(reply->request(), suggestedFileName); + return; - default: // non extant case - break; - } - } + case KParts::BrowserOpenOrSaveQuestion::Cancel: + return; - // case KParts::BrowserRun::Embed - KService::List partServices = KMimeTypeTrader::self()->query(mimeType, QL1S("KParts/ReadOnlyPart")); - if (partServices.count() > 0) - { - QString p = replyUrl.pathOrUrl(); - - // A part can handle this. Embed it! - QString html; - html += ""; - html += ""; - html += ""; - html += p; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - - mainFrame()->setHtml(html); - _isOnRekonqPage = true; - Application::instance()->mainWindow()->mainView()->urlBar()->setQUrl(replyUrl); - Application::instance()->mainWindow()->updateActions(); - } - else - { - // No parts, just app services. Load it! - KRun::run(*appService, replyUrl, 0); + default: // non extant case + break; } + } - return; + // case KParts::BrowserRun::Embed + KService::List partServices = KMimeTypeTrader::self()->query(mimeType, QL1S("KParts/ReadOnlyPart")); + if (partServices.count() > 0) + { + QString p = replyUrl.pathOrUrl(); + + // A part can handle this. Embed it! + QString html; + html += ""; + html += ""; + html += ""; + html += p; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + + mainFrame()->setHtml(html); + _isOnRekonqPage = true; + Application::instance()->mainWindow()->mainView()->urlBar()->setQUrl(replyUrl); + Application::instance()->mainWindow()->updateActions(); + } + else + { + // No parts, just app services. Load it! + KRun::run(*appService, replyUrl, 0); } + + return; } -- cgit v1.2.1