26 #include "hbdocumentloader_p.h" |
26 #include "hbdocumentloader_p.h" |
27 #include "hbdocumentloaderactions_p.h" |
27 #include "hbdocumentloaderactions_p.h" |
28 #include "hbdocumentloadersyntax_p.h" |
28 #include "hbdocumentloadersyntax_p.h" |
29 #include "hbdocumentloader.h" |
29 #include "hbdocumentloader.h" |
30 |
30 |
|
31 #include <hbxmlloaderbinaryactions_p.h> |
|
32 #include <hbxmlloaderbinarysyntax_p.h> |
|
33 |
|
34 #ifndef HB_BOOTSTRAPPED |
|
35 |
31 #include <QGraphicsWidget> |
36 #include <QGraphicsWidget> |
32 |
|
33 #include <QCoreApplication> |
37 #include <QCoreApplication> |
34 #include <QDir> |
38 #include <QDir> |
35 #include <QPluginLoader> |
39 #include <QPluginLoader> |
36 #include "hbdocumentloaderplugin.h" |
40 #include "hbdocumentloaderplugin.h" |
37 #include <hbmainwindow.h> |
41 #include <hbmainwindow.h> |
38 #include <hbinstance.h> |
42 #include <hbinstance.h> |
|
43 #include <QBuffer> |
|
44 |
|
45 #endif // HB_BOOTSTRAPPED |
39 |
46 |
40 /* |
47 /* |
41 \class HbDocumentLoaderPrivate |
48 \class HbDocumentLoaderPrivate |
42 \internal |
49 \internal |
43 \proto |
50 \proto |
44 */ |
51 */ |
45 |
52 |
|
53 //#define DEBUG_TIMES |
|
54 |
|
55 #ifdef DEBUG_TIMES |
|
56 #include <QTime> |
|
57 #include <QDebug> |
|
58 static QTime debugTime; |
|
59 |
|
60 #ifdef Q_OS_SYMBIAN |
|
61 #include <e32debug.h> |
|
62 #endif |
|
63 |
|
64 void doDebugPrintX(const char* text) |
|
65 { |
|
66 #ifdef Q_OS_SYMBIAN |
|
67 RDebug::Printf(text); |
|
68 #else |
|
69 qDebug() << text; |
|
70 #endif |
|
71 } |
|
72 |
|
73 // Takes standard c-format. |
|
74 void debugPrintX(const char* cformat, ...) |
|
75 { |
|
76 va_list ap; |
|
77 va_start(ap, cformat); |
|
78 QString str = QString().vsprintf(cformat, ap); |
|
79 va_end(ap); |
|
80 doDebugPrintX(str.toAscii().constData()); |
|
81 } |
|
82 |
|
83 #endif // DEBUG_TIMES |
|
84 |
46 |
85 |
47 HbDocumentLoaderPrivate::HbDocumentLoaderPrivate(const HbMainWindow *window) |
86 HbDocumentLoaderPrivate::HbDocumentLoaderPrivate(const HbMainWindow *window) |
48 : q_ptr(0) |
87 : q_ptr(0) |
49 { |
88 { |
50 actions = new HbDocumentLoaderActions(this); |
89 #ifdef HB_BOOTSTRAPPED |
51 syntax = new HbDocumentLoaderSyntax(actions, window); |
90 Q_UNUSED(window); |
|
91 #else |
|
92 actions = new HbDocumentLoaderActions(this, window); |
|
93 binarysyntax = new HbXmlLoaderBinarySyntax(actions); |
52 pluginManager = new HbDocumentLoaderPluginManager; |
94 pluginManager = new HbDocumentLoaderPluginManager; |
|
95 #endif |
|
96 binaryactions = new HbXmlLoaderBinaryActions(); |
|
97 syntax = new HbDocumentLoaderSyntax(binaryactions); |
53 } |
98 } |
54 |
99 |
55 HbDocumentLoaderPrivate::~HbDocumentLoaderPrivate() |
100 HbDocumentLoaderPrivate::~HbDocumentLoaderPrivate() |
56 { |
101 { |
|
102 delete binaryactions; |
|
103 delete syntax; |
|
104 #ifndef HB_BOOTSTRAPPED |
57 delete pluginManager; |
105 delete pluginManager; |
58 delete syntax; |
|
59 delete actions; |
106 delete actions; |
|
107 delete binarysyntax; |
|
108 #endif |
|
109 } |
|
110 |
|
111 bool HbDocumentLoaderPrivate::createBinary( QIODevice *srcDevice, QIODevice *dstDevice ) |
|
112 { |
|
113 bool result = true; |
|
114 syntax->setActions( binaryactions ); |
|
115 #ifdef DEBUG_TIMES |
|
116 debugTime.restart(); |
|
117 debugPrintX("MYTRACE: DocML create binary, start"); |
|
118 #endif |
|
119 binaryactions->setOutputDevice( dstDevice ); |
|
120 // TODO: Has to process all sections! |
|
121 QList<QString> sectionsList; |
|
122 QHash< QString, qint64 > sectionsPositionList; |
|
123 qint64 startPos = srcDevice->pos(); |
|
124 if( syntax->scanForSections( srcDevice, sectionsList ) ) { |
|
125 srcDevice->seek( startPos ); |
|
126 result = syntax->load( srcDevice, "" ); |
|
127 if( !sectionsList.isEmpty() ) { |
|
128 for( int i = 0; i < sectionsList.size(); i++ ) { |
|
129 sectionsPositionList[ sectionsList.at( i ) ] = dstDevice->pos(); |
|
130 srcDevice->seek( startPos ); |
|
131 result &= syntax->load( srcDevice, sectionsList.at( i ) ); |
|
132 } |
|
133 } |
|
134 } else { |
|
135 result = false; |
|
136 } |
|
137 qint64 sectionsMetaDataPos = dstDevice->pos(); |
|
138 QDataStream stream( dstDevice ); |
|
139 stream << sectionsPositionList; |
|
140 stream << sectionsMetaDataPos; |
|
141 |
|
142 |
|
143 #ifdef DEBUG_TIMES |
|
144 debugPrintX("MYTRACE: DocML create binary, end: %d", debugTime.elapsed()); |
|
145 #endif |
|
146 return result; |
60 } |
147 } |
61 |
148 |
62 bool HbDocumentLoaderPrivate::load( QIODevice *device, const QString §ion ) |
149 bool HbDocumentLoaderPrivate::load( QIODevice *device, const QString §ion ) |
63 { |
150 { |
64 return syntax->load( device, section ); |
151 #ifdef HB_BOOTSTRAPPED |
|
152 Q_UNUSED(device); |
|
153 Q_UNUSED(section); |
|
154 return false; |
|
155 #else |
|
156 bool result(true); |
|
157 |
|
158 if (binarysyntax->isBinary(device)) { |
|
159 binarysyntax->setActions(actions); |
|
160 #ifdef DEBUG_TIMES |
|
161 debugTime.restart(); |
|
162 debugPrintX("MYTRACE: DocML load binary, start"); |
|
163 #endif |
|
164 result = binarysyntax->load( device, section ); |
|
165 #ifdef DEBUG_TIMES |
|
166 debugPrintX("MYTRACE: DocML load binary, end: %d", debugTime.elapsed()); |
|
167 #endif |
|
168 } else { |
|
169 syntax->setActions(actions); |
|
170 #ifdef DEBUG_TIMES |
|
171 debugTime.restart(); |
|
172 debugPrintX("MYTRACE: DocML load plain text, start"); |
|
173 #endif |
|
174 result = syntax->load( device, section ); |
|
175 #ifdef DEBUG_TIMES |
|
176 debugPrintX("MYTRACE: DocML load plain text, end: %d", debugTime.elapsed()); |
|
177 #endif |
|
178 } |
|
179 return result; |
|
180 #endif |
65 } |
181 } |
66 |
182 |
67 QList<QObject *> HbDocumentLoaderPrivate::takeAll() |
183 QList<QObject *> HbDocumentLoaderPrivate::takeAll() |
68 { |
184 { |
|
185 #ifdef HB_BOOTSTRAPPED |
|
186 QList<QObject *> list; |
|
187 return list; |
|
188 #else |
69 return actions->takeAll(); |
189 return actions->takeAll(); |
|
190 #endif |
70 } |
191 } |
71 |
192 |
72 QGraphicsWidget* HbDocumentLoaderPrivate::findWidget(const QString &name) const |
193 QGraphicsWidget* HbDocumentLoaderPrivate::findWidget(const QString &name) const |
73 { |
194 { |
|
195 #ifdef HB_BOOTSTRAPPED |
|
196 Q_UNUSED(name); |
|
197 return 0; |
|
198 #else |
74 return actions->findWidget( name ); |
199 return actions->findWidget( name ); |
|
200 #endif |
75 } |
201 } |
76 |
202 |
77 QObject* HbDocumentLoaderPrivate::findObject(const QString &name) const |
203 QObject* HbDocumentLoaderPrivate::findObject(const QString &name) const |
78 { |
204 { |
|
205 #ifdef HB_BOOTSTRAPPED |
|
206 Q_UNUSED(name); |
|
207 return 0; |
|
208 #else |
79 return actions->findObject( name ); |
209 return actions->findObject( name ); |
|
210 #endif |
80 } |
211 } |
81 |
212 |
82 |
213 |
83 QObject *HbDocumentLoaderPrivate::lookUp(const QString& type, const QString &name, const QString &plugin) |
214 QObject *HbDocumentLoaderPrivate::lookUp(const QString& type, const QString &name, const QString &plugin) |
84 { |
215 { |
|
216 #ifdef HB_BOOTSTRAPPED |
|
217 Q_UNUSED(type); |
|
218 Q_UNUSED(name); |
|
219 Q_UNUSED(plugin); |
|
220 return 0; |
|
221 #else |
85 if ( plugin.isEmpty() ) { |
222 if ( plugin.isEmpty() ) { |
86 return q_ptr->createObject( type, name ); |
223 return q_ptr->createObject( type, name ); |
87 } else { |
224 } else { |
88 QObject *object = pluginManager->lookUp( type, name, plugin ); |
225 QObject *object = pluginManager->lookUp( type, name, plugin ); |
89 if ( !object ) { |
226 if ( !object ) { |
90 // use factory loader for fallback |
227 // use factory loader for fallback |
91 object = q_ptr->createObject( type, name ); |
228 object = q_ptr->createObject( type, name ); |
92 } |
229 } |
93 return object; |
230 return object; |
94 } |
231 } |
|
232 #endif |
95 } |
233 } |
96 |
234 |
97 void HbDocumentLoaderPrivate::reset() |
235 void HbDocumentLoaderPrivate::reset() |
98 { |
236 { |
|
237 #ifndef HB_BOOTSTRAPPED |
99 actions->reset(); |
238 actions->reset(); |
|
239 #endif |
100 } |
240 } |
101 |
241 |
102 bool HbDocumentLoaderPrivate::setObjectTree( QList<QObject *> roots ) |
242 bool HbDocumentLoaderPrivate::setObjectTree( QList<QObject *> roots ) |
103 { |
243 { |
|
244 #ifdef HB_BOOTSTRAPPED |
|
245 Q_UNUSED(roots); |
|
246 return false; |
|
247 #else |
104 return actions->setObjectTree( roots ); |
248 return actions->setObjectTree( roots ); |
|
249 #endif |
105 } |
250 } |
106 |
251 |
107 QString HbDocumentLoaderPrivate::version() |
252 QString HbDocumentLoaderPrivate::version() |
108 { |
253 { |
|
254 #ifdef HB_BOOTSTRAPPED |
|
255 return QString(); |
|
256 #else |
109 return HbDocumentLoaderSyntax::version(); |
257 return HbDocumentLoaderSyntax::version(); |
110 } |
258 #endif |
111 |
259 } |
112 |
260 |
|
261 |
|
262 #ifndef HB_BOOTSTRAPPED |
113 HbDocumentLoaderPluginManager::HbDocumentLoaderPluginManager() |
263 HbDocumentLoaderPluginManager::HbDocumentLoaderPluginManager() |
114 { |
264 { |
115 } |
265 } |
116 |
266 |
117 HbDocumentLoaderPluginManager::~HbDocumentLoaderPluginManager() |
267 HbDocumentLoaderPluginManager::~HbDocumentLoaderPluginManager() |