diff --git a/generators/chm/kio-msits/CMakeLists.txt b/generators/chm/kio-msits/CMakeLists.txt index b36407a39..5b50c878b 100644 --- a/generators/chm/kio-msits/CMakeLists.txt +++ b/generators/chm/kio-msits/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../.. + ${CMAKE_CURRENT_SOURCE_DIR}/../lib ${CHM_INCLUDE_DIR} ) diff --git a/generators/chm/kio-msits/msits.cpp b/generators/chm/kio-msits/msits.cpp index 5a8c5bc0a..22db86fdb 100644 --- a/generators/chm/kio-msits/msits.cpp +++ b/generators/chm/kio-msits/msits.cpp @@ -19,18 +19,16 @@ #include #include -#include #include #include #include -#include #include #include #include #include "msits.h" - +#include "libchmurlfactory.h" using namespace KIO; @@ -80,8 +78,9 @@ static bool isDirectory ( const QString & filename ) void ProtocolMSITS::get( const KUrl& url ) { - QString fileName; + QString htmdata, fileName; chmUnitInfo ui; + QByteArray buf; kDebug() << "kio_msits::get() " << url.path(); @@ -90,35 +89,43 @@ void ProtocolMSITS::get( const KUrl& url ) kDebug() << "kio_msits::get: parseLoadAndLookup returned " << fileName; - if ( isDirectory (fileName) ) + if ( LCHMUrlFactory::handleFileType( url.path(), htmdata ) ) { - error( KIO::ERR_IS_DIRECTORY, url.prettyUrl() ); - return; + buf = htmdata.toUtf8(); + kDebug() << "Using special handling for image pages: " << htmdata; } - - if ( !ResolveObject ( fileName, &ui) ) + else { - kDebug() << "kio_msits::get: could not resolve filename " << fileName; - error( KIO::ERR_DOES_NOT_EXIST, url.prettyUrl() ); - return; - } + if ( isDirectory (fileName) ) + { + error( KIO::ERR_IS_DIRECTORY, url.prettyUrl() ); + return; + } - QByteArray buf (ui.length, '\0'); + if ( !ResolveObject ( fileName, &ui) ) + { + kDebug() << "kio_msits::get: could not resolve filename " << fileName; + error( KIO::ERR_DOES_NOT_EXIST, url.prettyUrl() ); + return; + } - if ( RetrieveObject (&ui, (unsigned char*) buf.data(), 0, ui.length) == 0 ) - { - kDebug() << "kio_msits::get: could not retrieve filename " << fileName; - error( KIO::ERR_NO_CONTENT, url.prettyUrl() ); - return; + buf.resize( ui.length ); + + if ( RetrieveObject (&ui, (unsigned char*) buf.data(), 0, ui.length) == 0 ) + { + kDebug() << "kio_msits::get: could not retrieve filename " << fileName; + error( KIO::ERR_NO_CONTENT, url.prettyUrl() ); + return; + } } - totalSize( ui.length ); + totalSize( buf.size() ); KMimeType::Ptr result = KMimeType::findByNameAndContent( fileName, buf ); kDebug() << "Emitting mimetype " << result->name(); mimeType( result->name() ); data( buf ); - processedSize( ui.length ); + processedSize( buf.size() ); finished(); } @@ -138,7 +145,11 @@ bool ProtocolMSITS::parseLoadAndLookup ( const KUrl& url, QString& abspath ) QString filename = url.path().left (pos); abspath = url.path().mid (pos + 2); // skip :: - + + // Some buggy apps add ms-its:/ to the path as well + if ( abspath.startsWith( "ms-its:" ) ) + abspath = abspath.mid( 7 ); + kDebug() << "ProtocolMSITS::parseLoadAndLookup: filename " << filename << ", path " << abspath; if ( filename.isEmpty() ) @@ -276,7 +287,6 @@ void ProtocolMSITS::listDir (const KUrl & url) return; } -// totalFiles(listing.size()); UDSEntry entry; int striplength = filepath.length(); diff --git a/generators/chm/kio-msits/msits.h b/generators/chm/kio-msits/msits.h index ba8a589c2..4d147cf29 100644 --- a/generators/chm/kio-msits/msits.h +++ b/generators/chm/kio-msits/msits.h @@ -22,7 +22,6 @@ #define MSITS_H -//#include #include #include @@ -52,7 +51,7 @@ private: // Resolve an object inside a CHM file inline bool ResolveObject (const QString& fileName, chmUnitInfo *ui) { - return m_chmFile != NULL && ::chm_resolve_object(m_chmFile, fileName.toAscii().constData(), ui) == CHM_RESOLVE_SUCCESS; + return m_chmFile != NULL && ::chm_resolve_object(m_chmFile, fileName.toUtf8().constData(), ui) == CHM_RESOLVE_SUCCESS; } // Retrieve an object from the CHM file