Reactivate it

frameworks
Montel Laurent 11 years ago
parent 855d2df586
commit 778f5bb9cb
  1. 2
      generators/chm/CMakeLists.txt
  2. 4
      generators/chm/kio-msits/CMakeLists.txt
  3. 23
      generators/chm/kio-msits/kio_mits_debug.cpp
  4. 27
      generators/chm/kio-msits/kio_mits_debug.h
  5. 64
      generators/chm/kio-msits/msits.cpp

@ -1,4 +1,4 @@
#add_subdirectory( kio-msits ) add_subdirectory( kio-msits )
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_SOURCE_DIR}/../..

@ -7,12 +7,12 @@ include_directories(
########### next target ############### ########### next target ###############
set(kio_msits_PART_SRCS msits.cpp ) set(kio_msits_PART_SRCS msits.cpp kio_mits_debug.cpp)
add_library(kio_msits MODULE ${kio_msits_PART_SRCS}) add_library(kio_msits MODULE ${kio_msits_PART_SRCS})
target_link_libraries(kio_msits KF5::KIOCore ${CHM_LIBRARY} ) target_link_libraries(kio_msits KF5::KIOCore Qt5::Core ${CHM_LIBRARY} )
install(TARGETS kio_msits DESTINATION ${KDE_INSTALL_PLUGINDIR} ) install(TARGETS kio_msits DESTINATION ${KDE_INSTALL_PLUGINDIR} )

@ -0,0 +1,23 @@
/* This file is part of the KDE project
Copyright (C) 2014 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kio_mits_debug.h"
Q_LOGGING_CATEGORY(KIO_MITS_LOG, "log_kio_msits")

@ -0,0 +1,27 @@
/* This file is part of the KDE project
Copyright (C) 2014 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KIO_MITS_DEBUG_H
#define KIO_MITS_DEBUG_H
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(KIO_MITS_LOG)
#endif

@ -18,8 +18,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <kapplication.h> #include <qcoreapplication.h>
#include <QDebug> #include "kio_mits_debug.h"
#include <QUrl> #include <QUrl>
#include <QMimeType> #include <QMimeType>
#include <QMimeDatabase> #include <QMimeDatabase>
@ -38,20 +38,21 @@ extern "C"
{ {
int Q_DECL_EXPORT kdemain( int argc, char **argv ) int Q_DECL_EXPORT kdemain( int argc, char **argv )
{ {
kDebug() << "*** kio_msits Init"; qCDebug(KIO_MITS_LOG) << "*** kio_msits Init";
KComponentData instance( "kio_msits" ); QCoreApplication app(argc, argv);
app.setApplicationName(QLatin1String("kio_msits"));
if ( argc != 4 ) if ( argc != 4 )
{ {
kDebug() << "Usage: kio_msits protocol domain-socket1 domain-socket2"; qCDebug(KIO_MITS_LOG) << "Usage: kio_msits protocol domain-socket1 domain-socket2";
exit (-1); exit (-1);
} }
ProtocolMSITS slave ( argv[2], argv[3] ); ProtocolMSITS slave ( argv[2], argv[3] );
slave.dispatchLoop(); slave.dispatchLoop();
kDebug() << "*** kio_msits Done"; qCDebug(KIO_MITS_LOG) << "*** kio_msits Done";
return 0; return 0;
} }
} }
@ -84,30 +85,30 @@ void ProtocolMSITS::get( const QUrl& url )
chmUnitInfo ui; chmUnitInfo ui;
QByteArray buf; QByteArray buf;
kDebug() << "kio_msits::get() " << url.path(); qCDebug(KIO_MITS_LOG) << "kio_msits::get() " << url.path();
if ( !parseLoadAndLookup ( url, fileName ) ) if ( !parseLoadAndLookup ( url, fileName ) )
return; // error() has been called by parseLoadAndLookup return; // error() has been called by parseLoadAndLookup
kDebug() << "kio_msits::get: parseLoadAndLookup returned " << fileName; qCDebug(KIO_MITS_LOG) << "kio_msits::get: parseLoadAndLookup returned " << fileName;
if ( LCHMUrlFactory::handleFileType( url.path(), htmdata ) ) if ( LCHMUrlFactory::handleFileType( url.path(), htmdata ) )
{ {
buf = htmdata.toUtf8(); buf = htmdata.toUtf8();
kDebug() << "Using special handling for image pages: " << htmdata; qCDebug(KIO_MITS_LOG) << "Using special handling for image pages: " << htmdata;
} }
else else
{ {
if ( isDirectory (fileName) ) if ( isDirectory (fileName) )
{ {
error( KIO::ERR_IS_DIRECTORY, url.prettyUrl() ); error( KIO::ERR_IS_DIRECTORY, url.toString() );
return; return;
} }
if ( !ResolveObject ( fileName, &ui) ) if ( !ResolveObject ( fileName, &ui) )
{ {
kDebug() << "kio_msits::get: could not resolve filename " << fileName; qCDebug(KIO_MITS_LOG) << "kio_msits::get: could not resolve filename " << fileName;
error( KIO::ERR_DOES_NOT_EXIST, url.prettyUrl() ); error( KIO::ERR_DOES_NOT_EXIST, url.toString() );
return; return;
} }
@ -115,17 +116,20 @@ void ProtocolMSITS::get( const QUrl& url )
if ( RetrieveObject (&ui, (unsigned char*) buf.data(), 0, ui.length) == 0 ) if ( RetrieveObject (&ui, (unsigned char*) buf.data(), 0, ui.length) == 0 )
{ {
kDebug() << "kio_msits::get: could not retrieve filename " << fileName; qCDebug(KIO_MITS_LOG) << "kio_msits::get: could not retrieve filename " << fileName;
error( KIO::ERR_NO_CONTENT, url.prettyUrl() ); error( KIO::ERR_NO_CONTENT, url.toString() );
return; return;
} }
} }
totalSize( buf.size() ); totalSize( buf.size() );
#if 0 //PORT QT5
QMimeDatabase db;
QMimeType result = db.mimeTypeForNameAndData( fileName, buf ); QMimeType result = db.mimeTypeForNameAndData( fileName, buf );
kDebug() << "Emitting mimetype " << result->name(); qCDebug(KIO_MITS_LOG) << "Emitting mimetype " << result.name();
mimeType( result->name() ); mimeType( result.name() );
#endif
data( buf ); data( buf );
processedSize( buf.size() ); processedSize( buf.size() );
@ -135,13 +139,13 @@ void ProtocolMSITS::get( const QUrl& url )
bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath ) bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath )
{ {
kDebug() << "ProtocolMSITS::parseLoadAndLookup (const KUrl&) " << url.path(); qCDebug(KIO_MITS_LOG) << "ProtocolMSITS::parseLoadAndLookup (const KUrl&) " << url.path();
int pos = url.path().indexOf ("::"); int pos = url.path().indexOf ("::");
if ( pos == -1 ) if ( pos == -1 )
{ {
error( KIO::ERR_MALFORMED_URL, url.prettyUrl() ); error( KIO::ERR_MALFORMED_URL, url.toString() );
return false; return false;
} }
@ -152,11 +156,11 @@ bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath )
if ( abspath.startsWith( "ms-its:" ) ) if ( abspath.startsWith( "ms-its:" ) )
abspath = abspath.mid( 7 ); abspath = abspath.mid( 7 );
kDebug() << "ProtocolMSITS::parseLoadAndLookup: filename " << filename << ", path " << abspath; qCDebug(KIO_MITS_LOG) << "ProtocolMSITS::parseLoadAndLookup: filename " << filename << ", path " << abspath;
if ( filename.isEmpty() ) if ( filename.isEmpty() )
{ {
error( KIO::ERR_MALFORMED_URL, url.prettyUrl() ); error( KIO::ERR_MALFORMED_URL, url.toString() );
return false; return false;
} }
@ -164,14 +168,14 @@ bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath )
if ( m_chmFile && filename == m_openedFile ) if ( m_chmFile && filename == m_openedFile )
return true; return true;
kDebug() << "Opening a new CHM file " << QFile::encodeName( QDir::toNativeSeparators( filename ) ); qCDebug(KIO_MITS_LOG) << "Opening a new CHM file " << QFile::encodeName( QDir::toNativeSeparators( filename ) );
// First try to open a temporary file // First try to open a temporary file
chmFile * tmpchm; chmFile * tmpchm;
if( (tmpchm = chm_open ( QFile::encodeName( QDir::toNativeSeparators( filename) ) ) ) == 0 ) if( (tmpchm = chm_open ( QFile::encodeName( QDir::toNativeSeparators( filename) ).constData() ) ) == 0 )
{ {
error( KIO::ERR_COULD_NOT_READ, url.prettyUrl() ); error( KIO::ERR_COULD_NOT_READ, url.toString() );
return false; return false;
} }
@ -182,7 +186,7 @@ bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath )
m_chmFile = tmpchm; m_chmFile = tmpchm;
m_openedFile = filename; m_openedFile = filename;
kDebug() << "A CHM file " << filename << " has beed opened successfully"; qCDebug(KIO_MITS_LOG) << "A CHM file " << filename << " has beed opened successfully";
return true; return true;
} }
@ -225,18 +229,18 @@ void ProtocolMSITS::stat (const QUrl &url)
QString fileName; QString fileName;
chmUnitInfo ui; chmUnitInfo ui;
kDebug() << "kio_msits::stat (const KUrl& url) " << url.path(); qCDebug(KIO_MITS_LOG) << "kio_msits::stat (const KUrl& url) " << url.path();
if ( !parseLoadAndLookup ( url, fileName ) ) if ( !parseLoadAndLookup ( url, fileName ) )
return; // error() has been called by parseLoadAndLookup return; // error() has been called by parseLoadAndLookup
if ( !ResolveObject ( fileName, &ui ) ) if ( !ResolveObject ( fileName, &ui ) )
{ {
error( KIO::ERR_DOES_NOT_EXIST, url.prettyUrl() ); error( KIO::ERR_DOES_NOT_EXIST, url.toString() );
return; return;
} }
kDebug() << "kio_msits::stat: adding an entry for " << fileName; qCDebug(KIO_MITS_LOG) << "kio_msits::stat: adding an entry for " << fileName;
UDSEntry entry; UDSEntry entry;
if ( isDirectory ( fileName ) ) if ( isDirectory ( fileName ) )
@ -262,7 +266,7 @@ void ProtocolMSITS::listDir (const QUrl & url)
{ {
QString filepath; QString filepath;
kDebug() << "kio_msits::listDir (const KUrl& url) " << url.path(); qCDebug(KIO_MITS_LOG) << "kio_msits::listDir (const KUrl& url) " << url.path();
if ( !parseLoadAndLookup ( url, filepath ) ) if ( !parseLoadAndLookup ( url, filepath ) )
return; // error() has been called by parseLoadAndLookup return; // error() has been called by parseLoadAndLookup
@ -275,12 +279,12 @@ void ProtocolMSITS::listDir (const QUrl & url)
return; return;
} }
kDebug() << "kio_msits::listDir: enumerating directory " << filepath; qCDebug(KIO_MITS_LOG) << "kio_msits::listDir: enumerating directory " << filepath;
QVector<QString> listing; QVector<QString> listing;
if ( chm_enumerate_dir ( m_chmFile, if ( chm_enumerate_dir ( m_chmFile,
filepath.toLocal8Bit(), filepath.toLocal8Bit().constData(),
CHM_ENUMERATE_NORMAL | CHM_ENUMERATE_FILES | CHM_ENUMERATE_DIRS, CHM_ENUMERATE_NORMAL | CHM_ENUMERATE_FILES | CHM_ENUMERATE_DIRS,
chmlib_enumerator, chmlib_enumerator,
&listing ) != 1 ) &listing ) != 1 )

Loading…
Cancel
Save