summaryrefslogtreecommitdiffstats
path: root/parts/documentation/plugins/chm
diff options
context:
space:
mode:
Diffstat (limited to 'parts/documentation/plugins/chm')
-rw-r--r--parts/documentation/plugins/chm/Makefile.am14
-rw-r--r--parts/documentation/plugins/chm/docchmplugin.cpp198
-rw-r--r--parts/documentation/plugins/chm/docchmplugin.desktop44
-rw-r--r--parts/documentation/plugins/chm/docchmplugin.h50
4 files changed, 306 insertions, 0 deletions
diff --git a/parts/documentation/plugins/chm/Makefile.am b/parts/documentation/plugins/chm/Makefile.am
new file mode 100644
index 00000000..6df1ba52
--- /dev/null
+++ b/parts/documentation/plugins/chm/Makefile.am
@@ -0,0 +1,14 @@
+INCLUDES = -I$(top_srcdir)/lib/interfaces -I$(top_srcdir)/lib/util \
+ -I$(top_srcdir)/parts/documentation/interfaces $(all_includes)
+
+METASOURCES = AUTO
+
+kde_module_LTLIBRARIES = libdocchmplugin.la
+
+noinst_HEADERS = docchmplugin.h
+kde_services_DATA = docchmplugin.desktop
+
+libdocchmplugin_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries)
+libdocchmplugin_la_SOURCES = docchmplugin.cpp
+libdocchmplugin_la_LIBADD = $(top_builddir)/lib/libkdevelop.la \
+ $(top_builddir)/parts/documentation/interfaces/libdocumentation_interfaces.la
diff --git a/parts/documentation/plugins/chm/docchmplugin.cpp b/parts/documentation/plugins/chm/docchmplugin.cpp
new file mode 100644
index 00000000..e2b2b556
--- /dev/null
+++ b/parts/documentation/plugins/chm/docchmplugin.cpp
@@ -0,0 +1,198 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Alexander Dymo *
+ * cloudtemple@mksat.net *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "docchmplugin.h"
+
+#include <kurl.h>
+#include <kaboutdata.h>
+#include <kconfig.h>
+#include <klocale.h>
+#include <klistview.h>
+#include <kio/netaccess.h>
+#include <iostream>
+#include <fstream>
+#include <qvaluevector.h>
+#include <kdevgenericfactory.h>
+#include <kdevplugininfo.h>
+#include <qregexp.h>
+
+#include "../../../../config.h"
+
+static const KDevPluginInfo data("docchmplugin");
+typedef KDevGenericFactory<DocCHMPlugin> DocCHMPluginFactory;
+K_EXPORT_COMPONENT_FACTORY( libdocchmplugin, DocCHMPluginFactory(data) )
+
+DocCHMPlugin::DocCHMPlugin(QObject* parent, const char* name, QStringList // args
+ )
+ :DocumentationPlugin(DocCHMPluginFactory::instance()->config(), parent, name)
+{
+ setCapabilities(CustomDocumentationTitles); // | Index | FullTextSearch | ProjectDocumentation
+ autoSetup();
+}
+
+DocCHMPlugin::~DocCHMPlugin()
+{
+}
+
+
+DocumentationCatalogItem* DocCHMPlugin::createCatalog(KListView* contents, const QString& title, const QString& url)
+{
+ DocumentationCatalogItem *item = new DocumentationCatalogItem(this, contents, title);
+ item->setURL(KURL(url));
+
+ return item;
+}
+
+QPair<KFile::Mode, QString> DocCHMPlugin::catalogLocatorProps()
+{
+ return QPair<KFile::Mode, QString>(KFile::File, "*.chm");
+}
+
+QString DocCHMPlugin::catalogTitle(const QString& // url
+ )
+{
+ return QString::null;
+}
+
+QString DocCHMPlugin::pluginName() const
+{
+ return i18n("CHM Documentation Collection");
+}
+
+
+QString DocCHMPlugin::getSpecialData(const QString& name, KURL url) {
+ QString ret = "";
+ url.setProtocol("ms-its");
+
+ url.addPath("/:" + name);
+ QString tmpFile;
+ if( KIO::NetAccess::download( url, tmpFile, 0 ) )
+ {
+ std::filebuf fb;
+ fb.open (tmpFile.ascii(), std::ios::in);
+ std::istream is(&fb);
+ char buf[5000] = " ";
+ while(is.good()) {
+ is.getline(buf, 5000);
+ ret += buf; ret += "\n";
+ }
+ fb.close();
+ KIO::NetAccess::removeTempFile( tmpFile );
+ } else {
+ kdDebug(9002) << "DocCHMPlugin::getSpecialData could not download data from " << url.url() << endl;
+ }
+ return ret;
+}
+
+
+///this currently is useless, because htdig cannot use kioslaves
+QStringList DocCHMPlugin::fullTextSearchLocations()
+{
+ //return QStringList::split( '\n', getSpecialData("contents", m_url));
+ return QStringList();
+}
+
+bool DocCHMPlugin::needRefreshIndex(DocumentationCatalogItem* // item
+ )
+{
+ return false;
+}
+
+void DocCHMPlugin::autoSetupPlugin()
+{
+ return;
+}
+
+void DocCHMPlugin::createIndex(IndexBox* // index
+ , DocumentationCatalogItem* // item
+ )
+{
+ return;
+}
+
+
+static KListViewItem* chainEnd(KListViewItem *parent) {
+ if(parent == 0) return 0;
+ KListViewItem* ret = dynamic_cast<KListViewItem*>(parent->firstChild());
+ if(ret == 0) return 0;
+ while(ret->nextSibling() != 0) {
+ ret = dynamic_cast<KListViewItem*>(ret->nextSibling());
+ }
+ return ret;
+}
+
+static QString decodeHTML(const QString& s) {
+ QRegExp rx(QString::fromLatin1("&#(\\d+);|&nbsp;"));
+ QString out = s;
+ int pos = rx.search(out);
+ while(pos > -1) {
+ QString found = rx.cap(0);
+ if(found != "&nbsp;") {
+ out.replace(pos, found.length(), static_cast<char>(rx.cap(1).toInt()));
+ }else{
+ out.replace(pos, found.length(), " ");
+ }
+ pos = rx.search(out, pos+1);
+ }
+ return out;
+}
+
+
+void DocCHMPlugin::createTOC(DocumentationCatalogItem* item)
+{
+ QStringList lines = QStringList::split("\n", getSpecialData("catalog", item->url()) );
+ if(lines.count() % 4 != 0) { kdDebug(9002) << "DocCHMPlugin::createTOC: wrong count of strings"; return;}
+
+ QValueVector<DocumentationItem*> items;
+ items.push_back(item);
+ for(QStringList::Iterator it = lines.begin(); it != lines.end();) {
+ bool ok1 = true, ok2 = true;
+ int parent = (*it).toInt(&ok1);
+ ++it;
+ int current = (*it).toInt(&ok2);
+ ++it;
+ if(int(items.size()) != current || !ok1 || !ok2 || parent < 0 || parent >= int(items.size()) || current < 0 || current != int(items.size())) {
+ kdDebug(9002) << "DocCHMPlugin::createTOC error while parsing output of ioslave" << endl;
+ break;
+ }
+
+ QString& name(*it);
+ ++it;
+ KURL url(*it);
+ ++it;
+
+ items.push_back(new DocumentationItem(
+ DocumentationItem::Document, items[parent], chainEnd(items[parent]), decodeHTML(name)));
+ items[current]->setURL(url);
+ if(parent != 0) items[parent]->setType(DocumentationItem::Book);
+ }
+
+
+ return;
+}
+
+void DocCHMPlugin::setCatalogURL(DocumentationCatalogItem* item)
+{
+ KURL chmURL = item->url();
+ chmURL.setProtocol("ms-its");
+ chmURL.addPath("/");
+ item->setURL(chmURL);
+}
+
+#include "docchmplugin.moc"
diff --git a/parts/documentation/plugins/chm/docchmplugin.desktop b/parts/documentation/plugins/chm/docchmplugin.desktop
new file mode 100644
index 00000000..1e538ed7
--- /dev/null
+++ b/parts/documentation/plugins/chm/docchmplugin.desktop
@@ -0,0 +1,44 @@
+[Desktop Entry]
+Type=Service
+Name=DocCHMPlugin
+Name[da]=DocCHM-plugin
+Name[hu]=DocCHMPPlugin
+Name[sk]=Doc CHM modul
+Name[sv]=CHM-dokumentationsinsticksmodul
+Name[ta]=DocCHM சொருகு
+Name[zh_TW]=Doc CHM 外掛程式
+Exec=blubb
+Comment=Documentation plugin for CHM documentation
+Comment[ca]=Connector de documentació per a documentació CHM
+Comment[da]=Dokumentations-plugin for CHM-dokumentation
+Comment[de]=Dokumentations-Modul für CHM-Dokumentation
+Comment[el]=Πρόσθετο τεκμηρίωσης για τεκμηρίωση CHM
+Comment[es]=Complemento de documentación para CHM
+Comment[et]=CHM dokumentatsiooni plugin
+Comment[eu]=CHM dokumentazioarako dokumentazioa plugin-aDocumentation plugin for CHM documentation
+Comment[fa]=وصلۀ مستندسازی برای مستندات CHM
+Comment[fr]=Module externe de documentation pour la documentation CHM
+Comment[gl]=Extensión de documentación para documentación CHM
+Comment[hu]=Dokumentációmodul CHM formátumú dokumentációhoz
+Comment[it]=Plugin di documentazione per file CHM
+Comment[ja]=CHM ドキュメンテーションのためのドキュメンテーションプラグイン
+Comment[ms]=Plugin dokumentasi untuk dokumentasi CHM
+Comment[nds]=Dokmentatschoon-Moduul för CHM-Dokmentatschonen
+Comment[ne]=CHM मिसिलीकरणका लागि मिसिलीकरण प्लगइन
+Comment[nl]=Documentatie plugin voor CHM documentatie
+Comment[pl]=Wtyczka dokumentacji dla dokumentacji w formacie CHM
+Comment[pt]='Plugin' para documentação CHM
+Comment[pt_BR]=Plug-in de documentação para documento CHM
+Comment[ru]=Модуль для просмотра документации в файлах CHM
+Comment[sk]=Dokumentačný modul pre CHM dokumentáciu
+Comment[sr]=Документациони прикључак за CHM документацију
+Comment[sr@Latn]=Dokumentacioni priključak za CHM dokumentaciju
+Comment[sv]=Dokumentationsinsticksmodul för CHM-dokumentation
+Comment[ta]= CHM ஆவணத்திற்கான ஆவணச் சொருகு
+Comment[tg]=Модул барои намоиши файлҳои CHM-е, ки ҳуҷҷатҳо мавҷуд аст
+Comment[tr]=CHM belgelendirmesi için belgelendirme eklentisi
+Comment[zh_CN]=CHM 文档的文档插件
+Comment[zh_TW]=CHM 文件外掛程式
+ServiceTypes=KDevelop/DocumentationPlugins
+X-KDevelop-Version=5
+X-KDE-Library=libdocchmplugin
diff --git a/parts/documentation/plugins/chm/docchmplugin.h b/parts/documentation/plugins/chm/docchmplugin.h
new file mode 100644
index 00000000..69bc441b
--- /dev/null
+++ b/parts/documentation/plugins/chm/docchmplugin.h
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Alexander Dymo *
+ * cloudtemple@mksat.net *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef DOCCHMPLUGIN_H
+#define DOCCHMPLUGIN_H
+
+#include <kdevdocumentationplugin.h>
+
+class DocCHMPlugin :public DocumentationPlugin
+{
+ Q_OBJECT
+public:
+ DocCHMPlugin(QObject* parent, const char* name, QStringList args = QStringList());
+ ~DocCHMPlugin();
+
+ virtual QString pluginName() const;
+
+ virtual void setCatalogURL(DocumentationCatalogItem* item);
+ virtual QString catalogTitle(const QString& url);
+ virtual QPair<KFile::Mode, QString> catalogLocatorProps();
+ virtual DocumentationCatalogItem* createCatalog(KListView* contents, const QString& title, const QString& url);
+ virtual void createTOC(DocumentationCatalogItem* item);
+
+ virtual void createIndex(IndexBox* index, DocumentationCatalogItem* item);
+ virtual bool needRefreshIndex(DocumentationCatalogItem* item);
+
+ virtual QStringList fullTextSearchLocations();
+
+ virtual void autoSetupPlugin();
+protected:
+ QString getSpecialData(const QString& name, KURL url);
+};
+
+#endif