summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer
Unidiff
Diffstat (limited to 'noncore/apps/tableviewer') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/db/common.cpp28
-rw-r--r--noncore/apps/tableviewer/db/datacache.cpp12
-rw-r--r--noncore/apps/tableviewer/db/xmlsource.cpp30
-rw-r--r--noncore/apps/tableviewer/tableviewer.cpp14
-rw-r--r--noncore/apps/tableviewer/tableviewer.pro8
-rw-r--r--noncore/apps/tableviewer/ui/tvlistview.cpp9
6 files changed, 66 insertions, 35 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,124 +1,132 @@
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>
26using 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
30static const int del_flag = 0x1; 38static const int del_flag = 0x1;
31static const int new_flag = 0x2; 39static const int new_flag = 0x2;
32 40
33/* Helper function */ 41/* Helper function */
34 42
35int parseNextNumber(QString *q) { 43int 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 }
53 } 61 }
54 /* now truncate q */ 62 /* now truncate q */
55 if (found_digits) 63 if (found_digits)
56 q->remove(0, i); 64 q->remove(0, i);
57 return result; 65 return result;
58} 66}
59 67
60/*! 68/*!
61 \class QStringVector 69 \class QStringVector
62 \brief A Vector of QStrings that can be sorted and searched 70 \brief A Vector of QStrings that can be sorted and searched
63 71
64 Implmented in order to allow reverse lookup on the string name 72 Implmented in order to allow reverse lookup on the string name
65 73
66*/ 74*/
67 75
68/*! 76/*!
69 This function implements the compare function in order to allow the 77 This function implements the compare function in order to allow the
70 searching and sorting of the QStringVector to occur 78 searching and sorting of the QStringVector to occur
71 79
72 \returns an int which is either 80 \returns an int which is either
73 <UL> 81 <UL>
74 <LI> < 0 if the first string is smaller than the second,</LI> 82 <LI> < 0 if the first string is smaller than the second,</LI>
75 <LI> > 0 if the first string is bigger then the second,</LI> 83 <LI> > 0 if the first string is bigger then the second,</LI>
76 <LI> == 0 if the first string is equal to the second.</LI> 84 <LI> == 0 if the first string is equal to the second.</LI>
77 </UL> 85 </UL>
78*/ 86*/
79int QStringVector::compareItems(Item a, Item b) 87int QStringVector::compareItems(Item a, Item b)
80{ 88{
81 QString *qa = (QString *)a; 89 QString *qa = (QString *)a;
82 QString *qb = (QString *)b; 90 QString *qb = (QString *)b;
83 91
84 return QString::compare(*qa, *qb); 92 return QString::compare(*qa, *qb);
85} 93}
86 94
87/*! 95/*!
88 \class TVVariant 96 \class TVVariant
89 A way of abstracting void * and keeping information on 97 A way of abstracting void * and keeping information on
90 the keytypes and behaviours in one place 98 the keytypes and behaviours in one place
91*/ 99*/
92 100
93TVVariantPrivate::TVVariantPrivate() 101TVVariantPrivate::TVVariantPrivate()
94{ 102{
95 typ = TVVariant::Invalid; 103 typ = TVVariant::Invalid;
96} 104}
97 105
98TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d) 106TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d)
99{ 107{
100 switch(d->typ) 108 switch(d->typ)
101 { 109 {
102 case TVVariant::Invalid: 110 case TVVariant::Invalid:
103 break; 111 break;
104 case TVVariant::String: 112 case TVVariant::String:
105 value.ptr = new QString(*((QString *)d->value.ptr)); 113 value.ptr = new QString(*((QString *)d->value.ptr));
106 break; 114 break;
107 case TVVariant::Date: 115 case TVVariant::Date:
108 value.ptr = new QDate(*((QDate *)d->value.ptr)); 116 value.ptr = new QDate(*((QDate *)d->value.ptr));
109 break; 117 break;
110 case TVVariant::Time: 118 case TVVariant::Time:
111 value.ptr = new QTime(*((QTime *)d->value.ptr)); 119 value.ptr = new QTime(*((QTime *)d->value.ptr));
112 break; 120 break;
113 case TVVariant::Int: 121 case TVVariant::Int:
114 value.i = d->value.i; 122 value.i = d->value.i;
115 break; 123 break;
116 default: 124 default:
117 ASSERT( 0 ); 125 ASSERT( 0 );
118 } 126 }
119 127
120 typ = d->typ; 128 typ = d->typ;
121} 129}
122 130
123TVVariantPrivate::~TVVariantPrivate() 131TVVariantPrivate::~TVVariantPrivate()
124{ 132{
@@ -219,193 +227,193 @@ void TVVariant::detach()
219{ 227{
220 if (d->count == 1) 228 if (d->count == 1)
221 return; 229 return;
222 230
223 d->deref(); 231 d->deref();
224 d = new TVVariantPrivate(d); 232 d = new TVVariantPrivate(d);
225} 233}
226 234
227const QString TVVariant::typeName() const 235const QString TVVariant::typeName() const
228{ 236{
229 return typeToName(d->typ); 237 return typeToName(d->typ);
230} 238}
231 239
232void TVVariant::clear() 240void TVVariant::clear()
233{ 241{
234 if (d->count > 1) 242 if (d->count > 1)
235 { 243 {
236 d->deref(); 244 d->deref();
237 d = new TVVariantPrivate; 245 d = new TVVariantPrivate;
238 return; 246 return;
239 } 247 }
240 248
241 d->clear(); 249 d->clear();
242} 250}
243 251
244const QString TVVariant::typeToName(KeyType typ) 252const QString TVVariant::typeToName(KeyType typ)
245{ 253{
246 switch(typ) { 254 switch(typ) {
247 case String: 255 case String:
248 return QString("String"); 256 return QString("String");
249 case Date: 257 case Date:
250 return QString("Date"); 258 return QString("Date");
251 case Time: 259 case Time:
252 return QString("Time"); 260 return QString("Time");
253 case Int: 261 case Int:
254 return QString("Int"); 262 return QString("Int");
255 case Invalid: 263 case Invalid:
256 default: 264 default:
257 return QString("Invalid"); 265 return QString("Invalid");
258 } 266 }
259 return QString("Invalid"); 267 return QString("Invalid");
260} 268}
261 269
262TVVariant::KeyType TVVariant::nameToType(const QString &name) 270TVVariant::KeyType TVVariant::nameToType(const QString &name)
263{ 271{
264 if(!qstrcmp("String", name)) 272 if(!qstrcmp("String", name))
265 return String; 273 return String;
266 if(!qstrcmp("Date", name)) 274 if(!qstrcmp("Date", name))
267 return Date; 275 return Date;
268 if(!qstrcmp("Time", name)) 276 if(!qstrcmp("Time", name))
269 return Time; 277 return Time;
270 if(!qstrcmp("Int", name)) 278 if(!qstrcmp("Int", name))
271 return Int; 279 return Int;
272 280
273 return Invalid; 281 return Invalid;
274} 282}
275 283
276void TVVariant::load(QDataStream &s ) 284void TVVariant::load(QDataStream &s )
277{ 285{
278 KeyType t; 286 KeyType t;
279 s >> t; 287 s >> t;
280 288
281 d->typ = t; 289 d->typ = t;
282 switch(t) { 290 switch(t) {
283 case Invalid: 291 case Invalid:
284 d->typ = t; 292 d->typ = t;
285 break; 293 break;
286 case String: 294 case String:
287 { 295 {
288 QString *x = new QString; 296 QString *x = new QString;
289 s >> *x; 297 s >> *x;
290 d->value.ptr = x; 298 d->value.ptr = x;
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
319void TVVariant::save( QDataStream &s ) const 327void 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}
340 348
341QDataStream& operator>>(QDataStream& s, TVVariant& p) 349QDataStream& operator>>(QDataStream& s, TVVariant& p)
342{ 350{
343 p.load( s ); 351 p.load( s );
344 return s; 352 return s;
345} 353}
346 354
347QDataStream& operator<<(QDataStream &s, const TVVariant& p) 355QDataStream& operator<<(QDataStream &s, const TVVariant& p)
348{ 356{
349 p.save( s ); 357 p.save( s );
350 return s; 358 return s;
351} 359}
352 360
353QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p) 361QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p)
354{ 362{
355 Q_UINT8 u = 0; 363 Q_UINT8 u = 0;
356 s >> u; 364 s >> u;
357 p = (TVVariant::KeyType) u; 365 p = (TVVariant::KeyType) u;
358 366
359 return s; 367 return s;
360} 368}
361 369
362QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p) 370QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p)
363{ 371{
364 s << (Q_UINT8)p; 372 s << (Q_UINT8)p;
365 return s; 373 return s;
366} 374}
367 375
368const QString TVVariant::toString() const 376const QString TVVariant::toString() const
369{ 377{
370 switch(d->typ) { 378 switch(d->typ) {
371 case String: 379 case String:
372 return *((QString*)d->value.ptr); 380 return *((QString*)d->value.ptr);
373 case Date: 381 case Date:
374 return ((QDate*)d->value.ptr)->toString(); 382 return ((QDate*)d->value.ptr)->toString();
375 case Time: 383 case Time:
376 return ((QTime*)d->value.ptr)->toString(); 384 return ((QTime*)d->value.ptr)->toString();
377 case Int: 385 case Int:
378 return QString::number(d->value.i); 386 return QString::number(d->value.i);
379 case Invalid: 387 case Invalid:
380 default: 388 default:
381 return QString::null; 389 return QString::null;
382 } 390 }
383 return QString::null; 391 return QString::null;
384} 392}
385 393
386// TODO DO, this properly, */ 394// TODO DO, this properly, */
387int TVVariant::toInt() const 395int TVVariant::toInt() const
388{ 396{
389 if(d->typ == Int) 397 if(d->typ == Int)
390 return d->value.i; 398 return d->value.i;
391 399
392 if(d->typ == String) { 400 if(d->typ == String) {
393 QString tmpq(*(QString *)d->value.ptr); 401 QString tmpq(*(QString *)d->value.ptr);
394 return parseNextNumber(&tmpq); 402 return parseNextNumber(&tmpq);
395 } 403 }
396 404
397 return 0; 405 return 0;
398} 406}
399 407
400const QDate TVVariant::toDate() const 408const QDate TVVariant::toDate() const
401{ 409{
402 if(d->typ == Date) 410 if(d->typ == Date)
403 return *((QDate *)d->value.ptr); 411 return *((QDate *)d->value.ptr);
404 412
405 if(d->typ == String) { 413 if(d->typ == String) {
406 QString q = toString(); 414 QString q = toString();
407 415
408 /* date format is day mon d yyyy */ 416 /* date format is day mon d yyyy */
409 /* ignore the first three letters, read the next 417 /* ignore the first three letters, read the next
410 three for month.. etc */ 418 three for month.. etc */
411 419
@@ -985,193 +993,193 @@ bool KeyList::validIndex(int i) const
985 return FALSE; 993 return FALSE;
986 return TRUE; 994 return TRUE;
987} 995}
988 996
989QDataStream &operator<<( QDataStream &s, const KeyList &k) 997QDataStream &operator<<( QDataStream &s, const KeyList &k)
990{ 998{
991 s << k.getNumFields(); 999 s << k.getNumFields();
992 1000
993 KeyListIterator it(k); 1001 KeyListIterator it(k);
994 1002
995 while(it.current()) { 1003 while(it.current()) {
996 s << (Q_UINT16)it.currentKey(); 1004 s << (Q_UINT16)it.currentKey();
997 s << it.current()->name(); 1005 s << it.current()->name();
998 s << it.current()->example(); 1006 s << it.current()->example();
999 s << (Q_UINT16)it.current()->flags(); 1007 s << (Q_UINT16)it.current()->flags();
1000 ++it; 1008 ++it;
1001 } 1009 }
1002 return s; 1010 return s;
1003} 1011}
1004 1012
1005QDataStream &operator>>( QDataStream &s, KeyList &k) 1013QDataStream &operator>>( QDataStream &s, KeyList &k)
1006{ 1014{
1007 int i; 1015 int i;
1008 int size; 1016 int size;
1009 int index = 0; 1017 int index = 0;
1010 int flags = 0; 1018 int flags = 0;
1011 TVVariant type = TVVariant(); 1019 TVVariant type = TVVariant();
1012 QString name; 1020 QString name;
1013 1021
1014 s >> size; 1022 s >> size;
1015 1023
1016 for (i=0; i < size; i++) { 1024 for (i=0; i < size; i++) {
1017 s >> (Q_UINT16 &)index; 1025 s >> (Q_UINT16 &)index;
1018 s >> name; 1026 s >> name;
1019 s >> type; 1027 s >> type;
1020 s >> (Q_UINT16 &)flags; 1028 s >> (Q_UINT16 &)flags;
1021 k.replace(index, new Key(name, type, flags)); 1029 k.replace(index, new Key(name, type, flags));
1022 } 1030 }
1023 return s; 1031 return s;
1024} 1032}
1025 1033
1026/*! 1034/*!
1027 \class DataElem 1035 \class DataElem
1028 \brief A class representing a single row or element of a table in a DBStore 1036 \brief A class representing a single row or element of a table in a DBStore
1029 1037
1030 This class holds the data of a row in a table. 1038 This class holds the data of a row in a table.
1031*/ 1039*/
1032 1040
1033 1041
1034/*! 1042/*!
1035 Constructs a DataElem. This function needs a container because the 1043 Constructs a DataElem. This function needs a container because the
1036 size, types of keys and primary key are all defined by the containing 1044 size, types of keys and primary key are all defined by the containing
1037 database 1045 database
1038*/ 1046*/
1039DataElem::DataElem(DBStore *c) : values(20) 1047DataElem::DataElem(DBStore *c) : values(20)
1040{ 1048{
1041 int size; 1049 int size;
1042 contained = c; 1050 contained = c;
1043 size = c->getNumFields(); 1051 size = c->getNumFields();
1044 values.setAutoDelete(TRUE); 1052 values.setAutoDelete(TRUE);
1045} 1053}
1046 1054
1047/*! 1055/*!
1048 Destroys a DataElem and frees memory used by the DataElem 1056 Destroys a DataElem and frees memory used by the DataElem
1049*/ 1057*/
1050DataElem::~DataElem() { 1058DataElem::~DataElem() {
1051} 1059}
1052 1060
1053 1061
1054 1062
1055QDataStream &operator<<( QDataStream &s, const DataElem &d) 1063QDataStream &operator<<( QDataStream &s, const DataElem &d)
1056{ 1064{
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
1072QDataStream &operator>>( QDataStream &s, DataElem &d) 1080QDataStream &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 */
1094int DataElem::getNumFields() const 1102int DataElem::getNumFields() const
1095{ 1103{
1096 return contained->getNumFields(); 1104 return contained->getNumFields();
1097} 1105}
1098 1106
1099KeyList DataElem::getKeys() const 1107KeyList 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
1106 set yet. 1114 set yet.
1107 1115
1108 \return A boolean value that is TRUE if the specfied field of this 1116 \return A boolean value that is TRUE if the specfied field of this
1109 element has been set and FALSE if the field has not yet been set 1117 element has been set and FALSE if the field has not yet been set
1110*/ 1118*/
1111bool DataElem::hasValidValue(int i) const 1119bool DataElem::hasValidValue(int i) const
1112{ 1120{
1113 if(!values.find(i)) 1121 if(!values.find(i))
1114 return FALSE; 1122 return FALSE;
1115 if(!contained->getKeys()->validIndex(i)) 1123 if(!contained->getKeys()->validIndex(i))
1116 return FALSE; 1124 return FALSE;
1117 return values.find(i)->isValid(); 1125 return values.find(i)->isValid();
1118} 1126}
1119 1127
1120/*! 1128/*!
1121 This function determines whether field name qs of the element has been 1129 This function determines whether field name qs of the element has been
1122 set yet. 1130 set yet.
1123 1131
1124 \return A boolean value that is TRUE if the specfied field of this 1132 \return A boolean value that is TRUE if the specfied field of this
1125 element has been set and FALSE if the field has not yet been set 1133 element has been set and FALSE if the field has not yet been set
1126*/ 1134*/
1127bool DataElem::hasValidValue(QString qs) const 1135bool DataElem::hasValidValue(QString qs) const
1128{ 1136{
1129 int i = contained->getKeyIndex(qs); 1137 int i = contained->getKeyIndex(qs);
1130 return hasValidValue(i); 1138 return hasValidValue(i);
1131} 1139}
1132 1140
1133/*! returns the type of the field specified by index i */ 1141/*! returns the type of the field specified by index i */
1134TVVariant::KeyType DataElem::getFieldType(int i) const 1142TVVariant::KeyType DataElem::getFieldType(int i) const
1135{ 1143{
1136 return contained->getKeyType(i); 1144 return contained->getKeyType(i);
1137} 1145}
1138 1146
1139/*! returns the type of the field specified by name qs */ 1147/*! returns the type of the field specified by name qs */
1140TVVariant::KeyType DataElem::getFieldType(QString qs) const 1148TVVariant::KeyType DataElem::getFieldType(QString qs) const
1141{ 1149{
1142 int i = contained->getKeyIndex(qs); 1150 int i = contained->getKeyIndex(qs);
1143 return contained->getKeyType(i); 1151 return contained->getKeyType(i);
1144} 1152}
1145 1153
1146/*! 1154/*!
1147 returns a pointer to the data stored in field index i for this 1155 returns a pointer to the data stored in field index i for this
1148 data element, (value may not be valid) 1156 data element, (value may not be valid)
1149*/ 1157*/
1150TVVariant DataElem::getField(int i) const 1158TVVariant DataElem::getField(int i) const
1151{ 1159{
1152 if(hasValidValue(i)) 1160 if(hasValidValue(i))
1153 return TVVariant(*values.find(i)); 1161 return TVVariant(*values.find(i));
1154 return TVVariant(); 1162 return TVVariant();
1155} 1163}
1156 1164
1157/*! 1165/*!
1158 returns a pointer to the data stored in field name qs for this 1166 returns a pointer to the data stored in field name qs for this
1159 data element, (value may not be valid) 1167 data element, (value may not be valid)
1160*/ 1168*/
1161TVVariant DataElem::getField(QString qs) const 1169TVVariant DataElem::getField(QString qs) const
1162{ 1170{
1163 int i = contained->getKeyIndex(qs); 1171 int i = contained->getKeyIndex(qs);
1164 return getField(i); 1172 return getField(i);
1165} 1173}
1166 1174
1167/*! 1175/*!
1168 Sets the value of the elements field index i to the value represented in 1176 Sets the value of the elements field index i to the value represented in
1169 the QString q. 1177 the QString q.
1170 1178
1171 \param i index of the field to set 1179 \param i index of the field to set
1172 \param q a string that can be parsed to get the value to be set 1180 \param q a string that can be parsed to get the value to be set
1173*/ 1181*/
1174void DataElem::setField(int i, QString q) 1182void DataElem::setField(int i, QString q)
1175{ 1183{
1176 /* from the type of the field, parse q and store */ 1184 /* from the type of the field, parse q and store */
1177 TVVariant::KeyType kt = contained->getKeyType(i); 1185 TVVariant::KeyType kt = contained->getKeyType(i);
@@ -1284,187 +1292,187 @@ QString DataElem::toQString() const
1284/*! formats individual fields to strings so can be displayed */ 1292/*! formats individual fields to strings so can be displayed */
1285QString DataElem::toQString(int i) const 1293QString DataElem::toQString(int i) const
1286{ 1294{
1287 if(hasValidValue(i)) { 1295 if(hasValidValue(i)) {
1288 return getField(i).toString(); 1296 return getField(i).toString();
1289 } 1297 }
1290 return ""; 1298 return "";
1291} 1299}
1292/*! formats individual fields to strings so can be sorted by QListView */ 1300/*! formats individual fields to strings so can be sorted by QListView */
1293QString DataElem::toSortableQString(int i) const 1301QString DataElem::toSortableQString(int i) const
1294{ 1302{
1295 QString scratch = ""; 1303 QString scratch = "";
1296 if(hasValidValue(i)) { 1304 if(hasValidValue(i)) {
1297 switch (contained->getKeyType(i)) { 1305 switch (contained->getKeyType(i)) {
1298 case TVVariant::String: { 1306 case TVVariant::String: {
1299 scratch += getField(i).toString(); 1307 scratch += getField(i).toString();
1300 break; 1308 break;
1301 } 1309 }
1302 case TVVariant::Int: { 1310 case TVVariant::Int: {
1303 scratch.sprintf("%08d", getField(i).toInt()); 1311 scratch.sprintf("%08d", getField(i).toInt());
1304 break; 1312 break;
1305 } 1313 }
1306 case TVVariant::Date: { 1314 case TVVariant::Date: {
1307 static QDate epochD(1800, 1, 1); 1315 static QDate epochD(1800, 1, 1);
1308 scratch.sprintf("%08d", 1316 scratch.sprintf("%08d",
1309 epochD.daysTo(getField(i).toDate())); 1317 epochD.daysTo(getField(i).toDate()));
1310 break; 1318 break;
1311 } 1319 }
1312 case TVVariant::Time: { 1320 case TVVariant::Time: {
1313 static QTime epochT(0, 0, 0); 1321 static QTime epochT(0, 0, 0);
1314 scratch.sprintf("%08d", 1322 scratch.sprintf("%08d",
1315 epochT.msecsTo(getField(i).toTime())); 1323 epochT.msecsTo(getField(i).toTime()));
1316 break; 1324 break;
1317 } 1325 }
1318 default: 1326 default:
1319 scratch += "Unknown type"; 1327 scratch += "Unknown type";
1320 break; 1328 break;
1321 } 1329 }
1322 } 1330 }
1323 return scratch; 1331 return scratch;
1324} 1332}
1325 1333
1326/* compare functions */ 1334/* compare functions */
1327 1335
1328bool DataElem::lessThan(int i, TVVariant v) const 1336bool DataElem::lessThan(int i, TVVariant v) const
1329{ 1337{
1330 if (!hasValidValue(i)) return FALSE; 1338 if (!hasValidValue(i)) return FALSE;
1331 1339
1332 if (getField(i).type() != v.type()) 1340 if (getField(i).type() != v.type())
1333 return FALSE; 1341 return FALSE;
1334 1342
1335 return (getField(i) < v); 1343 return (getField(i) < v);
1336} 1344}
1337 1345
1338bool DataElem::moreThan(int i, TVVariant v) const 1346bool DataElem::moreThan(int i, TVVariant v) const
1339{ 1347{
1340 if (!hasValidValue(i)) return FALSE; 1348 if (!hasValidValue(i)) return FALSE;
1341 1349
1342 if (getField(i).type() != v.type()) 1350 if (getField(i).type() != v.type())
1343 return FALSE; 1351 return FALSE;
1344 1352
1345 return (getField(i) > v); 1353 return (getField(i) > v);
1346} 1354}
1347 1355
1348bool DataElem::equalTo(int i, TVVariant v) const 1356bool DataElem::equalTo(int i, TVVariant v) const
1349{ 1357{
1350 if (!hasValidValue(i)) return FALSE; 1358 if (!hasValidValue(i)) return FALSE;
1351 1359
1352 if (getField(i).type() != v.type()) 1360 if (getField(i).type() != v.type())
1353 return FALSE; 1361 return FALSE;
1354 1362
1355 return (getField(i) == v); 1363 return (getField(i) == v);
1356} 1364}
1357 1365
1358bool DataElem::contains(int i, TVVariant v) const 1366bool 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
1385bool DataElem::startsWith(int i, TVVariant v) const 1393bool 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
1411bool DataElem::endsWith(int i, TVVariant v) const 1419bool 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*/
1449bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) 1457bool 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
@@ -1,249 +1,257 @@
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/* 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>
32using 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*/
45DBStore::DBStore() 53DBStore::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;
56} 64}
57 65
58//TODO 66//TODO
59/*! 67/*!
60 Reinitializes the table to empty (include a resize of the master table, 68 Reinitializes the table to empty (include a resize of the master table,
61 which should free some memory) 69 which should free some memory)
62*/ 70*/
63void DBStore::freeTable() 71void DBStore::freeTable()
64{ 72{
65 name = ""; 73 name = "";
66 if(archive) { 74 if(archive) {
67 delete archive; 75 delete archive;
68 archive = 0; 76 archive = 0;
69 } 77 }
70 kRep->clear(); /* clear the current key list */ 78 kRep->clear(); /* clear the current key list */
71 79
72 number_elems = 0; 80 number_elems = 0;
73 table_size = INIT_TABLE_SIZE; 81 table_size = INIT_TABLE_SIZE;
74 master_table.resize(table_size); 82 master_table.resize(table_size);
75 full = false; 83 full = false;
76 current_elem = 0; 84 current_elem = 0;
77} 85}
78 86
79/*! 87/*!
80 Removes all items from the DBStore and destroys the DBStore 88 Removes all items from the DBStore and destroys the DBStore
81*/ 89*/
82DBStore::~DBStore() 90DBStore::~DBStore()
83{ 91{
84 freeTable(); 92 freeTable();
85} 93}
86 94
87/*! 95/*!
88 This function opens the given xml file, loads it and sets up the 96 This function opens the given xml file, loads it and sets up the
89 appropriate data structures. 97 appropriate data structures.
90 98
91 \param file_name A string representing the name of the file to be opened 99 \param file_name A string representing the name of the file to be opened
92 \return true if successful, false otherwise. 100 \return true if successful, false otherwise.
93*/ 101*/
94bool DBStore::openSource(QIODevice *inDev, const QString &source) { 102bool DBStore::openSource(QIODevice *inDev, const QString &source) {
95 103
96 /* first check if db is already open, if contains data.. then clear */ 104 /* first check if db is already open, if contains data.. then clear */
97 if(number_elems > 0) { 105 if(number_elems > 0) {
98 freeTable(); 106 freeTable();
99 } 107 }
100 108
101 if (source == "text/x-xml-tableviewer") { 109 if (source == "text/x-xml-tableviewer") {
102 archive = new DBXml(this); 110 archive = new DBXml(this);
103 } else if (source == "text/csv") { 111 } else if (source == "text/csv") {
104 archive = new DBCsv(this); 112 archive = new DBCsv(this);
105 } else 113 } else
106 return false; 114 return false;
107 115
108 return (archive->openSource(inDev)); 116 return (archive->openSource(inDev));
109} 117}
110 118
111bool DBStore::saveSource(QIODevice *outDev, const QString &source) 119bool DBStore::saveSource(QIODevice *outDev, const QString &source)
112{ 120{
113 /* saving a new file */ 121 /* saving a new file */
114 if(!archive) { 122 if(!archive) {
115 if (source == "text/x-xml-tableviewer") { 123 if (source == "text/x-xml-tableviewer") {
116 archive = new DBXml(this); 124 archive = new DBXml(this);
117 } else if (source == "text/x-xml-tableviewer") { 125 } else if (source == "text/x-xml-tableviewer") {
118 archive = new DBCsv(this); 126 archive = new DBCsv(this);
119 } else 127 } else
120 return false; 128 return false;
121 } 129 }
122 130
123 /* changing file type */ 131 /* changing file type */
124 if(archive->type() != source) { 132 if(archive->type() != source) {
125 delete archive; 133 delete archive;
126 if (source == "text/x-xml-tableviewer") { 134 if (source == "text/x-xml-tableviewer") {
127 archive = new DBXml(this); 135 archive = new DBXml(this);
128 } else if (source == "text/x-xml-tableviewer") { 136 } else if (source == "text/x-xml-tableviewer") {
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*/
144void DBStore::addItem(DataElem *delem) 152void DBStore::addItem(DataElem *delem)
145{ 153{
146 addItemInternal(delem); 154 addItemInternal(delem);
147} 155}
148 156
149void DBStore::addItemInternal(DataElem *delem) 157void 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
177void DBStore::removeItem(DataElem *r) 185void DBStore::removeItem(DataElem *r)
178{ 186{
179 int position = master_table.findRef(r); 187 int position = master_table.findRef(r);
180 if(position != -1) { 188 if(position != -1) {
181 /* there is at least one item, this is it */ 189 /* there is at least one item, this is it */
182 /* replace this with the last element, decrease the element count */ 190 /* replace this with the last element, decrease the element count */
183 master_table.insert(position, master_table.at(--number_elems)); 191 master_table.insert(position, master_table.at(--number_elems));
184 master_table.remove(number_elems); 192 master_table.remove(number_elems);
185 delete r; 193 delete r;
186 } 194 }
187} 195}
188 196
189/*! 197/*!
190 Sets the name of the database 198 Sets the name of the database
191 199
192 \param n A string representing the new name of the database. 200 \param n A string representing the new name of the database.
193*/ 201*/
194void DBStore::setName(const QString &n) 202void DBStore::setName(const QString &n)
195{ 203{
196 name = n; 204 name = n;
197} 205}
198 206
199/*! 207/*!
200 Gets the name of the database 208 Gets the name of the database
201 209
202 \return A string representing the name of the database. 210 \return A string representing the name of the database.
203*/ 211*/
204QString DBStore::getName() 212QString DBStore::getName()
205{ 213{
206 return name; 214 return name;
207} 215}
208 216
209/*! 217/*!
210 Retrieves a pointer to the key representation of the database for 218 Retrieves a pointer to the key representation of the database for
211 other classes to use as reference. 219 other classes to use as reference.
212 220
213 \return a pointer to the databases key representaion 221 \return a pointer to the databases key representaion
214*/ 222*/
215KeyList *DBStore::getKeys() 223KeyList *DBStore::getKeys()
216{ 224{
217 return kRep; 225 return kRep;
218} 226}
219 227
220/*! 228/*!
221 sets the database's key representation the passed pointer 229 sets the database's key representation the passed pointer
222 \param a pointer to a key representaton 230 \param a pointer to a key representaton
223*/ 231*/
224void DBStore::setKeys(KeyList *k) 232void DBStore::setKeys(KeyList *k)
225{ 233{
226 kRep = k; 234 kRep = k;
227} 235}
228 236
229/*! 237/*!
230 Sets the current element to the first element of the database 238 Sets the current element to the first element of the database
231*/ 239*/
232void DBStore::first() 240void DBStore::first()
233{ 241{
234 current_elem = 0; 242 current_elem = 0;
235} 243}
236 244
237/*! 245/*!
238 Sets the current element to the last element of the database 246 Sets the current element to the last element of the database
239*/ 247*/
240void DBStore::last() 248void DBStore::last()
241{ 249{
242 current_elem = number_elems - 1; 250 current_elem = number_elems - 1;
243} 251}
244 252
245/*! 253/*!
246 Sets the current element to the next element of the database if 254 Sets the current element to the next element of the database if
247 there exists an element after the current one. 255 there exists an element after the current one.
248*/ 256*/
249bool DBStore::next() 257bool DBStore::next()
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,297 +1,303 @@
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>
25using namespace Opie::Core;
26 26
27/* QT */
28#include <qdict.h>
29#include <qtextstream.h>
30
31/* STD */
32#include <stdlib.h>
27 33
28DBXml::DBXml(DBStore *d) 34DBXml::DBXml(DBStore *d)
29{ 35{
30 dstore = d; 36 dstore = d;
31} 37}
32 38
33QString DBXml::type() 39QString DBXml::type()
34{ 40{
35 return "xml"; 41 return "xml";
36} 42}
37 43
38bool DBXml::openSource(QIODevice *inDev) 44bool 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
51 return ok; 57 return ok;
52} 58}
53 59
54bool DBXml::saveSource(QIODevice *outDev) 60bool DBXml::saveSource(QIODevice *outDev)
55{ 61{
56 int i; 62 int i;
57 DataElem *elem; 63 DataElem *elem;
58 KeyList *k; 64 KeyList *k;
59 65
60 QTextStream outstream(outDev); 66 QTextStream outstream(outDev);
61 67
62 outstream << "<database name=\"" << dstore->getName() << "\">" << endl; 68 outstream << "<database name=\"" << dstore->getName() << "\">" << endl;
63 outstream << "<header>" << endl; 69 outstream << "<header>" << endl;
64 70
65 k = dstore->getKeys(); 71 k = dstore->getKeys();
66 KeyListIterator it(*k); 72 KeyListIterator it(*k);
67 while(it.current()) { 73 while(it.current()) {
68 if (!it.current()->delFlag()) { 74 if (!it.current()->delFlag()) {
69 outstream << "<key name=\"KEYID" << it.currentKey() << "\" "; 75 outstream << "<key name=\"KEYID" << it.currentKey() << "\" ";
70 outstream << "type=\"" 76 outstream << "type=\""
71 << TVVariant::typeToName(it.current()->type()) 77 << TVVariant::typeToName(it.current()->type())
72 << "\">"; 78 << "\">";
73 outstream << encodeAttr(it.current()->name()) << "</key>" << endl; 79 outstream << encodeAttr(it.current()->name()) << "</key>" << endl;
74 } 80 }
75 ++it; 81 ++it;
76 } 82 }
77 83
78 outstream << "</header>" << endl; 84 outstream << "</header>" << endl;
79 85
80 dstore->first(); 86 dstore->first();
81 87
82 do { 88 do {
83 elem = dstore->getCurrentData(); 89 elem = dstore->getCurrentData();
84 if (!elem) 90 if (!elem)
85 break; 91 break;
86 outstream << "<record>" << endl; 92 outstream << "<record>" << endl;
87 it.toFirst(); 93 it.toFirst();
88 while (it.current()) { 94 while (it.current()) {
89 i = it.currentKey(); 95 i = it.currentKey();
90 if (elem->hasValidValue(i)) { 96 if (elem->hasValidValue(i)) {
91 outstream << "<KEYID" << i << ">"; 97 outstream << "<KEYID" << i << ">";
92 if (dstore->getKeyType(i) == TVVariant::Date) { 98 if (dstore->getKeyType(i) == TVVariant::Date) {
93 // dates in files are different from displayed dates 99 // dates in files are different from displayed dates
94 QDate date = elem->getField(i).toDate(); 100 QDate date = elem->getField(i).toDate();
95 outstream << date.day() << "/" 101 outstream << date.day() << "/"
96 << date.month() << "/" 102 << date.month() << "/"
97 << date.year(); 103 << date.year();
98 } else { 104 } else {
99 outstream << encodeAttr(elem->toQString(i)); 105 outstream << encodeAttr(elem->toQString(i));
100 } 106 }
101 outstream << "</KEYID" << i << ">" << endl; 107 outstream << "</KEYID" << i << ">" << endl;
102 } 108 }
103 ++it; 109 ++it;
104 } 110 }
105 outstream << "</record>" << endl; 111 outstream << "</record>" << endl;
106 } while(dstore->next()); 112 } while(dstore->next());
107 113
108 outstream << "</database>" << endl; 114 outstream << "</database>" << endl;
109 return TRUE; 115 return TRUE;
110} 116}
111 117
112DBXml::~DBXml() {} 118DBXml::~DBXml() {}
113 119
114/*! 120/*!
115 \class DBXmlHandler 121 \class DBXmlHandler
116 \brief An Xml parser for flat tables. 122 \brief An Xml parser for flat tables.
117 123
118 An xml parser for parsing the files used by the table viewer application. 124 An xml parser for parsing the files used by the table viewer application.
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*/
128DBXmlHandler::DBXmlHandler(DBStore *ds) 134DBXmlHandler::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*/
137DBXmlHandler::~DBXmlHandler() 143DBXmlHandler::~DBXmlHandler()
138{ 144{
139} 145}
140 146
141QString DBXmlHandler::errorProtocol() 147QString 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
147bool DBXmlHandler::startDocument() 153bool DBXmlHandler::startDocument()
148{ 154{
149 errorProt = ""; 155 errorProt = "";
150 state = StateInit; 156 state = StateInit;
151 return TRUE; 157 return TRUE;
152} 158}
153 159
154bool DBXmlHandler::startElement(const QString&, const QString&, 160bool 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
203bool DBXmlHandler::endElement(const QString&, const QString&, 209bool 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
235bool DBXmlHandler::characters(const QString& ch) 241bool 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
261QString DBXmlHandler::errorString() 267QString 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
266bool DBXmlHandler::warning(const QXmlParseException& exception) 272bool 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
277bool DBXmlHandler::error(const QXmlParseException& exception) 283bool 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
288bool DBXmlHandler::fatalError(const QXmlParseException& exception) 294bool 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}
diff --git a/noncore/apps/tableviewer/tableviewer.cpp b/noncore/apps/tableviewer/tableviewer.cpp
index 102b94c..9538cb3 100644
--- a/noncore/apps/tableviewer/tableviewer.cpp
+++ b/noncore/apps/tableviewer/tableviewer.cpp
@@ -1,387 +1,389 @@
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 20
21/* local includes */
22#include "tableviewer.h" 21#include "tableviewer.h"
23#include "ui/tvbrowseview.h" 22#include "ui/tvbrowseview.h"
24#include "ui/tvfilterview.h" 23#include "ui/tvfilterview.h"
25#include "ui/tvlistview.h" 24#include "ui/tvlistview.h"
26#include "ui/tveditview.h" 25#include "ui/tveditview.h"
27#include "ui/tvkeyedit.h" 26#include "ui/tvkeyedit.h"
28#include "db/datacache.h" 27#include "db/datacache.h"
29 28
30/* QPE includes */ 29/* OPIE */
30#include <opie2/odebug.h>
31#include <qpe/fileselector.h> 31#include <qpe/fileselector.h>
32#include <qpe/resource.h> 32#include <qpe/resource.h>
33#include <qtoolbar.h> 33using namespace Opie::Core;
34 34
35/* QTE includes */ 35/* QT */
36#include <qmenubar.h> 36#include <qmenubar.h>
37#include <qtoolbar.h>
37#include <qpopupmenu.h> 38#include <qpopupmenu.h>
38#include <qapplication.h> 39#include <qapplication.h>
39#include <qwidgetstack.h> 40#include <qwidgetstack.h>
40#include <qlayout.h> 41#include <qlayout.h>
41#include <qbuffer.h> 42#include <qbuffer.h>
43
42/*! 44/*!
43 \class TableViewerWindow 45 \class TableViewerWindow
44 \brief The main window widget of the application 46 \brief The main window widget of the application
45 47
46 This is the main widget of the table viewer application. 48 This is the main widget of the table viewer application.
47 It is the co-ordination point. 49 It is the co-ordination point.
48*/ 50*/
49 51
50/*! 52/*!
51 Constructs a new TableViewerWindow 53 Constructs a new TableViewerWindow
52*/ 54*/
53TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f) 55TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f)
54 : QMainWindow(parent, name, f) 56 : QMainWindow(parent, name, f)
55{ 57{
56 setCaption(tr("Table Viewer")); 58 setCaption(tr("Table Viewer"));
57 59
58/* Build data */ 60/* Build data */
59 ds = new DBStore(); 61 ds = new DBStore();
60 doc.setType("text/x-xml-tableviewer"); 62 doc.setType("text/x-xml-tableviewer");
61 doc.setName("table"); 63 doc.setName("table");
62 64
63 dirty = FALSE; 65 dirty = FALSE;
64 ts.current_column = 0; 66 ts.current_column = 0;
65 ts.kRep = ds->getKeys(); 67 ts.kRep = ds->getKeys();
66 68
67/* build menus */ 69/* build menus */
68 menu = new QMenuBar(this, 0); 70 menu = new QMenuBar(this, 0);
69 71
70 QPopupMenu *file_menu = new QPopupMenu; 72 QPopupMenu *file_menu = new QPopupMenu;
71 file_menu->insertItem("New", this, SLOT(newDocument())); 73 file_menu->insertItem("New", this, SLOT(newDocument()));
72 74
73 file_menu->insertItem("Open", this, SLOT(selectDocument())); 75 file_menu->insertItem("Open", this, SLOT(selectDocument()));
74 file_menu->insertSeparator(); 76 file_menu->insertSeparator();
75 file_menu->insertItem("Properties"); 77 file_menu->insertItem("Properties");
76 78
77 /* later will want to set this up to clean up first via this, SLOT(quit) */ 79 /* later will want to set this up to clean up first via this, SLOT(quit) */
78 menu->insertItem("Document", file_menu); 80 menu->insertItem("Document", file_menu);
79 81
80 QPopupMenu *edit_menu = new QPopupMenu; 82 QPopupMenu *edit_menu = new QPopupMenu;
81 edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot())); 83 edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot()));
82 edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot())); 84 edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot()));
83 edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot())); 85 edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot()));
84 menu->insertItem("Edit", edit_menu); 86 menu->insertItem("Edit", edit_menu);
85 87
86 QPopupMenu *view_menu = new QPopupMenu; 88 QPopupMenu *view_menu = new QPopupMenu;
87 view_menu->insertItem("Browse View", this, SLOT(browseViewSlot())); 89 view_menu->insertItem("Browse View", this, SLOT(browseViewSlot()));
88 view_menu->insertItem("List View", this, SLOT(listViewSlot())); 90 view_menu->insertItem("List View", this, SLOT(listViewSlot()));
89 menu->insertItem("View", view_menu); 91 menu->insertItem("View", view_menu);
90 92
91 QVBoxLayout *main_layout = new QVBoxLayout; 93 QVBoxLayout *main_layout = new QVBoxLayout;
92 94
93 /* Build tool bar */ 95 /* Build tool bar */
94 navigation = new QToolBar(this, "navigation"); 96 navigation = new QToolBar(this, "navigation");
95 QToolButton *newItemButton = new QToolButton( 97 QToolButton *newItemButton = new QToolButton(
96 QIconSet(Resource::loadPixmap("new")), "New Item", QString::null, 98 QIconSet(Resource::loadPixmap("new")), "New Item", QString::null,
97 this, SLOT(newItemSlot()), navigation, "New Item"); 99 this, SLOT(newItemSlot()), navigation, "New Item");
98 QToolButton *editItemButton = new QToolButton( 100 QToolButton *editItemButton = new QToolButton(
99 QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null, 101 QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null,
100 this, SLOT(editItemSlot()), navigation, "Edit Item"); 102 this, SLOT(editItemSlot()), navigation, "Edit Item");
101 QToolButton *deleteItemButton = new QToolButton( 103 QToolButton *deleteItemButton = new QToolButton(
102 QIconSet(Resource::loadPixmap("trash")), "Delete Item", 104 QIconSet(Resource::loadPixmap("trash")), "Delete Item",
103 QString::null, this, 105 QString::null, this,
104 SLOT(deleteItemSlot()), navigation, "Delete Item"); 106 SLOT(deleteItemSlot()), navigation, "Delete Item");
105 107
106 navigation->addSeparator(); 108 navigation->addSeparator();
107 109
108 QToolButton *firstItemButton = new QToolButton( 110 QToolButton *firstItemButton = new QToolButton(
109 QIconSet(Resource::loadPixmap("fastback")), "First Item", 111 QIconSet(Resource::loadPixmap("fastback")), "First Item",
110 QString::null, this, 112 QString::null, this,
111 SLOT(firstItem()), navigation, "First Item"); 113 SLOT(firstItem()), navigation, "First Item");
112 QToolButton *previousItemButton = new QToolButton( 114 QToolButton *previousItemButton = new QToolButton(
113 QIconSet(Resource::loadPixmap("back")), "Previous Item", 115 QIconSet(Resource::loadPixmap("back")), "Previous Item",
114 QString::null, this, 116 QString::null, this,
115 SLOT(previousItem()), navigation, "Previous Item"); 117 SLOT(previousItem()), navigation, "Previous Item");
116 QToolButton *nextItemButton = new QToolButton( 118 QToolButton *nextItemButton = new QToolButton(
117 QIconSet(Resource::loadPixmap("forward")), "Next Item", 119 QIconSet(Resource::loadPixmap("forward")), "Next Item",
118 QString::null, this, 120 QString::null, this,
119 SLOT(nextItem()), navigation, "Next Item"); 121 SLOT(nextItem()), navigation, "Next Item");
120 QToolButton *lastItemButton = new QToolButton( 122 QToolButton *lastItemButton = new QToolButton(
121 QIconSet(Resource::loadPixmap("fastforward")), "Last Item", 123 QIconSet(Resource::loadPixmap("fastforward")), "Last Item",
122 QString::null, this, 124 QString::null, this,
123 SLOT(lastItem()), navigation, "Last Item"); 125 SLOT(lastItem()), navigation, "Last Item");
124 126
125 navigation->addSeparator(); 127 navigation->addSeparator();
126 QToolButton *browseButton = new QToolButton( 128 QToolButton *browseButton = new QToolButton(
127 QIconSet(Resource::loadPixmap("day")), "View Single Item", 129 QIconSet(Resource::loadPixmap("day")), "View Single Item",
128 QString::null, this, 130 QString::null, this,
129 SLOT(browseViewSlot()), navigation, "View Single Item"); 131 SLOT(browseViewSlot()), navigation, "View Single Item");
130 QToolButton *listButton = new QToolButton( 132 QToolButton *listButton = new QToolButton(
131 QIconSet(Resource::loadPixmap("month")), "View Multiple Items", 133 QIconSet(Resource::loadPixmap("month")), "View Multiple Items",
132 QString::null, this, 134 QString::null, this,
133 SLOT(listViewSlot()), navigation, "View Multiple Items"); 135 SLOT(listViewSlot()), navigation, "View Multiple Items");
134 136
135 setToolBarsMovable(FALSE); 137 setToolBarsMovable(FALSE);
136 setToolBarsMovable(FALSE); 138 setToolBarsMovable(FALSE);
137 setToolBarsMovable(FALSE); 139 setToolBarsMovable(FALSE);
138 140
139/* Build widgets */ 141/* Build widgets */
140 browseView = new TVBrowseView(&ts, this, 0); 142 browseView = new TVBrowseView(&ts, this, 0);
141 listView = new TVListView(&ts, this, 0); 143 listView = new TVListView(&ts, this, 0);
142 filterView = new TVFilterView(&ts, this, 0); 144 filterView = new TVFilterView(&ts, this, 0);
143 fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer", 145 fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer",
144 this, "fileselector"); 146 this, "fileselector");
145 fileSelector->setNewVisible(FALSE); 147 fileSelector->setNewVisible(FALSE);
146 fileSelector->setCloseVisible(FALSE); 148 fileSelector->setCloseVisible(FALSE);
147 149
148 cw = new QWidgetStack(this, 0); 150 cw = new QWidgetStack(this, 0);
149 cw->addWidget(listView, ListState); 151 cw->addWidget(listView, ListState);
150 cw->addWidget(browseView, BrowseState); 152 cw->addWidget(browseView, BrowseState);
151 cw->addWidget(filterView, FilterState); 153 cw->addWidget(filterView, FilterState);
152 cw->addWidget(fileSelector, FileState); 154 cw->addWidget(fileSelector, FileState);
153 155
154 current_view = FileState; 156 current_view = FileState;
155 cw->raiseWidget(current_view); 157 cw->raiseWidget(current_view);
156 fileSelector->reread(); 158 fileSelector->reread();
157 159
158 connect(browseView, SIGNAL(searchOnKey(int,TVVariant)), 160 connect(browseView, SIGNAL(searchOnKey(int,TVVariant)),
159 this, SLOT(searchOnKey(int,TVVariant))); 161 this, SLOT(searchOnKey(int,TVVariant)));
160 connect(browseView, SIGNAL(sortChanged(int)), 162 connect(browseView, SIGNAL(sortChanged(int)),
161 this, SLOT(setPrimaryKey(int))); 163 this, SLOT(setPrimaryKey(int)));
162 164
163 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot())); 165 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot()));
164 connect(fileSelector, SIGNAL(fileSelected(const DocLnk&)), 166 connect(fileSelector, SIGNAL(fileSelected(const DocLnk&)),
165 this, SLOT(openDocument(const DocLnk&))); 167 this, SLOT(openDocument(const DocLnk&)));
166 168
167 main_layout->addWidget(menu); 169 main_layout->addWidget(menu);
168 main_layout->addWidget(cw); 170 main_layout->addWidget(cw);
169 171
170 setCentralWidget(cw); 172 setCentralWidget(cw);
171 173
172} 174}
173 175
174/*! 176/*!
175 Destroys the TableViewerWindow 177 Destroys the TableViewerWindow
176*/ 178*/
177TableViewerWindow::~TableViewerWindow() 179TableViewerWindow::~TableViewerWindow()
178{ 180{
179 if(dirty) 181 if(dirty)
180 saveDocument(); 182 saveDocument();
181} 183}
182 184
183/*! 185/*!
184 Opens a file dialog and loads the file specified by the dialog 186 Opens a file dialog and loads the file specified by the dialog
185*/ 187*/
186void TableViewerWindow::selectDocument() 188void TableViewerWindow::selectDocument()
187{ 189{
188 if(dirty) 190 if(dirty)
189 saveDocument(); 191 saveDocument();
190 current_view = FileState; 192 current_view = FileState;
191 cw->raiseWidget(current_view); 193 cw->raiseWidget(current_view);
192 fileSelector->reread(); 194 fileSelector->reread();
193} 195}
194 196
195void TableViewerWindow::saveDocument() 197void TableViewerWindow::saveDocument()
196{ 198{
197 if(!dirty) 199 if(!dirty)
198 return; 200 return;
199 201
200 FileManager fm; 202 FileManager fm;
201 QIODevice *dev = fm.saveFile(doc); 203 QIODevice *dev = fm.saveFile(doc);
202 204
203 if(!ds->saveSource(dev, doc.type())){ 205 if(!ds->saveSource(dev, doc.type())){
204 qWarning("Save unsuccessful"); 206 owarn << "Save unsuccessful" << oendl;
205 return; 207 return;
206 } 208 }
207 dev->close(); 209 dev->close();
208 dirty = FALSE; 210 dirty = FALSE;
209} 211}
210 212
211void TableViewerWindow::newDocument() 213void TableViewerWindow::newDocument()
212{ 214{
213 DocLnk nf; 215 DocLnk nf;
214 nf.setType("text/x-xml-tableviewer"); 216 nf.setType("text/x-xml-tableviewer");
215 nf.setName("table"); 217 nf.setName("table");
216 218
217 delete ds; 219 delete ds;
218 ds = new DBStore(); 220 ds = new DBStore();
219 221
220 ts.current_column = 0; 222 ts.current_column = 0;
221 ts.kRep = ds->getKeys(); 223 ts.kRep = ds->getKeys();
222 browseView->reset(); 224 browseView->reset();
223 listView->reset(); 225 listView->reset();
224 filterView->reset(); 226 filterView->reset();
225 227
226 doc = nf; 228 doc = nf;
227 dirty = FALSE; 229 dirty = FALSE;
228 230
229 current_view = BrowseState; 231 current_view = BrowseState;
230 cw->raiseWidget(current_view); 232 cw->raiseWidget(current_view);
231 233
232 /* now set up for editing the keys */ 234 /* now set up for editing the keys */
233 ts.kRep->addKey("key", TVVariant::String); 235 ts.kRep->addKey("key", TVVariant::String);
234 editKeysSlot(); 236 editKeysSlot();
235} 237}
236 238
237void TableViewerWindow::setDocument(const QString &f) 239void TableViewerWindow::setDocument(const QString &f)
238{ 240{
239 openDocument(DocLnk(f, TRUE)); 241 openDocument(DocLnk(f, TRUE));
240} 242}
241 243
242void TableViewerWindow::openDocument(const DocLnk &f) 244void TableViewerWindow::openDocument(const DocLnk &f)
243{ 245{
244 246
245 if (!f.isValid()) 247 if (!f.isValid())
246 return; 248 return;
247 249
248 FileManager fm; 250 FileManager fm;
249 QIODevice *dev = fm.openFile(f); 251 QIODevice *dev = fm.openFile(f);
250 doc = f; 252 doc = f;
251 253
252 if(ds->openSource(dev, doc.type())) { 254 if(ds->openSource(dev, doc.type())) {
253 DataElem *d; 255 DataElem *d;
254 256
255 browseView->reset(); 257 browseView->reset();
256 listView->reset(); 258 listView->reset();
257 filterView->reset(); 259 filterView->reset();
258 260
259 current_view = BrowseState; 261 current_view = BrowseState;
260 cw->raiseWidget(current_view); 262 cw->raiseWidget(current_view);
261 263
262 /* set up new table state and ensure sub widgets have a reference */ 264 /* set up new table state and ensure sub widgets have a reference */
263 ts.current_column = 0; 265 ts.current_column = 0;
264 ts.kRep = ds->getKeys(); 266 ts.kRep = ds->getKeys();
265 browseView->rebuildKeys(); 267 browseView->rebuildKeys();
266 listView->rebuildKeys(); 268 listView->rebuildKeys();
267 filterView->rebuildKeys(); 269 filterView->rebuildKeys();
268 270
269 ds->first(); 271 ds->first();
270 /* set up the list view */ 272 /* set up the list view */
271 listView->clearItems(); 273 listView->clearItems();
272 do { 274 do {
273 d = ds->getCurrentData(); 275 d = ds->getCurrentData();
274 if(d) 276 if(d)
275 listView->addItem(d); 277 listView->addItem(d);
276 } while(ds->next()); 278 } while(ds->next());
277 279
278 /* Set up browse view, Will be based of structure of listView */ 280 /* Set up browse view, Will be based of structure of listView */
279 listView->first(); 281 listView->first();
280 ts.current_elem = listView->getCurrentData(); 282 ts.current_elem = listView->getCurrentData();
281 browseView->rebuildData(); 283 browseView->rebuildData();
282 listView->rebuildData(); 284 listView->rebuildData();
283 285
284 QString scratch = "Table Viewer";/* later take from constant */ 286 QString scratch = "Table Viewer";/* later take from constant */
285 scratch += " - "; 287 scratch += " - ";
286 scratch += ds->getName(); 288 scratch += ds->getName();
287 setCaption(tr(scratch)); 289 setCaption(tr(scratch));
288 290
289 dirty = FALSE; 291 dirty = FALSE;
290 } else { 292 } else {
291 qWarning(tr("could not load Document")); 293 owarn << tr("could not load Document") << oendl;
292 } 294 }
293 dev->close(); 295 dev->close();
294} 296}
295 297
296/*! 298/*!
297 Moves to the first item of the current table 299 Moves to the first item of the current table
298*/ 300*/
299void TableViewerWindow::firstItem() 301void TableViewerWindow::firstItem()
300{ 302{
301 listView->first(); 303 listView->first();
302 ts.current_elem = listView->getCurrentData(); 304 ts.current_elem = listView->getCurrentData();
303 browseView->rebuildData(); 305 browseView->rebuildData();
304} 306}
305 307
306/*! 308/*!
307 Moves to the lat item of the current table 309 Moves to the lat item of the current table
308*/ 310*/
309void TableViewerWindow::lastItem() 311void TableViewerWindow::lastItem()
310{ 312{
311 listView->last(); 313 listView->last();
312 ts.current_elem = listView->getCurrentData(); 314 ts.current_elem = listView->getCurrentData();
313 browseView->rebuildData(); 315 browseView->rebuildData();
314} 316}
315 317
316/*! 318/*!
317 Moves to the next item of the current table 319 Moves to the next item of the current table
318*/ 320*/
319void TableViewerWindow::nextItem() 321void TableViewerWindow::nextItem()
320{ 322{
321 listView->next(); 323 listView->next();
322 ts.current_elem = listView->getCurrentData(); 324 ts.current_elem = listView->getCurrentData();
323 browseView->rebuildData(); 325 browseView->rebuildData();
324} 326}
325 327
326/*! 328/*!
327 Moves to the previous item of the current table 329 Moves to the previous item of the current table
328*/ 330*/
329void TableViewerWindow::previousItem() 331void TableViewerWindow::previousItem()
330{ 332{
331 listView->previous(); 333 listView->previous();
332 ts.current_elem = listView->getCurrentData(); 334 ts.current_elem = listView->getCurrentData();
333 browseView->rebuildData(); 335 browseView->rebuildData();
334} 336}
335 337
336/*! 338/*!
337 Raises the List View. This is a mode change for the application. 339 Raises the List View. This is a mode change for the application.
338*/ 340*/
339void TableViewerWindow::listViewSlot() 341void TableViewerWindow::listViewSlot()
340{ 342{
341 if(current_view == FilterState) 343 if(current_view == FilterState)
342 applyFilter(); 344 applyFilter();
343 current_view = ListState; 345 current_view = ListState;
344 cw->raiseWidget(current_view); 346 cw->raiseWidget(current_view);
345} 347}
346 348
347void TableViewerWindow::applyFilter() 349void TableViewerWindow::applyFilter()
348{ 350{
349 DataElem *d; 351 DataElem *d;
350 352
351 listView->clearItems(); 353 listView->clearItems();
352 ds->first(); 354 ds->first();
353 do { 355 do {
354 d = ds->getCurrentData(); 356 d = ds->getCurrentData();
355 if(d) 357 if(d)
356 if(filterView->passesFilter(d)) 358 if(filterView->passesFilter(d))
357 listView->addItem(d); 359 listView->addItem(d);
358 } while(ds->next()); 360 } while(ds->next());
359 listView->first(); 361 listView->first();
360 listView->rebuildData(); 362 listView->rebuildData();
361} 363}
362 364
363/*! 365/*!
364 Raises the Browse View. This is a mode change for the application. 366 Raises the Browse View. This is a mode change for the application.
365*/ 367*/
366void TableViewerWindow::browseViewSlot() 368void TableViewerWindow::browseViewSlot()
367{ 369{
368 if(current_view == FilterState) 370 if(current_view == FilterState)
369 applyFilter(); 371 applyFilter();
370 372
371 ts.current_elem = listView->getCurrentData(); 373 ts.current_elem = listView->getCurrentData();
372 browseView->rebuildData(); 374 browseView->rebuildData();
373 375
374 current_view = BrowseState; 376 current_view = BrowseState;
375 cw->raiseWidget(current_view); 377 cw->raiseWidget(current_view);
376} 378}
377 379
378/*! 380/*!
379 Raises the List View. This is a mode change for the application. 381 Raises the List View. This is a mode change for the application.
380*/ 382*/
381void TableViewerWindow::filterViewSlot() 383void TableViewerWindow::filterViewSlot()
382{ 384{
383 current_view = FilterState; 385 current_view = FilterState;
384 cw->raiseWidget(current_view); 386 cw->raiseWidget(current_view);
385} 387}
386 388
387 389
diff --git a/noncore/apps/tableviewer/tableviewer.pro b/noncore/apps/tableviewer/tableviewer.pro
index 1de23bb..564f50f 100644
--- a/noncore/apps/tableviewer/tableviewer.pro
+++ b/noncore/apps/tableviewer/tableviewer.pro
@@ -1,38 +1,38 @@
1 CONFIG = qt warn_on quick-app 1 CONFIG = qt warn_on quick-app
2 SUBDIRS = db ui 2 SUBDIRS = db ui
3 HEADERS = tableviewer.h \ 3 HEADERS = tableviewer.h \
4 xmlencodeattr.h \ 4 xmlencodeattr.h \
5 ui/commonwidgets.h \ 5 ui/commonwidgets.h \
6 ui/tvbrowseview.h \ 6 ui/tvbrowseview.h \
7 ui/tvlistview.h \ 7 ui/tvlistview.h \
8 ui/tvfilterview.h \ 8 ui/tvfilterview.h \
9 ui/tveditview.h \ 9 ui/tveditview.h \
10 ui/browsekeyentry.h \ 10 ui/browsekeyentry.h \
11 ui/filterkeyentry.h \ 11 ui/filterkeyentry.h \
12 ui/tvkeyedit.h \ 12 ui/tvkeyedit.h \
13 db/datacache.h \ 13 db/datacache.h \
14 db/common.h \ 14 db/common.h \
15 db/xmlsource.h \ 15 db/xmlsource.h \
16 db/csvsource.h 16 db/csvsource.h
17 SOURCES = main.cpp \ 17 SOURCES = main.cpp \
18 tableviewer.cpp \ 18 tableviewer.cpp \
19 xmlencodeattr.cpp \ 19 xmlencodeattr.cpp \
20 ui/commonwidgets.cpp \ 20 ui/commonwidgets.cpp \
21 ui/tvbrowseview.cpp \ 21 ui/tvbrowseview.cpp \
22 ui/tvfilterview.cpp \ 22 ui/tvfilterview.cpp \
23 ui/browsekeyentry.cpp \ 23 ui/browsekeyentry.cpp \
24 ui/filterkeyentry.cpp \ 24 ui/filterkeyentry.cpp \
25 ui/tvlistview.cpp \ 25 ui/tvlistview.cpp \
26 ui/tveditview.cpp \ 26 ui/tveditview.cpp \
27 ui/tvkeyedit.cpp \ 27 ui/tvkeyedit.cpp \
28 db/datacache.cpp \ 28 db/datacache.cpp \
29 db/xmlsource.cpp \ 29 db/xmlsource.cpp \
30 db/csvsource.cpp \ 30 db/csvsource.cpp \
31 db/common.cpp 31 db/common.cpp
32 INTERFACES= ui/tvkeyedit_gen.ui 32 INTERFACES= ui/tvkeyedit_gen.ui
33 TARGET = tableviewer 33 TARGET = tableviewer
34INCLUDEPATH += $(OPIEDIR)/include 34 INCLUDEPATH+= $(OPIEDIR)/include
35DEPENDPATH += $(OPIEDIR)/include 35 DEPENDPATH+= $(OPIEDIR)/include
36 LIBS += -lqpe -lopiecore2 36 LIBS += -lqpe -lopiecore2
37 37
38include ( $(OPIEDIR)/include.pro ) 38include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/apps/tableviewer/ui/tvlistview.cpp b/noncore/apps/tableviewer/ui/tvlistview.cpp
index b10ff1d..c3e6432 100644
--- a/noncore/apps/tableviewer/ui/tvlistview.cpp
+++ b/noncore/apps/tableviewer/ui/tvlistview.cpp
@@ -1,262 +1,269 @@
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
20#include "tvlistview.h" 21#include "tvlistview.h"
21#include "../db/common.h" 22#include "../db/common.h"
23
24/* OPIE */
25#include <opie2/odebug.h>
26using namespace Opie::Core;
27
28/* QT */
22#include <qtoolbutton.h> 29#include <qtoolbutton.h>
23#include <qlistview.h> 30#include <qlistview.h>
24#include <qlayout.h> 31#include <qlayout.h>
25 32
26void TVListViewPrivate::setColumnWidth(int column, int width) 33void TVListViewPrivate::setColumnWidth(int column, int width)
27{ 34{
28 if(width > 70) width = 70; 35 if(width > 70) width = 70;
29 QListView::setColumnWidth(column, width); 36 QListView::setColumnWidth(column, width);
30} 37}
31 38
32void TVListViewPrivate::setSorting(int column, bool increasing) 39void TVListViewPrivate::setSorting(int column, bool increasing)
33{ 40{
34 emit sortChanged(column); 41 emit sortChanged(column);
35 QListView::setSorting(column, increasing); 42 QListView::setSorting(column, increasing);
36} 43}
37 44
38TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name, 45TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name,
39 WFlags fl) : QListView(parent, name, fl) { 46 WFlags fl) : QListView(parent, name, fl) {
40 ; 47 ;
41} 48}
42 49
43class TVListViewItem : public QListViewItem 50class TVListViewItem : public QListViewItem
44{ 51{
45public: 52public:
46 53
47 TVListViewItem(QListView *parent, DataElem *d); 54 TVListViewItem(QListView *parent, DataElem *d);
48 ~TVListViewItem(); 55 ~TVListViewItem();
49 56
50 QString text(int i) const 57 QString text(int i) const
51 { 58 {
52 return data_reference->toQString(i); 59 return data_reference->toQString(i);
53 } 60 }
54 61
55 /* Do nothing... all data for this item should be generated */ 62 /* Do nothing... all data for this item should be generated */
56 void setText(int i, const QString &) 63 void setText(int i, const QString &)
57 { 64 {
58 ; 65 ;
59 } 66 }
60 QString key(int i, bool a) const 67 QString key(int i, bool a) const
61 { 68 {
62 return data_reference->toSortableQString(i); 69 return data_reference->toSortableQString(i);
63 } 70 }
64 71
65 void setDataElem(DataElem *d) 72 void setDataElem(DataElem *d)
66 { 73 {
67 data_reference = d; 74 data_reference = d;
68 } 75 }
69 76
70 DataElem *getDataElem() { 77 DataElem *getDataElem() {
71 return data_reference; 78 return data_reference;
72 } 79 }
73private: 80private:
74 DataElem *data_reference; 81 DataElem *data_reference;
75}; 82};
76 83
77TVListViewItem::TVListViewItem(QListView *parent, DataElem *d) 84TVListViewItem::TVListViewItem(QListView *parent, DataElem *d)
78 : QListViewItem(parent) 85 : QListViewItem(parent)
79{ 86{
80 data_reference = d; 87 data_reference = d;
81} 88}
82 89
83TVListViewItem::~TVListViewItem() 90TVListViewItem::~TVListViewItem()
84{ 91{
85 data_reference = 0; 92 data_reference = 0;
86} 93}
87 94
88TVListView::TVListView(TableState *t, QWidget* parent, 95TVListView::TVListView(TableState *t, QWidget* parent,
89 const char *name, WFlags fl ) : QWidget(parent, name, fl) 96 const char *name, WFlags fl ) : QWidget(parent, name, fl)
90{ 97{
91 if (!name) 98 if (!name)
92 setName("TVListView"); 99 setName("TVListView");
93 100
94 // the next two lines need to be rationalized. 101 // the next two lines need to be rationalized.
95 resize(318,457); 102 resize(318,457);
96 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, 103 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
97 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth())); 104 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth()));
98 setCaption(tr("List View")); 105 setCaption(tr("List View"));
99 106
100 QVBoxLayout *layout = new QVBoxLayout(this); 107 QVBoxLayout *layout = new QVBoxLayout(this);
101 layout->setSpacing(0); 108 layout->setSpacing(0);
102 layout->setMargin(0); 109 layout->setMargin(0);
103 110
104 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay"); 111 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay");
105 layout->addWidget(listViewDisplay); 112 layout->addWidget(listViewDisplay);
106 113
107 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem*)), this, 114 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem*)), this,
108 SLOT(setCurrent(QListViewItem*))); 115 SLOT(setCurrent(QListViewItem*)));
109 connect(listViewDisplay, SIGNAL(sortChanged(int)), this, 116 connect(listViewDisplay, SIGNAL(sortChanged(int)), this,
110 SLOT(setSorting(int))); 117 SLOT(setSorting(int)));
111 118
112 listViewDisplay->setShowSortIndicator(true); 119 listViewDisplay->setShowSortIndicator(true);
113 120
114 it = new QListViewItemIterator(listViewDisplay); 121 it = new QListViewItemIterator(listViewDisplay);
115 ts = t; 122 ts = t;
116} 123}
117 124
118TVListView::~TVListView() 125TVListView::~TVListView()
119{ 126{
120} 127}
121 128
122void TVListView::addItem(DataElem *d) 129void TVListView::addItem(DataElem *d)
123{ 130{
124 TVListViewItem *i = new TVListViewItem(listViewDisplay, d); 131 TVListViewItem *i = new TVListViewItem(listViewDisplay, d);
125 132
126 delete it; 133 delete it;
127 it = new QListViewItemIterator(i); 134 it = new QListViewItemIterator(i);
128} 135}
129 136
130/* remove current (it) item */ 137/* remove current (it) item */
131void TVListView::removeItem() 138void TVListView::removeItem()
132{ 139{
133 QListViewItemIterator other(*it); 140 QListViewItemIterator other(*it);
134 141
135 QListViewItemIterator tmp = *it; 142 QListViewItemIterator tmp = *it;
136 (*it)++; 143 (*it)++;
137 if (!it->current()) { 144 if (!it->current()) {
138 *it = tmp; 145 *it = tmp;
139 (*it)--; 146 (*it)--;
140 if (!it->current()) { 147 if (!it->current()) {
141 delete it; 148 delete it;
142 it = 0; 149 it = 0;
143 } 150 }
144 } 151 }
145 152
146 delete other.current(); 153 delete other.current();
147} 154}
148 155
149void TVListView::clearItems() 156void TVListView::clearItems()
150{ 157{
151 /* This is ok since the destructor for TVListItem does not know about 158 /* This is ok since the destructor for TVListItem does not know about
152 the data_reference pointer.. and hence will leave it alone */ 159 the data_reference pointer.. and hence will leave it alone */
153 listViewDisplay->clear(); 160 listViewDisplay->clear();
154 delete it; 161 delete it;
155 it = new QListViewItemIterator(listViewDisplay); 162 it = new QListViewItemIterator(listViewDisplay);
156} 163}
157 164
158void TVListView::first() 165void TVListView::first()
159{ 166{
160 delete it; 167 delete it;
161 it = new QListViewItemIterator(listViewDisplay); 168 it = new QListViewItemIterator(listViewDisplay);
162} 169}
163 170
164void TVListView::last() 171void TVListView::last()
165{ 172{
166 qWarning("TVListView::last not yet implemented"); 173 owarn << "TVListView::last not yet implemented" << oendl;
167} 174}
168 175
169void TVListView::next() 176void TVListView::next()
170{ 177{
171 QListViewItemIterator tmp = *it; 178 QListViewItemIterator tmp = *it;
172 (*it)++; 179 (*it)++;
173 if (!it->current()) { 180 if (!it->current()) {
174 *it = tmp; 181 *it = tmp;
175 } 182 }
176} 183}
177 184
178void TVListView::previous() 185void TVListView::previous()
179{ 186{
180 QListViewItemIterator tmp = *it; 187 QListViewItemIterator tmp = *it;
181 (*it)--; 188 (*it)--;
182 if (!it->current()) { 189 if (!it->current()) {
183 *it = tmp; 190 *it = tmp;
184 } 191 }
185} 192}
186 193
187DataElem *TVListView::getCurrentData() { 194DataElem *TVListView::getCurrentData() {
188 if (it->current()) { 195 if (it->current()) {
189 return ((TVListViewItem *)it->current())->getDataElem(); 196 return ((TVListViewItem *)it->current())->getDataElem();
190 } 197 }
191 return NULL; 198 return NULL;
192} 199}
193 200
194/*! Now to implement the closest match function */ 201/*! Now to implement the closest match function */
195void TVListView::findItem(int keyId, TVVariant value) 202void TVListView::findItem(int keyId, TVVariant value)
196{ 203{
197 QListViewItem *i; 204 QListViewItem *i;
198 TVListViewItem *best_so_far = NULL; 205 TVListViewItem *best_so_far = NULL;
199 /* start at the beginning... go through till find the closest elem */ 206 /* start at the beginning... go through till find the closest elem */
200 i = listViewDisplay->firstChild(); 207 i = listViewDisplay->firstChild();
201 while (i) { 208 while (i) {
202 /* search stuff */ 209 /* search stuff */
203 if(best_so_far) { 210 if(best_so_far) {
204 if (DataElem::closer( 211 if (DataElem::closer(
205 ((TVListViewItem *)i)->getDataElem(), 212 ((TVListViewItem *)i)->getDataElem(),
206 best_so_far->getDataElem(), value, keyId)) 213 best_so_far->getDataElem(), value, keyId))
207 best_so_far = (TVListViewItem *)i; 214 best_so_far = (TVListViewItem *)i;
208 } else { 215 } else {
209 if (DataElem::closer( 216 if (DataElem::closer(
210 ((TVListViewItem *)i)->getDataElem(), 217 ((TVListViewItem *)i)->getDataElem(),
211 NULL, value, keyId)) 218 NULL, value, keyId))
212 best_so_far = (TVListViewItem *)i; 219 best_so_far = (TVListViewItem *)i;
213 } 220 }
214 221
215 i = i->itemBelow(); 222 i = i->itemBelow();
216 } 223 }
217 if (best_so_far) { 224 if (best_so_far) {
218 /* set best_so_far to current element */ 225 /* set best_so_far to current element */
219 delete it; 226 delete it;
220 it = new QListViewItemIterator(best_so_far); 227 it = new QListViewItemIterator(best_so_far);
221 } 228 }
222} 229}
223 230
224void TVListView::rebuildKeys() 231void TVListView::rebuildKeys()
225{ 232{
226 int i; 233 int i;
227 if(!ts) return; 234 if(!ts) return;
228 if(!ts->kRep) return; 235 if(!ts->kRep) return;
229 236
230 i = listViewDisplay->columns(); 237 i = listViewDisplay->columns();
231 238
232 while(i > 0) 239 while(i > 0)
233 listViewDisplay->removeColumn(--i); 240 listViewDisplay->removeColumn(--i);
234 241
235 KeyListIterator kit(*ts->kRep); 242 KeyListIterator kit(*ts->kRep);
236 i = 0; 243 i = 0;
237 while(kit.current()) { 244 while(kit.current()) {
238 if(!kit.current()->delFlag()) { 245 if(!kit.current()->delFlag()) {
239 listViewDisplay->addColumn(kit.current()->name()); 246 listViewDisplay->addColumn(kit.current()->name());
240 keyIds.insert(i, kit.currentKey()); 247 keyIds.insert(i, kit.currentKey());
241 ++i; 248 ++i;
242 } 249 }
243 ++kit; 250 ++kit;
244 } 251 }
245} 252}
246 253
247 254
248void TVListView::setSorting(int column) 255void TVListView::setSorting(int column)
249{ 256{
250 /* Without table state can't do anything */ 257 /* Without table state can't do anything */
251 if (ts == 0) 258 if (ts == 0)
252 return; 259 return;
253 if (keyIds[column] != ts->current_column) { 260 if (keyIds[column] != ts->current_column) {
254 ts->current_column = keyIds[column]; 261 ts->current_column = keyIds[column];
255 } 262 }
256} 263}
257 264
258void TVListView::rebuildData() { 265void TVListView::rebuildData() {
259 int i; 266 int i;
260 QMap<int, int>::Iterator kit; 267 QMap<int, int>::Iterator kit;
261 /* Need to set sort order */ 268 /* Need to set sort order */
262 if(!ts) 269 if(!ts)