-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 17 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.h | 3 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 20 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.h | 3 | ||||
-rw-r--r-- | microkde/kresources/configpage.cpp | 14 |
5 files changed, 35 insertions, 22 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index 7d96cb7..e58e4f7 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -11,349 +11,354 @@ | |||
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 | #define NO_DIRWATCH | ||
59 | #include "resourcedir.h" | 60 | #include "resourcedir.h" |
60 | #include "syncprefwidget.h" | 61 | #include "syncprefwidget.h" |
61 | 62 | ||
62 | //#define ALLOW_LOCKING | 63 | //#define ALLOW_LOCKING |
63 | 64 | ||
64 | using namespace KABC; | 65 | using namespace KABC; |
65 | 66 | ||
66 | extern "C" | 67 | extern "C" |
67 | #ifdef _WIN32_ | 68 | #ifdef _WIN32_ |
68 | __declspec(dllexport) | 69 | __declspec(dllexport) |
69 | #else | 70 | #else |
70 | { | 71 | { |
71 | #endif | 72 | #endif |
72 | 73 | ||
73 | //US void *init_kabc_dir() | 74 | //US void *init_kabc_dir() |
74 | void *init_microkabc_dir() | 75 | void *init_microkabc_dir() |
75 | { | 76 | { |
76 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>(); | 77 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>(); |
77 | } | 78 | } |
78 | #ifndef _WIN32_ | 79 | #ifndef _WIN32_ |
79 | } | 80 | } |
80 | #endif | 81 | #endif |
81 | 82 | ||
82 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) | 83 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) |
83 | : Resource( config, syncable ) | 84 | : Resource( config, syncable ) |
84 | { | 85 | { |
85 | QString path; | 86 | QString path; |
86 | 87 | ||
87 | KConfig *cfg = (KConfig *)config; | 88 | KConfig *cfg = (KConfig *)config; |
88 | if ( cfg ) { | 89 | if ( cfg ) { |
89 | //US path = config->readEntry( "FilePath" ); | 90 | //US path = config->readEntry( "FilePath" ); |
90 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); | 91 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); |
91 | //US mFormatName = config->readEntry( "FileFormat" ); | 92 | //US mFormatName = config->readEntry( "FileFormat" ); |
92 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); | 93 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); |
93 | } else { | 94 | } else { |
94 | path = StdAddressBook::directoryName(); | 95 | path = StdAddressBook::directoryName(); |
95 | mFormatName = "vcard"; | 96 | mFormatName = "vcard"; |
96 | } | 97 | } |
97 | 98 | ||
98 | 99 | ||
99 | FormatFactory *factory = FormatFactory::self(); | 100 | FormatFactory *factory = FormatFactory::self(); |
100 | mFormat = factory->format( mFormatName ); | 101 | mFormat = factory->format( mFormatName ); |
101 | 102 | ||
102 | if ( !mFormat ) { | 103 | if ( !mFormat ) { |
103 | mFormatName = "vcard"; | 104 | mFormatName = "vcard"; |
104 | mFormat = factory->format( mFormatName ); | 105 | mFormat = factory->format( mFormatName ); |
105 | } | 106 | } |
106 | 107 | ||
107 | /*US | 108 | /*US |
108 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); | 109 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); |
109 | if (mFormatName == "vcard") | 110 | if (mFormatName == "vcard") |
110 | mFormat = new VCardFormatPlugin2(); | 111 | mFormat = new VCardFormatPlugin2(); |
111 | else if (mFormatName == "binary") | 112 | else if (mFormatName == "binary") |
112 | mFormat = new BinaryFormat(); | 113 | mFormat = new BinaryFormat(); |
113 | else | 114 | else |
114 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); | 115 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); |
115 | */ | 116 | */ |
116 | 117 | #ifndef NO_DIRWATCH | |
117 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); | 118 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); |
118 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); | 119 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); |
119 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); | 120 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); |
120 | 121 | #endif | |
121 | setPath( path ); | 122 | setPath( path ); |
122 | } | 123 | } |
123 | 124 | ||
124 | ResourceDir::~ResourceDir() | 125 | ResourceDir::~ResourceDir() |
125 | { | 126 | { |
126 | delete mFormat; | 127 | delete mFormat; |
127 | mFormat = 0; | 128 | mFormat = 0; |
128 | } | 129 | } |
129 | 130 | ||
130 | void ResourceDir::writeConfig( KConfig *config ) | 131 | void ResourceDir::writeConfig( KConfig *config ) |
131 | { | 132 | { |
132 | config->setGroup( "Resource_" + identifier() ); | 133 | config->setGroup( "Resource_" + identifier() ); |
133 | Resource::writeConfig( config ); | 134 | Resource::writeConfig( config ); |
134 | 135 | ||
135 | config->writeEntry( "FilePath", mPath ); | 136 | config->writeEntry( "FilePath", mPath ); |
136 | config->writeEntry( "FileFormat", mFormatName ); | 137 | config->writeEntry( "FileFormat", mFormatName ); |
137 | } | 138 | } |
138 | 139 | ||
139 | Ticket *ResourceDir::requestSaveTicket() | 140 | Ticket *ResourceDir::requestSaveTicket() |
140 | { | 141 | { |
141 | 142 | ||
142 | 143 | ||
143 | if ( !addressBook() ) return 0; | 144 | if ( !addressBook() ) return 0; |
144 | #ifdef ALLOW_LOCKING | 145 | #ifdef ALLOW_LOCKING |
145 | if ( !lock( mPath ) ) { | 146 | if ( !lock( mPath ) ) { |
146 | 147 | ||
147 | return 0; | 148 | return 0; |
148 | } | 149 | } |
149 | #endif | 150 | #endif |
150 | return createTicket( this ); | 151 | return createTicket( this ); |
151 | 152 | ||
152 | } | 153 | } |
153 | 154 | ||
154 | 155 | ||
155 | bool ResourceDir::doOpen() | 156 | bool ResourceDir::doOpen() |
156 | { | 157 | { |
157 | QDir dir( mPath ); | 158 | QDir dir( mPath ); |
158 | if ( !dir.exists() ) { // no directory available | 159 | if ( !dir.exists() ) { // no directory available |
159 | return dir.mkdir( dir.path() ); | 160 | return dir.mkdir( dir.path() ); |
160 | } else { | 161 | } else { |
161 | QString testName = dir.entryList( QDir::Files )[0]; | 162 | QString testName = dir.entryList( QDir::Files )[0]; |
162 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory | 163 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory |
163 | return true; | 164 | return true; |
164 | 165 | ||
165 | QFile file( mPath + "/" + testName ); | 166 | QFile file( mPath + "/" + testName ); |
166 | if ( file.open( IO_ReadOnly ) ) | 167 | if ( file.open( IO_ReadOnly ) ) |
167 | return true; | 168 | return true; |
168 | 169 | ||
169 | if ( file.size() == 0 ) | 170 | if ( file.size() == 0 ) |
170 | return true; | 171 | return true; |
171 | 172 | ||
172 | bool ok = mFormat->checkFormat( &file ); | 173 | bool ok = mFormat->checkFormat( &file ); |
173 | file.close(); | 174 | file.close(); |
174 | return ok; | 175 | return ok; |
175 | } | 176 | } |
176 | } | 177 | } |
177 | 178 | ||
178 | void ResourceDir::doClose() | 179 | void ResourceDir::doClose() |
179 | { | 180 | { |
180 | } | 181 | } |
181 | 182 | ||
182 | bool ResourceDir::load() | 183 | bool ResourceDir::load() |
183 | { | 184 | { |
184 | QDir dir( mPath ); | 185 | QDir dir( mPath ); |
185 | QStringList files = dir.entryList( QDir::Files ); | 186 | QStringList files = dir.entryList( QDir::Files ); |
186 | 187 | ||
187 | QStringList::Iterator it; | 188 | QStringList::Iterator it; |
188 | bool ok = true; | 189 | bool ok = true; |
189 | for ( it = files.begin(); it != files.end(); ++it ) { | 190 | for ( it = files.begin(); it != files.end(); ++it ) { |
190 | QFile file( mPath + "/" + (*it) ); | 191 | QFile file( mPath + "/" + (*it) ); |
191 | 192 | ||
192 | if ( !file.open( IO_ReadOnly ) ) { | 193 | if ( !file.open( IO_ReadOnly ) ) { |
193 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); | 194 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); |
194 | ok = false; | 195 | ok = false; |
195 | continue; | 196 | continue; |
196 | } | 197 | } |
197 | 198 | ||
198 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) | 199 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) |
199 | ok = false; | 200 | ok = false; |
200 | 201 | ||
201 | file.close(); | 202 | file.close(); |
202 | } | 203 | } |
203 | 204 | ||
204 | return ok; | 205 | return ok; |
205 | } | 206 | } |
206 | 207 | ||
207 | bool ResourceDir::save( Ticket *ticket ) | 208 | bool ResourceDir::save( Ticket *ticket ) |
208 | { | 209 | { |
209 | AddressBook::Iterator it; | 210 | AddressBook::Iterator it; |
210 | bool ok = true; | 211 | bool ok = true; |
211 | 212 | #ifndef NO_DIRWATCH | |
212 | mDirWatch.stopScan(); | 213 | mDirWatch.stopScan(); |
213 | 214 | #endif | |
214 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 215 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
215 | if ( (*it).resource() != this || !(*it).changed() ) | 216 | if ( (*it).resource() != this || !(*it).changed() ) |
216 | continue; | 217 | continue; |
217 | 218 | ||
218 | QFile file( mPath + "/" + (*it).uid() ); | 219 | QFile file( mPath + "/" + (*it).uid() ); |
219 | if ( !file.open( IO_WriteOnly ) ) { | 220 | if ( !file.open( IO_WriteOnly ) ) { |
220 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); | 221 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); |
221 | continue; | 222 | continue; |
222 | } | 223 | } |
223 | 224 | ||
224 | mFormat->save( *it, &file ); | 225 | mFormat->save( *it, &file ); |
225 | 226 | ||
226 | // mark as unchanged | 227 | // mark as unchanged |
227 | (*it).setChanged( false ); | 228 | (*it).setChanged( false ); |
228 | 229 | ||
229 | file.close(); | 230 | file.close(); |
230 | } | 231 | } |
232 | #ifndef NO_DIRWATCH | ||
231 | mDirWatch.startScan(); | 233 | mDirWatch.startScan(); |
232 | 234 | #endif | |
233 | delete ticket; | 235 | delete ticket; |
234 | #ifdef ALLOW_LOCKING | 236 | #ifdef ALLOW_LOCKING |
235 | unlock( mPath ); | 237 | unlock( mPath ); |
236 | #endif | 238 | #endif |
237 | return ok; | 239 | return ok; |
238 | } | 240 | } |
239 | 241 | ||
240 | bool ResourceDir::lock( const QString &path ) | 242 | bool ResourceDir::lock( const QString &path ) |
241 | { | 243 | { |
242 | #ifdef ALLOW_LOCKING | 244 | #ifdef ALLOW_LOCKING |
243 | QString p = path; | 245 | QString p = path; |
244 | //US change the implementation how the lockfilename is getting created | 246 | //US change the implementation how the lockfilename is getting created |
245 | //US p.replace( QRegExp("/"), "_" ); | 247 | //US p.replace( QRegExp("/"), "_" ); |
246 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); | 248 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); |
247 | KURL url(p); | 249 | KURL url(p); |
248 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 250 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
249 | 251 | ||
250 | 252 | ||
251 | if ( QFile::exists( lockName ) ) return false; | 253 | if ( QFile::exists( lockName ) ) return false; |
252 | 254 | ||
253 | QString lockUniqueName; | 255 | QString lockUniqueName; |
254 | lockUniqueName = p + KApplication::randomString( 8 ); | 256 | lockUniqueName = p + KApplication::randomString( 8 ); |
255 | 257 | ||
256 | url = lockUniqueName; | 258 | url = lockUniqueName; |
257 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 259 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
258 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 260 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
259 | 261 | ||
260 | // Create unique file | 262 | // Create unique file |
261 | QFile file( mLockUniqueName ); | 263 | QFile file( mLockUniqueName ); |
262 | file.open( IO_WriteOnly ); | 264 | file.open( IO_WriteOnly ); |
263 | file.close(); | 265 | file.close(); |
264 | 266 | ||
265 | // Create lock file | 267 | // Create lock file |
266 | int result = 0; | 268 | int result = 0; |
267 | #ifndef _WIN32_ | 269 | #ifndef _WIN32_ |
268 | result = ::link( QFile::encodeName( mLockUniqueName ), | 270 | result = ::link( QFile::encodeName( mLockUniqueName ), |
269 | QFile::encodeName( lockName ) ); | 271 | QFile::encodeName( lockName ) ); |
270 | #endif | 272 | #endif |
271 | if ( result == 0 ) { | 273 | if ( result == 0 ) { |
272 | addressBook()->emitAddressBookLocked(); | 274 | addressBook()->emitAddressBookLocked(); |
273 | return true; | 275 | return true; |
274 | } | 276 | } |
275 | 277 | ||
276 | // TODO: check stat | 278 | // TODO: check stat |
277 | 279 | ||
278 | return false; | 280 | return false; |
279 | #else | 281 | #else |
280 | return true; | 282 | return true; |
281 | #endif | 283 | #endif |
282 | } | 284 | } |
283 | 285 | ||
284 | void ResourceDir::unlock( const QString &path ) | 286 | void ResourceDir::unlock( const QString &path ) |
285 | { | 287 | { |
286 | #ifdef ALLOW_LOCKING | 288 | #ifdef ALLOW_LOCKING |
287 | QString p = path; | 289 | QString p = path; |
288 | //US change the implementation how the lockfilename is getting created | 290 | //US change the implementation how the lockfilename is getting created |
289 | //US p.replace( QRegExp( "/" ), "_" ); | 291 | //US p.replace( QRegExp( "/" ), "_" ); |
290 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); | 292 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); |
291 | KURL url(p); | 293 | KURL url(p); |
292 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 294 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
293 | 295 | ||
294 | ::unlink( QFile::encodeName( lockName ) ); | 296 | ::unlink( QFile::encodeName( lockName ) ); |
295 | QFile::remove( mLockUniqueName ); | 297 | QFile::remove( mLockUniqueName ); |
296 | addressBook()->emitAddressBookUnlocked(); | 298 | addressBook()->emitAddressBookUnlocked(); |
297 | #else | 299 | #else |
298 | return; | 300 | return; |
299 | #endif | 301 | #endif |
300 | } | 302 | } |
301 | 303 | ||
302 | void ResourceDir::setPath( const QString &path ) | 304 | void ResourceDir::setPath( const QString &path ) |
303 | { | 305 | { |
306 | #ifndef NO_DIRWATCH | ||
304 | mDirWatch.stopScan(); | 307 | mDirWatch.stopScan(); |
305 | mDirWatch.removeDir( mPath ); | 308 | mDirWatch.removeDir( mPath ); |
306 | 309 | ||
307 | mPath = path; | 310 | mPath = path; |
308 | 311 | ||
309 | mDirWatch.addDir( mPath, true ); | 312 | mDirWatch.addDir( mPath, true ); |
310 | mDirWatch.startScan(); | 313 | mDirWatch.startScan(); |
311 | 314 | #else | |
315 | mPath = path; | ||
316 | #endif | ||
312 | //US simulate KDirWatch event | 317 | //US simulate KDirWatch event |
313 | //US pathChanged(); | 318 | //US pathChanged(); |
314 | 319 | ||
315 | } | 320 | } |
316 | 321 | ||
317 | QString ResourceDir::path() const | 322 | QString ResourceDir::path() const |
318 | { | 323 | { |
319 | return mPath; | 324 | return mPath; |
320 | } | 325 | } |
321 | 326 | ||
322 | void ResourceDir::setFormat( const QString &format ) | 327 | void ResourceDir::setFormat( const QString &format ) |
323 | { | 328 | { |
324 | mFormatName = format; | 329 | mFormatName = format; |
325 | 330 | ||
326 | if ( mFormat ) | 331 | if ( mFormat ) |
327 | delete mFormat; | 332 | delete mFormat; |
328 | 333 | ||
329 | FormatFactory *factory = FormatFactory::self(); | 334 | FormatFactory *factory = FormatFactory::self(); |
330 | mFormat = factory->format( mFormatName ); | 335 | mFormat = factory->format( mFormatName ); |
331 | /*US | 336 | /*US |
332 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); | 337 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); |
333 | if (mFormatName == "vcard") | 338 | if (mFormatName == "vcard") |
334 | mFormat = new VCardFormatPlugin2(); | 339 | mFormat = new VCardFormatPlugin2(); |
335 | else if (mFormatName == "binary") | 340 | else if (mFormatName == "binary") |
336 | mFormat = new BinaryFormat(); | 341 | mFormat = new BinaryFormat(); |
337 | else | 342 | else |
338 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); | 343 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); |
339 | */ | 344 | */ |
340 | 345 | ||
341 | } | 346 | } |
342 | 347 | ||
343 | QString ResourceDir::format() const | 348 | QString ResourceDir::format() const |
344 | { | 349 | { |
345 | return mFormatName; | 350 | return mFormatName; |
346 | } | 351 | } |
347 | 352 | ||
348 | void ResourceDir::pathChanged() | 353 | void ResourceDir::pathChanged() |
349 | { | 354 | { |
350 | if ( !addressBook() ) | 355 | if ( !addressBook() ) |
351 | return; | 356 | return; |
352 | 357 | ||
353 | QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); | 358 | QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); |
354 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 359 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
355 | load(); | 360 | load(); |
356 | addressBook()->emitAddressBookChanged(); | 361 | addressBook()->emitAddressBookChanged(); |
357 | } | 362 | } |
358 | } | 363 | } |
359 | 364 | ||
diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h index c2aedad..77cd18c 100644 --- a/kabc/plugins/dir/resourcedir.h +++ b/kabc/plugins/dir/resourcedir.h | |||
@@ -59,57 +59,58 @@ public: | |||
59 | 59 | ||
60 | virtual Ticket *requestSaveTicket(); | 60 | virtual Ticket *requestSaveTicket(); |
61 | 61 | ||
62 | virtual bool load(); | 62 | virtual bool load(); |
63 | virtual bool save( Ticket * ); | 63 | virtual bool save( Ticket * ); |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Set path to be used for saving. | 66 | * Set path to be used for saving. |
67 | */ | 67 | */ |
68 | void setPath( const QString & ); | 68 | void setPath( const QString & ); |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Return path used for loading and saving the address book. | 71 | * Return path used for loading and saving the address book. |
72 | */ | 72 | */ |
73 | QString path() const; | 73 | QString path() const; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Set the format by name. | 76 | * Set the format by name. |
77 | */ | 77 | */ |
78 | void setFormat( const QString &format ); | 78 | void setFormat( const QString &format ); |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Returns the format name. | 81 | * Returns the format name. |
82 | */ | 82 | */ |
83 | QString format() const; | 83 | QString format() const; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Remove a addressee from its source. | 86 | * Remove a addressee from its source. |
87 | * This method is mainly called by KABC::AddressBook. | 87 | * This method is mainly called by KABC::AddressBook. |
88 | */ | 88 | */ |
89 | virtual void removeAddressee( const Addressee& addr ); | 89 | virtual void removeAddressee( const Addressee& addr ); |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * This method is called by an error handler if the application | 92 | * This method is called by an error handler if the application |
93 | * crashed | 93 | * crashed |
94 | */ | 94 | */ |
95 | virtual void cleanUp(); | 95 | virtual void cleanUp(); |
96 | 96 | ||
97 | protected slots: | 97 | protected slots: |
98 | void pathChanged(); | 98 | void pathChanged(); |
99 | 99 | ||
100 | protected: | 100 | protected: |
101 | bool lock( const QString &path ); | 101 | bool lock( const QString &path ); |
102 | void unlock( const QString &path ); | 102 | void unlock( const QString &path ); |
103 | 103 | ||
104 | private: | 104 | private: |
105 | FormatPlugin *mFormat; | 105 | FormatPlugin *mFormat; |
106 | 106 | ||
107 | #ifndef NO_DIRWATCH | ||
107 | KDirWatch mDirWatch; | 108 | KDirWatch mDirWatch; |
108 | 109 | #endif | |
109 | QString mPath; | 110 | QString mPath; |
110 | QString mFormatName; | 111 | QString mFormatName; |
111 | QString mLockUniqueName; | 112 | QString mLockUniqueName; |
112 | }; | 113 | }; |
113 | 114 | ||
114 | } | 115 | } |
115 | #endif | 116 | #endif |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 17263ae..b8c32d5 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -4,167 +4,169 @@ | |||
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 | #define NO_DIRWATCH | |
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncprefwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | //#define ALLOW_LOCKING | 56 | //#define ALLOW_LOCKING |
57 | 57 | ||
58 | |||
59 | |||
58 | using namespace KABC; | 60 | using namespace KABC; |
59 | 61 | ||
60 | extern "C" | 62 | extern "C" |
61 | #ifdef _WIN32_ | 63 | #ifdef _WIN32_ |
62 | __declspec(dllexport) | 64 | __declspec(dllexport) |
63 | #else | 65 | #else |
64 | { | 66 | { |
65 | #endif | 67 | #endif |
66 | 68 | ||
67 | //US void *init_kabc_file() | 69 | //US void *init_kabc_file() |
68 | void *init_microkabc_file() | 70 | void *init_microkabc_file() |
69 | { | 71 | { |
70 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); | 72 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); |
71 | } | 73 | } |
72 | #ifndef _WIN32_ | 74 | #ifndef _WIN32_ |
73 | } | 75 | } |
74 | #endif | 76 | #endif |
75 | 77 | ||
76 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) | 78 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) |
77 | : Resource( config, syncable ) , mFormat( 0 ) | 79 | : Resource( config, syncable ) , mFormat( 0 ) |
78 | { | 80 | { |
79 | QString fileName, formatName, default_fileName; | 81 | QString fileName, formatName, default_fileName; |
80 | 82 | ||
81 | if (syncable == true) | 83 | if (syncable == true) |
82 | default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; | 84 | default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; |
83 | else | 85 | else |
84 | default_fileName = StdAddressBook::fileName(); | 86 | default_fileName = StdAddressBook::fileName(); |
85 | 87 | ||
86 | KConfig *cfg = (KConfig *)config; | 88 | KConfig *cfg = (KConfig *)config; |
87 | if ( cfg ) { | 89 | if ( cfg ) { |
88 | fileName = cfg->readEntry( "FileName", default_fileName ); | 90 | fileName = cfg->readEntry( "FileName", default_fileName ); |
89 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 91 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
90 | } else { | 92 | } else { |
91 | fileName = default_fileName; | 93 | fileName = default_fileName; |
92 | formatName = "vcard"; | 94 | formatName = "vcard"; |
93 | } | 95 | } |
94 | 96 | ||
95 | init( fileName, formatName ); | 97 | init( fileName, formatName ); |
96 | } | 98 | } |
97 | 99 | ||
98 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , | 100 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , |
99 | const QString &formatName ) | 101 | const QString &formatName ) |
100 | : Resource( 0, syncable ) | 102 | : Resource( 0, syncable ) |
101 | { | 103 | { |
102 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 104 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
103 | init( fileName, formatName ); | 105 | init( fileName, formatName ); |
104 | } | 106 | } |
105 | 107 | ||
106 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 108 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
107 | { | 109 | { |
108 | mFormatName = formatName; | 110 | mFormatName = formatName; |
109 | 111 | ||
110 | FormatFactory *factory = FormatFactory::self(); | 112 | FormatFactory *factory = FormatFactory::self(); |
111 | mFormat = factory->format( mFormatName ); | 113 | mFormat = factory->format( mFormatName ); |
112 | 114 | ||
113 | if ( !mFormat ) { | 115 | if ( !mFormat ) { |
114 | mFormatName = "vcard"; | 116 | mFormatName = "vcard"; |
115 | mFormat = factory->format( mFormatName ); | 117 | mFormat = factory->format( mFormatName ); |
116 | } | 118 | } |
117 | 119 | ||
118 | 120 | #ifndef NO_DIRWATCH | |
119 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 121 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
120 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 122 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
121 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 123 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
122 | 124 | #endif | |
123 | setFileName( fileName ); | 125 | setFileName( fileName ); |
124 | } | 126 | } |
125 | 127 | ||
126 | ResourceFile::~ResourceFile() | 128 | ResourceFile::~ResourceFile() |
127 | { | 129 | { |
128 | delete mFormat; | 130 | delete mFormat; |
129 | mFormat = 0; | 131 | mFormat = 0; |
130 | } | 132 | } |
131 | 133 | ||
132 | void ResourceFile::writeConfig( KConfig *config ) | 134 | void ResourceFile::writeConfig( KConfig *config ) |
133 | { | 135 | { |
134 | 136 | ||
135 | config->setGroup( "Resource_" + identifier() ); | 137 | config->setGroup( "Resource_" + identifier() ); |
136 | Resource::writeConfig( config ); | 138 | Resource::writeConfig( config ); |
137 | 139 | ||
138 | config->writeEntry( "FileName", mFileName ); | 140 | config->writeEntry( "FileName", mFileName ); |
139 | config->writeEntry( "FileFormat", mFormatName ); | 141 | config->writeEntry( "FileFormat", mFormatName ); |
140 | 142 | ||
141 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 143 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
142 | 144 | ||
143 | } | 145 | } |
144 | 146 | ||
145 | Ticket *ResourceFile::requestSaveTicket() | 147 | Ticket *ResourceFile::requestSaveTicket() |
146 | { | 148 | { |
147 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 149 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
148 | 150 | ||
149 | if ( !addressBook() ) return 0; | 151 | if ( !addressBook() ) return 0; |
150 | 152 | ||
151 | #ifdef ALLOW_LOCKING | 153 | #ifdef ALLOW_LOCKING |
152 | if ( !lock( mFileName ) ) { | 154 | if ( !lock( mFileName ) ) { |
153 | qDebug("unablt to lock file "); | 155 | qDebug("unablt to lock file "); |
154 | return 0; | 156 | return 0; |
155 | } | 157 | } |
156 | #endif | 158 | #endif |
157 | return createTicket( this ); | 159 | return createTicket( this ); |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
161 | bool ResourceFile::doOpen() | 163 | bool ResourceFile::doOpen() |
162 | { | 164 | { |
163 | QFile file( mFileName ); | 165 | QFile file( mFileName ); |
164 | 166 | ||
165 | if ( !file.exists() ) { | 167 | if ( !file.exists() ) { |
166 | // try to create the file | 168 | // try to create the file |
167 | bool ok = file.open( IO_WriteOnly ); | 169 | bool ok = file.open( IO_WriteOnly ); |
168 | if ( ok ) | 170 | if ( ok ) |
169 | file.close(); | 171 | file.close(); |
170 | 172 | ||
@@ -182,203 +184,207 @@ bool ResourceFile::doOpen() | |||
182 | file.close(); | 184 | file.close(); |
183 | 185 | ||
184 | return ok; | 186 | return ok; |
185 | } | 187 | } |
186 | } | 188 | } |
187 | 189 | ||
188 | void ResourceFile::doClose() | 190 | void ResourceFile::doClose() |
189 | { | 191 | { |
190 | } | 192 | } |
191 | 193 | ||
192 | bool ResourceFile::load() | 194 | bool ResourceFile::load() |
193 | { | 195 | { |
194 | 196 | ||
195 | 197 | ||
196 | QFile file( mFileName ); | 198 | QFile file( mFileName ); |
197 | if ( !file.open( IO_ReadOnly ) ) { | 199 | if ( !file.open( IO_ReadOnly ) ) { |
198 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 200 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
199 | return false; | 201 | return false; |
200 | } | 202 | } |
201 | 203 | ||
202 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 204 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
203 | 205 | ||
204 | return mFormat->loadAll( addressBook(), this, &file ); | 206 | return mFormat->loadAll( addressBook(), this, &file ); |
205 | } | 207 | } |
206 | 208 | ||
207 | bool ResourceFile::save( Ticket *ticket ) | 209 | bool ResourceFile::save( Ticket *ticket ) |
208 | { | 210 | { |
209 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 211 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
210 | 212 | ||
211 | 213 | ||
212 | // create backup file | 214 | // create backup file |
213 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 215 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
214 | 216 | ||
215 | /*US we use a simpler method to create a backupfile | 217 | /*US we use a simpler method to create a backupfile |
216 | 218 | ||
217 | (void) KSaveFile::backupFile( mFileName, QString::null | 219 | (void) KSaveFile::backupFile( mFileName, QString::null |
218 | ,extension ); | 220 | ,extension ); |
219 | 221 | ||
220 | KSaveFile saveFile( mFileName ); | 222 | KSaveFile saveFile( mFileName ); |
221 | bool ok = false; | 223 | bool ok = false; |
222 | if ( saveFile.status() == 0 && saveFile.file() ) | 224 | if ( saveFile.status() == 0 && saveFile.file() ) |
223 | { | 225 | { |
224 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 226 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
225 | ok = saveFile.close(); | 227 | ok = saveFile.close(); |
226 | } | 228 | } |
227 | */ | 229 | */ |
228 | 230 | ||
229 | //US ToDo: write backupfile | 231 | //US ToDo: write backupfile |
232 | #ifndef NO_DIRWATCH | ||
230 | mDirWatch.stopScan(); | 233 | mDirWatch.stopScan(); |
231 | 234 | #endif | |
232 | QFile info; | 235 | QFile info; |
233 | info.setName( mFileName ); | 236 | info.setName( mFileName ); |
234 | bool ok = info.open( IO_WriteOnly ); | 237 | bool ok = info.open( IO_WriteOnly ); |
235 | if ( ok ) { | 238 | if ( ok ) { |
236 | mFormat->saveAll( addressBook(), this, &info ); | 239 | mFormat->saveAll( addressBook(), this, &info ); |
237 | 240 | ||
238 | info.close(); | 241 | info.close(); |
239 | ok = true; | 242 | ok = true; |
240 | } | 243 | } |
241 | else { | 244 | else { |
242 | 245 | ||
243 | } | 246 | } |
244 | 247 | ||
245 | if ( !ok ) | 248 | if ( !ok ) |
246 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 249 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
247 | 250 | #ifndef NO_DIRWATCH | |
248 | mDirWatch.startScan(); | 251 | mDirWatch.startScan(); |
249 | 252 | #endif | |
250 | delete ticket; | 253 | delete ticket; |
251 | #ifdef ALLOW_LOCKING | 254 | #ifdef ALLOW_LOCKING |
252 | unlock( mFileName ); | 255 | unlock( mFileName ); |
253 | #endif | 256 | #endif |
254 | 257 | ||
255 | return ok; | 258 | return ok; |
256 | } | 259 | } |
257 | 260 | ||
258 | bool ResourceFile::lock( const QString &fileName ) | 261 | bool ResourceFile::lock( const QString &fileName ) |
259 | { | 262 | { |
260 | #ifdef ALLOW_LOCKING | 263 | #ifdef ALLOW_LOCKING |
261 | 264 | ||
262 | 265 | ||
263 | QString fn = fileName; | 266 | QString fn = fileName; |
264 | 267 | ||
265 | //US change the implementation how the lockfilename is getting created | 268 | //US change the implementation how the lockfilename is getting created |
266 | //US fn.replace( QRegExp("/"), "_" ); | 269 | //US fn.replace( QRegExp("/"), "_" ); |
267 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 270 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
268 | 271 | ||
269 | KURL url(fn); | 272 | KURL url(fn); |
270 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 273 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
271 | 274 | ||
272 | 275 | ||
273 | 276 | ||
274 | if (QFile::exists( lockName )) return false; | 277 | if (QFile::exists( lockName )) return false; |
275 | 278 | ||
276 | QString lockUniqueName; | 279 | QString lockUniqueName; |
277 | lockUniqueName = fn + KApplication::randomString( 8 ); | 280 | lockUniqueName = fn + KApplication::randomString( 8 ); |
278 | 281 | ||
279 | url = lockUniqueName; | 282 | url = lockUniqueName; |
280 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 283 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
281 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 284 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
282 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 285 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
283 | 286 | ||
284 | // Create unique file | 287 | // Create unique file |
285 | QFile file( mLockUniqueName ); | 288 | QFile file( mLockUniqueName ); |
286 | file.open( IO_WriteOnly ); | 289 | file.open( IO_WriteOnly ); |
287 | file.close(); | 290 | file.close(); |
288 | 291 | ||
289 | // Create lock file | 292 | // Create lock file |
290 | int result = 0; | 293 | int result = 0; |
291 | #ifndef _WIN32_ | 294 | #ifndef _WIN32_ |
292 | result = ::link( QFile::encodeName( mLockUniqueName ), | 295 | result = ::link( QFile::encodeName( mLockUniqueName ), |
293 | QFile::encodeName( lockName ) ); | 296 | QFile::encodeName( lockName ) ); |
294 | #endif | 297 | #endif |
295 | if ( result == 0 ) { | 298 | if ( result == 0 ) { |
296 | addressBook()->emitAddressBookLocked(); | 299 | addressBook()->emitAddressBookLocked(); |
297 | return true; | 300 | return true; |
298 | } | 301 | } |
299 | 302 | ||
300 | // TODO: check stat | 303 | // TODO: check stat |
301 | 304 | ||
302 | return false; | 305 | return false; |
303 | #else | 306 | #else |
304 | return true; | 307 | return true; |
305 | #endif | 308 | #endif |
306 | } | 309 | } |
307 | 310 | ||
308 | void ResourceFile::unlock( const QString &fileName ) | 311 | void ResourceFile::unlock( const QString &fileName ) |
309 | { | 312 | { |
310 | #ifdef ALLOW_LOCKING | 313 | #ifdef ALLOW_LOCKING |
311 | QString fn = fileName; | 314 | QString fn = fileName; |
312 | //US change the implementation how the lockfilename is getting created | 315 | //US change the implementation how the lockfilename is getting created |
313 | //US fn.replace( QRegExp( "/" ), "_" ); | 316 | //US fn.replace( QRegExp( "/" ), "_" ); |
314 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 317 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
315 | //US QString lockName = fn + ".lock"; | 318 | //US QString lockName = fn + ".lock"; |
316 | KURL url(fn); | 319 | KURL url(fn); |
317 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 320 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
318 | 321 | ||
319 | QFile::remove( lockName ); | 322 | QFile::remove( lockName ); |
320 | QFile::remove( mLockUniqueName ); | 323 | QFile::remove( mLockUniqueName ); |
321 | addressBook()->emitAddressBookUnlocked(); | 324 | addressBook()->emitAddressBookUnlocked(); |
322 | #else | 325 | #else |
323 | return; | 326 | return; |
324 | #endif | 327 | #endif |
325 | } | 328 | } |
326 | 329 | ||
327 | void ResourceFile::setFileName( const QString &fileName ) | 330 | void ResourceFile::setFileName( const QString &fileName ) |
328 | { | 331 | { |
332 | #ifndef NO_DIRWATCH | ||
329 | mDirWatch.stopScan(); | 333 | mDirWatch.stopScan(); |
330 | mDirWatch.removeFile( mFileName ); | 334 | mDirWatch.removeFile( mFileName ); |
331 | |||
332 | mFileName = fileName; | 335 | mFileName = fileName; |
333 | 336 | ||
334 | 337 | ||
335 | mDirWatch.addFile( mFileName ); | 338 | mDirWatch.addFile( mFileName ); |
336 | mDirWatch.startScan(); | 339 | mDirWatch.startScan(); |
340 | #else | ||
341 | mFileName = fileName; | ||
342 | #endif | ||
337 | 343 | ||
338 | //US simulate KDirWatch event | 344 | //US simulate KDirWatch event |
339 | //US fileChanged(); | 345 | //US fileChanged(); |
340 | } | 346 | } |
341 | 347 | ||
342 | QString ResourceFile::fileName() const | 348 | QString ResourceFile::fileName() const |
343 | { | 349 | { |
344 | return mFileName; | 350 | return mFileName; |
345 | } | 351 | } |
346 | 352 | ||
347 | void ResourceFile::setFormat( const QString &format ) | 353 | void ResourceFile::setFormat( const QString &format ) |
348 | { | 354 | { |
349 | mFormatName = format; | 355 | mFormatName = format; |
350 | delete mFormat; | 356 | delete mFormat; |
351 | 357 | ||
352 | FormatFactory *factory = FormatFactory::self(); | 358 | FormatFactory *factory = FormatFactory::self(); |
353 | mFormat = factory->format( mFormatName ); | 359 | mFormat = factory->format( mFormatName ); |
354 | /*US | 360 | /*US |
355 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 361 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
356 | if (mFormatName == "vcard") { | 362 | if (mFormatName == "vcard") { |
357 | mFormat = new VCardFormatPlugin2(); | 363 | mFormat = new VCardFormatPlugin2(); |
358 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 364 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
359 | } | 365 | } |
360 | else if (mFormatName == "binary") { | 366 | else if (mFormatName == "binary") { |
361 | mFormat = new BinaryFormat(); | 367 | mFormat = new BinaryFormat(); |
362 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 368 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
363 | } | 369 | } |
364 | else | 370 | else |
365 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 371 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
366 | */ | 372 | */ |
367 | 373 | ||
368 | } | 374 | } |
369 | 375 | ||
370 | QString ResourceFile::format() const | 376 | QString ResourceFile::format() const |
371 | { | 377 | { |
372 | return mFormatName; | 378 | return mFormatName; |
373 | } | 379 | } |
374 | 380 | ||
375 | void ResourceFile::fileChanged() | 381 | void ResourceFile::fileChanged() |
376 | { | 382 | { |
377 | // There is a small theoretical chance that KDirWatch calls us before | 383 | // There is a small theoretical chance that KDirWatch calls us before |
378 | // we are fully constructed | 384 | // we are fully constructed |
379 | if (!addressBook()) | 385 | if (!addressBook()) |
380 | return; | 386 | return; |
381 | 387 | ||
382 | 388 | ||
383 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 389 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); |
384 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h index 0a3027c..8339340 100644 --- a/kabc/plugins/file/resourcefile.h +++ b/kabc/plugins/file/resourcefile.h | |||
@@ -108,55 +108,56 @@ public: | |||
108 | /** | 108 | /** |
109 | * Set name of file to be used for saving. | 109 | * Set name of file to be used for saving. |
110 | */ | 110 | */ |
111 | void setFileName( const QString & ); | 111 | void setFileName( const QString & ); |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Return name of file used for loading and saving the address book. | 114 | * Return name of file used for loading and saving the address book. |
115 | */ | 115 | */ |
116 | QString fileName() const; | 116 | QString fileName() const; |
117 | 117 | ||
118 | /** | 118 | /** |
119 | Sets a new format by name. | 119 | Sets a new format by name. |
120 | */ | 120 | */ |
121 | void setFormat( const QString &name ); | 121 | void setFormat( const QString &name ); |
122 | 122 | ||
123 | /** | 123 | /** |
124 | Returns the format name. | 124 | Returns the format name. |
125 | */ | 125 | */ |
126 | QString format() const; | 126 | QString format() const; |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Remove a addressee from its source. | 129 | * Remove a addressee from its source. |
130 | * This method is mainly called by KABC::AddressBook. | 130 | * This method is mainly called by KABC::AddressBook. |
131 | */ | 131 | */ |
132 | virtual void removeAddressee( const Addressee& addr ); | 132 | virtual void removeAddressee( const Addressee& addr ); |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * This method is called by an error handler if the application | 135 | * This method is called by an error handler if the application |
136 | * crashed | 136 | * crashed |
137 | */ | 137 | */ |
138 | virtual void cleanUp(); | 138 | virtual void cleanUp(); |
139 | 139 | ||
140 | protected slots: | 140 | protected slots: |
141 | void fileChanged(); | 141 | void fileChanged(); |
142 | 142 | ||
143 | protected: | 143 | protected: |
144 | void init( const QString &fileName, const QString &format ); | 144 | void init( const QString &fileName, const QString &format ); |
145 | 145 | ||
146 | bool lock( const QString &fileName ); | 146 | bool lock( const QString &fileName ); |
147 | void unlock( const QString &fileName ); | 147 | void unlock( const QString &fileName ); |
148 | 148 | ||
149 | private: | 149 | private: |
150 | QString mFileName; | 150 | QString mFileName; |
151 | QString mFormatName; | 151 | QString mFormatName; |
152 | 152 | ||
153 | FormatPlugin *mFormat; | 153 | FormatPlugin *mFormat; |
154 | 154 | ||
155 | QString mLockUniqueName; | 155 | QString mLockUniqueName; |
156 | 156 | #ifndef NO_DIRWATCH | |
157 | KDirWatch mDirWatch; | 157 | KDirWatch mDirWatch; |
158 | #endif | ||
158 | }; | 159 | }; |
159 | 160 | ||
160 | } | 161 | } |
161 | 162 | ||
162 | #endif | 163 | #endif |
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp index 1a3a22c..02c5fb1 100644 --- a/microkde/kresources/configpage.cpp +++ b/microkde/kresources/configpage.cpp | |||
@@ -55,121 +55,121 @@ $Id$ | |||
55 | #include <qfile.h> | 55 | #include <qfile.h> |
56 | #include <kglobal.h> | 56 | #include <kglobal.h> |
57 | 57 | ||
58 | using namespace KRES; | 58 | using namespace KRES; |
59 | 59 | ||
60 | const QString ConfigPage::syncfamily = "syncprofiles"; | 60 | const QString ConfigPage::syncfamily = "syncprofiles"; |
61 | 61 | ||
62 | 62 | ||
63 | class ConfigViewItem : public QCheckListItem | 63 | class ConfigViewItem : public QCheckListItem |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | ConfigViewItem( QListView *parent, Resource* resource ) : | 66 | ConfigViewItem( QListView *parent, Resource* resource ) : |
67 | QCheckListItem( parent, resource->resourceName(), CheckBox ), | 67 | QCheckListItem( parent, resource->resourceName(), CheckBox ), |
68 | mResource( resource ), | 68 | mResource( resource ), |
69 | mIsStandard( false ) | 69 | mIsStandard( false ) |
70 | { | 70 | { |
71 | setText( 1, mResource->type() ); | 71 | setText( 1, mResource->type() ); |
72 | setOn( mResource->isActive() ); | 72 | setOn( mResource->isActive() ); |
73 | } | 73 | } |
74 | 74 | ||
75 | void setStandard( bool value ) | 75 | void setStandard( bool value ) |
76 | { | 76 | { |
77 | setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); | 77 | setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); |
78 | mIsStandard = value; | 78 | mIsStandard = value; |
79 | } | 79 | } |
80 | 80 | ||
81 | bool standard() const { return mIsStandard; } | 81 | bool standard() const { return mIsStandard; } |
82 | bool readOnly() const { return mResource->readOnly(); } | 82 | bool readOnly() const { return mResource->readOnly(); } |
83 | 83 | ||
84 | Resource *resource() { return mResource; } | 84 | Resource *resource() { return mResource; } |
85 | 85 | ||
86 | private: | 86 | private: |
87 | Resource* mResource; | 87 | Resource* mResource; |
88 | 88 | ||
89 | bool mIsStandard; | 89 | bool mIsStandard; |
90 | }; | 90 | }; |
91 | 91 | ||
92 | ConfigPage::ConfigPage( QWidget *parent, const char *name ) | 92 | ConfigPage::ConfigPage( QWidget *parent, const char *name ) |
93 | : QWidget( parent, name ), | 93 | : QWidget( parent, name ), |
94 | mCurrentManager( 0 ), | 94 | mCurrentManager( 0 ), |
95 | mCurrentConfig( 0 ) | 95 | mCurrentConfig( 0 ) |
96 | { | 96 | { |
97 | setCaption( i18n( "Resource Configuration" ) ); | 97 | setCaption( i18n( "Resource Configuration" ) ); |
98 | 98 | ||
99 | QVBoxLayout *mainLayout = new QVBoxLayout( this ); | 99 | QVBoxLayout *mainLayout = new QVBoxLayout( this ); |
100 | 100 | ||
101 | QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); | 101 | QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); |
102 | groupBox->setColumnLayout(0, Qt::Vertical ); | 102 | groupBox->setColumnLayout(0, Qt::Vertical ); |
103 | groupBox->layout()->setSpacing( 6 ); | 103 | groupBox->layout()->setSpacing( 3 ); |
104 | groupBox->layout()->setMargin( 11 ); | 104 | groupBox->layout()->setMargin( 5 ); |
105 | QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 ); | 105 | QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 ); |
106 | 106 | ||
107 | //US mFamilyCombo = new KComboBox( false, groupBox ); | 107 | //US mFamilyCombo = new KComboBox( false, groupBox ); |
108 | mFamilyCombo = new KComboBox( groupBox ); | 108 | mFamilyCombo = new KComboBox( groupBox ); |
109 | groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); | 109 | groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); |
110 | 110 | ||
111 | mListView = new KListView( groupBox ); | 111 | mListView = new KListView( groupBox ); |
112 | mListView->setAllColumnsShowFocus( true ); | 112 | mListView->setAllColumnsShowFocus( true ); |
113 | mListView->addColumn( i18n( "Name" ) ); | 113 | mListView->addColumn( i18n( "Name" ) ); |
114 | mListView->addColumn( i18n( "Type" ) ); | 114 | mListView->addColumn( i18n( "Type" ) ); |
115 | mListView->addColumn( i18n( "Standard" ) ); | 115 | mListView->addColumn( i18n( "Standard" ) ); |
116 | 116 | ||
117 | //US groupBoxLayout->addWidget( mListView, 1, 0 ); | 117 | //US groupBoxLayout->addWidget( mListView, 1, 0 ); |
118 | groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); | 118 | groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); |
119 | 119 | ||
120 | 120 | ||
121 | mAddButton = new QPushButton( i18n( "&Add..." ), this ); | 121 | mAddButton = new QPushButton( i18n( "&Add..." ), groupBox ); |
122 | groupBoxLayout->addWidget( mAddButton, 2, 0 ); | 122 | groupBoxLayout->addWidget( mAddButton, 2, 0 ); |
123 | mRemoveButton = new QPushButton( i18n( "&Remove" ), this ); | 123 | mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox ); |
124 | groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); | 124 | groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); |
125 | mEditButton = new QPushButton( i18n( "&Edit..." ), this ); | 125 | mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox ); |
126 | groupBoxLayout->addWidget( mEditButton, 3, 0 ); | 126 | groupBoxLayout->addWidget( mEditButton, 3, 0 ); |
127 | mStandardButton = new QPushButton( i18n( "&Use as Standard" ), this ); | 127 | mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox ); |
128 | groupBoxLayout->addWidget( mStandardButton, 3, 1 ); | 128 | groupBoxLayout->addWidget( mStandardButton, 3, 1 ); |
129 | 129 | ||
130 | mRemoveButton->setEnabled( false ); | 130 | mRemoveButton->setEnabled( false ); |
131 | mEditButton->setEnabled( false ); | 131 | mEditButton->setEnabled( false ); |
132 | mStandardButton->setEnabled( false ); | 132 | mStandardButton->setEnabled( false ); |
133 | 133 | ||
134 | 134 | ||
135 | connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); | 135 | connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); |
136 | connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); | 136 | connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); |
137 | connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); | 137 | connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); |
138 | connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); | 138 | connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); |
139 | 139 | ||
140 | 140 | ||
141 | mainLayout->addWidget( groupBox ); | 141 | mainLayout->addWidget( groupBox ); |
142 | 142 | ||
143 | connect( mFamilyCombo, SIGNAL( activated( int ) ), | 143 | connect( mFamilyCombo, SIGNAL( activated( int ) ), |
144 | SLOT( slotFamilyChanged( int ) ) ); | 144 | SLOT( slotFamilyChanged( int ) ) ); |
145 | connect( mListView, SIGNAL( selectionChanged() ), | 145 | connect( mListView, SIGNAL( selectionChanged() ), |
146 | SLOT( slotSelectionChanged() ) ); | 146 | SLOT( slotSelectionChanged() ) ); |
147 | connect( mListView, SIGNAL( clicked( QListViewItem * ) ), | 147 | connect( mListView, SIGNAL( clicked( QListViewItem * ) ), |
148 | SLOT( slotItemClicked( QListViewItem * ) ) ); | 148 | SLOT( slotItemClicked( QListViewItem * ) ) ); |
149 | 149 | ||
150 | mLastItem = 0; | 150 | mLastItem = 0; |
151 | 151 | ||
152 | //US mConfig = new KConfig( "kcmkresourcesrc" ); | 152 | //US mConfig = new KConfig( "kcmkresourcesrc" ); |
153 | mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); | 153 | mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); |
154 | mConfig->setGroup( "General" ); | 154 | mConfig->setGroup( "General" ); |
155 | 155 | ||
156 | load(); | 156 | load(); |
157 | } | 157 | } |
158 | 158 | ||
159 | ConfigPage::~ConfigPage() | 159 | ConfigPage::~ConfigPage() |
160 | { | 160 | { |
161 | QValueList<ResourcePageInfo>::Iterator it; | 161 | QValueList<ResourcePageInfo>::Iterator it; |
162 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { | 162 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { |
163 | (*it).mManager->removeListener( this ); | 163 | (*it).mManager->removeListener( this ); |
164 | delete (*it).mManager; | 164 | delete (*it).mManager; |
165 | delete (*it).mConfig; | 165 | delete (*it).mConfig; |
166 | } | 166 | } |
167 | 167 | ||
168 | mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); | 168 | mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); |
169 | delete mConfig; | 169 | delete mConfig; |
170 | mConfig = 0; | 170 | mConfig = 0; |
171 | } | 171 | } |
172 | 172 | ||
173 | void ConfigPage::load() | 173 | void ConfigPage::load() |
174 | { | 174 | { |
175 | kdDebug(5650) << "ConfigPage::load()" << endl; | 175 | kdDebug(5650) << "ConfigPage::load()" << endl; |