author | eilers <eilers> | 2004-06-27 17:20:04 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-06-27 17:20:04 (UTC) |
commit | e211aea3b9201920f442b36f6726d10c09b63154 (patch) (unidiff) | |
tree | a65a20ae610bf053c0ff4dd561759a3369784d39 | |
parent | b394de64efa36eb463148da1409c87e8537c0dd9 (diff) | |
download | opie-e211aea3b9201920f442b36f6726d10c09b63154.zip opie-e211aea3b9201920f442b36f6726d10c09b63154.tar.gz opie-e211aea3b9201920f442b36f6726d10c09b63154.tar.bz2 |
Fixing Bug #1328:
VCards: Real encoding in UTF-8. Now even chars > 0xff are supported.
SQL: Switching form latin1 encoding to UTF-8 encoding. We are now fully
Unicode compliant !
Sorry for all users already using the SQL interface for loosing their special
characters. There was no other way !
All other should export its SQL database to xml before updating and reimporting afterwards !
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 24 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 232 |
2 files changed, 235 insertions, 21 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index 69eddfe..b9a491e 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -1,238 +1,228 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. | 4 | =. |
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 | 30 | ||
31 | #include "osqlquery.h" | 31 | #include "osqlquery.h" |
32 | #include "osqlitedriver.h" | 32 | #include "osqlitedriver.h" |
33 | 33 | ||
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | 35 | ||
36 | #include <stdlib.h> | 36 | #include <stdlib.h> |
37 | #include <stdio.h> | 37 | #include <stdio.h> |
38 | 38 | ||
39 | // fromLocal8Bit() does not work as expected. Thus it | 39 | namespace Opie { |
40 | // is replaced by fromLatin1() (eilers) | 40 | namespace DB { |
41 | #define __BUGGY_LOCAL8BIT_ | ||
42 | |||
43 | namespace Opie { | ||
44 | namespace DB { | ||
45 | namespace Internal { | 41 | namespace Internal { |
46 | 42 | ||
47 | namespace { | 43 | namespace { |
48 | struct Query { | 44 | struct Query { |
49 | OSQLError::ValueList errors; | 45 | OSQLError::ValueList errors; |
50 | OSQLResultItem::ValueList items; | 46 | OSQLResultItem::ValueList items; |
51 | OSQLiteDriver *driver; | 47 | OSQLiteDriver *driver; |
52 | }; | 48 | }; |
53 | } | 49 | } |
54 | 50 | ||
55 | 51 | ||
56 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) | 52 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) |
57 | : OSQLDriver( lib ) | 53 | : OSQLDriver( lib ) |
58 | { | 54 | { |
59 | m_sqlite = 0l; | 55 | m_sqlite = 0l; |
60 | } | 56 | } |
61 | 57 | ||
62 | 58 | ||
63 | OSQLiteDriver::~OSQLiteDriver() { | 59 | OSQLiteDriver::~OSQLiteDriver() { |
64 | close(); | 60 | close(); |
65 | } | 61 | } |
66 | 62 | ||
67 | 63 | ||
68 | QString OSQLiteDriver::id()const { | 64 | QString OSQLiteDriver::id()const { |
69 | return QString::fromLatin1("SQLite"); | 65 | return QString::fromLatin1("SQLite"); |
70 | } | 66 | } |
71 | 67 | ||
72 | void OSQLiteDriver::setUserName( const QString& ) {} | 68 | void OSQLiteDriver::setUserName( const QString& ) {} |
73 | 69 | ||
74 | 70 | ||
75 | void OSQLiteDriver::setPassword( const QString& ) {} | 71 | void OSQLiteDriver::setPassword( const QString& ) {} |
76 | 72 | ||
77 | 73 | ||
78 | void OSQLiteDriver::setUrl( const QString& url ) { | 74 | void OSQLiteDriver::setUrl( const QString& url ) { |
79 | m_url = url; | 75 | m_url = url; |
80 | } | 76 | } |
81 | 77 | ||
82 | 78 | ||
83 | void OSQLiteDriver::setOptions( const QStringList& ) { | 79 | void OSQLiteDriver::setOptions( const QStringList& ) { |
84 | } | 80 | } |
85 | 81 | ||
86 | /* | 82 | /* |
87 | * Functions to patch a regex search into sqlite | 83 | * Functions to patch a regex search into sqlite |
88 | */ | 84 | */ |
89 | int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ | 85 | int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ |
90 | int res; | 86 | int res; |
91 | if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ | 87 | if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ |
92 | if (reg->regex_raw != NULL) { | 88 | if (reg->regex_raw != NULL) { |
93 | free(reg->regex_raw); | 89 | free(reg->regex_raw); |
94 | regfree(®->regex_c); | 90 | regfree(®->regex_c); |
95 | } | 91 | } |
96 | reg->regex_raw = (char *)malloc(strlen(zPattern)+1); | 92 | reg->regex_raw = (char *)malloc(strlen(zPattern)+1); |
97 | strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1); | 93 | strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1); |
98 | res = regcomp(®->regex_c, zPattern, REG_EXTENDED); | 94 | res = regcomp(®->regex_c, zPattern, REG_EXTENDED); |
99 | if ( res != 0 ) { | 95 | if ( res != 0 ) { |
100 | printf("Regcomp failed with code %u on string %s\n",res,zPattern); | 96 | printf("Regcomp failed with code %u on string %s\n",res,zPattern); |
101 | free(reg->regex_raw); | 97 | free(reg->regex_raw); |
102 | reg->regex_raw=NULL; | 98 | reg->regex_raw=NULL; |
103 | return 0; | 99 | return 0; |
104 | } | 100 | } |
105 | } | 101 | } |
106 | res = (regexec(®->regex_c, zString, 0, NULL, 0)==0); | 102 | res = (regexec(®->regex_c, zString, 0, NULL, 0)==0); |
107 | return res; | 103 | return res; |
108 | } | 104 | } |
109 | 105 | ||
110 | void rlikeFunc(sqlite_func *context, int arg, const char **argv){ | 106 | void rlikeFunc(sqlite_func *context, int arg, const char **argv){ |
111 | if( argv[0]==0 || argv[1]==0 ){ | 107 | if( argv[0]==0 || argv[1]==0 ){ |
112 | printf("One of arguments Null!!\n"); | 108 | printf("One of arguments Null!!\n"); |
113 | return; | 109 | return; |
114 | } | 110 | } |
115 | sqlite_set_result_int(context, | 111 | sqlite_set_result_int(context, |
116 | sqliteRlikeCompare((const char*)argv[0], | 112 | sqliteRlikeCompare((const char*)argv[0], |
117 | (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); | 113 | (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); |
118 | } | 114 | } |
119 | 115 | ||
120 | /* | 116 | /* |
121 | * try to open a db specified via setUrl | 117 | * try to open a db specified via setUrl |
122 | * and options | 118 | * and options |
123 | */ | 119 | */ |
124 | bool OSQLiteDriver::open() { | 120 | bool OSQLiteDriver::open() { |
125 | char *error; | 121 | char *error; |
126 | 122 | ||
127 | odebug << "OSQLiteDriver::open: about to open" << oendl; | 123 | odebug << "OSQLiteDriver::open: about to open" << oendl; |
128 | m_sqlite = sqlite_open(m_url.local8Bit(), | 124 | m_sqlite = sqlite_open(m_url.local8Bit(), |
129 | 0, | 125 | 0, |
130 | &error ); | 126 | &error ); |
131 | 127 | ||
132 | /* failed to open */ | 128 | /* failed to open */ |
133 | if (m_sqlite == 0l ) { | 129 | if (m_sqlite == 0l ) { |
134 | // FIXME set the last error | 130 | // FIXME set the last error |
135 | owarn << "OSQLiteDriver::open: " << error << "" << oendl; | 131 | owarn << "OSQLiteDriver::open: " << error << "" << oendl; |
136 | free( error ); | 132 | free( error ); |
137 | return false; | 133 | return false; |
138 | } | 134 | } |
139 | if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) | 135 | if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) |
140 | odebug << "Unable to create user defined function!" << oendl; | 136 | odebug << "Unable to create user defined function!" << oendl; |
141 | if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) | 137 | if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) |
142 | odebug << "Unable to set rlike function result type!" << oendl; | 138 | odebug << "Unable to set rlike function result type!" << oendl; |
143 | sqreg.regex_raw = NULL; | 139 | sqreg.regex_raw = NULL; |
144 | return true; | 140 | return true; |
145 | } | 141 | } |
146 | 142 | ||
147 | 143 | ||
148 | /* close the db | 144 | /* close the db |
149 | * sqlite closes them without | 145 | * sqlite closes them without |
150 | * telling failure or success | 146 | * telling failure or success |
151 | */ | 147 | */ |
152 | bool OSQLiteDriver::close() { | 148 | bool OSQLiteDriver::close() { |
153 | if (m_sqlite ) | 149 | if (m_sqlite ) |
154 | sqlite_close( m_sqlite ), m_sqlite=0l; | 150 | sqlite_close( m_sqlite ), m_sqlite=0l; |
155 | if (sqreg.regex_raw != NULL){ | 151 | if (sqreg.regex_raw != NULL){ |
156 | odebug << "Freeing regex on close" << oendl; | 152 | odebug << "Freeing regex on close" << oendl; |
157 | free(sqreg.regex_raw); | 153 | free(sqreg.regex_raw); |
158 | sqreg.regex_raw=NULL; | 154 | sqreg.regex_raw=NULL; |
159 | regfree(&sqreg.regex_c); | 155 | regfree(&sqreg.regex_c); |
160 | } | 156 | } |
161 | return true; | 157 | return true; |
162 | } | 158 | } |
163 | 159 | ||
164 | 160 | ||
165 | /* Query */ | 161 | /* Query */ |
166 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 162 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
167 | if ( !m_sqlite ) { | 163 | if ( !m_sqlite ) { |
168 | // FIXME set error code | 164 | // FIXME set error code |
169 | OSQLResult result( OSQLResult::Failure ); | 165 | OSQLResult result( OSQLResult::Failure ); |
170 | return result; | 166 | return result; |
171 | } | 167 | } |
172 | Query query; | 168 | Query query; |
173 | query.driver = this; | 169 | query.driver = this; |
174 | char *err; | 170 | char *err; |
175 | /* SQLITE_OK 0 if return code > 0 == failure */ | 171 | /* SQLITE_OK 0 if return code > 0 == failure */ |
176 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { | 172 | if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { |
177 | owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; | 173 | qWarning("OSQLiteDriver::query: Error while executing %s",err); |
178 | free(err ); | 174 | free(err ); |
179 | // FixMe Errors | 175 | // FixMe Errors |
180 | } | 176 | } |
181 | 177 | ||
182 | OSQLResult result(OSQLResult::Success, | 178 | OSQLResult result(OSQLResult::Success, |
183 | query.items, | 179 | query.items, |
184 | query.errors ); | 180 | query.errors ); |
185 | return result; | 181 | return result; |
186 | } | 182 | } |
187 | 183 | ||
188 | 184 | ||
189 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 185 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
190 | 186 | ||
191 | } | 187 | } |
192 | 188 | ||
193 | 189 | ||
194 | OSQLError OSQLiteDriver::lastError() { | 190 | OSQLError OSQLiteDriver::lastError() { |
195 | OSQLError error; | 191 | OSQLError error; |
196 | return error; | 192 | return error; |
197 | }; | 193 | }; |
198 | 194 | ||
199 | 195 | ||
200 | /* handle a callback add the row to the global | 196 | /* handle a callback add the row to the global |
201 | * OSQLResultItem | 197 | * OSQLResultItem |
202 | */ | 198 | */ |
203 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 199 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
204 | return 0; | 200 | return 0; |
205 | } | 201 | } |
206 | 202 | ||
207 | 203 | ||
208 | /* callback_handler add the values to the list*/ | 204 | /* callback_handler add the values to the list*/ |
209 | int OSQLiteDriver::call_back( void* voi, int argc, | 205 | int OSQLiteDriver::call_back( void* voi, int argc, |
210 | char** argv, char** columns) { | 206 | char** argv, char** columns) { |
211 | Query* qu = (Query*)voi; | 207 | Query* qu = (Query*)voi; |
212 | 208 | ||
213 | //copy them over to a OSQLResultItem | 209 | //copy them over to a OSQLResultItem |
214 | QMap<QString, QString> tableString; | 210 | QMap<QString, QString> tableString; |
215 | QMap<int, QString> tableInt; | 211 | QMap<int, QString> tableInt; |
216 | for (int i = 0; i < argc; i++ ) { | 212 | for (int i = 0; i < argc; i++ ) { |
217 | 213 | ||
218 | #ifdef __BUGGY_LOCAL8BIT_ | 214 | tableInt.insert( i, QString::fromUtf8( argv[i] ) ); |
219 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); | 215 | tableString.insert( QString::fromUtf8( columns[i] ), |
220 | tableString.insert( QString::fromLatin1( columns[i] ), | 216 | QString::fromUtf8( argv[i] ) ); |
221 | QString::fromLatin1( argv[i] ) ); | ||
222 | #else | ||
223 | tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); | ||
224 | tableString.insert( QString::fromLocal8Bit( columns[i] ), | ||
225 | QString::fromLocal8Bit( argv[i] ) ); | ||
226 | #endif | ||
227 | } | 217 | } |
228 | OSQLResultItem item( tableString, tableInt ); | 218 | OSQLResultItem item( tableString, tableInt ); |
229 | qu->items.append( item ); | 219 | qu->items.append( item ); |
230 | 220 | ||
231 | return ((Query*)voi)->driver->handleCallBack( argc, | 221 | return ((Query*)voi)->driver->handleCallBack( argc, |
232 | argv, | 222 | argv, |
233 | columns ); | 223 | columns ); |
234 | 224 | ||
235 | 225 | ||
236 | } | 226 | } |
237 | 227 | ||
238 | }}} // namespace OPIE::DB::Internal | 228 | }}} // namespace OPIE::DB::Internal |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index b6ea461..caf3c6e 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -117,192 +117,401 @@ bool OPimContactAccessBackend_VCard::save() | |||
117 | } | 117 | } |
118 | cleanStrTbl(); | 118 | cleanStrTbl(); |
119 | deleteVObject( obj ); | 119 | deleteVObject( obj ); |
120 | 120 | ||
121 | m_dirty = false; | 121 | m_dirty = false; |
122 | return true; | 122 | return true; |
123 | 123 | ||
124 | 124 | ||
125 | } | 125 | } |
126 | void OPimContactAccessBackend_VCard::clear () | 126 | void OPimContactAccessBackend_VCard::clear () |
127 | { | 127 | { |
128 | m_map.clear(); | 128 | m_map.clear(); |
129 | m_dirty = true; // ??? sure ? (se) | 129 | m_dirty = true; // ??? sure ? (se) |
130 | } | 130 | } |
131 | 131 | ||
132 | bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact ) | 132 | bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact ) |
133 | { | 133 | { |
134 | m_map.insert( newcontact.uid(), newcontact ); | 134 | m_map.insert( newcontact.uid(), newcontact ); |
135 | m_dirty = true; | 135 | m_dirty = true; |
136 | return true; | 136 | return true; |
137 | } | 137 | } |
138 | 138 | ||
139 | bool OPimContactAccessBackend_VCard::remove ( int uid ) | 139 | bool OPimContactAccessBackend_VCard::remove ( int uid ) |
140 | { | 140 | { |
141 | m_map.remove( uid ); | 141 | m_map.remove( uid ); |
142 | m_dirty = true; | 142 | m_dirty = true; |
143 | return true; | 143 | return true; |
144 | } | 144 | } |
145 | 145 | ||
146 | bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact ) | 146 | bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact ) |
147 | { | 147 | { |
148 | m_map.replace( contact.uid(), contact ); | 148 | m_map.replace( contact.uid(), contact ); |
149 | m_dirty = true; | 149 | m_dirty = true; |
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const | 153 | OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const |
154 | { | 154 | { |
155 | return m_map[uid]; | 155 | return m_map[uid]; |
156 | } | 156 | } |
157 | 157 | ||
158 | QArray<int> OPimContactAccessBackend_VCard::allRecords() const | 158 | QArray<int> OPimContactAccessBackend_VCard::allRecords() const |
159 | { | 159 | { |
160 | QArray<int> ar( m_map.count() ); | 160 | QArray<int> ar( m_map.count() ); |
161 | QMap<int, OPimContact>::ConstIterator it; | 161 | QMap<int, OPimContact>::ConstIterator it; |
162 | int i = 0; | 162 | int i = 0; |
163 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 163 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
164 | ar[i] = it.key(); | 164 | ar[i] = it.key(); |
165 | i++; | 165 | i++; |
166 | } | 166 | } |
167 | return ar; | 167 | return ar; |
168 | } | 168 | } |
169 | 169 | ||
170 | // Not implemented | 170 | // Not implemented |
171 | QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& ) | 171 | QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& ) |
172 | { | 172 | { |
173 | QArray<int> ar(0); | 173 | QArray<int> ar(0); |
174 | return ar; | 174 | return ar; |
175 | } | 175 | } |
176 | 176 | ||
177 | // Not implemented | 177 | // Not implemented |
178 | QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 178 | QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
179 | { | 179 | { |
180 | QArray<int> ar(0); | 180 | QArray<int> ar(0); |
181 | return ar; | 181 | return ar; |
182 | } | 182 | } |
183 | 183 | ||
184 | const uint OPimContactAccessBackend_VCard::querySettings() | 184 | const uint OPimContactAccessBackend_VCard::querySettings() |
185 | { | 185 | { |
186 | return 0; // No search possible | 186 | return 0; // No search possible |
187 | } | 187 | } |
188 | 188 | ||
189 | bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const | 189 | bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const |
190 | { | 190 | { |
191 | return false; // No search possible, therefore all settings invalid ;) | 191 | return false; // No search possible, therefore all settings invalid ;) |
192 | } | 192 | } |
193 | 193 | ||
194 | bool OPimContactAccessBackend_VCard::wasChangedExternally() | 194 | bool OPimContactAccessBackend_VCard::wasChangedExternally() |
195 | { | 195 | { |
196 | return false; // Don't expect concurrent access | 196 | return false; // Don't expect concurrent access |
197 | } | 197 | } |
198 | 198 | ||
199 | // Not implemented | 199 | // Not implemented |
200 | QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int ) | 200 | QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int ) |
201 | { | 201 | { |
202 | QArray<int> ar(0); | 202 | QArray<int> ar(0); |
203 | return ar; | 203 | return ar; |
204 | } | 204 | } |
205 | 205 | ||
206 | // *** Private stuff *** | 206 | // *** Private stuff *** |
207 | 207 | ||
208 | 208 | ||
209 | OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) | 209 | OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) |
210 | { | 210 | { |
211 | OPimContact c; | 211 | OPimContact c; |
212 | 212 | ||
213 | <<<<<<< ocontactaccessbackend_vcard.cpp | ||
214 | VObjectIterator it; | ||
215 | initPropIterator( &it, obj ); | ||
216 | while( moreIteration( &it ) ) { | ||
217 | VObject *o = nextVObject( &it ); | ||
218 | QCString name = vObjectName( o ); | ||
219 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | ||
220 | qDebug( "(1)Read: %s", QString( value ).latin1() ); | ||
221 | if ( name == VCNameProp ) { | ||
222 | VObjectIterator nit; | ||
223 | initPropIterator( &nit, o ); | ||
224 | while( moreIteration( &nit ) ) { | ||
225 | VObject *o = nextVObject( &nit ); | ||
226 | QCString name = vObjectTypeInfo( o ); | ||
227 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | ||
228 | qDebug( "(2)Read: %s", value.latin1() ); | ||
229 | if ( name == VCNamePrefixesProp ) | ||
230 | c.setTitle( value ); | ||
231 | else if ( name == VCNameSuffixesProp ) | ||
232 | c.setSuffix( value ); | ||
233 | else if ( name == VCFamilyNameProp ) | ||
234 | c.setLastName( value ); | ||
235 | else if ( name == VCGivenNameProp ) | ||
236 | c.setFirstName( value ); | ||
237 | else if ( name == VCAdditionalNamesProp ) | ||
238 | c.setMiddleName( value ); | ||
239 | } | ||
240 | } | ||
241 | else if ( name == VCAdrProp ) { | ||
242 | bool work = TRUE; // default address is work address | ||
243 | QString street; | ||
244 | QString city; | ||
245 | QString region; | ||
246 | QString postal; | ||
247 | QString country; | ||
248 | |||
249 | VObjectIterator nit; | ||
250 | initPropIterator( &nit, o ); | ||
251 | while( moreIteration( &nit ) ) { | ||
252 | VObject *o = nextVObject( &nit ); | ||
253 | QCString name = vObjectName( o ); | ||
254 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | ||
255 | if ( name == VCHomeProp ) | ||
256 | work = FALSE; | ||
257 | else if ( name == VCWorkProp ) | ||
258 | work = TRUE; | ||
259 | else if ( name == VCStreetAddressProp ) | ||
260 | street = value; | ||
261 | else if ( name == VCCityProp ) | ||
262 | city = value; | ||
263 | else if ( name == VCRegionProp ) | ||
264 | region = value; | ||
265 | else if ( name == VCPostalCodeProp ) | ||
266 | postal = value; | ||
267 | else if ( name == VCCountryNameProp ) | ||
268 | country = value; | ||
269 | } | ||
270 | if ( work ) { | ||
271 | c.setBusinessStreet( street ); | ||
272 | c.setBusinessCity( city ); | ||
273 | c.setBusinessCountry( country ); | ||
274 | c.setBusinessZip( postal ); | ||
275 | c.setBusinessState( region ); | ||
276 | } else { | ||
277 | c.setHomeStreet( street ); | ||
278 | c.setHomeCity( city ); | ||
279 | c.setHomeCountry( country ); | ||
280 | c.setHomeZip( postal ); | ||
281 | c.setHomeState( region ); | ||
282 | } | ||
283 | } | ||
284 | else if ( name == VCTelephoneProp ) { | ||
285 | enum { | ||
286 | HOME = 0x01, | ||
287 | WORK = 0x02, | ||
288 | VOICE = 0x04, | ||
289 | CELL = 0x08, | ||
290 | FAX = 0x10, | ||
291 | PAGER = 0x20, | ||
292 | UNKNOWN = 0x80 | ||
293 | }; | ||
294 | int type = 0; | ||
295 | |||
296 | VObjectIterator nit; | ||
297 | initPropIterator( &nit, o ); | ||
298 | while( moreIteration( &nit ) ) { | ||
299 | VObject *o = nextVObject( &nit ); | ||
300 | QCString name = vObjectTypeInfo( o ); | ||
301 | if ( name == VCHomeProp ) | ||
302 | type |= HOME; | ||
303 | else if ( name == VCWorkProp ) | ||
304 | type |= WORK; | ||
305 | else if ( name == VCVoiceProp ) | ||
306 | type |= VOICE; | ||
307 | else if ( name == VCCellularProp ) | ||
308 | type |= CELL; | ||
309 | else if ( name == VCFaxProp ) | ||
310 | type |= FAX; | ||
311 | else if ( name == VCPagerProp ) | ||
312 | type |= PAGER; | ||
313 | else if ( name == VCPreferredProp ) | ||
314 | ; | ||
315 | else | ||
316 | type |= UNKNOWN; | ||
317 | } | ||
318 | if ( (type & UNKNOWN) != UNKNOWN ) { | ||
319 | if ( ( type & (HOME|WORK) ) == 0 ) // default | ||
320 | type |= HOME; | ||
321 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default | ||
322 | type |= VOICE; | ||
323 | |||
324 | qWarning("value %s %d", value.data(), type ); | ||
325 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) | ||
326 | c.setHomePhone( value ); | ||
327 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | ||
328 | c.setHomeFax( value ); | ||
329 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | ||
330 | c.setHomeMobile( value ); | ||
331 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) | ||
332 | c.setBusinessPhone( value ); | ||
333 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) | ||
334 | c.setBusinessFax( value ); | ||
335 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) | ||
336 | c.setBusinessMobile( value ); | ||
337 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | ||
338 | c.setBusinessPager( value ); | ||
339 | } | ||
340 | } | ||
341 | else if ( name == VCEmailAddressProp ) { | ||
342 | QString email = QString::fromUtf8( vObjectStringZValue( o ) ); | ||
343 | bool valid = TRUE; | ||
344 | VObjectIterator nit; | ||
345 | initPropIterator( &nit, o ); | ||
346 | while( moreIteration( &nit ) ) { | ||
347 | VObject *o = nextVObject( &nit ); | ||
348 | QCString name = vObjectTypeInfo( o ); | ||
349 | if ( name != VCInternetProp && name != VCHomeProp && | ||
350 | name != VCWorkProp && | ||
351 | name != VCPreferredProp ) | ||
352 | // ### preffered should map to default email | ||
353 | valid = FALSE; | ||
354 | } | ||
355 | if ( valid ) { | ||
356 | c.insertEmail( email ); | ||
357 | } | ||
358 | } | ||
359 | else if ( name == VCURLProp ) { | ||
360 | VObjectIterator nit; | ||
361 | initPropIterator( &nit, o ); | ||
362 | while( moreIteration( &nit ) ) { | ||
363 | VObject *o = nextVObject( &nit ); | ||
364 | QCString name = vObjectTypeInfo( o ); | ||
365 | if ( name == VCHomeProp ) | ||
366 | c.setHomeWebpage( value ); | ||
367 | else if ( name == VCWorkProp ) | ||
368 | c.setBusinessWebpage( value ); | ||
369 | } | ||
370 | } | ||
371 | else if ( name == VCOrgProp ) { | ||
372 | VObjectIterator nit; | ||
373 | initPropIterator( &nit, o ); | ||
374 | while( moreIteration( &nit ) ) { | ||
375 | VObject *o = nextVObject( &nit ); | ||
376 | QCString name = vObjectName( o ); | ||
377 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | ||
378 | if ( name == VCOrgNameProp ) | ||
379 | c.setCompany( value ); | ||
380 | else if ( name == VCOrgUnitProp ) | ||
381 | c.setDepartment( value ); | ||
382 | else if ( name == VCOrgUnit2Prop ) | ||
383 | c.setOffice( value ); | ||
384 | } | ||
385 | } | ||
386 | else if ( name == VCTitleProp ) { | ||
387 | c.setJobTitle( value ); | ||
388 | } | ||
389 | else if ( name == "X-Qtopia-Profession" ) { | ||
390 | c.setProfession( value ); | ||
391 | } | ||
392 | else if ( name == "X-Qtopia-Manager" ) { | ||
393 | c.setManager( value ); | ||
394 | } | ||
395 | else if ( name == "X-Qtopia-Assistant" ) { | ||
396 | c.setAssistant( value ); | ||
397 | } | ||
398 | else if ( name == "X-Qtopia-Spouse" ) { | ||
399 | c.setSpouse( value ); | ||
400 | } | ||
401 | else if ( name == "X-Qtopia-Gender" ) { | ||
402 | c.setGender( value ); | ||
403 | } | ||
404 | else if ( name == "X-Qtopia-Anniversary" ) { | ||
405 | c.setAnniversary( convVCardDateToDate( value ) ); | ||
406 | } | ||
407 | else if ( name == "X-Qtopia-Nickname" ) { | ||
408 | c.setNickname( value ); | ||
409 | } | ||
410 | else if ( name == "X-Qtopia-Children" ) { | ||
411 | c.setChildren( value ); | ||
412 | } | ||
413 | else if ( name == VCBirthDateProp ) { | ||
414 | // Reading Birthdate regarding RFC 2425 (5.8.4) | ||
415 | c.setBirthday( convVCardDateToDate( value ) ); | ||
416 | |||
417 | } | ||
418 | else if ( name == VCCommentProp ) { | ||
419 | c.setNotes( value ); | ||
420 | } | ||
421 | ======= | ||
213 | VObjectIterator it; | 422 | VObjectIterator it; |
214 | initPropIterator( &it, obj ); | 423 | initPropIterator( &it, obj ); |
215 | while( moreIteration( &it ) ) { | 424 | while( moreIteration( &it ) ) { |
216 | VObject *o = nextVObject( &it ); | 425 | VObject *o = nextVObject( &it ); |
217 | QCString name = vObjectName( o ); | 426 | QCString name = vObjectName( o ); |
218 | QCString value = vObjectStringZValue( o ); | 427 | QCString value = vObjectStringZValue( o ); |
219 | if ( name == VCNameProp ) { | 428 | if ( name == VCNameProp ) { |
220 | VObjectIterator nit; | 429 | VObjectIterator nit; |
221 | initPropIterator( &nit, o ); | 430 | initPropIterator( &nit, o ); |
222 | while( moreIteration( &nit ) ) { | 431 | while( moreIteration( &nit ) ) { |
223 | VObject *o = nextVObject( &nit ); | 432 | VObject *o = nextVObject( &nit ); |
224 | QCString name = vObjectTypeInfo( o ); | 433 | QCString name = vObjectTypeInfo( o ); |
225 | QString value = vObjectStringZValue( o ); | 434 | QString value = vObjectStringZValue( o ); |
226 | if ( name == VCNamePrefixesProp ) | 435 | if ( name == VCNamePrefixesProp ) |
227 | c.setTitle( value ); | 436 | c.setTitle( value ); |
228 | else if ( name == VCNameSuffixesProp ) | 437 | else if ( name == VCNameSuffixesProp ) |
229 | c.setSuffix( value ); | 438 | c.setSuffix( value ); |
230 | else if ( name == VCFamilyNameProp ) | 439 | else if ( name == VCFamilyNameProp ) |
231 | c.setLastName( value ); | 440 | c.setLastName( value ); |
232 | else if ( name == VCGivenNameProp ) | 441 | else if ( name == VCGivenNameProp ) |
233 | c.setFirstName( value ); | 442 | c.setFirstName( value ); |
234 | else if ( name == VCAdditionalNamesProp ) | 443 | else if ( name == VCAdditionalNamesProp ) |
235 | c.setMiddleName( value ); | 444 | c.setMiddleName( value ); |
236 | } | 445 | } |
237 | } | 446 | } |
238 | else if ( name == VCAdrProp ) { | 447 | else if ( name == VCAdrProp ) { |
239 | bool work = TRUE; // default address is work address | 448 | bool work = TRUE; // default address is work address |
240 | QString street; | 449 | QString street; |
241 | QString city; | 450 | QString city; |
242 | QString region; | 451 | QString region; |
243 | QString postal; | 452 | QString postal; |
244 | QString country; | 453 | QString country; |
245 | 454 | ||
246 | VObjectIterator nit; | 455 | VObjectIterator nit; |
247 | initPropIterator( &nit, o ); | 456 | initPropIterator( &nit, o ); |
248 | while( moreIteration( &nit ) ) { | 457 | while( moreIteration( &nit ) ) { |
249 | VObject *o = nextVObject( &nit ); | 458 | VObject *o = nextVObject( &nit ); |
250 | QCString name = vObjectName( o ); | 459 | QCString name = vObjectName( o ); |
251 | QString value = vObjectStringZValue( o ); | 460 | QString value = vObjectStringZValue( o ); |
252 | if ( name == VCHomeProp ) | 461 | if ( name == VCHomeProp ) |
253 | work = FALSE; | 462 | work = FALSE; |
254 | else if ( name == VCWorkProp ) | 463 | else if ( name == VCWorkProp ) |
255 | work = TRUE; | 464 | work = TRUE; |
256 | else if ( name == VCStreetAddressProp ) | 465 | else if ( name == VCStreetAddressProp ) |
257 | street = value; | 466 | street = value; |
258 | else if ( name == VCCityProp ) | 467 | else if ( name == VCCityProp ) |
259 | city = value; | 468 | city = value; |
260 | else if ( name == VCRegionProp ) | 469 | else if ( name == VCRegionProp ) |
261 | region = value; | 470 | region = value; |
262 | else if ( name == VCPostalCodeProp ) | 471 | else if ( name == VCPostalCodeProp ) |
263 | postal = value; | 472 | postal = value; |
264 | else if ( name == VCCountryNameProp ) | 473 | else if ( name == VCCountryNameProp ) |
265 | country = value; | 474 | country = value; |
266 | } | 475 | } |
267 | if ( work ) { | 476 | if ( work ) { |
268 | c.setBusinessStreet( street ); | 477 | c.setBusinessStreet( street ); |
269 | c.setBusinessCity( city ); | 478 | c.setBusinessCity( city ); |
270 | c.setBusinessCountry( country ); | 479 | c.setBusinessCountry( country ); |
271 | c.setBusinessZip( postal ); | 480 | c.setBusinessZip( postal ); |
272 | c.setBusinessState( region ); | 481 | c.setBusinessState( region ); |
273 | } else { | 482 | } else { |
274 | c.setHomeStreet( street ); | 483 | c.setHomeStreet( street ); |
275 | c.setHomeCity( city ); | 484 | c.setHomeCity( city ); |
276 | c.setHomeCountry( country ); | 485 | c.setHomeCountry( country ); |
277 | c.setHomeZip( postal ); | 486 | c.setHomeZip( postal ); |
278 | c.setHomeState( region ); | 487 | c.setHomeState( region ); |
279 | } | 488 | } |
280 | } | 489 | } |
281 | else if ( name == VCTelephoneProp ) { | 490 | else if ( name == VCTelephoneProp ) { |
282 | enum { | 491 | enum { |
283 | HOME = 0x01, | 492 | HOME = 0x01, |
284 | WORK = 0x02, | 493 | WORK = 0x02, |
285 | VOICE = 0x04, | 494 | VOICE = 0x04, |
286 | CELL = 0x08, | 495 | CELL = 0x08, |
287 | FAX = 0x10, | 496 | FAX = 0x10, |
288 | PAGER = 0x20, | 497 | PAGER = 0x20, |
289 | UNKNOWN = 0x80 | 498 | UNKNOWN = 0x80 |
290 | }; | 499 | }; |
291 | int type = 0; | 500 | int type = 0; |
292 | 501 | ||
293 | VObjectIterator nit; | 502 | VObjectIterator nit; |
294 | initPropIterator( &nit, o ); | 503 | initPropIterator( &nit, o ); |
295 | while( moreIteration( &nit ) ) { | 504 | while( moreIteration( &nit ) ) { |
296 | VObject *o = nextVObject( &nit ); | 505 | VObject *o = nextVObject( &nit ); |
297 | QCString name = vObjectTypeInfo( o ); | 506 | QCString name = vObjectTypeInfo( o ); |
298 | if ( name == VCHomeProp ) | 507 | if ( name == VCHomeProp ) |
299 | type |= HOME; | 508 | type |= HOME; |
300 | else if ( name == VCWorkProp ) | 509 | else if ( name == VCWorkProp ) |
301 | type |= WORK; | 510 | type |= WORK; |
302 | else if ( name == VCVoiceProp ) | 511 | else if ( name == VCVoiceProp ) |
303 | type |= VOICE; | 512 | type |= VOICE; |
304 | else if ( name == VCCellularProp ) | 513 | else if ( name == VCCellularProp ) |
305 | type |= CELL; | 514 | type |= CELL; |
306 | else if ( name == VCFaxProp ) | 515 | else if ( name == VCFaxProp ) |
307 | type |= FAX; | 516 | type |= FAX; |
308 | else if ( name == VCPagerProp ) | 517 | else if ( name == VCPagerProp ) |
@@ -322,277 +531,292 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
322 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) | 531 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) |
323 | c.setHomePhone( value ); | 532 | c.setHomePhone( value ); |
324 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | 533 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) |
325 | c.setHomeFax( value ); | 534 | c.setHomeFax( value ); |
326 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | 535 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) |
327 | c.setHomeMobile( value ); | 536 | c.setHomeMobile( value ); |
328 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) | 537 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) |
329 | c.setBusinessPhone( value ); | 538 | c.setBusinessPhone( value ); |
330 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) | 539 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) |
331 | c.setBusinessFax( value ); | 540 | c.setBusinessFax( value ); |
332 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) | 541 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) |
333 | c.setBusinessMobile( value ); | 542 | c.setBusinessMobile( value ); |
334 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | 543 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) |
335 | c.setBusinessPager( value ); | 544 | c.setBusinessPager( value ); |
336 | } | 545 | } |
337 | } | 546 | } |
338 | else if ( name == VCEmailAddressProp ) { | 547 | else if ( name == VCEmailAddressProp ) { |
339 | QString email = vObjectStringZValue( o ); | 548 | QString email = vObjectStringZValue( o ); |
340 | bool valid = TRUE; | 549 | bool valid = TRUE; |
341 | VObjectIterator nit; | 550 | VObjectIterator nit; |
342 | initPropIterator( &nit, o ); | 551 | initPropIterator( &nit, o ); |
343 | while( moreIteration( &nit ) ) { | 552 | while( moreIteration( &nit ) ) { |
344 | VObject *o = nextVObject( &nit ); | 553 | VObject *o = nextVObject( &nit ); |
345 | QCString name = vObjectTypeInfo( o ); | 554 | QCString name = vObjectTypeInfo( o ); |
346 | if ( name != VCInternetProp && name != VCHomeProp && | 555 | if ( name != VCInternetProp && name != VCHomeProp && |
347 | name != VCWorkProp && | 556 | name != VCWorkProp && |
348 | name != VCPreferredProp ) | 557 | name != VCPreferredProp ) |
349 | // ### preffered should map to default email | 558 | // ### preffered should map to default email |
350 | valid = FALSE; | 559 | valid = FALSE; |
351 | } | 560 | } |
352 | if ( valid ) { | 561 | if ( valid ) { |
353 | c.insertEmail( email ); | 562 | c.insertEmail( email ); |
354 | } | 563 | } |
355 | } | 564 | } |
356 | else if ( name == VCURLProp ) { | 565 | else if ( name == VCURLProp ) { |
357 | VObjectIterator nit; | 566 | VObjectIterator nit; |
358 | initPropIterator( &nit, o ); | 567 | initPropIterator( &nit, o ); |
359 | while( moreIteration( &nit ) ) { | 568 | while( moreIteration( &nit ) ) { |
360 | VObject *o = nextVObject( &nit ); | 569 | VObject *o = nextVObject( &nit ); |
361 | QCString name = vObjectTypeInfo( o ); | 570 | QCString name = vObjectTypeInfo( o ); |
362 | if ( name == VCHomeProp ) | 571 | if ( name == VCHomeProp ) |
363 | c.setHomeWebpage( value ); | 572 | c.setHomeWebpage( value ); |
364 | else if ( name == VCWorkProp ) | 573 | else if ( name == VCWorkProp ) |
365 | c.setBusinessWebpage( value ); | 574 | c.setBusinessWebpage( value ); |
366 | } | 575 | } |
367 | } | 576 | } |
368 | else if ( name == VCOrgProp ) { | 577 | else if ( name == VCOrgProp ) { |
369 | VObjectIterator nit; | 578 | VObjectIterator nit; |
370 | initPropIterator( &nit, o ); | 579 | initPropIterator( &nit, o ); |
371 | while( moreIteration( &nit ) ) { | 580 | while( moreIteration( &nit ) ) { |
372 | VObject *o = nextVObject( &nit ); | 581 | VObject *o = nextVObject( &nit ); |
373 | QCString name = vObjectName( o ); | 582 | QCString name = vObjectName( o ); |
374 | QString value = vObjectStringZValue( o ); | 583 | QString value = vObjectStringZValue( o ); |
375 | if ( name == VCOrgNameProp ) | 584 | if ( name == VCOrgNameProp ) |
376 | c.setCompany( value ); | 585 | c.setCompany( value ); |
377 | else if ( name == VCOrgUnitProp ) | 586 | else if ( name == VCOrgUnitProp ) |
378 | c.setDepartment( value ); | 587 | c.setDepartment( value ); |
379 | else if ( name == VCOrgUnit2Prop ) | 588 | else if ( name == VCOrgUnit2Prop ) |
380 | c.setOffice( value ); | 589 | c.setOffice( value ); |
381 | } | 590 | } |
382 | } | 591 | } |
383 | else if ( name == VCTitleProp ) { | 592 | else if ( name == VCTitleProp ) { |
384 | c.setJobTitle( value ); | 593 | c.setJobTitle( value ); |
385 | } | 594 | } |
386 | else if ( name == "X-Qtopia-Profession" ) { | 595 | else if ( name == "X-Qtopia-Profession" ) { |
387 | c.setProfession( value ); | 596 | c.setProfession( value ); |
388 | } | 597 | } |
389 | else if ( name == "X-Qtopia-Manager" ) { | 598 | else if ( name == "X-Qtopia-Manager" ) { |
390 | c.setManager( value ); | 599 | c.setManager( value ); |
391 | } | 600 | } |
392 | else if ( name == "X-Qtopia-Assistant" ) { | 601 | else if ( name == "X-Qtopia-Assistant" ) { |
393 | c.setAssistant( value ); | 602 | c.setAssistant( value ); |
394 | } | 603 | } |
395 | else if ( name == "X-Qtopia-Spouse" ) { | 604 | else if ( name == "X-Qtopia-Spouse" ) { |
396 | c.setSpouse( value ); | 605 | c.setSpouse( value ); |
397 | } | 606 | } |
398 | else if ( name == "X-Qtopia-Gender" ) { | 607 | else if ( name == "X-Qtopia-Gender" ) { |
399 | c.setGender( value ); | 608 | c.setGender( value ); |
400 | } | 609 | } |
401 | else if ( name == "X-Qtopia-Anniversary" ) { | 610 | else if ( name == "X-Qtopia-Anniversary" ) { |
402 | c.setAnniversary( convVCardDateToDate( value ) ); | 611 | c.setAnniversary( convVCardDateToDate( value ) ); |
403 | } | 612 | } |
404 | else if ( name == "X-Qtopia-Nickname" ) { | 613 | else if ( name == "X-Qtopia-Nickname" ) { |
405 | c.setNickname( value ); | 614 | c.setNickname( value ); |
406 | } | 615 | } |
407 | else if ( name == "X-Qtopia-Children" ) { | 616 | else if ( name == "X-Qtopia-Children" ) { |
408 | c.setChildren( value ); | 617 | c.setChildren( value ); |
409 | } | 618 | } |
410 | else if ( name == VCBirthDateProp ) { | 619 | else if ( name == VCBirthDateProp ) { |
411 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 620 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
412 | c.setBirthday( convVCardDateToDate( value ) ); | 621 | c.setBirthday( convVCardDateToDate( value ) ); |
413 | 622 | ||
414 | } | 623 | } |
415 | else if ( name == VCCommentProp ) { | 624 | else if ( name == VCCommentProp ) { |
416 | c.setNotes( value ); | 625 | c.setNotes( value ); |
417 | } | 626 | } |
627 | >>>>>>> 1.15 | ||
418 | #if 0 | 628 | #if 0 |
629 | <<<<<<< ocontactaccessbackend_vcard.cpp | ||
630 | else { | ||
631 | printf("Name: %s, value=%s\n", name.data(), QString::fromUtf8( vObjectStringZValue( o ) ) ); | ||
632 | VObjectIterator nit; | ||
633 | initPropIterator( &nit, o ); | ||
634 | while( moreIteration( &nit ) ) { | ||
635 | VObject *o = nextVObject( &nit ); | ||
636 | QCString name = vObjectName( o ); | ||
637 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | ||
638 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | ||
639 | } | ||
640 | } | ||
641 | ======= | ||
419 | else { | 642 | else { |
420 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 643 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
421 | VObjectIterator nit; | 644 | VObjectIterator nit; |
422 | initPropIterator( &nit, o ); | 645 | initPropIterator( &nit, o ); |
423 | while( moreIteration( &nit ) ) { | 646 | while( moreIteration( &nit ) ) { |
424 | VObject *o = nextVObject( &nit ); | 647 | VObject *o = nextVObject( &nit ); |
425 | QCString name = vObjectName( o ); | 648 | QCString name = vObjectName( o ); |
426 | QString value = vObjectStringZValue( o ); | 649 | QString value = vObjectStringZValue( o ); |
427 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 650 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
428 | } | 651 | } |
429 | } | 652 | } |
653 | >>>>>>> 1.15 | ||
430 | #endif | 654 | #endif |
431 | } | 655 | } |
432 | c.setFileAs(); | 656 | c.setFileAs(); |
433 | return c; | 657 | return c; |
434 | } | 658 | } |
435 | 659 | ||
436 | 660 | ||
437 | VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) | 661 | VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) |
438 | { | 662 | { |
439 | VObject *vcard = newVObject( VCCardProp ); | 663 | VObject *vcard = newVObject( VCCardProp ); |
440 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 664 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
441 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 665 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
442 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | 666 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); |
443 | 667 | ||
444 | // full name | 668 | // full name |
445 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | 669 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); |
446 | 670 | ||
447 | // name properties | 671 | // name properties |
448 | VObject *name = safeAddProp( vcard, VCNameProp ); | 672 | VObject *name = safeAddProp( vcard, VCNameProp ); |
449 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | 673 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); |
450 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); | 674 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); |
451 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); | 675 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); |
452 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); | 676 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); |
453 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); | 677 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); |
454 | 678 | ||
455 | // home properties | 679 | // home properties |
456 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); | 680 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); |
457 | safeAddProp( home_adr, VCHomeProp ); | 681 | safeAddProp( home_adr, VCHomeProp ); |
458 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); | 682 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); |
459 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); | 683 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); |
460 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); | 684 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); |
461 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); | 685 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); |
462 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); | 686 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); |
463 | 687 | ||
464 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); | 688 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); |
465 | safeAddProp( home_phone, VCHomeProp ); | 689 | safeAddProp( home_phone, VCHomeProp ); |
466 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); | 690 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); |
467 | safeAddProp( home_phone, VCHomeProp ); | 691 | safeAddProp( home_phone, VCHomeProp ); |
468 | safeAddProp( home_phone, VCCellularProp ); | 692 | safeAddProp( home_phone, VCCellularProp ); |
469 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); | 693 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); |
470 | safeAddProp( home_phone, VCHomeProp ); | 694 | safeAddProp( home_phone, VCHomeProp ); |
471 | safeAddProp( home_phone, VCFaxProp ); | 695 | safeAddProp( home_phone, VCFaxProp ); |
472 | 696 | ||
473 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); | 697 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); |
474 | safeAddProp( url, VCHomeProp ); | 698 | safeAddProp( url, VCHomeProp ); |
475 | 699 | ||
476 | // work properties | 700 | // work properties |
477 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); | 701 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); |
478 | safeAddProp( work_adr, VCWorkProp ); | 702 | safeAddProp( work_adr, VCWorkProp ); |
479 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); | 703 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); |
480 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); | 704 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); |
481 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); | 705 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); |
482 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); | 706 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); |
483 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | 707 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); |
484 | 708 | ||
485 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | 709 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); |
486 | safeAddProp( work_phone, VCWorkProp ); | 710 | safeAddProp( work_phone, VCWorkProp ); |
487 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | 711 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); |
488 | safeAddProp( work_phone, VCWorkProp ); | 712 | safeAddProp( work_phone, VCWorkProp ); |
489 | safeAddProp( work_phone, VCCellularProp ); | 713 | safeAddProp( work_phone, VCCellularProp ); |
490 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | 714 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); |
491 | safeAddProp( work_phone, VCWorkProp ); | 715 | safeAddProp( work_phone, VCWorkProp ); |
492 | safeAddProp( work_phone, VCFaxProp ); | 716 | safeAddProp( work_phone, VCFaxProp ); |
493 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | 717 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); |
494 | safeAddProp( work_phone, VCWorkProp ); | 718 | safeAddProp( work_phone, VCWorkProp ); |
495 | safeAddProp( work_phone, VCPagerProp ); | 719 | safeAddProp( work_phone, VCPagerProp ); |
496 | 720 | ||
497 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | 721 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); |
498 | safeAddProp( url, VCWorkProp ); | 722 | safeAddProp( url, VCWorkProp ); |
499 | 723 | ||
500 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | 724 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); |
501 | safeAddProp( title, VCWorkProp ); | 725 | safeAddProp( title, VCWorkProp ); |
502 | 726 | ||
503 | 727 | ||
504 | QStringList emails = c.emailList(); | 728 | QStringList emails = c.emailList(); |
505 | // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 | 729 | // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 |
506 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 730 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
507 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 731 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
508 | safeAddProp( email, VCInternetProp ); | 732 | safeAddProp( email, VCInternetProp ); |
509 | } | 733 | } |
510 | 734 | ||
511 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 735 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
512 | 736 | ||
513 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 737 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
514 | if ( c.birthday().isValid() ){ | 738 | if ( c.birthday().isValid() ){ |
515 | owarn << "Exporting birthday as: " << convDateToVCardDate( c.birthday() ) << "" << oendl; | 739 | owarn << "Exporting birthday as: " << convDateToVCardDate( c.birthday() ) << "" << oendl; |
516 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); | 740 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); |
517 | } | 741 | } |
518 | 742 | ||
519 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 743 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
520 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 744 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
521 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 745 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
522 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 746 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
523 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 747 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
524 | } | 748 | } |
525 | 749 | ||
526 | // some values we have to export as custom fields | 750 | // some values we have to export as custom fields |
527 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | 751 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); |
528 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | 752 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); |
529 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | 753 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); |
530 | 754 | ||
531 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | 755 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); |
532 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | 756 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); |
533 | if ( c.anniversary().isValid() ){ | 757 | if ( c.anniversary().isValid() ){ |
534 | owarn << "Exporting anniversary as: " << convDateToVCardDate( c.anniversary() ) << "" << oendl; | 758 | owarn << "Exporting anniversary as: " << convDateToVCardDate( c.anniversary() ) << "" << oendl; |
535 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); | 759 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); |
536 | } | 760 | } |
537 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | 761 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); |
538 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | 762 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); |
539 | 763 | ||
540 | return vcard; | 764 | return vcard; |
541 | } | 765 | } |
542 | 766 | ||
543 | QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | 767 | QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const |
544 | { | 768 | { |
545 | QString str_rfc2425 = QString("%1-%2-%3") | 769 | QString str_rfc2425 = QString("%1-%2-%3") |
546 | .arg( d.year() ) | 770 | .arg( d.year() ) |
547 | .arg( d.month(), 2 ) | 771 | .arg( d.month(), 2 ) |
548 | .arg( d.day(), 2 ); | 772 | .arg( d.day(), 2 ); |
549 | // Now replace spaces with "0"... | 773 | // Now replace spaces with "0"... |
550 | int pos = 0; | 774 | int pos = 0; |
551 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) | 775 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) |
552 | str_rfc2425.replace( pos, 1, "0" ); | 776 | str_rfc2425.replace( pos, 1, "0" ); |
553 | 777 | ||
554 | return str_rfc2425; | 778 | return str_rfc2425; |
555 | } | 779 | } |
556 | 780 | ||
557 | QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | 781 | QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) |
558 | { | 782 | { |
559 | int monthPos = datestr.find('-'); | 783 | int monthPos = datestr.find('-'); |
560 | int dayPos = datestr.find('-', monthPos+1 ); | 784 | int dayPos = datestr.find('-', monthPos+1 ); |
561 | int sep_ignore = 1; | 785 | int sep_ignore = 1; |
562 | if ( monthPos == -1 || dayPos == -1 ) { | 786 | if ( monthPos == -1 || dayPos == -1 ) { |
563 | odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; | 787 | odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; |
564 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) | 788 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) |
565 | if ( datestr.length() == 8 ){ | 789 | if ( datestr.length() == 8 ){ |
566 | monthPos = 4; | 790 | monthPos = 4; |
567 | dayPos = 6; | 791 | dayPos = 6; |
568 | sep_ignore = 0; | 792 | sep_ignore = 0; |
569 | odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; | 793 | odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; |
570 | } else { | 794 | } else { |
571 | return QDate(); | 795 | return QDate(); |
572 | } | 796 | } |
573 | } | 797 | } |
574 | int y = datestr.left( monthPos ).toInt(); | 798 | int y = datestr.left( monthPos ).toInt(); |
575 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); | 799 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); |
576 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); | 800 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); |
577 | odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; | 801 | odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; |
578 | QDate date ( y,m,d ); | 802 | QDate date ( y,m,d ); |
579 | return date; | 803 | return date; |
580 | } | 804 | } |
581 | 805 | ||
582 | VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 806 | VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
583 | { | 807 | { |
584 | VObject *ret = 0; | 808 | VObject *ret = 0; |
585 | if ( o && !value.isEmpty() ) | 809 | if ( o && !value.isEmpty() ) |
586 | ret = addPropValue( o, prop, value.latin1() ); | 810 | ret = addPropValue( o, prop, value.utf8() ); |
587 | return ret; | 811 | return ret; |
588 | } | 812 | } |
589 | 813 | ||
590 | VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) | 814 | VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) |
591 | { | 815 | { |
592 | VObject *ret = 0; | 816 | VObject *ret = 0; |
593 | if ( o ) | 817 | if ( o ) |
594 | ret = addProp( o, prop ); | 818 | ret = addProp( o, prop ); |
595 | return ret; | 819 | return ret; |
596 | } | 820 | } |
597 | 821 | ||
598 | } | 822 | } |