-rw-r--r-- | kabc/addressbook.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 8 | ||||
-rw-r--r-- | kabc/stdaddressbook.cpp | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 97bd3ef..0838157 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,641 +1,641 @@ | |||
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 | 41 | ||
42 | #include <kglobal.h> | 42 | #include <kglobal.h> |
43 | #include <klocale.h> | 43 | #include <klocale.h> |
44 | #include <kdebug.h> | 44 | #include <kdebug.h> |
45 | #include "addressbook.h" | 45 | #include "addressbook.h" |
46 | #include "resource.h" | 46 | #include "resource.h" |
47 | 47 | ||
48 | //US #include "addressbook.moc" | 48 | //US #include "addressbook.moc" |
49 | 49 | ||
50 | using namespace KABC; | 50 | using namespace KABC; |
51 | 51 | ||
52 | struct AddressBook::AddressBookData | 52 | struct AddressBook::AddressBookData |
53 | { | 53 | { |
54 | Addressee::List mAddressees; | 54 | Addressee::List mAddressees; |
55 | Addressee::List mRemovedAddressees; | 55 | Addressee::List mRemovedAddressees; |
56 | Field::List mAllFields; | 56 | Field::List mAllFields; |
57 | KConfig *mConfig; | 57 | KConfig *mConfig; |
58 | KRES::Manager<Resource> *mManager; | 58 | KRES::Manager<Resource> *mManager; |
59 | //US ErrorHandler *mErrorHandler; | 59 | //US ErrorHandler *mErrorHandler; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | struct AddressBook::Iterator::IteratorData | 62 | struct AddressBook::Iterator::IteratorData |
63 | { | 63 | { |
64 | Addressee::List::Iterator mIt; | 64 | Addressee::List::Iterator mIt; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | struct AddressBook::ConstIterator::ConstIteratorData | 67 | struct AddressBook::ConstIterator::ConstIteratorData |
68 | { | 68 | { |
69 | Addressee::List::ConstIterator mIt; | 69 | Addressee::List::ConstIterator mIt; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | AddressBook::Iterator::Iterator() | 72 | AddressBook::Iterator::Iterator() |
73 | { | 73 | { |
74 | d = new IteratorData; | 74 | d = new IteratorData; |
75 | } | 75 | } |
76 | 76 | ||
77 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 77 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
78 | { | 78 | { |
79 | d = new IteratorData; | 79 | d = new IteratorData; |
80 | d->mIt = i.d->mIt; | 80 | d->mIt = i.d->mIt; |
81 | } | 81 | } |
82 | 82 | ||
83 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 83 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
84 | { | 84 | { |
85 | if( this == &i ) return *this; // guard against self assignment | 85 | if( this == &i ) return *this; // guard against self assignment |
86 | delete d; // delete the old data the Iterator was completely constructed before | 86 | delete d; // delete the old data the Iterator was completely constructed before |
87 | d = new IteratorData; | 87 | d = new IteratorData; |
88 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
89 | return *this; | 89 | return *this; |
90 | } | 90 | } |
91 | 91 | ||
92 | AddressBook::Iterator::~Iterator() | 92 | AddressBook::Iterator::~Iterator() |
93 | { | 93 | { |
94 | delete d; | 94 | delete d; |
95 | } | 95 | } |
96 | 96 | ||
97 | const Addressee &AddressBook::Iterator::operator*() const | 97 | const Addressee &AddressBook::Iterator::operator*() const |
98 | { | 98 | { |
99 | return *(d->mIt); | 99 | return *(d->mIt); |
100 | } | 100 | } |
101 | 101 | ||
102 | Addressee &AddressBook::Iterator::operator*() | 102 | Addressee &AddressBook::Iterator::operator*() |
103 | { | 103 | { |
104 | return *(d->mIt); | 104 | return *(d->mIt); |
105 | } | 105 | } |
106 | 106 | ||
107 | Addressee *AddressBook::Iterator::operator->() | 107 | Addressee *AddressBook::Iterator::operator->() |
108 | { | 108 | { |
109 | return &(*(d->mIt)); | 109 | return &(*(d->mIt)); |
110 | } | 110 | } |
111 | 111 | ||
112 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 112 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
113 | { | 113 | { |
114 | (d->mIt)++; | 114 | (d->mIt)++; |
115 | return *this; | 115 | return *this; |
116 | } | 116 | } |
117 | 117 | ||
118 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 118 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
119 | { | 119 | { |
120 | (d->mIt)++; | 120 | (d->mIt)++; |
121 | return *this; | 121 | return *this; |
122 | } | 122 | } |
123 | 123 | ||
124 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 124 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
125 | { | 125 | { |
126 | (d->mIt)--; | 126 | (d->mIt)--; |
127 | return *this; | 127 | return *this; |
128 | } | 128 | } |
129 | 129 | ||
130 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 130 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
131 | { | 131 | { |
132 | (d->mIt)--; | 132 | (d->mIt)--; |
133 | return *this; | 133 | return *this; |
134 | } | 134 | } |
135 | 135 | ||
136 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 136 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
137 | { | 137 | { |
138 | return ( d->mIt == it.d->mIt ); | 138 | return ( d->mIt == it.d->mIt ); |
139 | } | 139 | } |
140 | 140 | ||
141 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 141 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
142 | { | 142 | { |
143 | return ( d->mIt != it.d->mIt ); | 143 | return ( d->mIt != it.d->mIt ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | AddressBook::ConstIterator::ConstIterator() | 147 | AddressBook::ConstIterator::ConstIterator() |
148 | { | 148 | { |
149 | d = new ConstIteratorData; | 149 | d = new ConstIteratorData; |
150 | } | 150 | } |
151 | 151 | ||
152 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 152 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
153 | { | 153 | { |
154 | d = new ConstIteratorData; | 154 | d = new ConstIteratorData; |
155 | d->mIt = i.d->mIt; | 155 | d->mIt = i.d->mIt; |
156 | } | 156 | } |
157 | 157 | ||
158 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 158 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
159 | { | 159 | { |
160 | if( this == &i ) return *this; // guard for self assignment | 160 | if( this == &i ) return *this; // guard for self assignment |
161 | delete d; // delete the old data because the Iterator was really constructed before | 161 | delete d; // delete the old data because the Iterator was really constructed before |
162 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
163 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
164 | return *this; | 164 | return *this; |
165 | } | 165 | } |
166 | 166 | ||
167 | AddressBook::ConstIterator::~ConstIterator() | 167 | AddressBook::ConstIterator::~ConstIterator() |
168 | { | 168 | { |
169 | delete d; | 169 | delete d; |
170 | } | 170 | } |
171 | 171 | ||
172 | const Addressee &AddressBook::ConstIterator::operator*() const | 172 | const Addressee &AddressBook::ConstIterator::operator*() const |
173 | { | 173 | { |
174 | return *(d->mIt); | 174 | return *(d->mIt); |
175 | } | 175 | } |
176 | 176 | ||
177 | const Addressee* AddressBook::ConstIterator::operator->() const | 177 | const Addressee* AddressBook::ConstIterator::operator->() const |
178 | { | 178 | { |
179 | return &(*(d->mIt)); | 179 | return &(*(d->mIt)); |
180 | } | 180 | } |
181 | 181 | ||
182 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 182 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
183 | { | 183 | { |
184 | (d->mIt)++; | 184 | (d->mIt)++; |
185 | return *this; | 185 | return *this; |
186 | } | 186 | } |
187 | 187 | ||
188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
189 | { | 189 | { |
190 | (d->mIt)++; | 190 | (d->mIt)++; |
191 | return *this; | 191 | return *this; |
192 | } | 192 | } |
193 | 193 | ||
194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
195 | { | 195 | { |
196 | (d->mIt)--; | 196 | (d->mIt)--; |
197 | return *this; | 197 | return *this; |
198 | } | 198 | } |
199 | 199 | ||
200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
201 | { | 201 | { |
202 | (d->mIt)--; | 202 | (d->mIt)--; |
203 | return *this; | 203 | return *this; |
204 | } | 204 | } |
205 | 205 | ||
206 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 206 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
207 | { | 207 | { |
208 | return ( d->mIt == it.d->mIt ); | 208 | return ( d->mIt == it.d->mIt ); |
209 | } | 209 | } |
210 | 210 | ||
211 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 211 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
212 | { | 212 | { |
213 | return ( d->mIt != it.d->mIt ); | 213 | return ( d->mIt != it.d->mIt ); |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | AddressBook::AddressBook() | 217 | AddressBook::AddressBook() |
218 | { | 218 | { |
219 | init(0); | 219 | init(0); |
220 | } | 220 | } |
221 | 221 | ||
222 | AddressBook::AddressBook( const QString &config ) | 222 | AddressBook::AddressBook( const QString &config ) |
223 | { | 223 | { |
224 | init(config); | 224 | init(config); |
225 | } | 225 | } |
226 | 226 | ||
227 | void AddressBook::init(const QString &config) | 227 | void AddressBook::init(const QString &config) |
228 | { | 228 | { |
229 | d = new AddressBookData; | 229 | d = new AddressBookData; |
230 | if (config != 0) { | 230 | if (config != 0) { |
231 | d->mConfig = new KConfig( config ); | 231 | d->mConfig = new KConfig( config ); |
232 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 232 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
233 | } | 233 | } |
234 | else { | 234 | else { |
235 | d->mConfig = 0; | 235 | d->mConfig = 0; |
236 | // qDebug("AddressBook::init 1 config=0"); | 236 | // qDebug("AddressBook::init 1 config=0"); |
237 | } | 237 | } |
238 | 238 | ||
239 | //US d->mErrorHandler = 0; | 239 | //US d->mErrorHandler = 0; |
240 | d->mManager = new KRES::Manager<Resource>( "contact" ); | 240 | d->mManager = new KRES::Manager<Resource>( "contact" ); |
241 | d->mManager->readConfig( d->mConfig ); | 241 | d->mManager->readConfig( d->mConfig ); |
242 | } | 242 | } |
243 | 243 | ||
244 | AddressBook::~AddressBook() | 244 | AddressBook::~AddressBook() |
245 | { | 245 | { |
246 | delete d->mConfig; d->mConfig = 0; | 246 | delete d->mConfig; d->mConfig = 0; |
247 | delete d->mManager; d->mManager = 0; | 247 | delete d->mManager; d->mManager = 0; |
248 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 248 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
249 | delete d; d = 0; | 249 | delete d; d = 0; |
250 | } | 250 | } |
251 | 251 | ||
252 | bool AddressBook::load() | 252 | bool AddressBook::load() |
253 | { | 253 | { |
254 | kdDebug(5700) << "AddressBook::load()" << endl; | 254 | |
255 | 255 | ||
256 | clear(); | 256 | clear(); |
257 | 257 | ||
258 | KRES::Manager<Resource>::ActiveIterator it; | 258 | KRES::Manager<Resource>::ActiveIterator it; |
259 | bool ok = true; | 259 | bool ok = true; |
260 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 260 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
261 | if ( !(*it)->load() ) { | 261 | if ( !(*it)->load() ) { |
262 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 262 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
263 | ok = false; | 263 | ok = false; |
264 | } | 264 | } |
265 | 265 | ||
266 | // mark all addressees as unchanged | 266 | // mark all addressees as unchanged |
267 | Addressee::List::Iterator addrIt; | 267 | Addressee::List::Iterator addrIt; |
268 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) | 268 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) |
269 | (*addrIt).setChanged( false ); | 269 | (*addrIt).setChanged( false ); |
270 | 270 | ||
271 | return ok; | 271 | return ok; |
272 | } | 272 | } |
273 | 273 | ||
274 | bool AddressBook::save( Ticket *ticket ) | 274 | bool AddressBook::save( Ticket *ticket ) |
275 | { | 275 | { |
276 | kdDebug(5700) << "AddressBook::save()"<< endl; | 276 | kdDebug(5700) << "AddressBook::save()"<< endl; |
277 | 277 | ||
278 | if ( ticket->resource() ) { | 278 | if ( ticket->resource() ) { |
279 | deleteRemovedAddressees(); | 279 | deleteRemovedAddressees(); |
280 | 280 | ||
281 | return ticket->resource()->save( ticket ); | 281 | return ticket->resource()->save( ticket ); |
282 | } | 282 | } |
283 | 283 | ||
284 | return false; | 284 | return false; |
285 | } | 285 | } |
286 | 286 | ||
287 | AddressBook::Iterator AddressBook::begin() | 287 | AddressBook::Iterator AddressBook::begin() |
288 | { | 288 | { |
289 | Iterator it = Iterator(); | 289 | Iterator it = Iterator(); |
290 | it.d->mIt = d->mAddressees.begin(); | 290 | it.d->mIt = d->mAddressees.begin(); |
291 | return it; | 291 | return it; |
292 | } | 292 | } |
293 | 293 | ||
294 | AddressBook::ConstIterator AddressBook::begin() const | 294 | AddressBook::ConstIterator AddressBook::begin() const |
295 | { | 295 | { |
296 | ConstIterator it = ConstIterator(); | 296 | ConstIterator it = ConstIterator(); |
297 | it.d->mIt = d->mAddressees.begin(); | 297 | it.d->mIt = d->mAddressees.begin(); |
298 | return it; | 298 | return it; |
299 | } | 299 | } |
300 | 300 | ||
301 | AddressBook::Iterator AddressBook::end() | 301 | AddressBook::Iterator AddressBook::end() |
302 | { | 302 | { |
303 | Iterator it = Iterator(); | 303 | Iterator it = Iterator(); |
304 | it.d->mIt = d->mAddressees.end(); | 304 | it.d->mIt = d->mAddressees.end(); |
305 | return it; | 305 | return it; |
306 | } | 306 | } |
307 | 307 | ||
308 | AddressBook::ConstIterator AddressBook::end() const | 308 | AddressBook::ConstIterator AddressBook::end() const |
309 | { | 309 | { |
310 | ConstIterator it = ConstIterator(); | 310 | ConstIterator it = ConstIterator(); |
311 | it.d->mIt = d->mAddressees.end(); | 311 | it.d->mIt = d->mAddressees.end(); |
312 | return it; | 312 | return it; |
313 | } | 313 | } |
314 | 314 | ||
315 | void AddressBook::clear() | 315 | void AddressBook::clear() |
316 | { | 316 | { |
317 | d->mAddressees.clear(); | 317 | d->mAddressees.clear(); |
318 | } | 318 | } |
319 | 319 | ||
320 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 320 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
321 | { | 321 | { |
322 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 322 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
323 | 323 | ||
324 | if ( !resource ) | 324 | if ( !resource ) |
325 | { | 325 | { |
326 | qDebug("AddressBook::requestSaveTicket no resource" ); | 326 | qDebug("AddressBook::requestSaveTicket no resource" ); |
327 | resource = standardResource(); | 327 | resource = standardResource(); |
328 | } | 328 | } |
329 | 329 | ||
330 | KRES::Manager<Resource>::ActiveIterator it; | 330 | KRES::Manager<Resource>::ActiveIterator it; |
331 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 331 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
332 | if ( (*it) == resource ) { | 332 | if ( (*it) == resource ) { |
333 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 333 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
334 | return 0; | 334 | return 0; |
335 | else | 335 | else |
336 | return (*it)->requestSaveTicket(); | 336 | return (*it)->requestSaveTicket(); |
337 | } | 337 | } |
338 | } | 338 | } |
339 | 339 | ||
340 | return 0; | 340 | return 0; |
341 | } | 341 | } |
342 | 342 | ||
343 | void AddressBook::insertAddressee( const Addressee &a ) | 343 | void AddressBook::insertAddressee( const Addressee &a ) |
344 | { | 344 | { |
345 | Addressee::List::Iterator it; | 345 | Addressee::List::Iterator it; |
346 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 346 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
347 | if ( a.uid() == (*it).uid() ) { | 347 | if ( a.uid() == (*it).uid() ) { |
348 | bool changed = false; | 348 | bool changed = false; |
349 | Addressee addr = a; | 349 | Addressee addr = a; |
350 | if ( addr != (*it) ) | 350 | if ( addr != (*it) ) |
351 | changed = true; | 351 | changed = true; |
352 | 352 | ||
353 | (*it) = a; | 353 | (*it) = a; |
354 | if ( (*it).resource() == 0 ) | 354 | if ( (*it).resource() == 0 ) |
355 | (*it).setResource( standardResource() ); | 355 | (*it).setResource( standardResource() ); |
356 | 356 | ||
357 | if ( changed ) { | 357 | if ( changed ) { |
358 | (*it).setRevision( QDateTime::currentDateTime() ); | 358 | (*it).setRevision( QDateTime::currentDateTime() ); |
359 | (*it).setChanged( true ); | 359 | (*it).setChanged( true ); |
360 | } | 360 | } |
361 | 361 | ||
362 | return; | 362 | return; |
363 | } | 363 | } |
364 | } | 364 | } |
365 | d->mAddressees.append( a ); | 365 | d->mAddressees.append( a ); |
366 | Addressee& addr = d->mAddressees.last(); | 366 | Addressee& addr = d->mAddressees.last(); |
367 | if ( addr.resource() == 0 ) | 367 | if ( addr.resource() == 0 ) |
368 | addr.setResource( standardResource() ); | 368 | addr.setResource( standardResource() ); |
369 | 369 | ||
370 | addr.setChanged( true ); | 370 | addr.setChanged( true ); |
371 | } | 371 | } |
372 | 372 | ||
373 | void AddressBook::removeAddressee( const Addressee &a ) | 373 | void AddressBook::removeAddressee( const Addressee &a ) |
374 | { | 374 | { |
375 | Iterator it; | 375 | Iterator it; |
376 | for ( it = begin(); it != end(); ++it ) { | 376 | for ( it = begin(); it != end(); ++it ) { |
377 | if ( a.uid() == (*it).uid() ) { | 377 | if ( a.uid() == (*it).uid() ) { |
378 | removeAddressee( it ); | 378 | removeAddressee( it ); |
379 | return; | 379 | return; |
380 | } | 380 | } |
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | void AddressBook::removeAddressee( const Iterator &it ) | 384 | void AddressBook::removeAddressee( const Iterator &it ) |
385 | { | 385 | { |
386 | d->mRemovedAddressees.append( (*it) ); | 386 | d->mRemovedAddressees.append( (*it) ); |
387 | d->mAddressees.remove( it.d->mIt ); | 387 | d->mAddressees.remove( it.d->mIt ); |
388 | } | 388 | } |
389 | 389 | ||
390 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 390 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
391 | { | 391 | { |
392 | Iterator it; | 392 | Iterator it; |
393 | for ( it = begin(); it != end(); ++it ) { | 393 | for ( it = begin(); it != end(); ++it ) { |
394 | if ( a.uid() == (*it).uid() ) { | 394 | if ( a.uid() == (*it).uid() ) { |
395 | return it; | 395 | return it; |
396 | } | 396 | } |
397 | } | 397 | } |
398 | return end(); | 398 | return end(); |
399 | } | 399 | } |
400 | 400 | ||
401 | Addressee AddressBook::findByUid( const QString &uid ) | 401 | Addressee AddressBook::findByUid( const QString &uid ) |
402 | { | 402 | { |
403 | Iterator it; | 403 | Iterator it; |
404 | for ( it = begin(); it != end(); ++it ) { | 404 | for ( it = begin(); it != end(); ++it ) { |
405 | if ( uid == (*it).uid() ) { | 405 | if ( uid == (*it).uid() ) { |
406 | return *it; | 406 | return *it; |
407 | } | 407 | } |
408 | } | 408 | } |
409 | return Addressee(); | 409 | return Addressee(); |
410 | } | 410 | } |
411 | 411 | ||
412 | Addressee::List AddressBook::allAddressees() | 412 | Addressee::List AddressBook::allAddressees() |
413 | { | 413 | { |
414 | return d->mAddressees; | 414 | return d->mAddressees; |
415 | } | 415 | } |
416 | 416 | ||
417 | Addressee::List AddressBook::findByName( const QString &name ) | 417 | Addressee::List AddressBook::findByName( const QString &name ) |
418 | { | 418 | { |
419 | Addressee::List results; | 419 | Addressee::List results; |
420 | 420 | ||
421 | Iterator it; | 421 | Iterator it; |
422 | for ( it = begin(); it != end(); ++it ) { | 422 | for ( it = begin(); it != end(); ++it ) { |
423 | if ( name == (*it).name() ) { | 423 | if ( name == (*it).name() ) { |
424 | results.append( *it ); | 424 | results.append( *it ); |
425 | } | 425 | } |
426 | } | 426 | } |
427 | 427 | ||
428 | return results; | 428 | return results; |
429 | } | 429 | } |
430 | 430 | ||
431 | Addressee::List AddressBook::findByEmail( const QString &email ) | 431 | Addressee::List AddressBook::findByEmail( const QString &email ) |
432 | { | 432 | { |
433 | Addressee::List results; | 433 | Addressee::List results; |
434 | QStringList mailList; | 434 | QStringList mailList; |
435 | 435 | ||
436 | Iterator it; | 436 | Iterator it; |
437 | for ( it = begin(); it != end(); ++it ) { | 437 | for ( it = begin(); it != end(); ++it ) { |
438 | mailList = (*it).emails(); | 438 | mailList = (*it).emails(); |
439 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 439 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
440 | if ( email == (*ite) ) { | 440 | if ( email == (*ite) ) { |
441 | results.append( *it ); | 441 | results.append( *it ); |
442 | } | 442 | } |
443 | } | 443 | } |
444 | } | 444 | } |
445 | 445 | ||
446 | return results; | 446 | return results; |
447 | } | 447 | } |
448 | 448 | ||
449 | Addressee::List AddressBook::findByCategory( const QString &category ) | 449 | Addressee::List AddressBook::findByCategory( const QString &category ) |
450 | { | 450 | { |
451 | Addressee::List results; | 451 | Addressee::List results; |
452 | 452 | ||
453 | Iterator it; | 453 | Iterator it; |
454 | for ( it = begin(); it != end(); ++it ) { | 454 | for ( it = begin(); it != end(); ++it ) { |
455 | if ( (*it).hasCategory( category) ) { | 455 | if ( (*it).hasCategory( category) ) { |
456 | results.append( *it ); | 456 | results.append( *it ); |
457 | } | 457 | } |
458 | } | 458 | } |
459 | 459 | ||
460 | return results; | 460 | return results; |
461 | } | 461 | } |
462 | 462 | ||
463 | void AddressBook::dump() const | 463 | void AddressBook::dump() const |
464 | { | 464 | { |
465 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 465 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
466 | 466 | ||
467 | ConstIterator it; | 467 | ConstIterator it; |
468 | for( it = begin(); it != end(); ++it ) { | 468 | for( it = begin(); it != end(); ++it ) { |
469 | (*it).dump(); | 469 | (*it).dump(); |
470 | } | 470 | } |
471 | 471 | ||
472 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 472 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
473 | } | 473 | } |
474 | 474 | ||
475 | QString AddressBook::identifier() | 475 | QString AddressBook::identifier() |
476 | { | 476 | { |
477 | QStringList identifier; | 477 | QStringList identifier; |
478 | 478 | ||
479 | 479 | ||
480 | KRES::Manager<Resource>::ActiveIterator it; | 480 | KRES::Manager<Resource>::ActiveIterator it; |
481 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 481 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
482 | if ( !(*it)->identifier().isEmpty() ) | 482 | if ( !(*it)->identifier().isEmpty() ) |
483 | identifier.append( (*it)->identifier() ); | 483 | identifier.append( (*it)->identifier() ); |
484 | } | 484 | } |
485 | 485 | ||
486 | return identifier.join( ":" ); | 486 | return identifier.join( ":" ); |
487 | } | 487 | } |
488 | 488 | ||
489 | Field::List AddressBook::fields( int category ) | 489 | Field::List AddressBook::fields( int category ) |
490 | { | 490 | { |
491 | if ( d->mAllFields.isEmpty() ) { | 491 | if ( d->mAllFields.isEmpty() ) { |
492 | d->mAllFields = Field::allFields(); | 492 | d->mAllFields = Field::allFields(); |
493 | } | 493 | } |
494 | 494 | ||
495 | if ( category == Field::All ) return d->mAllFields; | 495 | if ( category == Field::All ) return d->mAllFields; |
496 | 496 | ||
497 | Field::List result; | 497 | Field::List result; |
498 | Field::List::ConstIterator it; | 498 | Field::List::ConstIterator it; |
499 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 499 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
500 | if ( (*it)->category() & category ) result.append( *it ); | 500 | if ( (*it)->category() & category ) result.append( *it ); |
501 | } | 501 | } |
502 | 502 | ||
503 | return result; | 503 | return result; |
504 | } | 504 | } |
505 | 505 | ||
506 | bool AddressBook::addCustomField( const QString &label, int category, | 506 | bool AddressBook::addCustomField( const QString &label, int category, |
507 | const QString &key, const QString &app ) | 507 | const QString &key, const QString &app ) |
508 | { | 508 | { |
509 | if ( d->mAllFields.isEmpty() ) { | 509 | if ( d->mAllFields.isEmpty() ) { |
510 | d->mAllFields = Field::allFields(); | 510 | d->mAllFields = Field::allFields(); |
511 | } | 511 | } |
512 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 512 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
513 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 513 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
514 | 514 | ||
515 | QString k = key.isNull() ? label : key; | 515 | QString k = key.isNull() ? label : key; |
516 | 516 | ||
517 | Field *field = Field::createCustomField( label, category, k, a ); | 517 | Field *field = Field::createCustomField( label, category, k, a ); |
518 | 518 | ||
519 | if ( !field ) return false; | 519 | if ( !field ) return false; |
520 | 520 | ||
521 | d->mAllFields.append( field ); | 521 | d->mAllFields.append( field ); |
522 | 522 | ||
523 | return true; | 523 | return true; |
524 | } | 524 | } |
525 | 525 | ||
526 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 526 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
527 | { | 527 | { |
528 | if (!ab.d) return s; | 528 | if (!ab.d) return s; |
529 | 529 | ||
530 | return s << ab.d->mAddressees; | 530 | return s << ab.d->mAddressees; |
531 | } | 531 | } |
532 | 532 | ||
533 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 533 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
534 | { | 534 | { |
535 | if (!ab.d) return s; | 535 | if (!ab.d) return s; |
536 | 536 | ||
537 | s >> ab.d->mAddressees; | 537 | s >> ab.d->mAddressees; |
538 | 538 | ||
539 | return s; | 539 | return s; |
540 | } | 540 | } |
541 | 541 | ||
542 | bool AddressBook::addResource( Resource *resource ) | 542 | bool AddressBook::addResource( Resource *resource ) |
543 | { | 543 | { |
544 | qDebug("AddressBook::addResource 1"); | 544 | qDebug("AddressBook::addResource 1"); |
545 | 545 | ||
546 | if ( !resource->open() ) { | 546 | if ( !resource->open() ) { |
547 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 547 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
548 | return false; | 548 | return false; |
549 | } | 549 | } |
550 | 550 | ||
551 | resource->setAddressBook( this ); | 551 | resource->setAddressBook( this ); |
552 | 552 | ||
553 | d->mManager->add( resource ); | 553 | d->mManager->add( resource ); |
554 | return true; | 554 | return true; |
555 | } | 555 | } |
556 | 556 | ||
557 | bool AddressBook::removeResource( Resource *resource ) | 557 | bool AddressBook::removeResource( Resource *resource ) |
558 | { | 558 | { |
559 | resource->close(); | 559 | resource->close(); |
560 | 560 | ||
561 | if ( resource == standardResource() ) | 561 | if ( resource == standardResource() ) |
562 | d->mManager->setStandardResource( 0 ); | 562 | d->mManager->setStandardResource( 0 ); |
563 | 563 | ||
564 | resource->setAddressBook( 0 ); | 564 | resource->setAddressBook( 0 ); |
565 | 565 | ||
566 | d->mManager->remove( resource ); | 566 | d->mManager->remove( resource ); |
567 | return true; | 567 | return true; |
568 | } | 568 | } |
569 | 569 | ||
570 | QPtrList<Resource> AddressBook::resources() | 570 | QPtrList<Resource> AddressBook::resources() |
571 | { | 571 | { |
572 | QPtrList<Resource> list; | 572 | QPtrList<Resource> list; |
573 | 573 | ||
574 | // qDebug("AddressBook::resources() 1"); | 574 | // qDebug("AddressBook::resources() 1"); |
575 | 575 | ||
576 | KRES::Manager<Resource>::ActiveIterator it; | 576 | KRES::Manager<Resource>::ActiveIterator it; |
577 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 577 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
578 | list.append( *it ); | 578 | list.append( *it ); |
579 | 579 | ||
580 | return list; | 580 | return list; |
581 | } | 581 | } |
582 | 582 | ||
583 | /*US | 583 | /*US |
584 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 584 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
585 | { | 585 | { |
586 | delete d->mErrorHandler; | 586 | delete d->mErrorHandler; |
587 | d->mErrorHandler = handler; | 587 | d->mErrorHandler = handler; |
588 | } | 588 | } |
589 | */ | 589 | */ |
590 | 590 | ||
591 | void AddressBook::error( const QString& msg ) | 591 | void AddressBook::error( const QString& msg ) |
592 | { | 592 | { |
593 | /*US | 593 | /*US |
594 | if ( !d->mErrorHandler ) // create default error handler | 594 | if ( !d->mErrorHandler ) // create default error handler |
595 | d->mErrorHandler = new ConsoleErrorHandler; | 595 | d->mErrorHandler = new ConsoleErrorHandler; |
596 | 596 | ||
597 | if ( d->mErrorHandler ) | 597 | if ( d->mErrorHandler ) |
598 | d->mErrorHandler->error( msg ); | 598 | d->mErrorHandler->error( msg ); |
599 | else | 599 | else |
600 | kdError(5700) << "no error handler defined" << endl; | 600 | kdError(5700) << "no error handler defined" << endl; |
601 | */ | 601 | */ |
602 | kdDebug(5700) << "msg" << endl; | 602 | kdDebug(5700) << "msg" << endl; |
603 | qDebug(msg); | 603 | qDebug(msg); |
604 | } | 604 | } |
605 | 605 | ||
606 | void AddressBook::deleteRemovedAddressees() | 606 | void AddressBook::deleteRemovedAddressees() |
607 | { | 607 | { |
608 | Addressee::List::Iterator it; | 608 | Addressee::List::Iterator it; |
609 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 609 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
610 | Resource *resource = (*it).resource(); | 610 | Resource *resource = (*it).resource(); |
611 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 611 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
612 | resource->removeAddressee( *it ); | 612 | resource->removeAddressee( *it ); |
613 | } | 613 | } |
614 | 614 | ||
615 | d->mRemovedAddressees.clear(); | 615 | d->mRemovedAddressees.clear(); |
616 | } | 616 | } |
617 | 617 | ||
618 | void AddressBook::setStandardResource( Resource *resource ) | 618 | void AddressBook::setStandardResource( Resource *resource ) |
619 | { | 619 | { |
620 | // qDebug("AddressBook::setStandardResource 1"); | 620 | // qDebug("AddressBook::setStandardResource 1"); |
621 | d->mManager->setStandardResource( resource ); | 621 | d->mManager->setStandardResource( resource ); |
622 | } | 622 | } |
623 | 623 | ||
624 | Resource *AddressBook::standardResource() | 624 | Resource *AddressBook::standardResource() |
625 | { | 625 | { |
626 | return d->mManager->standardResource(); | 626 | return d->mManager->standardResource(); |
627 | } | 627 | } |
628 | 628 | ||
629 | KRES::Manager<Resource> *AddressBook::resourceManager() | 629 | KRES::Manager<Resource> *AddressBook::resourceManager() |
630 | { | 630 | { |
631 | return d->mManager; | 631 | return d->mManager; |
632 | } | 632 | } |
633 | 633 | ||
634 | void AddressBook::cleanUp() | 634 | void AddressBook::cleanUp() |
635 | { | 635 | { |
636 | KRES::Manager<Resource>::ActiveIterator it; | 636 | KRES::Manager<Resource>::ActiveIterator it; |
637 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 637 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
638 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 638 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
639 | (*it)->cleanUp(); | 639 | (*it)->cleanUp(); |
640 | } | 640 | } |
641 | } | 641 | } |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 80af841..3920f69 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -1,389 +1,389 @@ | |||
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 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #ifndef _WIN32_ | 30 | #ifndef _WIN32_ |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qfileinfo.h> | 35 | #include <qfileinfo.h> |
36 | #include <qregexp.h> | 36 | #include <qregexp.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | 38 | ||
39 | #include <kapplication.h> | 39 | #include <kapplication.h> |
40 | #include <kconfig.h> | 40 | #include <kconfig.h> |
41 | #include <kdebug.h> | 41 | #include <kdebug.h> |
42 | #include <klocale.h> | 42 | #include <klocale.h> |
43 | //US #include <ksavefile.h> | 43 | //US #include <ksavefile.h> |
44 | #include <kstandarddirs.h> | 44 | #include <kstandarddirs.h> |
45 | 45 | ||
46 | #include "formatfactory.h" | 46 | #include "formatfactory.h" |
47 | 47 | ||
48 | #include "resource.h" | 48 | #include "resource.h" |
49 | #include "resourcefileconfig.h" | 49 | #include "resourcefileconfig.h" |
50 | #include "stdaddressbook.h" | 50 | #include "stdaddressbook.h" |
51 | 51 | ||
52 | //US #include "../../formats/vcardformatplugin2.h" | 52 | //US #include "../../formats/vcardformatplugin2.h" |
53 | //US #include "../../formats/binaryformat.h" | 53 | //US #include "../../formats/binaryformat.h" |
54 | 54 | ||
55 | 55 | ||
56 | #include "resourcefile.h" | 56 | #include "resourcefile.h" |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | 59 | ||
60 | extern "C" | 60 | extern "C" |
61 | { | 61 | { |
62 | //US void *init_kabc_file() | 62 | //US void *init_kabc_file() |
63 | void *init_microkabc_file() | 63 | void *init_microkabc_file() |
64 | { | 64 | { |
65 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); | 65 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | ResourceFile::ResourceFile( const KConfig *config ) | 70 | ResourceFile::ResourceFile( const KConfig *config ) |
71 | : Resource( config ) , mFormat( 0 ) | 71 | : Resource( config ) , mFormat( 0 ) |
72 | { | 72 | { |
73 | QString fileName, formatName; | 73 | QString fileName, formatName; |
74 | 74 | ||
75 | KConfig *cfg = (KConfig *)config; | 75 | KConfig *cfg = (KConfig *)config; |
76 | if ( cfg ) { | 76 | if ( cfg ) { |
77 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | 77 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); |
78 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 78 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
79 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | 79 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); |
80 | } else { | 80 | } else { |
81 | fileName = StdAddressBook::fileName(); | 81 | fileName = StdAddressBook::fileName(); |
82 | formatName = "vcard"; | 82 | formatName = "vcard"; |
83 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | 83 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); |
84 | } | 84 | } |
85 | 85 | ||
86 | init( fileName, formatName ); | 86 | init( fileName, formatName ); |
87 | } | 87 | } |
88 | 88 | ||
89 | ResourceFile::ResourceFile( const QString &fileName, | 89 | ResourceFile::ResourceFile( const QString &fileName, |
90 | const QString &formatName ) | 90 | const QString &formatName ) |
91 | : Resource( 0 ) | 91 | : Resource( 0 ) |
92 | { | 92 | { |
93 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 93 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
94 | init( fileName, formatName ); | 94 | init( fileName, formatName ); |
95 | } | 95 | } |
96 | 96 | ||
97 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 97 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
98 | { | 98 | { |
99 | mFormatName = formatName; | 99 | mFormatName = formatName; |
100 | 100 | ||
101 | FormatFactory *factory = FormatFactory::self(); | 101 | FormatFactory *factory = FormatFactory::self(); |
102 | mFormat = factory->format( mFormatName ); | 102 | mFormat = factory->format( mFormatName ); |
103 | 103 | ||
104 | if ( !mFormat ) { | 104 | if ( !mFormat ) { |
105 | mFormatName = "vcard"; | 105 | mFormatName = "vcard"; |
106 | mFormat = factory->format( mFormatName ); | 106 | mFormat = factory->format( mFormatName ); |
107 | } | 107 | } |
108 | 108 | ||
109 | /*US | 109 | /*US |
110 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); | 110 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); |
111 | if (mFormatName == "vcard") { | 111 | if (mFormatName == "vcard") { |
112 | mFormat = new VCardFormatPlugin2(); | 112 | mFormat = new VCardFormatPlugin2(); |
113 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); | 113 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); |
114 | } | 114 | } |
115 | else if (mFormatName == "binary") { | 115 | else if (mFormatName == "binary") { |
116 | mFormat = new BinaryFormat(); | 116 | mFormat = new BinaryFormat(); |
117 | // qDebug("ResourceFile::init format BinaryFormat"); | 117 | // qDebug("ResourceFile::init format BinaryFormat"); |
118 | } | 118 | } |
119 | else | 119 | else |
120 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); | 120 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); |
121 | */ | 121 | */ |
122 | 122 | ||
123 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | 123 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods |
124 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 124 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
125 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 125 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
126 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 126 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
127 | */ | 127 | */ |
128 | 128 | ||
129 | setFileName( fileName ); | 129 | setFileName( fileName ); |
130 | } | 130 | } |
131 | 131 | ||
132 | ResourceFile::~ResourceFile() | 132 | ResourceFile::~ResourceFile() |
133 | { | 133 | { |
134 | delete mFormat; | 134 | delete mFormat; |
135 | mFormat = 0; | 135 | mFormat = 0; |
136 | } | 136 | } |
137 | 137 | ||
138 | void ResourceFile::writeConfig( KConfig *config ) | 138 | void ResourceFile::writeConfig( KConfig *config ) |
139 | { | 139 | { |
140 | Resource::writeConfig( config ); | 140 | Resource::writeConfig( config ); |
141 | 141 | ||
142 | config->writeEntry( "FileName", mFileName ); | 142 | config->writeEntry( "FileName", mFileName ); |
143 | config->writeEntry( "FileFormat", mFormatName ); | 143 | config->writeEntry( "FileFormat", mFormatName ); |
144 | 144 | ||
145 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 145 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
146 | 146 | ||
147 | } | 147 | } |
148 | 148 | ||
149 | Ticket *ResourceFile::requestSaveTicket() | 149 | Ticket *ResourceFile::requestSaveTicket() |
150 | { | 150 | { |
151 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 151 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
152 | 152 | ||
153 | if ( !addressBook() ) return 0; | 153 | if ( !addressBook() ) return 0; |
154 | 154 | ||
155 | if ( !lock( mFileName ) ) { | 155 | if ( !lock( mFileName ) ) { |
156 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | 156 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" |
157 | << mFileName << "'" << endl; | 157 | << mFileName << "'" << endl; |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | return createTicket( this ); | 160 | return createTicket( this ); |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | bool ResourceFile::doOpen() | 164 | bool ResourceFile::doOpen() |
165 | { | 165 | { |
166 | QFile file( mFileName ); | 166 | QFile file( mFileName ); |
167 | 167 | ||
168 | if ( !file.exists() ) { | 168 | if ( !file.exists() ) { |
169 | // try to create the file | 169 | // try to create the file |
170 | bool ok = file.open( IO_WriteOnly ); | 170 | bool ok = file.open( IO_WriteOnly ); |
171 | if ( ok ) | 171 | if ( ok ) |
172 | file.close(); | 172 | file.close(); |
173 | 173 | ||
174 | return ok; | 174 | return ok; |
175 | } else { | 175 | } else { |
176 | if ( !file.open( IO_ReadWrite ) ) | 176 | if ( !file.open( IO_ReadWrite ) ) |
177 | return false; | 177 | return false; |
178 | 178 | ||
179 | if ( file.size() == 0 ) { | 179 | if ( file.size() == 0 ) { |
180 | file.close(); | 180 | file.close(); |
181 | return true; | 181 | return true; |
182 | } | 182 | } |
183 | 183 | ||
184 | bool ok = mFormat->checkFormat( &file ); | 184 | bool ok = mFormat->checkFormat( &file ); |
185 | file.close(); | 185 | file.close(); |
186 | 186 | ||
187 | return ok; | 187 | return ok; |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | void ResourceFile::doClose() | 191 | void ResourceFile::doClose() |
192 | { | 192 | { |
193 | } | 193 | } |
194 | 194 | ||
195 | bool ResourceFile::load() | 195 | bool ResourceFile::load() |
196 | { | 196 | { |
197 | kdDebug(5700) << "ResourceFile::load(): '" << mFileName << "'" << endl; | 197 | |
198 | 198 | ||
199 | QFile file( mFileName ); | 199 | QFile file( mFileName ); |
200 | if ( !file.open( IO_ReadOnly ) ) { | 200 | if ( !file.open( IO_ReadOnly ) ) { |
201 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 201 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
202 | return false; | 202 | return false; |
203 | } | 203 | } |
204 | 204 | ||
205 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 205 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
206 | 206 | ||
207 | return mFormat->loadAll( addressBook(), this, &file ); | 207 | return mFormat->loadAll( addressBook(), this, &file ); |
208 | } | 208 | } |
209 | 209 | ||
210 | bool ResourceFile::save( Ticket *ticket ) | 210 | bool ResourceFile::save( Ticket *ticket ) |
211 | { | 211 | { |
212 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 212 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
213 | kdDebug(5700) << "ResourceFile::save()" << endl; | 213 | |
214 | 214 | ||
215 | // create backup file | 215 | // create backup file |
216 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 216 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
217 | 217 | ||
218 | /*US we use a simpler method to create a backupfile | 218 | /*US we use a simpler method to create a backupfile |
219 | 219 | ||
220 | (void) KSaveFile::backupFile( mFileName, QString::null | 220 | (void) KSaveFile::backupFile( mFileName, QString::null |
221 | ,extension ); | 221 | ,extension ); |
222 | 222 | ||
223 | KSaveFile saveFile( mFileName ); | 223 | KSaveFile saveFile( mFileName ); |
224 | bool ok = false; | 224 | bool ok = false; |
225 | if ( saveFile.status() == 0 && saveFile.file() ) | 225 | if ( saveFile.status() == 0 && saveFile.file() ) |
226 | { | 226 | { |
227 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 227 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
228 | ok = saveFile.close(); | 228 | ok = saveFile.close(); |
229 | } | 229 | } |
230 | */ | 230 | */ |
231 | 231 | ||
232 | //US ToDo: write backupfile | 232 | //US ToDo: write backupfile |
233 | QFile info; | 233 | QFile info; |
234 | info.setName( mFileName ); | 234 | info.setName( mFileName ); |
235 | bool ok = info.open( IO_WriteOnly ); | 235 | bool ok = info.open( IO_WriteOnly ); |
236 | if ( ok ) { | 236 | if ( ok ) { |
237 | mFormat->saveAll( addressBook(), this, &info ); | 237 | mFormat->saveAll( addressBook(), this, &info ); |
238 | 238 | ||
239 | info.close(); | 239 | info.close(); |
240 | ok = true; | 240 | ok = true; |
241 | } | 241 | } |
242 | else { | 242 | else { |
243 | 243 | ||
244 | } | 244 | } |
245 | 245 | ||
246 | if ( !ok ) | 246 | if ( !ok ) |
247 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 247 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
248 | 248 | ||
249 | delete ticket; | 249 | delete ticket; |
250 | unlock( mFileName ); | 250 | unlock( mFileName ); |
251 | 251 | ||
252 | return ok; | 252 | return ok; |
253 | 253 | ||
254 | qDebug("ResourceFile::save has to be changed"); | 254 | qDebug("ResourceFile::save has to be changed"); |
255 | return true; | 255 | return true; |
256 | } | 256 | } |
257 | 257 | ||
258 | bool ResourceFile::lock( const QString &fileName ) | 258 | bool ResourceFile::lock( const QString &fileName ) |
259 | { | 259 | { |
260 | kdDebug(5700) << "ResourceFile::lock()" << endl; | 260 | |
261 | 261 | ||
262 | QString fn = fileName; | 262 | QString fn = fileName; |
263 | 263 | ||
264 | //US change the implementation how the lockfilename is getting created | 264 | //US change the implementation how the lockfilename is getting created |
265 | //US fn.replace( QRegExp("/"), "_" ); | 265 | //US fn.replace( QRegExp("/"), "_" ); |
266 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 266 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
267 | 267 | ||
268 | KURL url(fn); | 268 | KURL url(fn); |
269 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 269 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
270 | 270 | ||
271 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 271 | |
272 | 272 | ||
273 | if (QFile::exists( lockName )) return false; | 273 | if (QFile::exists( lockName )) return false; |
274 | 274 | ||
275 | QString lockUniqueName; | 275 | QString lockUniqueName; |
276 | lockUniqueName = fn + KApplication::randomString( 8 ); | 276 | lockUniqueName = fn + KApplication::randomString( 8 ); |
277 | 277 | ||
278 | url = lockUniqueName; | 278 | url = lockUniqueName; |
279 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 279 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
280 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 280 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
281 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 281 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
282 | 282 | ||
283 | // Create unique file | 283 | // Create unique file |
284 | QFile file( mLockUniqueName ); | 284 | QFile file( mLockUniqueName ); |
285 | file.open( IO_WriteOnly ); | 285 | file.open( IO_WriteOnly ); |
286 | file.close(); | 286 | file.close(); |
287 | 287 | ||
288 | // Create lock file | 288 | // Create lock file |
289 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 289 | int result = ::link( QFile::encodeName( mLockUniqueName ), |
290 | QFile::encodeName( lockName ) ); | 290 | QFile::encodeName( lockName ) ); |
291 | 291 | ||
292 | if ( result == 0 ) { | 292 | if ( result == 0 ) { |
293 | addressBook()->emitAddressBookLocked(); | 293 | addressBook()->emitAddressBookLocked(); |
294 | return true; | 294 | return true; |
295 | } | 295 | } |
296 | 296 | ||
297 | // TODO: check stat | 297 | // TODO: check stat |
298 | 298 | ||
299 | return false; | 299 | return false; |
300 | } | 300 | } |
301 | 301 | ||
302 | void ResourceFile::unlock( const QString &fileName ) | 302 | void ResourceFile::unlock( const QString &fileName ) |
303 | { | 303 | { |
304 | QString fn = fileName; | 304 | QString fn = fileName; |
305 | //US change the implementation how the lockfilename is getting created | 305 | //US change the implementation how the lockfilename is getting created |
306 | //US fn.replace( QRegExp( "/" ), "_" ); | 306 | //US fn.replace( QRegExp( "/" ), "_" ); |
307 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 307 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
308 | //US QString lockName = fn + ".lock"; | 308 | //US QString lockName = fn + ".lock"; |
309 | KURL url(fn); | 309 | KURL url(fn); |
310 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 310 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
311 | 311 | ||
312 | QFile::remove( lockName ); | 312 | QFile::remove( lockName ); |
313 | QFile::remove( mLockUniqueName ); | 313 | QFile::remove( mLockUniqueName ); |
314 | addressBook()->emitAddressBookUnlocked(); | 314 | addressBook()->emitAddressBookUnlocked(); |
315 | } | 315 | } |
316 | 316 | ||
317 | void ResourceFile::setFileName( const QString &fileName ) | 317 | void ResourceFile::setFileName( const QString &fileName ) |
318 | { | 318 | { |
319 | /*US ToDo: no synchronization so far. Has to be changed in the future | 319 | /*US ToDo: no synchronization so far. Has to be changed in the future |
320 | mDirWatch.stopScan(); | 320 | mDirWatch.stopScan(); |
321 | mDirWatch.removeFile( mFileName ); | 321 | mDirWatch.removeFile( mFileName ); |
322 | */ | 322 | */ |
323 | mFileName = fileName; | 323 | mFileName = fileName; |
324 | 324 | ||
325 | 325 | ||
326 | /*US ToDo: no synchronization so far. Has to be changed in the future | 326 | /*US ToDo: no synchronization so far. Has to be changed in the future |
327 | mDirWatch.addFile( mFileName ); | 327 | mDirWatch.addFile( mFileName ); |
328 | mDirWatch.startScan(); | 328 | mDirWatch.startScan(); |
329 | */ | 329 | */ |
330 | //US simulate KDirWatch event | 330 | //US simulate KDirWatch event |
331 | fileChanged(); | 331 | fileChanged(); |
332 | } | 332 | } |
333 | 333 | ||
334 | QString ResourceFile::fileName() const | 334 | QString ResourceFile::fileName() const |
335 | { | 335 | { |
336 | return mFileName; | 336 | return mFileName; |
337 | } | 337 | } |
338 | 338 | ||
339 | void ResourceFile::setFormat( const QString &format ) | 339 | void ResourceFile::setFormat( const QString &format ) |
340 | { | 340 | { |
341 | mFormatName = format; | 341 | mFormatName = format; |
342 | delete mFormat; | 342 | delete mFormat; |
343 | 343 | ||
344 | FormatFactory *factory = FormatFactory::self(); | 344 | FormatFactory *factory = FormatFactory::self(); |
345 | mFormat = factory->format( mFormatName ); | 345 | mFormat = factory->format( mFormatName ); |
346 | /*US | 346 | /*US |
347 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 347 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
348 | if (mFormatName == "vcard") { | 348 | if (mFormatName == "vcard") { |
349 | mFormat = new VCardFormatPlugin2(); | 349 | mFormat = new VCardFormatPlugin2(); |
350 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 350 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
351 | } | 351 | } |
352 | else if (mFormatName == "binary") { | 352 | else if (mFormatName == "binary") { |
353 | mFormat = new BinaryFormat(); | 353 | mFormat = new BinaryFormat(); |
354 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 354 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
355 | } | 355 | } |
356 | else | 356 | else |
357 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 357 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
358 | */ | 358 | */ |
359 | 359 | ||
360 | } | 360 | } |
361 | 361 | ||
362 | QString ResourceFile::format() const | 362 | QString ResourceFile::format() const |
363 | { | 363 | { |
364 | return mFormatName; | 364 | return mFormatName; |
365 | } | 365 | } |
366 | 366 | ||
367 | void ResourceFile::fileChanged() | 367 | void ResourceFile::fileChanged() |
368 | { | 368 | { |
369 | // There is a small theoretical chance that KDirWatch calls us before | 369 | // There is a small theoretical chance that KDirWatch calls us before |
370 | // we are fully constructed | 370 | // we are fully constructed |
371 | if (!addressBook()) | 371 | if (!addressBook()) |
372 | return; | 372 | return; |
373 | load(); | 373 | load(); |
374 | addressBook()->emitAddressBookChanged(); | 374 | addressBook()->emitAddressBookChanged(); |
375 | } | 375 | } |
376 | 376 | ||
377 | void ResourceFile::removeAddressee( const Addressee &addr ) | 377 | void ResourceFile::removeAddressee( const Addressee &addr ) |
378 | { | 378 | { |
379 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 379 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
380 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 380 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
381 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 381 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
382 | } | 382 | } |
383 | 383 | ||
384 | void ResourceFile::cleanUp() | 384 | void ResourceFile::cleanUp() |
385 | { | 385 | { |
386 | unlock( mFileName ); | 386 | unlock( mFileName ); |
387 | } | 387 | } |
388 | 388 | ||
389 | //US #include "resourcefile.moc" | 389 | //US #include "resourcefile.moc" |
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index 075f12f..1e00cc6 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp | |||
@@ -1,228 +1,228 @@ | |||
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 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include "resource.h" | 29 | #include "resource.h" |
30 | #include <kresources/manager.h> | 30 | #include <kresources/manager.h> |
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | #include <kstaticdeleter.h> | 33 | #include <kstaticdeleter.h> |
34 | #include <kstandarddirs.h> | 34 | #include <kstandarddirs.h> |
35 | 35 | ||
36 | #include "stdaddressbook.h" | 36 | #include "stdaddressbook.h" |
37 | 37 | ||
38 | using namespace KABC; | 38 | using namespace KABC; |
39 | 39 | ||
40 | StdAddressBook *StdAddressBook::mSelf = 0; | 40 | StdAddressBook *StdAddressBook::mSelf = 0; |
41 | bool StdAddressBook::mAutomaticSave = true; | 41 | bool StdAddressBook::mAutomaticSave = true; |
42 | 42 | ||
43 | static KStaticDeleter<StdAddressBook> addressBookDeleter; | 43 | static KStaticDeleter<StdAddressBook> addressBookDeleter; |
44 | 44 | ||
45 | QString StdAddressBook::fileName() | 45 | QString StdAddressBook::fileName() |
46 | { | 46 | { |
47 | return locateLocal( "data", "kabc/std.vcf" ); | 47 | return locateLocal( "data", "kabc/std.vcf" ); |
48 | } | 48 | } |
49 | 49 | ||
50 | QString StdAddressBook::directoryName() | 50 | QString StdAddressBook::directoryName() |
51 | { | 51 | { |
52 | return locateLocal( "data", "kabc/stdvcf" ); | 52 | return locateLocal( "data", "kabc/stdvcf" ); |
53 | } | 53 | } |
54 | 54 | ||
55 | void StdAddressBook::handleCrash() | 55 | void StdAddressBook::handleCrash() |
56 | { | 56 | { |
57 | StdAddressBook::self()->cleanUp(); | 57 | StdAddressBook::self()->cleanUp(); |
58 | } | 58 | } |
59 | 59 | ||
60 | StdAddressBook *StdAddressBook::self() | 60 | StdAddressBook *StdAddressBook::self() |
61 | { | 61 | { |
62 | 62 | ||
63 | if ( !mSelf ) | 63 | if ( !mSelf ) |
64 | { | 64 | { |
65 | QString appdir = StdAddressBook::setTempAppDir(); | 65 | QString appdir = StdAddressBook::setTempAppDir(); |
66 | 66 | ||
67 | kdDebug(5700) << "StdAddressBook::self()" << endl; | 67 | kdDebug(5700) << "StdAddressBook::self()" << endl; |
68 | // US im am not sure why I have to use the other format here?? | 68 | // US im am not sure why I have to use the other format here?? |
69 | #ifdef KAB_EMBEDDED | 69 | #ifdef KAB_EMBEDDED |
70 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); | 70 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); |
71 | #else //KAB_EMBEDDED | 71 | #else //KAB_EMBEDDED |
72 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); | 72 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); |
73 | #endif //KAB_EMBEDDED | 73 | #endif //KAB_EMBEDDED |
74 | KStandardDirs::setAppDir( appdir ); | 74 | KStandardDirs::setAppDir( appdir ); |
75 | } | 75 | } |
76 | 76 | ||
77 | return mSelf; | 77 | return mSelf; |
78 | } | 78 | } |
79 | 79 | ||
80 | QString StdAddressBook::setTempAppDir() | 80 | QString StdAddressBook::setTempAppDir() |
81 | { | 81 | { |
82 | QString appDIR = KStandardDirs::appDir(); | 82 | QString appDIR = KStandardDirs::appDir(); |
83 | #ifdef DESKTOP_VERSION | 83 | #ifdef DESKTOP_VERSION |
84 | QString appdir = QDir::homeDirPath(); | 84 | QString appdir = QDir::homeDirPath(); |
85 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) | 85 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) |
86 | appdir += "kaddressbook/"; | 86 | appdir += "kaddressbook/"; |
87 | else | 87 | else |
88 | appdir += "/kaddressbook/"; | 88 | appdir += "/kaddressbook/"; |
89 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); | 89 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); |
90 | #else | 90 | #else |
91 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; | 91 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; |
92 | 92 | ||
93 | KStandardDirs::setAppDir( appdir ); | 93 | KStandardDirs::setAppDir( appdir ); |
94 | #endif | 94 | #endif |
95 | 95 | ||
96 | return appDIR; | 96 | return appDIR; |
97 | } | 97 | } |
98 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) | 98 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) |
99 | { | 99 | { |
100 | 100 | ||
101 | if ( !mSelf ) | 101 | if ( !mSelf ) |
102 | { | 102 | { |
103 | QString appdir =StdAddressBook::setTempAppDir(); | 103 | QString appdir =StdAddressBook::setTempAppDir(); |
104 | #ifdef KAB_EMBEDDED | 104 | #ifdef KAB_EMBEDDED |
105 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); | 105 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); |
106 | #else //KAB_EMBEDDED | 106 | #else //KAB_EMBEDDED |
107 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); | 107 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); |
108 | #endif //KAB_EMBEDDED | 108 | #endif //KAB_EMBEDDED |
109 | KStandardDirs::setAppDir( appdir ); | 109 | KStandardDirs::setAppDir( appdir ); |
110 | } | 110 | } |
111 | return mSelf; | 111 | return mSelf; |
112 | } | 112 | } |
113 | 113 | ||
114 | StdAddressBook::StdAddressBook() | 114 | StdAddressBook::StdAddressBook() |
115 | //US : AddressBook( "kabcrc" ) | 115 | //US : AddressBook( "kabcrc" ) |
116 | : AddressBook( locateLocal( "config", "kabcrc") ) | 116 | : AddressBook( locateLocal( "config", "kabcrc") ) |
117 | { | 117 | { |
118 | 118 | ||
119 | init( false ); | 119 | init( false ); |
120 | } | 120 | } |
121 | 121 | ||
122 | StdAddressBook::StdAddressBook( bool onlyFastResources ) | 122 | StdAddressBook::StdAddressBook( bool onlyFastResources ) |
123 | //US : AddressBook( "kabcrc" ) | 123 | //US : AddressBook( "kabcrc" ) |
124 | : AddressBook( locateLocal( "config", "kabcrc") ) | 124 | : AddressBook( locateLocal( "config", "kabcrc") ) |
125 | { | 125 | { |
126 | 126 | ||
127 | init( onlyFastResources ); | 127 | init( onlyFastResources ); |
128 | } | 128 | } |
129 | 129 | ||
130 | StdAddressBook::~StdAddressBook() | 130 | StdAddressBook::~StdAddressBook() |
131 | { | 131 | { |
132 | if ( mAutomaticSave ) | 132 | if ( mAutomaticSave ) |
133 | save(); | 133 | save(); |
134 | } | 134 | } |
135 | 135 | ||
136 | void StdAddressBook::init( bool ) | 136 | void StdAddressBook::init( bool ) |
137 | { | 137 | { |
138 | KRES::Manager<Resource> *manager = resourceManager(); | 138 | KRES::Manager<Resource> *manager = resourceManager(); |
139 | KRES::Manager<Resource>::ActiveIterator it; | 139 | KRES::Manager<Resource>::ActiveIterator it; |
140 | 140 | ||
141 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 141 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
142 | (*it)->setAddressBook( this ); | 142 | (*it)->setAddressBook( this ); |
143 | if ( !(*it)->open() ) | 143 | if ( !(*it)->open() ) |
144 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 144 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
145 | } | 145 | } |
146 | 146 | ||
147 | Resource *res = standardResource(); | 147 | Resource *res = standardResource(); |
148 | if ( !res ) { | 148 | if ( !res ) { |
149 | res = manager->createResource( "file" ); | 149 | res = manager->createResource( "file" ); |
150 | if ( res ) | 150 | if ( res ) |
151 | { | 151 | { |
152 | addResource( res ); | 152 | addResource( res ); |
153 | } | 153 | } |
154 | else | 154 | else |
155 | kdDebug(5700) << "No resource available!!!" << endl; | 155 | qDebug(" No resource available!!!"); |
156 | } | 156 | } |
157 | 157 | ||
158 | setStandardResource( res ); | 158 | setStandardResource( res ); |
159 | manager->writeConfig(); | 159 | manager->writeConfig(); |
160 | 160 | ||
161 | load(); | 161 | load(); |
162 | } | 162 | } |
163 | 163 | ||
164 | bool StdAddressBook::save() | 164 | bool StdAddressBook::save() |
165 | { | 165 | { |
166 | kdDebug(5700) << "StdAddressBook::save()" << endl; | 166 | kdDebug(5700) << "StdAddressBook::save()" << endl; |
167 | 167 | ||
168 | bool ok = true; | 168 | bool ok = true; |
169 | AddressBook *ab = self(); | 169 | AddressBook *ab = self(); |
170 | 170 | ||
171 | ab->deleteRemovedAddressees(); | 171 | ab->deleteRemovedAddressees(); |
172 | 172 | ||
173 | KRES::Manager<Resource>::ActiveIterator it; | 173 | KRES::Manager<Resource>::ActiveIterator it; |
174 | KRES::Manager<Resource> *manager = ab->resourceManager(); | 174 | KRES::Manager<Resource> *manager = ab->resourceManager(); |
175 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 175 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
176 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 176 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
177 | Ticket *ticket = ab->requestSaveTicket( *it ); | 177 | Ticket *ticket = ab->requestSaveTicket( *it ); |
178 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 178 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
179 | if ( !ticket ) { | 179 | if ( !ticket ) { |
180 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) | 180 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) |
181 | .arg( (*it)->resourceName() ) ); | 181 | .arg( (*it)->resourceName() ) ); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | 184 | ||
185 | if ( !ab->save( ticket ) ) | 185 | if ( !ab->save( ticket ) ) |
186 | ok = false; | 186 | ok = false; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | return ok; | 190 | return ok; |
191 | } | 191 | } |
192 | 192 | ||
193 | void StdAddressBook::close() | 193 | void StdAddressBook::close() |
194 | { | 194 | { |
195 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? | 195 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? |
196 | //US addressBookDeleter.destructObject(); | 196 | //US addressBookDeleter.destructObject(); |
197 | addressBookDeleter.setObject(0); | 197 | addressBookDeleter.setObject(0); |
198 | 198 | ||
199 | } | 199 | } |
200 | 200 | ||
201 | void StdAddressBook::setAutomaticSave( bool enable ) | 201 | void StdAddressBook::setAutomaticSave( bool enable ) |
202 | { | 202 | { |
203 | mAutomaticSave = enable; | 203 | mAutomaticSave = enable; |
204 | } | 204 | } |
205 | 205 | ||
206 | bool StdAddressBook::automaticSave() | 206 | bool StdAddressBook::automaticSave() |
207 | { | 207 | { |
208 | return mAutomaticSave; | 208 | return mAutomaticSave; |
209 | } | 209 | } |
210 | 210 | ||
211 | // should get const for 4.X | 211 | // should get const for 4.X |
212 | Addressee StdAddressBook::whoAmI() | 212 | Addressee StdAddressBook::whoAmI() |
213 | { | 213 | { |
214 | //US KConfig config( "kabcrc" ); | 214 | //US KConfig config( "kabcrc" ); |
215 | KConfig config( locateLocal("config", "kabcrc") ); | 215 | KConfig config( locateLocal("config", "kabcrc") ); |
216 | config.setGroup( "General" ); | 216 | config.setGroup( "General" ); |
217 | 217 | ||
218 | return findByUid( config.readEntry( "WhoAmI" ) ); | 218 | return findByUid( config.readEntry( "WhoAmI" ) ); |
219 | } | 219 | } |
220 | 220 | ||
221 | void StdAddressBook::setWhoAmI( const Addressee &addr ) | 221 | void StdAddressBook::setWhoAmI( const Addressee &addr ) |
222 | { | 222 | { |
223 | //US KConfig config( "kabcrc" ); | 223 | //US KConfig config( "kabcrc" ); |
224 | KConfig config( locateLocal("config", "kabcrc") ); | 224 | KConfig config( locateLocal("config", "kabcrc") ); |
225 | config.setGroup( "General" ); | 225 | config.setGroup( "General" ); |
226 | 226 | ||
227 | config.writeEntry( "WhoAmI", addr.uid() ); | 227 | config.writeEntry( "WhoAmI", addr.uid() ); |
228 | } | 228 | } |