summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/opiecore.pro6
-rw-r--r--libopie2/opiecore/xmltree.cpp (renamed from libopie2/opiepim/core/backends/private/xmltree.cc)2
-rw-r--r--libopie2/opiecore/xmltree.h (renamed from libopie2/opiepim/core/backends/private/xmltree.h)4
-rw-r--r--libopie2/opiepim/backend/backends.pro6
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp5
5 files changed, 10 insertions, 13 deletions
diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro
index ff3c036..67ef072 100644
--- a/libopie2/opiecore/opiecore.pro
+++ b/libopie2/opiecore/opiecore.pro
@@ -1,39 +1,41 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = oapplication.h \ 4HEADERS = oapplication.h \
5 oconfig.h \ 5 oconfig.h \
6 odebug.h \ 6 odebug.h \
7 oglobal.h \ 7 oglobal.h \
8 oglobalsettings.h \ 8 oglobalsettings.h \
9 oprocess.h \ 9 oprocess.h \
10 oprocctrl.h \ 10 oprocctrl.h \
11 osmartpointer.h \ 11 osmartpointer.h \
12 ostorageinfo.h 12 ostorageinfo.h \
13 xmltree.h
13 14
14SOURCES = oapplication.cpp \ 15SOURCES = oapplication.cpp \
15 oconfig.cpp \ 16 oconfig.cpp \
16 odebug.cpp \ 17 odebug.cpp \
17 oglobal.cpp \ 18 oglobal.cpp \
18 oglobalsettings.cpp \ 19 oglobalsettings.cpp \
19 oprocess.cpp \ 20 oprocess.cpp \
20 oprocctrl.cpp \ 21 oprocctrl.cpp \
21 ostorageinfo.cpp 22 ostorageinfo.cpp \
23 xmltree.cpp
22 24
23include ( device/device.pro ) 25include ( device/device.pro )
24 26
25INTERFACES = 27INTERFACES =
26TARGET = opiecore2 28TARGET = opiecore2
27VERSION = 1.9.0 29VERSION = 1.9.0
28INCLUDEPATH += $(OPIEDIR)/include 30INCLUDEPATH += $(OPIEDIR)/include
29DEPENDPATH += $(OPIEDIR)/include 31DEPENDPATH += $(OPIEDIR)/include
30 32
31!contains( platform, x11 ) { 33!contains( platform, x11 ) {
32 LIBS = -lqpe 34 LIBS = -lqpe
33 include ( $(OPIEDIR)/include.pro ) 35 include ( $(OPIEDIR)/include.pro )
34} 36}
35 37
36contains( platform, x11 ) { 38contains( platform, x11 ) {
37 LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 39 LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
38} 40}
39 41
diff --git a/libopie2/opiepim/core/backends/private/xmltree.cc b/libopie2/opiecore/xmltree.cpp
index 40749ca..72fe9fd 100644
--- a/libopie2/opiepim/core/backends/private/xmltree.cc
+++ b/libopie2/opiecore/xmltree.cpp
@@ -1,323 +1,323 @@
1/* This file is part of the KDE project 1/* This file is part of the KDE project
2 Copyright (C) 2001 Simon Hausmann <hausmann@kde.org> 2 Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include "xmltree.h" 20#include "xmltree.h"
21 21
22#include <qpe/stringutil.h> 22#include <qpe/stringutil.h>
23 23
24#include <qxml.h> 24#include <qxml.h>
25 25
26#include <assert.h> 26#include <assert.h>
27 27
28using namespace Opie::Pim::Private; 28using namespace Opie::Core;
29 29
30XMLElement::XMLElement() 30XMLElement::XMLElement()
31 : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 ) 31 : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 )
32{ 32{
33} 33}
34 34
35XMLElement::~XMLElement() 35XMLElement::~XMLElement()
36{ 36{
37 XMLElement *n = m_first; 37 XMLElement *n = m_first;
38 38
39 while ( n ) 39 while ( n )
40 { 40 {
41 XMLElement *tmp = n; 41 XMLElement *tmp = n;
42 n = n->m_next; 42 n = n->m_next;
43 delete tmp; 43 delete tmp;
44 } 44 }
45} 45}
46 46
47void XMLElement::appendChild( XMLElement *child ) 47void XMLElement::appendChild( XMLElement *child )
48{ 48{
49 if ( child->m_parent ) 49 if ( child->m_parent )
50 child->m_parent->removeChild( child ); 50 child->m_parent->removeChild( child );
51 51
52 child->m_parent = this; 52 child->m_parent = this;
53 53
54 if ( m_last ) 54 if ( m_last )
55 m_last->m_next = child; 55 m_last->m_next = child;
56 56
57 child->m_prev = m_last; 57 child->m_prev = m_last;
58 58
59 if ( !m_first ) 59 if ( !m_first )
60 m_first = child; 60 m_first = child;
61 61
62 m_last = child; 62 m_last = child;
63} 63}
64 64
65void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild ) 65void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild )
66{ 66{
67 assert( newChild != refChild ); 67 assert( newChild != refChild );
68 68
69 if ( refChild == m_last ) 69 if ( refChild == m_last )
70 { 70 {
71 appendChild( newChild ); 71 appendChild( newChild );
72 return; 72 return;
73 } 73 }
74 74
75 assert( refChild ); 75 assert( refChild );
76 assert( refChild->m_parent ); 76 assert( refChild->m_parent );
77 assert( refChild->m_parent == this ); 77 assert( refChild->m_parent == this );
78 78
79 if ( newChild->m_parent && newChild != refChild ) 79 if ( newChild->m_parent && newChild != refChild )
80 newChild->m_parent->removeChild( newChild ); 80 newChild->m_parent->removeChild( newChild );
81 81
82 newChild->m_parent = this; 82 newChild->m_parent = this;
83 83
84 XMLElement *next = refChild->m_next; 84 XMLElement *next = refChild->m_next;
85 85
86 refChild->m_next = newChild; 86 refChild->m_next = newChild;
87 87
88 newChild->m_prev = refChild; 88 newChild->m_prev = refChild;
89 newChild->m_next = next; 89 newChild->m_next = next;
90 90
91 if ( next ) 91 if ( next )
92 next->m_prev = newChild; 92 next->m_prev = newChild;
93} 93}
94 94
95QString XMLElement::attribute( const QString &attr ) const 95QString XMLElement::attribute( const QString &attr ) const
96{ 96{
97 AttributeMap::ConstIterator it = m_attributes.find( attr ); 97 AttributeMap::ConstIterator it = m_attributes.find( attr );
98 if ( it == m_attributes.end() ) 98 if ( it == m_attributes.end() )
99 return QString::null; 99 return QString::null;
100 return it.data(); 100 return it.data();
101} 101}
102 102
103void XMLElement::setAttribute( const QString &attr, const QString &value ) 103void XMLElement::setAttribute( const QString &attr, const QString &value )
104{ 104{
105 m_attributes.replace( attr, value ); 105 m_attributes.replace( attr, value );
106} 106}
107 107
108void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) 108void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild )
109{ 109{
110 assert( refChild ); 110 assert( refChild );
111 assert( refChild->m_parent ); 111 assert( refChild->m_parent );
112 assert( refChild->m_parent == this ); 112 assert( refChild->m_parent == this );
113 assert( newChild != refChild ); 113 assert( newChild != refChild );
114 114
115 if ( newChild->m_parent && newChild != refChild ) 115 if ( newChild->m_parent && newChild != refChild )
116 newChild->m_parent->removeChild( newChild ); 116 newChild->m_parent->removeChild( newChild );
117 117
118 newChild->m_parent = this; 118 newChild->m_parent = this;
119 119
120 XMLElement *prev = refChild->m_prev; 120 XMLElement *prev = refChild->m_prev;
121 121
122 refChild->m_prev = newChild; 122 refChild->m_prev = newChild;
123 123
124 newChild->m_prev = prev; 124 newChild->m_prev = prev;
125 newChild->m_next = refChild; 125 newChild->m_next = refChild;
126 126
127 if ( prev ) 127 if ( prev )
128 prev->m_next = newChild; 128 prev->m_next = newChild;
129 129
130 if ( refChild == m_first ) 130 if ( refChild == m_first )
131 m_first = newChild; 131 m_first = newChild;
132} 132}
133 133
134void XMLElement::removeChild( XMLElement *child ) 134void XMLElement::removeChild( XMLElement *child )
135{ 135{
136 if ( child->m_parent != this ) 136 if ( child->m_parent != this )
137 return; 137 return;
138 138
139 if ( m_first == child ) 139 if ( m_first == child )
140 m_first = child->m_next; 140 m_first = child->m_next;
141 141
142 if ( m_last == child ) 142 if ( m_last == child )
143 m_last = child->m_prev; 143 m_last = child->m_prev;
144 144
145 if ( child->m_prev ) 145 if ( child->m_prev )
146 child->m_prev->m_next = child->m_next; 146 child->m_prev->m_next = child->m_next;
147 147
148 if ( child->m_next ) 148 if ( child->m_next )
149 child->m_next->m_prev = child->m_prev; 149 child->m_next->m_prev = child->m_prev;
150 150
151 child->m_parent = 0; 151 child->m_parent = 0;
152 child->m_prev = 0; 152 child->m_prev = 0;
153 child->m_next = 0; 153 child->m_next = 0;
154} 154}
155 155
156void XMLElement::save( QTextStream &s, uint indent ) 156void XMLElement::save( QTextStream &s, uint indent )
157{ 157{
158 if ( !m_value.isEmpty() ) 158 if ( !m_value.isEmpty() )
159 { 159 {
160 s << Qtopia::escapeString( m_value ); 160 s << Qtopia::escapeString( m_value );
161 return; 161 return;
162 } 162 }
163 163
164 for ( uint i = 0; i < indent; ++i ) 164 for ( uint i = 0; i < indent; ++i )
165 s << " "; 165 s << " ";
166 166
167 s << "<" << m_tag; 167 s << "<" << m_tag;
168 168
169 if ( !m_attributes.isEmpty() ) 169 if ( !m_attributes.isEmpty() )
170 { 170 {
171 s << " "; 171 s << " ";
172 AttributeMap::ConstIterator it = m_attributes.begin(); 172 AttributeMap::ConstIterator it = m_attributes.begin();
173 AttributeMap::ConstIterator end = m_attributes.end(); 173 AttributeMap::ConstIterator end = m_attributes.end();
174 for (; it != end; ++it ) 174 for (; it != end; ++it )
175 { 175 {
176 s << it.key() << "=\"" << Qtopia::escapeString( it.data() ) << "\""; 176 s << it.key() << "=\"" << Qtopia::escapeString( it.data() ) << "\"";
177 s << " "; 177 s << " ";
178 } 178 }
179 } 179 }
180 180
181 if ( m_last ) 181 if ( m_last )
182 { 182 {
183 if ( ( m_first && !m_first->value().isEmpty() ) || !m_parent ) 183 if ( ( m_first && !m_first->value().isEmpty() ) || !m_parent )
184 s << ">"; 184 s << ">";
185 else 185 else
186 s << ">" << endl; 186 s << ">" << endl;
187 187
188 int newIndent = indent; 188 int newIndent = indent;
189 if ( m_parent ) 189 if ( m_parent )
190 newIndent++; 190 newIndent++;
191 191
192 XMLElement *n = m_first; 192 XMLElement *n = m_first;
193 while ( n ) 193 while ( n )
194 { 194 {
195 n->save( s, newIndent ); 195 n->save( s, newIndent );
196 n = n->nextChild(); 196 n = n->nextChild();
197 } 197 }
198 198
199 if ( m_last && m_last->value().isEmpty() && m_parent ) 199 if ( m_last && m_last->value().isEmpty() && m_parent )
200 for ( uint i = 0; i < indent; ++i ) 200 for ( uint i = 0; i < indent; ++i )
201 s << " "; 201 s << " ";
202 202
203 if ( m_parent ) 203 if ( m_parent )
204 s << "</" << m_tag << ">" << endl; 204 s << "</" << m_tag << ">" << endl;
205 } 205 }
206 else 206 else
207 s << "/>" << endl; 207 s << "/>" << endl;
208} 208}
209 209
210class Handler : public QXmlDefaultHandler 210class Handler : public QXmlDefaultHandler
211{ 211{
212public: 212public:
213 Handler() : m_node( 0 ), m_root( 0 ) {} 213 Handler() : m_node( 0 ), m_root( 0 ) {}
214 214
215 XMLElement *root() const { return m_root; } 215 XMLElement *root() const { return m_root; }
216 216
217 virtual bool startDocument(); 217 virtual bool startDocument();
218 virtual bool endDocument(); 218 virtual bool endDocument();
219 virtual bool startElement( const QString &ns, const QString &ln, const QString &qName, 219 virtual bool startElement( const QString &ns, const QString &ln, const QString &qName,
220 const QXmlAttributes &attr ); 220 const QXmlAttributes &attr );
221 virtual bool endElement( const QString &ns, const QString &ln, const QString &qName ); 221 virtual bool endElement( const QString &ns, const QString &ln, const QString &qName );
222 virtual bool characters( const QString &ch ); 222 virtual bool characters( const QString &ch );
223 223
224private: 224private:
225 XMLElement *m_node; 225 XMLElement *m_node;
226 XMLElement *m_root; 226 XMLElement *m_root;
227}; 227};
228 228
229bool Handler::startDocument() 229bool Handler::startDocument()
230{ 230{
231 m_root = m_node = new XMLElement; 231 m_root = m_node = new XMLElement;
232 232
233 return true; 233 return true;
234} 234}
235 235
236bool Handler::endDocument() 236bool Handler::endDocument()
237{ 237{
238 return m_root == m_node; 238 return m_root == m_node;
239} 239}
240 240
241bool Handler::startElement( const QString &, const QString &, const QString &qName, 241bool Handler::startElement( const QString &, const QString &, const QString &qName,
242 const QXmlAttributes &attr ) 242 const QXmlAttributes &attr )
243{ 243{
244 XMLElement *bm = new XMLElement; 244 XMLElement *bm = new XMLElement;
245 245
246 XMLElement::AttributeMap attributes; 246 XMLElement::AttributeMap attributes;
247 for ( int i = 0; i < attr.length(); ++i ) 247 for ( int i = 0; i < attr.length(); ++i )
248 attributes[ attr.qName( i ) ] = attr.value( i ); 248 attributes[ attr.qName( i ) ] = attr.value( i );
249 249
250 bm->setAttributes( attributes ); 250 bm->setAttributes( attributes );
251 251
252 bm->setTagName( qName ); 252 bm->setTagName( qName );
253 253
254 m_node->appendChild( bm ); 254 m_node->appendChild( bm );
255 m_node = bm; 255 m_node = bm;
256 256
257 return true; 257 return true;
258} 258}
259 259
260bool Handler::endElement( const QString &, const QString &, const QString & ) 260bool Handler::endElement( const QString &, const QString &, const QString & )
261{ 261{
262 if ( m_node == m_root ) 262 if ( m_node == m_root )
263 return false; 263 return false;
264 264
265 m_node = m_node->parent(); 265 m_node = m_node->parent();
266 return true; 266 return true;
267} 267}
268 268
269bool Handler::characters( const QString &ch ) 269bool Handler::characters( const QString &ch )
270{ 270{
271 XMLElement *textNode = new XMLElement; 271 XMLElement *textNode = new XMLElement;
272 textNode->setValue( ch ); 272 textNode->setValue( ch );
273 m_node->appendChild( textNode ); 273 m_node->appendChild( textNode );
274 return true; 274 return true;
275} 275}
276 276
277XMLElement *XMLElement::namedItem( const QString &name ) 277XMLElement *XMLElement::namedItem( const QString &name )
278{ 278{
279 XMLElement *e = m_first; 279 XMLElement *e = m_first;
280 280
281 for (; e; e = e->nextChild() ) 281 for (; e; e = e->nextChild() )
282 if ( e->tagName() == name ) 282 if ( e->tagName() == name )
283 return e; 283 return e;
284 284
285 return 0; 285 return 0;
286} 286}
287 287
288XMLElement *XMLElement::clone() const 288XMLElement *XMLElement::clone() const
289{ 289{
290 XMLElement *res = new XMLElement; 290 XMLElement *res = new XMLElement;
291 291
292 res->setTagName( m_tag ); 292 res->setTagName( m_tag );
293 res->setValue( m_value ); 293 res->setValue( m_value );
294 res->setAttributes( m_attributes ); 294 res->setAttributes( m_attributes );
295 295
296 XMLElement *e = m_first; 296 XMLElement *e = m_first;
297 for (; e; e = e->m_next ) 297 for (; e; e = e->m_next )
298 res->appendChild( e->clone() ); 298 res->appendChild( e->clone() );
299 299
300 return res; 300 return res;
301} 301}
302 302
303XMLElement *XMLElement::load( const QString &fileName ) 303XMLElement *XMLElement::load( const QString &fileName )
304{ 304{
305 QFile f( fileName ); 305 QFile f( fileName );
306 if ( !f.open( IO_ReadOnly ) ) 306 if ( !f.open( IO_ReadOnly ) )
307 return 0; 307 return 0;
308 308
309 QTextStream stream( &f ); 309 QTextStream stream( &f );
310 stream.setEncoding( QTextStream::UnicodeUTF8 ); 310 stream.setEncoding( QTextStream::UnicodeUTF8 );
311 QXmlInputSource src( stream ); 311 QXmlInputSource src( stream );
312 QXmlSimpleReader reader; 312 QXmlSimpleReader reader;
313 Handler handler; 313 Handler handler;
314 314
315 reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); 315 reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false );
316 reader.setContentHandler( &handler ); 316 reader.setContentHandler( &handler );
317 reader.parse( src ); 317 reader.parse( src );
318 318
319 return handler.root();; 319 return handler.root();;
320} 320}
321 321
322/* vim: et sw=4 322/* vim: et sw=4
323 */ 323 */
diff --git a/libopie2/opiepim/core/backends/private/xmltree.h b/libopie2/opiecore/xmltree.h
index 9817a02..5fd79e7 100644
--- a/libopie2/opiepim/core/backends/private/xmltree.h
+++ b/libopie2/opiecore/xmltree.h
@@ -1,122 +1,120 @@
1/* This file is part of the KDE project 1/* This file is part of the KDE project
2 Copyright (C) 2000,2001 Simon Hausmann <hausmann@kde.org> 2 Copyright (C) 2000,2001 Simon Hausmann <hausmann@kde.org>
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20 20
21#ifndef __bookmarks_h__ 21#ifndef __bookmarks_h__
22#define __bookmarks_h__ 22#define __bookmarks_h__
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qmap.h> 25#include <qmap.h>
26#include <qtextstream.h> 26#include <qtextstream.h>
27 27
28namespace Opie { 28namespace Opie {
29namespace Pim { 29namespace Core {
30namespace Private{
31 30
32/** 31/**
33 * A small xml lib written by Simon Hausmann. 32 * A small xml lib written by Simon Hausmann.
34 */ 33 */
35class XMLElement 34class XMLElement
36{ 35{
37public: 36public:
38 typedef QMap<QString, QString> AttributeMap; 37 typedef QMap<QString, QString> AttributeMap;
39 38
40 /** 39 /**
41 * The constructor of XMLElement 40 * The constructor of XMLElement
42 */ 41 */
43 XMLElement(); 42 XMLElement();
44 ~XMLElement(); 43 ~XMLElement();
45 44
46 /** appendChild appends a child to the XMLElement behind the last element. 45 /** appendChild appends a child to the XMLElement behind the last element.
47 * The ownership of the child get's transfered to the 46 * The ownership of the child get's transfered to the
48 * this XMLElement. 47 * this XMLElement.
49 * If child is already the child of another parent 48 * If child is already the child of another parent
50 * it's get removed from the other parent first. 49 * it's get removed from the other parent first.
51 */ 50 */
52 void appendChild( XMLElement *child ); 51 void appendChild( XMLElement *child );
53 52
54 /** inserts newChild after refChild. If newChild is the child 53 /** inserts newChild after refChild. If newChild is the child
55 * of another parent the child will get removed. 54 * of another parent the child will get removed.
56 * The ownership of child gets transfered. 55 * The ownership of child gets transfered.
57 * 56 *
58 */ 57 */
59 void insertAfter( XMLElement *newChild, XMLElement *refChild ); 58 void insertAfter( XMLElement *newChild, XMLElement *refChild );
60 59
61 /** same as insertAfter but the element get's inserted before refChild. 60 /** same as insertAfter but the element get's inserted before refChild.
62 * 61 *
63 */ 62 */
64 void insertBefore( XMLElement *newChild, XMLElement *refChild ); 63 void insertBefore( XMLElement *newChild, XMLElement *refChild );
65 64
66 /** removeChild removes the child from the XMLElement. 65 /** removeChild removes the child from the XMLElement.
67 * The ownership gets dropped. You need to delete the 66 * The ownership gets dropped. You need to delete the
68 * child yourself. 67 * child yourself.
69 */ 68 */
70 void removeChild( XMLElement *child ); 69 void removeChild( XMLElement *child );
71 70
72 /** parent() returns the parent of this XMLElement 71 /** parent() returns the parent of this XMLElement
73 * If there is no parent 0l gets returned 72 * If there is no parent 0l gets returned
74 */ 73 */
75 XMLElement *parent() const { return m_parent; } 74 XMLElement *parent() const { return m_parent; }
76 XMLElement *firstChild() const { return m_first; } 75 XMLElement *firstChild() const { return m_first; }
77 XMLElement *nextChild() const { return m_next; } 76 XMLElement *nextChild() const { return m_next; }
78 XMLElement *prevChild() const { return m_prev; } 77 XMLElement *prevChild() const { return m_prev; }
79 XMLElement *lastChild() const { return m_last; } 78 XMLElement *lastChild() const { return m_last; }
80 79
81 void setTagName( const QString &tag ) { m_tag = tag; } 80 void setTagName( const QString &tag ) { m_tag = tag; }
82 QString tagName() const { return m_tag; } 81 QString tagName() const { return m_tag; }
83 82
84 void setValue( const QString &val ) { m_value = val; } 83 void setValue( const QString &val ) { m_value = val; }
85 QString value() const { return m_value; } 84 QString value() const { return m_value; }
86 85
87 void setAttributes( const AttributeMap &attrs ) { m_attributes = attrs; } 86 void setAttributes( const AttributeMap &attrs ) { m_attributes = attrs; }
88 AttributeMap attributes() const { return m_attributes; } 87 AttributeMap attributes() const { return m_attributes; }
89 AttributeMap &attributes() { return m_attributes; } 88 AttributeMap &attributes() { return m_attributes; }
90 89
91 QString attribute( const QString & ) const; 90 QString attribute( const QString & ) const;
92 void setAttribute( const QString &attr, const QString &value ); 91 void setAttribute( const QString &attr, const QString &value );
93 void save( QTextStream &stream, uint indent = 0 ); 92 void save( QTextStream &stream, uint indent = 0 );
94 93
95 XMLElement *namedItem( const QString &name ); 94 XMLElement *namedItem( const QString &name );
96 95
97 XMLElement *clone() const; 96 XMLElement *clone() const;
98 97
99 static XMLElement *load( const QString &fileName ); 98 static XMLElement *load( const QString &fileName );
100 99
101private: 100private:
102 QString m_tag; 101 QString m_tag;
103 QString m_value; 102 QString m_value;
104 AttributeMap m_attributes; 103 AttributeMap m_attributes;
105 104
106 XMLElement *m_parent; 105 XMLElement *m_parent;
107 XMLElement *m_next; 106 XMLElement *m_next;
108 XMLElement *m_prev; 107 XMLElement *m_prev;
109 XMLElement *m_first; 108 XMLElement *m_first;
110 XMLElement *m_last; 109 XMLElement *m_last;
111 110
112 XMLElement( const XMLElement &rhs ); 111 XMLElement( const XMLElement &rhs );
113 XMLElement &operator=( const XMLElement &rhs ); 112 XMLElement &operator=( const XMLElement &rhs );
114 class Private; 113 class Private;
115 Private* d; 114 Private* d;
116}; 115};
117 116
118} 117}
119}
120} // namespace Opie 118} // namespace Opie
121 119
122#endif 120#endif
diff --git a/libopie2/opiepim/backend/backends.pro b/libopie2/opiepim/backend/backends.pro
index d4867ba..953d928 100644
--- a/libopie2/opiepim/backend/backends.pro
+++ b/libopie2/opiepim/backend/backends.pro
@@ -1,33 +1,31 @@
1SOURCES += core/backends/ocontactaccessbackend_sql.cpp \ 1SOURCES += core/backends/ocontactaccessbackend_sql.cpp \
2 core/backends/ocontactaccessbackend_vcard.cpp \ 2 core/backends/ocontactaccessbackend_vcard.cpp \
3 core/backends/ocontactaccessbackend_xml.cpp \ 3 core/backends/ocontactaccessbackend_xml.cpp \
4 core/backends/ocontactaccess.cpp \ 4 core/backends/ocontactaccess.cpp \
5 core/backends/odatebookaccessbackend.cpp \ 5 core/backends/odatebookaccessbackend.cpp \
6 core/backends/odatebookaccessbackend_xml.cpp \ 6 core/backends/odatebookaccessbackend_xml.cpp \
7 core/backends/otodoaccessbackend.cpp \ 7 core/backends/otodoaccessbackend.cpp \
8 core/backends/otodoaccess.cpp \ 8 core/backends/otodoaccess.cpp \
9 core/backends/otodoaccesssql.cpp \ 9 core/backends/otodoaccesssql.cpp \
10 core/backends/otodoaccessvcal.cpp \ 10 core/backends/otodoaccessvcal.cpp \
11 core/backends/otodoaccessxml.cpp \ 11 core/backends/otodoaccessxml.cpp \
12 core/backends/odatebookaccess.cpp \ 12 core/backends/odatebookaccess.cpp \
13 core/backends/odatebookaccessbackend_sql.cpp \ 13 core/backends/odatebookaccessbackend_sql.cpp
14 core/backends/private/xmltree.cc
15 14
16HEADERS += core/backends/obackendfactory.h \ 15HEADERS += core/backends/obackendfactory.h \
17 core/backends/ocontactaccessbackend.h \ 16 core/backends/ocontactaccessbackend.h \
18 core/backends/ocontactaccessbackend_sql.h \ 17 core/backends/ocontactaccessbackend_sql.h \
19 core/backends/ocontactaccessbackend_vcard.h \ 18 core/backends/ocontactaccessbackend_vcard.h \
20 core/backends/ocontactaccessbackend_xml.h \ 19 core/backends/ocontactaccessbackend_xml.h \
21 core/backends/ocontactaccess.h \ 20 core/backends/ocontactaccess.h \
22 core/backends/odatebookaccessbackend.h \ 21 core/backends/odatebookaccessbackend.h \
23 core/backends/odatebookaccessbackend_sql.h \ 22 core/backends/odatebookaccessbackend_sql.h \
24 core/backends/odatebookaccessbackend_xml.h \ 23 core/backends/odatebookaccessbackend_xml.h \
25 core/backends/opimaccessbackend.h \ 24 core/backends/opimaccessbackend.h \
26 core/backends/opimaccesstemplate.h \ 25 core/backends/opimaccesstemplate.h \
27 core/backends/otodoaccessbackend.h \ 26 core/backends/otodoaccessbackend.h \
28 core/backends/otodoaccess.h \ 27 core/backends/otodoaccess.h \
29 core/backends/otodoaccesssql.h \ 28 core/backends/otodoaccesssql.h \
30 core/backends/otodoaccessvcal.h \ 29 core/backends/otodoaccessvcal.h \
31 core/backends/otodoaccessxml.h \ 30 core/backends/otodoaccessxml.h \
32 core/backends/odatebookaccess.h \ 31 core/backends/odatebookaccess.h
33 core/backends/private/xmltree.h
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index f5e76d5..2b467c3 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -1,564 +1,563 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * XML Backend for the OPIE-Contact Database. 30 * XML Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33#include <opie2/ocontactaccessbackend_xml.h> 33#include <opie2/ocontactaccessbackend_xml.h>
34 34
35#include <qasciidict.h> 35#include <qasciidict.h>
36#include <qfile.h> 36#include <qfile.h>
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qregexp.h> 38#include <qregexp.h>
39#include <qarray.h> 39#include <qarray.h>
40#include <qmap.h> 40#include <qmap.h>
41 41
42#include <qpe/global.h> 42#include <qpe/global.h>
43 43
44#include "private/xmltree.h" 44#include <opie2/xmltree.h>
45#include <opie2/ocontactaccessbackend.h> 45#include <opie2/ocontactaccessbackend.h>
46#include <opie2/ocontactaccess.h> 46#include <opie2/ocontactaccess.h>
47 47
48#include <stdlib.h> 48#include <stdlib.h>
49#include <errno.h> 49#include <errno.h>
50 50
51using namespace Opie; 51using namespace Opie::Core;
52using namespace Opie::Pim::Private;
53 52
54 53
55namespace Opie { 54namespace Opie {
56OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ): 55OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ):
57 m_changed( false ) 56 m_changed( false )
58{ 57{
59 // Just m_contactlist should call delete if an entry 58 // Just m_contactlist should call delete if an entry
60 // is removed. 59 // is removed.
61 m_contactList.setAutoDelete( true ); 60 m_contactList.setAutoDelete( true );
62 m_uidToContact.setAutoDelete( false ); 61 m_uidToContact.setAutoDelete( false );
63 62
64 m_appName = appname; 63 m_appName = appname;
65 64
66 /* Set journalfile name ... */ 65 /* Set journalfile name ... */
67 m_journalName = getenv("HOME"); 66 m_journalName = getenv("HOME");
68 m_journalName +="/.abjournal" + appname; 67 m_journalName +="/.abjournal" + appname;
69 68
70 /* Expecting to access the default filename if nothing else is set */ 69 /* Expecting to access the default filename if nothing else is set */
71 if ( filename.isEmpty() ){ 70 if ( filename.isEmpty() ){
72 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 71 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
73 } else 72 } else
74 m_fileName = filename; 73 m_fileName = filename;
75 74
76 /* Load Database now */ 75 /* Load Database now */
77 load (); 76 load ();
78} 77}
79 78
80bool OPimContactAccessBackend_XML::save() 79bool OPimContactAccessBackend_XML::save()
81{ 80{
82 81
83 if ( !m_changed ) 82 if ( !m_changed )
84 return true; 83 return true;
85 84
86 QString strNewFile = m_fileName + ".new"; 85 QString strNewFile = m_fileName + ".new";
87 QFile f( strNewFile ); 86 QFile f( strNewFile );
88 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 87 if ( !f.open( IO_WriteOnly|IO_Raw ) )
89 return false; 88 return false;
90 89
91 int total_written; 90 int total_written;
92 int idx_offset = 0; 91 int idx_offset = 0;
93 QString out; 92 QString out;
94 93
95 // Write Header 94 // Write Header
96 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 95 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
97 " <Groups>\n" 96 " <Groups>\n"
98 " </Groups>\n" 97 " </Groups>\n"
99 " <Contacts>\n"; 98 " <Contacts>\n";
100 QCString cstr = out.utf8(); 99 QCString cstr = out.utf8();
101 f.writeBlock( cstr.data(), cstr.length() ); 100 f.writeBlock( cstr.data(), cstr.length() );
102 idx_offset += cstr.length(); 101 idx_offset += cstr.length();
103 out = ""; 102 out = "";
104 103
105 // Write all contacts 104 // Write all contacts
106 QListIterator<OPimContact> it( m_contactList ); 105 QListIterator<OPimContact> it( m_contactList );
107 for ( ; it.current(); ++it ) { 106 for ( ; it.current(); ++it ) {
108 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); 107 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset );
109 out += "<Contact "; 108 out += "<Contact ";
110 (*it)->save( out ); 109 (*it)->save( out );
111 out += "/>\n"; 110 out += "/>\n";
112 cstr = out.utf8(); 111 cstr = out.utf8();
113 total_written = f.writeBlock( cstr.data(), cstr.length() ); 112 total_written = f.writeBlock( cstr.data(), cstr.length() );
114 idx_offset += cstr.length(); 113 idx_offset += cstr.length();
115 if ( total_written != int(cstr.length()) ) { 114 if ( total_written != int(cstr.length()) ) {
116 f.close(); 115 f.close();
117 QFile::remove( strNewFile ); 116 QFile::remove( strNewFile );
118 return false; 117 return false;
119 } 118 }
120 out = ""; 119 out = "";
121 } 120 }
122 out += " </Contacts>\n</AddressBook>\n"; 121 out += " </Contacts>\n</AddressBook>\n";
123 122
124 // Write Footer 123 // Write Footer
125 cstr = out.utf8(); 124 cstr = out.utf8();
126 total_written = f.writeBlock( cstr.data(), cstr.length() ); 125 total_written = f.writeBlock( cstr.data(), cstr.length() );
127 if ( total_written != int( cstr.length() ) ) { 126 if ( total_written != int( cstr.length() ) ) {
128 f.close(); 127 f.close();
129 QFile::remove( strNewFile ); 128 QFile::remove( strNewFile );
130 return false; 129 return false;
131 } 130 }
132 f.close(); 131 f.close();
133 132
134 // move the file over, I'm just going to use the system call 133 // move the file over, I'm just going to use the system call
135 // because, I don't feel like using QDir. 134 // because, I don't feel like using QDir.
136 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 135 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
137 qWarning( "problem renaming file %s to %s, errno: %d", 136 qWarning( "problem renaming file %s to %s, errno: %d",
138 strNewFile.latin1(), m_journalName.latin1(), errno ); 137 strNewFile.latin1(), m_journalName.latin1(), errno );
139 // remove the tmp file... 138 // remove the tmp file...
140 QFile::remove( strNewFile ); 139 QFile::remove( strNewFile );
141 } 140 }
142 141
143 /* The journalfile should be removed now... */ 142 /* The journalfile should be removed now... */
144 removeJournal(); 143 removeJournal();
145 144
146 m_changed = false; 145 m_changed = false;
147 return true; 146 return true;
148} 147}
149 148
150bool OPimContactAccessBackend_XML::load () 149bool OPimContactAccessBackend_XML::load ()
151{ 150{
152 m_contactList.clear(); 151 m_contactList.clear();
153 m_uidToContact.clear(); 152 m_uidToContact.clear();
154 153
155 /* Load XML-File and journal if it exists */ 154 /* Load XML-File and journal if it exists */
156 if ( !load ( m_fileName, false ) ) 155 if ( !load ( m_fileName, false ) )
157 return false; 156 return false;
158 /* The returncode of the journalfile is ignored due to the 157 /* The returncode of the journalfile is ignored due to the
159 * fact that it does not exist when this class is instantiated ! 158 * fact that it does not exist when this class is instantiated !
160 * But there may such a file exist, if the application crashed. 159 * But there may such a file exist, if the application crashed.
161 * Therefore we try to load it to get the changes before the # 160 * Therefore we try to load it to get the changes before the #
162 * crash happened... 161 * crash happened...
163 */ 162 */
164 load (m_journalName, true); 163 load (m_journalName, true);
165 164
166 return true; 165 return true;
167} 166}
168 167
169void OPimContactAccessBackend_XML::clear () 168void OPimContactAccessBackend_XML::clear ()
170{ 169{
171 m_contactList.clear(); 170 m_contactList.clear();
172 m_uidToContact.clear(); 171 m_uidToContact.clear();
173 172
174 m_changed = false; 173 m_changed = false;
175} 174}
176 175
177bool OPimContactAccessBackend_XML::wasChangedExternally() 176bool OPimContactAccessBackend_XML::wasChangedExternally()
178{ 177{
179 QFileInfo fi( m_fileName ); 178 QFileInfo fi( m_fileName );
180 179
181 QDateTime lastmod = fi.lastModified (); 180 QDateTime lastmod = fi.lastModified ();
182 181
183 return (lastmod != m_readtime); 182 return (lastmod != m_readtime);
184} 183}
185 184
186QArray<int> OPimContactAccessBackend_XML::allRecords() const 185QArray<int> OPimContactAccessBackend_XML::allRecords() const
187{ 186{
188 QArray<int> uid_list( m_contactList.count() ); 187 QArray<int> uid_list( m_contactList.count() );
189 188
190 uint counter = 0; 189 uint counter = 0;
191 QListIterator<OPimContact> it( m_contactList ); 190 QListIterator<OPimContact> it( m_contactList );
192 for( ; it.current(); ++it ){ 191 for( ; it.current(); ++it ){
193 uid_list[counter++] = (*it)->uid(); 192 uid_list[counter++] = (*it)->uid();
194 } 193 }
195 194
196 return ( uid_list ); 195 return ( uid_list );
197} 196}
198 197
199OPimContact OPimContactAccessBackend_XML::find ( int uid ) const 198OPimContact OPimContactAccessBackend_XML::find ( int uid ) const
200{ 199{
201 OPimContact foundContact; //Create empty contact 200 OPimContact foundContact; //Create empty contact
202 201
203 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) ); 202 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) );
204 203
205 if ( found ){ 204 if ( found ){
206 foundContact = *found; 205 foundContact = *found;
207 } 206 }
208 207
209 return ( foundContact ); 208 return ( foundContact );
210} 209}
211 210
212QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, 211QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings,
213 const QDateTime& d ) 212 const QDateTime& d )
214{ 213{
215 214
216 QArray<int> m_currentQuery( m_contactList.count() ); 215 QArray<int> m_currentQuery( m_contactList.count() );
217 QListIterator<OPimContact> it( m_contactList ); 216 QListIterator<OPimContact> it( m_contactList );
218 uint arraycounter = 0; 217 uint arraycounter = 0;
219 218
220 for( ; it.current(); ++it ){ 219 for( ; it.current(); ++it ){
221 /* Search all fields and compare them with query object. Store them into list 220 /* Search all fields and compare them with query object. Store them into list
222 * if all fields matches. 221 * if all fields matches.
223 */ 222 */
224 QDate* queryDate = 0l; 223 QDate* queryDate = 0l;
225 QDate* checkDate = 0l; 224 QDate* checkDate = 0l;
226 bool allcorrect = true; 225 bool allcorrect = true;
227 for ( int i = 0; i < Qtopia::Groups; i++ ) { 226 for ( int i = 0; i < Qtopia::Groups; i++ ) {
228 // Birthday and anniversary are special nonstring fields and should 227 // Birthday and anniversary are special nonstring fields and should
229 // be handled specially 228 // be handled specially
230 switch ( i ){ 229 switch ( i ){
231 case Qtopia::Birthday: 230 case Qtopia::Birthday:
232 queryDate = new QDate( query.birthday() ); 231 queryDate = new QDate( query.birthday() );
233 checkDate = new QDate( (*it)->birthday() ); 232 checkDate = new QDate( (*it)->birthday() );
234 case Qtopia::Anniversary: 233 case Qtopia::Anniversary:
235 if ( queryDate == 0l ){ 234 if ( queryDate == 0l ){
236 queryDate = new QDate( query.anniversary() ); 235 queryDate = new QDate( query.anniversary() );
237 checkDate = new QDate( (*it)->anniversary() ); 236 checkDate = new QDate( (*it)->anniversary() );
238 } 237 }
239 238
240 if ( queryDate->isValid() ){ 239 if ( queryDate->isValid() ){
241 if( checkDate->isValid() ){ 240 if( checkDate->isValid() ){
242 if ( settings & OPimContactAccess::DateYear ){ 241 if ( settings & OPimContactAccess::DateYear ){
243 if ( queryDate->year() != checkDate->year() ) 242 if ( queryDate->year() != checkDate->year() )
244 allcorrect = false; 243 allcorrect = false;
245 } 244 }
246 if ( settings & OPimContactAccess::DateMonth ){ 245 if ( settings & OPimContactAccess::DateMonth ){
247 if ( queryDate->month() != checkDate->month() ) 246 if ( queryDate->month() != checkDate->month() )
248 allcorrect = false; 247 allcorrect = false;
249 } 248 }
250 if ( settings & OPimContactAccess::DateDay ){ 249 if ( settings & OPimContactAccess::DateDay ){
251 if ( queryDate->day() != checkDate->day() ) 250 if ( queryDate->day() != checkDate->day() )
252 allcorrect = false; 251 allcorrect = false;
253 } 252 }
254 if ( settings & OPimContactAccess::DateDiff ) { 253 if ( settings & OPimContactAccess::DateDiff ) {
255 QDate current; 254 QDate current;
256 // If we get an additional date, we 255 // If we get an additional date, we
257 // will take this date instead of 256 // will take this date instead of
258 // the current one.. 257 // the current one..
259 if ( !d.date().isValid() ) 258 if ( !d.date().isValid() )
260 current = QDate::currentDate(); 259 current = QDate::currentDate();
261 else 260 else
262 current = d.date(); 261 current = d.date();
263 262
264 // We have to equalize the year, otherwise 263 // We have to equalize the year, otherwise
265 // the search will fail.. 264 // the search will fail..
266 checkDate->setYMD( current.year(), 265 checkDate->setYMD( current.year(),
267 checkDate->month(), 266 checkDate->month(),
268 checkDate->day() ); 267 checkDate->day() );
269 if ( *checkDate < current ) 268 if ( *checkDate < current )
270 checkDate->setYMD( current.year()+1, 269 checkDate->setYMD( current.year()+1,
271 checkDate->month(), 270 checkDate->month(),
272 checkDate->day() ); 271 checkDate->day() );
273 272
274 // Check whether the birthday/anniversary date is between 273 // Check whether the birthday/anniversary date is between
275 // the current/given date and the maximum date 274 // the current/given date and the maximum date
276 // ( maximum time range ) ! 275 // ( maximum time range ) !
277 qWarning("Checking if %s is between %s and %s ! ", 276 qWarning("Checking if %s is between %s and %s ! ",
278 checkDate->toString().latin1(), 277 checkDate->toString().latin1(),
279 current.toString().latin1(), 278 current.toString().latin1(),
280 queryDate->toString().latin1() ); 279 queryDate->toString().latin1() );
281 if ( current.daysTo( *queryDate ) >= 0 ){ 280 if ( current.daysTo( *queryDate ) >= 0 ){
282 if ( !( ( *checkDate >= current ) && 281 if ( !( ( *checkDate >= current ) &&
283 ( *checkDate <= *queryDate ) ) ){ 282 ( *checkDate <= *queryDate ) ) ){
284 allcorrect = false; 283 allcorrect = false;
285 qWarning (" Nope!.."); 284 qWarning (" Nope!..");
286 } 285 }
287 } 286 }
288 } 287 }
289 } else{ 288 } else{
290 // checkDate is invalid. Therefore this entry is always rejected 289 // checkDate is invalid. Therefore this entry is always rejected
291 allcorrect = false; 290 allcorrect = false;
292 } 291 }
293 } 292 }
294 293
295 delete queryDate; 294 delete queryDate;
296 queryDate = 0l; 295 queryDate = 0l;
297 delete checkDate; 296 delete checkDate;
298 checkDate = 0l; 297 checkDate = 0l;
299 break; 298 break;
300 default: 299 default:
301 /* Just compare fields which are not empty in the query object */ 300 /* Just compare fields which are not empty in the query object */
302 if ( !query.field(i).isEmpty() ){ 301 if ( !query.field(i).isEmpty() ){
303 switch ( settings & ~( OPimContactAccess::IgnoreCase 302 switch ( settings & ~( OPimContactAccess::IgnoreCase
304 | OPimContactAccess::DateDiff 303 | OPimContactAccess::DateDiff
305 | OPimContactAccess::DateYear 304 | OPimContactAccess::DateYear
306 | OPimContactAccess::DateMonth 305 | OPimContactAccess::DateMonth
307 | OPimContactAccess::DateDay 306 | OPimContactAccess::DateDay
308 | OPimContactAccess::MatchOne 307 | OPimContactAccess::MatchOne
309 ) ){ 308 ) ){
310 309
311 case OPimContactAccess::RegExp:{ 310 case OPimContactAccess::RegExp:{
312 QRegExp expr ( query.field(i), 311 QRegExp expr ( query.field(i),
313 !(settings & OPimContactAccess::IgnoreCase), 312 !(settings & OPimContactAccess::IgnoreCase),
314 false ); 313 false );
315 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 314 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
316 allcorrect = false; 315 allcorrect = false;
317 } 316 }
318 break; 317 break;
319 case OPimContactAccess::WildCards:{ 318 case OPimContactAccess::WildCards:{
320 QRegExp expr ( query.field(i), 319 QRegExp expr ( query.field(i),
321 !(settings & OPimContactAccess::IgnoreCase), 320 !(settings & OPimContactAccess::IgnoreCase),
322 true ); 321 true );
323 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 322 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
324 allcorrect = false; 323 allcorrect = false;
325 } 324 }
326 break; 325 break;
327 case OPimContactAccess::ExactMatch:{ 326 case OPimContactAccess::ExactMatch:{
328 if (settings & OPimContactAccess::IgnoreCase){ 327 if (settings & OPimContactAccess::IgnoreCase){
329 if ( query.field(i).upper() != 328 if ( query.field(i).upper() !=
330 (*it)->field(i).upper() ) 329 (*it)->field(i).upper() )
331 allcorrect = false; 330 allcorrect = false;
332 }else{ 331 }else{
333 if ( query.field(i) != (*it)->field(i) ) 332 if ( query.field(i) != (*it)->field(i) )
334 allcorrect = false; 333 allcorrect = false;
335 } 334 }
336 } 335 }
337 break; 336 break;
338 } 337 }
339 } 338 }
340 } 339 }
341 } 340 }
342 if ( allcorrect ){ 341 if ( allcorrect ){
343 m_currentQuery[arraycounter++] = (*it)->uid(); 342 m_currentQuery[arraycounter++] = (*it)->uid();
344 } 343 }
345 } 344 }
346 345
347 // Shrink to fit.. 346 // Shrink to fit..
348 m_currentQuery.resize(arraycounter); 347 m_currentQuery.resize(arraycounter);
349 348
350 return m_currentQuery; 349 return m_currentQuery;
351} 350}
352 351
353QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const 352QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
354{ 353{
355 QArray<int> m_currentQuery( m_contactList.count() ); 354 QArray<int> m_currentQuery( m_contactList.count() );
356 QListIterator<OPimContact> it( m_contactList ); 355 QListIterator<OPimContact> it( m_contactList );
357 uint arraycounter = 0; 356 uint arraycounter = 0;
358 357
359 for( ; it.current(); ++it ){ 358 for( ; it.current(); ++it ){
360 if ( (*it)->match( r ) ){ 359 if ( (*it)->match( r ) ){
361 m_currentQuery[arraycounter++] = (*it)->uid(); 360 m_currentQuery[arraycounter++] = (*it)->uid();
362 } 361 }
363 362
364 } 363 }
365 // Shrink to fit.. 364 // Shrink to fit..
366 m_currentQuery.resize(arraycounter); 365 m_currentQuery.resize(arraycounter);
367 366
368 return m_currentQuery; 367 return m_currentQuery;
369} 368}
370 369
371const uint OPimContactAccessBackend_XML::querySettings() 370const uint OPimContactAccessBackend_XML::querySettings()
372{ 371{
373 return ( OPimContactAccess::WildCards 372 return ( OPimContactAccess::WildCards
374 | OPimContactAccess::IgnoreCase 373 | OPimContactAccess::IgnoreCase
375 | OPimContactAccess::RegExp 374 | OPimContactAccess::RegExp
376 | OPimContactAccess::ExactMatch 375 | OPimContactAccess::ExactMatch
377 | OPimContactAccess::DateDiff 376 | OPimContactAccess::DateDiff
378 | OPimContactAccess::DateYear 377 | OPimContactAccess::DateYear
379 | OPimContactAccess::DateMonth 378 | OPimContactAccess::DateMonth
380 | OPimContactAccess::DateDay 379 | OPimContactAccess::DateDay
381 ); 380 );
382} 381}
383 382
384bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const 383bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
385{ 384{
386 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 385 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
387 * may be added with any of the other settings. IgnoreCase should never used alone. 386 * may be added with any of the other settings. IgnoreCase should never used alone.
388 * Wildcards, RegExp, ExactMatch should never used at the same time... 387 * Wildcards, RegExp, ExactMatch should never used at the same time...
389 */ 388 */
390 389
391 // Step 1: Check whether the given settings are supported by this backend 390 // Step 1: Check whether the given settings are supported by this backend
392 if ( ( querySettings & ( 391 if ( ( querySettings & (
393 OPimContactAccess::IgnoreCase 392 OPimContactAccess::IgnoreCase
394 | OPimContactAccess::WildCards 393 | OPimContactAccess::WildCards
395 | OPimContactAccess::DateDiff 394 | OPimContactAccess::DateDiff
396 | OPimContactAccess::DateYear 395 | OPimContactAccess::DateYear
397 | OPimContactAccess::DateMonth 396 | OPimContactAccess::DateMonth
398 | OPimContactAccess::DateDay 397 | OPimContactAccess::DateDay
399 | OPimContactAccess::RegExp 398 | OPimContactAccess::RegExp
400 | OPimContactAccess::ExactMatch 399 | OPimContactAccess::ExactMatch
401 ) ) != querySettings ) 400 ) ) != querySettings )
402 return false; 401 return false;
403 402
404 // Step 2: Check whether the given combinations are ok.. 403 // Step 2: Check whether the given combinations are ok..
405 404
406 // IngoreCase alone is invalid 405 // IngoreCase alone is invalid
407 if ( querySettings == OPimContactAccess::IgnoreCase ) 406 if ( querySettings == OPimContactAccess::IgnoreCase )
408 return false; 407 return false;
409 408
410 // WildCards, RegExp and ExactMatch should never used at the same time 409 // WildCards, RegExp and ExactMatch should never used at the same time
411 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 410 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
412 | OPimContactAccess::DateDiff 411 | OPimContactAccess::DateDiff
413 | OPimContactAccess::DateYear 412 | OPimContactAccess::DateYear
414 | OPimContactAccess::DateMonth 413 | OPimContactAccess::DateMonth
415 | OPimContactAccess::DateDay 414 | OPimContactAccess::DateDay
416 ) 415 )
417 ){ 416 ){
418 case OPimContactAccess::RegExp: 417 case OPimContactAccess::RegExp:
419 return ( true ); 418 return ( true );
420 case OPimContactAccess::WildCards: 419 case OPimContactAccess::WildCards:
421 return ( true ); 420 return ( true );
422 case OPimContactAccess::ExactMatch: 421 case OPimContactAccess::ExactMatch:
423 return ( true ); 422 return ( true );
424 case 0: // one of the upper removed bits were set.. 423 case 0: // one of the upper removed bits were set..
425 return ( true ); 424 return ( true );
426 default: 425 default:
427 return ( false ); 426 return ( false );
428 } 427 }
429} 428}
430 429
431// Currently only asc implemented.. 430// Currently only asc implemented..
432QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) 431QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
433{ 432{
434 QMap<QString, int> nameToUid; 433 QMap<QString, int> nameToUid;
435 QStringList names; 434 QStringList names;
436 QArray<int> m_currentQuery( m_contactList.count() ); 435 QArray<int> m_currentQuery( m_contactList.count() );
437 436
438 // First fill map and StringList with all Names 437 // First fill map and StringList with all Names
439 // Afterwards sort namelist and use map to fill array to return.. 438 // Afterwards sort namelist and use map to fill array to return..
440 QListIterator<OPimContact> it( m_contactList ); 439 QListIterator<OPimContact> it( m_contactList );
441 for( ; it.current(); ++it ){ 440 for( ; it.current(); ++it ){
442 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); 441 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
443 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); 442 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
444 } 443 }
445 names.sort(); 444 names.sort();
446 445
447 int i = 0; 446 int i = 0;
448 if ( asc ){ 447 if ( asc ){
449 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 448 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
450 m_currentQuery[i++] = nameToUid[ (*it) ]; 449 m_currentQuery[i++] = nameToUid[ (*it) ];
451 }else{ 450 }else{
452 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 451 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
453 m_currentQuery[i++] = nameToUid[ (*it) ]; 452 m_currentQuery[i++] = nameToUid[ (*it) ];
454 } 453 }
455 454
456 return m_currentQuery; 455 return m_currentQuery;
457 456
458} 457}
459 458
460bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact ) 459bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
461{ 460{
462 //qWarning("odefaultbackend: ACTION::ADD"); 461 //qWarning("odefaultbackend: ACTION::ADD");
463 updateJournal (newcontact, ACTION_ADD); 462 updateJournal (newcontact, ACTION_ADD);
464 addContact_p( newcontact ); 463 addContact_p( newcontact );
465 464
466 m_changed = true; 465 m_changed = true;
467 466
468 return true; 467 return true;
469} 468}
470 469
471bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact ) 470bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
472{ 471{
473 m_changed = true; 472 m_changed = true;
474 473
475 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); 474 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
476 475
477 if ( found ) { 476 if ( found ) {
478 OPimContact* newCont = new OPimContact( contact ); 477 OPimContact* newCont = new OPimContact( contact );
479 478
480 updateJournal ( *newCont, ACTION_REPLACE); 479 updateJournal ( *newCont, ACTION_REPLACE);
481 m_contactList.removeRef ( found ); 480 m_contactList.removeRef ( found );
482 m_contactList.append ( newCont ); 481 m_contactList.append ( newCont );
483 m_uidToContact.remove( QString().setNum( contact.uid() ) ); 482 m_uidToContact.remove( QString().setNum( contact.uid() ) );
484 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); 483 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
485 484
486 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); 485 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid());
487 486
488 return true; 487 return true;
489 } else 488 } else
490 return false; 489 return false;
491} 490}
492 491
493bool OPimContactAccessBackend_XML::remove ( int uid ) 492bool OPimContactAccessBackend_XML::remove ( int uid )
494{ 493{
495 m_changed = true; 494 m_changed = true;
496 495
497 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) ); 496 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) );
498 497
499 if ( found ) { 498 if ( found ) {
500 updateJournal ( *found, ACTION_REMOVE); 499 updateJournal ( *found, ACTION_REMOVE);
501 m_contactList.removeRef ( found ); 500 m_contactList.removeRef ( found );
502 m_uidToContact.remove( QString().setNum( uid ) ); 501 m_uidToContact.remove( QString().setNum( uid ) );
503 502
504 return true; 503 return true;
505 } else 504 } else
506 return false; 505 return false;
507} 506}
508 507
509bool OPimContactAccessBackend_XML::reload(){ 508bool OPimContactAccessBackend_XML::reload(){
510 /* Reload is the same as load in this implementation */ 509 /* Reload is the same as load in this implementation */
511 return ( load() ); 510 return ( load() );
512} 511}
513 512
514void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact ) 513void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact )
515{ 514{
516 OPimContact* contRef = new OPimContact( newcontact ); 515 OPimContact* contRef = new OPimContact( newcontact );
517 516
518 m_contactList.append ( contRef ); 517 m_contactList.append ( contRef );
519 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); 518 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
520} 519}
521 520
522/* This function loads the xml-database and the journalfile */ 521/* This function loads the xml-database and the journalfile */
523bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal ) 522bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal )
524{ 523{
525 524
526 /* We use the time of the last read to check if the file was 525 /* We use the time of the last read to check if the file was
527 * changed externally. 526 * changed externally.
528 */ 527 */
529 if ( !isJournal ){ 528 if ( !isJournal ){
530 QFileInfo fi( filename ); 529 QFileInfo fi( filename );
531 m_readtime = fi.lastModified (); 530 m_readtime = fi.lastModified ();
532 } 531 }
533 532
534 const int JOURNALACTION = Qtopia::Notes + 1; 533 const int JOURNALACTION = Qtopia::Notes + 1;
535 const int JOURNALROW = JOURNALACTION + 1; 534 const int JOURNALROW = JOURNALACTION + 1;
536 535
537 bool foundAction = false; 536 bool foundAction = false;
538 journal_action action = ACTION_ADD; 537 journal_action action = ACTION_ADD;
539 int journalKey = 0; 538 int journalKey = 0;
540 QMap<int, QString> contactMap; 539 QMap<int, QString> contactMap;
541 QMap<QString, QString> customMap; 540 QMap<QString, QString> customMap;
542 QMap<QString, QString>::Iterator customIt; 541 QMap<QString, QString>::Iterator customIt;
543 QAsciiDict<int> dict( 47 ); 542 QAsciiDict<int> dict( 47 );
544 543
545 dict.setAutoDelete( TRUE ); 544 dict.setAutoDelete( TRUE );
546 dict.insert( "Uid", new int(Qtopia::AddressUid) ); 545 dict.insert( "Uid", new int(Qtopia::AddressUid) );
547 dict.insert( "Title", new int(Qtopia::Title) ); 546 dict.insert( "Title", new int(Qtopia::Title) );
548 dict.insert( "FirstName", new int(Qtopia::FirstName) ); 547 dict.insert( "FirstName", new int(Qtopia::FirstName) );
549 dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); 548 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
550 dict.insert( "LastName", new int(Qtopia::LastName) ); 549 dict.insert( "LastName", new int(Qtopia::LastName) );
551 dict.insert( "Suffix", new int(Qtopia::Suffix) ); 550 dict.insert( "Suffix", new int(Qtopia::Suffix) );
552 dict.insert( "FileAs", new int(Qtopia::FileAs) ); 551 dict.insert( "FileAs", new int(Qtopia::FileAs) );
553 dict.insert( "Categories", new int(Qtopia::AddressCategory) ); 552 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
554 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); 553 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
555 dict.insert( "Emails", new int(Qtopia::Emails) ); 554 dict.insert( "Emails", new int(Qtopia::Emails) );
556 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); 555 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
557 dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); 556 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
558 dict.insert( "HomeState", new int(Qtopia::HomeState) ); 557 dict.insert( "HomeState", new int(Qtopia::HomeState) );
559 dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); 558 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
560 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); 559 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
561 dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); 560 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
562 dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); 561 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
563 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); 562 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
564 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); 563 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );