author | zautrix <zautrix> | 2004-09-21 07:09:09 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-21 07:09:09 (UTC) |
commit | 1cf4cc6e7bf25ee309852c7c97155de86917289f (patch) (unidiff) | |
tree | 721dd83559c3c7635d132b8a95cd6fdc4cdcc351 /kabc/plugins | |
parent | 434ddaa08e0a650422ef271332a1d11879028095 (diff) | |
download | kdepimpi-1cf4cc6e7bf25ee309852c7c97155de86917289f.zip kdepimpi-1cf4cc6e7bf25ee309852c7c97155de86917289f.tar.gz kdepimpi-1cf4cc6e7bf25ee309852c7c97155de86917289f.tar.bz2 |
qtopia format changes
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 135 |
1 files changed, 26 insertions, 109 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 1f90fcb..f9cabcb 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -1,405 +1,322 @@ | |||
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 | #include <libkdepim/ksyncprofile.h> | ||
56 | #include <qpe/quuid.h> | ||
57 | 55 | ||
58 | using namespace KABC; | 56 | using namespace KABC; |
59 | extern "C" | 57 | extern "C" |
60 | { | 58 | { |
61 | void *init_microkabc_qtopia() | 59 | void *init_microkabc_qtopia() |
62 | { | 60 | { |
63 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); | 61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); |
64 | } | 62 | } |
65 | } | 63 | } |
66 | 64 | ||
67 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) | 65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) |
68 | : Resource( config, syncable ), mConverter (0) | 66 | : Resource( config, syncable ), mConverter (0) |
69 | { | 67 | { |
70 | // 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 |
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
72 | init( fileName ); | 70 | init( fileName ); |
73 | } | 71 | } |
74 | 72 | ||
75 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) | 73 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) |
76 | : Resource( 0, syncable ) | 74 | : Resource( 0, syncable ) |
77 | { | 75 | { |
78 | init( fileName ); | 76 | init( fileName ); |
79 | } | 77 | } |
80 | 78 | ||
81 | void ResourceQtopia::init( const QString &fileName ) | 79 | void ResourceQtopia::init( const QString &fileName ) |
82 | { | 80 | { |
83 | 81 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 85 | ||
88 | setFileName( fileName ); | 86 | setFileName( fileName ); |
89 | } | 87 | } |
90 | 88 | ||
91 | ResourceQtopia::~ResourceQtopia() | 89 | ResourceQtopia::~ResourceQtopia() |
92 | { | 90 | { |
93 | if (mConverter != 0) | 91 | if (mConverter != 0) |
94 | delete mConverter; | 92 | delete mConverter; |
95 | 93 | ||
96 | if(mAccess != 0) | 94 | if(mAccess != 0) |
97 | delete mAccess; | 95 | delete mAccess; |
98 | } | 96 | } |
99 | 97 | ||
100 | void ResourceQtopia::writeConfig( KConfig *config ) | 98 | void ResourceQtopia::writeConfig( KConfig *config ) |
101 | { | 99 | { |
102 | Resource::writeConfig( config ); | 100 | Resource::writeConfig( config ); |
103 | } | 101 | } |
104 | 102 | ||
105 | Ticket *ResourceQtopia::requestSaveTicket() | 103 | Ticket *ResourceQtopia::requestSaveTicket() |
106 | { | 104 | { |
107 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 105 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; |
108 | 106 | ||
109 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); | 107 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); |
110 | 108 | ||
111 | if ( !addressBook() ) return 0; | 109 | if ( !addressBook() ) return 0; |
112 | 110 | ||
113 | if ( !lock( fileName() ) ) { | 111 | if ( !lock( fileName() ) ) { |
114 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
115 | << fileName() << "'" << endl; | 113 | << fileName() << "'" << endl; |
116 | return 0; | 114 | return 0; |
117 | } | 115 | } |
118 | return createTicket( this ); | 116 | return createTicket( this ); |
119 | } | 117 | } |
120 | 118 | ||
121 | 119 | ||
122 | bool ResourceQtopia::doOpen() | 120 | bool ResourceQtopia::doOpen() |
123 | { | 121 | { |
124 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); | 122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
125 | 123 | ||
126 | mAccess = new AddressBookAccess(); | 124 | mAccess = new AddressBookAccess(); |
127 | 125 | ||
128 | if ( !mAccess ) { | 126 | if ( !mAccess ) { |
129 | qDebug("Unable to load file() %s", fileName().latin1()); | 127 | qDebug("Unable to load file() %s", fileName().latin1()); |
130 | return false; | 128 | return false; |
131 | } | 129 | } |
132 | 130 | ||
133 | 131 | ||
134 | if (mConverter == 0) | 132 | if (mConverter == 0) |
135 | { | 133 | { |
136 | mConverter = new QtopiaConverter(); | 134 | mConverter = new QtopiaConverter(); |
137 | bool res = mConverter->init(); | 135 | bool res = mConverter->init(); |
138 | if ( !res ) | 136 | if ( !res ) |
139 | { | 137 | { |
140 | 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"); |
141 | qDebug(msg); | 139 | qDebug(msg); |
142 | delete mAccess; | 140 | delete mAccess; |
143 | mAccess = 0; | 141 | mAccess = 0; |
144 | return false; | 142 | return false; |
145 | } | 143 | } |
146 | } | 144 | } |
147 | 145 | ||
148 | return true; | 146 | return true; |
149 | } | 147 | } |
150 | 148 | ||
151 | void ResourceQtopia::doClose() | 149 | void ResourceQtopia::doClose() |
152 | { | 150 | { |
153 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | 151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); |
154 | 152 | ||
155 | if(mAccess) | 153 | if(mAccess) |
156 | { | 154 | { |
157 | delete mAccess; | 155 | delete mAccess; |
158 | mAccess = 0; | 156 | mAccess = 0; |
159 | } | 157 | } |
160 | // it seems so, that deletion of access deletes backend as well | 158 | // it seems so, that deletion of access deletes backend as well |
161 | //delete backend; | 159 | //delete backend; |
162 | 160 | ||
163 | return; | 161 | return; |
164 | } | 162 | } |
165 | 163 | ||
166 | bool ResourceQtopia::load() | 164 | bool ResourceQtopia::load() |
167 | { | 165 | { |
168 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | 166 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); |
169 | 167 | ||
170 | AddressBookIterator it(*mAccess); | 168 | AddressBookIterator it(*mAccess); |
171 | const PimContact* contact; | 169 | const PimContact* contact; |
172 | bool res; | 170 | bool res; |
173 | 171 | ||
174 | for (contact=it.toFirst(); it.current(); ++it) | 172 | for (contact=it.toFirst(); it.current(); ++it) |
175 | { | 173 | { |
176 | contact = it.current(); | 174 | contact = it.current(); |
177 | 175 | ||
178 | KABC::Addressee addressee; | 176 | KABC::Addressee addressee; |
179 | 177 | ||
180 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 178 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); |
181 | 179 | ||
182 | if ( !addressee.isEmpty() && res ) | 180 | if ( !addressee.isEmpty() && res ) |
183 | { | 181 | { |
184 | addressee.setResource( this ); | 182 | addressee.setResource( this ); |
185 | addressBook()->insertAddressee( addressee ); | 183 | addressBook()->insertAddressee( addressee ); |
186 | } | 184 | } |
187 | } | 185 | } |
188 | 186 | ||
189 | return true; | 187 | return true; |
190 | } | 188 | } |
191 | 189 | ||
192 | bool ResourceQtopia::save( Ticket *ticket ) | 190 | bool ResourceQtopia::save( Ticket *ticket ) |
193 | { | 191 | { |
194 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); | 192 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); |
195 | |||
196 | mDirWatch.stopScan(); | ||
197 | |||
198 | KABC::AddressBook::Iterator it; | ||
199 | bool res; | ||
200 | KABC::Addressee::List changedAddressees; | ||
201 | QStringList addedUID; | ||
202 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | ||
203 | //KABC::Addressee addressee = (*it); | ||
204 | // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() ); | ||
205 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | ||
206 | QUuid uid( (*it).originalExternalUID() ); | ||
207 | bool ok; | ||
208 | PimContact c = mAccess->contactForId( uid, &ok ); | ||
209 | qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() ); | ||
210 | res = mConverter->addresseeToQtopia( *it, c ); | ||
211 | if (res == true) { | ||
212 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | ||
213 | qDebug("skipping adding of contact "); | ||
214 | continue; | ||
215 | PimContact e; | ||
216 | AddressBookAccess Access2; | ||
217 | Access2.addContact(e); | ||
218 | const PimContact* contact; | ||
219 | bool res; | ||
220 | QString uid2, Ouid; | ||
221 | AddressBookIterator itt(Access2); | ||
222 | for (contact=itt.toFirst(); itt.current(); ++itt) | ||
223 | { | ||
224 | contact = itt.current(); | ||
225 | QString exuid = contact->uid().toString(); | ||
226 | Ouid =exuid; | ||
227 | int ente = exuid.find( "-0000"); | ||
228 | if ( exuid.left(1) == "{" ) | ||
229 | exuid = exuid.mid(1); | ||
230 | if ( ente > -1 ) | ||
231 | exuid = exuid.left( ente-1 ); | ||
232 | uid2 = exuid; | ||
233 | qDebug("trying find uid "); | ||
234 | if ( !addressBook()->containsExternalUid( uid2 ) ) { | ||
235 | qDebug("ab not contains "); | ||
236 | if ( !addedUID.contains( uid2 )) { | ||
237 | qDebug("list not contains "); | ||
238 | break; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | } | ||
243 | if ( !itt.current()) { | ||
244 | qDebug("ERROR uid "); | ||
245 | continue; | ||
246 | } | ||
247 | else | ||
248 | qDebug("ADD uid detected "); | ||
249 | |||
250 | |||
251 | QUuid uid3( Ouid); | ||
252 | PimContact d = Access2.contactForId( uid3, &ok ); | ||
253 | if ( ! ok ) { | ||
254 | qDebug("ADD: Error getting new uid "); | ||
255 | } else { | ||
256 | qDebug("NEW UID found "); | ||
257 | PimContact g = mAccess->contactForId( c.uid(), &ok ); | ||
258 | KABC::Addressee addressee; | ||
259 | mConverter->qtopiaToAddressee( g, addressee ); | ||
260 | addressee.setUid((*it).uid() ); | ||
261 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
262 | changedAddressees.append( addressee ); | ||
263 | addedUID.append( uid2 ); | ||
264 | } | ||
265 | |||
266 | |||
267 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | ||
268 | qDebug("Remove contact "); | ||
269 | if ( ok ) | ||
270 | mAccess->removeContact(c); | ||
271 | else | ||
272 | qDebug("Error remove contact from qtopia "); | ||
273 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | ||
274 | if ( ok ) { | ||
275 | qDebug("Update contact "); | ||
276 | mAccess->updateContact(c); | ||
277 | PimContact g = mAccess->contactForId( c.uid(), &ok ); | ||
278 | KABC::Addressee addressee; | ||
279 | mConverter->qtopiaToAddressee( g, addressee ); | ||
280 | addressee.setUid((*it).uid() ); | ||
281 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | ||
282 | changedAddressees.append( addressee ); | ||
283 | } | ||
284 | else | ||
285 | qDebug("Error update contact from qtopia "); | ||
286 | |||
287 | } | ||
288 | |||
289 | } else { | ||
290 | qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | 193 | ||
295 | KABC::Addressee::List::Iterator it2; | 194 | mDirWatch.stopScan(); |
296 | for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) | ||
297 | addressBook()->insertAddressee((*it2)); | ||
298 | 195 | ||
196 | KABC::AddressBook::Iterator it; | ||
197 | bool res; | ||
299 | 198 | ||
199 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | ||
200 | PimContact c; | ||
201 | KABC::Addressee addressee = (*it); | ||
300 | 202 | ||
301 | mDirWatch.startScan(); | 203 | res = mConverter->addresseeToQtopia( *it, c ); |
204 | if (res == true) | ||
205 | { | ||
206 | mAccess->addContact(c); | ||
207 | // if (res == false) | ||
208 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
213 | } | ||
214 | } | ||
302 | 215 | ||
303 | delete ticket; | 216 | // mAccess->addressBookUpdated(); |
304 | unlock( fileName() ); | ||
305 | 217 | ||
306 | return true; | 218 | mDirWatch.startScan(); |
219 | |||
220 | delete ticket; | ||
221 | unlock( fileName() ); | ||
222 | |||
223 | return true; | ||
307 | } | 224 | } |
308 | 225 | ||
309 | bool ResourceQtopia::lock( const QString &lockfileName ) | 226 | bool ResourceQtopia::lock( const QString &lockfileName ) |
310 | { | 227 | { |
311 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); | 228 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
312 | 229 | ||
313 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | 230 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; |
314 | 231 | ||
315 | QString fn = lockfileName; | 232 | QString fn = lockfileName; |
316 | 233 | ||
317 | KURL url(fn); | 234 | KURL url(fn); |
318 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 235 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
319 | 236 | ||
320 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 237 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
321 | 238 | ||
322 | if (QFile::exists( lockName )) | 239 | if (QFile::exists( lockName )) |
323 | { | 240 | { |
324 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); | 241 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); |
325 | return false; | 242 | return false; |
326 | } | 243 | } |
327 | 244 | ||
328 | QString lockUniqueName; | 245 | QString lockUniqueName; |
329 | lockUniqueName = fn + KApplication::randomString( 8 ); | 246 | lockUniqueName = fn + KApplication::randomString( 8 ); |
330 | 247 | ||
331 | url = lockUniqueName; | 248 | url = lockUniqueName; |
332 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 249 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
333 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 250 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
334 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 251 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
335 | 252 | ||
336 | // Create unique file | 253 | // Create unique file |
337 | QFile file( mLockUniqueName ); | 254 | QFile file( mLockUniqueName ); |
338 | file.open( IO_WriteOnly ); | 255 | file.open( IO_WriteOnly ); |
339 | file.close(); | 256 | file.close(); |
340 | 257 | ||
341 | // Create lock file | 258 | // Create lock file |
342 | int result = 0; | 259 | int result = 0; |
343 | #ifndef _WIN32_ | 260 | #ifndef _WIN32_ |
344 | result = ::link( QFile::encodeName( mLockUniqueName ), | 261 | result = ::link( QFile::encodeName( mLockUniqueName ), |
345 | QFile::encodeName( lockName ) ); | 262 | QFile::encodeName( lockName ) ); |
346 | #endif | 263 | #endif |
347 | if ( result == 0 ) { | 264 | if ( result == 0 ) { |
348 | addressBook()->emitAddressBookLocked(); | 265 | addressBook()->emitAddressBookLocked(); |
349 | return true; | 266 | return true; |
350 | } | 267 | } |
351 | 268 | ||
352 | // TODO: check stat | 269 | // TODO: check stat |
353 | 270 | ||
354 | return false; | 271 | return false; |
355 | } | 272 | } |
356 | 273 | ||
357 | void ResourceQtopia::unlock( const QString &fileName ) | 274 | void ResourceQtopia::unlock( const QString &fileName ) |
358 | { | 275 | { |
359 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | 276 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); |
360 | 277 | ||
361 | QString fn = fileName; | 278 | QString fn = fileName; |
362 | KURL url(fn); | 279 | KURL url(fn); |
363 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 280 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
364 | 281 | ||
365 | QFile::remove( lockName ); | 282 | QFile::remove( lockName ); |
366 | QFile::remove( mLockUniqueName ); | 283 | QFile::remove( mLockUniqueName ); |
367 | addressBook()->emitAddressBookUnlocked(); | 284 | addressBook()->emitAddressBookUnlocked(); |
368 | } | 285 | } |
369 | 286 | ||
370 | void ResourceQtopia::setFileName( const QString &newFileName ) | 287 | void ResourceQtopia::setFileName( const QString &newFileName ) |
371 | { | 288 | { |
372 | mDirWatch.stopScan(); | 289 | mDirWatch.stopScan(); |
373 | mDirWatch.removeFile( fileName() ); | 290 | mDirWatch.removeFile( fileName() ); |
374 | 291 | ||
375 | Resource::setFileName( newFileName ); | 292 | Resource::setFileName( newFileName ); |
376 | 293 | ||
377 | mDirWatch.addFile( fileName() ); | 294 | mDirWatch.addFile( fileName() ); |
378 | mDirWatch.startScan(); | 295 | mDirWatch.startScan(); |
379 | } | 296 | } |
380 | 297 | ||
381 | 298 | ||
382 | void ResourceQtopia::fileChanged() | 299 | void ResourceQtopia::fileChanged() |
383 | { | 300 | { |
384 | // There is a small theoretical chance that KDirWatch calls us before | 301 | // There is a small theoretical chance that KDirWatch calls us before |
385 | // we are fully constructed | 302 | // we are fully constructed |
386 | if (!addressBook()) | 303 | if (!addressBook()) |
387 | return; | 304 | return; |
388 | 305 | ||
389 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 306 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 307 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
391 | load(); | 308 | load(); |
392 | addressBook()->emitAddressBookChanged(); | 309 | addressBook()->emitAddressBookChanged(); |
393 | } | 310 | } |
394 | } | 311 | } |
395 | 312 | ||
396 | void ResourceQtopia::removeAddressee( const Addressee &addr ) | 313 | void ResourceQtopia::removeAddressee( const Addressee &addr ) |
397 | { | 314 | { |
398 | } | 315 | } |
399 | 316 | ||
400 | void ResourceQtopia::cleanUp() | 317 | void ResourceQtopia::cleanUp() |
401 | { | 318 | { |
402 | unlock( fileName() ); | 319 | unlock( fileName() ); |
403 | } | 320 | } |
404 | 321 | ||
405 | //US #include "resourceqtopia.moc" | 322 | //US #include "resourceqtopia.moc" |