From 2abe5fa9ef89eda285770598afba80eddfa65edb Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 17 Apr 2013 22:00:02 +0200 Subject: [PATCH 1/2] Do yet another attempt at finding the correct mimetype Makes okular http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/digital-editions/assets/welcome.epub work --- core/document.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/document.cpp b/core/document.cpp index d9b7998a7..2517461f0 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1859,6 +1859,18 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi mime = newmime; offers = KMimeTypeTrader::self()->query( mime->name(), "okular/Generator", constraint ); } + if ( offers.isEmpty() ) + { + // There's still no offers, do a final mime search based on the filename + // We need this becuase sometimes (e.g. when downloading from a webserver) the mimetype we + // use is the one feeded by the server, that may be wrong + newmime = KMimeType::findByUrl( docFile ); + if ( newmime->name() != mime->name() ) + { + mime = newmime; + offers = KMimeTypeTrader::self()->query( mime->name(), "okular/Generator", constraint ); + } + } } if (offers.isEmpty()) { From f7b742af0d7a10c699725a8a184f4ad935ad69d2 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 17 Apr 2013 22:13:02 +0200 Subject: [PATCH 2/2] Rename the variable Makes it easier to understand, imho --- core/document.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 2517461f0..51b4735c7 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1797,7 +1797,7 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi QByteArray filedata; qint64 document_size = -1; bool isstdin = url.fileName( KUrl::ObeyTrailingSlash ) == QLatin1String( "-" ); - bool loadingMimeByContent = false; + bool triedMimeFromFileContent = false; if ( !isstdin ) { if ( mime.count() <= 0 ) @@ -1843,17 +1843,17 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi if ( !mime || mime->name() == QLatin1String( "application/octet-stream" ) ) return false; document_size = filedata.size(); - loadingMimeByContent = true; + triedMimeFromFileContent = true; } // 0. load Generator // request only valid non-disabled plugins suitable for the mimetype QString constraint("([X-KDE-Priority] > 0) and (exist Library)") ; KService::List offers = KMimeTypeTrader::self()->query(mime->name(),"okular/Generator",constraint); - if ( offers.isEmpty() && !isstdin ) + if ( offers.isEmpty() && !triedMimeFromFileContent ) { KMimeType::Ptr newmime = KMimeType::findByFileContent( docFile ); - loadingMimeByContent = true; + triedMimeFromFileContent = true; if ( newmime->name() != mime->name() ) { mime = newmime; @@ -1906,10 +1906,10 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi KService::Ptr offer = offers.at( hRank ); // 1. load Document bool openOk = d->openDocumentInternal( offer, isstdin, docFile, filedata ); - if ( !openOk && !loadingMimeByContent ) + if ( !openOk && !triedMimeFromFileContent ) { KMimeType::Ptr newmime = KMimeType::findByFileContent( docFile ); - loadingMimeByContent = true; + triedMimeFromFileContent = true; if ( newmime->name() != mime->name() ) { mime = newmime;