-rw-r--r-- | noncore/apps/tableviewer/db/common.cpp | 28 | ||||
-rw-r--r-- | noncore/apps/tableviewer/db/datacache.cpp | 12 | ||||
-rw-r--r-- | noncore/apps/tableviewer/db/xmlsource.cpp | 30 |
3 files changed, 46 insertions, 24 deletions
diff --git a/noncore/apps/tableviewer/db/common.cpp b/noncore/apps/tableviewer/db/common.cpp index dbf9370..6e544ba 100644 --- a/noncore/apps/tableviewer/db/common.cpp +++ b/noncore/apps/tableviewer/db/common.cpp | |||
@@ -1,52 +1,60 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <stdlib.h> | 20 | #include "common.h" |
21 | #include "datacache.h" | ||
22 | |||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
25 | #include <qpe/timestring.h> | ||
26 | using namespace Opie::Core; | ||
27 | |||
28 | /* QT */ | ||
21 | #include <qstring.h> | 29 | #include <qstring.h> |
22 | #include <qheader.h> | 30 | #include <qheader.h> |
23 | #include <qvector.h> | 31 | #include <qvector.h> |
24 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
25 | #include <qpe/timestring.h> | 33 | |
26 | #include "common.h" | 34 | /* STD */ |
27 | #include "datacache.h" | ||
28 | #include <assert.h> | 35 | #include <assert.h> |
36 | #include <stdlib.h> | ||
29 | 37 | ||
30 | static const int del_flag = 0x1; | 38 | static const int del_flag = 0x1; |
31 | static const int new_flag = 0x2; | 39 | static const int new_flag = 0x2; |
32 | 40 | ||
33 | /* Helper function */ | 41 | /* Helper function */ |
34 | 42 | ||
35 | int parseNextNumber(QString *q) { | 43 | int parseNextNumber(QString *q) { |
36 | QChar c; | 44 | QChar c; |
37 | uint i; | 45 | uint i; |
38 | int result = 0; | 46 | int result = 0; |
39 | 47 | ||
40 | bool found_digits = FALSE; | 48 | bool found_digits = FALSE; |
41 | for(i = 0; i < q->length(); i++) { | 49 | for(i = 0; i < q->length(); i++) { |
42 | c = q->at(i); | 50 | c = q->at(i); |
43 | if (c.isDigit()) { | 51 | if (c.isDigit()) { |
44 | if (found_digits) | 52 | if (found_digits) |
45 | result *= 10; | 53 | result *= 10; |
46 | found_digits = TRUE; | 54 | found_digits = TRUE; |
47 | result += c.digitValue(); | 55 | result += c.digitValue(); |
48 | } else { | 56 | } else { |
49 | if (found_digits) | 57 | if (found_digits) |
50 | break; | 58 | break; |
51 | /* just skip this char */ | 59 | /* just skip this char */ |
52 | } | 60 | } |
@@ -291,49 +299,49 @@ void TVVariant::load(QDataStream &s ) | |||
291 | } | 299 | } |
292 | break; | 300 | break; |
293 | case Time: | 301 | case Time: |
294 | { | 302 | { |
295 | QTime *x = new QTime; | 303 | QTime *x = new QTime; |
296 | s >> *x; | 304 | s >> *x; |
297 | d->value.ptr = x; | 305 | d->value.ptr = x; |
298 | } | 306 | } |
299 | break; | 307 | break; |
300 | case Date: | 308 | case Date: |
301 | { | 309 | { |
302 | QDate *x = new QDate; | 310 | QDate *x = new QDate; |
303 | s >> *x; | 311 | s >> *x; |
304 | d->value.ptr = x; | 312 | d->value.ptr = x; |
305 | } | 313 | } |
306 | break; | 314 | break; |
307 | case Int: | 315 | case Int: |
308 | { | 316 | { |
309 | int x; | 317 | int x; |
310 | s >> x; | 318 | s >> x; |
311 | d->value.i = x; | 319 | d->value.i = x; |
312 | } | 320 | } |
313 | break; | 321 | break; |
314 | default: | 322 | default: |
315 | qFatal("Unrecognized data type"); | 323 | ofatal << "Unrecognized data type" << oendl; |
316 | } | 324 | } |
317 | } | 325 | } |
318 | 326 | ||
319 | void TVVariant::save( QDataStream &s ) const | 327 | void TVVariant::save( QDataStream &s ) const |
320 | { | 328 | { |
321 | s << type(); | 329 | s << type(); |
322 | 330 | ||
323 | switch( d->typ ) { | 331 | switch( d->typ ) { |
324 | case String: | 332 | case String: |
325 | s << *((QString *)d->value.ptr); | 333 | s << *((QString *)d->value.ptr); |
326 | break; | 334 | break; |
327 | case Date: | 335 | case Date: |
328 | s << *((QDate *)d->value.ptr); | 336 | s << *((QDate *)d->value.ptr); |
329 | break; | 337 | break; |
330 | case Time: | 338 | case Time: |
331 | s << *((QTime *)d->value.ptr); | 339 | s << *((QTime *)d->value.ptr); |
332 | break; | 340 | break; |
333 | case Int: | 341 | case Int: |
334 | s << d->value.i; | 342 | s << d->value.i; |
335 | break; | 343 | break; |
336 | case Invalid: | 344 | case Invalid: |
337 | break; | 345 | break; |
338 | } | 346 | } |
339 | } | 347 | } |
@@ -1057,49 +1065,49 @@ QDataStream &operator<<( QDataStream &s, const DataElem &d) | |||
1057 | int size = d.getNumFields(); | 1065 | int size = d.getNumFields(); |
1058 | 1066 | ||
1059 | s << size; /* redundent data but makes streaming easier */ | 1067 | s << size; /* redundent data but makes streaming easier */ |
1060 | KeyList k = d.getKeys(); | 1068 | KeyList k = d.getKeys(); |
1061 | 1069 | ||
1062 | KeyListIterator it(k); | 1070 | KeyListIterator it(k); |
1063 | 1071 | ||
1064 | while(it.current()) { | 1072 | while(it.current()) { |
1065 | s << (Q_UINT16)it.currentKey(); | 1073 | s << (Q_UINT16)it.currentKey(); |
1066 | s << d.getField(it.currentKey()); | 1074 | s << d.getField(it.currentKey()); |
1067 | ++it; | 1075 | ++it; |
1068 | } | 1076 | } |
1069 | return s; | 1077 | return s; |
1070 | } | 1078 | } |
1071 | 1079 | ||
1072 | QDataStream &operator>>( QDataStream &s, DataElem &d) | 1080 | QDataStream &operator>>( QDataStream &s, DataElem &d) |
1073 | { | 1081 | { |
1074 | int i; | 1082 | int i; |
1075 | int size; | 1083 | int size; |
1076 | TVVariant t; | 1084 | TVVariant t; |
1077 | int index = 0; | 1085 | int index = 0; |
1078 | 1086 | ||
1079 | s >> size; /* redundent data but makes streaming easier */ | 1087 | s >> size; /* redundent data but makes streaming easier */ |
1080 | if (size != d.getNumFields()) { | 1088 | if (size != d.getNumFields()) { |
1081 | qWarning("DataSize mis-match"); | 1089 | owarn << "DataSize mis-match" << oendl; |
1082 | return s; /* sanity check failed.. don't load */ | 1090 | return s; /* sanity check failed.. don't load */ |
1083 | } | 1091 | } |
1084 | 1092 | ||
1085 | for(i = 0; i < size; i++) { | 1093 | for(i = 0; i < size; i++) { |
1086 | s >> (Q_UINT16)index; | 1094 | s >> (Q_UINT16)index; |
1087 | s >> t; | 1095 | s >> t; |
1088 | d.setField(index, t); | 1096 | d.setField(index, t); |
1089 | } | 1097 | } |
1090 | return s; | 1098 | return s; |
1091 | } | 1099 | } |
1092 | 1100 | ||
1093 | /*! Returns the number of possible (not valid) fields in the data element */ | 1101 | /*! Returns the number of possible (not valid) fields in the data element */ |
1094 | int DataElem::getNumFields() const | 1102 | int DataElem::getNumFields() const |
1095 | { | 1103 | { |
1096 | return contained->getNumFields(); | 1104 | return contained->getNumFields(); |
1097 | } | 1105 | } |
1098 | 1106 | ||
1099 | KeyList DataElem::getKeys() const | 1107 | KeyList DataElem::getKeys() const |
1100 | { | 1108 | { |
1101 | return *(contained->getKeys()); | 1109 | return *(contained->getKeys()); |
1102 | } | 1110 | } |
1103 | 1111 | ||
1104 | /*! | 1112 | /*! |
1105 | This function determines whether field index i of the element has been | 1113 | This function determines whether field index i of the element has been |
@@ -1356,115 +1364,115 @@ bool DataElem::equalTo(int i, TVVariant v) const | |||
1356 | } | 1364 | } |
1357 | 1365 | ||
1358 | bool DataElem::contains(int i, TVVariant v) const | 1366 | bool DataElem::contains(int i, TVVariant v) const |
1359 | { | 1367 | { |
1360 | if (!hasValidValue(i)) return FALSE; | 1368 | if (!hasValidValue(i)) return FALSE; |
1361 | 1369 | ||
1362 | if (getField(i).type() != v.type()) | 1370 | if (getField(i).type() != v.type()) |
1363 | return FALSE; | 1371 | return FALSE; |
1364 | 1372 | ||
1365 | switch(getField(i).type()) { | 1373 | switch(getField(i).type()) { |
1366 | case TVVariant::String: { | 1374 | case TVVariant::String: { |
1367 | QString qs1 = getField(i).toString().lower(); | 1375 | QString qs1 = getField(i).toString().lower(); |
1368 | QString qs2 = v.toString().lower(); | 1376 | QString qs2 = v.toString().lower(); |
1369 | if (qs1.contains(qs2) > 0) return TRUE; | 1377 | if (qs1.contains(qs2) > 0) return TRUE; |
1370 | break; | 1378 | break; |
1371 | } | 1379 | } |
1372 | /* meaningless for ints */ | 1380 | /* meaningless for ints */ |
1373 | /* meaningless for time */ | 1381 | /* meaningless for time */ |
1374 | /* meaningless for dates */ | 1382 | /* meaningless for dates */ |
1375 | case TVVariant::Int: | 1383 | case TVVariant::Int: |
1376 | case TVVariant::Time: | 1384 | case TVVariant::Time: |
1377 | case TVVariant::Date: | 1385 | case TVVariant::Date: |
1378 | break; | 1386 | break; |
1379 | default: | 1387 | default: |
1380 | qWarning("Tried to compare unknown data type"); | 1388 | owarn << "Tried to compare unknown data type" << oendl; |
1381 | } | 1389 | } |
1382 | return FALSE; | 1390 | return FALSE; |
1383 | } | 1391 | } |
1384 | 1392 | ||
1385 | bool DataElem::startsWith(int i, TVVariant v) const | 1393 | bool DataElem::startsWith(int i, TVVariant v) const |
1386 | { | 1394 | { |
1387 | if (!hasValidValue(i)) return FALSE; | 1395 | if (!hasValidValue(i)) return FALSE; |
1388 | 1396 | ||
1389 | if (getField(i).type() != v.type()) | 1397 | if (getField(i).type() != v.type()) |
1390 | return FALSE; | 1398 | return FALSE; |
1391 | 1399 | ||
1392 | switch(getField(i).type()) { | 1400 | switch(getField(i).type()) { |
1393 | case TVVariant::String: { | 1401 | case TVVariant::String: { |
1394 | QString qs1 = getField(i).toString().lower(); | 1402 | QString qs1 = getField(i).toString().lower(); |
1395 | QString qs2 = v.toString().lower(); | 1403 | QString qs2 = v.toString().lower(); |
1396 | return qs1.startsWith(qs2); | 1404 | return qs1.startsWith(qs2); |
1397 | } | 1405 | } |
1398 | /* meaningless for ints */ | 1406 | /* meaningless for ints */ |
1399 | /* meaningless for time */ | 1407 | /* meaningless for time */ |
1400 | /* meaningless for dates */ | 1408 | /* meaningless for dates */ |
1401 | case TVVariant::Int: | 1409 | case TVVariant::Int: |
1402 | case TVVariant::Time: | 1410 | case TVVariant::Time: |
1403 | case TVVariant::Date: | 1411 | case TVVariant::Date: |
1404 | return FALSE; | 1412 | return FALSE; |
1405 | default: | 1413 | default: |
1406 | qWarning("Tried to compare unknown data type"); | 1414 | owarn << "Tried to compare unknown data type" << oendl; |
1407 | } | 1415 | } |
1408 | return FALSE; | 1416 | return FALSE; |
1409 | } | 1417 | } |
1410 | 1418 | ||
1411 | bool DataElem::endsWith(int i, TVVariant v) const | 1419 | bool DataElem::endsWith(int i, TVVariant v) const |
1412 | { | 1420 | { |
1413 | if (!hasValidValue(i)) return FALSE; | 1421 | if (!hasValidValue(i)) return FALSE; |
1414 | 1422 | ||
1415 | if (getField(i).type() != v.type()) | 1423 | if (getField(i).type() != v.type()) |
1416 | return FALSE; | 1424 | return FALSE; |
1417 | 1425 | ||
1418 | switch(getField(i).type()) { | 1426 | switch(getField(i).type()) { |
1419 | case TVVariant::String: { | 1427 | case TVVariant::String: { |
1420 | QString qs1 = getField(i).toString().lower(); | 1428 | QString qs1 = getField(i).toString().lower(); |
1421 | QString qs2 = v.toString().lower(); | 1429 | QString qs2 = v.toString().lower(); |
1422 | return qs1.startsWith(qs2); | 1430 | return qs1.startsWith(qs2); |
1423 | } | 1431 | } |
1424 | /* meaningless for ints */ | 1432 | /* meaningless for ints */ |
1425 | /* meaningless for time */ | 1433 | /* meaningless for time */ |
1426 | /* meaningless for dates */ | 1434 | /* meaningless for dates */ |
1427 | case TVVariant::Int: | 1435 | case TVVariant::Int: |
1428 | case TVVariant::Time: | 1436 | case TVVariant::Time: |
1429 | case TVVariant::Date: | 1437 | case TVVariant::Date: |
1430 | return FALSE; | 1438 | return FALSE; |
1431 | default: | 1439 | default: |
1432 | qWarning("Tried to compare unknown data type"); | 1440 | owarn << "Tried to compare unknown data type" << oendl; |
1433 | } | 1441 | } |
1434 | return FALSE; | 1442 | return FALSE; |
1435 | } | 1443 | } |
1436 | 1444 | ||
1437 | /*! | 1445 | /*! |
1438 | Determins which of the first to parameters are closer to the third, target | 1446 | Determins which of the first to parameters are closer to the third, target |
1439 | parameter. | 1447 | parameter. |
1440 | 1448 | ||
1441 | \return | 1449 | \return |
1442 | <UL> | 1450 | <UL> |
1443 | <LI>TRUE if the first element is a closer match to the target than the | 1451 | <LI>TRUE if the first element is a closer match to the target than the |
1444 | second element</LI> | 1452 | second element</LI> |
1445 | <LI>FALSE if the first element is not a closer match to the target than | 1453 | <LI>FALSE if the first element is not a closer match to the target than |
1446 | the second element</LI> | 1454 | the second element</LI> |
1447 | </UL> | 1455 | </UL> |
1448 | */ | 1456 | */ |
1449 | bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) | 1457 | bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) |
1450 | { | 1458 | { |
1451 | int type; | 1459 | int type; |
1452 | 1460 | ||
1453 | if(!d1) return FALSE; | 1461 | if(!d1) return FALSE; |
1454 | 1462 | ||
1455 | if (!d1->hasValidValue(column)) return FALSE; | 1463 | if (!d1->hasValidValue(column)) return FALSE; |
1456 | 1464 | ||
1457 | if(!target.isValid()) return FALSE; | 1465 | if(!target.isValid()) return FALSE; |
1458 | 1466 | ||
1459 | type = d1->getField(column).type(); | 1467 | type = d1->getField(column).type(); |
1460 | 1468 | ||
1461 | if(d2) { | 1469 | if(d2) { |
1462 | if (type != d2->getField(column).type()) { | 1470 | if (type != d2->getField(column).type()) { |
1463 | /* can't do compare */ | 1471 | /* can't do compare */ |
1464 | qWarning("Tried to compare two incompatable types"); | 1472 | owarn << "Tried to compare two incompatable types" << oendl; |
1465 | return FALSE; | 1473 | return FALSE; |
1466 | } | 1474 | } |
1467 | return target.closer(d1->getField(column), d2->getField(column)); | 1475 | return target.closer(d1->getField(column), d2->getField(column)); |
1468 | } | 1476 | } |
1469 | return target.close(d1->getField(column)); | 1477 | return target.close(d1->getField(column)); |
1470 | } | 1478 | } |
diff --git a/noncore/apps/tableviewer/db/datacache.cpp b/noncore/apps/tableviewer/db/datacache.cpp index 7c14eef..6380e1b 100644 --- a/noncore/apps/tableviewer/db/datacache.cpp +++ b/noncore/apps/tableviewer/db/datacache.cpp | |||
@@ -5,51 +5,59 @@ | |||
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | /* | 20 | /* |
21 | * This file is used to load the xml files that represent the database. | 21 | * This file is used to load the xml files that represent the database. |
22 | * The main requirment for said file is each data entry must contain a key, | 22 | * The main requirment for said file is each data entry must contain a key, |
23 | * otherwise any other data headings are allowed. | 23 | * otherwise any other data headings are allowed. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "datacache.h" | 26 | #include "datacache.h" |
27 | #include "xmlsource.h" | 27 | #include "xmlsource.h" |
28 | #include "csvsource.h" | 28 | #include "csvsource.h" |
29 | #include <stdlib.h> | 29 | |
30 | /* OPIE */ | ||
31 | #include <opie2/odebug.h> | ||
32 | using namespace Opie::Core; | ||
33 | |||
34 | /* QT */ | ||
30 | #include <qheader.h> | 35 | #include <qheader.h> |
31 | 36 | ||
37 | /* STD */ | ||
38 | #include <stdlib.h> | ||
39 | |||
32 | #define INIT_TABLE_SIZE 128 | 40 | #define INIT_TABLE_SIZE 128 |
33 | 41 | ||
34 | /*! | 42 | /*! |
35 | \class DBStore datastore.h | 43 | \class DBStore datastore.h |
36 | 44 | ||
37 | \brief The DBStore class is the class responsible for storing, sorting and | 45 | \brief The DBStore class is the class responsible for storing, sorting and |
38 | searching the data loaded by the application | 46 | searching the data loaded by the application |
39 | 47 | ||
40 | */ | 48 | */ |
41 | 49 | ||
42 | /*! | 50 | /*! |
43 | Constructs a DBStore item | 51 | Constructs a DBStore item |
44 | */ | 52 | */ |
45 | DBStore::DBStore() | 53 | DBStore::DBStore() |
46 | { | 54 | { |
47 | name = ""; | 55 | name = ""; |
48 | number_elems = 0; | 56 | number_elems = 0; |
49 | full = false; | 57 | full = false; |
50 | kRep = new KeyList(); | 58 | kRep = new KeyList(); |
51 | master_table.resize(INIT_TABLE_SIZE); | 59 | master_table.resize(INIT_TABLE_SIZE); |
52 | table_size = INIT_TABLE_SIZE; | 60 | table_size = INIT_TABLE_SIZE; |
53 | 61 | ||
54 | current_elem = 0; | 62 | current_elem = 0; |
55 | archive = 0; | 63 | archive = 0; |
@@ -129,49 +137,49 @@ bool DBStore::saveSource(QIODevice *outDev, const QString &source) | |||
129 | archive = new DBCsv(this); | 137 | archive = new DBCsv(this); |
130 | } else | 138 | } else |
131 | return false; | 139 | return false; |
132 | } | 140 | } |
133 | 141 | ||
134 | return (archive->saveSource(outDev)); | 142 | return (archive->saveSource(outDev)); |
135 | } | 143 | } |
136 | 144 | ||
137 | /*! | 145 | /*! |
138 | This function is used to add new elements to the database. If the database | 146 | This function is used to add new elements to the database. If the database |
139 | has already reached the maximum allowable size this function does not alter | 147 | has already reached the maximum allowable size this function does not alter |
140 | the database. | 148 | the database. |
141 | 149 | ||
142 | \param delm An already allocated and initialized data element to be added | 150 | \param delm An already allocated and initialized data element to be added |
143 | */ | 151 | */ |
144 | void DBStore::addItem(DataElem *delem) | 152 | void DBStore::addItem(DataElem *delem) |
145 | { | 153 | { |
146 | addItemInternal(delem); | 154 | addItemInternal(delem); |
147 | } | 155 | } |
148 | 156 | ||
149 | void DBStore::addItemInternal(DataElem *delem) | 157 | void DBStore::addItemInternal(DataElem *delem) |
150 | { | 158 | { |
151 | /* if already full, don't over fill, do a qWarning though */ | 159 | /* if already full, don't over fill, do a qWarning though */ |
152 | if (full) { | 160 | if (full) { |
153 | qWarning("Attempted to add items to already full table"); | 161 | owarn << "Attempted to add items to already full table" << oendl; |
154 | return; | 162 | return; |
155 | } | 163 | } |
156 | 164 | ||
157 | master_table.insert(number_elems, delem); | 165 | master_table.insert(number_elems, delem); |
158 | 166 | ||
159 | current_elem = number_elems; | 167 | current_elem = number_elems; |
160 | number_elems++; | 168 | number_elems++; |
161 | 169 | ||
162 | if(number_elems >= table_size) { | 170 | if(number_elems >= table_size) { |
163 | /* filled current table, double if we can */ | 171 | /* filled current table, double if we can */ |
164 | table_size = table_size << 1; | 172 | table_size = table_size << 1; |
165 | 173 | ||
166 | /* check that the new table size is still valid, i.e. that we didn't | 174 | /* check that the new table size is still valid, i.e. that we didn't |
167 | just shift the 1 bit of the end of the int. */ | 175 | just shift the 1 bit of the end of the int. */ |
168 | if (!table_size) { | 176 | if (!table_size) { |
169 | full = true; | 177 | full = true; |
170 | /* no point in doing antying else. */ | 178 | /* no point in doing antying else. */ |
171 | return; | 179 | return; |
172 | } | 180 | } |
173 | master_table.resize(table_size); | 181 | master_table.resize(table_size); |
174 | } | 182 | } |
175 | } | 183 | } |
176 | 184 | ||
177 | void DBStore::removeItem(DataElem *r) | 185 | void DBStore::removeItem(DataElem *r) |
diff --git a/noncore/apps/tableviewer/db/xmlsource.cpp b/noncore/apps/tableviewer/db/xmlsource.cpp index 94fec36..4ca6aee 100644 --- a/noncore/apps/tableviewer/db/xmlsource.cpp +++ b/noncore/apps/tableviewer/db/xmlsource.cpp | |||
@@ -1,50 +1,56 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "xmlsource.h" | 20 | #include "xmlsource.h" |
21 | #include <qdict.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <qtextstream.h> | ||
24 | #include "../xmlencodeattr.h" | 21 | #include "../xmlencodeattr.h" |
25 | 22 | ||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
25 | using namespace Opie::Core; | ||
26 | 26 | ||
27 | /* QT */ | ||
28 | #include <qdict.h> | ||
29 | #include <qtextstream.h> | ||
30 | |||
31 | /* STD */ | ||
32 | #include <stdlib.h> | ||
27 | 33 | ||
28 | DBXml::DBXml(DBStore *d) | 34 | DBXml::DBXml(DBStore *d) |
29 | { | 35 | { |
30 | dstore = d; | 36 | dstore = d; |
31 | } | 37 | } |
32 | 38 | ||
33 | QString DBXml::type() | 39 | QString DBXml::type() |
34 | { | 40 | { |
35 | return "xml"; | 41 | return "xml"; |
36 | } | 42 | } |
37 | 43 | ||
38 | bool DBXml::openSource(QIODevice *inDev) | 44 | bool DBXml::openSource(QIODevice *inDev) |
39 | { | 45 | { |
40 | bool ok; | 46 | bool ok; |
41 | 47 | ||
42 | DBXmlHandler h(dstore); | 48 | DBXmlHandler h(dstore); |
43 | 49 | ||
44 | QTextStream tsIn(inDev); | 50 | QTextStream tsIn(inDev); |
45 | QXmlInputSource source(tsIn); | 51 | QXmlInputSource source(tsIn); |
46 | QXmlSimpleReader reader; | 52 | QXmlSimpleReader reader; |
47 | reader.setContentHandler(&h); | 53 | reader.setContentHandler(&h); |
48 | reader.setErrorHandler(&h); | 54 | reader.setErrorHandler(&h); |
49 | ok = reader.parse(source); | 55 | ok = reader.parse(source); |
50 | 56 | ||
@@ -119,179 +125,179 @@ DBXml::~DBXml() {} | |||
119 | 125 | ||
120 | The format of the xml files can be found at the front of the file | 126 | The format of the xml files can be found at the front of the file |
121 | dataparser.h | 127 | dataparser.h |
122 | */ | 128 | */ |
123 | 129 | ||
124 | /*! | 130 | /*! |
125 | Constructs a new DBXmlHandler, and sets that the table should be | 131 | Constructs a new DBXmlHandler, and sets that the table should be |
126 | constructed in the DBStore pointed to by ds. | 132 | constructed in the DBStore pointed to by ds. |
127 | */ | 133 | */ |
128 | DBXmlHandler::DBXmlHandler(DBStore *ds) | 134 | DBXmlHandler::DBXmlHandler(DBStore *ds) |
129 | { | 135 | { |
130 | data_store = ds; | 136 | data_store = ds; |
131 | current_keyrep = 0; | 137 | current_keyrep = 0; |
132 | } | 138 | } |
133 | 139 | ||
134 | /*! | 140 | /*! |
135 | Destroys the DBXmlHandler | 141 | Destroys the DBXmlHandler |
136 | */ | 142 | */ |
137 | DBXmlHandler::~DBXmlHandler() | 143 | DBXmlHandler::~DBXmlHandler() |
138 | { | 144 | { |
139 | } | 145 | } |
140 | 146 | ||
141 | QString DBXmlHandler::errorProtocol() | 147 | QString DBXmlHandler::errorProtocol() |
142 | { | 148 | { |
143 | qWarning("Error reading file"); | 149 | owarn << "Error reading file" << oendl; |
144 | return errorProt; | 150 | return errorProt; |
145 | } | 151 | } |
146 | 152 | ||
147 | bool DBXmlHandler::startDocument() | 153 | bool DBXmlHandler::startDocument() |
148 | { | 154 | { |
149 | errorProt = ""; | 155 | errorProt = ""; |
150 | state = StateInit; | 156 | state = StateInit; |
151 | return TRUE; | 157 | return TRUE; |
152 | } | 158 | } |
153 | 159 | ||
154 | bool DBXmlHandler::startElement(const QString&, const QString&, | 160 | bool DBXmlHandler::startElement(const QString&, const QString&, |
155 | const QString& qName, const QXmlAttributes& atts) | 161 | const QString& qName, const QXmlAttributes& atts) |
156 | { | 162 | { |
157 | if (state == StateInit && qName == "database") { | 163 | if (state == StateInit && qName == "database") { |
158 | // First thing it expects is a <document name="..."> tag | 164 | // First thing it expects is a <document name="..."> tag |
159 | state = StateDocument; | 165 | state = StateDocument; |
160 | data_store->setName(atts.value("name")); | 166 | data_store->setName(atts.value("name")); |
161 | return TRUE; | 167 | return TRUE; |
162 | } | 168 | } |
163 | if (state == StateDocument && qName == "header") { | 169 | if (state == StateDocument && qName == "header") { |
164 | state = StateHeader; | 170 | state = StateHeader; |
165 | if (current_keyrep) delete current_keyrep; | 171 | if (current_keyrep) delete current_keyrep; |
166 | current_keyrep = new KeyList(); | 172 | current_keyrep = new KeyList(); |
167 | return TRUE; | 173 | return TRUE; |
168 | } | 174 | } |
169 | if (state == StateHeader && qName == "key") { | 175 | if (state == StateHeader && qName == "key") { |
170 | /* Ok, adding a new key to our KeyList TODO */ | 176 | /* Ok, adding a new key to our KeyList TODO */ |
171 | state = StateKey; | 177 | state = StateKey; |
172 | last_key_type = TVVariant::String; | 178 | last_key_type = TVVariant::String; |
173 | key = atts.value("name"); | 179 | key = atts.value("name"); |
174 | if (key.isEmpty()) { | 180 | if (key.isEmpty()) { |
175 | qWarning("empty key name"); | 181 | owarn << "empty key name" << oendl; |
176 | return FALSE; | 182 | return FALSE; |
177 | } | 183 | } |
178 | if(!atts.value("type").isEmpty()) | 184 | if(!atts.value("type").isEmpty()) |
179 | last_key_type = TVVariant::nameToType(atts.value("type")); | 185 | last_key_type = TVVariant::nameToType(atts.value("type")); |
180 | return TRUE; | 186 | return TRUE; |
181 | } | 187 | } |
182 | if (state == StateDocument && qName == "record") { | 188 | if (state == StateDocument && qName == "record") { |
183 | state = StateRecord; | 189 | state = StateRecord; |
184 | current_data = new DataElem(data_store); | 190 | current_data = new DataElem(data_store); |
185 | // Now expecting a <record> tag | 191 | // Now expecting a <record> tag |
186 | return TRUE; | 192 | return TRUE; |
187 | } | 193 | } |
188 | if (state == StateRecord) { | 194 | if (state == StateRecord) { |
189 | state = StateField; | 195 | state = StateField; |
190 | /* the qName is the name of a key */ | 196 | /* the qName is the name of a key */ |
191 | if (!keyIndexList[qName]) { | 197 | if (!keyIndexList[qName]) { |
192 | /* invalid key, we failed */ | 198 | /* invalid key, we failed */ |
193 | qWarning("Invalid key in record"); | 199 | owarn << "Invalid key in record" << oendl; |
194 | return FALSE; | 200 | return FALSE; |
195 | } | 201 | } |
196 | keyIndex = *keyIndexList[qName]; | 202 | keyIndex = *keyIndexList[qName]; |
197 | return TRUE; | 203 | return TRUE; |
198 | } | 204 | } |
199 | qWarning("Unable to determine tag type"); | 205 | owarn << "Unable to determine tag type" << oendl; |
200 | return FALSE; | 206 | return FALSE; |
201 | } | 207 | } |
202 | 208 | ||
203 | bool DBXmlHandler::endElement(const QString&, const QString&, | 209 | bool DBXmlHandler::endElement(const QString&, const QString&, |
204 | const QString& qName) | 210 | const QString& qName) |
205 | { | 211 | { |
206 | switch(state) { | 212 | switch(state) { |
207 | case StateField: | 213 | case StateField: |
208 | // TODO checks 'could' be done of the popped value | 214 | // TODO checks 'could' be done of the popped value |
209 | state = StateRecord; | 215 | state = StateRecord; |
210 | break; | 216 | break; |
211 | case StateKey: | 217 | case StateKey: |
212 | // TODO checks 'could' be done of the popped value | 218 | // TODO checks 'could' be done of the popped value |
213 | state = StateHeader; | 219 | state = StateHeader; |
214 | break; | 220 | break; |
215 | case StateHeader: | 221 | case StateHeader: |
216 | data_store->setKeys(current_keyrep); | 222 | data_store->setKeys(current_keyrep); |
217 | state = StateDocument; | 223 | state = StateDocument; |
218 | break; | 224 | break; |
219 | case StateRecord: | 225 | case StateRecord: |
220 | data_store->addItem(current_data); | 226 | data_store->addItem(current_data); |
221 | state = StateDocument; | 227 | state = StateDocument; |
222 | break; | 228 | break; |
223 | case StateDocument: | 229 | case StateDocument: |
224 | // we are done... | 230 | // we are done... |
225 | break; | 231 | break; |
226 | default: | 232 | default: |
227 | // should only get a 'endElement' from one of the above states. | 233 | // should only get a 'endElement' from one of the above states. |
228 | qWarning("Invalid end tag"); | 234 | owarn << "Invalid end tag" << oendl; |
229 | return FALSE; | 235 | return FALSE; |
230 | break; | 236 | break; |
231 | } | 237 | } |
232 | return TRUE; | 238 | return TRUE; |
233 | } | 239 | } |
234 | 240 | ||
235 | bool DBXmlHandler::characters(const QString& ch) | 241 | bool DBXmlHandler::characters(const QString& ch) |
236 | { | 242 | { |
237 | // this is where the 'between tag' stuff happens. | 243 | // this is where the 'between tag' stuff happens. |
238 | // e.g. the stuff between tags. | 244 | // e.g. the stuff between tags. |
239 | QString ch_simplified = ch.simplifyWhiteSpace(); | 245 | QString ch_simplified = ch.simplifyWhiteSpace(); |
240 | 246 | ||
241 | if (ch_simplified.isEmpty()) | 247 | if (ch_simplified.isEmpty()) |
242 | return TRUE; | 248 | return TRUE; |
243 | 249 | ||
244 | if (state == StateKey) { | 250 | if (state == StateKey) { |
245 | int *tmp_val = new int; | 251 | int *tmp_val = new int; |
246 | /* We just grabbed the display name of a key */ | 252 | /* We just grabbed the display name of a key */ |
247 | *tmp_val = current_keyrep->addKey(ch_simplified, last_key_type); | 253 | *tmp_val = current_keyrep->addKey(ch_simplified, last_key_type); |
248 | keyIndexList.insert(key, tmp_val); | 254 | keyIndexList.insert(key, tmp_val); |
249 | return TRUE; | 255 | return TRUE; |
250 | } | 256 | } |
251 | if (state == StateField) { | 257 | if (state == StateField) { |
252 | /* Ok, need to add data here */ | 258 | /* Ok, need to add data here */ |
253 | current_data->setField(keyIndex, ch_simplified); | 259 | current_data->setField(keyIndex, ch_simplified); |
254 | return TRUE; | 260 | return TRUE; |
255 | } | 261 | } |
256 | 262 | ||
257 | qWarning("Junk characters found... ignored"); | 263 | owarn << "Junk characters found... ignored" << oendl; |
258 | return TRUE; | 264 | return TRUE; |
259 | } | 265 | } |
260 | 266 | ||
261 | QString DBXmlHandler::errorString() | 267 | QString DBXmlHandler::errorString() |
262 | { | 268 | { |
263 | return "the document is not in the expected file format"; | 269 | return "the document is not in the expected file format"; |
264 | } | 270 | } |
265 | 271 | ||
266 | bool DBXmlHandler::warning(const QXmlParseException& exception) | 272 | bool DBXmlHandler::warning(const QXmlParseException& exception) |
267 | { | 273 | { |
268 | errorProt += QString("warning parsing error: %1 in line %2, column %3\n" ) | 274 | errorProt += QString("warning parsing error: %1 in line %2, column %3\n" ) |
269 | .arg(exception.message()) | 275 | .arg(exception.message()) |
270 | .arg(exception.lineNumber()) | 276 | .arg(exception.lineNumber()) |
271 | .arg(exception.columnNumber()); | 277 | .arg(exception.columnNumber()); |
272 | 278 | ||
273 | qWarning(errorProt); | 279 | owarn << errorProt << oendl; |
274 | return QXmlDefaultHandler::fatalError(exception); | 280 | return QXmlDefaultHandler::fatalError(exception); |
275 | } | 281 | } |
276 | 282 | ||
277 | bool DBXmlHandler::error(const QXmlParseException& exception) | 283 | bool DBXmlHandler::error(const QXmlParseException& exception) |
278 | { | 284 | { |
279 | errorProt += QString("error parsing error: %1 in line %2, column %3\n" ) | 285 | errorProt += QString("error parsing error: %1 in line %2, column %3\n" ) |
280 | .arg(exception.message()) | 286 | .arg(exception.message()) |
281 | .arg(exception.lineNumber()) | 287 | .arg(exception.lineNumber()) |
282 | .arg(exception.columnNumber()); | 288 | .arg(exception.columnNumber()); |
283 | 289 | ||
284 | qWarning(errorProt); | 290 | owarn << errorProt << oendl; |
285 | return QXmlDefaultHandler::fatalError(exception); | 291 | return QXmlDefaultHandler::fatalError(exception); |
286 | } | 292 | } |
287 | 293 | ||
288 | bool DBXmlHandler::fatalError(const QXmlParseException& exception) | 294 | bool DBXmlHandler::fatalError(const QXmlParseException& exception) |
289 | { | 295 | { |
290 | errorProt += QString("fatal parsing error: %1 in line %2, column %3\n" ) | 296 | errorProt += QString("fatal parsing error: %1 in line %2, column %3\n" ) |
291 | .arg(exception.message()) | 297 | .arg(exception.message()) |
292 | .arg(exception.lineNumber()) | 298 | .arg(exception.lineNumber()) |
293 | .arg(exception.columnNumber()); | 299 | .arg(exception.columnNumber()); |
294 | 300 | ||
295 | qWarning(errorProt); | 301 | owarn << errorProt << oendl; |
296 | return QXmlDefaultHandler::fatalError(exception); | 302 | return QXmlDefaultHandler::fatalError(exception); |
297 | } | 303 | } |