-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.cpp | 18 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.h | 5 |
2 files changed, 18 insertions, 5 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,232 +1,240 @@ | |||
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 | ||
31 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ): | 35 | OContactAccessBackend_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 | ||
37 | bool OContactAccessBackend_VCard::load () | 43 | bool 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 | } |
69 | bool OContactAccessBackend_VCard::reload() | 75 | bool OContactAccessBackend_VCard::reload() |
70 | { | 76 | { |
71 | return load(); | 77 | return load(); |
72 | } | 78 | } |
73 | bool OContactAccessBackend_VCard::save() | 79 | bool 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 | } |
101 | void OContactAccessBackend_VCard::clear () | 105 | void 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 | ||
107 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 111 | bool 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 | ||
114 | bool OContactAccessBackend_VCard::remove ( int uid ) | 118 | bool 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 | ||
121 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 125 | bool 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 | ||
128 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 132 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
129 | { | 133 | { |
130 | return m_map[uid]; | 134 | return m_map[uid]; |
131 | } | 135 | } |
132 | 136 | ||
133 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 137 | QArray<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 |
146 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) | 150 | QArray<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 |
153 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 157 | QArray<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 | ||
159 | const uint OContactAccessBackend_VCard::querySettings() | 163 | const uint OContactAccessBackend_VCard::querySettings() |
160 | { | 164 | { |
161 | return 0; // No search possible | 165 | return 0; // No search possible |
162 | } | 166 | } |
163 | 167 | ||
164 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 168 | bool 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 | ||
173 | bool 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 | ||
173 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 181 | OContact 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 ); |
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 | ||
30 | class VObject; | 34 | class VObject; |
31 | 35 | ||
32 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 36 | class 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 | ||
53 | private: | 58 | private: |
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 |