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