-rw-r--r-- | kabc/addressbook.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 28 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 2 | ||||
-rw-r--r-- | kabc/resource.cpp | 5 | ||||
-rw-r--r-- | kabc/resource.h | 2 | ||||
-rw-r--r-- | kabc/stdaddressbook.cpp | 36 | ||||
-rw-r--r-- | kabc/syncprefwidget.cpp | 681 | ||||
-rw-r--r-- | kabc/syncprefwidget.h | 138 |
12 files changed, 415 insertions, 487 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 20310a0..c61b387 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,646 +1,646 @@ | |||
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, "contact"); | 219 | init(0, "contact"); |
220 | } | 220 | } |
221 | 221 | ||
222 | AddressBook::AddressBook( const QString &config ) | 222 | AddressBook::AddressBook( const QString &config ) |
223 | { | 223 | { |
224 | init(config, "contact"); | 224 | init(config, "contact"); |
225 | } | 225 | } |
226 | 226 | ||
227 | AddressBook::AddressBook( const QString &config, const QString &family ) | 227 | AddressBook::AddressBook( const QString &config, const QString &family ) |
228 | { | 228 | { |
229 | init(config, family); | 229 | init(config, family); |
230 | 230 | ||
231 | } | 231 | } |
232 | 232 | ||
233 | // the default family is "contact" | 233 | // the default family is "contact" |
234 | void AddressBook::init(const QString &config, const QString &family ) | 234 | void AddressBook::init(const QString &config, const QString &family ) |
235 | { | 235 | { |
236 | d = new AddressBookData; | 236 | d = new AddressBookData; |
237 | if (config != 0) { | 237 | if (config != 0) { |
238 | d->mConfig = new KConfig( config ); | 238 | d->mConfig = new KConfig( locateLocal("config", config) ); |
239 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 239 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
240 | } | 240 | } |
241 | else { | 241 | else { |
242 | d->mConfig = 0; | 242 | d->mConfig = 0; |
243 | // qDebug("AddressBook::init 1 config=0"); | 243 | // qDebug("AddressBook::init 1 config=0"); |
244 | } | 244 | } |
245 | 245 | ||
246 | //US d->mErrorHandler = 0; | 246 | //US d->mErrorHandler = 0; |
247 | d->mManager = new KRES::Manager<Resource>( family, false ); | 247 | d->mManager = new KRES::Manager<Resource>( family, false ); |
248 | d->mManager->readConfig( d->mConfig ); | 248 | d->mManager->readConfig( d->mConfig ); |
249 | } | 249 | } |
250 | 250 | ||
251 | AddressBook::~AddressBook() | 251 | AddressBook::~AddressBook() |
252 | { | 252 | { |
253 | delete d->mConfig; d->mConfig = 0; | 253 | delete d->mConfig; d->mConfig = 0; |
254 | delete d->mManager; d->mManager = 0; | 254 | delete d->mManager; d->mManager = 0; |
255 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 255 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
256 | delete d; d = 0; | 256 | delete d; d = 0; |
257 | } | 257 | } |
258 | 258 | ||
259 | bool AddressBook::load() | 259 | bool AddressBook::load() |
260 | { | 260 | { |
261 | 261 | ||
262 | 262 | ||
263 | clear(); | 263 | clear(); |
264 | 264 | ||
265 | KRES::Manager<Resource>::ActiveIterator it; | 265 | KRES::Manager<Resource>::ActiveIterator it; |
266 | bool ok = true; | 266 | bool ok = true; |
267 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 267 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
268 | if ( !(*it)->load() ) { | 268 | if ( !(*it)->load() ) { |
269 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 269 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
270 | ok = false; | 270 | ok = false; |
271 | } | 271 | } |
272 | 272 | ||
273 | // mark all addressees as unchanged | 273 | // mark all addressees as unchanged |
274 | Addressee::List::Iterator addrIt; | 274 | Addressee::List::Iterator addrIt; |
275 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) | 275 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) |
276 | (*addrIt).setChanged( false ); | 276 | (*addrIt).setChanged( false ); |
277 | 277 | ||
278 | return ok; | 278 | return ok; |
279 | } | 279 | } |
280 | 280 | ||
281 | bool AddressBook::save( Ticket *ticket ) | 281 | bool AddressBook::save( Ticket *ticket ) |
282 | { | 282 | { |
283 | kdDebug(5700) << "AddressBook::save()"<< endl; | 283 | kdDebug(5700) << "AddressBook::save()"<< endl; |
284 | 284 | ||
285 | if ( ticket->resource() ) { | 285 | if ( ticket->resource() ) { |
286 | deleteRemovedAddressees(); | 286 | deleteRemovedAddressees(); |
287 | 287 | ||
288 | return ticket->resource()->save( ticket ); | 288 | return ticket->resource()->save( ticket ); |
289 | } | 289 | } |
290 | 290 | ||
291 | return false; | 291 | return false; |
292 | } | 292 | } |
293 | 293 | ||
294 | AddressBook::Iterator AddressBook::begin() | 294 | AddressBook::Iterator AddressBook::begin() |
295 | { | 295 | { |
296 | Iterator it = Iterator(); | 296 | Iterator it = Iterator(); |
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::ConstIterator AddressBook::begin() const | 301 | AddressBook::ConstIterator AddressBook::begin() const |
302 | { | 302 | { |
303 | ConstIterator it = ConstIterator(); | 303 | ConstIterator it = ConstIterator(); |
304 | it.d->mIt = d->mAddressees.begin(); | 304 | it.d->mIt = d->mAddressees.begin(); |
305 | return it; | 305 | return it; |
306 | } | 306 | } |
307 | 307 | ||
308 | AddressBook::Iterator AddressBook::end() | 308 | AddressBook::Iterator AddressBook::end() |
309 | { | 309 | { |
310 | Iterator it = Iterator(); | 310 | Iterator it = Iterator(); |
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 | AddressBook::ConstIterator AddressBook::end() const | 315 | AddressBook::ConstIterator AddressBook::end() const |
316 | { | 316 | { |
317 | ConstIterator it = ConstIterator(); | 317 | ConstIterator it = ConstIterator(); |
318 | it.d->mIt = d->mAddressees.end(); | 318 | it.d->mIt = d->mAddressees.end(); |
319 | return it; | 319 | return it; |
320 | } | 320 | } |
321 | 321 | ||
322 | void AddressBook::clear() | 322 | void AddressBook::clear() |
323 | { | 323 | { |
324 | d->mAddressees.clear(); | 324 | d->mAddressees.clear(); |
325 | } | 325 | } |
326 | 326 | ||
327 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 327 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
328 | { | 328 | { |
329 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 329 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
330 | 330 | ||
331 | if ( !resource ) | 331 | if ( !resource ) |
332 | { | 332 | { |
333 | qDebug("AddressBook::requestSaveTicket no resource" ); | 333 | qDebug("AddressBook::requestSaveTicket no resource" ); |
334 | resource = standardResource(); | 334 | resource = standardResource(); |
335 | } | 335 | } |
336 | 336 | ||
337 | KRES::Manager<Resource>::ActiveIterator it; | 337 | KRES::Manager<Resource>::ActiveIterator it; |
338 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 338 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
339 | if ( (*it) == resource ) { | 339 | if ( (*it) == resource ) { |
340 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 340 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
341 | return 0; | 341 | return 0; |
342 | else | 342 | else |
343 | return (*it)->requestSaveTicket(); | 343 | return (*it)->requestSaveTicket(); |
344 | } | 344 | } |
345 | } | 345 | } |
346 | 346 | ||
347 | return 0; | 347 | return 0; |
348 | } | 348 | } |
349 | 349 | ||
350 | void AddressBook::insertAddressee( const Addressee &a ) | 350 | void AddressBook::insertAddressee( const Addressee &a ) |
351 | { | 351 | { |
352 | Addressee::List::Iterator it; | 352 | Addressee::List::Iterator it; |
353 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 353 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
354 | if ( a.uid() == (*it).uid() ) { | 354 | if ( a.uid() == (*it).uid() ) { |
355 | bool changed = false; | 355 | bool changed = false; |
356 | Addressee addr = a; | 356 | Addressee addr = a; |
357 | if ( addr != (*it) ) | 357 | if ( addr != (*it) ) |
358 | changed = true; | 358 | changed = true; |
359 | 359 | ||
360 | (*it) = a; | 360 | (*it) = a; |
361 | if ( (*it).resource() == 0 ) | 361 | if ( (*it).resource() == 0 ) |
362 | (*it).setResource( standardResource() ); | 362 | (*it).setResource( standardResource() ); |
363 | 363 | ||
364 | if ( changed ) { | 364 | if ( changed ) { |
365 | (*it).setRevision( QDateTime::currentDateTime() ); | 365 | (*it).setRevision( QDateTime::currentDateTime() ); |
366 | (*it).setChanged( true ); | 366 | (*it).setChanged( true ); |
367 | } | 367 | } |
368 | 368 | ||
369 | return; | 369 | return; |
370 | } | 370 | } |
371 | } | 371 | } |
372 | d->mAddressees.append( a ); | 372 | d->mAddressees.append( a ); |
373 | Addressee& addr = d->mAddressees.last(); | 373 | Addressee& addr = d->mAddressees.last(); |
374 | if ( addr.resource() == 0 ) | 374 | if ( addr.resource() == 0 ) |
375 | addr.setResource( standardResource() ); | 375 | addr.setResource( standardResource() ); |
376 | 376 | ||
377 | addr.setChanged( true ); | 377 | addr.setChanged( true ); |
378 | } | 378 | } |
379 | 379 | ||
380 | void AddressBook::removeAddressee( const Addressee &a ) | 380 | void AddressBook::removeAddressee( const Addressee &a ) |
381 | { | 381 | { |
382 | Iterator it; | 382 | Iterator it; |
383 | for ( it = begin(); it != end(); ++it ) { | 383 | for ( it = begin(); it != end(); ++it ) { |
384 | if ( a.uid() == (*it).uid() ) { | 384 | if ( a.uid() == (*it).uid() ) { |
385 | removeAddressee( it ); | 385 | removeAddressee( it ); |
386 | return; | 386 | return; |
387 | } | 387 | } |
388 | } | 388 | } |
389 | } | 389 | } |
390 | 390 | ||
391 | void AddressBook::removeAddressee( const Iterator &it ) | 391 | void AddressBook::removeAddressee( const Iterator &it ) |
392 | { | 392 | { |
393 | d->mRemovedAddressees.append( (*it) ); | 393 | d->mRemovedAddressees.append( (*it) ); |
394 | d->mAddressees.remove( it.d->mIt ); | 394 | d->mAddressees.remove( it.d->mIt ); |
395 | } | 395 | } |
396 | 396 | ||
397 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 397 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
398 | { | 398 | { |
399 | Iterator it; | 399 | Iterator it; |
400 | for ( it = begin(); it != end(); ++it ) { | 400 | for ( it = begin(); it != end(); ++it ) { |
401 | if ( a.uid() == (*it).uid() ) { | 401 | if ( a.uid() == (*it).uid() ) { |
402 | return it; | 402 | return it; |
403 | } | 403 | } |
404 | } | 404 | } |
405 | return end(); | 405 | return end(); |
406 | } | 406 | } |
407 | 407 | ||
408 | Addressee AddressBook::findByUid( const QString &uid ) | 408 | Addressee AddressBook::findByUid( const QString &uid ) |
409 | { | 409 | { |
410 | Iterator it; | 410 | Iterator it; |
411 | for ( it = begin(); it != end(); ++it ) { | 411 | for ( it = begin(); it != end(); ++it ) { |
412 | if ( uid == (*it).uid() ) { | 412 | if ( uid == (*it).uid() ) { |
413 | return *it; | 413 | return *it; |
414 | } | 414 | } |
415 | } | 415 | } |
416 | return Addressee(); | 416 | return Addressee(); |
417 | } | 417 | } |
418 | 418 | ||
419 | Addressee::List AddressBook::allAddressees() | 419 | Addressee::List AddressBook::allAddressees() |
420 | { | 420 | { |
421 | return d->mAddressees; | 421 | return d->mAddressees; |
422 | } | 422 | } |
423 | 423 | ||
424 | Addressee::List AddressBook::findByName( const QString &name ) | 424 | Addressee::List AddressBook::findByName( const QString &name ) |
425 | { | 425 | { |
426 | Addressee::List results; | 426 | Addressee::List results; |
427 | 427 | ||
428 | Iterator it; | 428 | Iterator it; |
429 | for ( it = begin(); it != end(); ++it ) { | 429 | for ( it = begin(); it != end(); ++it ) { |
430 | if ( name == (*it).name() ) { | 430 | if ( name == (*it).name() ) { |
431 | results.append( *it ); | 431 | results.append( *it ); |
432 | } | 432 | } |
433 | } | 433 | } |
434 | 434 | ||
435 | return results; | 435 | return results; |
436 | } | 436 | } |
437 | 437 | ||
438 | Addressee::List AddressBook::findByEmail( const QString &email ) | 438 | Addressee::List AddressBook::findByEmail( const QString &email ) |
439 | { | 439 | { |
440 | Addressee::List results; | 440 | Addressee::List results; |
441 | QStringList mailList; | 441 | QStringList mailList; |
442 | 442 | ||
443 | Iterator it; | 443 | Iterator it; |
444 | for ( it = begin(); it != end(); ++it ) { | 444 | for ( it = begin(); it != end(); ++it ) { |
445 | mailList = (*it).emails(); | 445 | mailList = (*it).emails(); |
446 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 446 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
447 | if ( email == (*ite) ) { | 447 | if ( email == (*ite) ) { |
448 | results.append( *it ); | 448 | results.append( *it ); |
449 | } | 449 | } |
450 | } | 450 | } |
451 | } | 451 | } |
452 | 452 | ||
453 | return results; | 453 | return results; |
454 | } | 454 | } |
455 | 455 | ||
456 | Addressee::List AddressBook::findByCategory( const QString &category ) | 456 | Addressee::List AddressBook::findByCategory( const QString &category ) |
457 | { | 457 | { |
458 | Addressee::List results; | 458 | Addressee::List results; |
459 | 459 | ||
460 | Iterator it; | 460 | Iterator it; |
461 | for ( it = begin(); it != end(); ++it ) { | 461 | for ( it = begin(); it != end(); ++it ) { |
462 | if ( (*it).hasCategory( category) ) { | 462 | if ( (*it).hasCategory( category) ) { |
463 | results.append( *it ); | 463 | results.append( *it ); |
464 | } | 464 | } |
465 | } | 465 | } |
466 | 466 | ||
467 | return results; | 467 | return results; |
468 | } | 468 | } |
469 | 469 | ||
470 | void AddressBook::dump() const | 470 | void AddressBook::dump() const |
471 | { | 471 | { |
472 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 472 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
473 | 473 | ||
474 | ConstIterator it; | 474 | ConstIterator it; |
475 | for( it = begin(); it != end(); ++it ) { | 475 | for( it = begin(); it != end(); ++it ) { |
476 | (*it).dump(); | 476 | (*it).dump(); |
477 | } | 477 | } |
478 | 478 | ||
479 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 479 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
480 | } | 480 | } |
481 | 481 | ||
482 | QString AddressBook::identifier() | 482 | QString AddressBook::identifier() |
483 | { | 483 | { |
484 | QStringList identifier; | 484 | QStringList identifier; |
485 | 485 | ||
486 | 486 | ||
487 | KRES::Manager<Resource>::ActiveIterator it; | 487 | KRES::Manager<Resource>::ActiveIterator it; |
488 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 488 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
489 | if ( !(*it)->identifier().isEmpty() ) | 489 | if ( !(*it)->identifier().isEmpty() ) |
490 | identifier.append( (*it)->identifier() ); | 490 | identifier.append( (*it)->identifier() ); |
491 | } | 491 | } |
492 | 492 | ||
493 | return identifier.join( ":" ); | 493 | return identifier.join( ":" ); |
494 | } | 494 | } |
495 | 495 | ||
496 | Field::List AddressBook::fields( int category ) | 496 | Field::List AddressBook::fields( int category ) |
497 | { | 497 | { |
498 | if ( d->mAllFields.isEmpty() ) { | 498 | if ( d->mAllFields.isEmpty() ) { |
499 | d->mAllFields = Field::allFields(); | 499 | d->mAllFields = Field::allFields(); |
500 | } | 500 | } |
501 | 501 | ||
502 | if ( category == Field::All ) return d->mAllFields; | 502 | if ( category == Field::All ) return d->mAllFields; |
503 | 503 | ||
504 | Field::List result; | 504 | Field::List result; |
505 | Field::List::ConstIterator it; | 505 | Field::List::ConstIterator it; |
506 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 506 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
507 | if ( (*it)->category() & category ) result.append( *it ); | 507 | if ( (*it)->category() & category ) result.append( *it ); |
508 | } | 508 | } |
509 | 509 | ||
510 | return result; | 510 | return result; |
511 | } | 511 | } |
512 | 512 | ||
513 | bool AddressBook::addCustomField( const QString &label, int category, | 513 | bool AddressBook::addCustomField( const QString &label, int category, |
514 | const QString &key, const QString &app ) | 514 | const QString &key, const QString &app ) |
515 | { | 515 | { |
516 | if ( d->mAllFields.isEmpty() ) { | 516 | if ( d->mAllFields.isEmpty() ) { |
517 | d->mAllFields = Field::allFields(); | 517 | d->mAllFields = Field::allFields(); |
518 | } | 518 | } |
519 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 519 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
520 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 520 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
521 | 521 | ||
522 | QString k = key.isNull() ? label : key; | 522 | QString k = key.isNull() ? label : key; |
523 | 523 | ||
524 | Field *field = Field::createCustomField( label, category, k, a ); | 524 | Field *field = Field::createCustomField( label, category, k, a ); |
525 | 525 | ||
526 | if ( !field ) return false; | 526 | if ( !field ) return false; |
527 | 527 | ||
528 | d->mAllFields.append( field ); | 528 | d->mAllFields.append( field ); |
529 | 529 | ||
530 | return true; | 530 | return true; |
531 | } | 531 | } |
532 | 532 | ||
533 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 533 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
534 | { | 534 | { |
535 | if (!ab.d) return s; | 535 | if (!ab.d) return s; |
536 | 536 | ||
537 | return s << ab.d->mAddressees; | 537 | return s << ab.d->mAddressees; |
538 | } | 538 | } |
539 | 539 | ||
540 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 540 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
541 | { | 541 | { |
542 | if (!ab.d) return s; | 542 | if (!ab.d) return s; |
543 | 543 | ||
544 | s >> ab.d->mAddressees; | 544 | s >> ab.d->mAddressees; |
545 | 545 | ||
546 | return s; | 546 | return s; |
547 | } | 547 | } |
548 | 548 | ||
549 | bool AddressBook::addResource( Resource *resource ) | 549 | bool AddressBook::addResource( Resource *resource ) |
550 | { | 550 | { |
551 | if ( !resource->open() ) { | 551 | if ( !resource->open() ) { |
552 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 552 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
553 | return false; | 553 | return false; |
554 | } | 554 | } |
555 | 555 | ||
556 | resource->setAddressBook( this ); | 556 | resource->setAddressBook( this ); |
557 | 557 | ||
558 | d->mManager->add( resource ); | 558 | d->mManager->add( resource ); |
559 | return true; | 559 | return true; |
560 | } | 560 | } |
561 | 561 | ||
562 | bool AddressBook::removeResource( Resource *resource ) | 562 | bool AddressBook::removeResource( Resource *resource ) |
563 | { | 563 | { |
564 | resource->close(); | 564 | resource->close(); |
565 | 565 | ||
566 | if ( resource == standardResource() ) | 566 | if ( resource == standardResource() ) |
567 | d->mManager->setStandardResource( 0 ); | 567 | d->mManager->setStandardResource( 0 ); |
568 | 568 | ||
569 | resource->setAddressBook( 0 ); | 569 | resource->setAddressBook( 0 ); |
570 | 570 | ||
571 | d->mManager->remove( resource ); | 571 | d->mManager->remove( resource ); |
572 | return true; | 572 | return true; |
573 | } | 573 | } |
574 | 574 | ||
575 | QPtrList<Resource> AddressBook::resources() | 575 | QPtrList<Resource> AddressBook::resources() |
576 | { | 576 | { |
577 | QPtrList<Resource> list; | 577 | QPtrList<Resource> list; |
578 | 578 | ||
579 | // qDebug("AddressBook::resources() 1"); | 579 | // qDebug("AddressBook::resources() 1"); |
580 | 580 | ||
581 | KRES::Manager<Resource>::ActiveIterator it; | 581 | KRES::Manager<Resource>::ActiveIterator it; |
582 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 582 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
583 | list.append( *it ); | 583 | list.append( *it ); |
584 | 584 | ||
585 | return list; | 585 | return list; |
586 | } | 586 | } |
587 | 587 | ||
588 | /*US | 588 | /*US |
589 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 589 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
590 | { | 590 | { |
591 | delete d->mErrorHandler; | 591 | delete d->mErrorHandler; |
592 | d->mErrorHandler = handler; | 592 | d->mErrorHandler = handler; |
593 | } | 593 | } |
594 | */ | 594 | */ |
595 | 595 | ||
596 | void AddressBook::error( const QString& msg ) | 596 | void AddressBook::error( const QString& msg ) |
597 | { | 597 | { |
598 | /*US | 598 | /*US |
599 | if ( !d->mErrorHandler ) // create default error handler | 599 | if ( !d->mErrorHandler ) // create default error handler |
600 | d->mErrorHandler = new ConsoleErrorHandler; | 600 | d->mErrorHandler = new ConsoleErrorHandler; |
601 | 601 | ||
602 | if ( d->mErrorHandler ) | 602 | if ( d->mErrorHandler ) |
603 | d->mErrorHandler->error( msg ); | 603 | d->mErrorHandler->error( msg ); |
604 | else | 604 | else |
605 | kdError(5700) << "no error handler defined" << endl; | 605 | kdError(5700) << "no error handler defined" << endl; |
606 | */ | 606 | */ |
607 | kdDebug(5700) << "msg" << endl; | 607 | kdDebug(5700) << "msg" << endl; |
608 | qDebug(msg); | 608 | qDebug(msg); |
609 | } | 609 | } |
610 | 610 | ||
611 | void AddressBook::deleteRemovedAddressees() | 611 | void AddressBook::deleteRemovedAddressees() |
612 | { | 612 | { |
613 | Addressee::List::Iterator it; | 613 | Addressee::List::Iterator it; |
614 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 614 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
615 | Resource *resource = (*it).resource(); | 615 | Resource *resource = (*it).resource(); |
616 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 616 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
617 | resource->removeAddressee( *it ); | 617 | resource->removeAddressee( *it ); |
618 | } | 618 | } |
619 | 619 | ||
620 | d->mRemovedAddressees.clear(); | 620 | d->mRemovedAddressees.clear(); |
621 | } | 621 | } |
622 | 622 | ||
623 | void AddressBook::setStandardResource( Resource *resource ) | 623 | void AddressBook::setStandardResource( Resource *resource ) |
624 | { | 624 | { |
625 | // qDebug("AddressBook::setStandardResource 1"); | 625 | // qDebug("AddressBook::setStandardResource 1"); |
626 | d->mManager->setStandardResource( resource ); | 626 | d->mManager->setStandardResource( resource ); |
627 | } | 627 | } |
628 | 628 | ||
629 | Resource *AddressBook::standardResource() | 629 | Resource *AddressBook::standardResource() |
630 | { | 630 | { |
631 | return d->mManager->standardResource(); | 631 | return d->mManager->standardResource(); |
632 | } | 632 | } |
633 | 633 | ||
634 | KRES::Manager<Resource> *AddressBook::resourceManager() | 634 | KRES::Manager<Resource> *AddressBook::resourceManager() |
635 | { | 635 | { |
636 | return d->mManager; | 636 | return d->mManager; |
637 | } | 637 | } |
638 | 638 | ||
639 | void AddressBook::cleanUp() | 639 | void AddressBook::cleanUp() |
640 | { | 640 | { |
641 | KRES::Manager<Resource>::ActiveIterator it; | 641 | KRES::Manager<Resource>::ActiveIterator it; |
642 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 642 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
643 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 643 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
644 | (*it)->cleanUp(); | 644 | (*it)->cleanUp(); |
645 | } | 645 | } |
646 | } | 646 | } |
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index 29f1e3a..eccd482 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -1,365 +1,365 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 | 28 | ||
29 | #include <sys/types.h> | 29 | #include <sys/types.h> |
30 | #include <sys/stat.h> | 30 | #include <sys/stat.h> |
31 | #ifndef _WIN32_ | 31 | #ifndef _WIN32_ |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | #include <qtimer.h> | 36 | #include <qtimer.h> |
37 | #include <qwidget.h> | 37 | #include <qwidget.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 | //US #include <kgenericfactory.h> | 42 | //US #include <kgenericfactory.h> |
43 | #include <kglobal.h> | 43 | #include <kglobal.h> |
44 | #include <klocale.h> | 44 | #include <klocale.h> |
45 | #include <kstandarddirs.h> | 45 | #include <kstandarddirs.h> |
46 | #include <kurlrequester.h> | 46 | #include <kurlrequester.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | 48 | ||
49 | #include "addressbook.h" | 49 | #include "addressbook.h" |
50 | 50 | ||
51 | #include "formatfactory.h" | 51 | #include "formatfactory.h" |
52 | 52 | ||
53 | #include "resourcedirconfig.h" | 53 | #include "resourcedirconfig.h" |
54 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
55 | 55 | ||
56 | //US | 56 | //US |
57 | #include <qdir.h> | 57 | #include <qdir.h> |
58 | 58 | ||
59 | #include "resourcedir.h" | 59 | #include "resourcedir.h" |
60 | #include "syncprefwidget.h" | 60 | #include "syncprefwidget.h" |
61 | 61 | ||
62 | using namespace KABC; | 62 | using namespace KABC; |
63 | 63 | ||
64 | extern "C" | 64 | extern "C" |
65 | #ifdef _WIN32_ | 65 | #ifdef _WIN32_ |
66 | __declspec(dllexport) | 66 | __declspec(dllexport) |
67 | #else | 67 | #else |
68 | { | 68 | { |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | //US void *init_kabc_dir() | 71 | //US void *init_kabc_dir() |
72 | void *init_microkabc_dir() | 72 | void *init_microkabc_dir() |
73 | { | 73 | { |
74 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidget>(); | 74 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>(); |
75 | } | 75 | } |
76 | #ifndef _WIN32_ | 76 | #ifndef _WIN32_ |
77 | } | 77 | } |
78 | #endif | 78 | #endif |
79 | 79 | ||
80 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) | 80 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) |
81 | : Resource( config, syncable ) | 81 | : Resource( config, syncable ) |
82 | { | 82 | { |
83 | QString path; | 83 | QString path; |
84 | 84 | ||
85 | KConfig *cfg = (KConfig *)config; | 85 | KConfig *cfg = (KConfig *)config; |
86 | if ( cfg ) { | 86 | if ( cfg ) { |
87 | //US path = config->readEntry( "FilePath" ); | 87 | //US path = config->readEntry( "FilePath" ); |
88 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); | 88 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); |
89 | //US mFormatName = config->readEntry( "FileFormat" ); | 89 | //US mFormatName = config->readEntry( "FileFormat" ); |
90 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); | 90 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); |
91 | } else { | 91 | } else { |
92 | path = StdAddressBook::directoryName(); | 92 | path = StdAddressBook::directoryName(); |
93 | mFormatName = "vcard"; | 93 | mFormatName = "vcard"; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | FormatFactory *factory = FormatFactory::self(); | 97 | FormatFactory *factory = FormatFactory::self(); |
98 | mFormat = factory->format( mFormatName ); | 98 | mFormat = factory->format( mFormatName ); |
99 | 99 | ||
100 | if ( !mFormat ) { | 100 | if ( !mFormat ) { |
101 | mFormatName = "vcard"; | 101 | mFormatName = "vcard"; |
102 | mFormat = factory->format( mFormatName ); | 102 | mFormat = factory->format( mFormatName ); |
103 | } | 103 | } |
104 | 104 | ||
105 | /*US | 105 | /*US |
106 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); | 106 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); |
107 | if (mFormatName == "vcard") | 107 | if (mFormatName == "vcard") |
108 | mFormat = new VCardFormatPlugin2(); | 108 | mFormat = new VCardFormatPlugin2(); |
109 | else if (mFormatName == "binary") | 109 | else if (mFormatName == "binary") |
110 | mFormat = new BinaryFormat(); | 110 | mFormat = new BinaryFormat(); |
111 | else | 111 | else |
112 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); | 112 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); |
113 | */ | 113 | */ |
114 | 114 | ||
115 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); | 115 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); |
116 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); | 116 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); |
117 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); | 117 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); |
118 | 118 | ||
119 | setPath( path ); | 119 | setPath( path ); |
120 | } | 120 | } |
121 | 121 | ||
122 | ResourceDir::~ResourceDir() | 122 | ResourceDir::~ResourceDir() |
123 | { | 123 | { |
124 | delete mFormat; | 124 | delete mFormat; |
125 | mFormat = 0; | 125 | mFormat = 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | void ResourceDir::writeConfig( KConfig *config ) | 128 | void ResourceDir::writeConfig( KConfig *config ) |
129 | { | 129 | { |
130 | config->setGroup( "Resource_" + identifier() ); | 130 | config->setGroup( "Resource_" + identifier() ); |
131 | Resource::writeConfig( config ); | 131 | Resource::writeConfig( config ); |
132 | 132 | ||
133 | config->writeEntry( "FilePath", mPath ); | 133 | config->writeEntry( "FilePath", mPath ); |
134 | config->writeEntry( "FileFormat", mFormatName ); | 134 | config->writeEntry( "FileFormat", mFormatName ); |
135 | } | 135 | } |
136 | 136 | ||
137 | Ticket *ResourceDir::requestSaveTicket() | 137 | Ticket *ResourceDir::requestSaveTicket() |
138 | { | 138 | { |
139 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; | 139 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; |
140 | 140 | ||
141 | if ( !addressBook() ) return 0; | 141 | if ( !addressBook() ) return 0; |
142 | 142 | ||
143 | if ( !lock( mPath ) ) { | 143 | if ( !lock( mPath ) ) { |
144 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" | 144 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" |
145 | << mPath << "'" << endl; | 145 | << mPath << "'" << endl; |
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | return createTicket( this ); | 148 | return createTicket( this ); |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | bool ResourceDir::doOpen() | 152 | bool ResourceDir::doOpen() |
153 | { | 153 | { |
154 | QDir dir( mPath ); | 154 | QDir dir( mPath ); |
155 | if ( !dir.exists() ) { // no directory available | 155 | if ( !dir.exists() ) { // no directory available |
156 | return dir.mkdir( dir.path() ); | 156 | return dir.mkdir( dir.path() ); |
157 | } else { | 157 | } else { |
158 | QString testName = dir.entryList( QDir::Files )[0]; | 158 | QString testName = dir.entryList( QDir::Files )[0]; |
159 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory | 159 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory |
160 | return true; | 160 | return true; |
161 | 161 | ||
162 | QFile file( mPath + "/" + testName ); | 162 | QFile file( mPath + "/" + testName ); |
163 | if ( file.open( IO_ReadOnly ) ) | 163 | if ( file.open( IO_ReadOnly ) ) |
164 | return true; | 164 | return true; |
165 | 165 | ||
166 | if ( file.size() == 0 ) | 166 | if ( file.size() == 0 ) |
167 | return true; | 167 | return true; |
168 | 168 | ||
169 | bool ok = mFormat->checkFormat( &file ); | 169 | bool ok = mFormat->checkFormat( &file ); |
170 | file.close(); | 170 | file.close(); |
171 | return ok; | 171 | return ok; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | void ResourceDir::doClose() | 175 | void ResourceDir::doClose() |
176 | { | 176 | { |
177 | } | 177 | } |
178 | 178 | ||
179 | bool ResourceDir::load() | 179 | bool ResourceDir::load() |
180 | { | 180 | { |
181 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; | 181 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; |
182 | 182 | ||
183 | QDir dir( mPath ); | 183 | QDir dir( mPath ); |
184 | QStringList files = dir.entryList( QDir::Files ); | 184 | QStringList files = dir.entryList( QDir::Files ); |
185 | 185 | ||
186 | QStringList::Iterator it; | 186 | QStringList::Iterator it; |
187 | bool ok = true; | 187 | bool ok = true; |
188 | for ( it = files.begin(); it != files.end(); ++it ) { | 188 | for ( it = files.begin(); it != files.end(); ++it ) { |
189 | QFile file( mPath + "/" + (*it) ); | 189 | QFile file( mPath + "/" + (*it) ); |
190 | 190 | ||
191 | if ( !file.open( IO_ReadOnly ) ) { | 191 | if ( !file.open( IO_ReadOnly ) ) { |
192 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); | 192 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); |
193 | ok = false; | 193 | ok = false; |
194 | continue; | 194 | continue; |
195 | } | 195 | } |
196 | 196 | ||
197 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) | 197 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) |
198 | ok = false; | 198 | ok = false; |
199 | 199 | ||
200 | file.close(); | 200 | file.close(); |
201 | } | 201 | } |
202 | 202 | ||
203 | return ok; | 203 | return ok; |
204 | } | 204 | } |
205 | 205 | ||
206 | bool ResourceDir::save( Ticket *ticket ) | 206 | bool ResourceDir::save( Ticket *ticket ) |
207 | { | 207 | { |
208 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; | 208 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; |
209 | 209 | ||
210 | AddressBook::Iterator it; | 210 | AddressBook::Iterator it; |
211 | bool ok = true; | 211 | bool ok = true; |
212 | 212 | ||
213 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 213 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
214 | if ( (*it).resource() != this || !(*it).changed() ) | 214 | if ( (*it).resource() != this || !(*it).changed() ) |
215 | continue; | 215 | continue; |
216 | 216 | ||
217 | QFile file( mPath + "/" + (*it).uid() ); | 217 | QFile file( mPath + "/" + (*it).uid() ); |
218 | if ( !file.open( IO_WriteOnly ) ) { | 218 | if ( !file.open( IO_WriteOnly ) ) { |
219 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); | 219 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); |
220 | continue; | 220 | continue; |
221 | } | 221 | } |
222 | 222 | ||
223 | mFormat->save( *it, &file ); | 223 | mFormat->save( *it, &file ); |
224 | 224 | ||
225 | // mark as unchanged | 225 | // mark as unchanged |
226 | (*it).setChanged( false ); | 226 | (*it).setChanged( false ); |
227 | 227 | ||
228 | file.close(); | 228 | file.close(); |
229 | } | 229 | } |
230 | 230 | ||
231 | delete ticket; | 231 | delete ticket; |
232 | unlock( mPath ); | 232 | unlock( mPath ); |
233 | 233 | ||
234 | return ok; | 234 | return ok; |
235 | } | 235 | } |
236 | 236 | ||
237 | bool ResourceDir::lock( const QString &path ) | 237 | bool ResourceDir::lock( const QString &path ) |
238 | { | 238 | { |
239 | kdDebug(5700) << "ResourceDir::lock()" << endl; | 239 | kdDebug(5700) << "ResourceDir::lock()" << endl; |
240 | 240 | ||
241 | QString p = path; | 241 | QString p = path; |
242 | //US change the implementation how the lockfilename is getting created | 242 | //US change the implementation how the lockfilename is getting created |
243 | //US p.replace( QRegExp("/"), "_" ); | 243 | //US p.replace( QRegExp("/"), "_" ); |
244 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); | 244 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); |
245 | KURL url(p); | 245 | KURL url(p); |
246 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 246 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
247 | 247 | ||
248 | 248 | ||
249 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 249 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
250 | 250 | ||
251 | if ( QFile::exists( lockName ) ) return false; | 251 | if ( QFile::exists( lockName ) ) return false; |
252 | 252 | ||
253 | QString lockUniqueName; | 253 | QString lockUniqueName; |
254 | lockUniqueName = p + KApplication::randomString( 8 ); | 254 | lockUniqueName = p + KApplication::randomString( 8 ); |
255 | 255 | ||
256 | url = lockUniqueName; | 256 | url = lockUniqueName; |
257 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 257 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
258 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 258 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
259 | 259 | ||
260 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 260 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
261 | 261 | ||
262 | // Create unique file | 262 | // Create unique file |
263 | QFile file( mLockUniqueName ); | 263 | QFile file( mLockUniqueName ); |
264 | file.open( IO_WriteOnly ); | 264 | file.open( IO_WriteOnly ); |
265 | file.close(); | 265 | file.close(); |
266 | 266 | ||
267 | // Create lock file | 267 | // Create lock file |
268 | int result = 0; | 268 | int result = 0; |
269 | #ifndef _WIN32_ | 269 | #ifndef _WIN32_ |
270 | result = ::link( QFile::encodeName( mLockUniqueName ), | 270 | result = ::link( QFile::encodeName( mLockUniqueName ), |
271 | QFile::encodeName( lockName ) ); | 271 | QFile::encodeName( lockName ) ); |
272 | #endif | 272 | #endif |
273 | if ( result == 0 ) { | 273 | if ( result == 0 ) { |
274 | addressBook()->emitAddressBookLocked(); | 274 | addressBook()->emitAddressBookLocked(); |
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | 277 | ||
278 | // TODO: check stat | 278 | // TODO: check stat |
279 | 279 | ||
280 | return false; | 280 | return false; |
281 | } | 281 | } |
282 | 282 | ||
283 | void ResourceDir::unlock( const QString &path ) | 283 | void ResourceDir::unlock( const QString &path ) |
284 | { | 284 | { |
285 | QString p = path; | 285 | QString p = path; |
286 | //US change the implementation how the lockfilename is getting created | 286 | //US change the implementation how the lockfilename is getting created |
287 | //US p.replace( QRegExp( "/" ), "_" ); | 287 | //US p.replace( QRegExp( "/" ), "_" ); |
288 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); | 288 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); |
289 | KURL url(p); | 289 | KURL url(p); |
290 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 290 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
291 | 291 | ||
292 | ::unlink( QFile::encodeName( lockName ) ); | 292 | ::unlink( QFile::encodeName( lockName ) ); |
293 | QFile::remove( mLockUniqueName ); | 293 | QFile::remove( mLockUniqueName ); |
294 | addressBook()->emitAddressBookUnlocked(); | 294 | addressBook()->emitAddressBookUnlocked(); |
295 | } | 295 | } |
296 | 296 | ||
297 | void ResourceDir::setPath( const QString &path ) | 297 | void ResourceDir::setPath( const QString &path ) |
298 | { | 298 | { |
299 | mDirWatch.stopScan(); | 299 | mDirWatch.stopScan(); |
300 | mDirWatch.removeDir( mPath ); | 300 | mDirWatch.removeDir( mPath ); |
301 | 301 | ||
302 | mPath = path; | 302 | mPath = path; |
303 | 303 | ||
304 | mDirWatch.addDir( mPath, true ); | 304 | mDirWatch.addDir( mPath, true ); |
305 | mDirWatch.startScan(); | 305 | mDirWatch.startScan(); |
306 | 306 | ||
307 | //US simulate KDirWatch event | 307 | //US simulate KDirWatch event |
308 | //US pathChanged(); | 308 | //US pathChanged(); |
309 | 309 | ||
310 | } | 310 | } |
311 | 311 | ||
312 | QString ResourceDir::path() const | 312 | QString ResourceDir::path() const |
313 | { | 313 | { |
314 | return mPath; | 314 | return mPath; |
315 | } | 315 | } |
316 | 316 | ||
317 | void ResourceDir::setFormat( const QString &format ) | 317 | void ResourceDir::setFormat( const QString &format ) |
318 | { | 318 | { |
319 | mFormatName = format; | 319 | mFormatName = format; |
320 | 320 | ||
321 | if ( mFormat ) | 321 | if ( mFormat ) |
322 | delete mFormat; | 322 | delete mFormat; |
323 | 323 | ||
324 | FormatFactory *factory = FormatFactory::self(); | 324 | FormatFactory *factory = FormatFactory::self(); |
325 | mFormat = factory->format( mFormatName ); | 325 | mFormat = factory->format( mFormatName ); |
326 | /*US | 326 | /*US |
327 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); | 327 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); |
328 | if (mFormatName == "vcard") | 328 | if (mFormatName == "vcard") |
329 | mFormat = new VCardFormatPlugin2(); | 329 | mFormat = new VCardFormatPlugin2(); |
330 | else if (mFormatName == "binary") | 330 | else if (mFormatName == "binary") |
331 | mFormat = new BinaryFormat(); | 331 | mFormat = new BinaryFormat(); |
332 | else | 332 | else |
333 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); | 333 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); |
334 | */ | 334 | */ |
335 | 335 | ||
336 | } | 336 | } |
337 | 337 | ||
338 | QString ResourceDir::format() const | 338 | QString ResourceDir::format() const |
339 | { | 339 | { |
340 | return mFormatName; | 340 | return mFormatName; |
341 | } | 341 | } |
342 | 342 | ||
343 | void ResourceDir::pathChanged() | 343 | void ResourceDir::pathChanged() |
344 | { | 344 | { |
345 | if ( !addressBook() ) | 345 | if ( !addressBook() ) |
346 | return; | 346 | return; |
347 | 347 | ||
348 | QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); | 348 | QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); |
349 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 349 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
350 | load(); | 350 | load(); |
351 | addressBook()->emitAddressBookChanged(); | 351 | addressBook()->emitAddressBookChanged(); |
352 | } | 352 | } |
353 | } | 353 | } |
354 | 354 | ||
355 | void ResourceDir::removeAddressee( const Addressee& addr ) | 355 | void ResourceDir::removeAddressee( const Addressee& addr ) |
356 | { | 356 | { |
357 | QFile::remove( mPath + "/" + addr.uid() ); | 357 | QFile::remove( mPath + "/" + addr.uid() ); |
358 | } | 358 | } |
359 | 359 | ||
360 | void ResourceDir::cleanUp() | 360 | void ResourceDir::cleanUp() |
361 | { | 361 | { |
362 | unlock( mPath ); | 362 | unlock( mPath ); |
363 | } | 363 | } |
364 | 364 | ||
365 | //US #include "resourcedir.moc" | 365 | //US #include "resourcedir.moc" |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index d98efc8..da2e4d7 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -1,399 +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 | #include <kmessagebox.h> | 45 | #include <kmessagebox.h> |
46 | 46 | ||
47 | #include "formatfactory.h" | 47 | #include "formatfactory.h" |
48 | 48 | ||
49 | #include "resource.h" | 49 | #include "resource.h" |
50 | #include "resourcefileconfig.h" | 50 | #include "resourcefileconfig.h" |
51 | #include "stdaddressbook.h" | 51 | #include "stdaddressbook.h" |
52 | 52 | ||
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncprefwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | 56 | ||
57 | using namespace KABC; | 57 | using namespace KABC; |
58 | 58 | ||
59 | extern "C" | 59 | extern "C" |
60 | #ifdef _WIN32_ | 60 | #ifdef _WIN32_ |
61 | __declspec(dllexport) | 61 | __declspec(dllexport) |
62 | #else | 62 | #else |
63 | { | 63 | { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | //US void *init_kabc_file() | 66 | //US void *init_kabc_file() |
67 | void *init_microkabc_file() | 67 | void *init_microkabc_file() |
68 | { | 68 | { |
69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidget>(); | 69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); |
70 | } | 70 | } |
71 | #ifndef _WIN32_ | 71 | #ifndef _WIN32_ |
72 | } | 72 | } |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) | 75 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) |
76 | : Resource( config, syncable ) , mFormat( 0 ) | 76 | : Resource( config, syncable ) , mFormat( 0 ) |
77 | { | 77 | { |
78 | QString fileName, formatName; | 78 | QString fileName, formatName, default_fileName; |
79 | |||
80 | if (syncable == true) | ||
81 | default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; | ||
82 | else | ||
83 | default_fileName = StdAddressBook::fileName(); | ||
79 | 84 | ||
80 | KConfig *cfg = (KConfig *)config; | 85 | KConfig *cfg = (KConfig *)config; |
81 | if ( cfg ) { | 86 | if ( cfg ) { |
82 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | 87 | fileName = cfg->readEntry( "FileName", default_fileName ); |
83 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 88 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
84 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
85 | } else { | 89 | } else { |
86 | fileName = StdAddressBook::fileName(); | 90 | fileName = default_fileName; |
87 | formatName = "vcard"; | 91 | formatName = "vcard"; |
88 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
89 | } | 92 | } |
90 | 93 | ||
91 | init( fileName, formatName ); | 94 | init( fileName, formatName ); |
92 | } | 95 | } |
93 | 96 | ||
94 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , | 97 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , |
95 | const QString &formatName ) | 98 | const QString &formatName ) |
96 | : Resource( 0, syncable ) | 99 | : Resource( 0, syncable ) |
97 | { | 100 | { |
98 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 101 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
99 | init( fileName, formatName ); | 102 | init( fileName, formatName ); |
100 | } | 103 | } |
101 | 104 | ||
102 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 105 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
103 | { | 106 | { |
104 | mFormatName = formatName; | 107 | mFormatName = formatName; |
105 | 108 | ||
106 | FormatFactory *factory = FormatFactory::self(); | 109 | FormatFactory *factory = FormatFactory::self(); |
107 | mFormat = factory->format( mFormatName ); | 110 | mFormat = factory->format( mFormatName ); |
108 | 111 | ||
109 | if ( !mFormat ) { | 112 | if ( !mFormat ) { |
110 | mFormatName = "vcard"; | 113 | mFormatName = "vcard"; |
111 | mFormat = factory->format( mFormatName ); | 114 | mFormat = factory->format( mFormatName ); |
112 | } | 115 | } |
113 | 116 | ||
114 | /*US | ||
115 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); | ||
116 | if (mFormatName == "vcard") { | ||
117 | mFormat = new VCardFormatPlugin2(); | ||
118 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); | ||
119 | } | ||
120 | else if (mFormatName == "binary") { | ||
121 | mFormat = new BinaryFormat(); | ||
122 | // qDebug("ResourceFile::init format BinaryFormat"); | ||
123 | } | ||
124 | else | ||
125 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); | ||
126 | */ | ||
127 | 117 | ||
128 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 118 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
129 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 119 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
130 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 120 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
131 | 121 | ||
132 | setFileName( fileName ); | 122 | setFileName( fileName ); |
133 | } | 123 | } |
134 | 124 | ||
135 | ResourceFile::~ResourceFile() | 125 | ResourceFile::~ResourceFile() |
136 | { | 126 | { |
137 | delete mFormat; | 127 | delete mFormat; |
138 | mFormat = 0; | 128 | mFormat = 0; |
139 | } | 129 | } |
140 | 130 | ||
141 | void ResourceFile::writeConfig( KConfig *config ) | 131 | void ResourceFile::writeConfig( KConfig *config ) |
142 | { | 132 | { |
143 | 133 | ||
144 | config->setGroup( "Resource_" + identifier() ); | 134 | config->setGroup( "Resource_" + identifier() ); |
145 | Resource::writeConfig( config ); | 135 | Resource::writeConfig( config ); |
146 | 136 | ||
147 | config->writeEntry( "FileName", mFileName ); | 137 | config->writeEntry( "FileName", mFileName ); |
148 | config->writeEntry( "FileFormat", mFormatName ); | 138 | config->writeEntry( "FileFormat", mFormatName ); |
149 | 139 | ||
150 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 140 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
151 | 141 | ||
152 | } | 142 | } |
153 | 143 | ||
154 | Ticket *ResourceFile::requestSaveTicket() | 144 | Ticket *ResourceFile::requestSaveTicket() |
155 | { | 145 | { |
156 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 146 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
157 | 147 | ||
158 | if ( !addressBook() ) return 0; | 148 | if ( !addressBook() ) return 0; |
159 | 149 | ||
160 | if ( !lock( mFileName ) ) { | 150 | if ( !lock( mFileName ) ) { |
161 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | 151 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" |
162 | << mFileName << "'" << endl; | 152 | << mFileName << "'" << endl; |
163 | return 0; | 153 | return 0; |
164 | } | 154 | } |
165 | return createTicket( this ); | 155 | return createTicket( this ); |
166 | } | 156 | } |
167 | 157 | ||
168 | 158 | ||
169 | bool ResourceFile::doOpen() | 159 | bool ResourceFile::doOpen() |
170 | { | 160 | { |
171 | QFile file( mFileName ); | 161 | QFile file( mFileName ); |
172 | 162 | ||
173 | if ( !file.exists() ) { | 163 | if ( !file.exists() ) { |
174 | // try to create the file | 164 | // try to create the file |
175 | bool ok = file.open( IO_WriteOnly ); | 165 | bool ok = file.open( IO_WriteOnly ); |
176 | if ( ok ) | 166 | if ( ok ) |
177 | file.close(); | 167 | file.close(); |
178 | 168 | ||
179 | return ok; | 169 | return ok; |
180 | } else { | 170 | } else { |
181 | if ( !file.open( IO_ReadWrite ) ) | 171 | if ( !file.open( IO_ReadWrite ) ) |
182 | return false; | 172 | return false; |
183 | 173 | ||
184 | if ( file.size() == 0 ) { | 174 | if ( file.size() == 0 ) { |
185 | file.close(); | 175 | file.close(); |
186 | return true; | 176 | return true; |
187 | } | 177 | } |
188 | 178 | ||
189 | bool ok = mFormat->checkFormat( &file ); | 179 | bool ok = mFormat->checkFormat( &file ); |
190 | file.close(); | 180 | file.close(); |
191 | 181 | ||
192 | return ok; | 182 | return ok; |
193 | } | 183 | } |
194 | } | 184 | } |
195 | 185 | ||
196 | void ResourceFile::doClose() | 186 | void ResourceFile::doClose() |
197 | { | 187 | { |
198 | } | 188 | } |
199 | 189 | ||
200 | bool ResourceFile::load() | 190 | bool ResourceFile::load() |
201 | { | 191 | { |
202 | 192 | ||
203 | 193 | ||
204 | QFile file( mFileName ); | 194 | QFile file( mFileName ); |
205 | if ( !file.open( IO_ReadOnly ) ) { | 195 | if ( !file.open( IO_ReadOnly ) ) { |
206 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 196 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
207 | return false; | 197 | return false; |
208 | } | 198 | } |
209 | 199 | ||
210 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 200 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
211 | 201 | ||
212 | return mFormat->loadAll( addressBook(), this, &file ); | 202 | return mFormat->loadAll( addressBook(), this, &file ); |
213 | } | 203 | } |
214 | 204 | ||
215 | bool ResourceFile::save( Ticket *ticket ) | 205 | bool ResourceFile::save( Ticket *ticket ) |
216 | { | 206 | { |
217 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 207 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
218 | 208 | ||
219 | 209 | ||
220 | // create backup file | 210 | // create backup file |
221 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 211 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
222 | 212 | ||
223 | /*US we use a simpler method to create a backupfile | 213 | /*US we use a simpler method to create a backupfile |
224 | 214 | ||
225 | (void) KSaveFile::backupFile( mFileName, QString::null | 215 | (void) KSaveFile::backupFile( mFileName, QString::null |
226 | ,extension ); | 216 | ,extension ); |
227 | 217 | ||
228 | KSaveFile saveFile( mFileName ); | 218 | KSaveFile saveFile( mFileName ); |
229 | bool ok = false; | 219 | bool ok = false; |
230 | if ( saveFile.status() == 0 && saveFile.file() ) | 220 | if ( saveFile.status() == 0 && saveFile.file() ) |
231 | { | 221 | { |
232 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 222 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
233 | ok = saveFile.close(); | 223 | ok = saveFile.close(); |
234 | } | 224 | } |
235 | */ | 225 | */ |
236 | 226 | ||
237 | //US ToDo: write backupfile | 227 | //US ToDo: write backupfile |
238 | QFile info; | 228 | QFile info; |
239 | info.setName( mFileName ); | 229 | info.setName( mFileName ); |
240 | bool ok = info.open( IO_WriteOnly ); | 230 | bool ok = info.open( IO_WriteOnly ); |
241 | if ( ok ) { | 231 | if ( ok ) { |
242 | mFormat->saveAll( addressBook(), this, &info ); | 232 | mFormat->saveAll( addressBook(), this, &info ); |
243 | 233 | ||
244 | info.close(); | 234 | info.close(); |
245 | ok = true; | 235 | ok = true; |
246 | } | 236 | } |
247 | else { | 237 | else { |
248 | 238 | ||
249 | } | 239 | } |
250 | 240 | ||
251 | if ( !ok ) | 241 | if ( !ok ) |
252 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 242 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
253 | 243 | ||
254 | delete ticket; | 244 | delete ticket; |
255 | unlock( mFileName ); | 245 | unlock( mFileName ); |
256 | 246 | ||
257 | return ok; | 247 | return ok; |
258 | 248 | ||
259 | qDebug("ResourceFile::save has to be changed"); | 249 | qDebug("ResourceFile::save has to be changed"); |
260 | return true; | 250 | return true; |
261 | } | 251 | } |
262 | 252 | ||
263 | bool ResourceFile::lock( const QString &fileName ) | 253 | bool ResourceFile::lock( const QString &fileName ) |
264 | { | 254 | { |
265 | 255 | ||
266 | 256 | ||
267 | QString fn = fileName; | 257 | QString fn = fileName; |
268 | 258 | ||
269 | //US change the implementation how the lockfilename is getting created | 259 | //US change the implementation how the lockfilename is getting created |
270 | //US fn.replace( QRegExp("/"), "_" ); | 260 | //US fn.replace( QRegExp("/"), "_" ); |
271 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 261 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
272 | 262 | ||
273 | KURL url(fn); | 263 | KURL url(fn); |
274 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 264 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
275 | 265 | ||
276 | 266 | ||
277 | 267 | ||
278 | if (QFile::exists( lockName )) return false; | 268 | if (QFile::exists( lockName )) return false; |
279 | 269 | ||
280 | QString lockUniqueName; | 270 | QString lockUniqueName; |
281 | lockUniqueName = fn + KApplication::randomString( 8 ); | 271 | lockUniqueName = fn + KApplication::randomString( 8 ); |
282 | 272 | ||
283 | url = lockUniqueName; | 273 | url = lockUniqueName; |
284 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 274 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
285 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 275 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
286 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 276 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
287 | 277 | ||
288 | // Create unique file | 278 | // Create unique file |
289 | QFile file( mLockUniqueName ); | 279 | QFile file( mLockUniqueName ); |
290 | file.open( IO_WriteOnly ); | 280 | file.open( IO_WriteOnly ); |
291 | file.close(); | 281 | file.close(); |
292 | 282 | ||
293 | // Create lock file | 283 | // Create lock file |
294 | int result = 0; | 284 | int result = 0; |
295 | #ifndef _WIN32_ | 285 | #ifndef _WIN32_ |
296 | result = ::link( QFile::encodeName( mLockUniqueName ), | 286 | result = ::link( QFile::encodeName( mLockUniqueName ), |
297 | QFile::encodeName( lockName ) ); | 287 | QFile::encodeName( lockName ) ); |
298 | #endif | 288 | #endif |
299 | if ( result == 0 ) { | 289 | if ( result == 0 ) { |
300 | addressBook()->emitAddressBookLocked(); | 290 | addressBook()->emitAddressBookLocked(); |
301 | return true; | 291 | return true; |
302 | } | 292 | } |
303 | 293 | ||
304 | // TODO: check stat | 294 | // TODO: check stat |
305 | 295 | ||
306 | return false; | 296 | return false; |
307 | } | 297 | } |
308 | 298 | ||
309 | void ResourceFile::unlock( const QString &fileName ) | 299 | void ResourceFile::unlock( const QString &fileName ) |
310 | { | 300 | { |
311 | QString fn = fileName; | 301 | QString fn = fileName; |
312 | //US change the implementation how the lockfilename is getting created | 302 | //US change the implementation how the lockfilename is getting created |
313 | //US fn.replace( QRegExp( "/" ), "_" ); | 303 | //US fn.replace( QRegExp( "/" ), "_" ); |
314 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 304 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
315 | //US QString lockName = fn + ".lock"; | 305 | //US QString lockName = fn + ".lock"; |
316 | KURL url(fn); | 306 | KURL url(fn); |
317 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 307 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
318 | 308 | ||
319 | QFile::remove( lockName ); | 309 | QFile::remove( lockName ); |
320 | QFile::remove( mLockUniqueName ); | 310 | QFile::remove( mLockUniqueName ); |
321 | addressBook()->emitAddressBookUnlocked(); | 311 | addressBook()->emitAddressBookUnlocked(); |
322 | } | 312 | } |
323 | 313 | ||
324 | void ResourceFile::setFileName( const QString &fileName ) | 314 | void ResourceFile::setFileName( const QString &fileName ) |
325 | { | 315 | { |
326 | mDirWatch.stopScan(); | 316 | mDirWatch.stopScan(); |
327 | mDirWatch.removeFile( mFileName ); | 317 | mDirWatch.removeFile( mFileName ); |
328 | 318 | ||
329 | mFileName = fileName; | 319 | mFileName = fileName; |
330 | 320 | ||
331 | 321 | ||
332 | mDirWatch.addFile( mFileName ); | 322 | mDirWatch.addFile( mFileName ); |
333 | mDirWatch.startScan(); | 323 | mDirWatch.startScan(); |
334 | 324 | ||
335 | //US simulate KDirWatch event | 325 | //US simulate KDirWatch event |
336 | //US fileChanged(); | 326 | //US fileChanged(); |
337 | } | 327 | } |
338 | 328 | ||
339 | QString ResourceFile::fileName() const | 329 | QString ResourceFile::fileName() const |
340 | { | 330 | { |
341 | return mFileName; | 331 | return mFileName; |
342 | } | 332 | } |
343 | 333 | ||
344 | void ResourceFile::setFormat( const QString &format ) | 334 | void ResourceFile::setFormat( const QString &format ) |
345 | { | 335 | { |
346 | mFormatName = format; | 336 | mFormatName = format; |
347 | delete mFormat; | 337 | delete mFormat; |
348 | 338 | ||
349 | FormatFactory *factory = FormatFactory::self(); | 339 | FormatFactory *factory = FormatFactory::self(); |
350 | mFormat = factory->format( mFormatName ); | 340 | mFormat = factory->format( mFormatName ); |
351 | /*US | 341 | /*US |
352 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 342 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
353 | if (mFormatName == "vcard") { | 343 | if (mFormatName == "vcard") { |
354 | mFormat = new VCardFormatPlugin2(); | 344 | mFormat = new VCardFormatPlugin2(); |
355 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 345 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
356 | } | 346 | } |
357 | else if (mFormatName == "binary") { | 347 | else if (mFormatName == "binary") { |
358 | mFormat = new BinaryFormat(); | 348 | mFormat = new BinaryFormat(); |
359 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 349 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
360 | } | 350 | } |
361 | else | 351 | else |
362 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 352 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
363 | */ | 353 | */ |
364 | 354 | ||
365 | } | 355 | } |
366 | 356 | ||
367 | QString ResourceFile::format() const | 357 | QString ResourceFile::format() const |
368 | { | 358 | { |
369 | return mFormatName; | 359 | return mFormatName; |
370 | } | 360 | } |
371 | 361 | ||
372 | void ResourceFile::fileChanged() | 362 | void ResourceFile::fileChanged() |
373 | { | 363 | { |
374 | // There is a small theoretical chance that KDirWatch calls us before | 364 | // There is a small theoretical chance that KDirWatch calls us before |
375 | // we are fully constructed | 365 | // we are fully constructed |
376 | if (!addressBook()) | 366 | if (!addressBook()) |
377 | return; | 367 | return; |
378 | 368 | ||
379 | 369 | ||
380 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 370 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); |
381 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 371 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
382 | load(); | 372 | load(); |
383 | addressBook()->emitAddressBookChanged(); | 373 | addressBook()->emitAddressBookChanged(); |
384 | } | 374 | } |
385 | } | 375 | } |
386 | 376 | ||
387 | void ResourceFile::removeAddressee( const Addressee &addr ) | 377 | void ResourceFile::removeAddressee( const Addressee &addr ) |
388 | { | 378 | { |
389 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 379 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
390 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 380 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
391 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 381 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
392 | } | 382 | } |
393 | 383 | ||
394 | void ResourceFile::cleanUp() | 384 | void ResourceFile::cleanUp() |
395 | { | 385 | { |
396 | unlock( mFileName ); | 386 | unlock( mFileName ); |
397 | } | 387 | } |
398 | 388 | ||
399 | //US #include "resourcefile.moc" | 389 | //US #include "resourcefile.moc" |
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp index 198e80a..17f115d 100644 --- a/kabc/plugins/ldap/resourceldap.cpp +++ b/kabc/plugins/ldap/resourceldap.cpp | |||
@@ -1,445 +1,445 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 <kdebug.h> | 28 | #include <kdebug.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klineedit.h> | 30 | #include <klineedit.h> |
31 | #include <klocale.h> | 31 | #include <klocale.h> |
32 | #include <kconfig.h> | 32 | #include <kconfig.h> |
33 | #include <kstringhandler.h> | 33 | #include <kstringhandler.h> |
34 | 34 | ||
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | 36 | ||
37 | #include "resourceldap.h" | 37 | #include "resourceldap.h" |
38 | #include "resourceldapconfig.h" | 38 | #include "resourceldapconfig.h" |
39 | #include "syncprefwidget.h" | 39 | #include "syncprefwidget.h" |
40 | 40 | ||
41 | using namespace KABC; | 41 | using namespace KABC; |
42 | 42 | ||
43 | extern "C" | 43 | extern "C" |
44 | { | 44 | { |
45 | //US void *init_kabc_ldap() | 45 | //US void *init_kabc_ldap() |
46 | void *init_microkabc_ldap() | 46 | void *init_microkabc_ldap() |
47 | { | 47 | { |
48 | return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidget>(); | 48 | return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidgetContainer>(); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); | 52 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); |
53 | 53 | ||
54 | 54 | ||
55 | ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) | 55 | ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) |
56 | : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) | 56 | : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) |
57 | { | 57 | { |
58 | KConfig *cfg = (KConfig *)config; | 58 | KConfig *cfg = (KConfig *)config; |
59 | if ( cfg ) { | 59 | if ( cfg ) { |
60 | mUser = cfg->readEntry( "LdapUser" ); | 60 | mUser = cfg->readEntry( "LdapUser" ); |
61 | mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); | 61 | mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); |
62 | mDn = cfg->readEntry( "LdapDn" ); | 62 | mDn = cfg->readEntry( "LdapDn" ); |
63 | mHost = cfg->readEntry( "LdapHost" ); | 63 | mHost = cfg->readEntry( "LdapHost" ); |
64 | mPort = cfg->readNumEntry( "LdapPort", 389 ); | 64 | mPort = cfg->readNumEntry( "LdapPort", 389 ); |
65 | mFilter = cfg->readEntry( "LdapFilter" ); | 65 | mFilter = cfg->readEntry( "LdapFilter" ); |
66 | mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); | 66 | mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); |
67 | 67 | ||
68 | QStringList attributes = cfg->readListEntry( "LdapAttributes" ); | 68 | QStringList attributes = cfg->readListEntry( "LdapAttributes" ); |
69 | for ( uint pos = 0; pos < attributes.count(); pos += 2 ) | 69 | for ( uint pos = 0; pos < attributes.count(); pos += 2 ) |
70 | mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); | 70 | mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); |
71 | } | 71 | } |
72 | 72 | ||
73 | /** | 73 | /** |
74 | If you want to add new attributes, append them here, add a | 74 | If you want to add new attributes, append them here, add a |
75 | translation string in the ctor of AttributesDialog and | 75 | translation string in the ctor of AttributesDialog and |
76 | handle them in the load() method below. | 76 | handle them in the load() method below. |
77 | These are the default values from | 77 | These are the default values from |
78 | */ | 78 | */ |
79 | if ( mAttributes.count() == 0 ) { | 79 | if ( mAttributes.count() == 0 ) { |
80 | mAttributes.insert( "commonName", "cn" ); | 80 | mAttributes.insert( "commonName", "cn" ); |
81 | mAttributes.insert( "formattedName", "displayName" ); | 81 | mAttributes.insert( "formattedName", "displayName" ); |
82 | mAttributes.insert( "familyName", "sn" ); | 82 | mAttributes.insert( "familyName", "sn" ); |
83 | mAttributes.insert( "givenName", "givenName" ); | 83 | mAttributes.insert( "givenName", "givenName" ); |
84 | mAttributes.insert( "mail", "mail" ); | 84 | mAttributes.insert( "mail", "mail" ); |
85 | mAttributes.insert( "mailAlias", "" ); | 85 | mAttributes.insert( "mailAlias", "" ); |
86 | mAttributes.insert( "phoneNumber", "telephoneNumber" ); | 86 | mAttributes.insert( "phoneNumber", "telephoneNumber" ); |
87 | mAttributes.insert( "uid", "uid" ); | 87 | mAttributes.insert( "uid", "uid" ); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | void ResourceLDAP::writeConfig( KConfig *config ) | 91 | void ResourceLDAP::writeConfig( KConfig *config ) |
92 | { | 92 | { |
93 | Resource::writeConfig( config ); | 93 | Resource::writeConfig( config ); |
94 | 94 | ||
95 | config->writeEntry( "LdapUser", mUser ); | 95 | config->writeEntry( "LdapUser", mUser ); |
96 | config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); | 96 | config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); |
97 | config->writeEntry( "LdapDn", mDn ); | 97 | config->writeEntry( "LdapDn", mDn ); |
98 | config->writeEntry( "LdapHost", mHost ); | 98 | config->writeEntry( "LdapHost", mHost ); |
99 | config->writeEntry( "LdapPort", mPort ); | 99 | config->writeEntry( "LdapPort", mPort ); |
100 | config->writeEntry( "LdapFilter", mFilter ); | 100 | config->writeEntry( "LdapFilter", mFilter ); |
101 | config->writeEntry( "LdapAnonymous", mAnonymous ); | 101 | config->writeEntry( "LdapAnonymous", mAnonymous ); |
102 | 102 | ||
103 | QStringList attributes; | 103 | QStringList attributes; |
104 | QMap<QString, QString>::Iterator it; | 104 | QMap<QString, QString>::Iterator it; |
105 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) | 105 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) |
106 | attributes << it.key() << it.data(); | 106 | attributes << it.key() << it.data(); |
107 | 107 | ||
108 | config->writeEntry( "LdapAttributes", attributes ); | 108 | config->writeEntry( "LdapAttributes", attributes ); |
109 | } | 109 | } |
110 | 110 | ||
111 | Ticket *ResourceLDAP::requestSaveTicket() | 111 | Ticket *ResourceLDAP::requestSaveTicket() |
112 | { | 112 | { |
113 | if ( !addressBook() ) { | 113 | if ( !addressBook() ) { |
114 | kdDebug(5700) << "no addressbook" << endl; | 114 | kdDebug(5700) << "no addressbook" << endl; |
115 | return 0; | 115 | return 0; |
116 | } | 116 | } |
117 | 117 | ||
118 | return createTicket( this ); | 118 | return createTicket( this ); |
119 | } | 119 | } |
120 | 120 | ||
121 | bool ResourceLDAP::doOpen() | 121 | bool ResourceLDAP::doOpen() |
122 | { | 122 | { |
123 | if ( mLdap ) | 123 | if ( mLdap ) |
124 | return false; | 124 | return false; |
125 | 125 | ||
126 | if ( !mPort ) | 126 | if ( !mPort ) |
127 | mPort = 389; | 127 | mPort = 389; |
128 | 128 | ||
129 | mLdap = ldap_init( mHost.local8Bit(), mPort ); | 129 | mLdap = ldap_init( mHost.local8Bit(), mPort ); |
130 | if ( !mLdap ) { | 130 | if ( !mLdap ) { |
131 | addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); | 131 | addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); |
132 | return false; | 132 | return false; |
133 | } | 133 | } |
134 | 134 | ||
135 | if ( !mUser.isEmpty() && !mAnonymous ) { | 135 | if ( !mUser.isEmpty() && !mAnonymous ) { |
136 | if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { | 136 | if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { |
137 | addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); | 137 | addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); |
138 | return false; | 138 | return false; |
139 | } | 139 | } |
140 | 140 | ||
141 | kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; | 141 | kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; |
142 | } else { | 142 | } else { |
143 | if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { | 143 | if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { |
144 | addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); | 144 | addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); |
145 | return false; | 145 | return false; |
146 | } | 146 | } |
147 | 147 | ||
148 | kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; | 148 | kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; |
149 | } | 149 | } |
150 | 150 | ||
151 | int deref = LDAP_DEREF_ALWAYS; | 151 | int deref = LDAP_DEREF_ALWAYS; |
152 | if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { | 152 | if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { |
153 | kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; | 153 | kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; |
154 | return false; | 154 | return false; |
155 | } | 155 | } |
156 | 156 | ||
157 | if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { | 157 | if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { |
158 | kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; | 158 | kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; |
159 | return false; | 159 | return false; |
160 | } | 160 | } |
161 | 161 | ||
162 | return true; | 162 | return true; |
163 | } | 163 | } |
164 | 164 | ||
165 | void ResourceLDAP::doClose() | 165 | void ResourceLDAP::doClose() |
166 | { | 166 | { |
167 | if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { | 167 | if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { |
168 | kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; | 168 | kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; |
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | 171 | ||
172 | mLdap = 0; | 172 | mLdap = 0; |
173 | } | 173 | } |
174 | 174 | ||
175 | bool ResourceLDAP::load() | 175 | bool ResourceLDAP::load() |
176 | { | 176 | { |
177 | LDAPMessage *res; | 177 | LDAPMessage *res; |
178 | LDAPMessage *msg; | 178 | LDAPMessage *msg; |
179 | BerElement *track; | 179 | BerElement *track; |
180 | char *names; | 180 | char *names; |
181 | char **values; | 181 | char **values; |
182 | 182 | ||
183 | char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; | 183 | char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; |
184 | 184 | ||
185 | QMap<QString, QString>::Iterator it; | 185 | QMap<QString, QString>::Iterator it; |
186 | int i = 0; | 186 | int i = 0; |
187 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { | 187 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { |
188 | if ( !it.data().isEmpty() ) { | 188 | if ( !it.data().isEmpty() ) { |
189 | unsigned int len = it.data().utf8().length(); | 189 | unsigned int len = it.data().utf8().length(); |
190 | LdapSearchAttr[ i ] = new char[ len+1 ]; | 190 | LdapSearchAttr[ i ] = new char[ len+1 ]; |
191 | memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); | 191 | memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); |
192 | LdapSearchAttr[ i ][ len ] = 0; | 192 | LdapSearchAttr[ i ][ len ] = 0; |
193 | ++i; | 193 | ++i; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | LdapSearchAttr[ i ] = 0; | 196 | LdapSearchAttr[ i ] = 0; |
197 | 197 | ||
198 | QString filter = mFilter; | 198 | QString filter = mFilter; |
199 | if ( filter.isEmpty() ) | 199 | if ( filter.isEmpty() ) |
200 | filter = "cn=*"; | 200 | filter = "cn=*"; |
201 | 201 | ||
202 | int result; | 202 | int result; |
203 | if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), | 203 | if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), |
204 | LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { | 204 | LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { |
205 | addressBook()->error( i18n( "Unable to search on server '%1': %2" ) | 205 | addressBook()->error( i18n( "Unable to search on server '%1': %2" ) |
206 | .arg( mHost ) | 206 | .arg( mHost ) |
207 | .arg( ldap_err2string( result ) ) ); | 207 | .arg( ldap_err2string( result ) ) ); |
208 | 208 | ||
209 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) | 209 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) |
210 | delete [] LdapSearchAttr[ i ]; | 210 | delete [] LdapSearchAttr[ i ]; |
211 | delete [] LdapSearchAttr; | 211 | delete [] LdapSearchAttr; |
212 | 212 | ||
213 | return false; | 213 | return false; |
214 | } | 214 | } |
215 | 215 | ||
216 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { | 216 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { |
217 | Addressee addr; | 217 | Addressee addr; |
218 | addr.setResource( this ); | 218 | addr.setResource( this ); |
219 | for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { | 219 | for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { |
220 | values = ldap_get_values( mLdap, msg, names ); | 220 | values = ldap_get_values( mLdap, msg, names ); |
221 | for ( int i = 0; i < ldap_count_values( values ); ++i ) { | 221 | for ( int i = 0; i < ldap_count_values( values ); ++i ) { |
222 | QString name = QString::fromUtf8( names ).lower(); | 222 | QString name = QString::fromUtf8( names ).lower(); |
223 | QString value = QString::fromUtf8( values[ i ] ); | 223 | QString value = QString::fromUtf8( values[ i ] ); |
224 | 224 | ||
225 | if ( name == mAttributes[ "commonName" ].lower() ) { | 225 | if ( name == mAttributes[ "commonName" ].lower() ) { |
226 | if ( !addr.formattedName().isEmpty() ) { | 226 | if ( !addr.formattedName().isEmpty() ) { |
227 | QString fn = addr.formattedName(); | 227 | QString fn = addr.formattedName(); |
228 | addr.setNameFromString( value ); | 228 | addr.setNameFromString( value ); |
229 | addr.setFormattedName( fn ); | 229 | addr.setFormattedName( fn ); |
230 | } else | 230 | } else |
231 | addr.setNameFromString( value ); | 231 | addr.setNameFromString( value ); |
232 | } else if ( name == mAttributes[ "formattedName" ].lower() ) { | 232 | } else if ( name == mAttributes[ "formattedName" ].lower() ) { |
233 | addr.setFormattedName( value ); | 233 | addr.setFormattedName( value ); |
234 | } else if ( name == mAttributes[ "givenName" ].lower() ) { | 234 | } else if ( name == mAttributes[ "givenName" ].lower() ) { |
235 | addr.setGivenName( value ); | 235 | addr.setGivenName( value ); |
236 | } else if ( name == mAttributes[ "mail" ].lower() ) { | 236 | } else if ( name == mAttributes[ "mail" ].lower() ) { |
237 | addr.insertEmail( value, true ); | 237 | addr.insertEmail( value, true ); |
238 | } else if ( name == mAttributes[ "mailAlias" ].lower() ) { | 238 | } else if ( name == mAttributes[ "mailAlias" ].lower() ) { |
239 | addr.insertEmail( value, false ); | 239 | addr.insertEmail( value, false ); |
240 | } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { | 240 | } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { |
241 | PhoneNumber phone; | 241 | PhoneNumber phone; |
242 | phone.setNumber( value ); | 242 | phone.setNumber( value ); |
243 | addr.insertPhoneNumber( phone ); | 243 | addr.insertPhoneNumber( phone ); |
244 | break; // read only the home number | 244 | break; // read only the home number |
245 | } else if ( name == mAttributes[ "familyName" ].lower() ) { | 245 | } else if ( name == mAttributes[ "familyName" ].lower() ) { |
246 | addr.setFamilyName( value ); | 246 | addr.setFamilyName( value ); |
247 | } else if ( name == mAttributes[ "uid" ].lower() ) { | 247 | } else if ( name == mAttributes[ "uid" ].lower() ) { |
248 | addr.setUid( value ); | 248 | addr.setUid( value ); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | ldap_value_free( values ); | 251 | ldap_value_free( values ); |
252 | } | 252 | } |
253 | ber_free( track, 0 ); | 253 | ber_free( track, 0 ); |
254 | 254 | ||
255 | addressBook()->insertAddressee( addr ); | 255 | addressBook()->insertAddressee( addr ); |
256 | } | 256 | } |
257 | 257 | ||
258 | ldap_msgfree( res ); | 258 | ldap_msgfree( res ); |
259 | 259 | ||
260 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) | 260 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) |
261 | delete [] LdapSearchAttr[ i ]; | 261 | delete [] LdapSearchAttr[ i ]; |
262 | delete [] LdapSearchAttr; | 262 | delete [] LdapSearchAttr; |
263 | 263 | ||
264 | return true; | 264 | return true; |
265 | } | 265 | } |
266 | 266 | ||
267 | bool ResourceLDAP::save( Ticket * ) | 267 | bool ResourceLDAP::save( Ticket * ) |
268 | { | 268 | { |
269 | AddressBook::Iterator it; | 269 | AddressBook::Iterator it; |
270 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 270 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
271 | if ( (*it).resource() == this && (*it).changed() ) { | 271 | if ( (*it).resource() == this && (*it).changed() ) { |
272 | LDAPMod **mods = NULL; | 272 | LDAPMod **mods = NULL; |
273 | 273 | ||
274 | addModOp( &mods, "objectClass", "organizationalPerson" ); | 274 | addModOp( &mods, "objectClass", "organizationalPerson" ); |
275 | addModOp( &mods, "objectClass", "person" ); | 275 | addModOp( &mods, "objectClass", "person" ); |
276 | addModOp( &mods, "objectClass", "Top" ); | 276 | addModOp( &mods, "objectClass", "Top" ); |
277 | addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() ); | 277 | addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() ); |
278 | addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() ); | 278 | addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() ); |
279 | addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() ); | 279 | addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() ); |
280 | addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() ); | 280 | addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() ); |
281 | addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() ); | 281 | addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() ); |
282 | 282 | ||
283 | QStringList emails = (*it).emails(); | 283 | QStringList emails = (*it).emails(); |
284 | QStringList::ConstIterator mailIt; | 284 | QStringList::ConstIterator mailIt; |
285 | bool first = true; | 285 | bool first = true; |
286 | for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) { | 286 | for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) { |
287 | if ( first ) { | 287 | if ( first ) { |
288 | addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) ); | 288 | addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) ); |
289 | first = false; | 289 | first = false; |
290 | } else | 290 | } else |
291 | addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) ); | 291 | addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) ); |
292 | } | 292 | } |
293 | 293 | ||
294 | PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home ); | 294 | PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home ); |
295 | addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() ); | 295 | addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() ); |
296 | 296 | ||
297 | QString dn = "cn=" + (*it).assembledName() + "," + mDn; | 297 | QString dn = "cn=" + (*it).assembledName() + "," + mDn; |
298 | 298 | ||
299 | int retval; | 299 | int retval; |
300 | if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS ) | 300 | if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS ) |
301 | addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) ); | 301 | addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) ); |
302 | 302 | ||
303 | ldap_mods_free( mods, 1 ); | 303 | ldap_mods_free( mods, 1 ); |
304 | 304 | ||
305 | // mark as unchanged | 305 | // mark as unchanged |
306 | (*it).setChanged( false ); | 306 | (*it).setChanged( false ); |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | return true; | 310 | return true; |
311 | } | 311 | } |
312 | 312 | ||
313 | void ResourceLDAP::removeAddressee( const Addressee &addr ) | 313 | void ResourceLDAP::removeAddressee( const Addressee &addr ) |
314 | { | 314 | { |
315 | LDAPMessage *res; | 315 | LDAPMessage *res; |
316 | LDAPMessage *msg; | 316 | LDAPMessage *msg; |
317 | 317 | ||
318 | QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter ); | 318 | QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter ); |
319 | 319 | ||
320 | kdDebug(5700) << "ldap:removeAddressee" << filter << endl; | 320 | kdDebug(5700) << "ldap:removeAddressee" << filter << endl; |
321 | 321 | ||
322 | ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(), | 322 | ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(), |
323 | 0, 0, &res ); | 323 | 0, 0, &res ); |
324 | 324 | ||
325 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { | 325 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { |
326 | char *dn = ldap_get_dn( mLdap, msg ); | 326 | char *dn = ldap_get_dn( mLdap, msg ); |
327 | kdDebug(5700) << "found " << dn << endl; | 327 | kdDebug(5700) << "found " << dn << endl; |
328 | if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS ) | 328 | if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS ) |
329 | addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) ); | 329 | addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) ); |
330 | ldap_memfree( dn ); | 330 | ldap_memfree( dn ); |
331 | } | 331 | } |
332 | 332 | ||
333 | ldap_msgfree( res ); | 333 | ldap_msgfree( res ); |
334 | } | 334 | } |
335 | 335 | ||
336 | void ResourceLDAP::setUser( const QString &user ) | 336 | void ResourceLDAP::setUser( const QString &user ) |
337 | { | 337 | { |
338 | mUser = user; | 338 | mUser = user; |
339 | } | 339 | } |
340 | 340 | ||
341 | QString ResourceLDAP::user() const | 341 | QString ResourceLDAP::user() const |
342 | { | 342 | { |
343 | return mUser; | 343 | return mUser; |
344 | } | 344 | } |
345 | 345 | ||
346 | void ResourceLDAP::setPassword( const QString &password ) | 346 | void ResourceLDAP::setPassword( const QString &password ) |
347 | { | 347 | { |
348 | mPassword = password; | 348 | mPassword = password; |
349 | } | 349 | } |
350 | 350 | ||
351 | QString ResourceLDAP::password() const | 351 | QString ResourceLDAP::password() const |
352 | { | 352 | { |
353 | return mPassword; | 353 | return mPassword; |
354 | } | 354 | } |
355 | 355 | ||
356 | void ResourceLDAP::setDn( const QString &dn ) | 356 | void ResourceLDAP::setDn( const QString &dn ) |
357 | { | 357 | { |
358 | mDn = dn; | 358 | mDn = dn; |
359 | } | 359 | } |
360 | 360 | ||
361 | QString ResourceLDAP::dn() const | 361 | QString ResourceLDAP::dn() const |
362 | { | 362 | { |
363 | return mDn; | 363 | return mDn; |
364 | } | 364 | } |
365 | 365 | ||
366 | void ResourceLDAP::setHost( const QString &host ) | 366 | void ResourceLDAP::setHost( const QString &host ) |
367 | { | 367 | { |
368 | mHost = host; | 368 | mHost = host; |
369 | } | 369 | } |
370 | 370 | ||
371 | QString ResourceLDAP::host() const | 371 | QString ResourceLDAP::host() const |
372 | { | 372 | { |
373 | return mHost; | 373 | return mHost; |
374 | } | 374 | } |
375 | 375 | ||
376 | void ResourceLDAP::setPort( int port ) | 376 | void ResourceLDAP::setPort( int port ) |
377 | { | 377 | { |
378 | mPort = port; | 378 | mPort = port; |
379 | } | 379 | } |
380 | 380 | ||
381 | int ResourceLDAP::port() const | 381 | int ResourceLDAP::port() const |
382 | { | 382 | { |
383 | return mPort; | 383 | return mPort; |
384 | } | 384 | } |
385 | 385 | ||
386 | void ResourceLDAP::setFilter( const QString &filter ) | 386 | void ResourceLDAP::setFilter( const QString &filter ) |
387 | { | 387 | { |
388 | mFilter = filter; | 388 | mFilter = filter; |
389 | } | 389 | } |
390 | 390 | ||
391 | QString ResourceLDAP::filter() const | 391 | QString ResourceLDAP::filter() const |
392 | { | 392 | { |
393 | return mFilter; | 393 | return mFilter; |
394 | } | 394 | } |
395 | 395 | ||
396 | void ResourceLDAP::setIsAnonymous( bool value ) | 396 | void ResourceLDAP::setIsAnonymous( bool value ) |
397 | { | 397 | { |
398 | mAnonymous = value; | 398 | mAnonymous = value; |
399 | } | 399 | } |
400 | 400 | ||
401 | bool ResourceLDAP::isAnonymous() const | 401 | bool ResourceLDAP::isAnonymous() const |
402 | { | 402 | { |
403 | return mAnonymous; | 403 | return mAnonymous; |
404 | } | 404 | } |
405 | 405 | ||
406 | void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes ) | 406 | void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes ) |
407 | { | 407 | { |
408 | mAttributes = attributes; | 408 | mAttributes = attributes; |
409 | } | 409 | } |
410 | 410 | ||
411 | QMap<QString, QString> ResourceLDAP::attributes() const | 411 | QMap<QString, QString> ResourceLDAP::attributes() const |
412 | { | 412 | { |
413 | return mAttributes; | 413 | return mAttributes; |
414 | } | 414 | } |
415 | 415 | ||
416 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ) | 416 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ) |
417 | { | 417 | { |
418 | if ( value.isNull() ) | 418 | if ( value.isNull() ) |
419 | return; | 419 | return; |
420 | 420 | ||
421 | LDAPMod**mods; | 421 | LDAPMod**mods; |
422 | 422 | ||
423 | mods = *pmods; | 423 | mods = *pmods; |
424 | 424 | ||
425 | uint i = 0; | 425 | uint i = 0; |
426 | if ( mods != 0 ) | 426 | if ( mods != 0 ) |
427 | for ( ; mods[ i ] != 0; ++i ); | 427 | for ( ; mods[ i ] != 0; ++i ); |
428 | 428 | ||
429 | if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) { | 429 | if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) { |
430 | kdError() << "ResourceLDAP: realloc" << endl; | 430 | kdError() << "ResourceLDAP: realloc" << endl; |
431 | return; | 431 | return; |
432 | } | 432 | } |
433 | 433 | ||
434 | *pmods = mods; | 434 | *pmods = mods; |
435 | mods[ i + 1 ] = 0; | 435 | mods[ i + 1 ] = 0; |
436 | 436 | ||
437 | mods[ i ] = new LDAPMod; | 437 | mods[ i ] = new LDAPMod; |
438 | 438 | ||
439 | mods[ i ]->mod_op = 0; | 439 | mods[ i ]->mod_op = 0; |
440 | mods[ i ]->mod_type = strdup( attr.utf8() ); | 440 | mods[ i ]->mod_type = strdup( attr.utf8() ); |
441 | mods[ i ]->mod_values = new char*[ 2 ]; | 441 | mods[ i ]->mod_values = new char*[ 2 ]; |
442 | mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() ); | 442 | mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() ); |
443 | mods[ i ]->mod_values[ 1 ] = 0; | 443 | mods[ i ]->mod_values[ 1 ] = 0; |
444 | } | 444 | } |
445 | 445 | ||
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index 9dfd473..4b811e9 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -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 | #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 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | //US #include "formatfactory.h" | 45 | //US #include "formatfactory.h" |
46 | //US #include <qpe/qpeapplication.h> | 46 | //US #include <qpe/qpeapplication.h> |
47 | 47 | ||
48 | #include <opie/ocontactaccess.h> | 48 | #include <opie/ocontactaccess.h> |
49 | #include <opie/ocontactaccessbackend_xml.h> | 49 | #include <opie/ocontactaccessbackend_xml.h> |
50 | 50 | ||
51 | #include "resourceopieconfig.h" | 51 | #include "resourceopieconfig.h" |
52 | #include "stdaddressbook.h" | 52 | #include "stdaddressbook.h" |
53 | #include "syncprefwidget.h" | 53 | #include "syncprefwidget.h" |
54 | 54 | ||
55 | #include "opieconverter.h" | 55 | #include "opieconverter.h" |
56 | 56 | ||
57 | #include "resourceopie.h" | 57 | #include "resourceopie.h" |
58 | 58 | ||
59 | using namespace KABC; | 59 | using namespace KABC; |
60 | extern "C" | 60 | extern "C" |
61 | { | 61 | { |
62 | void *init_microkabc_opie() | 62 | void *init_microkabc_opie() |
63 | { | 63 | { |
64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidget>(); | 64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidgetContainer>(); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) | 68 | ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) |
69 | : Resource( config, syncable ), mAccess(0), mConverter (0) | 69 | : Resource( config, syncable ), mAccess(0), mConverter (0) |
70 | { | 70 | { |
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
72 | 72 | ||
73 | KConfig *cfg = (KConfig *)config; | 73 | KConfig *cfg = (KConfig *)config; |
74 | if ( cfg ) { | 74 | if ( cfg ) { |
75 | fileName = cfg->readEntry( "FileName", fileName ); | 75 | fileName = cfg->readEntry( "FileName", fileName ); |
76 | 76 | ||
77 | } | 77 | } |
78 | 78 | ||
79 | init( fileName ); | 79 | init( fileName ); |
80 | } | 80 | } |
81 | 81 | ||
82 | ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) | 82 | ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) |
83 | : Resource( 0, syncable ) | 83 | : Resource( 0, syncable ) |
84 | { | 84 | { |
85 | init( fileName ); | 85 | init( fileName ); |
86 | } | 86 | } |
87 | 87 | ||
88 | void ResourceOpie::init( const QString &fileName ) | 88 | void ResourceOpie::init( const QString &fileName ) |
89 | { | 89 | { |
90 | qDebug("ResourceOpie::init()"); | 90 | qDebug("ResourceOpie::init()"); |
91 | 91 | ||
92 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 92 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
93 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 93 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
94 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 94 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
95 | 95 | ||
96 | setFileName( fileName ); | 96 | setFileName( fileName ); |
97 | } | 97 | } |
98 | 98 | ||
99 | ResourceOpie::~ResourceOpie() | 99 | ResourceOpie::~ResourceOpie() |
100 | { | 100 | { |
101 | if (mConverter != 0) | 101 | if (mConverter != 0) |
102 | delete mConverter; | 102 | delete mConverter; |
103 | 103 | ||
104 | if(mAccess != 0) | 104 | if(mAccess != 0) |
105 | delete mAccess; | 105 | delete mAccess; |
106 | } | 106 | } |
107 | 107 | ||
108 | void ResourceOpie::writeConfig( KConfig *config ) | 108 | void ResourceOpie::writeConfig( KConfig *config ) |
109 | { | 109 | { |
110 | Resource::writeConfig( config ); | 110 | Resource::writeConfig( config ); |
111 | 111 | ||
112 | config->writeEntry( "FileName", fileName() ); | 112 | config->writeEntry( "FileName", fileName() ); |
113 | } | 113 | } |
114 | 114 | ||
115 | Ticket *ResourceOpie::requestSaveTicket() | 115 | Ticket *ResourceOpie::requestSaveTicket() |
116 | { | 116 | { |
117 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 117 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
118 | 118 | ||
119 | qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); | 119 | qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); |
120 | 120 | ||
121 | if ( !addressBook() ) return 0; | 121 | if ( !addressBook() ) return 0; |
122 | 122 | ||
123 | if ( !lock( fileName() ) ) { | 123 | if ( !lock( fileName() ) ) { |
124 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | 124 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" |
125 | << fileName() << "'" << endl; | 125 | << fileName() << "'" << endl; |
126 | return 0; | 126 | return 0; |
127 | } | 127 | } |
128 | return createTicket( this ); | 128 | return createTicket( this ); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | bool ResourceOpie::doOpen() | 132 | bool ResourceOpie::doOpen() |
133 | { | 133 | { |
134 | qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); | 134 | qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); |
135 | 135 | ||
136 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); | 136 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); |
137 | mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); | 137 | mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); |
138 | 138 | ||
139 | if ( !mAccess ) { | 139 | if ( !mAccess ) { |
140 | qDebug("Unable to load file() %s", fileName().latin1()); | 140 | qDebug("Unable to load file() %s", fileName().latin1()); |
141 | return false; | 141 | return false; |
142 | } | 142 | } |
143 | 143 | ||
144 | mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available | 144 | mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available |
145 | 145 | ||
146 | 146 | ||
147 | if (mConverter == 0) | 147 | if (mConverter == 0) |
148 | { | 148 | { |
149 | mConverter = new OpieConverter(); | 149 | mConverter = new OpieConverter(); |
150 | bool res = mConverter->init(); | 150 | bool res = mConverter->init(); |
151 | if ( !res ) | 151 | if ( !res ) |
152 | { | 152 | { |
153 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); | 153 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); |
154 | delete mAccess; | 154 | delete mAccess; |
155 | mAccess = 0; | 155 | mAccess = 0; |
156 | return false; | 156 | return false; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | 161 | ||
162 | return true; | 162 | return true; |
163 | } | 163 | } |
164 | 164 | ||
165 | void ResourceOpie::doClose() | 165 | void ResourceOpie::doClose() |
166 | { | 166 | { |
167 | qDebug("ResourceOpie::doClose: %s", fileName().latin1()); | 167 | qDebug("ResourceOpie::doClose: %s", fileName().latin1()); |
168 | 168 | ||
169 | if(mAccess) | 169 | if(mAccess) |
170 | { | 170 | { |
171 | delete mAccess; | 171 | delete mAccess; |
172 | mAccess = 0; | 172 | mAccess = 0; |
173 | } | 173 | } |
174 | // it seems so, that deletion of access deletes backend as well | 174 | // it seems so, that deletion of access deletes backend as well |
175 | //delete backend; | 175 | //delete backend; |
176 | 176 | ||
177 | return; | 177 | return; |
178 | 178 | ||
179 | } | 179 | } |
180 | 180 | ||
181 | 181 | ||
182 | bool ResourceOpie::load() | 182 | bool ResourceOpie::load() |
183 | { | 183 | { |
184 | qDebug("ResourceOpie::load: %s", fileName().latin1()); | 184 | qDebug("ResourceOpie::load: %s", fileName().latin1()); |
185 | 185 | ||
186 | bool res = false; | 186 | bool res = false; |
187 | 187 | ||
188 | OContactAccess::List::Iterator it; | 188 | OContactAccess::List::Iterator it; |
189 | OContactAccess::List allList = mAccess->allRecords(); | 189 | OContactAccess::List allList = mAccess->allRecords(); |
190 | for ( it = allList.begin(); it != allList.end(); ++it ) | 190 | for ( it = allList.begin(); it != allList.end(); ++it ) |
191 | { | 191 | { |
192 | const OContact c = (*it); | 192 | const OContact c = (*it); |
193 | 193 | ||
194 | KABC::Addressee addressee; | 194 | KABC::Addressee addressee; |
195 | 195 | ||
196 | res = mConverter->opieToAddressee( c, addressee ); | 196 | res = mConverter->opieToAddressee( c, addressee ); |
197 | 197 | ||
198 | if ( !addressee.isEmpty() && res ) | 198 | if ( !addressee.isEmpty() && res ) |
199 | { | 199 | { |
200 | addressee.setResource( this ); | 200 | addressee.setResource( this ); |
201 | addressBook()->insertAddressee( addressee ); | 201 | addressBook()->insertAddressee( addressee ); |
202 | } | 202 | } |
203 | 203 | ||
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | return true; | 207 | return true; |
208 | } | 208 | } |
209 | 209 | ||
210 | bool ResourceOpie::save( Ticket *ticket ) | 210 | bool ResourceOpie::save( Ticket *ticket ) |
211 | { | 211 | { |
212 | qDebug("ResourceOpie::save: %s", fileName().latin1()); | 212 | qDebug("ResourceOpie::save: %s", fileName().latin1()); |
213 | 213 | ||
214 | 214 | ||
215 | 215 | ||
216 | KABC::AddressBook::Iterator it; | 216 | KABC::AddressBook::Iterator it; |
217 | bool res; | 217 | bool res; |
218 | 218 | ||
219 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 219 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
220 | OContact c; | 220 | OContact c; |
221 | KABC::Addressee addressee = (*it); | 221 | KABC::Addressee addressee = (*it); |
222 | 222 | ||
223 | res = mConverter->addresseeToOpie( *it, c ); | 223 | res = mConverter->addresseeToOpie( *it, c ); |
224 | if (res == true) | 224 | if (res == true) |
225 | { | 225 | { |
226 | res = mAccess->add(c); | 226 | res = mAccess->add(c); |
227 | if (res == false) | 227 | if (res == false) |
228 | qDebug("Unable to append Contact %s", c.fullName().latin1()); | 228 | qDebug("Unable to append Contact %s", c.fullName().latin1()); |
229 | } | 229 | } |
230 | else | 230 | else |
231 | { | 231 | { |
232 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | 232 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
233 | } | 233 | } |
234 | } | 234 | } |
235 | 235 | ||
236 | mAccess->save(); | 236 | mAccess->save(); |
237 | 237 | ||
238 | delete ticket; | 238 | delete ticket; |
239 | unlock( fileName() ); | 239 | unlock( fileName() ); |
240 | 240 | ||
241 | return true; | 241 | return true; |
242 | 242 | ||
243 | } | 243 | } |
244 | 244 | ||
245 | bool ResourceOpie::lock( const QString &lockfileName ) | 245 | bool ResourceOpie::lock( const QString &lockfileName ) |
246 | { | 246 | { |
247 | qDebug("ResourceOpie::lock: %s", fileName().latin1()); | 247 | qDebug("ResourceOpie::lock: %s", fileName().latin1()); |
248 | 248 | ||
249 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | 249 | kdDebug(5700) << "ResourceOpie::lock()" << endl; |
250 | 250 | ||
251 | QString fn = lockfileName; | 251 | QString fn = lockfileName; |
252 | 252 | ||
253 | KURL url(fn); | 253 | KURL url(fn); |
254 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 254 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
255 | 255 | ||
256 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 256 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
257 | 257 | ||
258 | if (QFile::exists( lockName )) | 258 | if (QFile::exists( lockName )) |
259 | { | 259 | { |
260 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); | 260 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); |
261 | return false; | 261 | return false; |
262 | } | 262 | } |
263 | 263 | ||
264 | QString lockUniqueName; | 264 | QString lockUniqueName; |
265 | lockUniqueName = fn + KApplication::randomString( 8 ); | 265 | lockUniqueName = fn + KApplication::randomString( 8 ); |
266 | 266 | ||
267 | url = lockUniqueName; | 267 | url = lockUniqueName; |
268 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 268 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
269 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 269 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
270 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 270 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
271 | 271 | ||
272 | // Create unique file | 272 | // Create unique file |
273 | QFile file( mLockUniqueName ); | 273 | QFile file( mLockUniqueName ); |
274 | file.open( IO_WriteOnly ); | 274 | file.open( IO_WriteOnly ); |
275 | file.close(); | 275 | file.close(); |
276 | 276 | ||
277 | // Create lock file | 277 | // Create lock file |
278 | int result = 0; | 278 | int result = 0; |
279 | #ifndef _WIN32_ | 279 | #ifndef _WIN32_ |
280 | result = ::link( QFile::encodeName( mLockUniqueName ), | 280 | result = ::link( QFile::encodeName( mLockUniqueName ), |
281 | QFile::encodeName( lockName ) ); | 281 | QFile::encodeName( lockName ) ); |
282 | #endif | 282 | #endif |
283 | if ( result == 0 ) { | 283 | if ( result == 0 ) { |
284 | addressBook()->emitAddressBookLocked(); | 284 | addressBook()->emitAddressBookLocked(); |
285 | return true; | 285 | return true; |
286 | } | 286 | } |
287 | 287 | ||
288 | // TODO: check stat | 288 | // TODO: check stat |
289 | 289 | ||
290 | return false; | 290 | return false; |
291 | } | 291 | } |
292 | 292 | ||
293 | void ResourceOpie::unlock( const QString &fileName ) | 293 | void ResourceOpie::unlock( const QString &fileName ) |
294 | { | 294 | { |
295 | qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | 295 | qDebug("ResourceOpie::unlock() %s", fileName.latin1()); |
296 | 296 | ||
297 | QString fn = fileName; | 297 | QString fn = fileName; |
298 | KURL url(fn); | 298 | KURL url(fn); |
299 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 299 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
300 | 300 | ||
301 | QFile::remove( lockName ); | 301 | QFile::remove( lockName ); |
302 | QFile::remove( mLockUniqueName ); | 302 | QFile::remove( mLockUniqueName ); |
303 | addressBook()->emitAddressBookUnlocked(); | 303 | addressBook()->emitAddressBookUnlocked(); |
304 | } | 304 | } |
305 | 305 | ||
306 | void ResourceOpie::setFileName( const QString &newFileName ) | 306 | void ResourceOpie::setFileName( const QString &newFileName ) |
307 | { | 307 | { |
308 | mDirWatch.stopScan(); | 308 | mDirWatch.stopScan(); |
309 | mDirWatch.removeFile( fileName() ); | 309 | mDirWatch.removeFile( fileName() ); |
310 | 310 | ||
311 | Resource::setFileName( newFileName ); | 311 | Resource::setFileName( newFileName ); |
312 | 312 | ||
313 | mDirWatch.addFile( fileName() ); | 313 | mDirWatch.addFile( fileName() ); |
314 | mDirWatch.startScan(); | 314 | mDirWatch.startScan(); |
315 | 315 | ||
316 | } | 316 | } |
317 | 317 | ||
318 | 318 | ||
319 | void ResourceOpie::fileChanged() | 319 | void ResourceOpie::fileChanged() |
320 | { | 320 | { |
321 | // There is a small theoretical chance that KDirWatch calls us before | 321 | // There is a small theoretical chance that KDirWatch calls us before |
322 | // we are fully constructed | 322 | // we are fully constructed |
323 | if (!addressBook()) | 323 | if (!addressBook()) |
324 | return; | 324 | return; |
325 | 325 | ||
326 | QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 326 | QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
327 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 327 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
328 | load(); | 328 | load(); |
329 | addressBook()->emitAddressBookChanged(); | 329 | addressBook()->emitAddressBookChanged(); |
330 | } | 330 | } |
331 | 331 | ||
332 | load(); | 332 | load(); |
333 | addressBook()->emitAddressBookChanged(); | 333 | addressBook()->emitAddressBookChanged(); |
334 | } | 334 | } |
335 | 335 | ||
336 | void ResourceOpie::removeAddressee( const Addressee &addr ) | 336 | void ResourceOpie::removeAddressee( const Addressee &addr ) |
337 | { | 337 | { |
338 | } | 338 | } |
339 | 339 | ||
340 | void ResourceOpie::cleanUp() | 340 | void ResourceOpie::cleanUp() |
341 | { | 341 | { |
342 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); | 342 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); |
343 | 343 | ||
344 | unlock( fileName() ); | 344 | unlock( fileName() ); |
345 | } | 345 | } |
346 | 346 | ||
347 | 347 | ||
348 | //US #include "resourceopie.moc" | 348 | //US #include "resourceopie.moc" |
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 5565580..93a4d33 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -1,319 +1,319 @@ | |||
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 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | //US #include <qtimer.h> | 35 | //US #include <qtimer.h> |
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | #include <qpe/pim/addressbookaccess.h> | 45 | #include <qpe/pim/addressbookaccess.h> |
46 | 46 | ||
47 | 47 | ||
48 | #include "resourceqtopiaconfig.h" | 48 | #include "resourceqtopiaconfig.h" |
49 | #include "stdaddressbook.h" | 49 | #include "stdaddressbook.h" |
50 | 50 | ||
51 | #include "qtopiaconverter.h" | 51 | #include "qtopiaconverter.h" |
52 | #include "syncprefwidget.h" | 52 | #include "syncprefwidget.h" |
53 | 53 | ||
54 | #include "resourceqtopia.h" | 54 | #include "resourceqtopia.h" |
55 | 55 | ||
56 | using namespace KABC; | 56 | using namespace KABC; |
57 | extern "C" | 57 | extern "C" |
58 | { | 58 | { |
59 | void *init_microkabc_qtopia() | 59 | void *init_microkabc_qtopia() |
60 | { | 60 | { |
61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidget>(); | 61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) | 65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) |
66 | : Resource( config, syncable ), mConverter (0) | 66 | : Resource( config, syncable ), mConverter (0) |
67 | { | 67 | { |
68 | // we can not choose the filename. Therefore use the default to display | 68 | // we can not choose the filename. Therefore use the default to display |
69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
70 | init( fileName ); | 70 | init( fileName ); |
71 | } | 71 | } |
72 | 72 | ||
73 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) | 73 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) |
74 | : Resource( 0, syncable ) | 74 | : Resource( 0, syncable ) |
75 | { | 75 | { |
76 | init( fileName ); | 76 | init( fileName ); |
77 | } | 77 | } |
78 | 78 | ||
79 | void ResourceQtopia::init( const QString &fileName ) | 79 | void ResourceQtopia::init( const QString &fileName ) |
80 | { | 80 | { |
81 | 81 | ||
82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
85 | 85 | ||
86 | setFileName( fileName ); | 86 | setFileName( fileName ); |
87 | } | 87 | } |
88 | 88 | ||
89 | ResourceQtopia::~ResourceQtopia() | 89 | ResourceQtopia::~ResourceQtopia() |
90 | { | 90 | { |
91 | if (mConverter != 0) | 91 | if (mConverter != 0) |
92 | delete mConverter; | 92 | delete mConverter; |
93 | 93 | ||
94 | if(mAccess != 0) | 94 | if(mAccess != 0) |
95 | delete mAccess; | 95 | delete mAccess; |
96 | } | 96 | } |
97 | 97 | ||
98 | void ResourceQtopia::writeConfig( KConfig *config ) | 98 | void ResourceQtopia::writeConfig( KConfig *config ) |
99 | { | 99 | { |
100 | Resource::writeConfig( config ); | 100 | Resource::writeConfig( config ); |
101 | } | 101 | } |
102 | 102 | ||
103 | Ticket *ResourceQtopia::requestSaveTicket() | 103 | Ticket *ResourceQtopia::requestSaveTicket() |
104 | { | 104 | { |
105 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 105 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; |
106 | 106 | ||
107 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); | 107 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); |
108 | 108 | ||
109 | if ( !addressBook() ) return 0; | 109 | if ( !addressBook() ) return 0; |
110 | 110 | ||
111 | if ( !lock( fileName() ) ) { | 111 | if ( !lock( fileName() ) ) { |
112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
113 | << fileName() << "'" << endl; | 113 | << fileName() << "'" << endl; |
114 | return 0; | 114 | return 0; |
115 | } | 115 | } |
116 | return createTicket( this ); | 116 | return createTicket( this ); |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | bool ResourceQtopia::doOpen() | 120 | bool ResourceQtopia::doOpen() |
121 | { | 121 | { |
122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); | 122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
123 | 123 | ||
124 | mAccess = new AddressBookAccess(); | 124 | mAccess = new AddressBookAccess(); |
125 | 125 | ||
126 | if ( !mAccess ) { | 126 | if ( !mAccess ) { |
127 | qDebug("Unable to load file() %s", fileName().latin1()); | 127 | qDebug("Unable to load file() %s", fileName().latin1()); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | if (mConverter == 0) | 132 | if (mConverter == 0) |
133 | { | 133 | { |
134 | mConverter = new QtopiaConverter(); | 134 | mConverter = new QtopiaConverter(); |
135 | bool res = mConverter->init(); | 135 | bool res = mConverter->init(); |
136 | if ( !res ) | 136 | if ( !res ) |
137 | { | 137 | { |
138 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); | 138 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); |
139 | qDebug(msg); | 139 | qDebug(msg); |
140 | delete mAccess; | 140 | delete mAccess; |
141 | mAccess = 0; | 141 | mAccess = 0; |
142 | return false; | 142 | return false; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | return true; | 146 | return true; |
147 | } | 147 | } |
148 | 148 | ||
149 | void ResourceQtopia::doClose() | 149 | void ResourceQtopia::doClose() |
150 | { | 150 | { |
151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | 151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); |
152 | 152 | ||
153 | if(mAccess) | 153 | if(mAccess) |
154 | { | 154 | { |
155 | delete mAccess; | 155 | delete mAccess; |
156 | mAccess = 0; | 156 | mAccess = 0; |
157 | } | 157 | } |
158 | // it seems so, that deletion of access deletes backend as well | 158 | // it seems so, that deletion of access deletes backend as well |
159 | //delete backend; | 159 | //delete backend; |
160 | 160 | ||
161 | return; | 161 | return; |
162 | } | 162 | } |
163 | 163 | ||
164 | bool ResourceQtopia::load() | 164 | bool ResourceQtopia::load() |
165 | { | 165 | { |
166 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | 166 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); |
167 | 167 | ||
168 | AddressBookIterator it(*mAccess); | 168 | AddressBookIterator it(*mAccess); |
169 | const PimContact* contact; | 169 | const PimContact* contact; |
170 | bool res; | 170 | bool res; |
171 | 171 | ||
172 | for (contact=it.toFirst(); it.current(); ++it) | 172 | for (contact=it.toFirst(); it.current(); ++it) |
173 | { | 173 | { |
174 | contact = it.current(); | 174 | contact = it.current(); |
175 | 175 | ||
176 | KABC::Addressee addressee; | 176 | KABC::Addressee addressee; |
177 | 177 | ||
178 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 178 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); |
179 | 179 | ||
180 | if ( !addressee.isEmpty() && res ) | 180 | if ( !addressee.isEmpty() && res ) |
181 | { | 181 | { |
182 | addressee.setResource( this ); | 182 | addressee.setResource( this ); |
183 | addressBook()->insertAddressee( addressee ); | 183 | addressBook()->insertAddressee( addressee ); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | return true; | 187 | return true; |
188 | } | 188 | } |
189 | 189 | ||
190 | bool ResourceQtopia::save( Ticket *ticket ) | 190 | bool ResourceQtopia::save( Ticket *ticket ) |
191 | { | 191 | { |
192 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); | 192 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); |
193 | 193 | ||
194 | 194 | ||
195 | KABC::AddressBook::Iterator it; | 195 | KABC::AddressBook::Iterator it; |
196 | bool res; | 196 | bool res; |
197 | 197 | ||
198 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 198 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
199 | PimContact c; | 199 | PimContact c; |
200 | KABC::Addressee addressee = (*it); | 200 | KABC::Addressee addressee = (*it); |
201 | 201 | ||
202 | res = mConverter->addresseeToQtopia( *it, c ); | 202 | res = mConverter->addresseeToQtopia( *it, c ); |
203 | if (res == true) | 203 | if (res == true) |
204 | { | 204 | { |
205 | mAccess->addContact(c); | 205 | mAccess->addContact(c); |
206 | // if (res == false) | 206 | // if (res == false) |
207 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); | 207 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); |
208 | } | 208 | } |
209 | else | 209 | else |
210 | { | 210 | { |
211 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | 211 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | // mAccess->addressBookUpdated(); | 215 | // mAccess->addressBookUpdated(); |
216 | 216 | ||
217 | delete ticket; | 217 | delete ticket; |
218 | unlock( fileName() ); | 218 | unlock( fileName() ); |
219 | 219 | ||
220 | return true; | 220 | return true; |
221 | } | 221 | } |
222 | 222 | ||
223 | bool ResourceQtopia::lock( const QString &lockfileName ) | 223 | bool ResourceQtopia::lock( const QString &lockfileName ) |
224 | { | 224 | { |
225 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); | 225 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
226 | 226 | ||
227 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | 227 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; |
228 | 228 | ||
229 | QString fn = lockfileName; | 229 | QString fn = lockfileName; |
230 | 230 | ||
231 | KURL url(fn); | 231 | KURL url(fn); |
232 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 232 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
233 | 233 | ||
234 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 234 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
235 | 235 | ||
236 | if (QFile::exists( lockName )) | 236 | if (QFile::exists( lockName )) |
237 | { | 237 | { |
238 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); | 238 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); |
239 | return false; | 239 | return false; |
240 | } | 240 | } |
241 | 241 | ||
242 | QString lockUniqueName; | 242 | QString lockUniqueName; |
243 | lockUniqueName = fn + KApplication::randomString( 8 ); | 243 | lockUniqueName = fn + KApplication::randomString( 8 ); |
244 | 244 | ||
245 | url = lockUniqueName; | 245 | url = lockUniqueName; |
246 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 246 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
247 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 247 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
248 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 248 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
249 | 249 | ||
250 | // Create unique file | 250 | // Create unique file |
251 | QFile file( mLockUniqueName ); | 251 | QFile file( mLockUniqueName ); |
252 | file.open( IO_WriteOnly ); | 252 | file.open( IO_WriteOnly ); |
253 | file.close(); | 253 | file.close(); |
254 | 254 | ||
255 | // Create lock file | 255 | // Create lock file |
256 | int result = 0; | 256 | int result = 0; |
257 | #ifndef _WIN32_ | 257 | #ifndef _WIN32_ |
258 | result = ::link( QFile::encodeName( mLockUniqueName ), | 258 | result = ::link( QFile::encodeName( mLockUniqueName ), |
259 | QFile::encodeName( lockName ) ); | 259 | QFile::encodeName( lockName ) ); |
260 | #endif | 260 | #endif |
261 | if ( result == 0 ) { | 261 | if ( result == 0 ) { |
262 | addressBook()->emitAddressBookLocked(); | 262 | addressBook()->emitAddressBookLocked(); |
263 | return true; | 263 | return true; |
264 | } | 264 | } |
265 | 265 | ||
266 | // TODO: check stat | 266 | // TODO: check stat |
267 | 267 | ||
268 | return false; | 268 | return false; |
269 | } | 269 | } |
270 | 270 | ||
271 | void ResourceQtopia::unlock( const QString &fileName ) | 271 | void ResourceQtopia::unlock( const QString &fileName ) |
272 | { | 272 | { |
273 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | 273 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); |
274 | 274 | ||
275 | QString fn = fileName; | 275 | QString fn = fileName; |
276 | KURL url(fn); | 276 | KURL url(fn); |
277 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 277 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
278 | 278 | ||
279 | QFile::remove( lockName ); | 279 | QFile::remove( lockName ); |
280 | QFile::remove( mLockUniqueName ); | 280 | QFile::remove( mLockUniqueName ); |
281 | addressBook()->emitAddressBookUnlocked(); | 281 | addressBook()->emitAddressBookUnlocked(); |
282 | } | 282 | } |
283 | 283 | ||
284 | void ResourceQtopia::setFileName( const QString &newFileName ) | 284 | void ResourceQtopia::setFileName( const QString &newFileName ) |
285 | { | 285 | { |
286 | mDirWatch.stopScan(); | 286 | mDirWatch.stopScan(); |
287 | mDirWatch.removeFile( fileName() ); | 287 | mDirWatch.removeFile( fileName() ); |
288 | 288 | ||
289 | Resource::setFileName( newFileName ); | 289 | Resource::setFileName( newFileName ); |
290 | 290 | ||
291 | mDirWatch.addFile( fileName() ); | 291 | mDirWatch.addFile( fileName() ); |
292 | mDirWatch.startScan(); | 292 | mDirWatch.startScan(); |
293 | } | 293 | } |
294 | 294 | ||
295 | 295 | ||
296 | void ResourceQtopia::fileChanged() | 296 | void ResourceQtopia::fileChanged() |
297 | { | 297 | { |
298 | // There is a small theoretical chance that KDirWatch calls us before | 298 | // There is a small theoretical chance that KDirWatch calls us before |
299 | // we are fully constructed | 299 | // we are fully constructed |
300 | if (!addressBook()) | 300 | if (!addressBook()) |
301 | return; | 301 | return; |
302 | 302 | ||
303 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 303 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
304 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 304 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
305 | load(); | 305 | load(); |
306 | addressBook()->emitAddressBookChanged(); | 306 | addressBook()->emitAddressBookChanged(); |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | void ResourceQtopia::removeAddressee( const Addressee &addr ) | 310 | void ResourceQtopia::removeAddressee( const Addressee &addr ) |
311 | { | 311 | { |
312 | } | 312 | } |
313 | 313 | ||
314 | void ResourceQtopia::cleanUp() | 314 | void ResourceQtopia::cleanUp() |
315 | { | 315 | { |
316 | unlock( fileName() ); | 316 | unlock( fileName() ); |
317 | } | 317 | } |
318 | 318 | ||
319 | //US #include "resourceqtopia.moc" | 319 | //US #include "resourceqtopia.moc" |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 70c3718..b63df0c 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -1,337 +1,337 @@ | |||
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 | 48 | ||
49 | #include "resourcesharpdtmconfig.h" | 49 | #include "resourcesharpdtmconfig.h" |
50 | #include "resourcesharpdtm.h" | 50 | #include "resourcesharpdtm.h" |
51 | 51 | ||
52 | #include "syncprefwidget.h" | 52 | #include "syncprefwidget.h" |
53 | 53 | ||
54 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
55 | 55 | ||
56 | #include "sharpdtmconverter.h" | 56 | #include "sharpdtmconverter.h" |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | extern "C" | 59 | extern "C" |
60 | { | 60 | { |
61 | void *init_microkabc_sharpdtm() | 61 | void *init_microkabc_sharpdtm() |
62 | { | 62 | { |
63 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidget>(); | 63 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) | 67 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) |
68 | : Resource( config, syncable ), mConverter (0) | 68 | : Resource( config, syncable ), mConverter (0) |
69 | { | 69 | { |
70 | // we can not choose the filename. Therefore use the default to display | 70 | // we can not choose the filename. Therefore use the default to display |
71 | 71 | ||
72 | QString fileName = SlZDataBase::addressbookFileName(); | 72 | QString fileName = SlZDataBase::addressbookFileName(); |
73 | init( fileName ); | 73 | init( fileName ); |
74 | } | 74 | } |
75 | 75 | ||
76 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) | 76 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) |
77 | : Resource( 0, syncable ) | 77 | : Resource( 0, syncable ) |
78 | { | 78 | { |
79 | init( fileName ); | 79 | init( fileName ); |
80 | } | 80 | } |
81 | 81 | ||
82 | void ResourceSharpDTM::init( const QString &fileName ) | 82 | void ResourceSharpDTM::init( const QString &fileName ) |
83 | { | 83 | { |
84 | 84 | ||
85 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 85 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
87 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 87 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
88 | 88 | ||
89 | setFileName( fileName ); | 89 | setFileName( fileName ); |
90 | } | 90 | } |
91 | 91 | ||
92 | ResourceSharpDTM::~ResourceSharpDTM() | 92 | ResourceSharpDTM::~ResourceSharpDTM() |
93 | { | 93 | { |
94 | if (mConverter != 0) | 94 | if (mConverter != 0) |
95 | delete mConverter; | 95 | delete mConverter; |
96 | 96 | ||
97 | if(mAccess != 0) | 97 | if(mAccess != 0) |
98 | delete mAccess; | 98 | delete mAccess; |
99 | } | 99 | } |
100 | 100 | ||
101 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 101 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
102 | { | 102 | { |
103 | Resource::writeConfig( config ); | 103 | Resource::writeConfig( config ); |
104 | } | 104 | } |
105 | 105 | ||
106 | Ticket *ResourceSharpDTM::requestSaveTicket() | 106 | Ticket *ResourceSharpDTM::requestSaveTicket() |
107 | { | 107 | { |
108 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl; | 108 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl; |
109 | 109 | ||
110 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | 110 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); |
111 | 111 | ||
112 | if ( !addressBook() ) return 0; | 112 | if ( !addressBook() ) return 0; |
113 | 113 | ||
114 | if ( !lock( fileName() ) ) { | 114 | if ( !lock( fileName() ) ) { |
115 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '" | 115 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '" |
116 | << fileName() << "'" << endl; | 116 | << fileName() << "'" << endl; |
117 | return 0; | 117 | return 0; |
118 | } | 118 | } |
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, true); | 130 | NULL, true); |
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 | 200 | ||
201 | KABC::AddressBook::Iterator it; | 201 | KABC::AddressBook::Iterator it; |
202 | bool res; | 202 | bool res; |
203 | 203 | ||
204 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 204 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
205 | CardId id = 0;// 0 means new card | 205 | CardId id = 0;// 0 means new card |
206 | KABC::Addressee addressee = (*it); | 206 | KABC::Addressee addressee = (*it); |
207 | 207 | ||
208 | res = mAccess->startEditCard(id); | 208 | res = mAccess->startEditCard(id); |
209 | if (res == true) | 209 | if (res == true) |
210 | { | 210 | { |
211 | res = mConverter->addresseeToSharp( *it, mAccess, id ); | 211 | res = mConverter->addresseeToSharp( *it, mAccess, id ); |
212 | if (res == true) | 212 | if (res == true) |
213 | { | 213 | { |
214 | res = mAccess->finishEditCard(&id); | 214 | res = mAccess->finishEditCard(&id); |
215 | if (res == false) | 215 | if (res == false) |
216 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 216 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
217 | } | 217 | } |
218 | else | 218 | else |
219 | { | 219 | { |
220 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 220 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
221 | mAccess->cancelEditCard(); | 221 | mAccess->cancelEditCard(); |
222 | } | 222 | } |
223 | } | 223 | } |
224 | else | 224 | else |
225 | { | 225 | { |
226 | qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); | 226 | qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); |
227 | } | 227 | } |
228 | 228 | ||
229 | } | 229 | } |
230 | 230 | ||
231 | //US mAccess->save(); | 231 | //US mAccess->save(); |
232 | 232 | ||
233 | delete ticket; | 233 | delete ticket; |
234 | unlock( fileName() ); | 234 | unlock( fileName() ); |
235 | 235 | ||
236 | return true; | 236 | return true; |
237 | } | 237 | } |
238 | 238 | ||
239 | bool ResourceSharpDTM::lock( const QString &lockfileName ) | 239 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
240 | { | 240 | { |
241 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); | 241 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); |
242 | 242 | ||
243 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | 243 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; |
244 | 244 | ||
245 | QString fn = lockfileName; | 245 | QString fn = lockfileName; |
246 | 246 | ||
247 | KURL url(fn); | 247 | KURL url(fn); |
248 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 248 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
249 | 249 | ||
250 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 250 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
251 | 251 | ||
252 | if (QFile::exists( lockName )) | 252 | if (QFile::exists( lockName )) |
253 | { | 253 | { |
254 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); | 254 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); |
255 | return false; | 255 | return false; |
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | QString lockUniqueName; | 259 | QString lockUniqueName; |
260 | lockUniqueName = fn + KApplication::randomString( 8 ); | 260 | lockUniqueName = fn + KApplication::randomString( 8 ); |
261 | 261 | ||
262 | url = lockUniqueName; | 262 | url = lockUniqueName; |
263 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 263 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
264 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 264 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
265 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 265 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
266 | 266 | ||
267 | // Create unique file | 267 | // Create unique file |
268 | QFile file( mLockUniqueName ); | 268 | QFile file( mLockUniqueName ); |
269 | file.open( IO_WriteOnly ); | 269 | file.open( IO_WriteOnly ); |
270 | file.close(); | 270 | file.close(); |
271 | 271 | ||
272 | // Create lock file | 272 | // Create lock file |
273 | int result = 0; | 273 | int result = 0; |
274 | #ifndef _WIN32_ | 274 | #ifndef _WIN32_ |
275 | result = ::link( QFile::encodeName( mLockUniqueName ), | 275 | result = ::link( QFile::encodeName( mLockUniqueName ), |
276 | QFile::encodeName( lockName ) ); | 276 | QFile::encodeName( lockName ) ); |
277 | #endif | 277 | #endif |
278 | if ( result == 0 ) { | 278 | if ( result == 0 ) { |
279 | addressBook()->emitAddressBookLocked(); | 279 | addressBook()->emitAddressBookLocked(); |
280 | return true; | 280 | return true; |
281 | } | 281 | } |
282 | 282 | ||
283 | // TODO: check stat | 283 | // TODO: check stat |
284 | 284 | ||
285 | return false; | 285 | return false; |
286 | } | 286 | } |
287 | 287 | ||
288 | void ResourceSharpDTM::unlock( const QString &fileName ) | 288 | void ResourceSharpDTM::unlock( const QString &fileName ) |
289 | { | 289 | { |
290 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | 290 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); |
291 | 291 | ||
292 | QString fn = fileName; | 292 | QString fn = fileName; |
293 | KURL url(fn); | 293 | KURL url(fn); |
294 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 294 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
295 | 295 | ||
296 | QFile::remove( lockName ); | 296 | QFile::remove( lockName ); |
297 | QFile::remove( mLockUniqueName ); | 297 | QFile::remove( mLockUniqueName ); |
298 | addressBook()->emitAddressBookUnlocked(); | 298 | addressBook()->emitAddressBookUnlocked(); |
299 | } | 299 | } |
300 | 300 | ||
301 | void ResourceSharpDTM::setFileName( const QString &newFileName ) | 301 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
302 | { | 302 | { |
303 | mDirWatch.stopScan(); | 303 | mDirWatch.stopScan(); |
304 | mDirWatch.removeFile( fileName() ); | 304 | mDirWatch.removeFile( fileName() ); |
305 | 305 | ||
306 | Resource::setFileName( newFileName ); | 306 | Resource::setFileName( newFileName ); |
307 | 307 | ||
308 | mDirWatch.addFile( fileName() ); | 308 | mDirWatch.addFile( fileName() ); |
309 | mDirWatch.startScan(); | 309 | mDirWatch.startScan(); |
310 | 310 | ||
311 | } | 311 | } |
312 | 312 | ||
313 | void ResourceSharpDTM::fileChanged() | 313 | void ResourceSharpDTM::fileChanged() |
314 | { | 314 | { |
315 | // There is a small theoretical chance that KDirWatch calls us before | 315 | // There is a small theoretical chance that KDirWatch calls us before |
316 | // we are fully constructed | 316 | // we are fully constructed |
317 | if (!addressBook()) | 317 | if (!addressBook()) |
318 | return; | 318 | return; |
319 | 319 | ||
320 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 320 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
321 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 321 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
322 | load(); | 322 | load(); |
323 | addressBook()->emitAddressBookChanged(); | 323 | addressBook()->emitAddressBookChanged(); |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 327 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) |
328 | { | 328 | { |
329 | } | 329 | } |
330 | 330 | ||
331 | void ResourceSharpDTM::cleanUp() | 331 | void ResourceSharpDTM::cleanUp() |
332 | { | 332 | { |
333 | unlock( fileName() ); | 333 | unlock( fileName() ); |
334 | } | 334 | } |
335 | 335 | ||
336 | 336 | ||
337 | 337 | ||
diff --git a/kabc/resource.cpp b/kabc/resource.cpp index 2f03927..d39fd6a 100644 --- a/kabc/resource.cpp +++ b/kabc/resource.cpp | |||
@@ -1,139 +1,144 @@ | |||
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 <kdebug.h> | 28 | #include <kdebug.h> |
29 | 29 | ||
30 | #include <ksyncprofile.h> | 30 | #include <ksyncprofile.h> |
31 | 31 | ||
32 | #include "resource.h" | 32 | #include "resource.h" |
33 | 33 | ||
34 | using namespace KABC; | 34 | using namespace KABC; |
35 | 35 | ||
36 | Resource::Resource( const KConfig *config, bool syncable ) | 36 | Resource::Resource( const KConfig *config, bool syncable ) |
37 | : KRES::Resource( config ), mAddressBook( 0 ), mSyncProfile( 0 ) | 37 | : KRES::Resource( config ), mAddressBook( 0 ), mSyncProfile( 0 ) |
38 | { | 38 | { |
39 | if(syncable == true) { | 39 | if(syncable == true) { |
40 | mSyncProfile = new KSyncProfile( identifier() ); | 40 | mSyncProfile = new KSyncProfile( identifier() ); |
41 | mSyncProfile->setName(resourceName()); | 41 | mSyncProfile->setName(resourceName()); |
42 | mSyncProfile->readConfig( (KConfig *)config ); | 42 | mSyncProfile->readConfig( (KConfig *)config ); |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | Resource::~Resource() | 46 | Resource::~Resource() |
47 | { | 47 | { |
48 | if (mSyncProfile != 0) { | 48 | if (mSyncProfile != 0) { |
49 | delete mSyncProfile; | 49 | delete mSyncProfile; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | void Resource::writeConfig( KConfig *config ) | 53 | void Resource::writeConfig( KConfig *config ) |
54 | { | 54 | { |
55 | KRES::Resource::writeConfig( config ); | 55 | KRES::Resource::writeConfig( config ); |
56 | 56 | ||
57 | if(mSyncProfile != 0) | 57 | if(mSyncProfile != 0) |
58 | mSyncProfile->writeConfig( config ); | 58 | mSyncProfile->writeConfig( config ); |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | void Resource::setAddressBook( AddressBook *ab ) | 62 | void Resource::setAddressBook( AddressBook *ab ) |
63 | { | 63 | { |
64 | mAddressBook = ab; | 64 | mAddressBook = ab; |
65 | } | 65 | } |
66 | 66 | ||
67 | AddressBook *Resource::addressBook() | 67 | AddressBook *Resource::addressBook() |
68 | { | 68 | { |
69 | return mAddressBook; | 69 | return mAddressBook; |
70 | } | 70 | } |
71 | 71 | ||
72 | bool Resource::doOpen() | 72 | bool Resource::doOpen() |
73 | { | 73 | { |
74 | return true; | 74 | return true; |
75 | } | 75 | } |
76 | 76 | ||
77 | void Resource::doClose() | 77 | void Resource::doClose() |
78 | { | 78 | { |
79 | } | 79 | } |
80 | 80 | ||
81 | Ticket *Resource::requestSaveTicket() | 81 | Ticket *Resource::requestSaveTicket() |
82 | { | 82 | { |
83 | return 0; | 83 | return 0; |
84 | } | 84 | } |
85 | 85 | ||
86 | bool Resource::load() | 86 | bool Resource::load() |
87 | { | 87 | { |
88 | return true; | 88 | return true; |
89 | } | 89 | } |
90 | 90 | ||
91 | bool Resource::save( Ticket * ) | 91 | bool Resource::save( Ticket * ) |
92 | { | 92 | { |
93 | return false; | 93 | return false; |
94 | } | 94 | } |
95 | 95 | ||
96 | Ticket *Resource::createTicket( Resource *resource ) | 96 | Ticket *Resource::createTicket( Resource *resource ) |
97 | { | 97 | { |
98 | return new Ticket( resource ); | 98 | return new Ticket( resource ); |
99 | } | 99 | } |
100 | 100 | ||
101 | void Resource::removeAddressee( const Addressee& ) | 101 | void Resource::removeAddressee( const Addressee& ) |
102 | { | 102 | { |
103 | // do nothing | 103 | // do nothing |
104 | } | 104 | } |
105 | 105 | ||
106 | void Resource::cleanUp() | 106 | void Resource::cleanUp() |
107 | { | 107 | { |
108 | // do nothing | 108 | // do nothing |
109 | } | 109 | } |
110 | 110 | ||
111 | bool Resource::isSyncable() const | 111 | bool Resource::isSyncable() const |
112 | { | 112 | { |
113 | return (mSyncProfile != 0); | 113 | return (mSyncProfile != 0); |
114 | } | 114 | } |
115 | 115 | ||
116 | KSyncProfile* Resource::getSyncProfile() | ||
117 | { | ||
118 | return mSyncProfile; | ||
119 | } | ||
120 | |||
116 | 121 | ||
117 | QString Resource::fileName() const | 122 | QString Resource::fileName() const |
118 | { | 123 | { |
119 | return mFileName; | 124 | return mFileName; |
120 | } | 125 | } |
121 | 126 | ||
122 | void Resource::setFileName( const QString &fileName ) | 127 | void Resource::setFileName( const QString &fileName ) |
123 | { | 128 | { |
124 | mFileName = fileName; | 129 | mFileName = fileName; |
125 | } | 130 | } |
126 | 131 | ||
127 | /** | 132 | /** |
128 | * Set the name of resource.You can override this method, | 133 | * Set the name of resource.You can override this method, |
129 | * but also remember to call Resource::setResourceName(). | 134 | * but also remember to call Resource::setResourceName(). |
130 | */ | 135 | */ |
131 | void Resource::setResourceName( const QString &name ) | 136 | void Resource::setResourceName( const QString &name ) |
132 | { | 137 | { |
133 | KRES::Resource::setResourceName(name); | 138 | KRES::Resource::setResourceName(name); |
134 | if(mSyncProfile != 0) { | 139 | if(mSyncProfile != 0) { |
135 | mSyncProfile->setName( name ); | 140 | mSyncProfile->setName( name ); |
136 | } | 141 | } |
137 | 142 | ||
138 | } | 143 | } |
139 | 144 | ||
diff --git a/kabc/resource.h b/kabc/resource.h index 7d42f81..2024d2d 100644 --- a/kabc/resource.h +++ b/kabc/resource.h | |||
@@ -1,169 +1,171 @@ | |||
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_RESOURCE_H | 28 | #ifndef KABC_RESOURCE_H |
29 | #define KABC_RESOURCE_H | 29 | #define KABC_RESOURCE_H |
30 | 30 | ||
31 | #include <kresources/resource.h> | 31 | #include <kresources/resource.h> |
32 | 32 | ||
33 | 33 | ||
34 | #include "addressbook.h" | 34 | #include "addressbook.h" |
35 | 35 | ||
36 | class KSyncProfile; | 36 | class KSyncProfile; |
37 | 37 | ||
38 | namespace KABC { | 38 | namespace KABC { |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * @short Helper class for handling coordinated save of address books. | 41 | * @short Helper class for handling coordinated save of address books. |
42 | * | 42 | * |
43 | * This class is used as helper class for saving address book. | 43 | * This class is used as helper class for saving address book. |
44 | * @see requestSaveTicket(), save(). | 44 | * @see requestSaveTicket(), save(). |
45 | */ | 45 | */ |
46 | class Ticket | 46 | class Ticket |
47 | { | 47 | { |
48 | friend class Resource; | 48 | friend class Resource; |
49 | public: | 49 | public: |
50 | Resource *resource() { return mResource; } | 50 | Resource *resource() { return mResource; } |
51 | 51 | ||
52 | private: | 52 | private: |
53 | Ticket( Resource *resource ) : mResource( resource ) {} | 53 | Ticket( Resource *resource ) : mResource( resource ) {} |
54 | 54 | ||
55 | Resource *mResource; | 55 | Resource *mResource; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * @internal | 59 | * @internal |
60 | */ | 60 | */ |
61 | class Resource : public KRES::Resource | 61 | class Resource : public KRES::Resource |
62 | { | 62 | { |
63 | private: | 63 | private: |
64 | /** | 64 | /** |
65 | * make this constructor private to force everybody to use the other one | 65 | * make this constructor private to force everybody to use the other one |
66 | */ | 66 | */ |
67 | Resource( const KConfig *config); | 67 | Resource( const KConfig *config); |
68 | 68 | ||
69 | public: | 69 | public: |
70 | /** | 70 | /** |
71 | * Constructor | 71 | * Constructor |
72 | */ | 72 | */ |
73 | Resource( const KConfig *config, bool syncable ); | 73 | Resource( const KConfig *config, bool syncable ); |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Destructor. | 76 | * Destructor. |
77 | */ | 77 | */ |
78 | virtual ~Resource(); | 78 | virtual ~Resource(); |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Sets the address book of the resource. | 81 | * Sets the address book of the resource. |
82 | */ | 82 | */ |
83 | void setAddressBook( AddressBook* ); | 83 | void setAddressBook( AddressBook* ); |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Returns a pointer to the addressbook. | 86 | * Returns a pointer to the addressbook. |
87 | */ | 87 | */ |
88 | AddressBook *addressBook(); | 88 | AddressBook *addressBook(); |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Writes the resource specific config to file. | 91 | * Writes the resource specific config to file. |
92 | */ | 92 | */ |
93 | virtual void writeConfig( KConfig *config ); | 93 | virtual void writeConfig( KConfig *config ); |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Open the resource and returns if it was successfully | 96 | * Open the resource and returns if it was successfully |
97 | */ | 97 | */ |
98 | virtual bool doOpen(); | 98 | virtual bool doOpen(); |
99 | 99 | ||
100 | 100 | ||
101 | /** | 101 | /** |
102 | * Request a ticket, you have to pass through @ref save() to | 102 | * Request a ticket, you have to pass through @ref save() to |
103 | * allow locking. | 103 | * allow locking. |
104 | */ | 104 | */ |
105 | virtual Ticket *requestSaveTicket(); | 105 | virtual Ticket *requestSaveTicket(); |
106 | 106 | ||
107 | /** | 107 | /** |
108 | * Load all addressees to the addressbook | 108 | * Load all addressees to the addressbook |
109 | */ | 109 | */ |
110 | virtual bool load(); | 110 | virtual bool load(); |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Save all addressees to the addressbook. | 113 | * Save all addressees to the addressbook. |
114 | * | 114 | * |
115 | * @param ticket The ticket you get by @ref requestSaveTicket() | 115 | * @param ticket The ticket you get by @ref requestSaveTicket() |
116 | */ | 116 | */ |
117 | virtual bool save( Ticket *ticket ); | 117 | virtual bool save( Ticket *ticket ); |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * Removes a addressee from resource. This method is mainly | 120 | * Removes a addressee from resource. This method is mainly |
121 | * used by record-based resources like LDAP or SQL. | 121 | * used by record-based resources like LDAP or SQL. |
122 | */ | 122 | */ |
123 | virtual void removeAddressee( const Addressee& addr ); | 123 | virtual void removeAddressee( const Addressee& addr ); |
124 | 124 | ||
125 | 125 | ||
126 | /** | 126 | /** |
127 | * This method is called by an error handler if the application | 127 | * This method is called by an error handler if the application |
128 | * crashed | 128 | * crashed |
129 | */ | 129 | */ |
130 | virtual void cleanUp(); | 130 | virtual void cleanUp(); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | * Set name of file to be used for saving. | 133 | * Set name of file to be used for saving. |
134 | */ | 134 | */ |
135 | virtual void setFileName( const QString & ); | 135 | virtual void setFileName( const QString & ); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * Return name of file used for loading and saving the address book. | 138 | * Return name of file used for loading and saving the address book. |
139 | */ | 139 | */ |
140 | virtual QString fileName() const; | 140 | virtual QString fileName() const; |
141 | 141 | ||
142 | 142 | ||
143 | virtual bool isSyncable() const; | 143 | virtual bool isSyncable() const; |
144 | 144 | ||
145 | virtual KSyncProfile* getSyncProfile(); | ||
146 | |||
145 | /** | 147 | /** |
146 | * Set the name of resource.You can override this method, | 148 | * Set the name of resource.You can override this method, |
147 | * but also remember to call Resource::setResourceName(). | 149 | * but also remember to call Resource::setResourceName(). |
148 | */ | 150 | */ |
149 | virtual void setResourceName( const QString &name ); | 151 | virtual void setResourceName( const QString &name ); |
150 | 152 | ||
151 | 153 | ||
152 | 154 | ||
153 | protected: | 155 | protected: |
154 | Ticket *createTicket( Resource * ); | 156 | Ticket *createTicket( Resource * ); |
155 | virtual void doClose(); | 157 | virtual void doClose(); |
156 | 158 | ||
157 | private: | 159 | private: |
158 | AddressBook *mAddressBook; | 160 | AddressBook *mAddressBook; |
159 | KSyncProfile *mSyncProfile; | 161 | KSyncProfile *mSyncProfile; |
160 | QString mFileName; | 162 | QString mFileName; |
161 | 163 | ||
162 | }; | 164 | }; |
163 | 165 | ||
164 | 166 | ||
165 | } | 167 | } |
166 | 168 | ||
167 | 169 | ||
168 | 170 | ||
169 | #endif | 171 | #endif |
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index 1e00cc6..760820e 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp | |||
@@ -1,228 +1,226 @@ | |||
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 | : AddressBook( "kabcrc" ) |
116 | : AddressBook( locateLocal( "config", "kabcrc") ) | ||
117 | { | 116 | { |
118 | 117 | ||
119 | init( false ); | 118 | init( false ); |
120 | } | 119 | } |
121 | 120 | ||
122 | StdAddressBook::StdAddressBook( bool onlyFastResources ) | 121 | StdAddressBook::StdAddressBook( bool onlyFastResources ) |
123 | //US : AddressBook( "kabcrc" ) | 122 | : AddressBook( "kabcrc" ) |
124 | : AddressBook( locateLocal( "config", "kabcrc") ) | ||
125 | { | 123 | { |
126 | 124 | ||
127 | init( onlyFastResources ); | 125 | init( onlyFastResources ); |
128 | } | 126 | } |
129 | 127 | ||
130 | StdAddressBook::~StdAddressBook() | 128 | StdAddressBook::~StdAddressBook() |
131 | { | 129 | { |
132 | if ( mAutomaticSave ) | 130 | if ( mAutomaticSave ) |
133 | save(); | 131 | save(); |
134 | } | 132 | } |
135 | 133 | ||
136 | void StdAddressBook::init( bool ) | 134 | void StdAddressBook::init( bool ) |
137 | { | 135 | { |
138 | KRES::Manager<Resource> *manager = resourceManager(); | 136 | KRES::Manager<Resource> *manager = resourceManager(); |
139 | KRES::Manager<Resource>::ActiveIterator it; | 137 | KRES::Manager<Resource>::ActiveIterator it; |
140 | 138 | ||
141 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 139 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
142 | (*it)->setAddressBook( this ); | 140 | (*it)->setAddressBook( this ); |
143 | if ( !(*it)->open() ) | 141 | if ( !(*it)->open() ) |
144 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 142 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
145 | } | 143 | } |
146 | 144 | ||
147 | Resource *res = standardResource(); | 145 | Resource *res = standardResource(); |
148 | if ( !res ) { | 146 | if ( !res ) { |
149 | res = manager->createResource( "file" ); | 147 | res = manager->createResource( "file" ); |
150 | if ( res ) | 148 | if ( res ) |
151 | { | 149 | { |
152 | addResource( res ); | 150 | addResource( res ); |
153 | } | 151 | } |
154 | else | 152 | else |
155 | qDebug(" No resource available!!!"); | 153 | qDebug(" No resource available!!!"); |
156 | } | 154 | } |
157 | 155 | ||
158 | setStandardResource( res ); | 156 | setStandardResource( res ); |
159 | manager->writeConfig(); | 157 | manager->writeConfig(); |
160 | 158 | ||
161 | load(); | 159 | load(); |
162 | } | 160 | } |
163 | 161 | ||
164 | bool StdAddressBook::save() | 162 | bool StdAddressBook::save() |
165 | { | 163 | { |
166 | kdDebug(5700) << "StdAddressBook::save()" << endl; | 164 | kdDebug(5700) << "StdAddressBook::save()" << endl; |
167 | 165 | ||
168 | bool ok = true; | 166 | bool ok = true; |
169 | AddressBook *ab = self(); | 167 | AddressBook *ab = self(); |
170 | 168 | ||
171 | ab->deleteRemovedAddressees(); | 169 | ab->deleteRemovedAddressees(); |
172 | 170 | ||
173 | KRES::Manager<Resource>::ActiveIterator it; | 171 | KRES::Manager<Resource>::ActiveIterator it; |
174 | KRES::Manager<Resource> *manager = ab->resourceManager(); | 172 | KRES::Manager<Resource> *manager = ab->resourceManager(); |
175 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 173 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
176 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 174 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
177 | Ticket *ticket = ab->requestSaveTicket( *it ); | 175 | Ticket *ticket = ab->requestSaveTicket( *it ); |
178 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 176 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
179 | if ( !ticket ) { | 177 | if ( !ticket ) { |
180 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) | 178 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) |
181 | .arg( (*it)->resourceName() ) ); | 179 | .arg( (*it)->resourceName() ) ); |
182 | return false; | 180 | return false; |
183 | } | 181 | } |
184 | 182 | ||
185 | if ( !ab->save( ticket ) ) | 183 | if ( !ab->save( ticket ) ) |
186 | ok = false; | 184 | ok = false; |
187 | } | 185 | } |
188 | } | 186 | } |
189 | 187 | ||
190 | return ok; | 188 | return ok; |
191 | } | 189 | } |
192 | 190 | ||
193 | void StdAddressBook::close() | 191 | void StdAddressBook::close() |
194 | { | 192 | { |
195 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? | 193 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? |
196 | //US addressBookDeleter.destructObject(); | 194 | //US addressBookDeleter.destructObject(); |
197 | addressBookDeleter.setObject(0); | 195 | addressBookDeleter.setObject(0); |
198 | 196 | ||
199 | } | 197 | } |
200 | 198 | ||
201 | void StdAddressBook::setAutomaticSave( bool enable ) | 199 | void StdAddressBook::setAutomaticSave( bool enable ) |
202 | { | 200 | { |
203 | mAutomaticSave = enable; | 201 | mAutomaticSave = enable; |
204 | } | 202 | } |
205 | 203 | ||
206 | bool StdAddressBook::automaticSave() | 204 | bool StdAddressBook::automaticSave() |
207 | { | 205 | { |
208 | return mAutomaticSave; | 206 | return mAutomaticSave; |
209 | } | 207 | } |
210 | 208 | ||
211 | // should get const for 4.X | 209 | // should get const for 4.X |
212 | Addressee StdAddressBook::whoAmI() | 210 | Addressee StdAddressBook::whoAmI() |
213 | { | 211 | { |
214 | //US KConfig config( "kabcrc" ); | 212 | //US KConfig config( "kabcrc" ); |
215 | KConfig config( locateLocal("config", "kabcrc") ); | 213 | KConfig config( locateLocal("config", "kabcrc") ); |
216 | config.setGroup( "General" ); | 214 | config.setGroup( "General" ); |
217 | 215 | ||
218 | return findByUid( config.readEntry( "WhoAmI" ) ); | 216 | return findByUid( config.readEntry( "WhoAmI" ) ); |
219 | } | 217 | } |
220 | 218 | ||
221 | void StdAddressBook::setWhoAmI( const Addressee &addr ) | 219 | void StdAddressBook::setWhoAmI( const Addressee &addr ) |
222 | { | 220 | { |
223 | //US KConfig config( "kabcrc" ); | 221 | //US KConfig config( "kabcrc" ); |
224 | KConfig config( locateLocal("config", "kabcrc") ); | 222 | KConfig config( locateLocal("config", "kabcrc") ); |
225 | config.setGroup( "General" ); | 223 | config.setGroup( "General" ); |
226 | 224 | ||
227 | config.writeEntry( "WhoAmI", addr.uid() ); | 225 | config.writeEntry( "WhoAmI", addr.uid() ); |
228 | } | 226 | } |
diff --git a/kabc/syncprefwidget.cpp b/kabc/syncprefwidget.cpp index 51a8040..a2bde72 100644 --- a/kabc/syncprefwidget.cpp +++ b/kabc/syncprefwidget.cpp | |||
@@ -1,495 +1,410 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KABC for platform independent KDE tools. | 2 | This file is part of KABC for platform independent KDE tools. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program 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 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | /*US | ||
29 | #include <qlayout.h> | ||
30 | #include <qlabel.h> | ||
31 | #include <qgroupbox.h> | ||
32 | #include <qbuttongroup.h> | ||
33 | #include <qlineedit.h> | ||
34 | #include <qfont.h> | ||
35 | #include <qslider.h> | ||
36 | #include <qfile.h> | ||
37 | #include <qtextstream.h> | ||
38 | #include <qcombobox.h> | ||
39 | #include <qvbox.h> | ||
40 | #include <qhbox.h> | ||
41 | #include <qspinbox.h> | ||
42 | #include <qdatetime.h> | ||
43 | #include <qcheckbox.h> | ||
44 | #include <qradiobutton.h> | ||
45 | #include <qpushbutton.h> | ||
46 | #include <qstrlist.h> | ||
47 | #include <qapplication.h> | ||
48 | |||
49 | #include <kcolorbutton.h> | ||
50 | #include <kdebug.h> | ||
51 | #include <klocale.h> | ||
52 | #include <kglobal.h> | ||
53 | #include <kfontdialog.h> | ||
54 | #include <kmessagebox.h> | ||
55 | #include <kcolordialog.h> | ||
56 | #include <kiconloader.h> | ||
57 | #include <kemailsettings.h> | ||
58 | #include <kstandarddirs.h> | ||
59 | #include <kfiledialog.h> | ||
60 | #include <kmessagebox.h> | ||
61 | |||
62 | #include <kurlrequester.h> | ||
63 | #include <klineedit.h> | ||
64 | #include <libkdepim/ksyncprofile.h> | ||
65 | |||
66 | |||
67 | #include "koprefs.h" | ||
68 | |||
69 | #include "kosyncprefsdialog.h" | ||
70 | #include "koglobals.h" | ||
71 | */ | ||
72 | 28 | ||
73 | #include <qlayout.h> | 29 | #include <qlayout.h> |
74 | #include <qbuttongroup.h> | 30 | #include <qbuttongroup.h> |
75 | #include <qcheckbox.h> | 31 | #include <qcheckbox.h> |
76 | #include <qradiobutton.h> | 32 | #include <qradiobutton.h> |
77 | #include <qvbox.h> | 33 | #include <qvbox.h> |
78 | #include <qhbox.h> | 34 | #include <qhbox.h> |
79 | #include <qlabel.h> | 35 | #include <qlabel.h> |
80 | #include <qlineedit.h> | 36 | #include <qlineedit.h> |
81 | #include <qpushbutton.h> | 37 | #include <qpushbutton.h> |
38 | #include <qscrollview.h> | ||
39 | #include <qcombobox.h> | ||
82 | 40 | ||
83 | 41 | ||
84 | #include <klocale.h> | 42 | #include <klocale.h> |
85 | #include <kdialog.h> | 43 | #include <kdialog.h> |
86 | 44 | ||
87 | 45 | #include "ksyncprofile.h" | |
46 | #include "resource.h" | ||
88 | #include "syncprefwidget.h" | 47 | #include "syncprefwidget.h" |
89 | 48 | ||
90 | 49 | ||
91 | SyncPrefWidget::SyncPrefWidget(QWidget *parent) : | 50 | SyncPrefWidget_Settings::SyncPrefWidget_Settings(QWidget *parent, const char *name) : |
92 | KRES::SyncWidget(parent) | 51 | KRES::SyncWidget(parent, name) |
93 | { | 52 | { |
94 | 53 | init(); | |
95 | //US setCaption( i18n("Synchronization Preferences")); | ||
96 | |||
97 | //US mSyncProfiles.setAutoDelete( true ); | ||
98 | init(); | ||
99 | } | 54 | } |
100 | 55 | ||
101 | 56 | ||
102 | SyncPrefWidget::~SyncPrefWidget() | 57 | SyncPrefWidget_Settings::~SyncPrefWidget_Settings() |
103 | { | 58 | { |
104 | } | 59 | } |
105 | 60 | ||
106 | //US #include <qlayout.h> | 61 | void SyncPrefWidget_Settings::init() |
107 | //US #include <qscrollview.h> | ||
108 | void SyncPrefWidget::init() | ||
109 | { | 62 | { |
110 | QLabel * lab; | ||
111 | QPushButton* button; | ||
112 | |||
113 | /*US | ||
114 | //QFrame *page = addPage(i18n("Sync Prefs"),0,0); | ||
115 | QVBox * mainbox = new QVBox( this ); | ||
116 | QScrollView* sv = new QScrollView( mainbox ); | ||
117 | QHBoxLayout * lay = new QHBoxLayout( this ); | ||
118 | lay->addWidget( mainbox ); | ||
119 | QHBox * b_box = new QHBox( mainbox ); | ||
120 | */ | ||
121 | /*US | ||
122 | QPushButton* button = new QPushButton( i18n("Ok"), b_box ); | ||
123 | connect ( button, SIGNAL( clicked()), this, SLOT (slotOK() ) ); | ||
124 | button = new QPushButton( i18n("Cancel"), b_box ); | ||
125 | connect ( button, SIGNAL( clicked()), this, SLOT (reject() ) ); | ||
126 | */ | ||
127 | //QBoxLayout * sl = new QVBoxLayout(this ); | ||
128 | //sl->addWidget ( sv ); | ||
129 | /*US | ||
130 | sv->setResizePolicy ( QScrollView::AutoOneFit ); | ||
131 | QFrame *topFrame = new QFrame ( sv ); | ||
132 | sv->addChild( topFrame ); | ||
133 | mSetupSyncAlgTab = topFrame; | ||
134 | QGridLayout *topLayout = new QGridLayout(topFrame,6,2); | ||
135 | topLayout->setSpacing(spacingHint()); | ||
136 | topLayout->setMargin(marginHint()); | ||
137 | */ | ||
138 | //US new code for the layout | ||
139 | QGridLayout *topLayout = new QGridLayout( this, 6,2 ); | 63 | QGridLayout *topLayout = new QGridLayout( this, 6,2 ); |
140 | topLayout->setMargin( KDialog::marginHint() ); | 64 | topLayout->setMargin( KDialog::marginHint() ); |
141 | topLayout->setSpacing( KDialog::spacingHint() ); | 65 | topLayout->setSpacing( KDialog::spacingHint() ); |
142 | 66 | ||
143 | //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame); | 67 | int iii = 0; |
144 | int iii = 0; | 68 | mIncludeInRing = new QCheckBox( i18n("Include in multiple sync"), this ); |
145 | //topLayout->addMultiCellWidget(lab , iii,iii,0,1); | 69 | topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1); |
146 | //++iii; | 70 | ++iii; |
147 | |||
148 | /*US | ||
149 | mMyMachineName = new QLineEdit(topFrame); | ||
150 | lab = new QLabel(mMyMachineName, i18n("Local device name:"), topFrame); | ||
151 | topLayout->addWidget(lab ,iii,0); | ||
152 | topLayout->addWidget(mMyMachineName,iii,1); | ||
153 | ++iii; | ||
154 | |||
155 | QHBox* buttonbox = new QHBox( topFrame); | ||
156 | topLayout->addMultiCellWidget(buttonbox, iii,iii,0,1); | ||
157 | ++iii; | ||
158 | button = new QPushButton( i18n("New profile"), buttonbox ); | ||
159 | connect ( button, SIGNAL( clicked()), this, SLOT (newProfile() ) ); | ||
160 | |||
161 | button = new QPushButton( i18n("Clone profile"), buttonbox ); | ||
162 | connect ( button, SIGNAL( clicked()), this, SLOT ( cloneProfile() ) ); | ||
163 | |||
164 | button = new QPushButton( i18n("Delete profile"), buttonbox ); | ||
165 | connect ( button, SIGNAL( clicked()), this, SLOT (deleteProfile() ) ); | ||
166 | |||
167 | mProfileBox = new QComboBox(topFrame); | ||
168 | mProfileBox->setEditable ( true ); | ||
169 | connect ( mProfileBox, SIGNAL(activated ( int ) ), this, SLOT (profileChanged( int ) ) ); | ||
170 | connect ( mProfileBox, SIGNAL( textChanged ( const QString & ) ), this, SLOT (textChanged( const QString & ) ) ); | ||
171 | |||
172 | lab = new QLabel(mProfileBox, i18n("Profile:"), topFrame); | ||
173 | topLayout->addWidget(lab ,iii,0); | ||
174 | topLayout->addWidget(mProfileBox, iii,1); | ||
175 | ++iii; | ||
176 | */ | ||
177 | mIncludeInRing = new QCheckBox( i18n("Include in multiple sync"), this ); | ||
178 | topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1); | ||
179 | ++iii; | ||
180 | |||
181 | mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), this ); | ||
182 | topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1); | ||
183 | ++iii; | ||
184 | QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync preferences"), this); | ||
185 | topLayout->addMultiCellWidget(gr, iii,iii,0,1); | ||
186 | ++iii; | ||
187 | loc = new QRadioButton ( i18n("Take local entry on conflict"), gr ); | ||
188 | rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr ); | ||
189 | newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr ); | ||
190 | ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr ); | ||
191 | f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr ); | ||
192 | f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr ); | ||
193 | // both = new QRadioButton ( i18n("Take both on conflict"), gr ); | ||
194 | 71 | ||
195 | mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), this ); | 72 | mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), this ); |
196 | topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1); | 73 | topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1); |
197 | ++iii; | 74 | ++iii; |
198 | |||
199 | mWriteBackExisting= new QCheckBox( i18n("Write back existing entries only"), this ); | ||
200 | topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1); | ||
201 | ++iii; | ||
202 | |||
203 | mWriteBackFile = new QCheckBox( i18n("Write back file"), this ); | ||
204 | topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1); | ||
205 | ++iii; | ||
206 | |||
207 | mIsNotLocal = new QCheckBox( i18n("Remote file (w down/upload command)"), this ); | ||
208 | topLayout->addMultiCellWidget(mIsNotLocal, iii,iii,0,1); | ||
209 | connect (mIsNotLocal, SIGNAL( checked(bool)), this, SLOT (kindChanged(bool) ) ); | ||
210 | /*US | ||
211 | proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), this); | ||
212 | gr = proGr; | ||
213 | topLayout->addMultiCellWidget(gr, iii,iii,0,1); | ||
214 | ++iii; | ||
215 | mIsLocal = new QRadioButton ( i18n("Local file"), gr ); | ||
216 | mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr ); | ||
217 | connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) ); | ||
218 | */ | ||
219 | 75 | ||
220 | /*US | 76 | mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), this ); |
221 | localFileWidget = new QVBox( topFrame); | 77 | topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1); |
222 | topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1); | 78 | ++iii; |
223 | ++iii; | ||
224 | QHBox* temphb = new QHBox( localFileWidget ); | ||
225 | lab = new QLabel( i18n("Local file:"), temphb); | ||
226 | mRemoteFile = new QLineEdit(localFileWidget); | ||
227 | 79 | ||
228 | button = new QPushButton( i18n("Choose..."), temphb ); | 80 | mWriteBackExisting= new QCheckBox( i18n("Write back existing entries only"), this ); |
229 | connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) ); | 81 | topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1); |
230 | */ | 82 | ++iii; |
231 | QHBox* temphb; | ||
232 | 83 | ||
233 | remoteFileWidget = new QVBox( this); | 84 | mWriteBackFile = new QCheckBox( i18n("Write back synced data"), this ); |
234 | topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1); | 85 | topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1); |
235 | ++iii; | 86 | ++iii; |
236 | lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget); | ||
237 | mRemotePrecommand = new QLineEdit(remoteFileWidget); | ||
238 | 87 | ||
239 | lab = new QLabel( i18n("Local temp file:"), remoteFileWidget); | 88 | } |
240 | mLocalTempFile = new QLineEdit(remoteFileWidget); | ||
241 | 89 | ||
90 | void SyncPrefWidget_Settings::loadSettings( KRES::Resource *res ) | ||
91 | { | ||
92 | KABC::Resource* resource = (KABC::Resource*)( res ); | ||
93 | KSyncProfile* prof = resource->getSyncProfile(); | ||
94 | |||
95 | if (prof == 0) | ||
96 | { | ||
97 | qDebug("SyncPrefWidget_Settings::loadSettings: something is wrong, because resource does have no syncprofile" ); | ||
98 | return; | ||
99 | } | ||
100 | |||
101 | mIncludeInRing->setChecked( prof->getIncludeInRingSync() ); | ||
102 | mAskForPreferences->setChecked( prof->getAskForPreferences()); | ||
103 | mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync()); | ||
104 | mWriteBackExisting->setChecked( prof->getWriteBackExisting() ); | ||
105 | mWriteBackFile->setChecked( prof->getWriteBackFile()); | ||
106 | } | ||
242 | 107 | ||
243 | lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget); | 108 | void SyncPrefWidget_Settings::saveSettings( KRES::Resource *res ) |
244 | mRemotePostcommand = new QLineEdit(remoteFileWidget); | 109 | { |
110 | KABC::Resource* resource = (KABC::Resource*)( res ); | ||
111 | KSyncProfile* prof = resource->getSyncProfile(); | ||
112 | |||
113 | if (prof == 0) | ||
114 | { | ||
115 | qDebug("SyncPrefWidget_Settings::saveSettings: something is wrong, because resource does have no syncprofile" ); | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | prof->setIncludeInRingSync( mIncludeInRing->isChecked() ); | ||
120 | prof->setAskForPreferences( mAskForPreferences->isChecked()); | ||
121 | prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() ); | ||
122 | prof->setWriteBackExisting(mWriteBackExisting->isChecked() ); | ||
123 | prof->setWriteBackFile( mWriteBackFile->isChecked()); | ||
124 | } | ||
245 | 125 | ||
246 | lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget); | ||
247 | temphb = new QHBox( remoteFileWidget ); | ||
248 | button = new QPushButton( i18n("ssh/scp"), temphb ); | ||
249 | connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) ); | ||
250 | button = new QPushButton( i18n("ftp"), temphb ); | ||
251 | connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) ); | ||
252 | lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget); | ||
253 | 126 | ||
127 | /*********************************************************************** | ||
128 | * | ||
129 | * | ||
130 | **********************************************************************/ | ||
254 | 131 | ||
255 | } | 132 | SyncPrefWidget_Conflict::SyncPrefWidget_Conflict(QWidget *parent, const char *name) : |
256 | /*US | 133 | KRES::SyncWidget(parent, name) |
257 | void SyncPrefWidget::slotOK() | ||
258 | { | 134 | { |
259 | if ( mMyMachineName->text() == "undefined" ) { | 135 | init(); |
260 | KMessageBox::error(this,i18n("Local device name undefined!\nPlease define device name!"),i18n("KO/Pi config error")); | ||
261 | return; | ||
262 | } | ||
263 | int i; | ||
264 | for (i = 0; i < mSyncProfileNames.count(); ++ i) { | ||
265 | if ( mSyncProfileNames.contains( mSyncProfileNames[i]) > 1 ) { | ||
266 | KMessageBox::error(this,i18n("Multiple profiles with same name!\nPlease use unique profile names!"),i18n("KO/Pi config error")); | ||
267 | return; | ||
268 | } | ||
269 | } | ||
270 | usrWriteConfig(); | ||
271 | QDialog::accept(); | ||
272 | } | 136 | } |
273 | void SyncPrefWidget::accept() | 137 | |
138 | |||
139 | SyncPrefWidget_Conflict::~SyncPrefWidget_Conflict() | ||
274 | { | 140 | { |
275 | slotOK(); | ||
276 | } | 141 | } |
277 | void KOSyncPrefsDialog::chooseFile() | 142 | |
143 | void SyncPrefWidget_Conflict::init() | ||
278 | { | 144 | { |
279 | QString fn =KOPrefs::instance()->mLastSyncedLocalFile; | 145 | QGridLayout *topLayout = new QGridLayout( this, 6,2 ); |
146 | topLayout->setMargin( KDialog::marginHint() ); | ||
147 | topLayout->setSpacing( KDialog::spacingHint() ); | ||
280 | 148 | ||
281 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); | 149 | int iii = 0; |
282 | if ( fn == "" ) | 150 | |
283 | return; | 151 | QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("In case of conflicts"), this); |
284 | mRemoteFile->setText( fn ); | 152 | topLayout->addMultiCellWidget(gr, iii,iii,0,1); |
153 | ++iii; | ||
154 | loc = new QRadioButton ( i18n("Take local entry on conflict"), gr ); | ||
155 | rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr ); | ||
156 | newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr ); | ||
157 | ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr ); | ||
158 | f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr ); | ||
159 | f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr ); | ||
160 | // both = new QRadioButton ( i18n("Take both on conflict"), gr ); | ||
285 | } | 161 | } |
286 | 162 | ||
287 | void KOSyncPrefsDialog::textChanged( const QString & s ) | 163 | void SyncPrefWidget_Conflict::loadSettings( KRES::Resource *res ) |
288 | { | 164 | { |
289 | if ( mProfileBox->count() == 0 ) | 165 | KABC::Resource* resource = (KABC::Resource*)( res ); |
290 | return; | 166 | KSyncProfile* prof = resource->getSyncProfile(); |
291 | if ( currentSelection < 3 ) { | 167 | |
292 | //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error")); | 168 | if (prof == 0) |
293 | mProfileBox->blockSignals( true ); | 169 | { |
294 | mProfileBox->setCurrentItem(mProfileBox-> currentItem ()); | 170 | qDebug("SyncPrefWidget_Conflict::loadSettings: something is wrong, because resource does have no syncprofile" ); |
295 | mProfileBox->blockSignals( false ); | 171 | return; |
296 | return; | 172 | } |
297 | } | 173 | |
298 | //qDebug("cur i %d ",mProfileBox-> currentItem () ); | 174 | switch ( prof->getSyncPrefs() ) { |
299 | mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ; | 175 | case 0: |
300 | KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ; | 176 | loc->setChecked( true); |
301 | prof->setName( s ); | 177 | break; |
302 | mSyncProfileNames[mProfileBox-> currentItem ()] = s; | 178 | case 1: |
179 | rem->setChecked( true ); | ||
180 | break; | ||
181 | case 2: | ||
182 | newest->setChecked( true); | ||
183 | break; | ||
184 | case 3: | ||
185 | ask->setChecked( true); | ||
186 | break; | ||
187 | case 4: | ||
188 | f_loc->setChecked( true); | ||
189 | break; | ||
190 | case 5: | ||
191 | f_rem->setChecked( true); | ||
192 | break; | ||
193 | case 6: | ||
194 | //both->setChecked( true); | ||
195 | break; | ||
196 | default: | ||
197 | break; | ||
198 | } | ||
303 | } | 199 | } |
304 | void KOSyncPrefsDialog::profileChanged( int item ) | 200 | |
201 | void SyncPrefWidget_Conflict::saveSettings( KRES::Resource *res ) | ||
305 | { | 202 | { |
306 | //qDebug("KOSyncPrefsDialog::profileChanged %d ", item ); | 203 | KABC::Resource* resource = (KABC::Resource*)( res ); |
307 | KSyncProfile* prof; | 204 | KSyncProfile* prof = resource->getSyncProfile(); |
308 | saveProfile(); | 205 | |
309 | currentSelection = item; | 206 | if (prof == 0) |
310 | prof = mSyncProfiles.at(item) ; | 207 | { |
311 | mRemotePrecommand->setText(prof->getPreSyncCommand()); | 208 | qDebug("SyncPrefWidget_Conftlict::saveSettings: something is wrong, because resource does have no syncprofile" ); |
312 | mRemotePostcommand->setText(prof->getPostSyncCommand()); | 209 | return; |
313 | mLocalTempFile->setText(prof->getLocalTempFile()); | 210 | } |
314 | mRemoteFile->setText(prof->getRemoteFileName()) ; | 211 | |
315 | mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync()); | 212 | int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ; |
316 | mAskForPreferences->setChecked( prof->getAskForPreferences()); | 213 | prof->setSyncPrefs( syncprefs ); |
317 | mWriteBackExisting->setChecked( prof->getWriteBackExisting() ); | 214 | |
318 | mWriteBackFile->setChecked( prof->getWriteBackFile()); | 215 | } |
319 | mIncludeInRing->setChecked( prof->getIncludeInRingSync() ); | 216 | |
320 | 217 | ||
321 | switch ( prof->getSyncPrefs() ) { | 218 | /*********************************************************************** |
322 | case 0: | 219 | * |
323 | loc->setChecked( true); | 220 | * |
324 | break; | 221 | **********************************************************************/ |
325 | case 1: | 222 | |
326 | rem->setChecked( true ); | 223 | SyncPrefWidget_Remote::SyncPrefWidget_Remote(QWidget *parent, const char *name) : |
327 | break; | 224 | KRES::SyncWidget(parent, name) |
328 | case 2: | 225 | { |
329 | newest->setChecked( true); | 226 | init(); |
330 | break; | ||
331 | case 3: | ||
332 | ask->setChecked( true); | ||
333 | break; | ||
334 | case 4: | ||
335 | f_loc->setChecked( true); | ||
336 | break; | ||
337 | case 5: | ||
338 | f_rem->setChecked( true); | ||
339 | break; | ||
340 | case 6: | ||
341 | //both->setChecked( true); | ||
342 | break; | ||
343 | default: | ||
344 | break; | ||
345 | } | ||
346 | mIsLocal->setChecked(prof->getIsLocalFileSync()) ; | ||
347 | mIsNotLocal->setChecked(!prof->getIsLocalFileSync()); | ||
348 | proGr->setEnabled( item > 2 ); | ||
349 | if ( item < 3 ) { | ||
350 | localFileWidget->setEnabled(false); | ||
351 | remoteFileWidget->setEnabled(false); | ||
352 | |||
353 | } else | ||
354 | kindChanged( prof->getIsLocalFileSync() ); | ||
355 | } | 227 | } |
356 | 228 | ||
357 | void KOSyncPrefsDialog::fillSSH() | 229 | |
230 | SyncPrefWidget_Remote::~SyncPrefWidget_Remote() | ||
358 | { | 231 | { |
359 | mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" ); | ||
360 | mLocalTempFile->setText("/tmp/mycalendar.ics" ); | ||
361 | mRemotePostcommand->setText("scp /tmp/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics" ); | ||
362 | } | 232 | } |
363 | void KOSyncPrefsDialog::fillFTP() | 233 | |
234 | void SyncPrefWidget_Remote::init() | ||
364 | { | 235 | { |
365 | mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" ); | 236 | QLabel * lab; |
366 | mLocalTempFile->setText("/tmp/mycalendar.ics" ); | 237 | QPushButton* button; |
367 | mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" ); | 238 | |
239 | |||
240 | QGridLayout *topLayout = new QGridLayout( this, 6,2 ); | ||
241 | topLayout->setMargin( KDialog::marginHint() ); | ||
242 | topLayout->setSpacing( KDialog::spacingHint() ); | ||
243 | |||
244 | int iii = 0; | ||
245 | |||
246 | QButtonGroup* gr; | ||
247 | |||
248 | QButtonGroup *proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), this); | ||
249 | gr = proGr; | ||
250 | topLayout->addMultiCellWidget(gr, iii,iii,0,1); | ||
251 | ++iii; | ||
252 | mProfileKind = new QComboBox( gr ); | ||
253 | |||
254 | mProfileKind->insertItem( i18n("Local file"), Local ); | ||
255 | mProfileKind->insertItem( i18n("Remote file (w down/upload cmd)"),Remote ); | ||
256 | mProfileKind->insertItem( i18n("Mobile device (cell phone)"), Mobile ); | ||
257 | |||
258 | connect( mProfileKind, SIGNAL( activated( int ) ), | ||
259 | this, SLOT (kindChanged( int ) ) ); | ||
260 | |||
261 | |||
262 | QHBox* temphb; | ||
263 | |||
264 | remoteFileWidget = new QVBox( this); | ||
265 | topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1); | ||
266 | ++iii; | ||
267 | lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget); | ||
268 | mRemotePrecommand = new QLineEdit(remoteFileWidget); | ||
269 | |||
270 | lab = new QLabel( i18n("Local temp file (=Location):"), remoteFileWidget); | ||
271 | mLocalTempFile = new QLineEdit(remoteFileWidget); | ||
272 | mLocalTempFile->setEnabled(false); | ||
273 | |||
274 | |||
275 | lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget); | ||
276 | mRemotePostcommand = new QLineEdit(remoteFileWidget); | ||
277 | |||
278 | lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget); | ||
279 | temphb = new QHBox( remoteFileWidget ); | ||
280 | button = new QPushButton( i18n("ssh/scp"), temphb ); | ||
281 | connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) ); | ||
282 | button = new QPushButton( i18n("ftp"), temphb ); | ||
283 | connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) ); | ||
284 | lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget); | ||
368 | 285 | ||
369 | } | 286 | } |
370 | void KOSyncPrefsDialog::kindChanged( bool b ) | 287 | |
288 | void SyncPrefWidget_Remote::loadSettings( KRES::Resource *res ) | ||
371 | { | 289 | { |
290 | KABC::Resource* resource = (KABC::Resource*)( res ); | ||
291 | KSyncProfile* prof = resource->getSyncProfile(); | ||
292 | |||
293 | if (prof == 0) | ||
294 | { | ||
295 | qDebug("SyncPrefWidget_Remote::loadSettings: something is wrong, because resource does have no syncprofile" ); | ||
296 | return; | ||
297 | } | ||
372 | 298 | ||
373 | localFileWidget->setEnabled(b); | 299 | int val; |
374 | remoteFileWidget->setEnabled(!b); | ||
375 | 300 | ||
301 | if (prof->getIsPhoneSync()) | ||
302 | val = Mobile; | ||
303 | else if (!prof->getIsLocalFileSync()) | ||
304 | val = Remote; | ||
305 | else // default value | ||
306 | val = Local; | ||
307 | |||
308 | mProfileKind->setCurrentItem( val ); | ||
309 | kindChanged( val ); | ||
310 | |||
311 | |||
312 | mRemotePrecommand->setText(prof->getPreSyncCommand()); | ||
313 | mLocalTempFile->setText(resource->fileName()); | ||
314 | mRemotePostcommand->setText(prof->getPostSyncCommand()); | ||
376 | } | 315 | } |
377 | void KOSyncPrefsDialog::deleteProfile() | 316 | |
317 | void SyncPrefWidget_Remote::saveSettings( KRES::Resource *res ) | ||
378 | { | 318 | { |
379 | //qDebug("KOSyncPrefsDialog::deleteProfile() "); | 319 | KABC::Resource* resource = (KABC::Resource*)( res ); |
380 | if ( currentSelection >= 0 ) { | 320 | KSyncProfile* prof = resource->getSyncProfile(); |
381 | if ( currentSelection < 3 ) { | 321 | |
382 | KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error")); | 322 | if (prof == 0) |
383 | return; | 323 | { |
384 | } | 324 | qDebug("SyncPrefWidget_Remote::saveSettings: something is wrong, because resource does have no syncprofile" ); |
385 | KSyncProfile* temp = mSyncProfiles.at(currentSelection); | 325 | return; |
386 | mSyncProfiles.remove( temp ); | 326 | } |
387 | mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection )); | 327 | |
388 | insertProfiles(); | 328 | int val = mProfileKind->currentItem(); |
389 | } | 329 | |
330 | if (val == Mobile) | ||
331 | { | ||
332 | prof->setIsLocalFileSync(true); | ||
333 | prof->setIsPhoneSync(true); | ||
334 | } | ||
335 | else if (val == Remote) | ||
336 | { | ||
337 | prof->setIsLocalFileSync(false); | ||
338 | prof->setIsPhoneSync(false); | ||
339 | } | ||
340 | else // default value is Local | ||
341 | { | ||
342 | prof->setIsLocalFileSync(true); | ||
343 | prof->setIsPhoneSync(false); | ||
344 | } | ||
345 | |||
346 | |||
347 | prof->setPreSyncCommand( mRemotePrecommand->text()); | ||
348 | //US prof->setLocalTempFile( mLocalTempFile->text()); | ||
349 | prof->setPostSyncCommand( mRemotePostcommand->text() ); | ||
390 | } | 350 | } |
391 | 351 | ||
392 | void KOSyncPrefsDialog::saveProfile() | 352 | |
353 | void SyncPrefWidget_Remote::fillSSH() | ||
393 | { | 354 | { |
394 | KSyncProfile* prof; | 355 | QString location = mLocalTempFile->text(); |
395 | if ( currentSelection >= 0 ) { | ||
396 | prof = mSyncProfiles.at(currentSelection) ; | ||
397 | prof->setPreSyncCommand( mRemotePrecommand->text()); | ||
398 | prof->setPostSyncCommand( mRemotePostcommand->text() ); | ||
399 | prof->setLocalTempFile( mLocalTempFile->text()); | ||
400 | prof->setRemoteFileName( mRemoteFile->text() ); | ||
401 | prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() ); | ||
402 | prof->setAskForPreferences( mAskForPreferences->isChecked()); | ||
403 | prof->setWriteBackExisting(mWriteBackExisting->isChecked() ); | ||
404 | prof->setWriteBackFile( mWriteBackFile->isChecked()); | ||
405 | prof->setIncludeInRingSync( mIncludeInRing->isChecked() ); | ||
406 | int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ; | ||
407 | prof->setSyncPrefs( syncprefs); | ||
408 | prof->setIsLocalFileSync( mIsLocal->isChecked() ); | ||
409 | } | ||
410 | 356 | ||
357 | mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/"+location + " " + location ); | ||
358 | //US mLocalTempFile->setText("/tmp/mycalendar.ics" ); | ||
359 | mRemotePostcommand->setText("scp " + location + " zaurus@192.168.0.65:/home/zaurus/kdepim/"+location ); | ||
411 | } | 360 | } |
412 | 361 | ||
413 | void KOSyncPrefsDialog::insertProfiles() | 362 | void SyncPrefWidget_Remote::fillFTP() |
414 | { | 363 | { |
415 | int curItem = mProfileBox->currentItem(); | 364 | QString location = mLocalTempFile->text(); |
416 | mProfileBox->blockSignals( true ); | 365 | |
417 | mProfileBox->clear(); | 366 | mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/" + location ); |
418 | mProfileBox->insertStringList (mSyncProfileNames ); | 367 | //US mLocalTempFile->setText("/tmp/mycalendar.ics" ); |
419 | int item = mSyncProfileNames.count() -1; | 368 | mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/"+location+ " " + location); |
420 | if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() ) | 369 | |
421 | mProfileBox->setCurrentItem( curItem ); | ||
422 | else if ( item >= 0 ) { | ||
423 | mProfileBox->setCurrentItem( item ); | ||
424 | } | ||
425 | currentSelection = -1; | ||
426 | if ( mSyncProfileNames.count() > 0 ) { | ||
427 | //qDebug(" profileChanged( mProfileBox->currentItem() "); | ||
428 | profileChanged( mProfileBox->currentItem() ); | ||
429 | currentSelection = mProfileBox->currentItem(); | ||
430 | } | ||
431 | mProfileBox->blockSignals( false ); | ||
432 | } | 370 | } |
433 | 371 | ||
434 | void KOSyncPrefsDialog::addProfile ( KSyncProfile* temp ) | 372 | |
373 | void SyncPrefWidget_Remote::kindChanged( int newKind ) | ||
435 | { | 374 | { |
436 | saveProfile(); | 375 | |
437 | mSyncProfiles.append( temp ); | 376 | if (newKind == Mobile) |
438 | mSyncProfileNames << temp->getName(); | 377 | remoteFileWidget->setEnabled(false); |
439 | insertProfiles(); | 378 | else if (newKind == Remote) |
440 | int last = mProfileBox->count() -1; | 379 | remoteFileWidget->setEnabled(true); |
441 | mProfileBox->blockSignals( true ); | 380 | else // default value is local |
442 | mProfileBox->setCurrentItem( last ); | 381 | remoteFileWidget->setEnabled(false); |
443 | mProfileBox->blockSignals( false ); | 382 | |
444 | profileChanged(last); | ||
445 | } | 383 | } |
446 | void KOSyncPrefsDialog::newProfile() | 384 | |
385 | /*********************************************************************** | ||
386 | * | ||
387 | * | ||
388 | **********************************************************************/ | ||
389 | |||
390 | |||
391 | SyncPrefWidgetContainer::SyncPrefWidgetContainer() | ||
392 | : SyncWidgetContainer() | ||
447 | { | 393 | { |
448 | addProfile ( new KSyncProfile () ); | ||
449 | } | 394 | } |
450 | 395 | ||
451 | void KOSyncPrefsDialog::cloneProfile() | 396 | KRES::SyncWidget* SyncPrefWidgetContainer::generateSettingsTab(QWidget *parent = 0, const char *name = 0) |
452 | { | 397 | { |
453 | if ( currentSelection >= 0 ) | 398 | return new SyncPrefWidget_Settings(parent, name); |
454 | addProfile (mSyncProfiles.at(currentSelection)->clone()) ; | ||
455 | else | ||
456 | newProfile(); | ||
457 | } | 399 | } |
458 | 400 | ||
459 | 401 | KRES::SyncWidget* SyncPrefWidgetContainer::generateConflictsTab(QWidget *parent = 0, const char *name = 0) | |
460 | void KOSyncPrefsDialog::usrReadConfig() | ||
461 | { | 402 | { |
462 | KConfig *config = KOGlobals::config(); | 403 | return new SyncPrefWidget_Conflict(parent, name); |
463 | config->setGroup("SyncProfiles"); | ||
464 | mSyncProfileNames = KOPrefs::instance()->mSyncProfileNames; | ||
465 | int i; | ||
466 | KSyncProfile* temp ; | ||
467 | mSyncProfiles.clear(); | ||
468 | for ( i = 0; i < mSyncProfileNames.count();++i ) { | ||
469 | temp = new KSyncProfile (); | ||
470 | temp->setName( mSyncProfileNames[i] ); | ||
471 | temp->readConfig( config ); | ||
472 | mSyncProfiles.append( temp ); | ||
473 | } | ||
474 | insertProfiles(); | ||
475 | mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName ); | ||
476 | } | 404 | } |
477 | 405 | ||
478 | 406 | KRES::SyncWidget* SyncPrefWidgetContainer::generateRemoteTab(QWidget *parent = 0, const char *name = 0) | |
479 | void KOSyncPrefsDialog::usrWriteConfig() | ||
480 | { | 407 | { |
481 | saveProfile(); | 408 | return new SyncPrefWidget_Remote(parent, name); |
482 | if ( currentSelection >= 0 ) | ||
483 | profileChanged(currentSelection); | ||
484 | KConfig *config = KOGlobals::config(); | ||
485 | config->setGroup("SyncProfiles"); | ||
486 | KSyncProfile* prof = mSyncProfiles.first(); | ||
487 | while ( prof ) { | ||
488 | prof->writeConfig(config); | ||
489 | prof = mSyncProfiles.next(); | ||
490 | } | ||
491 | KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames; | ||
492 | KOPrefs::instance()->mLocalMachineName = mMyMachineName->text(); | ||
493 | config->writeEntry("SyncProfileNames",&mSyncProfileNames); | ||
494 | } | 409 | } |
495 | */ | 410 | |
diff --git a/kabc/syncprefwidget.h b/kabc/syncprefwidget.h index 3709d78..b20a68e 100644 --- a/kabc/syncprefwidget.h +++ b/kabc/syncprefwidget.h | |||
@@ -1,121 +1,139 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KABC/Pi. | 2 | This file is part of KABC/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program 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 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef _SYNCPREFWIDGET_H | 28 | #ifndef _SYNCPREFWIDGET_H |
29 | #define _SYNCPREFWIDGET_H | 29 | #define _SYNCPREFWIDGET_H |
30 | 30 | ||
31 | #include <kresources/syncwidget.h> | 31 | #include <kresources/syncwidget.h> |
32 | 32 | ||
33 | /*US | ||
34 | //#include <qframe.h> | ||
35 | //#include <qdict.h> | ||
36 | #include <qvbox.h> | ||
37 | #include <qhbox.h> | ||
38 | //#include <qcolor.h> | ||
39 | //#include <qlistview.h> | ||
40 | |||
41 | #include <kdialogbase.h> | ||
42 | |||
43 | #include <libkdepim/kprefsdialog.h> | ||
44 | */ | ||
45 | |||
46 | //US class KColorButton; | ||
47 | //US class QSpinBox;; | ||
48 | class QRadioButton; | 33 | class QRadioButton; |
49 | class QCheckBox; | 34 | class QCheckBox; |
50 | class QVBox; | 35 | class QVBox; |
51 | //US class QSlider; | 36 | class QComboBox; |
52 | //US class KURLRequester; | ||
53 | //US class QComboBox; | ||
54 | class QLineEdit; | 37 | class QLineEdit; |
55 | //US class QStringList; | 38 | class KRES::Resource; |
56 | //US class KSyncProfile; | ||
57 | 39 | ||
58 | 40 | class SyncPrefWidget_Settings : public KRES::SyncWidget | |
59 | /** Dialog to change the korganizer configuration. | ||
60 | */ | ||
61 | class SyncPrefWidget : public KRES::SyncWidget | ||
62 | { | 41 | { |
63 | Q_OBJECT | 42 | Q_OBJECT |
64 | public: | 43 | public: |
65 | SyncPrefWidget(QWidget *parent=0); | 44 | SyncPrefWidget_Settings(QWidget *parent=0, const char *name = 0 ); |
66 | ~SyncPrefWidget(); | 45 | ~SyncPrefWidget_Settings(); |
67 | //US void usrReadConfig(); | ||
68 | 46 | ||
69 | public slots: | 47 | public slots: |
70 | protected slots: | 48 | virtual void loadSettings( KRES::Resource *resource ); |
71 | //US void accept(); | 49 | virtual void saveSettings( KRES::Resource *resource ); |
72 | //US void deleteProfile(); | ||
73 | //US void newProfile(); | ||
74 | //US void cloneProfile(); | ||
75 | //US void kindChanged(bool); | ||
76 | //US void fillSSH(); | ||
77 | //US void fillFTP(); | ||
78 | //US void textChanged( const QString & ); | ||
79 | //US void profileChanged( int ); | ||
80 | //US void chooseFile(); | ||
81 | //US void slotOK(); | ||
82 | 50 | ||
83 | protected: | ||
84 | //US void usrWriteConfig(); | ||
85 | 51 | ||
52 | protected: | ||
86 | void init(); | 53 | void init(); |
87 | 54 | ||
88 | private: | 55 | private: |
56 | QCheckBox* mIncludeInRing; | ||
57 | QCheckBox* mWriteBackFile; | ||
58 | QCheckBox* mWriteBackExisting; | ||
59 | QCheckBox* mAskForPreferences; | ||
60 | QCheckBox* mShowSummaryAfterSync; | ||
61 | }; | ||
89 | 62 | ||
90 | 63 | ||
91 | //US int currentSelection; | ||
92 | //US QPtrList<KSyncProfile> mSyncProfiles; | ||
93 | //US QStringList mSyncProfileNames; | ||
94 | //US QLineEdit * mMyMachineName; | ||
95 | //US QComboBox * mProfileBox; | ||
96 | //US QRadioButton* mIsLocal; | ||
97 | QCheckBox* mIsNotLocal; | ||
98 | QCheckBox* mIncludeInRing; | ||
99 | //US void addProfile ( KSyncProfile* ); | ||
100 | //US void insertProfiles(); | ||
101 | //US void saveProfile(); | ||
102 | //US QButtonGroup* proGr; | ||
103 | 64 | ||
65 | class SyncPrefWidget_Conflict : public KRES::SyncWidget | ||
66 | { | ||
67 | Q_OBJECT | ||
68 | public: | ||
69 | SyncPrefWidget_Conflict(QWidget *parent=0, const char *name = 0 ); | ||
70 | ~SyncPrefWidget_Conflict(); | ||
71 | |||
72 | public slots: | ||
73 | virtual void loadSettings( KRES::Resource *resource ); | ||
74 | virtual void saveSettings( KRES::Resource *resource ); | ||
75 | |||
76 | protected: | ||
77 | void init(); | ||
78 | |||
79 | private: | ||
104 | QRadioButton* loc, *rem, *newest, *ask, *f_loc,* f_rem, *both; | 80 | QRadioButton* loc, *rem, *newest, *ask, *f_loc,* f_rem, *both; |
81 | }; | ||
82 | |||
83 | |||
84 | |||
105 | 85 | ||
86 | class SyncPrefWidget_Remote : public KRES::SyncWidget | ||
87 | { | ||
88 | Q_OBJECT | ||
89 | public: | ||
90 | SyncPrefWidget_Remote(QWidget *parent=0, const char *name = 0 ); | ||
91 | ~SyncPrefWidget_Remote(); | ||
92 | |||
93 | enum Types { | ||
94 | Local = 0, | ||
95 | Remote = 1, | ||
96 | Mobile =2 | ||
97 | }; | ||
106 | 98 | ||
99 | |||
100 | public slots: | ||
101 | virtual void loadSettings( KRES::Resource *resource ); | ||
102 | virtual void saveSettings( KRES::Resource *resource ); | ||
103 | |||
104 | protected slots: | ||
105 | void fillSSH(); | ||
106 | void fillFTP(); | ||
107 | void kindChanged( int newKind ); | ||
108 | |||
109 | protected: | ||
110 | void init(); | ||
111 | |||
112 | private: | ||
113 | QComboBox* mProfileKind; | ||
107 | QLineEdit * mRemotePostcommand; | 114 | QLineEdit * mRemotePostcommand; |
108 | QLineEdit * mRemotePrecommand; | 115 | QLineEdit * mRemotePrecommand; |
109 | QLineEdit * mRemoteFile; | 116 | QLineEdit * mRemoteFile; |
110 | QLineEdit * mLocalTempFile; | 117 | QLineEdit * mLocalTempFile; |
111 | //US QWidget* mSetupSyncAlgTab; | ||
112 | |||
113 | //US QVBox* localFileWidget; | ||
114 | QVBox* remoteFileWidget; | 118 | QVBox* remoteFileWidget; |
115 | QCheckBox* mWriteBackFile; | ||
116 | QCheckBox* mWriteBackExisting; | ||
117 | QCheckBox* mAskForPreferences; | ||
118 | QCheckBox* mShowSummaryAfterSync; | ||
119 | }; | 119 | }; |
120 | 120 | ||
121 | |||
122 | |||
123 | |||
124 | |||
125 | class SyncPrefWidgetContainer : public KRES::SyncWidgetContainer | ||
126 | { | ||
127 | Q_OBJECT | ||
128 | |||
129 | public: | ||
130 | SyncPrefWidgetContainer(); | ||
131 | |||
132 | virtual KRES::SyncWidget* generateSettingsTab(QWidget *parent, const char *name); | ||
133 | virtual KRES::SyncWidget* generateConflictsTab(QWidget *parent, const char *name); | ||
134 | virtual KRES::SyncWidget* generateRemoteTab(QWidget *parent, const char *name); | ||
135 | }; | ||
136 | |||
137 | |||
138 | |||
121 | #endif | 139 | #endif |