summaryrefslogtreecommitdiffstats
path: root/parts/documentation/plugins/kdevtoc
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /parts/documentation/plugins/kdevtoc
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'parts/documentation/plugins/kdevtoc')
-rw-r--r--parts/documentation/plugins/kdevtoc/Makefile.am10
-rw-r--r--parts/documentation/plugins/kdevtoc/dockdevtocplugin.cpp277
-rw-r--r--parts/documentation/plugins/kdevtoc/dockdevtocplugin.desktop43
-rw-r--r--parts/documentation/plugins/kdevtoc/dockdevtocplugin.h54
4 files changed, 384 insertions, 0 deletions
diff --git a/parts/documentation/plugins/kdevtoc/Makefile.am b/parts/documentation/plugins/kdevtoc/Makefile.am
new file mode 100644
index 00000000..a40dd995
--- /dev/null
+++ b/parts/documentation/plugins/kdevtoc/Makefile.am
@@ -0,0 +1,10 @@
+INCLUDES = -I$(top_srcdir)/lib/interfaces -I$(top_srcdir)/lib/util \
+ -I$(top_srcdir)/parts/documentation/interfaces $(all_includes)
+METASOURCES = AUTO
+kde_module_LTLIBRARIES = libdockdevtocplugin.la
+libdockdevtocplugin_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries)
+kde_services_DATA = dockdevtocplugin.desktop
+noinst_HEADERS = dockdevtocplugin.h
+libdockdevtocplugin_la_SOURCES = dockdevtocplugin.cpp
+libdockdevtocplugin_la_LIBADD = $(top_builddir)/lib/libkdevelop.la \
+ $(top_builddir)/parts/documentation/interfaces/libdocumentation_interfaces.la
diff --git a/parts/documentation/plugins/kdevtoc/dockdevtocplugin.cpp b/parts/documentation/plugins/kdevtoc/dockdevtocplugin.cpp
new file mode 100644
index 00000000..65ebf35f
--- /dev/null
+++ b/parts/documentation/plugins/kdevtoc/dockdevtocplugin.cpp
@@ -0,0 +1,277 @@
+/***************************************************************************
+ * 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 "dockdevtocplugin.h"
+
+#include <unistd.h>
+
+#include <qdom.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qdialog.h>
+
+#include <kurl.h>
+#include <kaboutdata.h>
+#include <kconfig.h>
+#include <klocale.h>
+#include <klistview.h>
+#include <kstandarddirs.h>
+
+#include <urlutil.h>
+#include <kdevgenericfactory.h>
+#include <kdevplugininfo.h>
+
+#include "../../../../config.h"
+
+class TOCDocumentationCatalogItem: public DocumentationCatalogItem
+{
+public:
+ TOCDocumentationCatalogItem(const QString &tocFile, DocumentationPlugin* plugin,
+ KListView *parent, const QString &name)
+ :DocumentationCatalogItem(plugin, parent, name), m_tocFile(tocFile)
+ {
+ }
+ TOCDocumentationCatalogItem(const QString &tocFile, DocumentationPlugin* plugin,
+ DocumentationItem *parent, const QString &name)
+ :DocumentationCatalogItem(plugin, parent, name), m_tocFile(tocFile)
+ {
+ }
+ QString tocFile() const { return m_tocFile; }
+
+private:
+ QString m_tocFile;
+};
+
+
+static const KDevPluginInfo data("dockdevtocplugin");
+typedef KDevGenericFactory<DocKDevTOCPlugin> DocKDevTOCPluginFactory;
+K_EXPORT_COMPONENT_FACTORY( libdockdevtocplugin, DocKDevTOCPluginFactory(data) )
+
+DocKDevTOCPlugin::DocKDevTOCPlugin(QObject* parent, const char* name,
+ const QStringList /*args*/)
+ :DocumentationPlugin(DocKDevTOCPluginFactory::instance()->config(), parent, name)
+{
+ setCapabilities(Index);
+ autoSetup();
+}
+
+DocKDevTOCPlugin::~DocKDevTOCPlugin()
+{
+}
+
+QString DocKDevTOCPlugin::pluginName() const
+{
+ return i18n("KDevelopTOC Documentation Collection");
+}
+
+DocumentationCatalogItem* DocKDevTOCPlugin::createCatalog(KListView* contents, const QString& title, const QString& url)
+{
+ return new TOCDocumentationCatalogItem(url, this, contents, title);
+}
+
+QPair<KFile::Mode, QString> DocKDevTOCPlugin::catalogLocatorProps()
+{
+ return QPair<KFile::Mode, QString>(KFile::File, "*.toc");
+}
+
+QString DocKDevTOCPlugin::catalogTitle(const QString& url)
+{
+ QFileInfo fi(url);
+ if (!fi.exists())
+ return QString::null;
+
+ QFile f(url);
+ if (!f.open(IO_ReadOnly))
+ return QString::null;
+
+ QDomDocument doc;
+ if (!doc.setContent(&f) || (doc.doctype().name() != "kdeveloptoc"))
+ return QString::null;
+ f.close();
+
+ QDomElement titleEl = doc.documentElement().namedItem("title").toElement();
+
+ return titleEl.firstChild().toText().data();
+}
+
+
+QStringList DocKDevTOCPlugin::fullTextSearchLocations()
+{
+ return QStringList();
+}
+
+bool DocKDevTOCPlugin::needRefreshIndex(DocumentationCatalogItem* /*item*/)
+{
+ return false;
+}
+
+void DocKDevTOCPlugin::autoSetupPlugin()
+{
+ QStringList tocsDir = DocKDevTOCPluginFactory::instance()->dirs()->findAllResources("data", "kdevdocumentation/tocs/*.toc");
+
+ for (QStringList::const_iterator it = tocsDir.begin(); it != tocsDir.end(); ++it)
+ {
+ config->setGroup("Locations");
+ config->writePathEntry(catalogTitle(*it), *it);
+ }
+}
+
+void DocKDevTOCPlugin::createIndex(IndexBox* index, DocumentationCatalogItem* item)
+{
+ TOCDocumentationCatalogItem *tocItem = dynamic_cast<TOCDocumentationCatalogItem *>(item);
+ if (!tocItem)
+ return;
+
+ QFileInfo fi(tocItem->tocFile());
+
+ QFile f(tocItem->tocFile());
+ if (!f.open(IO_ReadOnly))
+ {
+ kdDebug(9002) << "Could not read" << tocItem->tocFile() << endl;
+ return;
+ }
+ QDomDocument doc;
+ if (!doc.setContent(&f) || doc.doctype().name() != "kdeveloptoc")
+ {
+ kdDebug(9002) << "Not a valid kdeveloptoc file: " << tocItem->tocFile() << endl;
+ return;
+ }
+ f.close();
+
+ QDomElement docEl = doc.documentElement();
+ QDomElement baseEl = docEl.namedItem("base").toElement();
+
+ QString base;
+ if (!baseEl.isNull())
+ base = baseEl.attribute("href", QString::null);
+
+ QDomElement indexEl = docEl.namedItem("index").toElement();
+ QDomElement childEl = indexEl.firstChild().toElement();
+ while (!childEl.isNull())
+ {
+ if (childEl.tagName() == "entry")
+ {
+ QString name = childEl.attribute("name");
+ QString url = childEl.attribute("url");
+
+ IndexItemProto *ii = new IndexItemProto(this, item, index, name, item->text(0));
+ ii->addURL(KURL(constructURL(base, url)));
+ }
+ childEl = childEl.nextSibling().toElement();
+ }
+}
+
+void DocKDevTOCPlugin::createTOC(DocumentationCatalogItem* item)
+{
+ TOCDocumentationCatalogItem *tocItem = dynamic_cast<TOCDocumentationCatalogItem *>(item);
+ if (!tocItem)
+ return;
+
+ QFileInfo fi(tocItem->tocFile());
+
+ QFile f(tocItem->tocFile());
+ if (!f.open(IO_ReadOnly))
+ {
+ kdDebug(9002) << "Could not read" << tocItem->tocFile() << endl;
+ return;
+ }
+ QDomDocument doc;
+ if (!doc.setContent(&f) || doc.doctype().name() != "kdeveloptoc")
+ {
+ kdDebug(9002) << "Not a valid kdeveloptoc file: " << tocItem->tocFile() << endl;
+ return;
+ }
+ f.close();
+
+ QDomElement docEl = doc.documentElement();
+ QDomElement baseEl = docEl.namedItem("base").toElement();
+
+ QString base;
+ if (!baseEl.isNull())
+ base = baseEl.attribute("href", QString::null);
+
+ QDomElement childEl = docEl.lastChild().toElement();
+ addTocSect(tocItem, childEl, base, 1);
+}
+
+void DocKDevTOCPlugin::addTocSect(DocumentationItem *parent, QDomElement childEl, const QString &base, uint level)
+{
+ while (!childEl.isNull())
+ {
+ if (childEl.tagName() == QString("tocsect%1").arg(level))
+ {
+ QString name = childEl.attribute("name");
+ QString url = childEl.attribute("url");
+
+ DocumentationItem *item = new DocumentationItem(level == 1 ? DocumentationItem::Book : DocumentationItem::Document, parent, name);
+ item->setURL(KURL(constructURL(base, url)));
+
+ QDomElement grandchildEl = childEl.lastChild().toElement();
+ addTocSect(item, grandchildEl, base, level+1);
+ }
+ childEl = childEl.previousSibling().toElement();
+ }
+}
+
+void DocKDevTOCPlugin::setCatalogURL(DocumentationCatalogItem* item)
+{
+ TOCDocumentationCatalogItem *tocItem = dynamic_cast<TOCDocumentationCatalogItem *>(item);
+ if (!tocItem)
+ return;
+
+ QFileInfo fi(tocItem->tocFile());
+
+ QFile f(tocItem->tocFile());
+ if (!f.open(IO_ReadOnly))
+ {
+ kdDebug(9002) << "Could not read" << tocItem->tocFile() << endl;
+ return;
+ }
+ QDomDocument doc;
+ if (!doc.setContent(&f) || doc.doctype().name() != "kdeveloptoc")
+ {
+ kdDebug(9002) << "Not a valid kdeveloptoc file: " << tocItem->tocFile() << endl;
+ return;
+ }
+ f.close();
+
+ QDomElement docEl = doc.documentElement();
+ QDomElement baseEl = docEl.namedItem("base").toElement();
+
+ if (item->url().isEmpty())
+ {
+ if (baseEl.isNull())
+ item->setURL(KURL());
+ else
+ item->setURL(KURL(constructURL(baseEl.attribute("href", QString::null),
+ baseEl.attribute("url", QString::null))));
+ }
+}
+
+QString DocKDevTOCPlugin::constructURL(const QString &base, const QString &url)
+{
+ if (base.isEmpty() && !url.isEmpty())
+ return url;
+ if (!url.isEmpty())
+ return base.endsWith("/") ? base + url : base + "/" + url;
+ else
+ return base;
+}
+
+#include "dockdevtocplugin.moc"
diff --git a/parts/documentation/plugins/kdevtoc/dockdevtocplugin.desktop b/parts/documentation/plugins/kdevtoc/dockdevtocplugin.desktop
new file mode 100644
index 00000000..d665e9af
--- /dev/null
+++ b/parts/documentation/plugins/kdevtoc/dockdevtocplugin.desktop
@@ -0,0 +1,43 @@
+[Desktop Entry]
+Type=Service
+Name=DocKDevTOCPlugin
+Name[da]=DocKDevTOC-plugin
+Name[sk]=Doc KDevTOC modul
+Name[sv]=KDevelop innehållsförteckning-dokumentationsinsticksmodul
+Name[ta]=DocKDevTOC சொருகு
+Name[zh_TW]=KDevelop 目錄文件外掛程式
+Exec=blubb
+Comment=Documentation plugin for KDevelopTOC documentation
+Comment[ca]=Connector de documentació per a documentació KDevelopTOC
+Comment[da]=Dokumentations-plugin for KDevelopTOC-dokumentation
+Comment[de]=Komponente für KDevelopTOC-Dokumentation
+Comment[el]=Πρόσθετο τεκμηρίωσης για τεκμηρίωση τύπου KDevelopTOC
+Comment[es]=Complemento de documentación para KDevelopTOC
+Comment[et]=KDevelopTOC dokumentatsiooni plugin
+Comment[eu]=KDevelopTOC dokumentaziorako dokumentazio plugin-a
+Comment[fa]=وصلۀ مستندسازی برای مستندات KDevelopTOC
+Comment[fr]=Module externe de documentation pour la documentation KDevelopTOC
+Comment[gl]=Extensión de documentación para documentación KDevelopTOC
+Comment[hu]=Dokumentációmodul KDevelopTOC-dokumentációhoz
+Comment[it]=Plugin di documentazione per file di KDevelopTOC
+Comment[ja]=KDevelopTOC ドキュメンテーションのためのドキュメンテーションプラグイン
+Comment[ms]=Plugin dokumentasi untuk dokumentasi KDevelopTOC
+Comment[nds]=Dokmentatschoon-Moduul för KDevelopTOC-Dokmentatschoon
+Comment[ne]=KDevelopTOC मिसिलीकरणका लागि मिसिलीकरण प्लगइन
+Comment[nl]=Documentatie plugin for KDevelopTOC documentatie
+Comment[pl]=Wtyczka dokumentacji dla dokumentacji w formacie KDevelopTOC
+Comment[pt]='Plugin' para documentação KDevelopTOC
+Comment[pt_BR]=Plug-in de documentação para document TOC do KDevelop
+Comment[ru]=Модуль для просмотра KDevelopTOC
+Comment[sk]=Dokumentačný modul pre KDevelopTOC dokumentáciu
+Comment[sr]=Документациони прикључак за KDevelopTOC документацију
+Comment[sr@Latn]=Dokumentacioni priključak za KDevelopTOC dokumentaciju
+Comment[sv]=Dokumentationsinsticksmodul för KDevelop innehållsförteckningsdokumentation
+Comment[ta]= KDevelopTOC ஆவணத்திற்கான ஆவணச் சொருகு
+Comment[tg]=Модул барои наоиши KDevelopTOC
+Comment[tr]=KDevelopTOC belgelendirmesi için belgelendirme eklentisi
+Comment[zh_CN]=KDevelopTOC 文档的文档插件
+Comment[zh_TW]=KDevelop 目錄文件外掛程式
+ServiceTypes=KDevelop/DocumentationPlugins
+X-KDevelop-Version=5
+X-KDE-Library=libdockdevtocplugin
diff --git a/parts/documentation/plugins/kdevtoc/dockdevtocplugin.h b/parts/documentation/plugins/kdevtoc/dockdevtocplugin.h
new file mode 100644
index 00000000..4a958473
--- /dev/null
+++ b/parts/documentation/plugins/kdevtoc/dockdevtocplugin.h
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * 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 DOCKDEVTOCPLUGIN_H
+#define DOCKDEVTOCPLUGIN_H
+
+#include <qdom.h>
+
+#include <kdevdocumentationplugin.h>
+
+class DocKDevTOCPlugin : public DocumentationPlugin
+{
+ Q_OBJECT
+public:
+ DocKDevTOCPlugin(QObject* parent, const char* name, const QStringList args = QStringList());
+ ~DocKDevTOCPlugin();
+
+ virtual QString pluginName() const;
+
+ virtual QString catalogTitle(const QString& url);
+ virtual DocumentationCatalogItem* createCatalog(KListView* contents, const QString& title, const QString& url);
+ virtual void createTOC(DocumentationCatalogItem* item);
+ virtual void setCatalogURL(DocumentationCatalogItem* item);
+
+ virtual bool needRefreshIndex(DocumentationCatalogItem* item);
+ virtual void createIndex(IndexBox* index, DocumentationCatalogItem* item);
+
+ virtual QStringList fullTextSearchLocations();
+
+ virtual QPair<KFile::Mode, QString > catalogLocatorProps();
+ virtual void autoSetupPlugin();
+
+protected:
+ void addTocSect(DocumentationItem *parent, QDomElement childEl, const QString &base, uint level);
+ static QString constructURL(const QString &base, const QString &url) ;
+};
+
+#endif