From 10fab8b8e0132c7e3a0273751861610a8c55d665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Tue, 3 Sep 2013 19:56:53 +0200 Subject: Additional k => tde renaming and fixes --- FAQ | 2 +- README | 4 +- acinclude.m4 | 24 +-- admin | 2 +- lib/Makefile.am | 8 +- lib/kio-msits/Makefile.am | 14 -- lib/kio-msits/kchmviewer.desktop | 11 -- lib/kio-msits/msits.cpp | 320 ------------------------------------- lib/kio-msits/msits.h | 79 --------- lib/kio-msits/msits.protocol | 24 --- lib/libchmfile/libchmurlfactory.h | 2 +- lib/tdeio-msits/Makefile.am | 14 ++ lib/tdeio-msits/kchmviewer.desktop | 11 ++ lib/tdeio-msits/msits.cpp | 320 +++++++++++++++++++++++++++++++++++++ lib/tdeio-msits/msits.h | 79 +++++++++ lib/tdeio-msits/msits.protocol | 24 +++ src/Makefile.am | 4 +- src/kchmviewwindow.cpp | 2 +- 18 files changed, 472 insertions(+), 472 deletions(-) delete mode 100644 lib/kio-msits/Makefile.am delete mode 100644 lib/kio-msits/kchmviewer.desktop delete mode 100755 lib/kio-msits/msits.cpp delete mode 100755 lib/kio-msits/msits.h delete mode 100755 lib/kio-msits/msits.protocol create mode 100644 lib/tdeio-msits/Makefile.am create mode 100644 lib/tdeio-msits/kchmviewer.desktop create mode 100755 lib/tdeio-msits/msits.cpp create mode 100755 lib/tdeio-msits/msits.h create mode 100755 lib/tdeio-msits/msits.protocol diff --git a/FAQ b/FAQ index 6cca480..09ea758 100644 --- a/FAQ +++ b/FAQ @@ -4,7 +4,7 @@ Q: The book shows without any problem using QTextWidget browser, but when I use An error occurred while loading ms-its:/home/user/SymphonyFrameWork.chm::/index.html Thefileorfolderms-its:/home/user/SymphonyFrameWork.chm::/index.htmldoesnotexist. -A: You have tdeio_chm installed, and because it installs itself as KIO slave for ms-its, sometime KDE uses it instead of tdeio_msits. +A: You have tdeio_chm installed, and because it installs itself as TDEIO slave for ms-its, sometime KDE uses it instead of tdeio_msits. To disable it, find the file chm.protocol in your KDE directory, and remove it. Then run tdeinit to reread the configuration. diff --git a/README b/README index 218c864..c68e440 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ KchmViewer is a chm (MS HTML help file format) viewer, written in C++. Unlike most existing CHM viewers for Unix, it uses Trolltech Qt widget library, and does not depend on KDE or Gnome. However, it may be compiled with full - KDE support, including KDE widgets and KIO/TDEHTML. + KDE support, including KDE widgets and TDEIO/TDEHTML. The main advantage of KchmViewer is extended support for non-English languages. Unlike others, KchmViewer in most cases correctly detects chm file encoding, correctly shows tables of context of Russian, Korean, Chinese and @@ -15,7 +15,7 @@ 2. FEATURES - Standalone viewer, depends on Qt only. Does not require KDE, Gnome or wxWindows toolkit. - - A KDE viewer can be compiled optionally, with KIO slave, TDEHTML and K*Widget support. + - A KDE viewer can be compiled optionally, with TDEIO slave, TDEHTML and K*Widget support. - Completely safe and harmless. Does not support JavaScript in any way, optionally warns you before opening an external web page, or switching to another help file. - Correctly detects and shows encoding of any valid chm file. diff --git a/acinclude.m4 b/acinclude.m4 index b6e2124..f598aa8 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -2070,35 +2070,35 @@ if test $kde_qtver = 3; then AC_SUBST(LIB_KDED, $lib_kded) AC_SUBST(LIB_TDECORE, "-ltdecore") AC_SUBST(LIB_TDEUI, "-ltdeui") - AC_SUBST(LIB_KIO, "-ltdeio") + AC_SUBST(LIB_TDEIO, "-ltdeio") AC_SUBST(LIB_KJS, "-lkjs") AC_SUBST(LIB_SMB, "-lsmb") AC_SUBST(LIB_KAB, "-lkab") AC_SUBST(LIB_TDEABC, "-ltdeabc") AC_SUBST(LIB_TDEHTML, "-ltdehtml") - AC_SUBST(LIB_KSPELL, "-ltdespell") - AC_SUBST(LIB_KPARTS, "-ltdeparts") + AC_SUBST(LIB_TDESPELL, "-ltdespell") + AC_SUBST(LIB_TDEPARTS, "-ltdeparts") AC_SUBST(LIB_TDEPRINT, "-ltdeprint") - AC_SUBST(LIB_KUTILS, "-ltdeutils") + AC_SUBST(LIB_TDEUTILS, "-ltdeutils") AC_SUBST(LIB_TDEPIM, "-ltdepim") - AC_SUBST(LIB_KIMPROXY, "-ltdeimproxy") + AC_SUBST(LIB_TDEIMPROXY, "-ltdeimproxy") AC_SUBST(LIB_KNEWSTUFF, "-lknewstuff") - AC_SUBST(LIB_KDNSSD, "-ltdednssd") - AC_SUBST(LIB_KUNITTEST, "-ltdeunittest") + AC_SUBST(LIB_TDEDNSSD, "-ltdednssd") + AC_SUBST(LIB_TDEUNITTEST, "-ltdeunittest") # these are for backward compatibility - AC_SUBST(LIB_KSYCOCA, "-ltdeio") + AC_SUBST(LIB_TDESYCOCA, "-ltdeio") AC_SUBST(LIB_TDEFILE, "-ltdeio") elif test $kde_qtver = 2; then AC_SUBST(LIB_TDECORE, "-ltdecore") AC_SUBST(LIB_TDEUI, "-ltdeui") - AC_SUBST(LIB_KIO, "-ltdeio") - AC_SUBST(LIB_KSYCOCA, "-ltdesycoca") + AC_SUBST(LIB_TDEIO, "-ltdeio") + AC_SUBST(LIB_TDESYCOCA, "-ltdesycoca") AC_SUBST(LIB_SMB, "-lsmb") AC_SUBST(LIB_TDEFILE, "-ltdefile") AC_SUBST(LIB_KAB, "-lkab") AC_SUBST(LIB_TDEHTML, "-ltdehtml") - AC_SUBST(LIB_KSPELL, "-ltdespell") - AC_SUBST(LIB_KPARTS, "-ltdeparts") + AC_SUBST(LIB_TDESPELL, "-ltdespell") + AC_SUBST(LIB_TDEPARTS, "-ltdeparts") AC_SUBST(LIB_TDEPRINT, "-ltdeprint") else AC_SUBST(LIB_TDECORE, "-ltdecore -lXext $(LIB_QT)") diff --git a/admin b/admin index b4d585c..6b7f722 160000 --- a/admin +++ b/admin @@ -1 +1 @@ -Subproject commit b4d585c643d92787bfa17b935ce00b09960ee360 +Subproject commit 6b7f7225eff4c49b2dd71804d5fdacb03efcf461 diff --git a/lib/Makefile.am b/lib/Makefile.am index 696d2a8..fcf2131 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,17 +1,17 @@ if AMC_USE_KDE -SUBDIR_KIO = kio-msits +SUBDIR_TDEIO = tdeio-msits endif if AMC_BUILD_CHMLIB SUBDIR_CHMLIB = chmlib endif -SUBDIRS = $(SUBDIR_CHMLIB) $(SUBDIR_KIO) libchmfile -DIST_SUBDIRS = chmlib kio-msits libchmfile +SUBDIRS = $(SUBDIR_CHMLIB) $(SUBDIR_TDEIO) libchmfile +DIST_SUBDIRS = chmlib tdeio-msits libchmfile package-messages: $(MAKE) -f admin/Makefile.common package-messages $(MAKE) -C po merge # Uncomment this line before opening the project in tdevelop for the first time! -#SUBDIRS = chmlib kio-msits libchmfile +#SUBDIRS = chmlib tdeio-msits libchmfile diff --git a/lib/kio-msits/Makefile.am b/lib/kio-msits/Makefile.am deleted file mode 100644 index 9bd5cff..0000000 --- a/lib/kio-msits/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -METASOURCES = AUTO -INCLUDES = $(QT_INCLUDES) $(CHM_INCLUDES) $(KDE_INCLUDES) $(LIBCHMFILE_INCLUDES) - -kde_module_LTLIBRARIES = tdeio_msits.la - -tdeio_msits_la_SOURCES = msits.cpp -tdeio_msits_la_LIBADD = -ltdeio $(CHM_LIBS) -tdeio_msits_la_LDFLAGS = -module -avoid-version $(KDE_LDFLAGS) $(LIB_QT) $(LIB_KIO) $(LIB_TDECORE) $(KDE_PLUGIN) $(QT_LDFLAGS) - -protocol_DATA = msits.protocol -protocoldir = $(kde_servicesdir) - -# Put it here to avoid creating another directory -kde_apps_DATA = kchmviewer.desktop diff --git a/lib/kio-msits/kchmviewer.desktop b/lib/kio-msits/kchmviewer.desktop deleted file mode 100644 index 31558d8..0000000 --- a/lib/kio-msits/kchmviewer.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Categories=Qt;TDE;Utility; -Encoding=UTF-8 -Type=Application -Exec=kchmviewer %U -Icon=kchmviewer -Terminal=0 -Name=KchmViewer -GenericName=CHM (MS-Help) Viewer -Comment=A viewer for CHM (MS-Help) files -MimeType=application/chm diff --git a/lib/kio-msits/msits.cpp b/lib/kio-msits/msits.cpp deleted file mode 100755 index 3e847f1..0000000 --- a/lib/kio-msits/msits.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "msits.h" -#include "libchmurlfactory.h" - -using namespace TDEIO; - -extern "C" -{ - int kdemain( int argc, char **argv ) - { - kdDebug() << "*** tdeio_msits Init" << endl; - - TDEInstance instance( "tdeio_msits" ); - - if ( argc != 4 ) - { - kdDebug() << "Usage: tdeio_msits protocol domain-socket1 domain-socket2" << endl; - exit (-1); - } - - ProtocolMSITS slave ( argv[2], argv[3] ); - slave.dispatchLoop(); - - kdDebug() << "*** tdeio_msits Done" << endl; - return 0; - } -} - -ProtocolMSITS::ProtocolMSITS (const TQCString &pool_socket, const TQCString &app_socket) - : SlaveBase ("tdeio_msits", pool_socket, app_socket) -{ - m_chmFile = 0; -} - -ProtocolMSITS::~ProtocolMSITS() -{ - if ( !m_chmFile ) - return; - - chm_close (m_chmFile); - m_chmFile = 0; -} - -// A simple stat() wrapper -static bool isDirectory ( const TQString & filename ) -{ - return filename[filename.length() - 1] == '/'; -} - - -void ProtocolMSITS::get( const KURL& url ) -{ - TQString htmdata, fileName; - chmUnitInfo ui; - TQByteArray buf; - - kdDebug() << "tdeio_msits::get() " << url.path() << endl; - - if ( !parseLoadAndLookup ( url, fileName ) ) - return; // error() has been called by parseLoadAndLookup - - kdDebug() << "tdeio_msits::get: parseLoadAndLookup returned " << fileName << endl; - - if ( LCHMUrlFactory::handleFileType( url.path(), htmdata ) ) - { - buf = htmdata.utf8(); - kdDebug() << "Using special handling for image pages: " << htmdata << endl; - } - else - { - if ( isDirectory (fileName) ) - { - error( TDEIO::ERR_IS_DIRECTORY, url.prettyURL() ); - return; - } - - if ( !ResolveObject ( fileName, &ui) ) - { - kdDebug() << "tdeio_msits::get: could not resolve filename " << fileName << endl; - error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL() ); - return; - } - - buf.resize( ui.length ); - - if ( RetrieveObject (&ui, (unsigned char*) buf.data(), 0, ui.length) == 0 ) - { - kdDebug() << "tdeio_msits::get: could not retrieve filename " << fileName << endl; - error( TDEIO::ERR_NO_CONTENT, url.prettyURL() ); - return; - } - } - - totalSize( buf.size() ); - KMimeMagicResult * result = KMimeMagic::self()->findBufferFileType( buf, fileName ); - kdDebug() << "Emitting mimetype " << result->mimeType() << endl; - - mimeType( result->mimeType() ); - data( buf ); - processedSize( buf.size() ); - - finished(); -} - - -bool ProtocolMSITS::parseLoadAndLookup ( const KURL& url, TQString& abspath ) -{ - kdDebug() << "ProtocolMSITS::parseLoadAndLookup (const KURL&) " << url.path() << endl; - - int pos = url.path().find ("::"); - - if ( pos == -1 ) - { - error( TDEIO::ERR_MALFORMED_URL, url.prettyURL() ); - return false; - } - - TQString 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 ); - - kdDebug() << "ProtocolMSITS::parseLoadAndLookup: filename " << filename << ", path " << abspath << endl; - - if ( filename.isEmpty() ) - { - error( TDEIO::ERR_MALFORMED_URL, url.prettyURL() ); - return false; - } - - // If the file has been already loaded, nothing to do. - if ( m_chmFile && filename == m_openedFile ) - return true; - - kdDebug() << "Opening a new CHM file " << filename << endl; - - // First try to open a temporary file - chmFile * tmpchm; - - if ( (tmpchm = chm_open ( TQFile::encodeName (filename))) == 0 ) - { - error( TDEIO::ERR_COULD_NOT_READ, url.prettyURL() ); - return false; - } - - // Replace an existing file by a new one - if ( m_chmFile ) - chm_close (m_chmFile); - - m_chmFile = tmpchm; - m_openedFile = filename; - - kdDebug() << "A CHM file " << filename << " has beed opened successfully" << endl; - return true; -} - -/* - * Shamelessly stolen from a KDE KIO tutorial - */ -static void app_entry(UDSEntry& e, unsigned int uds, const TQString& str) -{ - UDSAtom a; - a.m_uds = uds; - a.m_str = str; - e.append(a); -} - - // appends an int with the UDS-ID uds - static void app_entry(UDSEntry& e, unsigned int uds, long l) - { - UDSAtom a; - a.m_uds = uds; - a.m_long = l; - e.append(a); -} - -// internal function -// fills a directory item with its name and size -static void app_dir(UDSEntry& e, const TQString & name) -{ - e.clear(); - app_entry(e, TDEIO::UDS_NAME, name); - app_entry(e, TDEIO::UDS_FILE_TYPE, S_IFDIR); - app_entry(e, TDEIO::UDS_SIZE, 1); -} - -// internal function -// fills a file item with its name and size -static void app_file(UDSEntry& e, const TQString & name, size_t size) -{ - e.clear(); - app_entry(e, TDEIO::UDS_NAME, name); - app_entry(e, TDEIO::UDS_FILE_TYPE, S_IFREG); - app_entry(e, TDEIO::UDS_SIZE, size); -} - -void ProtocolMSITS::stat (const KURL & url) -{ - TQString fileName; - chmUnitInfo ui; - - kdDebug() << "tdeio_msits::stat (const KURL& url) " << url.path() << endl; - - if ( !parseLoadAndLookup ( url, fileName ) ) - return; // error() has been called by parseLoadAndLookup - - if ( !ResolveObject ( fileName, &ui ) ) - { - error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL() ); - return; - } - - kdDebug() << "tdeio_msits::stat: adding an entry for " << fileName << endl; - UDSEntry entry; - - if ( isDirectory ( fileName ) ) - app_dir(entry, fileName); - else - app_file(entry, fileName, ui.length); - - statEntry (entry); - - finished(); -} - - -// A local CHMLIB enumerator -static int chmlib_enumerator (struct chmFile *, struct chmUnitInfo *ui, void *context) -{ - ((TQValueVector *) context)->push_back (TQString::fromLocal8Bit (ui->path)); - return CHM_ENUMERATOR_CONTINUE; -} - - -void ProtocolMSITS::listDir (const KURL & url) -{ - TQString filepath; - - kdDebug() << "tdeio_msits::listDir (const KURL& url) " << url.path() << endl; - - if ( !parseLoadAndLookup ( url, filepath ) ) - return; // error() has been called by parseLoadAndLookup - - filepath += "/"; - - if ( !isDirectory (filepath) ) - { - error(TDEIO::ERR_CANNOT_ENTER_DIRECTORY, url.path()); - return; - } - - kdDebug() << "tdeio_msits::listDir: enumerating directory " << filepath << endl; - - TQValueVector listing; - - if ( chm_enumerate_dir ( m_chmFile, - filepath.local8Bit(), - CHM_ENUMERATE_NORMAL | CHM_ENUMERATE_FILES | CHM_ENUMERATE_DIRS, - chmlib_enumerator, - &listing ) != 1 ) - { - error(TDEIO::ERR_CANNOT_ENTER_DIRECTORY, url.path()); - return; - } - - UDSEntry entry; - unsigned int striplength = filepath.length(); - - for ( unsigned int i = 0; i < listing.size(); i++ ) - { - // Strip the direcroty name - TQString ename = listing[i].mid (striplength); - - if ( isDirectory ( ename ) ) - app_dir(entry, ename); - else - app_file(entry, ename, 0); - - listEntry(entry, false); - } - - listEntry(entry, true); - finished(); -} diff --git a/lib/kio-msits/msits.h b/lib/kio-msits/msits.h deleted file mode 100755 index 4248908..0000000 --- a/lib/kio-msits/msits.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2005 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef MSITS_H -#define MSITS_H - - -#include -#include - -#include -#include - -#include "config.h" -#include "chm_lib.h" - - -class ProtocolMSITS : public TDEIO::SlaveBase -{ -public: - ProtocolMSITS ( const TQCString&, const TQCString& ); - virtual ~ProtocolMSITS(); - - virtual void get ( const KURL& ); - virtual void listDir (const KURL & url); - virtual void stat (const KURL & url); - -private: - // This function does next thing: - // - parses the URL to get a file name and URL inside the file; - // - loads a new CHM file, if needed; - // - returns the parsed URL inside the file; - bool parseLoadAndLookup ( const KURL&, TQString& abspath ); - - // Resolve an object inside a CHM file - inline bool ResolveObject (const TQString& fileName, chmUnitInfo *ui) - { - return m_chmFile != NULL && ::chm_resolve_object(m_chmFile, fileName.utf8(), ui) == CHM_RESOLVE_SUCCESS; - } - - // Retrieve an object from the CHM file - inline size_t RetrieveObject (const chmUnitInfo *ui, unsigned char *buffer, LONGUINT64 fileOffset, LONGINT64 bufferSize) - { -#if USE_BUILTIN_CHMLIB - return ::chm_retrieve_object(m_chmFile, ui, buffer, - fileOffset, bufferSize); -#else - return ::chm_retrieve_object(m_chmFile, const_cast(ui), - buffer, fileOffset, bufferSize); -#endif - } - - // An opened file name, if presend - TQString m_openedFile; - - // a CHM structure file pointer (from chmlib) - chmFile * m_chmFile; -}; - - -#endif /* MSITS_H */ diff --git a/lib/kio-msits/msits.protocol b/lib/kio-msits/msits.protocol deleted file mode 100755 index bc1d65f..0000000 --- a/lib/kio-msits/msits.protocol +++ /dev/null @@ -1,24 +0,0 @@ -[Protocol] -exec=tdeio_msits -protocol=ms-its -input=none -output=filesystem -reading=true -listing=Name,Type,Size -defaultMimetype=text/html -Description=A tdeioslave for displaying WinHelp files -Description[da]=En tdeioslave til visning af Windows hjælpefiler -Description[de]=Ein Ein-/Ausgabemodul zur Anzeige von WinHelp-Dateien -Description[es]=Un tdeioslave para mostrar archivos WinHelp -Description[et]=WinHelp-failide kuvamise IO-moodul -Description[fr]=Un module d'entrée / sortie pour l'affichage des fichiers WinHelp -Description[hu]=KDE-protokoll WinHelp-fájlok megjelenítéséhez -Description[it]=Un tdeioslave per mostrare i file WinHelp -Description[nl]=Een tdeioslave voor het weergeven van WinHelp-bestanden -Description[pl]=tdeioslave do pokazywania plików WinHelp -Description[pt]=A 'tdeioslave' para mostrar ficheiros WinHelp -Description[pt_BR]=Um tdeioslave para exibir arquivos WinHelp -Description[ru]=Обработчик ввода-вывода для файлов WinHelp -Description[sv]=En I/O-slav för att visa WinHelp-filer -Description[xx]=xxA tdeioslave for displaying WinHelp filesxx -Icon=help diff --git a/lib/libchmfile/libchmurlfactory.h b/lib/libchmfile/libchmurlfactory.h index 343ac75..a897138 100644 --- a/lib/libchmfile/libchmurlfactory.h +++ b/lib/libchmfile/libchmurlfactory.h @@ -98,7 +98,7 @@ static inline TQString makeURLabsoluteIfNeeded( const TQString & url ) } -// Returns a special string, which allows the kio-slave, or viewwindow-browser iteraction +// Returns a special string, which allows the tdeio-slave, or viewwindow-browser iteraction // to regognize our own internal urls, which is necessary to show image-only pages. static inline TQString getInternalUriExtension() { diff --git a/lib/tdeio-msits/Makefile.am b/lib/tdeio-msits/Makefile.am new file mode 100644 index 0000000..37e1b64 --- /dev/null +++ b/lib/tdeio-msits/Makefile.am @@ -0,0 +1,14 @@ +METASOURCES = AUTO +INCLUDES = $(QT_INCLUDES) $(CHM_INCLUDES) $(KDE_INCLUDES) $(LIBCHMFILE_INCLUDES) + +kde_module_LTLIBRARIES = tdeio_msits.la + +tdeio_msits_la_SOURCES = msits.cpp +tdeio_msits_la_LIBADD = -ltdeio $(CHM_LIBS) +tdeio_msits_la_LDFLAGS = -module -avoid-version $(KDE_LDFLAGS) $(LIB_QT) $(LIB_TDEIO) $(LIB_TDECORE) $(KDE_PLUGIN) $(QT_LDFLAGS) + +protocol_DATA = msits.protocol +protocoldir = $(kde_servicesdir) + +# Put it here to avoid creating another directory +kde_apps_DATA = kchmviewer.desktop diff --git a/lib/tdeio-msits/kchmviewer.desktop b/lib/tdeio-msits/kchmviewer.desktop new file mode 100644 index 0000000..31558d8 --- /dev/null +++ b/lib/tdeio-msits/kchmviewer.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Categories=Qt;TDE;Utility; +Encoding=UTF-8 +Type=Application +Exec=kchmviewer %U +Icon=kchmviewer +Terminal=0 +Name=KchmViewer +GenericName=CHM (MS-Help) Viewer +Comment=A viewer for CHM (MS-Help) files +MimeType=application/chm diff --git a/lib/tdeio-msits/msits.cpp b/lib/tdeio-msits/msits.cpp new file mode 100755 index 0000000..28d2821 --- /dev/null +++ b/lib/tdeio-msits/msits.cpp @@ -0,0 +1,320 @@ +/*************************************************************************** + * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * + * Please do not use email address above for bug reports; see * + * the README file * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "msits.h" +#include "libchmurlfactory.h" + +using namespace TDEIO; + +extern "C" +{ + int kdemain( int argc, char **argv ) + { + kdDebug() << "*** tdeio_msits Init" << endl; + + TDEInstance instance( "tdeio_msits" ); + + if ( argc != 4 ) + { + kdDebug() << "Usage: tdeio_msits protocol domain-socket1 domain-socket2" << endl; + exit (-1); + } + + ProtocolMSITS slave ( argv[2], argv[3] ); + slave.dispatchLoop(); + + kdDebug() << "*** tdeio_msits Done" << endl; + return 0; + } +} + +ProtocolMSITS::ProtocolMSITS (const TQCString &pool_socket, const TQCString &app_socket) + : SlaveBase ("tdeio_msits", pool_socket, app_socket) +{ + m_chmFile = 0; +} + +ProtocolMSITS::~ProtocolMSITS() +{ + if ( !m_chmFile ) + return; + + chm_close (m_chmFile); + m_chmFile = 0; +} + +// A simple stat() wrapper +static bool isDirectory ( const TQString & filename ) +{ + return filename[filename.length() - 1] == '/'; +} + + +void ProtocolMSITS::get( const KURL& url ) +{ + TQString htmdata, fileName; + chmUnitInfo ui; + TQByteArray buf; + + kdDebug() << "tdeio_msits::get() " << url.path() << endl; + + if ( !parseLoadAndLookup ( url, fileName ) ) + return; // error() has been called by parseLoadAndLookup + + kdDebug() << "tdeio_msits::get: parseLoadAndLookup returned " << fileName << endl; + + if ( LCHMUrlFactory::handleFileType( url.path(), htmdata ) ) + { + buf = htmdata.utf8(); + kdDebug() << "Using special handling for image pages: " << htmdata << endl; + } + else + { + if ( isDirectory (fileName) ) + { + error( TDEIO::ERR_IS_DIRECTORY, url.prettyURL() ); + return; + } + + if ( !ResolveObject ( fileName, &ui) ) + { + kdDebug() << "tdeio_msits::get: could not resolve filename " << fileName << endl; + error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL() ); + return; + } + + buf.resize( ui.length ); + + if ( RetrieveObject (&ui, (unsigned char*) buf.data(), 0, ui.length) == 0 ) + { + kdDebug() << "tdeio_msits::get: could not retrieve filename " << fileName << endl; + error( TDEIO::ERR_NO_CONTENT, url.prettyURL() ); + return; + } + } + + totalSize( buf.size() ); + KMimeMagicResult * result = KMimeMagic::self()->findBufferFileType( buf, fileName ); + kdDebug() << "Emitting mimetype " << result->mimeType() << endl; + + mimeType( result->mimeType() ); + data( buf ); + processedSize( buf.size() ); + + finished(); +} + + +bool ProtocolMSITS::parseLoadAndLookup ( const KURL& url, TQString& abspath ) +{ + kdDebug() << "ProtocolMSITS::parseLoadAndLookup (const KURL&) " << url.path() << endl; + + int pos = url.path().find ("::"); + + if ( pos == -1 ) + { + error( TDEIO::ERR_MALFORMED_URL, url.prettyURL() ); + return false; + } + + TQString 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 ); + + kdDebug() << "ProtocolMSITS::parseLoadAndLookup: filename " << filename << ", path " << abspath << endl; + + if ( filename.isEmpty() ) + { + error( TDEIO::ERR_MALFORMED_URL, url.prettyURL() ); + return false; + } + + // If the file has been already loaded, nothing to do. + if ( m_chmFile && filename == m_openedFile ) + return true; + + kdDebug() << "Opening a new CHM file " << filename << endl; + + // First try to open a temporary file + chmFile * tmpchm; + + if ( (tmpchm = chm_open ( TQFile::encodeName (filename))) == 0 ) + { + error( TDEIO::ERR_COULD_NOT_READ, url.prettyURL() ); + return false; + } + + // Replace an existing file by a new one + if ( m_chmFile ) + chm_close (m_chmFile); + + m_chmFile = tmpchm; + m_openedFile = filename; + + kdDebug() << "A CHM file " << filename << " has beed opened successfully" << endl; + return true; +} + +/* + * Shamelessly stolen from a KDE TDEIO tutorial + */ +static void app_entry(UDSEntry& e, unsigned int uds, const TQString& str) +{ + UDSAtom a; + a.m_uds = uds; + a.m_str = str; + e.append(a); +} + + // appends an int with the UDS-ID uds + static void app_entry(UDSEntry& e, unsigned int uds, long l) + { + UDSAtom a; + a.m_uds = uds; + a.m_long = l; + e.append(a); +} + +// internal function +// fills a directory item with its name and size +static void app_dir(UDSEntry& e, const TQString & name) +{ + e.clear(); + app_entry(e, TDEIO::UDS_NAME, name); + app_entry(e, TDEIO::UDS_FILE_TYPE, S_IFDIR); + app_entry(e, TDEIO::UDS_SIZE, 1); +} + +// internal function +// fills a file item with its name and size +static void app_file(UDSEntry& e, const TQString & name, size_t size) +{ + e.clear(); + app_entry(e, TDEIO::UDS_NAME, name); + app_entry(e, TDEIO::UDS_FILE_TYPE, S_IFREG); + app_entry(e, TDEIO::UDS_SIZE, size); +} + +void ProtocolMSITS::stat (const KURL & url) +{ + TQString fileName; + chmUnitInfo ui; + + kdDebug() << "tdeio_msits::stat (const KURL& url) " << url.path() << endl; + + if ( !parseLoadAndLookup ( url, fileName ) ) + return; // error() has been called by parseLoadAndLookup + + if ( !ResolveObject ( fileName, &ui ) ) + { + error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL() ); + return; + } + + kdDebug() << "tdeio_msits::stat: adding an entry for " << fileName << endl; + UDSEntry entry; + + if ( isDirectory ( fileName ) ) + app_dir(entry, fileName); + else + app_file(entry, fileName, ui.length); + + statEntry (entry); + + finished(); +} + + +// A local CHMLIB enumerator +static int chmlib_enumerator (struct chmFile *, struct chmUnitInfo *ui, void *context) +{ + ((TQValueVector *) context)->push_back (TQString::fromLocal8Bit (ui->path)); + return CHM_ENUMERATOR_CONTINUE; +} + + +void ProtocolMSITS::listDir (const KURL & url) +{ + TQString filepath; + + kdDebug() << "tdeio_msits::listDir (const KURL& url) " << url.path() << endl; + + if ( !parseLoadAndLookup ( url, filepath ) ) + return; // error() has been called by parseLoadAndLookup + + filepath += "/"; + + if ( !isDirectory (filepath) ) + { + error(TDEIO::ERR_CANNOT_ENTER_DIRECTORY, url.path()); + return; + } + + kdDebug() << "tdeio_msits::listDir: enumerating directory " << filepath << endl; + + TQValueVector listing; + + if ( chm_enumerate_dir ( m_chmFile, + filepath.local8Bit(), + CHM_ENUMERATE_NORMAL | CHM_ENUMERATE_FILES | CHM_ENUMERATE_DIRS, + chmlib_enumerator, + &listing ) != 1 ) + { + error(TDEIO::ERR_CANNOT_ENTER_DIRECTORY, url.path()); + return; + } + + UDSEntry entry; + unsigned int striplength = filepath.length(); + + for ( unsigned int i = 0; i < listing.size(); i++ ) + { + // Strip the direcroty name + TQString ename = listing[i].mid (striplength); + + if ( isDirectory ( ename ) ) + app_dir(entry, ename); + else + app_file(entry, ename, 0); + + listEntry(entry, false); + } + + listEntry(entry, true); + finished(); +} diff --git a/lib/tdeio-msits/msits.h b/lib/tdeio-msits/msits.h new file mode 100755 index 0000000..4248908 --- /dev/null +++ b/lib/tdeio-msits/msits.h @@ -0,0 +1,79 @@ +/*************************************************************************** + * Copyright (C) 2004-2005 by Georgy Yunaev, gyunaev@ulduzsoft.com * + * Please do not use email address above for bug reports; see * + * the README file * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef MSITS_H +#define MSITS_H + + +#include +#include + +#include +#include + +#include "config.h" +#include "chm_lib.h" + + +class ProtocolMSITS : public TDEIO::SlaveBase +{ +public: + ProtocolMSITS ( const TQCString&, const TQCString& ); + virtual ~ProtocolMSITS(); + + virtual void get ( const KURL& ); + virtual void listDir (const KURL & url); + virtual void stat (const KURL & url); + +private: + // This function does next thing: + // - parses the URL to get a file name and URL inside the file; + // - loads a new CHM file, if needed; + // - returns the parsed URL inside the file; + bool parseLoadAndLookup ( const KURL&, TQString& abspath ); + + // Resolve an object inside a CHM file + inline bool ResolveObject (const TQString& fileName, chmUnitInfo *ui) + { + return m_chmFile != NULL && ::chm_resolve_object(m_chmFile, fileName.utf8(), ui) == CHM_RESOLVE_SUCCESS; + } + + // Retrieve an object from the CHM file + inline size_t RetrieveObject (const chmUnitInfo *ui, unsigned char *buffer, LONGUINT64 fileOffset, LONGINT64 bufferSize) + { +#if USE_BUILTIN_CHMLIB + return ::chm_retrieve_object(m_chmFile, ui, buffer, + fileOffset, bufferSize); +#else + return ::chm_retrieve_object(m_chmFile, const_cast(ui), + buffer, fileOffset, bufferSize); +#endif + } + + // An opened file name, if presend + TQString m_openedFile; + + // a CHM structure file pointer (from chmlib) + chmFile * m_chmFile; +}; + + +#endif /* MSITS_H */ diff --git a/lib/tdeio-msits/msits.protocol b/lib/tdeio-msits/msits.protocol new file mode 100755 index 0000000..bc1d65f --- /dev/null +++ b/lib/tdeio-msits/msits.protocol @@ -0,0 +1,24 @@ +[Protocol] +exec=tdeio_msits +protocol=ms-its +input=none +output=filesystem +reading=true +listing=Name,Type,Size +defaultMimetype=text/html +Description=A tdeioslave for displaying WinHelp files +Description[da]=En tdeioslave til visning af Windows hjælpefiler +Description[de]=Ein Ein-/Ausgabemodul zur Anzeige von WinHelp-Dateien +Description[es]=Un tdeioslave para mostrar archivos WinHelp +Description[et]=WinHelp-failide kuvamise IO-moodul +Description[fr]=Un module d'entrée / sortie pour l'affichage des fichiers WinHelp +Description[hu]=KDE-protokoll WinHelp-fájlok megjelenítéséhez +Description[it]=Un tdeioslave per mostrare i file WinHelp +Description[nl]=Een tdeioslave voor het weergeven van WinHelp-bestanden +Description[pl]=tdeioslave do pokazywania plików WinHelp +Description[pt]=A 'tdeioslave' para mostrar ficheiros WinHelp +Description[pt_BR]=Um tdeioslave para exibir arquivos WinHelp +Description[ru]=Обработчик ввода-вывода для файлов WinHelp +Description[sv]=En I/O-slav för att visa WinHelp-filer +Description[xx]=xxA tdeioslave for displaying WinHelp filesxx +Icon=help diff --git a/src/Makefile.am b/src/Makefile.am index 587ee65..e14ed77 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,8 +19,8 @@ SUBDIRS = $(LIB_KDEEXTRADIR) . pics # the library search path. kchmviewer_LDADD = $(top_builddir)/lib/libchmfile/libchmfile.a $(LIB_KDEEXTRA) \ - $(CHM_LIBS) $(LIB_QT) $(LIB_TDEUI) $(LIB_TDEHTML) $(LIB_KPARTS) $(LIB_KIO) -kchmviewer_LDFLAGS = $(QT_LDFLAGS) $(KDE_LDFLAGS) $(LIB_TDECORE) -lDCOP $(LIB_TDEUI) $(LIB_KPARTS) $(LIB_KIO) -L../lib/chmlib/ + $(CHM_LIBS) $(LIB_QT) $(LIB_TDEUI) $(LIB_TDEHTML) $(LIB_TDEPARTS) $(LIB_TDEIO) +kchmviewer_LDFLAGS = $(QT_LDFLAGS) $(KDE_LDFLAGS) $(LIB_TDECORE) -lDCOP $(LIB_TDEUI) $(LIB_TDEPARTS) $(LIB_TDEIO) -L../lib/chmlib/ METASOURCES = AUTO KDE_OPTIONS = qtonly diff --git a/src/kchmviewwindow.cpp b/src/kchmviewwindow.cpp index f776efe..71e0813 100644 --- a/src/kchmviewwindow.cpp +++ b/src/kchmviewwindow.cpp @@ -102,7 +102,7 @@ bool KCHMViewWindow::openUrl ( const TQString& origurl ) return true; // URL could be a complete ms-its link. The file should be already loaded (for TQTextBrowser), - // or will be loaded (for kio slave). We care only about the path component. + // or will be loaded (for tdeio slave). We care only about the path component. if ( LCHMUrlFactory::isNewChmURL( newurl, chmfile, page ) ) { // If a new chm file is opened here, and we do not use KCHMLPart, we better abort -- cgit v1.2.3