summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.cpp18
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.h5
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp18
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.h5
4 files changed, 36 insertions, 10 deletions
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp
index 903c0b7..013f3af 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.cpp
+++ b/libopie/pim/ocontactaccessbackend_vcard.cpp
@@ -1,296 +1,304 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#include "ocontactaccessbackend_vcard.h" 27#include "ocontactaccessbackend_vcard.h"
24#include "../../library/backend/vobject_p.h" 28#include "../../library/backend/vobject_p.h"
25#include "../../library/backend/qfiledirect_p.h" 29#include "../../library/backend/qfiledirect_p.h"
26 30
27#include <qpe/timeconversion.h> 31#include <qpe/timeconversion.h>
28 32
29#include <qfile.h> 33#include <qfile.h>
30 34
31OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ): 35OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ):
32 m_dirty( false ), 36 m_dirty( false ),
33 m_file( filename ) 37 m_file( filename )
34{} 38{
39 load();
40}
35 41
36 42
37bool OContactAccessBackend_VCard::load () 43bool OContactAccessBackend_VCard::load ()
38{ 44{
39 m_map.clear(); 45 m_map.clear();
40 m_dirty = false; 46 m_dirty = false;
41 47
42 VObject* obj = 0l; 48 VObject* obj = 0l;
43 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 49 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
44 if ( !obj ) 50 if ( !obj )
45 return false; 51 return false;
46 52
47 while ( obj ) { 53 while ( obj ) {
48 OContact con = parseVObject( obj ); 54 OContact con = parseVObject( obj );
49 /* 55 /*
50 * if uid is 0 assign a new one 56 * if uid is 0 assign a new one
51 * this at least happens on 57 * this at least happens on
52 * Nokia6210 58 * Nokia6210
53 */ 59 */
54 if ( con.uid() == 0 ){ 60 if ( con.uid() == 0 ){
55 con.setUid( 1 ); 61 con.setUid( 1 );
56 qWarning("assigned new uid %d",con.uid() ); 62 qWarning("assigned new uid %d",con.uid() );
57 } 63 }
58 64
59 m_map.insert( con.uid(), con ); 65 m_map.insert( con.uid(), con );
60 66
61 VObject *t = obj; 67 VObject *t = obj;
62 obj = nextVObjectInList(obj); 68 obj = nextVObjectInList(obj);
63 cleanVObject( t ); 69 cleanVObject( t );
64 } 70 }
65 71
66 return true; 72 return true;
67 73
68} 74}
69bool OContactAccessBackend_VCard::reload() 75bool OContactAccessBackend_VCard::reload()
70{ 76{
71 return load(); 77 return load();
72} 78}
73bool OContactAccessBackend_VCard::save() 79bool OContactAccessBackend_VCard::save()
74{ 80{
75 if (!m_dirty ) 81 if (!m_dirty )
76 return true; 82 return true;
77 83
78 QFileDirect file( m_file ); 84 QFileDirect file( m_file );
79 if (!file.open(IO_WriteOnly ) ) 85 if (!file.open(IO_WriteOnly ) )
80 return false; 86 return false;
81 87
82 VObject *obj; 88 VObject *obj;
83 obj = newVObject( VCCalProp ); 89 obj = newVObject( VCCalProp );
84 addPropValue( obj, VCVersionProp, "1.0" ); 90 addPropValue( obj, VCVersionProp, "1.0" );
85 91
86 VObject *vo; 92 VObject *vo;
87 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 93 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
88 vo = createVObject( *it ); 94 vo = createVObject( *it );
89 addVObjectProp( obj, vo ); 95 writeVObject( file.directHandle() , vo );
96 cleanVObject( vo );
90 } 97 }
91 writeVObject( file.directHandle() , obj );
92 cleanVObject( obj );
93
94 cleanStrTbl(); 98 cleanStrTbl();
95 99
96 m_dirty = false; 100 m_dirty = false;
97 return true; 101 return true;
98 102
99 103
100} 104}
101void OContactAccessBackend_VCard::clear () 105void OContactAccessBackend_VCard::clear ()
102{ 106{
103 m_map.clear(); 107 m_map.clear();
104 m_dirty = true; // ??? sure ? (se) 108 m_dirty = true; // ??? sure ? (se)
105} 109}
106 110
107bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) 111bool OContactAccessBackend_VCard::add ( const OContact& newcontact )
108{ 112{
109 m_map.insert( newcontact.uid(), newcontact ); 113 m_map.insert( newcontact.uid(), newcontact );
110 m_dirty = true; 114 m_dirty = true;
111 return true; 115 return true;
112} 116}
113 117
114bool OContactAccessBackend_VCard::remove ( int uid ) 118bool OContactAccessBackend_VCard::remove ( int uid )
115{ 119{
116 m_map.remove( uid ); 120 m_map.remove( uid );
117 m_dirty = true; 121 m_dirty = true;
118 return true; 122 return true;
119} 123}
120 124
121bool OContactAccessBackend_VCard::replace ( const OContact &contact ) 125bool OContactAccessBackend_VCard::replace ( const OContact &contact )
122{ 126{
123 m_map.replace( contact.uid(), contact ); 127 m_map.replace( contact.uid(), contact );
124 m_dirty = true; 128 m_dirty = true;
125 return true; 129 return true;
126} 130}
127 131
128OContact OContactAccessBackend_VCard::find ( int uid ) const 132OContact OContactAccessBackend_VCard::find ( int uid ) const
129{ 133{
130 return m_map[uid]; 134 return m_map[uid];
131} 135}
132 136
133QArray<int> OContactAccessBackend_VCard::allRecords() const 137QArray<int> OContactAccessBackend_VCard::allRecords() const
134{ 138{
135 QArray<int> ar( m_map.count() ); 139 QArray<int> ar( m_map.count() );
136 QMap<int, OContact>::ConstIterator it; 140 QMap<int, OContact>::ConstIterator it;
137 int i = 0; 141 int i = 0;
138 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 142 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
139 ar[i] = it.key(); 143 ar[i] = it.key();
140 i++; 144 i++;
141 } 145 }
142 return ar; 146 return ar;
143} 147}
144 148
145// Not implemented 149// Not implemented
146QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) 150QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int )
147{ 151{
148 QArray<int> ar(0); 152 QArray<int> ar(0);
149 return ar; 153 return ar;
150} 154}
151 155
152// Not implemented 156// Not implemented
153QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const 157QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
154{ 158{
155 QArray<int> ar(0); 159 QArray<int> ar(0);
156 return ar; 160 return ar;
157} 161}
158 162
159const uint OContactAccessBackend_VCard::querySettings() 163const uint OContactAccessBackend_VCard::querySettings()
160{ 164{
161 return 0; // No search possible 165 return 0; // No search possible
162} 166}
163 167
164bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const 168bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const
165{ 169{
166 return false; // No search possible, therefore all settings invalid ;) 170 return false; // No search possible, therefore all settings invalid ;)
167} 171}
168 172
173bool OContactAccessBackend_VCard::wasChangedExternally()
174{
175 return false; // Don't expect concurrent access
176}
169 177
170// *** Private stuff *** 178// *** Private stuff ***
171 179
172 180
173OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) 181OContact OContactAccessBackend_VCard::parseVObject( VObject *obj )
174{ 182{
175 OContact c; 183 OContact c;
176 184
177 VObjectIterator it; 185 VObjectIterator it;
178 initPropIterator( &it, obj ); 186 initPropIterator( &it, obj );
179 while( moreIteration( &it ) ) { 187 while( moreIteration( &it ) ) {
180 VObject *o = nextVObject( &it ); 188 VObject *o = nextVObject( &it );
181 QCString name = vObjectName( o ); 189 QCString name = vObjectName( o );
182 QCString value = vObjectStringZValue( o ); 190 QCString value = vObjectStringZValue( o );
183 if ( name == VCNameProp ) { 191 if ( name == VCNameProp ) {
184 VObjectIterator nit; 192 VObjectIterator nit;
185 initPropIterator( &nit, o ); 193 initPropIterator( &nit, o );
186 while( moreIteration( &nit ) ) { 194 while( moreIteration( &nit ) ) {
187 VObject *o = nextVObject( &nit ); 195 VObject *o = nextVObject( &nit );
188 QCString name = vObjectTypeInfo( o ); 196 QCString name = vObjectTypeInfo( o );
189 QString value = vObjectStringZValue( o ); 197 QString value = vObjectStringZValue( o );
190 if ( name == VCNamePrefixesProp ) 198 if ( name == VCNamePrefixesProp )
191 c.setTitle( value ); 199 c.setTitle( value );
192 else if ( name == VCNameSuffixesProp ) 200 else if ( name == VCNameSuffixesProp )
193 c.setSuffix( value ); 201 c.setSuffix( value );
194 else if ( name == VCFamilyNameProp ) 202 else if ( name == VCFamilyNameProp )
195 c.setLastName( value ); 203 c.setLastName( value );
196 else if ( name == VCGivenNameProp ) 204 else if ( name == VCGivenNameProp )
197 c.setFirstName( value ); 205 c.setFirstName( value );
198 else if ( name == VCAdditionalNamesProp ) 206 else if ( name == VCAdditionalNamesProp )
199 c.setMiddleName( value ); 207 c.setMiddleName( value );
200 } 208 }
201 } 209 }
202 else if ( name == VCAdrProp ) { 210 else if ( name == VCAdrProp ) {
203 bool work = TRUE; // default address is work address 211 bool work = TRUE; // default address is work address
204 QString street; 212 QString street;
205 QString city; 213 QString city;
206 QString region; 214 QString region;
207 QString postal; 215 QString postal;
208 QString country; 216 QString country;
209 217
210 VObjectIterator nit; 218 VObjectIterator nit;
211 initPropIterator( &nit, o ); 219 initPropIterator( &nit, o );
212 while( moreIteration( &nit ) ) { 220 while( moreIteration( &nit ) ) {
213 VObject *o = nextVObject( &nit ); 221 VObject *o = nextVObject( &nit );
214 QCString name = vObjectName( o ); 222 QCString name = vObjectName( o );
215 QString value = vObjectStringZValue( o ); 223 QString value = vObjectStringZValue( o );
216 if ( name == VCHomeProp ) 224 if ( name == VCHomeProp )
217 work = FALSE; 225 work = FALSE;
218 else if ( name == VCWorkProp ) 226 else if ( name == VCWorkProp )
219 work = TRUE; 227 work = TRUE;
220 else if ( name == VCStreetAddressProp ) 228 else if ( name == VCStreetAddressProp )
221 street = value; 229 street = value;
222 else if ( name == VCCityProp ) 230 else if ( name == VCCityProp )
223 city = value; 231 city = value;
224 else if ( name == VCRegionProp ) 232 else if ( name == VCRegionProp )
225 region = value; 233 region = value;
226 else if ( name == VCPostalCodeProp ) 234 else if ( name == VCPostalCodeProp )
227 postal = value; 235 postal = value;
228 else if ( name == VCCountryNameProp ) 236 else if ( name == VCCountryNameProp )
229 country = value; 237 country = value;
230 } 238 }
231 if ( work ) { 239 if ( work ) {
232 c.setBusinessStreet( street ); 240 c.setBusinessStreet( street );
233 c.setBusinessCity( city ); 241 c.setBusinessCity( city );
234 c.setBusinessCountry( country ); 242 c.setBusinessCountry( country );
235 c.setBusinessZip( postal ); 243 c.setBusinessZip( postal );
236 c.setBusinessState( region ); 244 c.setBusinessState( region );
237 } else { 245 } else {
238 c.setHomeStreet( street ); 246 c.setHomeStreet( street );
239 c.setHomeCity( city ); 247 c.setHomeCity( city );
240 c.setHomeCountry( country ); 248 c.setHomeCountry( country );
241 c.setHomeZip( postal ); 249 c.setHomeZip( postal );
242 c.setHomeState( region ); 250 c.setHomeState( region );
243 } 251 }
244 } 252 }
245 else if ( name == VCTelephoneProp ) { 253 else if ( name == VCTelephoneProp ) {
246 enum { 254 enum {
247 HOME = 0x01, 255 HOME = 0x01,
248 WORK = 0x02, 256 WORK = 0x02,
249 VOICE = 0x04, 257 VOICE = 0x04,
250 CELL = 0x08, 258 CELL = 0x08,
251 FAX = 0x10, 259 FAX = 0x10,
252 PAGER = 0x20, 260 PAGER = 0x20,
253 UNKNOWN = 0x80 261 UNKNOWN = 0x80
254 }; 262 };
255 int type = 0; 263 int type = 0;
256 264
257 VObjectIterator nit; 265 VObjectIterator nit;
258 initPropIterator( &nit, o ); 266 initPropIterator( &nit, o );
259 while( moreIteration( &nit ) ) { 267 while( moreIteration( &nit ) ) {
260 VObject *o = nextVObject( &nit ); 268 VObject *o = nextVObject( &nit );
261 QCString name = vObjectTypeInfo( o ); 269 QCString name = vObjectTypeInfo( o );
262 if ( name == VCHomeProp ) 270 if ( name == VCHomeProp )
263 type |= HOME; 271 type |= HOME;
264 else if ( name == VCWorkProp ) 272 else if ( name == VCWorkProp )
265 type |= WORK; 273 type |= WORK;
266 else if ( name == VCVoiceProp ) 274 else if ( name == VCVoiceProp )
267 type |= VOICE; 275 type |= VOICE;
268 else if ( name == VCCellularProp ) 276 else if ( name == VCCellularProp )
269 type |= CELL; 277 type |= CELL;
270 else if ( name == VCFaxProp ) 278 else if ( name == VCFaxProp )
271 type |= FAX; 279 type |= FAX;
272 else if ( name == VCPagerProp ) 280 else if ( name == VCPagerProp )
273 type |= PAGER; 281 type |= PAGER;
274 else if ( name == VCPreferredProp ) 282 else if ( name == VCPreferredProp )
275 ; 283 ;
276 else 284 else
277 type |= UNKNOWN; 285 type |= UNKNOWN;
278 } 286 }
279 if ( (type & UNKNOWN) != UNKNOWN ) { 287 if ( (type & UNKNOWN) != UNKNOWN ) {
280 if ( ( type & (HOME|WORK) ) == 0 ) // default 288 if ( ( type & (HOME|WORK) ) == 0 ) // default
281 type |= HOME; 289 type |= HOME;
282 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 290 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
283 type |= VOICE; 291 type |= VOICE;
284 292
285 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 293 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
286 c.setHomePhone( value ); 294 c.setHomePhone( value );
287 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 295 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
288 c.setHomeFax( value ); 296 c.setHomeFax( value );
289 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 297 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
290 c.setHomeMobile( value ); 298 c.setHomeMobile( value );
291 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 299 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
292 c.setBusinessPhone( value ); 300 c.setBusinessPhone( value );
293 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 301 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
294 c.setBusinessFax( value ); 302 c.setBusinessFax( value );
295 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 303 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
296 c.setBusinessMobile( value ); 304 c.setBusinessMobile( value );
diff --git a/libopie/pim/ocontactaccessbackend_vcard.h b/libopie/pim/ocontactaccessbackend_vcard.h
index c1422b0..177ec24 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.h
+++ b/libopie/pim/ocontactaccessbackend_vcard.h
@@ -1,65 +1,70 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#ifndef __OCONTACTACCESSBACKEND_VCARD_H_ 27#ifndef __OCONTACTACCESSBACKEND_VCARD_H_
24#define __OCONTACTACCESSBACKEND_VCARD_H_ 28#define __OCONTACTACCESSBACKEND_VCARD_H_
25 29
26#include <opie/ocontact.h> 30#include <opie/ocontact.h>
27 31
28#include "ocontactaccessbackend.h" 32#include "ocontactaccessbackend.h"
29 33
30class VObject; 34class VObject;
31 35
32class OContactAccessBackend_VCard : public OContactAccessBackend { 36class OContactAccessBackend_VCard : public OContactAccessBackend {
33 public: 37 public:
34 OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); 38 OContactAccessBackend_VCard ( QString appname, QString filename = 0l );
35 39
36 bool load (); 40 bool load ();
37 bool reload(); 41 bool reload();
38 bool save(); 42 bool save();
39 void clear (); 43 void clear ();
40 44
41 bool add ( const OContact& newcontact ); 45 bool add ( const OContact& newcontact );
42 bool remove ( int uid ); 46 bool remove ( int uid );
43 bool replace ( const OContact& contact ); 47 bool replace ( const OContact& contact );
44 48
45 OContact find ( int uid ) const; 49 OContact find ( int uid ) const;
46 QArray<int> allRecords() const; 50 QArray<int> allRecords() const;
47 QArray<int> queryByExample ( const OContact &query, int settings ); 51 QArray<int> queryByExample ( const OContact &query, int settings );
48 QArray<int> matchRegexp( const QRegExp &r ) const; 52 QArray<int> matchRegexp( const QRegExp &r ) const;
49 53
50 const uint querySettings(); 54 const uint querySettings();
51 bool hasQuerySettings (uint querySettings) const; 55 bool hasQuerySettings (uint querySettings) const;
56 bool wasChangedExternally();
52 57
53private: 58private:
54 OContact parseVObject( VObject* obj ); 59 OContact parseVObject( VObject* obj );
55 VObject* createVObject( const OContact& c ); 60 VObject* createVObject( const OContact& c );
56 QDate convVCardDateToDate( const QString& datestr ); 61 QDate convVCardDateToDate( const QString& datestr );
57 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); 62 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value );
58 VObject *safeAddProp( VObject* o, const char* prop); 63 VObject *safeAddProp( VObject* o, const char* prop);
59 64
60 bool m_dirty : 1; 65 bool m_dirty : 1;
61 QString m_file; 66 QString m_file;
62 QMap<int, OContact> m_map; 67 QMap<int, OContact> m_map;
63}; 68};
64 69
65#endif 70#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index 903c0b7..013f3af 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -1,296 +1,304 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#include "ocontactaccessbackend_vcard.h" 27#include "ocontactaccessbackend_vcard.h"
24#include "../../library/backend/vobject_p.h" 28#include "../../library/backend/vobject_p.h"
25#include "../../library/backend/qfiledirect_p.h" 29#include "../../library/backend/qfiledirect_p.h"
26 30
27#include <qpe/timeconversion.h> 31#include <qpe/timeconversion.h>
28 32
29#include <qfile.h> 33#include <qfile.h>
30 34
31OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ): 35OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ):
32 m_dirty( false ), 36 m_dirty( false ),
33 m_file( filename ) 37 m_file( filename )
34{} 38{
39 load();
40}
35 41
36 42
37bool OContactAccessBackend_VCard::load () 43bool OContactAccessBackend_VCard::load ()
38{ 44{
39 m_map.clear(); 45 m_map.clear();
40 m_dirty = false; 46 m_dirty = false;
41 47
42 VObject* obj = 0l; 48 VObject* obj = 0l;
43 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 49 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
44 if ( !obj ) 50 if ( !obj )
45 return false; 51 return false;
46 52
47 while ( obj ) { 53 while ( obj ) {
48 OContact con = parseVObject( obj ); 54 OContact con = parseVObject( obj );
49 /* 55 /*
50 * if uid is 0 assign a new one 56 * if uid is 0 assign a new one
51 * this at least happens on 57 * this at least happens on
52 * Nokia6210 58 * Nokia6210
53 */ 59 */
54 if ( con.uid() == 0 ){ 60 if ( con.uid() == 0 ){
55 con.setUid( 1 ); 61 con.setUid( 1 );
56 qWarning("assigned new uid %d",con.uid() ); 62 qWarning("assigned new uid %d",con.uid() );
57 } 63 }
58 64
59 m_map.insert( con.uid(), con ); 65 m_map.insert( con.uid(), con );
60 66
61 VObject *t = obj; 67 VObject *t = obj;
62 obj = nextVObjectInList(obj); 68 obj = nextVObjectInList(obj);
63 cleanVObject( t ); 69 cleanVObject( t );
64 } 70 }
65 71
66 return true; 72 return true;
67 73
68} 74}
69bool OContactAccessBackend_VCard::reload() 75bool OContactAccessBackend_VCard::reload()
70{ 76{
71 return load(); 77 return load();
72} 78}
73bool OContactAccessBackend_VCard::save() 79bool OContactAccessBackend_VCard::save()
74{ 80{
75 if (!m_dirty ) 81 if (!m_dirty )
76 return true; 82 return true;
77 83
78 QFileDirect file( m_file ); 84 QFileDirect file( m_file );
79 if (!file.open(IO_WriteOnly ) ) 85 if (!file.open(IO_WriteOnly ) )
80 return false; 86 return false;
81 87
82 VObject *obj; 88 VObject *obj;
83 obj = newVObject( VCCalProp ); 89 obj = newVObject( VCCalProp );
84 addPropValue( obj, VCVersionProp, "1.0" ); 90 addPropValue( obj, VCVersionProp, "1.0" );
85 91
86 VObject *vo; 92 VObject *vo;
87 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 93 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
88 vo = createVObject( *it ); 94 vo = createVObject( *it );
89 addVObjectProp( obj, vo ); 95 writeVObject( file.directHandle() , vo );
96 cleanVObject( vo );
90 } 97 }
91 writeVObject( file.directHandle() , obj );
92 cleanVObject( obj );
93
94 cleanStrTbl(); 98 cleanStrTbl();
95 99
96 m_dirty = false; 100 m_dirty = false;
97 return true; 101 return true;
98 102
99 103
100} 104}
101void OContactAccessBackend_VCard::clear () 105void OContactAccessBackend_VCard::clear ()
102{ 106{
103 m_map.clear(); 107 m_map.clear();
104 m_dirty = true; // ??? sure ? (se) 108 m_dirty = true; // ??? sure ? (se)
105} 109}
106 110
107bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) 111bool OContactAccessBackend_VCard::add ( const OContact& newcontact )
108{ 112{
109 m_map.insert( newcontact.uid(), newcontact ); 113 m_map.insert( newcontact.uid(), newcontact );
110 m_dirty = true; 114 m_dirty = true;
111 return true; 115 return true;
112} 116}
113 117
114bool OContactAccessBackend_VCard::remove ( int uid ) 118bool OContactAccessBackend_VCard::remove ( int uid )
115{ 119{
116 m_map.remove( uid ); 120 m_map.remove( uid );
117 m_dirty = true; 121 m_dirty = true;
118 return true; 122 return true;
119} 123}
120 124
121bool OContactAccessBackend_VCard::replace ( const OContact &contact ) 125bool OContactAccessBackend_VCard::replace ( const OContact &contact )
122{ 126{
123 m_map.replace( contact.uid(), contact ); 127 m_map.replace( contact.uid(), contact );
124 m_dirty = true; 128 m_dirty = true;
125 return true; 129 return true;
126} 130}
127 131
128OContact OContactAccessBackend_VCard::find ( int uid ) const 132OContact OContactAccessBackend_VCard::find ( int uid ) const
129{ 133{
130 return m_map[uid]; 134 return m_map[uid];
131} 135}
132 136
133QArray<int> OContactAccessBackend_VCard::allRecords() const 137QArray<int> OContactAccessBackend_VCard::allRecords() const
134{ 138{
135 QArray<int> ar( m_map.count() ); 139 QArray<int> ar( m_map.count() );
136 QMap<int, OContact>::ConstIterator it; 140 QMap<int, OContact>::ConstIterator it;
137 int i = 0; 141 int i = 0;
138 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 142 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
139 ar[i] = it.key(); 143 ar[i] = it.key();
140 i++; 144 i++;
141 } 145 }
142 return ar; 146 return ar;
143} 147}
144 148
145// Not implemented 149// Not implemented
146QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) 150QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int )
147{ 151{
148 QArray<int> ar(0); 152 QArray<int> ar(0);
149 return ar; 153 return ar;
150} 154}
151 155
152// Not implemented 156// Not implemented
153QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const 157QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
154{ 158{
155 QArray<int> ar(0); 159 QArray<int> ar(0);
156 return ar; 160 return ar;
157} 161}
158 162
159const uint OContactAccessBackend_VCard::querySettings() 163const uint OContactAccessBackend_VCard::querySettings()
160{ 164{
161 return 0; // No search possible 165 return 0; // No search possible
162} 166}
163 167
164bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const 168bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const
165{ 169{
166 return false; // No search possible, therefore all settings invalid ;) 170 return false; // No search possible, therefore all settings invalid ;)
167} 171}
168 172
173bool OContactAccessBackend_VCard::wasChangedExternally()
174{
175 return false; // Don't expect concurrent access
176}
169 177
170// *** Private stuff *** 178// *** Private stuff ***
171 179
172 180
173OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) 181OContact OContactAccessBackend_VCard::parseVObject( VObject *obj )
174{ 182{
175 OContact c; 183 OContact c;
176 184
177 VObjectIterator it; 185 VObjectIterator it;
178 initPropIterator( &it, obj ); 186 initPropIterator( &it, obj );
179 while( moreIteration( &it ) ) { 187 while( moreIteration( &it ) ) {
180 VObject *o = nextVObject( &it ); 188 VObject *o = nextVObject( &it );
181 QCString name = vObjectName( o ); 189 QCString name = vObjectName( o );
182 QCString value = vObjectStringZValue( o ); 190 QCString value = vObjectStringZValue( o );
183 if ( name == VCNameProp ) { 191 if ( name == VCNameProp ) {
184 VObjectIterator nit; 192 VObjectIterator nit;
185 initPropIterator( &nit, o ); 193 initPropIterator( &nit, o );
186 while( moreIteration( &nit ) ) { 194 while( moreIteration( &nit ) ) {
187 VObject *o = nextVObject( &nit ); 195 VObject *o = nextVObject( &nit );
188 QCString name = vObjectTypeInfo( o ); 196 QCString name = vObjectTypeInfo( o );
189 QString value = vObjectStringZValue( o ); 197 QString value = vObjectStringZValue( o );
190 if ( name == VCNamePrefixesProp ) 198 if ( name == VCNamePrefixesProp )
191 c.setTitle( value ); 199 c.setTitle( value );
192 else if ( name == VCNameSuffixesProp ) 200 else if ( name == VCNameSuffixesProp )
193 c.setSuffix( value ); 201 c.setSuffix( value );
194 else if ( name == VCFamilyNameProp ) 202 else if ( name == VCFamilyNameProp )
195 c.setLastName( value ); 203 c.setLastName( value );
196 else if ( name == VCGivenNameProp ) 204 else if ( name == VCGivenNameProp )
197 c.setFirstName( value ); 205 c.setFirstName( value );
198 else if ( name == VCAdditionalNamesProp ) 206 else if ( name == VCAdditionalNamesProp )
199 c.setMiddleName( value ); 207 c.setMiddleName( value );
200 } 208 }
201 } 209 }
202 else if ( name == VCAdrProp ) { 210 else if ( name == VCAdrProp ) {
203 bool work = TRUE; // default address is work address 211 bool work = TRUE; // default address is work address
204 QString street; 212 QString street;
205 QString city; 213 QString city;
206 QString region; 214 QString region;
207 QString postal; 215 QString postal;
208 QString country; 216 QString country;
209 217
210 VObjectIterator nit; 218 VObjectIterator nit;
211 initPropIterator( &nit, o ); 219 initPropIterator( &nit, o );
212 while( moreIteration( &nit ) ) { 220 while( moreIteration( &nit ) ) {
213 VObject *o = nextVObject( &nit ); 221 VObject *o = nextVObject( &nit );
214 QCString name = vObjectName( o ); 222 QCString name = vObjectName( o );
215 QString value = vObjectStringZValue( o ); 223 QString value = vObjectStringZValue( o );
216 if ( name == VCHomeProp ) 224 if ( name == VCHomeProp )
217 work = FALSE; 225 work = FALSE;
218 else if ( name == VCWorkProp ) 226 else if ( name == VCWorkProp )
219 work = TRUE; 227 work = TRUE;
220 else if ( name == VCStreetAddressProp ) 228 else if ( name == VCStreetAddressProp )
221 street = value; 229 street = value;
222 else if ( name == VCCityProp ) 230 else if ( name == VCCityProp )
223 city = value; 231 city = value;
224 else if ( name == VCRegionProp ) 232 else if ( name == VCRegionProp )
225 region = value; 233 region = value;
226 else if ( name == VCPostalCodeProp ) 234 else if ( name == VCPostalCodeProp )
227 postal = value; 235 postal = value;
228 else if ( name == VCCountryNameProp ) 236 else if ( name == VCCountryNameProp )
229 country = value; 237 country = value;
230 } 238 }
231 if ( work ) { 239 if ( work ) {
232 c.setBusinessStreet( street ); 240 c.setBusinessStreet( street );
233 c.setBusinessCity( city ); 241 c.setBusinessCity( city );
234 c.setBusinessCountry( country ); 242 c.setBusinessCountry( country );
235 c.setBusinessZip( postal ); 243 c.setBusinessZip( postal );
236 c.setBusinessState( region ); 244 c.setBusinessState( region );
237 } else { 245 } else {
238 c.setHomeStreet( street ); 246 c.setHomeStreet( street );
239 c.setHomeCity( city ); 247 c.setHomeCity( city );
240 c.setHomeCountry( country ); 248 c.setHomeCountry( country );
241 c.setHomeZip( postal ); 249 c.setHomeZip( postal );
242 c.setHomeState( region ); 250 c.setHomeState( region );
243 } 251 }
244 } 252 }
245 else if ( name == VCTelephoneProp ) { 253 else if ( name == VCTelephoneProp ) {
246 enum { 254 enum {
247 HOME = 0x01, 255 HOME = 0x01,
248 WORK = 0x02, 256 WORK = 0x02,
249 VOICE = 0x04, 257 VOICE = 0x04,
250 CELL = 0x08, 258 CELL = 0x08,
251 FAX = 0x10, 259 FAX = 0x10,
252 PAGER = 0x20, 260 PAGER = 0x20,
253 UNKNOWN = 0x80 261 UNKNOWN = 0x80
254 }; 262 };
255 int type = 0; 263 int type = 0;
256 264
257 VObjectIterator nit; 265 VObjectIterator nit;
258 initPropIterator( &nit, o ); 266 initPropIterator( &nit, o );
259 while( moreIteration( &nit ) ) { 267 while( moreIteration( &nit ) ) {
260 VObject *o = nextVObject( &nit ); 268 VObject *o = nextVObject( &nit );
261 QCString name = vObjectTypeInfo( o ); 269 QCString name = vObjectTypeInfo( o );
262 if ( name == VCHomeProp ) 270 if ( name == VCHomeProp )
263 type |= HOME; 271 type |= HOME;
264 else if ( name == VCWorkProp ) 272 else if ( name == VCWorkProp )
265 type |= WORK; 273 type |= WORK;
266 else if ( name == VCVoiceProp ) 274 else if ( name == VCVoiceProp )
267 type |= VOICE; 275 type |= VOICE;
268 else if ( name == VCCellularProp ) 276 else if ( name == VCCellularProp )
269 type |= CELL; 277 type |= CELL;
270 else if ( name == VCFaxProp ) 278 else if ( name == VCFaxProp )
271 type |= FAX; 279 type |= FAX;
272 else if ( name == VCPagerProp ) 280 else if ( name == VCPagerProp )
273 type |= PAGER; 281 type |= PAGER;
274 else if ( name == VCPreferredProp ) 282 else if ( name == VCPreferredProp )
275 ; 283 ;
276 else 284 else
277 type |= UNKNOWN; 285 type |= UNKNOWN;
278 } 286 }
279 if ( (type & UNKNOWN) != UNKNOWN ) { 287 if ( (type & UNKNOWN) != UNKNOWN ) {
280 if ( ( type & (HOME|WORK) ) == 0 ) // default 288 if ( ( type & (HOME|WORK) ) == 0 ) // default
281 type |= HOME; 289 type |= HOME;
282 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 290 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
283 type |= VOICE; 291 type |= VOICE;
284 292
285 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 293 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
286 c.setHomePhone( value ); 294 c.setHomePhone( value );
287 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 295 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
288 c.setHomeFax( value ); 296 c.setHomeFax( value );
289 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 297 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
290 c.setHomeMobile( value ); 298 c.setHomeMobile( value );
291 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 299 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
292 c.setBusinessPhone( value ); 300 c.setBusinessPhone( value );
293 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 301 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
294 c.setBusinessFax( value ); 302 c.setBusinessFax( value );
295 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 303 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
296 c.setBusinessMobile( value ); 304 c.setBusinessMobile( value );
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
index c1422b0..177ec24 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
@@ -1,65 +1,70 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#ifndef __OCONTACTACCESSBACKEND_VCARD_H_ 27#ifndef __OCONTACTACCESSBACKEND_VCARD_H_
24#define __OCONTACTACCESSBACKEND_VCARD_H_ 28#define __OCONTACTACCESSBACKEND_VCARD_H_
25 29
26#include <opie/ocontact.h> 30#include <opie/ocontact.h>
27 31
28#include "ocontactaccessbackend.h" 32#include "ocontactaccessbackend.h"
29 33
30class VObject; 34class VObject;
31 35
32class OContactAccessBackend_VCard : public OContactAccessBackend { 36class OContactAccessBackend_VCard : public OContactAccessBackend {
33 public: 37 public:
34 OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); 38 OContactAccessBackend_VCard ( QString appname, QString filename = 0l );
35 39
36 bool load (); 40 bool load ();
37 bool reload(); 41 bool reload();
38 bool save(); 42 bool save();
39 void clear (); 43 void clear ();
40 44
41 bool add ( const OContact& newcontact ); 45 bool add ( const OContact& newcontact );
42 bool remove ( int uid ); 46 bool remove ( int uid );
43 bool replace ( const OContact& contact ); 47 bool replace ( const OContact& contact );
44 48
45 OContact find ( int uid ) const; 49 OContact find ( int uid ) const;
46 QArray<int> allRecords() const; 50 QArray<int> allRecords() const;
47 QArray<int> queryByExample ( const OContact &query, int settings ); 51 QArray<int> queryByExample ( const OContact &query, int settings );
48 QArray<int> matchRegexp( const QRegExp &r ) const; 52 QArray<int> matchRegexp( const QRegExp &r ) const;
49 53
50 const uint querySettings(); 54 const uint querySettings();
51 bool hasQuerySettings (uint querySettings) const; 55 bool hasQuerySettings (uint querySettings) const;
56 bool wasChangedExternally();
52 57
53private: 58private:
54 OContact parseVObject( VObject* obj ); 59 OContact parseVObject( VObject* obj );
55 VObject* createVObject( const OContact& c ); 60 VObject* createVObject( const OContact& c );
56 QDate convVCardDateToDate( const QString& datestr ); 61 QDate convVCardDateToDate( const QString& datestr );
57 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); 62 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value );
58 VObject *safeAddProp( VObject* o, const char* prop); 63 VObject *safeAddProp( VObject* o, const char* prop);
59 64
60 bool m_dirty : 1; 65 bool m_dirty : 1;
61 QString m_file; 66 QString m_file;
62 QMap<int, OContact> m_map; 67 QMap<int, OContact> m_map;
63}; 68};
64 69
65#endif 70#endif