From 00bb99ac80741fc50ef8a289719373032f2391eb Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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/kdeaccessibility@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ksayit/src/docbookgenerator.cpp | 483 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 483 insertions(+) create mode 100644 ksayit/src/docbookgenerator.cpp (limited to 'ksayit/src/docbookgenerator.cpp') diff --git a/ksayit/src/docbookgenerator.cpp b/ksayit/src/docbookgenerator.cpp new file mode 100644 index 0000000..1d6db9c --- /dev/null +++ b/ksayit/src/docbookgenerator.cpp @@ -0,0 +1,483 @@ +// +// C++ Implementation: docbookgenerator +// +// Description: +// +// +// Author: Robert Vogl , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +// Qt includes +#include +#include + +//KDE includes +#include +#include +#include + +// App specific includes +#include "docbookgenerator.h" + + +DocbookGenerator::DocbookGenerator() +{ +} + + +DocbookGenerator::~DocbookGenerator() +{ +} + + +void DocbookGenerator::writeBook(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeBook()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "RobDocument" ) + return; + + // add node to document + doc << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "BookInfo" ){ + writeBookInfo( doc, i ); + } else if ( itemType == "Chapter" ) { + writeChapter( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + doc << "" << endl; +} + + +void DocbookGenerator::writeBookInfo(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeBookInfo()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "BookInfo" ) + return; + + // add node to document + doc << "" << endl; + writeTitleOfBook( doc, item ); + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "KeywordSet" ){ + writeKeywordSet( doc, i ); + } else if ( itemType == "Abstract" ) { + writeAbstract( doc, i ); + } else if ( itemType == "AuthorGroup" ) { + writeAuthorGroup( doc, i ); + } else if ( itemType == "Date" ) { + writeDate( doc, i ); + } else if ( itemType == "ReleaseInfo" ) { + writeReleaseInfo( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeTitleOfBook(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeTitle()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "BookInfo" ) + return; + + // Documents title is stored in root element (parent of BookInfo) + ListViewInterface *parent = static_cast(item->parent()); + if ( parent ){ + QString title = parent->text(0); + + // add node to document + doc << "" << title << "" << endl; + } +} + + +void DocbookGenerator::writeAuthorGroup(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeAuthorGroup()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "AuthorGroup" ) + return; + + // add node to document + doc << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "Author" ){ + writeAuthor( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeAuthor(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeAuthor()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Author" ) + return; + + QString author = QString::null; + author = ( item->getValue(KSayItGlobal::RAWDATA) ).toString(); + + // add node to document + doc << "" << endl; + + // process childs + doc << "" << author.section(' ', 0, 0) << "" << endl; + doc << "" << author.section(' ', 1, 1) << "" << endl; + + doc << "" << endl; +} + + +void DocbookGenerator::writeDate(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeDate()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Date" ) + return; + + QString date = item->text(1); + + // add node to document + doc << "" << date << "" << endl; +} + + +void DocbookGenerator::writeReleaseInfo(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeReleaseInfo()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "ReleaseInfo" ) + return; + + QString releaseinfo = item->text(1); + + // add node to document + doc << "" << releaseinfo << "" << endl; +} + + +void DocbookGenerator::writeKeywordSet(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeKeywordSet()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "KeywordSet" ) + return; + + // add node to document + doc << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = ( i->getValue(KSayItGlobal::XMLCONTEXTNAME) ).toString(); + if ( itemType == "Keyword" ){ + writeKeyword( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeKeyword(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeKeyword()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Keyword" ) + return; + + // QString keyword = item->text( 0 ); + QString keyword = QString::null; + keyword = (item->getValue(3)).toString(); + + // add node to document + doc << "" << keyword << "" << endl; + + // process childs + // no childs +} + + +void DocbookGenerator::writeAbstract(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeAbstract()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Abstract" ) + return; + + // add node to document + doc << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "Para" ){ + writePara( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeChapter( QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeChapter()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Chapter" ) + return; + + QString title = item->text(0); + + // add node to document + doc << "" << endl; + doc << "" << title << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "Para" ){ + writePara( doc, i ); + } else if ( itemType == "Sect1" ) { + writeSect1( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeSect1(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeSect1()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Sect1" ) + return; + + QString title = item->text(0); + + // add node to document + doc << "" << endl; + doc << "" << title << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "Para" ){ + writePara( doc, i ); + } else if ( itemType == "Sect2" ) { + writeSect2( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeSect2(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeSect1()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Sect2" ) + return; + + QString title = item->text(0); + + // add node to document + doc << "" << endl; + doc << "" << title << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = ( i->getValue(KSayItGlobal::XMLCONTEXTNAME) ).toString(); + if ( itemType == "Para" ){ + writePara( doc, i ); + } else if ( itemType == "Sect3" ) { + writeSect3( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeSect3(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeSect3()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Sect3" ) + return; + + QString title = item->text(0); + + // add node to document + doc << "" << endl; + doc << "" << title << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "Para" ){ + writePara( doc, i ); + } else if ( itemType == "Sect4" ) { + writeSect4( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeSect4(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeSect4()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Sect4" ) + return; + + QString title = item->text(0); + + // add node to document + doc << "" << endl; + doc << "" << title << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "Para" ){ + writePara( doc, i ); + } else if ( itemType == "Sect5" ) { + writeSect5( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writeSect5(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writeSect5()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Sect5" ) + return; + + QString title = item->text(0); + + // add node to document + doc << "" << endl; + doc << "" << title << "" << endl; + + // process childs + ListViewInterface *i = static_cast(item->firstChild()); + QString itemType; + while( i ){ + itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( itemType == "Para" ){ + writePara( doc, i ); + } + // next child + i = static_cast(i->nextSibling()); + } + + doc << "" << endl; +} + + +void DocbookGenerator::writePara(QTextStream &doc, ListViewInterface *item) +{ + kdDebug(100200) << "DocTreeViewImpl::writePara()" << endl; + // read item's content + QString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); + if ( whoAmI != "Para" ) + return; + + QString data = ( item->getValue(KSayItGlobal::RAWDATA) ).toString(); + + // add node to document + doc << "" << endl; + doc << data << endl; + doc << "" << endl; + + // process childs + // childs are embedded in data. +} + + + + -- cgit v1.2.1