diff -r 16d8024aca5e -r f7ac710697a9 src/hbutils/document/hbdocumentloader_p.cpp --- a/src/hbutils/document/hbdocumentloader_p.cpp Mon Apr 19 14:02:13 2010 +0300 +++ b/src/hbutils/document/hbdocumentloader_p.cpp Mon May 03 12:48:33 2010 +0300 @@ -28,14 +28,21 @@ #include "hbdocumentloadersyntax_p.h" #include "hbdocumentloader.h" +#include +#include + +#ifndef HB_BOOTSTRAPPED + #include - #include #include #include #include "hbdocumentloaderplugin.h" #include #include +#include + +#endif // HB_BOOTSTRAPPED /* \class HbDocumentLoaderPrivate @@ -43,45 +50,175 @@ \proto */ +//#define DEBUG_TIMES + +#ifdef DEBUG_TIMES +#include +#include +static QTime debugTime; + +#ifdef Q_OS_SYMBIAN +#include +#endif + +void doDebugPrintX(const char* text) +{ +#ifdef Q_OS_SYMBIAN + RDebug::Printf(text); +#else + qDebug() << text; +#endif +} + +// Takes standard c-format. +void debugPrintX(const char* cformat, ...) +{ + va_list ap; + va_start(ap, cformat); + QString str = QString().vsprintf(cformat, ap); + va_end(ap); + doDebugPrintX(str.toAscii().constData()); +} + +#endif // DEBUG_TIMES + HbDocumentLoaderPrivate::HbDocumentLoaderPrivate(const HbMainWindow *window) : q_ptr(0) { - actions = new HbDocumentLoaderActions(this); - syntax = new HbDocumentLoaderSyntax(actions, window); +#ifdef HB_BOOTSTRAPPED + Q_UNUSED(window); +#else + actions = new HbDocumentLoaderActions(this, window); + binarysyntax = new HbXmlLoaderBinarySyntax(actions); pluginManager = new HbDocumentLoaderPluginManager; +#endif + binaryactions = new HbXmlLoaderBinaryActions(); + syntax = new HbDocumentLoaderSyntax(binaryactions); } HbDocumentLoaderPrivate::~HbDocumentLoaderPrivate() { - delete pluginManager; + delete binaryactions; delete syntax; +#ifndef HB_BOOTSTRAPPED + delete pluginManager; delete actions; + delete binarysyntax; +#endif +} + +bool HbDocumentLoaderPrivate::createBinary( QIODevice *srcDevice, QIODevice *dstDevice ) +{ + bool result = true; + syntax->setActions( binaryactions ); +#ifdef DEBUG_TIMES + debugTime.restart(); + debugPrintX("MYTRACE: DocML create binary, start"); +#endif + binaryactions->setOutputDevice( dstDevice ); + // TODO: Has to process all sections! + QList sectionsList; + QHash< QString, qint64 > sectionsPositionList; + qint64 startPos = srcDevice->pos(); + if( syntax->scanForSections( srcDevice, sectionsList ) ) { + srcDevice->seek( startPos ); + result = syntax->load( srcDevice, "" ); + if( !sectionsList.isEmpty() ) { + for( int i = 0; i < sectionsList.size(); i++ ) { + sectionsPositionList[ sectionsList.at( i ) ] = dstDevice->pos(); + srcDevice->seek( startPos ); + result &= syntax->load( srcDevice, sectionsList.at( i ) ); + } + } + } else { + result = false; + } + qint64 sectionsMetaDataPos = dstDevice->pos(); + QDataStream stream( dstDevice ); + stream << sectionsPositionList; + stream << sectionsMetaDataPos; + + +#ifdef DEBUG_TIMES + debugPrintX("MYTRACE: DocML create binary, end: %d", debugTime.elapsed()); +#endif + return result; } bool HbDocumentLoaderPrivate::load( QIODevice *device, const QString §ion ) { - return syntax->load( device, section ); +#ifdef HB_BOOTSTRAPPED + Q_UNUSED(device); + Q_UNUSED(section); + return false; +#else + bool result(true); + + if (binarysyntax->isBinary(device)) { + binarysyntax->setActions(actions); +#ifdef DEBUG_TIMES + debugTime.restart(); + debugPrintX("MYTRACE: DocML load binary, start"); +#endif + result = binarysyntax->load( device, section ); +#ifdef DEBUG_TIMES + debugPrintX("MYTRACE: DocML load binary, end: %d", debugTime.elapsed()); +#endif + } else { + syntax->setActions(actions); +#ifdef DEBUG_TIMES + debugTime.restart(); + debugPrintX("MYTRACE: DocML load plain text, start"); +#endif + result = syntax->load( device, section ); +#ifdef DEBUG_TIMES + debugPrintX("MYTRACE: DocML load plain text, end: %d", debugTime.elapsed()); +#endif + } + return result; +#endif } QList HbDocumentLoaderPrivate::takeAll() { +#ifdef HB_BOOTSTRAPPED + QList list; + return list; +#else return actions->takeAll(); +#endif } QGraphicsWidget* HbDocumentLoaderPrivate::findWidget(const QString &name) const { +#ifdef HB_BOOTSTRAPPED + Q_UNUSED(name); + return 0; +#else return actions->findWidget( name ); +#endif } QObject* HbDocumentLoaderPrivate::findObject(const QString &name) const { +#ifdef HB_BOOTSTRAPPED + Q_UNUSED(name); + return 0; +#else return actions->findObject( name ); +#endif } QObject *HbDocumentLoaderPrivate::lookUp(const QString& type, const QString &name, const QString &plugin) { +#ifdef HB_BOOTSTRAPPED + Q_UNUSED(type); + Q_UNUSED(name); + Q_UNUSED(plugin); + return 0; +#else if ( plugin.isEmpty() ) { return q_ptr->createObject( type, name ); } else { @@ -92,24 +229,37 @@ } return object; } +#endif } void HbDocumentLoaderPrivate::reset() { +#ifndef HB_BOOTSTRAPPED actions->reset(); +#endif } bool HbDocumentLoaderPrivate::setObjectTree( QList roots ) { +#ifdef HB_BOOTSTRAPPED + Q_UNUSED(roots); + return false; +#else return actions->setObjectTree( roots ); +#endif } QString HbDocumentLoaderPrivate::version() { +#ifdef HB_BOOTSTRAPPED + return QString(); +#else return HbDocumentLoaderSyntax::version(); +#endif } +#ifndef HB_BOOTSTRAPPED HbDocumentLoaderPluginManager::HbDocumentLoaderPluginManager() { } @@ -228,5 +378,7 @@ return 0; } +#endif // HB_BOOTSTRAPPED + // end of file