author | zautrix <zautrix> | 2004-07-03 21:47:33 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-03 21:47:33 (UTC) |
commit | 5e59162e6eb6603610d1ca4c96d5d97acae0f60b (patch) (unidiff) | |
tree | c891d1e2125cf6f68509332fe06c878709525480 /kabc | |
parent | 54e76d203297aa5da51342492d482187f4d6cd20 (diff) | |
download | kdepimpi-5e59162e6eb6603610d1ca4c96d5d97acae0f60b.zip kdepimpi-5e59162e6eb6603610d1ca4c96d5d97acae0f60b.tar.gz kdepimpi-5e59162e6eb6603610d1ca4c96d5d97acae0f60b.tar.bz2 |
Fixed crash when accessing opie resource
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index a4f8d8a..3b2a6b7 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -1,399 +1,400 @@ | |||
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 | #include <qtimer.h> | 36 | #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 | 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 "resource.h" | 51 | #include "resource.h" |
52 | #include "resourceopieconfig.h" | 52 | #include "resourceopieconfig.h" |
53 | #include "stdaddressbook.h" | 53 | #include "stdaddressbook.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>(); | 64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | ResourceOpie::ResourceOpie( const KConfig *config ) | 68 | ResourceOpie::ResourceOpie( const KConfig *config ) |
69 | : Resource( config ), mConverter (0) | 69 | : Resource( config ), 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 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | 79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); |
80 | 80 | ||
81 | init( fileName ); | 81 | init( fileName ); |
82 | } | 82 | } |
83 | 83 | ||
84 | ResourceOpie::ResourceOpie( const QString &fileName ) | 84 | ResourceOpie::ResourceOpie( const QString &fileName ) |
85 | : Resource( 0 ) | 85 | : Resource( 0 ) |
86 | { | 86 | { |
87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | 87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); |
88 | init( fileName ); | 88 | init( fileName ); |
89 | } | 89 | } |
90 | 90 | ||
91 | void ResourceOpie::init( const QString &fileName ) | 91 | void ResourceOpie::init( const QString &fileName ) |
92 | { | 92 | { |
93 | 93 | ||
94 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | 94 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods |
95 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 95 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
96 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 96 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
97 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 97 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
98 | */ | 98 | */ |
99 | //US opie addressbook is always readonly | 99 | //US opie addressbook is always readonly |
100 | setReadOnly( true ); | 100 | setReadOnly( true ); |
101 | 101 | ||
102 | setFileName( fileName ); | 102 | setFileName( fileName ); |
103 | 103 | ||
104 | } | 104 | } |
105 | 105 | ||
106 | ResourceOpie::~ResourceOpie() | 106 | ResourceOpie::~ResourceOpie() |
107 | { | 107 | { |
108 | if (mConverter != 0) | 108 | if (mConverter != 0) |
109 | delete mConverter; | 109 | delete mConverter; |
110 | } | 110 | } |
111 | 111 | ||
112 | void ResourceOpie::writeConfig( KConfig *config ) | 112 | void ResourceOpie::writeConfig( KConfig *config ) |
113 | { | 113 | { |
114 | //US opie addressbook is always readonly | 114 | //US opie addressbook is always readonly |
115 | setReadOnly( true ); | 115 | setReadOnly( true ); |
116 | 116 | ||
117 | Resource::writeConfig( config ); | 117 | Resource::writeConfig( config ); |
118 | 118 | ||
119 | config->writeEntry( "FileName", mFileName ); | 119 | config->writeEntry( "FileName", mFileName ); |
120 | 120 | ||
121 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 121 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | Ticket *ResourceOpie::requestSaveTicket() | 125 | Ticket *ResourceOpie::requestSaveTicket() |
126 | { | 126 | { |
127 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 127 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
128 | 128 | ||
129 | if ( !addressBook() ) return 0; | 129 | if ( !addressBook() ) return 0; |
130 | 130 | ||
131 | if ( !lock( mFileName ) ) { | 131 | if ( !lock( mFileName ) ) { |
132 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | 132 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" |
133 | << mFileName << "'" << endl; | 133 | << mFileName << "'" << endl; |
134 | return 0; | 134 | return 0; |
135 | } | 135 | } |
136 | return createTicket( this ); | 136 | return createTicket( this ); |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | bool ResourceOpie::doOpen() | 140 | bool ResourceOpie::doOpen() |
141 | { | 141 | { |
142 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); | 142 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); |
143 | /*US | 143 | /*US |
144 | QFile file( mFileName ); | 144 | QFile file( mFileName ); |
145 | 145 | ||
146 | if ( !file.exists() ) { | 146 | if ( !file.exists() ) { |
147 | // try to create the file | 147 | // try to create the file |
148 | bool ok = file.open( IO_WriteOnly ); | 148 | bool ok = file.open( IO_WriteOnly ); |
149 | if ( ok ) | 149 | if ( ok ) |
150 | file.close(); | 150 | file.close(); |
151 | 151 | ||
152 | return ok; | 152 | return ok; |
153 | } else { | 153 | } else { |
154 | if ( !file.open( IO_ReadWrite ) ) | 154 | if ( !file.open( IO_ReadWrite ) ) |
155 | return false; | 155 | return false; |
156 | 156 | ||
157 | if ( file.size() == 0 ) { | 157 | if ( file.size() == 0 ) { |
158 | file.close(); | 158 | file.close(); |
159 | return true; | 159 | return true; |
160 | } | 160 | } |
161 | 161 | ||
162 | //US bool ok = mFormat->checkFormat( &file ); | 162 | //US bool ok = mFormat->checkFormat( &file ); |
163 | bool ok = true; | 163 | bool ok = true; |
164 | 164 | ||
165 | file.close(); | 165 | file.close(); |
166 | 166 | ||
167 | return ok; | 167 | return ok; |
168 | } | 168 | } |
169 | */ | 169 | */ |
170 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); | 170 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); |
171 | return true; | 171 | return true; |
172 | } | 172 | } |
173 | 173 | ||
174 | void ResourceOpie::doClose() | 174 | void ResourceOpie::doClose() |
175 | { | 175 | { |
176 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); | 176 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); |
177 | } | 177 | } |
178 | 178 | ||
179 | bool ResourceOpie::load() | 179 | bool ResourceOpie::load() |
180 | { | 180 | { |
181 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); | 181 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); |
182 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; | 182 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; |
183 | 183 | ||
184 | qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); | 184 | qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); |
185 | 185 | ||
186 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); | 186 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); |
187 | OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); | 187 | OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); |
188 | 188 | ||
189 | if ( !access ) { | 189 | if ( !access ) { |
190 | qDebug("Unable to load file() %s", mFileName.latin1()); | 190 | qDebug("Unable to load file() %s", mFileName.latin1()); |
191 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | 191 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); |
192 | return false; | 192 | return false; |
193 | } | 193 | } |
194 | 194 | ||
195 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | 195 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available |
196 | 196 | ||
197 | if (mConverter == 0) | 197 | if (mConverter == 0) |
198 | mConverter = new OpieConverter(); | 198 | mConverter = new OpieConverter(); |
199 | 199 | ||
200 | 200 | ||
201 | OContactAccess::List::Iterator it; | 201 | OContactAccess::List::Iterator it; |
202 | OContactAccess::List allList = access->allRecords(); | 202 | OContactAccess::List allList = access->allRecords(); |
203 | bool res = false; | 203 | bool res = false; |
204 | for ( it = allList.begin(); it != allList.end(); ++it ) | 204 | for ( it = allList.begin(); it != allList.end(); ++it ) |
205 | { | 205 | { |
206 | OContact c = (*it); | 206 | OContact c = (*it); |
207 | 207 | ||
208 | KABC::Addressee addressee; | 208 | KABC::Addressee addressee; |
209 | 209 | ||
210 | res = mConverter->opieToAddressee( c, addressee ); | 210 | res = mConverter->opieToAddressee( c, addressee ); |
211 | 211 | ||
212 | if ( !addressee.isEmpty() && res ) | 212 | if ( !addressee.isEmpty() && res ) |
213 | { | 213 | { |
214 | addressee.setResource( this ); | 214 | addressee.setResource( this ); |
215 | addressBook()->insertAddressee( addressee ); | 215 | addressBook()->insertAddressee( addressee ); |
216 | } | 216 | } |
217 | 217 | ||
218 | // qDebug("found %s", c.fullName().latin1()); | 218 | // qDebug("found %s", c.fullName().latin1()); |
219 | } | 219 | } |
220 | 220 | ||
221 | delete access; | 221 | delete access; |
222 | delete backend; | 222 | // it seems so, that deletion of access deletes backend as well |
223 | //delete backend; | ||
223 | 224 | ||
224 | return true; | 225 | return true; |
225 | } | 226 | } |
226 | 227 | ||
227 | bool ResourceOpie::save( Ticket *ticket ) | 228 | bool ResourceOpie::save( Ticket *ticket ) |
228 | { | 229 | { |
229 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); | 230 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); |
230 | /*US | 231 | /*US |
231 | 232 | ||
232 | qDebug("ResourceOpie::save %s", mFileName.latin1()); | 233 | qDebug("ResourceOpie::save %s", mFileName.latin1()); |
233 | kdDebug(5700) << "ResourceOpie::save()" << endl; | 234 | kdDebug(5700) << "ResourceOpie::save()" << endl; |
234 | 235 | ||
235 | // create backup file | 236 | // create backup file |
236 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 237 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
237 | */ | 238 | */ |
238 | /*US we use a simpler method to create a backupfile | 239 | /*US we use a simpler method to create a backupfile |
239 | 240 | ||
240 | (void) KSaveFile::backupFile( mFileName, QString::null | 241 | (void) KSaveFile::backupFile( mFileName, QString::null |
241 | ,extension ); | 242 | ,extension ); |
242 | 243 | ||
243 | KSaveFile saveFile( mFileName ); | 244 | KSaveFile saveFile( mFileName ); |
244 | bool ok = false; | 245 | bool ok = false; |
245 | if ( saveFile.status() == 0 && saveFile.file() ) | 246 | if ( saveFile.status() == 0 && saveFile.file() ) |
246 | { | 247 | { |
247 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 248 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
248 | ok = saveFile.close(); | 249 | ok = saveFile.close(); |
249 | } | 250 | } |
250 | */ | 251 | */ |
251 | /*US | 252 | /*US |
252 | //US ToDo: write backupfile | 253 | //US ToDo: write backupfile |
253 | QFile info; | 254 | QFile info; |
254 | info.setName( mFileName ); | 255 | info.setName( mFileName ); |
255 | bool ok = info.open( IO_WriteOnly ); | 256 | bool ok = info.open( IO_WriteOnly ); |
256 | if ( ok ) { | 257 | if ( ok ) { |
257 | //US mFormat->saveAll( addressBook(), this, &info ); | 258 | //US mFormat->saveAll( addressBook(), this, &info ); |
258 | 259 | ||
259 | info.close(); | 260 | info.close(); |
260 | ok = true; | 261 | ok = true; |
261 | } | 262 | } |
262 | else { | 263 | else { |
263 | 264 | ||
264 | } | 265 | } |
265 | 266 | ||
266 | if ( !ok ) | 267 | if ( !ok ) |
267 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 268 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
268 | 269 | ||
269 | delete ticket; | 270 | delete ticket; |
270 | unlock( mFileName ); | 271 | unlock( mFileName ); |
271 | 272 | ||
272 | return ok; | 273 | return ok; |
273 | 274 | ||
274 | qDebug("ResourceOpie::save has to be changed"); | 275 | qDebug("ResourceOpie::save has to be changed"); |
275 | */ | 276 | */ |
276 | return true; | 277 | return true; |
277 | 278 | ||
278 | } | 279 | } |
279 | 280 | ||
280 | bool ResourceOpie::lock( const QString &fileName ) | 281 | bool ResourceOpie::lock( const QString &fileName ) |
281 | { | 282 | { |
282 | qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); | 283 | qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); |
283 | 284 | ||
284 | /*US | 285 | /*US |
285 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); | 286 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); |
286 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | 287 | kdDebug(5700) << "ResourceOpie::lock()" << endl; |
287 | 288 | ||
288 | QString fn = fileName; | 289 | QString fn = fileName; |
289 | 290 | ||
290 | //US change the implementation how the lockfilename is getting created | 291 | //US change the implementation how the lockfilename is getting created |
291 | //US fn.replace( QRegExp("/"), "_" ); | 292 | //US fn.replace( QRegExp("/"), "_" ); |
292 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 293 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
293 | 294 | ||
294 | KURL url(fn); | 295 | KURL url(fn); |
295 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 296 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
296 | 297 | ||
297 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 298 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
298 | 299 | ||
299 | if (QFile::exists( lockName )) return false; | 300 | if (QFile::exists( lockName )) return false; |
300 | 301 | ||
301 | QString lockUniqueName; | 302 | QString lockUniqueName; |
302 | lockUniqueName = fn + KApplication::randomString( 8 ); | 303 | lockUniqueName = fn + KApplication::randomString( 8 ); |
303 | 304 | ||
304 | url = lockUniqueName; | 305 | url = lockUniqueName; |
305 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 306 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
306 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 307 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
307 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 308 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
308 | 309 | ||
309 | // Create unique file | 310 | // Create unique file |
310 | QFile file( mLockUniqueName ); | 311 | QFile file( mLockUniqueName ); |
311 | file.open( IO_WriteOnly ); | 312 | file.open( IO_WriteOnly ); |
312 | file.close(); | 313 | file.close(); |
313 | 314 | ||
314 | // Create lock file | 315 | // Create lock file |
315 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 316 | int result = ::link( QFile::encodeName( mLockUniqueName ), |
316 | QFile::encodeName( lockName ) ); | 317 | QFile::encodeName( lockName ) ); |
317 | 318 | ||
318 | if ( result == 0 ) { | 319 | if ( result == 0 ) { |
319 | addressBook()->emitAddressBookLocked(); | 320 | addressBook()->emitAddressBookLocked(); |
320 | return true; | 321 | return true; |
321 | } | 322 | } |
322 | 323 | ||
323 | // TODO: check stat | 324 | // TODO: check stat |
324 | 325 | ||
325 | return false; | 326 | return false; |
326 | */ | 327 | */ |
327 | 328 | ||
328 | return true; | 329 | return true; |
329 | } | 330 | } |
330 | 331 | ||
331 | void ResourceOpie::unlock( const QString &fileName ) | 332 | void ResourceOpie::unlock( const QString &fileName ) |
332 | { | 333 | { |
333 | qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1()); | 334 | qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1()); |
334 | /*US | 335 | /*US |
335 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | 336 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); |
336 | 337 | ||
337 | QString fn = fileName; | 338 | QString fn = fileName; |
338 | //US change the implementation how the lockfilename is getting created | 339 | //US change the implementation how the lockfilename is getting created |
339 | //US fn.replace( QRegExp( "/" ), "_" ); | 340 | //US fn.replace( QRegExp( "/" ), "_" ); |
340 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 341 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
341 | //US QString lockName = fn + ".lock"; | 342 | //US QString lockName = fn + ".lock"; |
342 | KURL url(fn); | 343 | KURL url(fn); |
343 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 344 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
344 | 345 | ||
345 | QFile::remove( lockName ); | 346 | QFile::remove( lockName ); |
346 | QFile::remove( mLockUniqueName ); | 347 | QFile::remove( mLockUniqueName ); |
347 | addressBook()->emitAddressBookUnlocked(); | 348 | addressBook()->emitAddressBookUnlocked(); |
348 | */ | 349 | */ |
349 | } | 350 | } |
350 | 351 | ||
351 | void ResourceOpie::setFileName( const QString &fileName ) | 352 | void ResourceOpie::setFileName( const QString &fileName ) |
352 | { | 353 | { |
353 | /*US ToDo: no synchronization so far. Has to be changed in the future | 354 | /*US ToDo: no synchronization so far. Has to be changed in the future |
354 | mDirWatch.stopScan(); | 355 | mDirWatch.stopScan(); |
355 | mDirWatch.removeFile( mFileName ); | 356 | mDirWatch.removeFile( mFileName ); |
356 | */ | 357 | */ |
357 | mFileName = fileName; | 358 | mFileName = fileName; |
358 | 359 | ||
359 | 360 | ||
360 | /*US ToDo: no synchronization so far. Has to be changed in the future | 361 | /*US ToDo: no synchronization so far. Has to be changed in the future |
361 | mDirWatch.addFile( mFileName ); | 362 | mDirWatch.addFile( mFileName ); |
362 | mDirWatch.startScan(); | 363 | mDirWatch.startScan(); |
363 | */ | 364 | */ |
364 | //US simulate KDirWatch event | 365 | //US simulate KDirWatch event |
365 | fileChanged(); | 366 | fileChanged(); |
366 | } | 367 | } |
367 | 368 | ||
368 | QString ResourceOpie::fileName() const | 369 | QString ResourceOpie::fileName() const |
369 | { | 370 | { |
370 | return mFileName; | 371 | return mFileName; |
371 | } | 372 | } |
372 | 373 | ||
373 | void ResourceOpie::fileChanged() | 374 | void ResourceOpie::fileChanged() |
374 | { | 375 | { |
375 | // There is a small theoretical chance that KDirWatch calls us before | 376 | // There is a small theoretical chance that KDirWatch calls us before |
376 | // we are fully constructed | 377 | // we are fully constructed |
377 | if (!addressBook()) | 378 | if (!addressBook()) |
378 | return; | 379 | return; |
379 | load(); | 380 | load(); |
380 | addressBook()->emitAddressBookChanged(); | 381 | addressBook()->emitAddressBookChanged(); |
381 | } | 382 | } |
382 | 383 | ||
383 | void ResourceOpie::removeAddressee( const Addressee &addr ) | 384 | void ResourceOpie::removeAddressee( const Addressee &addr ) |
384 | { | 385 | { |
385 | /*US | 386 | /*US |
386 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 387 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
387 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 388 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
388 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 389 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
389 | */ | 390 | */ |
390 | } | 391 | } |
391 | 392 | ||
392 | void ResourceOpie::cleanUp() | 393 | void ResourceOpie::cleanUp() |
393 | { | 394 | { |
394 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); | 395 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); |
395 | 396 | ||
396 | unlock( mFileName ); | 397 | unlock( mFileName ); |
397 | } | 398 | } |
398 | 399 | ||
399 | //US #include "resourceopie.moc" | 400 | //US #include "resourceopie.moc" |