author | zautrix <zautrix> | 2004-10-14 09:28:50 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-14 09:28:50 (UTC) |
commit | 3d79ab275374292196c7d032ffd2e321841c8cb0 (patch) (unidiff) | |
tree | 6ceaba2a5f375cfebc88189000221fe456e6f9d2 /kabc | |
parent | 57bd80b04dddd40a897dce8b6902d1046d71c631 (diff) | |
download | kdepimpi-3d79ab275374292196c7d032ffd2e321841c8cb0.zip kdepimpi-3d79ab275374292196c7d032ffd2e321841c8cb0.tar.gz kdepimpi-3d79ab275374292196c7d032ffd2e321841c8cb0.tar.bz2 |
umlaute phone fixes
-rw-r--r-- | kabc/addressbook.cpp | 3 | ||||
-rw-r--r-- | kabc/addressbook.h | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 4 |
3 files changed, 5 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index c584c35..3641c0c 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,1210 +1,1211 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | /*US | 28 | /*US |
29 | 29 | ||
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qfile.h> | 42 | #include <qfile.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | 44 | ||
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | #include <klocale.h> | 46 | #include <klocale.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <kdebug.h> | 48 | #include <kdebug.h> |
49 | #include <libkcal/syncdefines.h> | 49 | #include <libkcal/syncdefines.h> |
50 | #include <libkdepim/phoneaccess.h> | 50 | #include <libkdepim/phoneaccess.h> |
51 | #include "addressbook.h" | 51 | #include "addressbook.h" |
52 | #include "resource.h" | 52 | #include "resource.h" |
53 | #include "vcardconverter.h" | 53 | #include "vcardconverter.h" |
54 | #include "vcardparser/vcardtool.h" | 54 | #include "vcardparser/vcardtool.h" |
55 | 55 | ||
56 | //US #include "addressbook.moc" | 56 | //US #include "addressbook.moc" |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | 59 | ||
60 | struct AddressBook::AddressBookData | 60 | struct AddressBook::AddressBookData |
61 | { | 61 | { |
62 | Addressee::List mAddressees; | 62 | Addressee::List mAddressees; |
63 | Addressee::List mRemovedAddressees; | 63 | Addressee::List mRemovedAddressees; |
64 | Field::List mAllFields; | 64 | Field::List mAllFields; |
65 | KConfig *mConfig; | 65 | KConfig *mConfig; |
66 | KRES::Manager<Resource> *mManager; | 66 | KRES::Manager<Resource> *mManager; |
67 | //US ErrorHandler *mErrorHandler; | 67 | //US ErrorHandler *mErrorHandler; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | struct AddressBook::Iterator::IteratorData | 70 | struct AddressBook::Iterator::IteratorData |
71 | { | 71 | { |
72 | Addressee::List::Iterator mIt; | 72 | Addressee::List::Iterator mIt; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | struct AddressBook::ConstIterator::ConstIteratorData | 75 | struct AddressBook::ConstIterator::ConstIteratorData |
76 | { | 76 | { |
77 | Addressee::List::ConstIterator mIt; | 77 | Addressee::List::ConstIterator mIt; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | AddressBook::Iterator::Iterator() | 80 | AddressBook::Iterator::Iterator() |
81 | { | 81 | { |
82 | d = new IteratorData; | 82 | d = new IteratorData; |
83 | } | 83 | } |
84 | 84 | ||
85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
86 | { | 86 | { |
87 | d = new IteratorData; | 87 | d = new IteratorData; |
88 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
89 | } | 89 | } |
90 | 90 | ||
91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
92 | { | 92 | { |
93 | if( this == &i ) return *this; // guard against self assignment | 93 | if( this == &i ) return *this; // guard against self assignment |
94 | delete d; // delete the old data the Iterator was completely constructed before | 94 | delete d; // delete the old data the Iterator was completely constructed before |
95 | d = new IteratorData; | 95 | d = new IteratorData; |
96 | d->mIt = i.d->mIt; | 96 | d->mIt = i.d->mIt; |
97 | return *this; | 97 | return *this; |
98 | } | 98 | } |
99 | 99 | ||
100 | AddressBook::Iterator::~Iterator() | 100 | AddressBook::Iterator::~Iterator() |
101 | { | 101 | { |
102 | delete d; | 102 | delete d; |
103 | } | 103 | } |
104 | 104 | ||
105 | const Addressee &AddressBook::Iterator::operator*() const | 105 | const Addressee &AddressBook::Iterator::operator*() const |
106 | { | 106 | { |
107 | return *(d->mIt); | 107 | return *(d->mIt); |
108 | } | 108 | } |
109 | 109 | ||
110 | Addressee &AddressBook::Iterator::operator*() | 110 | Addressee &AddressBook::Iterator::operator*() |
111 | { | 111 | { |
112 | return *(d->mIt); | 112 | return *(d->mIt); |
113 | } | 113 | } |
114 | 114 | ||
115 | Addressee *AddressBook::Iterator::operator->() | 115 | Addressee *AddressBook::Iterator::operator->() |
116 | { | 116 | { |
117 | return &(*(d->mIt)); | 117 | return &(*(d->mIt)); |
118 | } | 118 | } |
119 | 119 | ||
120 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 120 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
121 | { | 121 | { |
122 | (d->mIt)++; | 122 | (d->mIt)++; |
123 | return *this; | 123 | return *this; |
124 | } | 124 | } |
125 | 125 | ||
126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
127 | { | 127 | { |
128 | (d->mIt)++; | 128 | (d->mIt)++; |
129 | return *this; | 129 | return *this; |
130 | } | 130 | } |
131 | 131 | ||
132 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 132 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
133 | { | 133 | { |
134 | (d->mIt)--; | 134 | (d->mIt)--; |
135 | return *this; | 135 | return *this; |
136 | } | 136 | } |
137 | 137 | ||
138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
139 | { | 139 | { |
140 | (d->mIt)--; | 140 | (d->mIt)--; |
141 | return *this; | 141 | return *this; |
142 | } | 142 | } |
143 | 143 | ||
144 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 144 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
145 | { | 145 | { |
146 | return ( d->mIt == it.d->mIt ); | 146 | return ( d->mIt == it.d->mIt ); |
147 | } | 147 | } |
148 | 148 | ||
149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
150 | { | 150 | { |
151 | return ( d->mIt != it.d->mIt ); | 151 | return ( d->mIt != it.d->mIt ); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | AddressBook::ConstIterator::ConstIterator() | 155 | AddressBook::ConstIterator::ConstIterator() |
156 | { | 156 | { |
157 | d = new ConstIteratorData; | 157 | d = new ConstIteratorData; |
158 | } | 158 | } |
159 | 159 | ||
160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
161 | { | 161 | { |
162 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
163 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
164 | } | 164 | } |
165 | 165 | ||
166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
167 | { | 167 | { |
168 | if( this == &i ) return *this; // guard for self assignment | 168 | if( this == &i ) return *this; // guard for self assignment |
169 | delete d; // delete the old data because the Iterator was really constructed before | 169 | delete d; // delete the old data because the Iterator was really constructed before |
170 | d = new ConstIteratorData; | 170 | d = new ConstIteratorData; |
171 | d->mIt = i.d->mIt; | 171 | d->mIt = i.d->mIt; |
172 | return *this; | 172 | return *this; |
173 | } | 173 | } |
174 | 174 | ||
175 | AddressBook::ConstIterator::~ConstIterator() | 175 | AddressBook::ConstIterator::~ConstIterator() |
176 | { | 176 | { |
177 | delete d; | 177 | delete d; |
178 | } | 178 | } |
179 | 179 | ||
180 | const Addressee &AddressBook::ConstIterator::operator*() const | 180 | const Addressee &AddressBook::ConstIterator::operator*() const |
181 | { | 181 | { |
182 | return *(d->mIt); | 182 | return *(d->mIt); |
183 | } | 183 | } |
184 | 184 | ||
185 | const Addressee* AddressBook::ConstIterator::operator->() const | 185 | const Addressee* AddressBook::ConstIterator::operator->() const |
186 | { | 186 | { |
187 | return &(*(d->mIt)); | 187 | return &(*(d->mIt)); |
188 | } | 188 | } |
189 | 189 | ||
190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
191 | { | 191 | { |
192 | (d->mIt)++; | 192 | (d->mIt)++; |
193 | return *this; | 193 | return *this; |
194 | } | 194 | } |
195 | 195 | ||
196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
197 | { | 197 | { |
198 | (d->mIt)++; | 198 | (d->mIt)++; |
199 | return *this; | 199 | return *this; |
200 | } | 200 | } |
201 | 201 | ||
202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
203 | { | 203 | { |
204 | (d->mIt)--; | 204 | (d->mIt)--; |
205 | return *this; | 205 | return *this; |
206 | } | 206 | } |
207 | 207 | ||
208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
209 | { | 209 | { |
210 | (d->mIt)--; | 210 | (d->mIt)--; |
211 | return *this; | 211 | return *this; |
212 | } | 212 | } |
213 | 213 | ||
214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
215 | { | 215 | { |
216 | return ( d->mIt == it.d->mIt ); | 216 | return ( d->mIt == it.d->mIt ); |
217 | } | 217 | } |
218 | 218 | ||
219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
220 | { | 220 | { |
221 | return ( d->mIt != it.d->mIt ); | 221 | return ( d->mIt != it.d->mIt ); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | AddressBook::AddressBook() | 225 | AddressBook::AddressBook() |
226 | { | 226 | { |
227 | init(0, "contact"); | 227 | init(0, "contact"); |
228 | } | 228 | } |
229 | 229 | ||
230 | AddressBook::AddressBook( const QString &config ) | 230 | AddressBook::AddressBook( const QString &config ) |
231 | { | 231 | { |
232 | init(config, "contact"); | 232 | init(config, "contact"); |
233 | } | 233 | } |
234 | 234 | ||
235 | AddressBook::AddressBook( const QString &config, const QString &family ) | 235 | AddressBook::AddressBook( const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | init(config, family); | 237 | init(config, family); |
238 | 238 | ||
239 | } | 239 | } |
240 | 240 | ||
241 | // the default family is "contact" | 241 | // the default family is "contact" |
242 | void AddressBook::init(const QString &config, const QString &family ) | 242 | void AddressBook::init(const QString &config, const QString &family ) |
243 | { | 243 | { |
244 | blockLSEchange = false; | 244 | blockLSEchange = false; |
245 | d = new AddressBookData; | 245 | d = new AddressBookData; |
246 | QString fami = family; | 246 | QString fami = family; |
247 | if (config != 0) { | 247 | if (config != 0) { |
248 | if ( family == "syncContact" ) { | 248 | if ( family == "syncContact" ) { |
249 | qDebug("creating sync config "); | 249 | qDebug("creating sync config "); |
250 | fami = "contact"; | 250 | fami = "contact"; |
251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
252 | con->setGroup( "General" ); | 252 | con->setGroup( "General" ); |
253 | con->writeEntry( "ResourceKeys", QString("sync") ); | 253 | con->writeEntry( "ResourceKeys", QString("sync") ); |
254 | con->writeEntry( "Standard", QString("sync") ); | 254 | con->writeEntry( "Standard", QString("sync") ); |
255 | con->setGroup( "Resource_sync" ); | 255 | con->setGroup( "Resource_sync" ); |
256 | con->writeEntry( "FileName", config ); | 256 | con->writeEntry( "FileName", config ); |
257 | con->writeEntry( "FileFormat", QString("vcard") ); | 257 | con->writeEntry( "FileFormat", QString("vcard") ); |
258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
259 | con->writeEntry( "ResourceName", QString("sync_res") ); | 259 | con->writeEntry( "ResourceName", QString("sync_res") ); |
260 | if ( config.right(4) == ".xml" ) | 260 | if ( config.right(4) == ".xml" ) |
261 | con->writeEntry( "ResourceType", QString("qtopia") ); | 261 | con->writeEntry( "ResourceType", QString("qtopia") ); |
262 | else if ( config == "sharp" ) { | 262 | else if ( config == "sharp" ) { |
263 | con->writeEntry( "ResourceType", QString("sharp") ); | 263 | con->writeEntry( "ResourceType", QString("sharp") ); |
264 | } else { | 264 | } else { |
265 | con->writeEntry( "ResourceType", QString("file") ); | 265 | con->writeEntry( "ResourceType", QString("file") ); |
266 | } | 266 | } |
267 | //con->sync(); | 267 | //con->sync(); |
268 | d->mConfig = con; | 268 | d->mConfig = con; |
269 | } | 269 | } |
270 | else | 270 | else |
271 | d->mConfig = new KConfig( locateLocal("config", config) ); | 271 | d->mConfig = new KConfig( locateLocal("config", config) ); |
272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
273 | } | 273 | } |
274 | else { | 274 | else { |
275 | d->mConfig = 0; | 275 | d->mConfig = 0; |
276 | // qDebug("AddressBook::init 1 config=0"); | 276 | // qDebug("AddressBook::init 1 config=0"); |
277 | } | 277 | } |
278 | 278 | ||
279 | //US d->mErrorHandler = 0; | 279 | //US d->mErrorHandler = 0; |
280 | d->mManager = new KRES::Manager<Resource>( fami ); | 280 | d->mManager = new KRES::Manager<Resource>( fami ); |
281 | d->mManager->readConfig( d->mConfig ); | 281 | d->mManager->readConfig( d->mConfig ); |
282 | if ( family == "syncContact" ) { | 282 | if ( family == "syncContact" ) { |
283 | KRES::Manager<Resource> *manager = d->mManager; | 283 | KRES::Manager<Resource> *manager = d->mManager; |
284 | KRES::Manager<Resource>::ActiveIterator it; | 284 | KRES::Manager<Resource>::ActiveIterator it; |
285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
286 | (*it)->setAddressBook( this ); | 286 | (*it)->setAddressBook( this ); |
287 | if ( !(*it)->open() ) | 287 | if ( !(*it)->open() ) |
288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
289 | } | 289 | } |
290 | Resource *res = standardResource(); | 290 | Resource *res = standardResource(); |
291 | if ( !res ) { | 291 | if ( !res ) { |
292 | qDebug("ERROR: no standard resource"); | 292 | qDebug("ERROR: no standard resource"); |
293 | res = manager->createResource( "file" ); | 293 | res = manager->createResource( "file" ); |
294 | if ( res ) | 294 | if ( res ) |
295 | { | 295 | { |
296 | addResource( res ); | 296 | addResource( res ); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
300 | } | 300 | } |
301 | setStandardResource( res ); | 301 | setStandardResource( res ); |
302 | manager->writeConfig(); | 302 | manager->writeConfig(); |
303 | } | 303 | } |
304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
305 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
307 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
309 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
311 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
313 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
315 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
317 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
319 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
320 | 320 | ||
321 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
322 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
324 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
326 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
330 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
331 | } | 331 | } |
332 | 332 | ||
333 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
334 | { | 334 | { |
335 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
336 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
338 | delete d; d = 0; | 338 | delete d; d = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bool AddressBook::load() | 341 | bool AddressBook::load() |
342 | { | 342 | { |
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } else { | 351 | } else { |
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | 352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); |
353 | } | 353 | } |
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | // exports all Addressees, which are syncable | 379 | // exports all Addressees, which are syncable |
380 | void AddressBook::export2File( QString fileName ) | 380 | void AddressBook::export2File( QString fileName ) |
381 | { | 381 | { |
382 | 382 | ||
383 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
384 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
386 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
387 | return ; | 387 | return ; |
388 | } | 388 | } |
389 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
390 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
391 | Iterator it; | 391 | Iterator it; |
392 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
393 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
394 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { | 395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { |
396 | if ( !(*it).IDStr().isEmpty() ) { | 396 | if ( !(*it).IDStr().isEmpty() ) { |
397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
398 | } | 398 | } |
399 | KABC::VCardConverter converter; | 399 | KABC::VCardConverter converter; |
400 | QString vcard; | 400 | QString vcard; |
401 | //Resource *resource() const; | 401 | //Resource *resource() const; |
402 | converter.addresseeToVCard( *it, vcard, version ); | 402 | converter.addresseeToVCard( *it, vcard, version ); |
403 | t << vcard << "\r\n"; | 403 | t << vcard << "\r\n"; |
404 | } | 404 | } |
405 | } | 405 | } |
406 | t << "\r\n\r\n"; | 406 | t << "\r\n\r\n"; |
407 | outFile.close(); | 407 | outFile.close(); |
408 | } | 408 | } |
409 | // if QStringList uids is empty, all are exported | 409 | // if QStringList uids is empty, all are exported |
410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
411 | { | 411 | { |
412 | KABC::VCardConverter converter; | 412 | KABC::VCardConverter converter; |
413 | QString datastream; | 413 | QString datastream; |
414 | Iterator it; | 414 | Iterator it; |
415 | bool all = uids.isEmpty(); | 415 | bool all = uids.isEmpty(); |
416 | for ( it = begin(); it != end(); ++it ) { | 416 | for ( it = begin(); it != end(); ++it ) { |
417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
418 | if ( ! all ) { | 418 | if ( ! all ) { |
419 | if ( ! ( uids.contains((*it).uid() ) )) | 419 | if ( ! ( uids.contains((*it).uid() ) )) |
420 | continue; | 420 | continue; |
421 | } | 421 | } |
422 | KABC::Addressee a = ( *it ); | 422 | KABC::Addressee a = ( *it ); |
423 | if ( a.isEmpty() ) | 423 | if ( a.isEmpty() ) |
424 | continue; | 424 | continue; |
425 | if ( all && a.resource() && !a.resource()->includeInSync() ) | 425 | if ( all && a.resource() && !a.resource()->includeInSync() ) |
426 | continue; | 426 | continue; |
427 | a.simplifyEmails(); | 427 | a.simplifyEmails(); |
428 | a.simplifyPhoneNumbers(); | 428 | a.simplifyPhoneNumbers(); |
429 | a.simplifyPhoneNumberTypes(); | 429 | a.simplifyPhoneNumberTypes(); |
430 | a.simplifyAddresses(); | 430 | a.simplifyAddresses(); |
431 | 431 | ||
432 | QString vcard; | 432 | QString vcard; |
433 | QString vcardnew; | 433 | QString vcardnew; |
434 | converter.addresseeToVCard( a, vcard ); | 434 | converter.addresseeToVCard( a, vcard ); |
435 | int start = 0; | 435 | int start = 0; |
436 | int next; | 436 | int next; |
437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
438 | int semi = vcard.find(";", next); | 438 | int semi = vcard.find(";", next); |
439 | int dopp = vcard.find(":", next); | 439 | int dopp = vcard.find(":", next); |
440 | int sep; | 440 | int sep; |
441 | if ( semi < dopp && semi >= 0 ) | 441 | if ( semi < dopp && semi >= 0 ) |
442 | sep = semi ; | 442 | sep = semi ; |
443 | else | 443 | else |
444 | sep = dopp; | 444 | sep = dopp; |
445 | vcardnew +=vcard.mid( start, next - start); | 445 | vcardnew +=vcard.mid( start, next - start); |
446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | 446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
447 | start = sep; | 447 | start = sep; |
448 | } | 448 | } |
449 | vcardnew += vcard.mid( start,vcard.length() ); | 449 | vcardnew += vcard.mid( start,vcard.length() ); |
450 | vcard = ""; | 450 | vcard = ""; |
451 | start = 0; | 451 | start = 0; |
452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
453 | int sep = vcardnew.find(":", next); | 453 | int sep = vcardnew.find(":", next); |
454 | vcard +=vcardnew.mid( start, next - start+3); | 454 | vcard +=vcardnew.mid( start, next - start+3); |
455 | start = sep; | 455 | start = sep; |
456 | } | 456 | } |
457 | vcard += vcardnew.mid( start,vcardnew.length() ); | 457 | vcard += vcardnew.mid( start,vcardnew.length() ); |
458 | vcard.replace ( QRegExp(";;;") , "" ); | 458 | vcard.replace ( QRegExp(";;;") , "" ); |
459 | vcard.replace ( QRegExp(";;") , "" ); | 459 | vcard.replace ( QRegExp(";;") , "" ); |
460 | datastream += vcard; | 460 | datastream += vcard; |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | QFile outFile(fileName); | 464 | QFile outFile(fileName); |
465 | if ( outFile.open(IO_WriteOnly) ) { | 465 | if ( outFile.open(IO_WriteOnly) ) { |
466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
467 | QTextStream t( &outFile ); // use a text stream | 467 | QTextStream t( &outFile ); // use a text stream |
468 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 468 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
469 | t <<datastream; | 469 | t <<datastream; |
470 | t << "\r\n\r\n"; | 470 | t << "\r\n\r\n"; |
471 | outFile.close(); | 471 | outFile.close(); |
472 | 472 | ||
473 | } else { | 473 | } else { |
474 | qDebug("Error open temp file "); | 474 | qDebug("Error open temp file "); |
475 | return false; | 475 | return false; |
476 | } | 476 | } |
477 | return true; | 477 | return true; |
478 | 478 | ||
479 | } | 479 | } |
480 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
481 | { | 481 | { |
482 | 482 | ||
483 | if ( removeOld ) | 483 | if ( removeOld ) |
484 | setUntagged( true ); | 484 | setUntagged( true ); |
485 | KABC::Addressee::List list; | 485 | KABC::Addressee::List list; |
486 | QFile file( fileName ); | 486 | QFile file( fileName ); |
487 | file.open( IO_ReadOnly ); | 487 | file.open( IO_ReadOnly ); |
488 | QByteArray rawData = file.readAll(); | 488 | QByteArray rawData = file.readAll(); |
489 | file.close(); | 489 | file.close(); |
490 | QString data; | 490 | QString data; |
491 | if ( replaceLabel ) { | 491 | if ( replaceLabel ) { |
492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
493 | data.replace ( QRegExp("LABEL") , "ADR" ); | 493 | data.replace ( QRegExp("LABEL") , "ADR" ); |
494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
495 | } else | 495 | } else |
496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
497 | KABC::VCardTool tool; | 497 | KABC::VCardTool tool; |
498 | list = tool.parseVCards( data ); | 498 | list = tool.parseVCards( data ); |
499 | KABC::Addressee::List::Iterator it; | 499 | KABC::Addressee::List::Iterator it; |
500 | for ( it = list.begin(); it != list.end(); ++it ) { | 500 | for ( it = list.begin(); it != list.end(); ++it ) { |
501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
502 | if ( !id.isEmpty() ) | 502 | if ( !id.isEmpty() ) |
503 | (*it).setIDStr(id ); | 503 | (*it).setIDStr(id ); |
504 | (*it).setResource( 0 ); | 504 | (*it).setResource( 0 ); |
505 | if ( replaceLabel ) | 505 | if ( replaceLabel ) |
506 | (*it).removeVoice(); | 506 | (*it).removeVoice(); |
507 | if ( removeOld ) | 507 | if ( removeOld ) |
508 | (*it).setTagged( true ); | 508 | (*it).setTagged( true ); |
509 | insertAddressee( (*it), false, true ); | 509 | insertAddressee( (*it), false, true ); |
510 | } | 510 | } |
511 | if ( removeOld ) | 511 | if ( removeOld ) |
512 | removeUntagged(); | 512 | removeUntagged(); |
513 | return list.count(); | ||
513 | } | 514 | } |
514 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
515 | { | 516 | { |
516 | Iterator ait; | 517 | Iterator ait; |
517 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
518 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
519 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
520 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
521 | } else | 522 | } else |
522 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
523 | } else | 524 | } else |
524 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
525 | } | 526 | } |
526 | } | 527 | } |
527 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
528 | { | 529 | { |
529 | Iterator ait; | 530 | Iterator ait; |
530 | bool todelete = false; | 531 | bool todelete = false; |
531 | Iterator todel; | 532 | Iterator todel; |
532 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
533 | if ( todelete ) | 534 | if ( todelete ) |
534 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
535 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
536 | todelete = true; | 537 | todelete = true; |
537 | todel = ait; | 538 | todel = ait; |
538 | } else | 539 | } else |
539 | todelete = false; | 540 | todelete = false; |
540 | } | 541 | } |
541 | if ( todelete ) | 542 | if ( todelete ) |
542 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
543 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
544 | } | 545 | } |
545 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
546 | { | 547 | { |
547 | Iterator ait; | 548 | Iterator ait; |
548 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
549 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
550 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
551 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
552 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
553 | } | 554 | } |
554 | } | 555 | } |
555 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 556 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
556 | { | 557 | { |
557 | Iterator ait; | 558 | Iterator ait; |
558 | for ( ait = begin(); ait != end(); ++ait ) { | 559 | for ( ait = begin(); ait != end(); ++ait ) { |
559 | QString id = (*ait).IDStr(); | 560 | QString id = (*ait).IDStr(); |
560 | (*ait).setIDStr( ":"); | 561 | (*ait).setIDStr( ":"); |
561 | (*ait).setExternalUID( id ); | 562 | (*ait).setExternalUID( id ); |
562 | (*ait).setOriginalExternalUID( id ); | 563 | (*ait).setOriginalExternalUID( id ); |
563 | if ( isPreSync ) | 564 | if ( isPreSync ) |
564 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 565 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
565 | else { | 566 | else { |
566 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 567 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
567 | (*ait).setID( currentSyncDevice,id ); | 568 | (*ait).setID( currentSyncDevice,id ); |
568 | 569 | ||
569 | } | 570 | } |
570 | } | 571 | } |
571 | } | 572 | } |
572 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 573 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
573 | { | 574 | { |
574 | 575 | ||
575 | setUntagged(); | 576 | setUntagged(); |
576 | KABC::Addressee::List list; | 577 | KABC::Addressee::List list; |
577 | QFile file( fileName ); | 578 | QFile file( fileName ); |
578 | file.open( IO_ReadOnly ); | 579 | file.open( IO_ReadOnly ); |
579 | QByteArray rawData = file.readAll(); | 580 | QByteArray rawData = file.readAll(); |
580 | file.close(); | 581 | file.close(); |
581 | QString data; | 582 | QString data; |
582 | 583 | ||
583 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 584 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
584 | KABC::VCardTool tool; | 585 | KABC::VCardTool tool; |
585 | list = tool.parseVCards( data ); | 586 | list = tool.parseVCards( data ); |
586 | KABC::Addressee::List::Iterator it; | 587 | KABC::Addressee::List::Iterator it; |
587 | for ( it = list.begin(); it != list.end(); ++it ) { | 588 | for ( it = list.begin(); it != list.end(); ++it ) { |
588 | Iterator ait; | 589 | Iterator ait; |
589 | for ( ait = begin(); ait != end(); ++ait ) { | 590 | for ( ait = begin(); ait != end(); ++ait ) { |
590 | if ( !(*ait).tagged() ) { | 591 | if ( !(*ait).tagged() ) { |
591 | if ( (*ait).containsAdr(*it)) { | 592 | if ( (*ait).containsAdr(*it)) { |
592 | (*ait).setTagged(true); | 593 | (*ait).setTagged(true); |
593 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 594 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
594 | (*it).setIDStr( ":"); | 595 | (*it).setIDStr( ":"); |
595 | (*it).setID( currentSyncDevice,id ); | 596 | (*it).setID( currentSyncDevice,id ); |
596 | (*it).setExternalUID( id ); | 597 | (*it).setExternalUID( id ); |
597 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 598 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
598 | (*it).setUid( ( (*ait).uid() )); | 599 | (*it).setUid( ( (*ait).uid() )); |
599 | break; | 600 | break; |
600 | } | 601 | } |
601 | } | 602 | } |
602 | 603 | ||
603 | } | 604 | } |
604 | if ( ait == end() ) | 605 | if ( ait == end() ) |
605 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 606 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
606 | } | 607 | } |
607 | clear(); | 608 | clear(); |
608 | for ( it = list.begin(); it != list.end(); ++it ) { | 609 | for ( it = list.begin(); it != list.end(); ++it ) { |
609 | insertAddressee( (*it) ); | 610 | insertAddressee( (*it) ); |
610 | } | 611 | } |
611 | } | 612 | } |
612 | 613 | ||
613 | bool AddressBook::saveABphone( QString fileName ) | 614 | bool AddressBook::saveABphone( QString fileName ) |
614 | { | 615 | { |
615 | //smplifyAddressees(); | 616 | //smplifyAddressees(); |
616 | qDebug("saveABphone:: saving AB... "); | 617 | qDebug("saveABphone:: saving AB... "); |
617 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 618 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
618 | return false; | 619 | return false; |
619 | qDebug("saveABphone:: writing to phone... "); | 620 | qDebug("saveABphone:: writing to phone... "); |
620 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 621 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
621 | return false; | 622 | return false; |
622 | } | 623 | } |
623 | qDebug("saveABphone:: re-reading from phone... "); | 624 | qDebug("saveABphone:: re-reading from phone... "); |
624 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 625 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
625 | return false; | 626 | return false; |
626 | } | 627 | } |
627 | return true; | 628 | return true; |
628 | } | 629 | } |
629 | bool AddressBook::saveAB() | 630 | bool AddressBook::saveAB() |
630 | { | 631 | { |
631 | bool ok = true; | 632 | bool ok = true; |
632 | 633 | ||
633 | deleteRemovedAddressees(); | 634 | deleteRemovedAddressees(); |
634 | Iterator ait; | 635 | Iterator ait; |
635 | for ( ait = begin(); ait != end(); ++ait ) { | 636 | for ( ait = begin(); ait != end(); ++ait ) { |
636 | if ( !(*ait).IDStr().isEmpty() ) { | 637 | if ( !(*ait).IDStr().isEmpty() ) { |
637 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 638 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
638 | } | 639 | } |
639 | } | 640 | } |
640 | KRES::Manager<Resource>::ActiveIterator it; | 641 | KRES::Manager<Resource>::ActiveIterator it; |
641 | KRES::Manager<Resource> *manager = d->mManager; | 642 | KRES::Manager<Resource> *manager = d->mManager; |
642 | qDebug("SaveAB::saving..." ); | 643 | qDebug("SaveAB::saving..." ); |
643 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 644 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
644 | qDebug("SaveAB::checking resource..." ); | 645 | qDebug("SaveAB::checking resource..." ); |
645 | if ( (*it)->readOnly() ) | 646 | if ( (*it)->readOnly() ) |
646 | qDebug("resource is readonly." ); | 647 | qDebug("resource is readonly." ); |
647 | if ( (*it)->isOpen() ) | 648 | if ( (*it)->isOpen() ) |
648 | qDebug("resource is open" ); | 649 | qDebug("resource is open" ); |
649 | 650 | ||
650 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 651 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
651 | Ticket *ticket = requestSaveTicket( *it ); | 652 | Ticket *ticket = requestSaveTicket( *it ); |
652 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 653 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
653 | if ( !ticket ) { | 654 | if ( !ticket ) { |
654 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 655 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
655 | .arg( (*it)->resourceName() ) ); | 656 | .arg( (*it)->resourceName() ) ); |
656 | return false; | 657 | return false; |
657 | } | 658 | } |
658 | 659 | ||
659 | //if ( !save( ticket ) ) | 660 | //if ( !save( ticket ) ) |
660 | if ( ticket->resource() ) { | 661 | if ( ticket->resource() ) { |
661 | QString name = ticket->resource()->resourceName(); | 662 | QString name = ticket->resource()->resourceName(); |
662 | if ( ! ticket->resource()->save( ticket ) ) | 663 | if ( ! ticket->resource()->save( ticket ) ) |
663 | ok = false; | 664 | ok = false; |
664 | else | 665 | else |
665 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 666 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
666 | 667 | ||
667 | } else | 668 | } else |
668 | ok = false; | 669 | ok = false; |
669 | 670 | ||
670 | } | 671 | } |
671 | } | 672 | } |
672 | return ok; | 673 | return ok; |
673 | } | 674 | } |
674 | 675 | ||
675 | AddressBook::Iterator AddressBook::begin() | 676 | AddressBook::Iterator AddressBook::begin() |
676 | { | 677 | { |
677 | Iterator it = Iterator(); | 678 | Iterator it = Iterator(); |
678 | it.d->mIt = d->mAddressees.begin(); | 679 | it.d->mIt = d->mAddressees.begin(); |
679 | return it; | 680 | return it; |
680 | } | 681 | } |
681 | 682 | ||
682 | AddressBook::ConstIterator AddressBook::begin() const | 683 | AddressBook::ConstIterator AddressBook::begin() const |
683 | { | 684 | { |
684 | ConstIterator it = ConstIterator(); | 685 | ConstIterator it = ConstIterator(); |
685 | it.d->mIt = d->mAddressees.begin(); | 686 | it.d->mIt = d->mAddressees.begin(); |
686 | return it; | 687 | return it; |
687 | } | 688 | } |
688 | 689 | ||
689 | AddressBook::Iterator AddressBook::end() | 690 | AddressBook::Iterator AddressBook::end() |
690 | { | 691 | { |
691 | Iterator it = Iterator(); | 692 | Iterator it = Iterator(); |
692 | it.d->mIt = d->mAddressees.end(); | 693 | it.d->mIt = d->mAddressees.end(); |
693 | return it; | 694 | return it; |
694 | } | 695 | } |
695 | 696 | ||
696 | AddressBook::ConstIterator AddressBook::end() const | 697 | AddressBook::ConstIterator AddressBook::end() const |
697 | { | 698 | { |
698 | ConstIterator it = ConstIterator(); | 699 | ConstIterator it = ConstIterator(); |
699 | it.d->mIt = d->mAddressees.end(); | 700 | it.d->mIt = d->mAddressees.end(); |
700 | return it; | 701 | return it; |
701 | } | 702 | } |
702 | 703 | ||
703 | void AddressBook::clear() | 704 | void AddressBook::clear() |
704 | { | 705 | { |
705 | d->mAddressees.clear(); | 706 | d->mAddressees.clear(); |
706 | } | 707 | } |
707 | 708 | ||
708 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 709 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
709 | { | 710 | { |
710 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 711 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
711 | 712 | ||
712 | if ( !resource ) | 713 | if ( !resource ) |
713 | { | 714 | { |
714 | qDebug("AddressBook::requestSaveTicket no resource" ); | 715 | qDebug("AddressBook::requestSaveTicket no resource" ); |
715 | resource = standardResource(); | 716 | resource = standardResource(); |
716 | } | 717 | } |
717 | 718 | ||
718 | KRES::Manager<Resource>::ActiveIterator it; | 719 | KRES::Manager<Resource>::ActiveIterator it; |
719 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 720 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
720 | if ( (*it) == resource ) { | 721 | if ( (*it) == resource ) { |
721 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 722 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
722 | return 0; | 723 | return 0; |
723 | else | 724 | else |
724 | return (*it)->requestSaveTicket(); | 725 | return (*it)->requestSaveTicket(); |
725 | } | 726 | } |
726 | } | 727 | } |
727 | 728 | ||
728 | return 0; | 729 | return 0; |
729 | } | 730 | } |
730 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 731 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
731 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 732 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
732 | { | 733 | { |
733 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 734 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
734 | //qDebug("block insert "); | 735 | //qDebug("block insert "); |
735 | return; | 736 | return; |
736 | } | 737 | } |
737 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 738 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
738 | bool found = false; | 739 | bool found = false; |
739 | Addressee::List::Iterator it; | 740 | Addressee::List::Iterator it; |
740 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 741 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
741 | if ( a.uid() == (*it).uid() ) { | 742 | if ( a.uid() == (*it).uid() ) { |
742 | 743 | ||
743 | bool changed = false; | 744 | bool changed = false; |
744 | Addressee addr = a; | 745 | Addressee addr = a; |
745 | if ( addr != (*it) ) | 746 | if ( addr != (*it) ) |
746 | changed = true; | 747 | changed = true; |
747 | 748 | ||
748 | if ( takeResource ) { | 749 | if ( takeResource ) { |
749 | Resource * res = (*it).resource(); | 750 | Resource * res = (*it).resource(); |
750 | (*it) = a; | 751 | (*it) = a; |
751 | (*it).setResource( res ); | 752 | (*it).setResource( res ); |
752 | } else { | 753 | } else { |
753 | (*it) = a; | 754 | (*it) = a; |
754 | if ( (*it).resource() == 0 ) | 755 | if ( (*it).resource() == 0 ) |
755 | (*it).setResource( standardResource() ); | 756 | (*it).setResource( standardResource() ); |
756 | } | 757 | } |
757 | if ( changed ) { | 758 | if ( changed ) { |
758 | if ( setRev ) { | 759 | if ( setRev ) { |
759 | 760 | ||
760 | // get rid of micro seconds | 761 | // get rid of micro seconds |
761 | QDateTime dt = QDateTime::currentDateTime(); | 762 | QDateTime dt = QDateTime::currentDateTime(); |
762 | QTime t = dt.time(); | 763 | QTime t = dt.time(); |
763 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 764 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
764 | (*it).setRevision( dt ); | 765 | (*it).setRevision( dt ); |
765 | } | 766 | } |
766 | (*it).setChanged( true ); | 767 | (*it).setChanged( true ); |
767 | } | 768 | } |
768 | 769 | ||
769 | found = true; | 770 | found = true; |
770 | } else { | 771 | } else { |
771 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 772 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
772 | QString name = (*it).uid().mid( 19 ); | 773 | QString name = (*it).uid().mid( 19 ); |
773 | Addressee b = a; | 774 | Addressee b = a; |
774 | QString id = b.getID( name ); | 775 | QString id = b.getID( name ); |
775 | if ( ! id.isEmpty() ) { | 776 | if ( ! id.isEmpty() ) { |
776 | QString des = (*it).note(); | 777 | QString des = (*it).note(); |
777 | int startN; | 778 | int startN; |
778 | if( (startN = des.find( id ) ) >= 0 ) { | 779 | if( (startN = des.find( id ) ) >= 0 ) { |
779 | int endN = des.find( ",", startN+1 ); | 780 | int endN = des.find( ",", startN+1 ); |
780 | des = des.left( startN ) + des.mid( endN+1 ); | 781 | des = des.left( startN ) + des.mid( endN+1 ); |
781 | (*it).setNote( des ); | 782 | (*it).setNote( des ); |
782 | } | 783 | } |
783 | } | 784 | } |
784 | } | 785 | } |
785 | } | 786 | } |
786 | } | 787 | } |
787 | if ( found ) | 788 | if ( found ) |
788 | return; | 789 | return; |
789 | d->mAddressees.append( a ); | 790 | d->mAddressees.append( a ); |
790 | Addressee& addr = d->mAddressees.last(); | 791 | Addressee& addr = d->mAddressees.last(); |
791 | if ( addr.resource() == 0 ) | 792 | if ( addr.resource() == 0 ) |
792 | addr.setResource( standardResource() ); | 793 | addr.setResource( standardResource() ); |
793 | 794 | ||
794 | addr.setChanged( true ); | 795 | addr.setChanged( true ); |
795 | } | 796 | } |
796 | 797 | ||
797 | void AddressBook::removeAddressee( const Addressee &a ) | 798 | void AddressBook::removeAddressee( const Addressee &a ) |
798 | { | 799 | { |
799 | Iterator it; | 800 | Iterator it; |
800 | Iterator it2; | 801 | Iterator it2; |
801 | bool found = false; | 802 | bool found = false; |
802 | for ( it = begin(); it != end(); ++it ) { | 803 | for ( it = begin(); it != end(); ++it ) { |
803 | if ( a.uid() == (*it).uid() ) { | 804 | if ( a.uid() == (*it).uid() ) { |
804 | found = true; | 805 | found = true; |
805 | it2 = it; | 806 | it2 = it; |
806 | } else { | 807 | } else { |
807 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 808 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
808 | QString name = (*it).uid().mid( 19 ); | 809 | QString name = (*it).uid().mid( 19 ); |
809 | Addressee b = a; | 810 | Addressee b = a; |
810 | QString id = b.getID( name ); | 811 | QString id = b.getID( name ); |
811 | if ( ! id.isEmpty() ) { | 812 | if ( ! id.isEmpty() ) { |
812 | QString des = (*it).note(); | 813 | QString des = (*it).note(); |
813 | if( des.find( id ) < 0 ) { | 814 | if( des.find( id ) < 0 ) { |
814 | des += id + ","; | 815 | des += id + ","; |
815 | (*it).setNote( des ); | 816 | (*it).setNote( des ); |
816 | } | 817 | } |
817 | } | 818 | } |
818 | } | 819 | } |
819 | 820 | ||
820 | } | 821 | } |
821 | } | 822 | } |
822 | 823 | ||
823 | if ( found ) | 824 | if ( found ) |
824 | removeAddressee( it2 ); | 825 | removeAddressee( it2 ); |
825 | 826 | ||
826 | } | 827 | } |
827 | 828 | ||
828 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 829 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
829 | { | 830 | { |
830 | Iterator it = begin(); | 831 | Iterator it = begin(); |
831 | Iterator it2 ; | 832 | Iterator it2 ; |
832 | QDateTime dt ( QDate( 2004,1,1) ); | 833 | QDateTime dt ( QDate( 2004,1,1) ); |
833 | while ( it != end() ) { | 834 | while ( it != end() ) { |
834 | (*it).setRevision( dt ); | 835 | (*it).setRevision( dt ); |
835 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 836 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
836 | (*it).setIDStr(""); | 837 | (*it).setIDStr(""); |
837 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 838 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
838 | it2 = it; | 839 | it2 = it; |
839 | //qDebug("removing %s ",(*it).uid().latin1() ); | 840 | //qDebug("removing %s ",(*it).uid().latin1() ); |
840 | ++it; | 841 | ++it; |
841 | removeAddressee( it2 ); | 842 | removeAddressee( it2 ); |
842 | } else { | 843 | } else { |
843 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 844 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
844 | ++it; | 845 | ++it; |
845 | } | 846 | } |
846 | } | 847 | } |
847 | deleteRemovedAddressees(); | 848 | deleteRemovedAddressees(); |
848 | } | 849 | } |
849 | 850 | ||
850 | void AddressBook::removeAddressee( const Iterator &it ) | 851 | void AddressBook::removeAddressee( const Iterator &it ) |
851 | { | 852 | { |
852 | d->mRemovedAddressees.append( (*it) ); | 853 | d->mRemovedAddressees.append( (*it) ); |
853 | d->mAddressees.remove( it.d->mIt ); | 854 | d->mAddressees.remove( it.d->mIt ); |
854 | } | 855 | } |
855 | 856 | ||
856 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 857 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
857 | { | 858 | { |
858 | Iterator it; | 859 | Iterator it; |
859 | for ( it = begin(); it != end(); ++it ) { | 860 | for ( it = begin(); it != end(); ++it ) { |
860 | if ( a.uid() == (*it).uid() ) { | 861 | if ( a.uid() == (*it).uid() ) { |
861 | return it; | 862 | return it; |
862 | } | 863 | } |
863 | } | 864 | } |
864 | return end(); | 865 | return end(); |
865 | } | 866 | } |
866 | 867 | ||
867 | Addressee AddressBook::findByUid( const QString &uid ) | 868 | Addressee AddressBook::findByUid( const QString &uid ) |
868 | { | 869 | { |
869 | Iterator it; | 870 | Iterator it; |
870 | for ( it = begin(); it != end(); ++it ) { | 871 | for ( it = begin(); it != end(); ++it ) { |
871 | if ( uid == (*it).uid() ) { | 872 | if ( uid == (*it).uid() ) { |
872 | return *it; | 873 | return *it; |
873 | } | 874 | } |
874 | } | 875 | } |
875 | return Addressee(); | 876 | return Addressee(); |
876 | } | 877 | } |
877 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 878 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
878 | { | 879 | { |
879 | //qDebug("AddressBook::preExternSync "); | 880 | //qDebug("AddressBook::preExternSync "); |
880 | AddressBook::Iterator it; | 881 | AddressBook::Iterator it; |
881 | for ( it = begin(); it != end(); ++it ) { | 882 | for ( it = begin(); it != end(); ++it ) { |
882 | (*it).setID( csd, (*it).externalUID() ); | 883 | (*it).setID( csd, (*it).externalUID() ); |
883 | (*it).computeCsum( csd ); | 884 | (*it).computeCsum( csd ); |
884 | } | 885 | } |
885 | mergeAB( aBook ,csd, isSubset ); | 886 | mergeAB( aBook ,csd, isSubset ); |
886 | } | 887 | } |
887 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 888 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
888 | { | 889 | { |
889 | //qDebug("AddressBook::postExternSync "); | 890 | //qDebug("AddressBook::postExternSync "); |
890 | AddressBook::Iterator it; | 891 | AddressBook::Iterator it; |
891 | for ( it = begin(); it != end(); ++it ) { | 892 | for ( it = begin(); it != end(); ++it ) { |
892 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 893 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
893 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 894 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
894 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 895 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
895 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 896 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
896 | if ( ad.isEmpty() ) { | 897 | if ( ad.isEmpty() ) { |
897 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 898 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
898 | } else { | 899 | } else { |
899 | (*it).computeCsum( csd ); | 900 | (*it).computeCsum( csd ); |
900 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 901 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
901 | ad.setID( csd, (*it).externalUID() ); | 902 | ad.setID( csd, (*it).externalUID() ); |
902 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 903 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
903 | aBook->insertAddressee( ad ); | 904 | aBook->insertAddressee( ad ); |
904 | } | 905 | } |
905 | } | 906 | } |
906 | } | 907 | } |
907 | } | 908 | } |
908 | 909 | ||
909 | bool AddressBook::containsExternalUid( const QString& uid ) | 910 | bool AddressBook::containsExternalUid( const QString& uid ) |
910 | { | 911 | { |
911 | Iterator it; | 912 | Iterator it; |
912 | for ( it = begin(); it != end(); ++it ) { | 913 | for ( it = begin(); it != end(); ++it ) { |
913 | if ( uid == (*it).externalUID( ) ) | 914 | if ( uid == (*it).externalUID( ) ) |
914 | return true; | 915 | return true; |
915 | } | 916 | } |
916 | return false; | 917 | return false; |
917 | } | 918 | } |
918 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 919 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
919 | { | 920 | { |
920 | Iterator it; | 921 | Iterator it; |
921 | for ( it = begin(); it != end(); ++it ) { | 922 | for ( it = begin(); it != end(); ++it ) { |
922 | if ( uid == (*it).getID( profile ) ) | 923 | if ( uid == (*it).getID( profile ) ) |
923 | return (*it); | 924 | return (*it); |
924 | } | 925 | } |
925 | return Addressee(); | 926 | return Addressee(); |
926 | } | 927 | } |
927 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 928 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
928 | { | 929 | { |
929 | Iterator it; | 930 | Iterator it; |
930 | Addressee ad; | 931 | Addressee ad; |
931 | for ( it = begin(); it != end(); ++it ) { | 932 | for ( it = begin(); it != end(); ++it ) { |
932 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 933 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
933 | if ( !ad.isEmpty() ) { | 934 | if ( !ad.isEmpty() ) { |
934 | (*it).mergeContact( ad ,isSubset); | 935 | (*it).mergeContact( ad ,isSubset); |
935 | } | 936 | } |
936 | } | 937 | } |
937 | #if 0 | 938 | #if 0 |
938 | // test only | 939 | // test only |
939 | for ( it = begin(); it != end(); ++it ) { | 940 | for ( it = begin(); it != end(); ++it ) { |
940 | 941 | ||
941 | qDebug("uid %s ", (*it).uid().latin1()); | 942 | qDebug("uid %s ", (*it).uid().latin1()); |
942 | } | 943 | } |
943 | #endif | 944 | #endif |
944 | } | 945 | } |
945 | 946 | ||
946 | #if 0 | 947 | #if 0 |
947 | Addressee::List AddressBook::getExternLastSyncAddressees() | 948 | Addressee::List AddressBook::getExternLastSyncAddressees() |
948 | { | 949 | { |
949 | Addressee::List results; | 950 | Addressee::List results; |
950 | 951 | ||
951 | Iterator it; | 952 | Iterator it; |
952 | for ( it = begin(); it != end(); ++it ) { | 953 | for ( it = begin(); it != end(); ++it ) { |
953 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 954 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
954 | if ( (*it).familyName().left(4) == "!E: " ) | 955 | if ( (*it).familyName().left(4) == "!E: " ) |
955 | results.append( *it ); | 956 | results.append( *it ); |
956 | } | 957 | } |
957 | } | 958 | } |
958 | 959 | ||
959 | return results; | 960 | return results; |
960 | } | 961 | } |
961 | #endif | 962 | #endif |
962 | void AddressBook::resetTempSyncStat() | 963 | void AddressBook::resetTempSyncStat() |
963 | { | 964 | { |
964 | Iterator it; | 965 | Iterator it; |
965 | for ( it = begin(); it != end(); ++it ) { | 966 | for ( it = begin(); it != end(); ++it ) { |
966 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 967 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
967 | } | 968 | } |
968 | 969 | ||
969 | } | 970 | } |
970 | 971 | ||
971 | QStringList AddressBook:: uidList() | 972 | QStringList AddressBook:: uidList() |
972 | { | 973 | { |
973 | QStringList results; | 974 | QStringList results; |
974 | Iterator it; | 975 | Iterator it; |
975 | for ( it = begin(); it != end(); ++it ) { | 976 | for ( it = begin(); it != end(); ++it ) { |
976 | results.append( (*it).uid() ); | 977 | results.append( (*it).uid() ); |
977 | } | 978 | } |
978 | return results; | 979 | return results; |
979 | } | 980 | } |
980 | 981 | ||
981 | 982 | ||
982 | Addressee::List AddressBook::allAddressees() | 983 | Addressee::List AddressBook::allAddressees() |
983 | { | 984 | { |
984 | return d->mAddressees; | 985 | return d->mAddressees; |
985 | 986 | ||
986 | } | 987 | } |
987 | 988 | ||
988 | Addressee::List AddressBook::findByName( const QString &name ) | 989 | Addressee::List AddressBook::findByName( const QString &name ) |
989 | { | 990 | { |
990 | Addressee::List results; | 991 | Addressee::List results; |
991 | 992 | ||
992 | Iterator it; | 993 | Iterator it; |
993 | for ( it = begin(); it != end(); ++it ) { | 994 | for ( it = begin(); it != end(); ++it ) { |
994 | if ( name == (*it).realName() ) { | 995 | if ( name == (*it).realName() ) { |
995 | results.append( *it ); | 996 | results.append( *it ); |
996 | } | 997 | } |
997 | } | 998 | } |
998 | 999 | ||
999 | return results; | 1000 | return results; |
1000 | } | 1001 | } |
1001 | 1002 | ||
1002 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1003 | Addressee::List AddressBook::findByEmail( const QString &email ) |
1003 | { | 1004 | { |
1004 | Addressee::List results; | 1005 | Addressee::List results; |
1005 | QStringList mailList; | 1006 | QStringList mailList; |
1006 | 1007 | ||
1007 | Iterator it; | 1008 | Iterator it; |
1008 | for ( it = begin(); it != end(); ++it ) { | 1009 | for ( it = begin(); it != end(); ++it ) { |
1009 | mailList = (*it).emails(); | 1010 | mailList = (*it).emails(); |
1010 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 1011 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1011 | if ( email == (*ite) ) { | 1012 | if ( email == (*ite) ) { |
1012 | results.append( *it ); | 1013 | results.append( *it ); |
1013 | } | 1014 | } |
1014 | } | 1015 | } |
1015 | } | 1016 | } |
1016 | 1017 | ||
1017 | return results; | 1018 | return results; |
1018 | } | 1019 | } |
1019 | 1020 | ||
1020 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1021 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1021 | { | 1022 | { |
1022 | Addressee::List results; | 1023 | Addressee::List results; |
1023 | 1024 | ||
1024 | Iterator it; | 1025 | Iterator it; |
1025 | for ( it = begin(); it != end(); ++it ) { | 1026 | for ( it = begin(); it != end(); ++it ) { |
1026 | if ( (*it).hasCategory( category) ) { | 1027 | if ( (*it).hasCategory( category) ) { |
1027 | results.append( *it ); | 1028 | results.append( *it ); |
1028 | } | 1029 | } |
1029 | } | 1030 | } |
1030 | 1031 | ||
1031 | return results; | 1032 | return results; |
1032 | } | 1033 | } |
1033 | 1034 | ||
1034 | void AddressBook::dump() const | 1035 | void AddressBook::dump() const |
1035 | { | 1036 | { |
1036 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1037 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1037 | 1038 | ||
1038 | ConstIterator it; | 1039 | ConstIterator it; |
1039 | for( it = begin(); it != end(); ++it ) { | 1040 | for( it = begin(); it != end(); ++it ) { |
1040 | (*it).dump(); | 1041 | (*it).dump(); |
1041 | } | 1042 | } |
1042 | 1043 | ||
1043 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1044 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1044 | } | 1045 | } |
1045 | 1046 | ||
1046 | QString AddressBook::identifier() | 1047 | QString AddressBook::identifier() |
1047 | { | 1048 | { |
1048 | QStringList identifier; | 1049 | QStringList identifier; |
1049 | 1050 | ||
1050 | 1051 | ||
1051 | KRES::Manager<Resource>::ActiveIterator it; | 1052 | KRES::Manager<Resource>::ActiveIterator it; |
1052 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1053 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1053 | if ( !(*it)->identifier().isEmpty() ) | 1054 | if ( !(*it)->identifier().isEmpty() ) |
1054 | identifier.append( (*it)->identifier() ); | 1055 | identifier.append( (*it)->identifier() ); |
1055 | } | 1056 | } |
1056 | 1057 | ||
1057 | return identifier.join( ":" ); | 1058 | return identifier.join( ":" ); |
1058 | } | 1059 | } |
1059 | 1060 | ||
1060 | Field::List AddressBook::fields( int category ) | 1061 | Field::List AddressBook::fields( int category ) |
1061 | { | 1062 | { |
1062 | if ( d->mAllFields.isEmpty() ) { | 1063 | if ( d->mAllFields.isEmpty() ) { |
1063 | d->mAllFields = Field::allFields(); | 1064 | d->mAllFields = Field::allFields(); |
1064 | } | 1065 | } |
1065 | 1066 | ||
1066 | if ( category == Field::All ) return d->mAllFields; | 1067 | if ( category == Field::All ) return d->mAllFields; |
1067 | 1068 | ||
1068 | Field::List result; | 1069 | Field::List result; |
1069 | Field::List::ConstIterator it; | 1070 | Field::List::ConstIterator it; |
1070 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1071 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1071 | if ( (*it)->category() & category ) result.append( *it ); | 1072 | if ( (*it)->category() & category ) result.append( *it ); |
1072 | } | 1073 | } |
1073 | 1074 | ||
1074 | return result; | 1075 | return result; |
1075 | } | 1076 | } |
1076 | 1077 | ||
1077 | bool AddressBook::addCustomField( const QString &label, int category, | 1078 | bool AddressBook::addCustomField( const QString &label, int category, |
1078 | const QString &key, const QString &app ) | 1079 | const QString &key, const QString &app ) |
1079 | { | 1080 | { |
1080 | if ( d->mAllFields.isEmpty() ) { | 1081 | if ( d->mAllFields.isEmpty() ) { |
1081 | d->mAllFields = Field::allFields(); | 1082 | d->mAllFields = Field::allFields(); |
1082 | } | 1083 | } |
1083 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1084 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1084 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1085 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1085 | 1086 | ||
1086 | QString k = key.isNull() ? label : key; | 1087 | QString k = key.isNull() ? label : key; |
1087 | 1088 | ||
1088 | Field *field = Field::createCustomField( label, category, k, a ); | 1089 | Field *field = Field::createCustomField( label, category, k, a ); |
1089 | 1090 | ||
1090 | if ( !field ) return false; | 1091 | if ( !field ) return false; |
1091 | 1092 | ||
1092 | d->mAllFields.append( field ); | 1093 | d->mAllFields.append( field ); |
1093 | 1094 | ||
1094 | return true; | 1095 | return true; |
1095 | } | 1096 | } |
1096 | 1097 | ||
1097 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1098 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1098 | { | 1099 | { |
1099 | if (!ab.d) return s; | 1100 | if (!ab.d) return s; |
1100 | 1101 | ||
1101 | return s << ab.d->mAddressees; | 1102 | return s << ab.d->mAddressees; |
1102 | } | 1103 | } |
1103 | 1104 | ||
1104 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1105 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1105 | { | 1106 | { |
1106 | if (!ab.d) return s; | 1107 | if (!ab.d) return s; |
1107 | 1108 | ||
1108 | s >> ab.d->mAddressees; | 1109 | s >> ab.d->mAddressees; |
1109 | 1110 | ||
1110 | return s; | 1111 | return s; |
1111 | } | 1112 | } |
1112 | 1113 | ||
1113 | bool AddressBook::addResource( Resource *resource ) | 1114 | bool AddressBook::addResource( Resource *resource ) |
1114 | { | 1115 | { |
1115 | if ( !resource->open() ) { | 1116 | if ( !resource->open() ) { |
1116 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1117 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1117 | return false; | 1118 | return false; |
1118 | } | 1119 | } |
1119 | 1120 | ||
1120 | resource->setAddressBook( this ); | 1121 | resource->setAddressBook( this ); |
1121 | 1122 | ||
1122 | d->mManager->add( resource ); | 1123 | d->mManager->add( resource ); |
1123 | return true; | 1124 | return true; |
1124 | } | 1125 | } |
1125 | 1126 | ||
1126 | bool AddressBook::removeResource( Resource *resource ) | 1127 | bool AddressBook::removeResource( Resource *resource ) |
1127 | { | 1128 | { |
1128 | resource->close(); | 1129 | resource->close(); |
1129 | 1130 | ||
1130 | if ( resource == standardResource() ) | 1131 | if ( resource == standardResource() ) |
1131 | d->mManager->setStandardResource( 0 ); | 1132 | d->mManager->setStandardResource( 0 ); |
1132 | 1133 | ||
1133 | resource->setAddressBook( 0 ); | 1134 | resource->setAddressBook( 0 ); |
1134 | 1135 | ||
1135 | d->mManager->remove( resource ); | 1136 | d->mManager->remove( resource ); |
1136 | return true; | 1137 | return true; |
1137 | } | 1138 | } |
1138 | 1139 | ||
1139 | QPtrList<Resource> AddressBook::resources() | 1140 | QPtrList<Resource> AddressBook::resources() |
1140 | { | 1141 | { |
1141 | QPtrList<Resource> list; | 1142 | QPtrList<Resource> list; |
1142 | 1143 | ||
1143 | // qDebug("AddressBook::resources() 1"); | 1144 | // qDebug("AddressBook::resources() 1"); |
1144 | 1145 | ||
1145 | KRES::Manager<Resource>::ActiveIterator it; | 1146 | KRES::Manager<Resource>::ActiveIterator it; |
1146 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1147 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1147 | list.append( *it ); | 1148 | list.append( *it ); |
1148 | 1149 | ||
1149 | return list; | 1150 | return list; |
1150 | } | 1151 | } |
1151 | 1152 | ||
1152 | /*US | 1153 | /*US |
1153 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1154 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1154 | { | 1155 | { |
1155 | delete d->mErrorHandler; | 1156 | delete d->mErrorHandler; |
1156 | d->mErrorHandler = handler; | 1157 | d->mErrorHandler = handler; |
1157 | } | 1158 | } |
1158 | */ | 1159 | */ |
1159 | 1160 | ||
1160 | void AddressBook::error( const QString& msg ) | 1161 | void AddressBook::error( const QString& msg ) |
1161 | { | 1162 | { |
1162 | /*US | 1163 | /*US |
1163 | if ( !d->mErrorHandler ) // create default error handler | 1164 | if ( !d->mErrorHandler ) // create default error handler |
1164 | d->mErrorHandler = new ConsoleErrorHandler; | 1165 | d->mErrorHandler = new ConsoleErrorHandler; |
1165 | 1166 | ||
1166 | if ( d->mErrorHandler ) | 1167 | if ( d->mErrorHandler ) |
1167 | d->mErrorHandler->error( msg ); | 1168 | d->mErrorHandler->error( msg ); |
1168 | else | 1169 | else |
1169 | kdError(5700) << "no error handler defined" << endl; | 1170 | kdError(5700) << "no error handler defined" << endl; |
1170 | */ | 1171 | */ |
1171 | kdDebug(5700) << "msg" << endl; | 1172 | kdDebug(5700) << "msg" << endl; |
1172 | qDebug(msg); | 1173 | qDebug(msg); |
1173 | } | 1174 | } |
1174 | 1175 | ||
1175 | void AddressBook::deleteRemovedAddressees() | 1176 | void AddressBook::deleteRemovedAddressees() |
1176 | { | 1177 | { |
1177 | Addressee::List::Iterator it; | 1178 | Addressee::List::Iterator it; |
1178 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1179 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1179 | Resource *resource = (*it).resource(); | 1180 | Resource *resource = (*it).resource(); |
1180 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1181 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1181 | resource->removeAddressee( *it ); | 1182 | resource->removeAddressee( *it ); |
1182 | } | 1183 | } |
1183 | 1184 | ||
1184 | d->mRemovedAddressees.clear(); | 1185 | d->mRemovedAddressees.clear(); |
1185 | } | 1186 | } |
1186 | 1187 | ||
1187 | void AddressBook::setStandardResource( Resource *resource ) | 1188 | void AddressBook::setStandardResource( Resource *resource ) |
1188 | { | 1189 | { |
1189 | // qDebug("AddressBook::setStandardResource 1"); | 1190 | // qDebug("AddressBook::setStandardResource 1"); |
1190 | d->mManager->setStandardResource( resource ); | 1191 | d->mManager->setStandardResource( resource ); |
1191 | } | 1192 | } |
1192 | 1193 | ||
1193 | Resource *AddressBook::standardResource() | 1194 | Resource *AddressBook::standardResource() |
1194 | { | 1195 | { |
1195 | return d->mManager->standardResource(); | 1196 | return d->mManager->standardResource(); |
1196 | } | 1197 | } |
1197 | 1198 | ||
1198 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1199 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1199 | { | 1200 | { |
1200 | return d->mManager; | 1201 | return d->mManager; |
1201 | } | 1202 | } |
1202 | 1203 | ||
1203 | void AddressBook::cleanUp() | 1204 | void AddressBook::cleanUp() |
1204 | { | 1205 | { |
1205 | KRES::Manager<Resource>::ActiveIterator it; | 1206 | KRES::Manager<Resource>::ActiveIterator it; |
1206 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1207 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1207 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1208 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1208 | (*it)->cleanUp(); | 1209 | (*it)->cleanUp(); |
1209 | } | 1210 | } |
1210 | } | 1211 | } |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 23bba02..5edca06 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,348 +1,348 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef KABC_ADDRESSBOOK_H | 28 | #ifndef KABC_ADDRESSBOOK_H |
29 | #define KABC_ADDRESSBOOK_H | 29 | #define KABC_ADDRESSBOOK_H |
30 | 30 | ||
31 | #include <qobject.h> | 31 | #include <qobject.h> |
32 | 32 | ||
33 | #include <kresources/manager.h> | 33 | #include <kresources/manager.h> |
34 | #include <qptrlist.h> | 34 | #include <qptrlist.h> |
35 | 35 | ||
36 | #include "addressee.h" | 36 | #include "addressee.h" |
37 | #include "field.h" | 37 | #include "field.h" |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class ErrorHandler; | 41 | class ErrorHandler; |
42 | class Resource; | 42 | class Resource; |
43 | class Ticket; | 43 | class Ticket; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | @short Address Book | 46 | @short Address Book |
47 | 47 | ||
48 | This class provides access to a collection of address book entries. | 48 | This class provides access to a collection of address book entries. |
49 | */ | 49 | */ |
50 | class AddressBook : public QObject | 50 | class AddressBook : public QObject |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); | 54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); |
55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); | 55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); |
56 | friend class StdAddressBook; | 56 | friend class StdAddressBook; |
57 | 57 | ||
58 | public: | 58 | public: |
59 | /** | 59 | /** |
60 | @short Address Book Iterator | 60 | @short Address Book Iterator |
61 | 61 | ||
62 | This class provides an iterator for address book entries. | 62 | This class provides an iterator for address book entries. |
63 | */ | 63 | */ |
64 | class Iterator | 64 | class Iterator |
65 | { | 65 | { |
66 | public: | 66 | public: |
67 | Iterator(); | 67 | Iterator(); |
68 | Iterator( const Iterator & ); | 68 | Iterator( const Iterator & ); |
69 | ~Iterator(); | 69 | ~Iterator(); |
70 | 70 | ||
71 | Iterator &operator=( const Iterator & ); | 71 | Iterator &operator=( const Iterator & ); |
72 | const Addressee &operator*() const; | 72 | const Addressee &operator*() const; |
73 | Addressee &operator*(); | 73 | Addressee &operator*(); |
74 | Addressee* operator->(); | 74 | Addressee* operator->(); |
75 | Iterator &operator++(); | 75 | Iterator &operator++(); |
76 | Iterator &operator++(int); | 76 | Iterator &operator++(int); |
77 | Iterator &operator--(); | 77 | Iterator &operator--(); |
78 | Iterator &operator--(int); | 78 | Iterator &operator--(int); |
79 | bool operator==( const Iterator &it ); | 79 | bool operator==( const Iterator &it ); |
80 | bool operator!=( const Iterator &it ); | 80 | bool operator!=( const Iterator &it ); |
81 | 81 | ||
82 | struct IteratorData; | 82 | struct IteratorData; |
83 | IteratorData *d; | 83 | IteratorData *d; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | @short Address Book Const Iterator | 87 | @short Address Book Const Iterator |
88 | 88 | ||
89 | This class provides a const iterator for address book entries. | 89 | This class provides a const iterator for address book entries. |
90 | */ | 90 | */ |
91 | class ConstIterator | 91 | class ConstIterator |
92 | { | 92 | { |
93 | public: | 93 | public: |
94 | ConstIterator(); | 94 | ConstIterator(); |
95 | ConstIterator( const ConstIterator & ); | 95 | ConstIterator( const ConstIterator & ); |
96 | ~ConstIterator(); | 96 | ~ConstIterator(); |
97 | 97 | ||
98 | ConstIterator &operator=( const ConstIterator & ); | 98 | ConstIterator &operator=( const ConstIterator & ); |
99 | const Addressee &operator*() const; | 99 | const Addressee &operator*() const; |
100 | const Addressee* operator->() const; | 100 | const Addressee* operator->() const; |
101 | ConstIterator &operator++(); | 101 | ConstIterator &operator++(); |
102 | ConstIterator &operator++(int); | 102 | ConstIterator &operator++(int); |
103 | ConstIterator &operator--(); | 103 | ConstIterator &operator--(); |
104 | ConstIterator &operator--(int); | 104 | ConstIterator &operator--(int); |
105 | bool operator==( const ConstIterator &it ); | 105 | bool operator==( const ConstIterator &it ); |
106 | bool operator!=( const ConstIterator &it ); | 106 | bool operator!=( const ConstIterator &it ); |
107 | 107 | ||
108 | struct ConstIteratorData; | 108 | struct ConstIteratorData; |
109 | ConstIteratorData *d; | 109 | ConstIteratorData *d; |
110 | }; | 110 | }; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | Constructs a address book object. | 113 | Constructs a address book object. |
114 | 114 | ||
115 | @param format File format class. | 115 | @param format File format class. |
116 | */ | 116 | */ |
117 | AddressBook(); | 117 | AddressBook(); |
118 | AddressBook( const QString &config ); | 118 | AddressBook( const QString &config ); |
119 | AddressBook( const QString &config, const QString &family ); | 119 | AddressBook( const QString &config, const QString &family ); |
120 | virtual ~AddressBook(); | 120 | virtual ~AddressBook(); |
121 | 121 | ||
122 | /** | 122 | /** |
123 | Requests a ticket for saving the addressbook. Calling this function locks | 123 | Requests a ticket for saving the addressbook. Calling this function locks |
124 | the addressbook for all other processes. If the address book is already | 124 | the addressbook for all other processes. If the address book is already |
125 | locked the function returns 0. You need the returned @ref Ticket object | 125 | locked the function returns 0. You need the returned @ref Ticket object |
126 | for calling the @ref save() function. | 126 | for calling the @ref save() function. |
127 | 127 | ||
128 | @see save() | 128 | @see save() |
129 | */ | 129 | */ |
130 | Ticket *requestSaveTicket( Resource *resource=0 ); | 130 | Ticket *requestSaveTicket( Resource *resource=0 ); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Load address book from file. | 133 | Load address book from file. |
134 | */ | 134 | */ |
135 | bool load(); | 135 | bool load(); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Save address book. The address book is saved to the file, the Ticket | 138 | Save address book. The address book is saved to the file, the Ticket |
139 | object has been requested for by @ref requestSaveTicket(). | 139 | object has been requested for by @ref requestSaveTicket(). |
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | bool saveABphone( QString fileName ); | 145 | bool saveABphone( QString fileName ); |
146 | void smplifyAddressees(); | 146 | void smplifyAddressees(); |
147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); | 147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); |
148 | void export2File( QString fileName ); | 148 | void export2File( QString fileName ); |
149 | bool export2PhoneFormat( QStringList uids ,QString fileName ); | 149 | bool export2PhoneFormat( QStringList uids ,QString fileName ); |
150 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); | 150 | int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
151 | void setUntagged( bool setNonSyncTagged = false ); | 151 | void setUntagged( bool setNonSyncTagged = false ); |
152 | void removeUntagged(); | 152 | void removeUntagged(); |
153 | void findNewExtIds( QString fileName, QString currentSyncDevice ); | 153 | void findNewExtIds( QString fileName, QString currentSyncDevice ); |
154 | /** | 154 | /** |
155 | Returns a iterator for first entry of address book. | 155 | Returns a iterator for first entry of address book. |
156 | */ | 156 | */ |
157 | Iterator begin(); | 157 | Iterator begin(); |
158 | 158 | ||
159 | /** | 159 | /** |
160 | Returns a const iterator for first entry of address book. | 160 | Returns a const iterator for first entry of address book. |
161 | */ | 161 | */ |
162 | ConstIterator begin() const; | 162 | ConstIterator begin() const; |
163 | 163 | ||
164 | /** | 164 | /** |
165 | Returns a iterator for first entry of address book. | 165 | Returns a iterator for first entry of address book. |
166 | */ | 166 | */ |
167 | Iterator end(); | 167 | Iterator end(); |
168 | 168 | ||
169 | /** | 169 | /** |
170 | Returns a const iterator for first entry of address book. | 170 | Returns a const iterator for first entry of address book. |
171 | */ | 171 | */ |
172 | ConstIterator end() const; | 172 | ConstIterator end() const; |
173 | 173 | ||
174 | /** | 174 | /** |
175 | Removes all entries from address book. | 175 | Removes all entries from address book. |
176 | */ | 176 | */ |
177 | void clear(); | 177 | void clear(); |
178 | 178 | ||
179 | /** | 179 | /** |
180 | Insert an Addressee object into address book. If an object with the same | 180 | Insert an Addressee object into address book. If an object with the same |
181 | unique id already exists in the address book it it replaced by the new | 181 | unique id already exists in the address book it it replaced by the new |
182 | one. If not the new object is appended to the address book. | 182 | one. If not the new object is appended to the address book. |
183 | */ | 183 | */ |
184 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 184 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
185 | 185 | ||
186 | /** | 186 | /** |
187 | Removes entry from the address book. | 187 | Removes entry from the address book. |
188 | */ | 188 | */ |
189 | void removeAddressee( const Addressee & ); | 189 | void removeAddressee( const Addressee & ); |
190 | 190 | ||
191 | /** | 191 | /** |
192 | This is like @ref removeAddressee() just above, with the difference that | 192 | This is like @ref removeAddressee() just above, with the difference that |
193 | the first element is a iterator, returned by @ref begin(). | 193 | the first element is a iterator, returned by @ref begin(). |
194 | */ | 194 | */ |
195 | void removeAddressee( const Iterator & ); | 195 | void removeAddressee( const Iterator & ); |
196 | 196 | ||
197 | /** | 197 | /** |
198 | Find the specified entry in address book. Returns end(), if the entry | 198 | Find the specified entry in address book. Returns end(), if the entry |
199 | couldn't be found. | 199 | couldn't be found. |
200 | */ | 200 | */ |
201 | Iterator find( const Addressee & ); | 201 | Iterator find( const Addressee & ); |
202 | 202 | ||
203 | /** | 203 | /** |
204 | Find the entry specified by an unique id. Returns an empty Addressee | 204 | Find the entry specified by an unique id. Returns an empty Addressee |
205 | object, if the address book does not contain an entry with this id. | 205 | object, if the address book does not contain an entry with this id. |
206 | */ | 206 | */ |
207 | Addressee findByUid( const QString & ); | 207 | Addressee findByUid( const QString & ); |
208 | 208 | ||
209 | 209 | ||
210 | /** | 210 | /** |
211 | Returns a list of all addressees in the address book. This list can | 211 | Returns a list of all addressees in the address book. This list can |
212 | be sorted with @ref KABC::AddresseeList for example. | 212 | be sorted with @ref KABC::AddresseeList for example. |
213 | */ | 213 | */ |
214 | Addressee::List allAddressees(); | 214 | Addressee::List allAddressees(); |
215 | 215 | ||
216 | /** | 216 | /** |
217 | Find all entries with the specified name in the address book. Returns | 217 | Find all entries with the specified name in the address book. Returns |
218 | an empty list, if no entries could be found. | 218 | an empty list, if no entries could be found. |
219 | */ | 219 | */ |
220 | Addressee::List findByName( const QString & ); | 220 | Addressee::List findByName( const QString & ); |
221 | 221 | ||
222 | /** | 222 | /** |
223 | Find all entries with the specified email address in the address book. | 223 | Find all entries with the specified email address in the address book. |
224 | Returns an empty list, if no entries could be found. | 224 | Returns an empty list, if no entries could be found. |
225 | */ | 225 | */ |
226 | Addressee::List findByEmail( const QString & ); | 226 | Addressee::List findByEmail( const QString & ); |
227 | 227 | ||
228 | /** | 228 | /** |
229 | Find all entries wich have the specified category in the address book. | 229 | Find all entries wich have the specified category in the address book. |
230 | Returns an empty list, if no entries could be found. | 230 | Returns an empty list, if no entries could be found. |
231 | */ | 231 | */ |
232 | Addressee::List findByCategory( const QString & ); | 232 | Addressee::List findByCategory( const QString & ); |
233 | 233 | ||
234 | /** | 234 | /** |
235 | Return a string identifying this addressbook. | 235 | Return a string identifying this addressbook. |
236 | */ | 236 | */ |
237 | virtual QString identifier(); | 237 | virtual QString identifier(); |
238 | 238 | ||
239 | /** | 239 | /** |
240 | Used for debug output. | 240 | Used for debug output. |
241 | */ | 241 | */ |
242 | void dump() const; | 242 | void dump() const; |
243 | 243 | ||
244 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 244 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
245 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 245 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
246 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 246 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
247 | 247 | ||
248 | /** | 248 | /** |
249 | Return list of all Fields known to the address book which are associated | 249 | Return list of all Fields known to the address book which are associated |
250 | with the given field category. | 250 | with the given field category. |
251 | */ | 251 | */ |
252 | Field::List fields( int category = Field::All ); | 252 | Field::List fields( int category = Field::All ); |
253 | 253 | ||
254 | /** | 254 | /** |
255 | Add custom field to address book. | 255 | Add custom field to address book. |
256 | 256 | ||
257 | @param label User visible label of the field. | 257 | @param label User visible label of the field. |
258 | @param category Ored list of field categories. | 258 | @param category Ored list of field categories. |
259 | @param key Identifier used as key for reading and writing the field. | 259 | @param key Identifier used as key for reading and writing the field. |
260 | @param app String used as application key for reading and writing | 260 | @param app String used as application key for reading and writing |
261 | the field. | 261 | the field. |
262 | */ | 262 | */ |
263 | bool addCustomField( const QString &label, int category = Field::All, | 263 | bool addCustomField( const QString &label, int category = Field::All, |
264 | const QString &key = QString::null, | 264 | const QString &key = QString::null, |
265 | const QString &app = QString::null ); | 265 | const QString &app = QString::null ); |
266 | 266 | ||
267 | 267 | ||
268 | /** | 268 | /** |
269 | Add address book resource. | 269 | Add address book resource. |
270 | */ | 270 | */ |
271 | bool addResource( Resource * ); | 271 | bool addResource( Resource * ); |
272 | 272 | ||
273 | /** | 273 | /** |
274 | Remove address book resource. | 274 | Remove address book resource. |
275 | */ | 275 | */ |
276 | bool removeResource( Resource * ); | 276 | bool removeResource( Resource * ); |
277 | 277 | ||
278 | /** | 278 | /** |
279 | Return pointer list of all resources. | 279 | Return pointer list of all resources. |
280 | */ | 280 | */ |
281 | QPtrList<Resource> resources(); | 281 | QPtrList<Resource> resources(); |
282 | 282 | ||
283 | /** | 283 | /** |
284 | Set the @p ErrorHandler, that is used by @ref error() to | 284 | Set the @p ErrorHandler, that is used by @ref error() to |
285 | provide gui-independend error messages. | 285 | provide gui-independend error messages. |
286 | */ | 286 | */ |
287 | void setErrorHandler( ErrorHandler * ); | 287 | void setErrorHandler( ErrorHandler * ); |
288 | 288 | ||
289 | /** | 289 | /** |
290 | Shows gui independend error messages. | 290 | Shows gui independend error messages. |
291 | */ | 291 | */ |
292 | void error( const QString& ); | 292 | void error( const QString& ); |
293 | 293 | ||
294 | /** | 294 | /** |
295 | Query all resources to clean up their lock files | 295 | Query all resources to clean up their lock files |
296 | */ | 296 | */ |
297 | void cleanUp(); | 297 | void cleanUp(); |
298 | 298 | ||
299 | // sync stuff | 299 | // sync stuff |
300 | //Addressee::List getExternLastSyncAddressees(); | 300 | //Addressee::List getExternLastSyncAddressees(); |
301 | void resetTempSyncStat(); | 301 | void resetTempSyncStat(); |
302 | QStringList uidList(); | 302 | QStringList uidList(); |
303 | void removeSyncAddressees( bool removeDeleted = false ); | 303 | void removeSyncAddressees( bool removeDeleted = false ); |
304 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); | 304 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); |
305 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 305 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
306 | bool containsExternalUid( const QString& uid ); | 306 | bool containsExternalUid( const QString& uid ); |
307 | 307 | ||
308 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); | 308 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); |
309 | void postExternSync( AddressBook* aBook, const QString& csd ); | 309 | void postExternSync( AddressBook* aBook, const QString& csd ); |
310 | signals: | 310 | signals: |
311 | /** | 311 | /** |
312 | Emitted, when the address book has changed on disk. | 312 | Emitted, when the address book has changed on disk. |
313 | */ | 313 | */ |
314 | void addressBookChanged( AddressBook * ); | 314 | void addressBookChanged( AddressBook * ); |
315 | 315 | ||
316 | /** | 316 | /** |
317 | Emitted, when the address book has been locked for writing. | 317 | Emitted, when the address book has been locked for writing. |
318 | */ | 318 | */ |
319 | void addressBookLocked( AddressBook * ); | 319 | void addressBookLocked( AddressBook * ); |
320 | 320 | ||
321 | /** | 321 | /** |
322 | Emitted, when the address book has been unlocked. | 322 | Emitted, when the address book has been unlocked. |
323 | */ | 323 | */ |
324 | void addressBookUnlocked( AddressBook * ); | 324 | void addressBookUnlocked( AddressBook * ); |
325 | 325 | ||
326 | protected: | 326 | protected: |
327 | void deleteRemovedAddressees(); | 327 | void deleteRemovedAddressees(); |
328 | void setStandardResource( Resource * ); | 328 | void setStandardResource( Resource * ); |
329 | Resource *standardResource(); | 329 | Resource *standardResource(); |
330 | KRES::Manager<Resource> *resourceManager(); | 330 | KRES::Manager<Resource> *resourceManager(); |
331 | 331 | ||
332 | void init(const QString &config, const QString &family); | 332 | void init(const QString &config, const QString &family); |
333 | 333 | ||
334 | private: | 334 | private: |
335 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 335 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
336 | 336 | ||
337 | 337 | ||
338 | struct AddressBookData; | 338 | struct AddressBookData; |
339 | AddressBookData *d; | 339 | AddressBookData *d; |
340 | bool blockLSEchange; | 340 | bool blockLSEchange; |
341 | }; | 341 | }; |
342 | 342 | ||
343 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 343 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
344 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 344 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
345 | 345 | ||
346 | } | 346 | } |
347 | 347 | ||
348 | #endif | 348 | #endif |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 2cdf4bf..ba17c50 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -1,406 +1,406 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | 31 | ||
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | //US #include <qtimer.h> | 36 | //US #include <qtimer.h> |
37 | 37 | ||
38 | #include <kapplication.h> | 38 | #include <kapplication.h> |
39 | #include <kconfig.h> | 39 | #include <kconfig.h> |
40 | #include <kdebug.h> | 40 | #include <kdebug.h> |
41 | #include <klocale.h> | 41 | #include <klocale.h> |
42 | //US #include <ksavefile.h> | 42 | //US #include <ksavefile.h> |
43 | #include <kstandarddirs.h> | 43 | #include <kstandarddirs.h> |
44 | #include <kmessagebox.h> | 44 | #include <kmessagebox.h> |
45 | 45 | ||
46 | #include <sl/slzdb.h> | 46 | #include <sl/slzdb.h> |
47 | 47 | ||
48 | #include <libkdepim/ksyncprofile.h> | 48 | #include <libkdepim/ksyncprofile.h> |
49 | 49 | ||
50 | #include "resourcesharpdtmconfig.h" | 50 | #include "resourcesharpdtmconfig.h" |
51 | #include "resourcesharpdtm.h" | 51 | #include "resourcesharpdtm.h" |
52 | 52 | ||
53 | #include "stdaddressbook.h" | 53 | #include "stdaddressbook.h" |
54 | 54 | ||
55 | #include "sharpdtmconverter.h" | 55 | #include "sharpdtmconverter.h" |
56 | //#define ALLOW_LOCKING | 56 | //#define ALLOW_LOCKING |
57 | using namespace KABC; | 57 | using namespace KABC; |
58 | extern "C" | 58 | extern "C" |
59 | { | 59 | { |
60 | void *init_microkabc_sharpdtm() | 60 | void *init_microkabc_sharpdtm() |
61 | { | 61 | { |
62 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); | 62 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) | 66 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) |
67 | : Resource( config ), mConverter (0) | 67 | : Resource( config ), mConverter (0) |
68 | { | 68 | { |
69 | // we can not choose the filename. Therefore use the default to display | 69 | // we can not choose the filename. Therefore use the default to display |
70 | 70 | ||
71 | QString fileName = SlZDataBase::addressbookFileName(); | 71 | QString fileName = SlZDataBase::addressbookFileName(); |
72 | init( fileName ); | 72 | init( fileName ); |
73 | } | 73 | } |
74 | 74 | ||
75 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) | 75 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) |
76 | : Resource( 0, syncable ) | 76 | : Resource( 0 ) |
77 | { | 77 | { |
78 | init( fileName ); | 78 | init( fileName ); |
79 | } | 79 | } |
80 | 80 | ||
81 | void ResourceSharpDTM::init( const QString &fileName ) | 81 | void ResourceSharpDTM::init( const QString &fileName ) |
82 | { | 82 | { |
83 | 83 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 87 | ||
88 | setFileName( fileName ); | 88 | setFileName( fileName ); |
89 | } | 89 | } |
90 | 90 | ||
91 | ResourceSharpDTM::~ResourceSharpDTM() | 91 | ResourceSharpDTM::~ResourceSharpDTM() |
92 | { | 92 | { |
93 | if (mConverter != 0) | 93 | if (mConverter != 0) |
94 | delete mConverter; | 94 | delete mConverter; |
95 | 95 | ||
96 | if(mAccess != 0) | 96 | if(mAccess != 0) |
97 | delete mAccess; | 97 | delete mAccess; |
98 | } | 98 | } |
99 | 99 | ||
100 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 100 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
101 | { | 101 | { |
102 | Resource::writeConfig( config ); | 102 | Resource::writeConfig( config ); |
103 | } | 103 | } |
104 | 104 | ||
105 | Ticket *ResourceSharpDTM::requestSaveTicket() | 105 | Ticket *ResourceSharpDTM::requestSaveTicket() |
106 | { | 106 | { |
107 | 107 | ||
108 | 108 | ||
109 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | 109 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); |
110 | 110 | ||
111 | if ( !addressBook() ) return 0; | 111 | if ( !addressBook() ) return 0; |
112 | 112 | ||
113 | #ifdef ALLOW_LOCKING | 113 | #ifdef ALLOW_LOCKING |
114 | if ( !lock( fileName() ) ) { | 114 | if ( !lock( fileName() ) ) { |
115 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); | 115 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); |
116 | return 0; | 116 | return 0; |
117 | } | 117 | } |
118 | #endif | 118 | #endif |
119 | return createTicket( this ); | 119 | return createTicket( this ); |
120 | } | 120 | } |
121 | 121 | ||
122 | 122 | ||
123 | bool ResourceSharpDTM::doOpen() | 123 | bool ResourceSharpDTM::doOpen() |
124 | { | 124 | { |
125 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); | 125 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); |
126 | 126 | ||
127 | // the last parameter in the SlZDataBase constructor means "readonly" | 127 | // the last parameter in the SlZDataBase constructor means "readonly" |
128 | mAccess = new SlZDataBase(fileName(), | 128 | mAccess = new SlZDataBase(fileName(), |
129 | SlZDataBase::addressbookItems(), | 129 | SlZDataBase::addressbookItems(), |
130 | NULL, false); | 130 | NULL, false); |
131 | 131 | ||
132 | if ( !mAccess ) { | 132 | if ( !mAccess ) { |
133 | qDebug("Unable to load file() %s", fileName().latin1()); | 133 | qDebug("Unable to load file() %s", fileName().latin1()); |
134 | return false; | 134 | return false; |
135 | } | 135 | } |
136 | 136 | ||
137 | if (mConverter == 0) | 137 | if (mConverter == 0) |
138 | { | 138 | { |
139 | mConverter = new SharpDTMConverter(); | 139 | mConverter = new SharpDTMConverter(); |
140 | bool res = mConverter->init(); | 140 | bool res = mConverter->init(); |
141 | if ( !res ) | 141 | if ( !res ) |
142 | { | 142 | { |
143 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 143 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); |
144 | 144 | ||
145 | qDebug(msg); | 145 | qDebug(msg); |
146 | delete mAccess; | 146 | delete mAccess; |
147 | mAccess = 0; | 147 | mAccess = 0; |
148 | return false; | 148 | return false; |
149 | } | 149 | } |
150 | } | 150 | } |
151 | 151 | ||
152 | return true; | 152 | return true; |
153 | } | 153 | } |
154 | 154 | ||
155 | void ResourceSharpDTM::doClose() | 155 | void ResourceSharpDTM::doClose() |
156 | { | 156 | { |
157 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); | 157 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); |
158 | 158 | ||
159 | if(mAccess) | 159 | if(mAccess) |
160 | { | 160 | { |
161 | delete mAccess; | 161 | delete mAccess; |
162 | mAccess = 0; | 162 | mAccess = 0; |
163 | } | 163 | } |
164 | // it seems so, that deletion of access deletes backend as well | 164 | // it seems so, that deletion of access deletes backend as well |
165 | //delete backend; | 165 | //delete backend; |
166 | 166 | ||
167 | return; | 167 | return; |
168 | } | 168 | } |
169 | 169 | ||
170 | bool ResourceSharpDTM::load() | 170 | bool ResourceSharpDTM::load() |
171 | { | 171 | { |
172 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); | 172 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); |
173 | 173 | ||
174 | bool res = false; | 174 | bool res = false; |
175 | 175 | ||
176 | CardId id; | 176 | CardId id; |
177 | 177 | ||
178 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) | 178 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
179 | { | 179 | { |
180 | id = mAccess->cardId(); | 180 | id = mAccess->cardId(); |
181 | 181 | ||
182 | KABC::Addressee addressee; | 182 | KABC::Addressee addressee; |
183 | 183 | ||
184 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 184 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
185 | 185 | ||
186 | if ( !addressee.isEmpty() && res ) | 186 | if ( !addressee.isEmpty() && res ) |
187 | { | 187 | { |
188 | addressee.setResource( this ); | 188 | addressee.setResource( this ); |
189 | addressBook()->insertAddressee( addressee ); | 189 | addressBook()->insertAddressee( addressee ); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | return true; | 193 | return true; |
194 | } | 194 | } |
195 | 195 | ||
196 | bool ResourceSharpDTM::save( Ticket *ticket ) | 196 | bool ResourceSharpDTM::save( Ticket *ticket ) |
197 | { | 197 | { |
198 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); | 198 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); |
199 | 199 | ||
200 | mDirWatch.stopScan(); | 200 | mDirWatch.stopScan(); |
201 | 201 | ||
202 | KABC::AddressBook::Iterator it; | 202 | KABC::AddressBook::Iterator it; |
203 | bool res; | 203 | bool res; |
204 | KABC::Addressee::List changedAddressees; | 204 | KABC::Addressee::List changedAddressees; |
205 | typedef QMap<int,QString> AddresseeMap; | 205 | typedef QMap<int,QString> AddresseeMap; |
206 | AddresseeMap map; | 206 | AddresseeMap map; |
207 | CardId id ; | 207 | CardId id ; |
208 | 208 | ||
209 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 209 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
210 | 210 | ||
211 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 211 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
212 | QString uid = (*it).originalExternalUID(); | 212 | QString uid = (*it).originalExternalUID(); |
213 | bool res; | 213 | bool res; |
214 | if ( uid.isEmpty() ) | 214 | if ( uid.isEmpty() ) |
215 | id = 0; | 215 | id = 0; |
216 | else | 216 | else |
217 | id = uid.toUInt(); | 217 | id = uid.toUInt(); |
218 | KABC::Addressee addressee = (*it); | 218 | KABC::Addressee addressee = (*it); |
219 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | 219 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { |
220 | res = mAccess->startEditCard(id); | 220 | res = mAccess->startEditCard(id); |
221 | if (res == true) | 221 | if (res == true) |
222 | { | 222 | { |
223 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 223 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
224 | if (res == true) | 224 | if (res == true) |
225 | { | 225 | { |
226 | res = mAccess->finishEditCard(&id); | 226 | res = mAccess->finishEditCard(&id); |
227 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 227 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
228 | //(*it).setExternalUID( QString::number( id ) ); | 228 | //(*it).setExternalUID( QString::number( id ) ); |
229 | //(*it).setOriginalExternalUID( QString::number( id ) ); | 229 | //(*it).setOriginalExternalUID( QString::number( id ) ); |
230 | map.insert(id,(*it).uid()); | 230 | map.insert(id,(*it).uid()); |
231 | if (res == false) | 231 | if (res == false) |
232 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 232 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
233 | 233 | ||
234 | } | 234 | } |
235 | else | 235 | else |
236 | { | 236 | { |
237 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 237 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
238 | mAccess->cancelEditCard(); | 238 | mAccess->cancelEditCard(); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 242 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
243 | res = mAccess->deleteCard(&id); | 243 | res = mAccess->deleteCard(&id); |
244 | if ( !res ) | 244 | if ( !res ) |
245 | qDebug("delete error "); | 245 | qDebug("delete error "); |
246 | 246 | ||
247 | 247 | ||
248 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 248 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
249 | //changed | 249 | //changed |
250 | res = mAccess->startEditCard(id); | 250 | res = mAccess->startEditCard(id); |
251 | if (res == true) | 251 | if (res == true) |
252 | { | 252 | { |
253 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 253 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
254 | if (res == true) | 254 | if (res == true) |
255 | { | 255 | { |
256 | res = mAccess->finishEditCard(&id); | 256 | res = mAccess->finishEditCard(&id); |
257 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | 257 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); |
258 | map.insert(id,(*it).uid()); | 258 | map.insert(id,(*it).uid()); |
259 | if (res == false) | 259 | if (res == false) |
260 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 260 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
261 | 261 | ||
262 | } | 262 | } |
263 | else | 263 | else |
264 | { | 264 | { |
265 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 265 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
266 | mAccess->cancelEditCard(); | 266 | mAccess->cancelEditCard(); |
267 | } | 267 | } |
268 | } | 268 | } |
269 | } | 269 | } |
270 | } | 270 | } |
271 | 271 | ||
272 | } | 272 | } |
273 | AddresseeMap::Iterator itam; | 273 | AddresseeMap::Iterator itam; |
274 | for ( res=mAccess->first(); res == true; res=mAccess->next()) | 274 | for ( res=mAccess->first(); res == true; res=mAccess->next()) |
275 | { | 275 | { |
276 | id = mAccess->cardId(); | 276 | id = mAccess->cardId(); |
277 | int idint = id; | 277 | int idint = id; |
278 | itam = map.find( idint ); | 278 | itam = map.find( idint ); |
279 | if ( itam != map.end() ) { | 279 | if ( itam != map.end() ) { |
280 | KABC::Addressee addressee; | 280 | KABC::Addressee addressee; |
281 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 281 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
282 | 282 | ||
283 | if ( !addressee.isEmpty() && res ) | 283 | if ( !addressee.isEmpty() && res ) |
284 | { | 284 | { |
285 | addressee.setResource( this ); | 285 | addressee.setResource( this ); |
286 | addressee.setUid( itam.data() ); | 286 | addressee.setUid( itam.data() ); |
287 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 287 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
288 | addressBook()->insertAddressee( addressee , false ); | 288 | addressBook()->insertAddressee( addressee , false ); |
289 | } | 289 | } |
290 | } | 290 | } |
291 | } | 291 | } |
292 | 292 | ||
293 | //US mAccess->save(); | 293 | //US mAccess->save(); |
294 | 294 | ||
295 | mDirWatch.startScan(); | 295 | mDirWatch.startScan(); |
296 | delete ticket; | 296 | delete ticket; |
297 | unlock( fileName() ); | 297 | unlock( fileName() ); |
298 | 298 | ||
299 | return true; | 299 | return true; |
300 | } | 300 | } |
301 | 301 | ||
302 | bool ResourceSharpDTM::lock( const QString &lockfileName ) | 302 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
303 | { | 303 | { |
304 | #ifdef ALLOW_LOCKING | 304 | #ifdef ALLOW_LOCKING |
305 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); | 305 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); |
306 | 306 | ||
307 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | 307 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; |
308 | 308 | ||
309 | QString fn = lockfileName; | 309 | QString fn = lockfileName; |
310 | 310 | ||
311 | KURL url(fn); | 311 | KURL url(fn); |
312 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 312 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
313 | 313 | ||
314 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 314 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
315 | 315 | ||
316 | if (QFile::exists( lockName )) | 316 | if (QFile::exists( lockName )) |
317 | { | 317 | { |
318 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); | 318 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); |
319 | return false; | 319 | return false; |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | QString lockUniqueName; | 323 | QString lockUniqueName; |
324 | lockUniqueName = fn + KApplication::randomString( 8 ); | 324 | lockUniqueName = fn + KApplication::randomString( 8 ); |
325 | 325 | ||
326 | url = lockUniqueName; | 326 | url = lockUniqueName; |
327 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 327 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
328 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 328 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
329 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 329 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
330 | 330 | ||
331 | // Create unique file | 331 | // Create unique file |
332 | QFile file( mLockUniqueName ); | 332 | QFile file( mLockUniqueName ); |
333 | file.open( IO_WriteOnly ); | 333 | file.open( IO_WriteOnly ); |
334 | file.close(); | 334 | file.close(); |
335 | 335 | ||
336 | // Create lock file | 336 | // Create lock file |
337 | int result = 0; | 337 | int result = 0; |
338 | #ifndef _WIN32_ | 338 | #ifndef _WIN32_ |
339 | result = ::link( QFile::encodeName( mLockUniqueName ), | 339 | result = ::link( QFile::encodeName( mLockUniqueName ), |
340 | QFile::encodeName( lockName ) ); | 340 | QFile::encodeName( lockName ) ); |
341 | #endif | 341 | #endif |
342 | if ( result == 0 ) { | 342 | if ( result == 0 ) { |
343 | addressBook()->emitAddressBookLocked(); | 343 | addressBook()->emitAddressBookLocked(); |
344 | return true; | 344 | return true; |
345 | } | 345 | } |
346 | 346 | ||
347 | // TODO: check stat | 347 | // TODO: check stat |
348 | 348 | ||
349 | return false; | 349 | return false; |
350 | #else | 350 | #else |
351 | return true; | 351 | return true; |
352 | #endif | 352 | #endif |
353 | } | 353 | } |
354 | 354 | ||
355 | void ResourceSharpDTM::unlock( const QString &fileName ) | 355 | void ResourceSharpDTM::unlock( const QString &fileName ) |
356 | { | 356 | { |
357 | #ifdef ALLOW_LOCKING | 357 | #ifdef ALLOW_LOCKING |
358 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | 358 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); |
359 | 359 | ||
360 | QString fn = fileName; | 360 | QString fn = fileName; |
361 | KURL url(fn); | 361 | KURL url(fn); |
362 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 362 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
363 | 363 | ||
364 | QFile::remove( lockName ); | 364 | QFile::remove( lockName ); |
365 | QFile::remove( mLockUniqueName ); | 365 | QFile::remove( mLockUniqueName ); |
366 | addressBook()->emitAddressBookUnlocked(); | 366 | addressBook()->emitAddressBookUnlocked(); |
367 | #endif | 367 | #endif |
368 | } | 368 | } |
369 | 369 | ||
370 | void ResourceSharpDTM::setFileName( const QString &newFileName ) | 370 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
371 | { | 371 | { |
372 | mDirWatch.stopScan(); | 372 | mDirWatch.stopScan(); |
373 | mDirWatch.removeFile( fileName() ); | 373 | mDirWatch.removeFile( fileName() ); |
374 | 374 | ||
375 | Resource::setFileName( newFileName ); | 375 | Resource::setFileName( newFileName ); |
376 | 376 | ||
377 | mDirWatch.addFile( fileName() ); | 377 | mDirWatch.addFile( fileName() ); |
378 | mDirWatch.startScan(); | 378 | mDirWatch.startScan(); |
379 | 379 | ||
380 | } | 380 | } |
381 | 381 | ||
382 | void ResourceSharpDTM::fileChanged() | 382 | void ResourceSharpDTM::fileChanged() |
383 | { | 383 | { |
384 | // There is a small theoretical chance that KDirWatch calls us before | 384 | // There is a small theoretical chance that KDirWatch calls us before |
385 | // we are fully constructed | 385 | // we are fully constructed |
386 | if (!addressBook()) | 386 | if (!addressBook()) |
387 | return; | 387 | return; |
388 | 388 | ||
389 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 389 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
391 | load(); | 391 | load(); |
392 | addressBook()->emitAddressBookChanged(); | 392 | addressBook()->emitAddressBookChanged(); |
393 | } | 393 | } |
394 | } | 394 | } |
395 | 395 | ||
396 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 396 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) |
397 | { | 397 | { |
398 | } | 398 | } |
399 | 399 | ||
400 | void ResourceSharpDTM::cleanUp() | 400 | void ResourceSharpDTM::cleanUp() |
401 | { | 401 | { |
402 | unlock( fileName() ); | 402 | unlock( fileName() ); |
403 | } | 403 | } |
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||