author | ulf69 <ulf69> | 2004-07-15 05:06:06 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-15 05:06:06 (UTC) |
commit | 59f727076930aada485db6531d4084f2bfe0b928 (patch) (unidiff) | |
tree | d68ab61d9f78759d36d8ccb2cdd3312987bf7917 /kabc | |
parent | 2ada2bfd67b5488115268e6667e55a9b4b297fa2 (diff) | |
download | kdepimpi-59f727076930aada485db6531d4084f2bfe0b928.zip kdepimpi-59f727076930aada485db6531d4084f2bfe0b928.tar.gz kdepimpi-59f727076930aada485db6531d4084f2bfe0b928.tar.bz2 |
ask for readwrite resources if the user wants them to reload in the case of an
external change.
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 10 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 10 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 12 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 9 |
4 files changed, 30 insertions, 11 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index 7825c6f..52863d5 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -1,106 +1,105 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | 28 | ||
29 | #include <sys/types.h> | 29 | #include <sys/types.h> |
30 | #include <sys/stat.h> | 30 | #include <sys/stat.h> |
31 | #ifndef _WIN32_ | 31 | #ifndef _WIN32_ |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | #include <qtimer.h> | 36 | #include <qtimer.h> |
37 | #include <qwidget.h> | 37 | #include <qwidget.h> |
38 | 38 | ||
39 | #include <kapplication.h> | 39 | #include <kapplication.h> |
40 | #include <kconfig.h> | 40 | #include <kconfig.h> |
41 | #include <kdebug.h> | 41 | #include <kdebug.h> |
42 | //US #include <kgenericfactory.h> | 42 | //US #include <kgenericfactory.h> |
43 | #include <kglobal.h> | 43 | #include <kglobal.h> |
44 | #include <klocale.h> | 44 | #include <klocale.h> |
45 | #include <kstandarddirs.h> | 45 | #include <kstandarddirs.h> |
46 | #include <kurlrequester.h> | 46 | #include <kurlrequester.h> |
47 | #include <kmessagebox.h> | ||
47 | 48 | ||
48 | #include "addressbook.h" | 49 | #include "addressbook.h" |
49 | 50 | ||
50 | #include "formatfactory.h" | 51 | #include "formatfactory.h" |
51 | 52 | ||
52 | #include "resourcedirconfig.h" | 53 | #include "resourcedirconfig.h" |
53 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
54 | 55 | ||
55 | //US | 56 | //US |
56 | #include <qdir.h> | 57 | #include <qdir.h> |
57 | //US #include "../../formats/vcardformatplugin2.h" | ||
58 | //US #include "../../formats/binaryformat.h" | ||
59 | 58 | ||
60 | #include "resourcedir.h" | 59 | #include "resourcedir.h" |
61 | 60 | ||
62 | using namespace KABC; | 61 | using namespace KABC; |
63 | 62 | ||
64 | extern "C" | 63 | extern "C" |
65 | #ifdef _WIN32_ | 64 | #ifdef _WIN32_ |
66 | __declspec(dllexport) | 65 | __declspec(dllexport) |
67 | #else | 66 | #else |
68 | { | 67 | { |
69 | #endif | 68 | #endif |
70 | 69 | ||
71 | //US void *init_kabc_dir() | 70 | //US void *init_kabc_dir() |
72 | void *init_microkabc_dir() | 71 | void *init_microkabc_dir() |
73 | { | 72 | { |
74 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); | 73 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); |
75 | } | 74 | } |
76 | #ifndef _WIN32_ | 75 | #ifndef _WIN32_ |
77 | } | 76 | } |
78 | #endif | 77 | #endif |
79 | 78 | ||
80 | ResourceDir::ResourceDir( const KConfig *config ) | 79 | ResourceDir::ResourceDir( const KConfig *config ) |
81 | : Resource( config ) | 80 | : Resource( config ) |
82 | { | 81 | { |
83 | QString path; | 82 | QString path; |
84 | 83 | ||
85 | KConfig *cfg = (KConfig *)config; | 84 | KConfig *cfg = (KConfig *)config; |
86 | if ( cfg ) { | 85 | if ( cfg ) { |
87 | //US path = config->readEntry( "FilePath" ); | 86 | //US path = config->readEntry( "FilePath" ); |
88 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); | 87 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); |
89 | //US mFormatName = config->readEntry( "FileFormat" ); | 88 | //US mFormatName = config->readEntry( "FileFormat" ); |
90 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); | 89 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); |
91 | } else { | 90 | } else { |
92 | path = StdAddressBook::directoryName(); | 91 | path = StdAddressBook::directoryName(); |
93 | mFormatName = "vcard"; | 92 | mFormatName = "vcard"; |
94 | } | 93 | } |
95 | 94 | ||
96 | 95 | ||
97 | FormatFactory *factory = FormatFactory::self(); | 96 | FormatFactory *factory = FormatFactory::self(); |
98 | mFormat = factory->format( mFormatName ); | 97 | mFormat = factory->format( mFormatName ); |
99 | 98 | ||
100 | if ( !mFormat ) { | 99 | if ( !mFormat ) { |
101 | mFormatName = "vcard"; | 100 | mFormatName = "vcard"; |
102 | mFormat = factory->format( mFormatName ); | 101 | mFormat = factory->format( mFormatName ); |
103 | } | 102 | } |
104 | 103 | ||
105 | /*US | 104 | /*US |
106 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); | 105 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); |
@@ -300,63 +299,66 @@ void ResourceDir::setPath( const QString &path ) | |||
300 | mDirWatch.removeDir( mPath ); | 299 | mDirWatch.removeDir( mPath ); |
301 | 300 | ||
302 | mPath = path; | 301 | mPath = path; |
303 | 302 | ||
304 | mDirWatch.addDir( mPath, true ); | 303 | mDirWatch.addDir( mPath, true ); |
305 | mDirWatch.startScan(); | 304 | mDirWatch.startScan(); |
306 | 305 | ||
307 | //US simulate KDirWatch event | 306 | //US simulate KDirWatch event |
308 | //US pathChanged(); | 307 | //US pathChanged(); |
309 | 308 | ||
310 | } | 309 | } |
311 | 310 | ||
312 | QString ResourceDir::path() const | 311 | QString ResourceDir::path() const |
313 | { | 312 | { |
314 | return mPath; | 313 | return mPath; |
315 | } | 314 | } |
316 | 315 | ||
317 | void ResourceDir::setFormat( const QString &format ) | 316 | void ResourceDir::setFormat( const QString &format ) |
318 | { | 317 | { |
319 | mFormatName = format; | 318 | mFormatName = format; |
320 | 319 | ||
321 | if ( mFormat ) | 320 | if ( mFormat ) |
322 | delete mFormat; | 321 | delete mFormat; |
323 | 322 | ||
324 | FormatFactory *factory = FormatFactory::self(); | 323 | FormatFactory *factory = FormatFactory::self(); |
325 | mFormat = factory->format( mFormatName ); | 324 | mFormat = factory->format( mFormatName ); |
326 | /*US | 325 | /*US |
327 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); | 326 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); |
328 | if (mFormatName == "vcard") | 327 | if (mFormatName == "vcard") |
329 | mFormat = new VCardFormatPlugin2(); | 328 | mFormat = new VCardFormatPlugin2(); |
330 | else if (mFormatName == "binary") | 329 | else if (mFormatName == "binary") |
331 | mFormat = new BinaryFormat(); | 330 | mFormat = new BinaryFormat(); |
332 | else | 331 | else |
333 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); | 332 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); |
334 | */ | 333 | */ |
335 | 334 | ||
336 | } | 335 | } |
337 | 336 | ||
338 | QString ResourceDir::format() const | 337 | QString ResourceDir::format() const |
339 | { | 338 | { |
340 | return mFormatName; | 339 | return mFormatName; |
341 | } | 340 | } |
342 | 341 | ||
343 | void ResourceDir::pathChanged() | 342 | void ResourceDir::pathChanged() |
344 | { | 343 | { |
345 | if ( !addressBook() ) | 344 | if ( !addressBook() ) |
346 | return; | 345 | return; |
347 | 346 | ||
348 | load(); | 347 | QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); |
349 | addressBook()->emitAddressBookChanged(); | 348 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
349 | load(); | ||
350 | addressBook()->emitAddressBookChanged(); | ||
351 | } | ||
350 | } | 352 | } |
351 | 353 | ||
352 | void ResourceDir::removeAddressee( const Addressee& addr ) | 354 | void ResourceDir::removeAddressee( const Addressee& addr ) |
353 | { | 355 | { |
354 | QFile::remove( mPath + "/" + addr.uid() ); | 356 | QFile::remove( mPath + "/" + addr.uid() ); |
355 | } | 357 | } |
356 | 358 | ||
357 | void ResourceDir::cleanUp() | 359 | void ResourceDir::cleanUp() |
358 | { | 360 | { |
359 | unlock( mPath ); | 361 | unlock( mPath ); |
360 | } | 362 | } |
361 | 363 | ||
362 | //US #include "resourcedir.moc" | 364 | //US #include "resourcedir.moc" |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 9f9b00f..1d3acec 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -1,92 +1,93 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #ifndef _WIN32_ | 30 | #ifndef _WIN32_ |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qfileinfo.h> | 35 | #include <qfileinfo.h> |
36 | #include <qregexp.h> | 36 | #include <qregexp.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | 38 | ||
39 | #include <kapplication.h> | 39 | #include <kapplication.h> |
40 | #include <kconfig.h> | 40 | #include <kconfig.h> |
41 | #include <kdebug.h> | 41 | #include <kdebug.h> |
42 | #include <klocale.h> | 42 | #include <klocale.h> |
43 | //US #include <ksavefile.h> | 43 | //US #include <ksavefile.h> |
44 | #include <kstandarddirs.h> | 44 | #include <kstandarddirs.h> |
45 | #include <kmessagebox.h> | ||
45 | 46 | ||
46 | #include "formatfactory.h" | 47 | #include "formatfactory.h" |
47 | 48 | ||
48 | #include "resource.h" | 49 | #include "resource.h" |
49 | #include "resourcefileconfig.h" | 50 | #include "resourcefileconfig.h" |
50 | #include "stdaddressbook.h" | 51 | #include "stdaddressbook.h" |
51 | 52 | ||
52 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
53 | 54 | ||
54 | using namespace KABC; | 55 | using namespace KABC; |
55 | 56 | ||
56 | extern "C" | 57 | extern "C" |
57 | #ifdef _WIN32_ | 58 | #ifdef _WIN32_ |
58 | __declspec(dllexport) | 59 | __declspec(dllexport) |
59 | #else | 60 | #else |
60 | { | 61 | { |
61 | #endif | 62 | #endif |
62 | 63 | ||
63 | //US void *init_kabc_file() | 64 | //US void *init_kabc_file() |
64 | void *init_microkabc_file() | 65 | void *init_microkabc_file() |
65 | { | 66 | { |
66 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); | 67 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); |
67 | } | 68 | } |
68 | #ifndef _WIN32_ | 69 | #ifndef _WIN32_ |
69 | } | 70 | } |
70 | #endif | 71 | #endif |
71 | 72 | ||
72 | ResourceFile::ResourceFile( const KConfig *config ) | 73 | ResourceFile::ResourceFile( const KConfig *config ) |
73 | : Resource( config ) , mFormat( 0 ) | 74 | : Resource( config ) , mFormat( 0 ) |
74 | { | 75 | { |
75 | QString fileName, formatName; | 76 | QString fileName, formatName; |
76 | 77 | ||
77 | KConfig *cfg = (KConfig *)config; | 78 | KConfig *cfg = (KConfig *)config; |
78 | if ( cfg ) { | 79 | if ( cfg ) { |
79 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | 80 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); |
80 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 81 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
81 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | 82 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); |
82 | } else { | 83 | } else { |
83 | fileName = StdAddressBook::fileName(); | 84 | fileName = StdAddressBook::fileName(); |
84 | formatName = "vcard"; | 85 | formatName = "vcard"; |
85 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | 86 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); |
86 | } | 87 | } |
87 | 88 | ||
88 | init( fileName, formatName ); | 89 | init( fileName, formatName ); |
89 | } | 90 | } |
90 | 91 | ||
91 | ResourceFile::ResourceFile( const QString &fileName, | 92 | ResourceFile::ResourceFile( const QString &fileName, |
92 | const QString &formatName ) | 93 | const QString &formatName ) |
@@ -327,65 +328,70 @@ void ResourceFile::setFileName( const QString &fileName ) | |||
327 | 328 | ||
328 | 329 | ||
329 | mDirWatch.addFile( mFileName ); | 330 | mDirWatch.addFile( mFileName ); |
330 | mDirWatch.startScan(); | 331 | mDirWatch.startScan(); |
331 | 332 | ||
332 | //US simulate KDirWatch event | 333 | //US simulate KDirWatch event |
333 | //US fileChanged(); | 334 | //US fileChanged(); |
334 | } | 335 | } |
335 | 336 | ||
336 | QString ResourceFile::fileName() const | 337 | QString ResourceFile::fileName() const |
337 | { | 338 | { |
338 | return mFileName; | 339 | return mFileName; |
339 | } | 340 | } |
340 | 341 | ||
341 | void ResourceFile::setFormat( const QString &format ) | 342 | void ResourceFile::setFormat( const QString &format ) |
342 | { | 343 | { |
343 | mFormatName = format; | 344 | mFormatName = format; |
344 | delete mFormat; | 345 | delete mFormat; |
345 | 346 | ||
346 | FormatFactory *factory = FormatFactory::self(); | 347 | FormatFactory *factory = FormatFactory::self(); |
347 | mFormat = factory->format( mFormatName ); | 348 | mFormat = factory->format( mFormatName ); |
348 | /*US | 349 | /*US |
349 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 350 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
350 | if (mFormatName == "vcard") { | 351 | if (mFormatName == "vcard") { |
351 | mFormat = new VCardFormatPlugin2(); | 352 | mFormat = new VCardFormatPlugin2(); |
352 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 353 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
353 | } | 354 | } |
354 | else if (mFormatName == "binary") { | 355 | else if (mFormatName == "binary") { |
355 | mFormat = new BinaryFormat(); | 356 | mFormat = new BinaryFormat(); |
356 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 357 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
357 | } | 358 | } |
358 | else | 359 | else |
359 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 360 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
360 | */ | 361 | */ |
361 | 362 | ||
362 | } | 363 | } |
363 | 364 | ||
364 | QString ResourceFile::format() const | 365 | QString ResourceFile::format() const |
365 | { | 366 | { |
366 | return mFormatName; | 367 | return mFormatName; |
367 | } | 368 | } |
368 | 369 | ||
369 | void ResourceFile::fileChanged() | 370 | void ResourceFile::fileChanged() |
370 | { | 371 | { |
371 | // There is a small theoretical chance that KDirWatch calls us before | 372 | // There is a small theoretical chance that KDirWatch calls us before |
372 | // we are fully constructed | 373 | // we are fully constructed |
373 | if (!addressBook()) | 374 | if (!addressBook()) |
374 | return; | 375 | return; |
375 | load(); | 376 | |
376 | addressBook()->emitAddressBookChanged(); | 377 | |
378 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | ||
379 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | ||
380 | load(); | ||
381 | addressBook()->emitAddressBookChanged(); | ||
382 | } | ||
377 | } | 383 | } |
378 | 384 | ||
379 | void ResourceFile::removeAddressee( const Addressee &addr ) | 385 | void ResourceFile::removeAddressee( const Addressee &addr ) |
380 | { | 386 | { |
381 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 387 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
382 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 388 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
383 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 389 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
384 | } | 390 | } |
385 | 391 | ||
386 | void ResourceFile::cleanUp() | 392 | void ResourceFile::cleanUp() |
387 | { | 393 | { |
388 | unlock( mFileName ); | 394 | unlock( mFileName ); |
389 | } | 395 | } |
390 | 396 | ||
391 | //US #include "resourcefile.moc" | 397 | //US #include "resourcefile.moc" |
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index 1436508..aaee801 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -1,145 +1,144 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | 31 | ||
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | ||
43 | 44 | ||
44 | //US #include "formatfactory.h" | 45 | //US #include "formatfactory.h" |
45 | //US #include <qpe/qpeapplication.h> | 46 | //US #include <qpe/qpeapplication.h> |
46 | 47 | ||
47 | #include <opie/ocontactaccess.h> | 48 | #include <opie/ocontactaccess.h> |
48 | #include <opie/ocontactaccessbackend_xml.h> | 49 | #include <opie/ocontactaccessbackend_xml.h> |
49 | 50 | ||
50 | #include "resourceopieconfig.h" | 51 | #include "resourceopieconfig.h" |
51 | #include "stdaddressbook.h" | 52 | #include "stdaddressbook.h" |
52 | 53 | ||
53 | #include "opieconverter.h" | 54 | #include "opieconverter.h" |
54 | 55 | ||
55 | #include "resourceopie.h" | 56 | #include "resourceopie.h" |
56 | 57 | ||
57 | using namespace KABC; | 58 | using namespace KABC; |
58 | extern "C" | 59 | extern "C" |
59 | { | 60 | { |
60 | void *init_microkabc_opie() | 61 | void *init_microkabc_opie() |
61 | { | 62 | { |
62 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); | 63 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); |
63 | } | 64 | } |
64 | } | 65 | } |
65 | 66 | ||
66 | ResourceOpie::ResourceOpie( const KConfig *config ) | 67 | ResourceOpie::ResourceOpie( const KConfig *config ) |
67 | : Resource( config ), mConverter (0) | 68 | : Resource( config ), mConverter (0) |
68 | { | 69 | { |
69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 70 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
70 | 71 | ||
71 | KConfig *cfg = (KConfig *)config; | 72 | KConfig *cfg = (KConfig *)config; |
72 | if ( cfg ) { | 73 | if ( cfg ) { |
73 | fileName = cfg->readEntry( "FileName", fileName ); | 74 | fileName = cfg->readEntry( "FileName", fileName ); |
74 | 75 | ||
75 | } | 76 | } |
76 | 77 | ||
77 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | 78 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); |
78 | 79 | ||
79 | init( fileName ); | 80 | init( fileName ); |
80 | } | 81 | } |
81 | 82 | ||
82 | ResourceOpie::ResourceOpie( const QString &fileName ) | 83 | ResourceOpie::ResourceOpie( const QString &fileName ) |
83 | : Resource( 0 ) | 84 | : Resource( 0 ) |
84 | { | 85 | { |
85 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | 86 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); |
86 | init( fileName ); | 87 | init( fileName ); |
87 | } | 88 | } |
88 | 89 | ||
89 | void ResourceOpie::init( const QString &fileName ) | 90 | void ResourceOpie::init( const QString &fileName ) |
90 | { | 91 | { |
91 | 92 | ||
92 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 93 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
93 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 94 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
94 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 95 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
95 | 96 | ||
96 | //US opie addressbook is always readonly | ||
97 | //US setReadOnly( true ); | ||
98 | 97 | ||
99 | setFileName( fileName ); | 98 | setFileName( fileName ); |
100 | 99 | ||
101 | } | 100 | } |
102 | 101 | ||
103 | ResourceOpie::~ResourceOpie() | 102 | ResourceOpie::~ResourceOpie() |
104 | { | 103 | { |
105 | if (mConverter != 0) | 104 | if (mConverter != 0) |
106 | delete mConverter; | 105 | delete mConverter; |
107 | } | 106 | } |
108 | 107 | ||
109 | void ResourceOpie::writeConfig( KConfig *config ) | 108 | void ResourceOpie::writeConfig( KConfig *config ) |
110 | { | 109 | { |
111 | Resource::writeConfig( config ); | 110 | Resource::writeConfig( config ); |
112 | 111 | ||
113 | config->writeEntry( "FileName", mFileName ); | 112 | config->writeEntry( "FileName", mFileName ); |
114 | 113 | ||
115 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 114 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
116 | 115 | ||
117 | } | 116 | } |
118 | 117 | ||
119 | Ticket *ResourceOpie::requestSaveTicket() | 118 | Ticket *ResourceOpie::requestSaveTicket() |
120 | { | 119 | { |
121 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 120 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
122 | 121 | ||
123 | if ( !addressBook() ) return 0; | 122 | if ( !addressBook() ) return 0; |
124 | 123 | ||
125 | if ( !lock( mFileName ) ) { | 124 | if ( !lock( mFileName ) ) { |
126 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | 125 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" |
127 | << mFileName << "'" << endl; | 126 | << mFileName << "'" << endl; |
128 | return 0; | 127 | return 0; |
129 | } | 128 | } |
130 | return createTicket( this ); | 129 | return createTicket( this ); |
131 | } | 130 | } |
132 | 131 | ||
133 | 132 | ||
134 | bool ResourceOpie::doOpen() | 133 | bool ResourceOpie::doOpen() |
135 | { | 134 | { |
136 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); | 135 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); |
137 | /*US | 136 | /*US |
138 | QFile file( mFileName ); | 137 | QFile file( mFileName ); |
139 | 138 | ||
140 | if ( !file.exists() ) { | 139 | if ( !file.exists() ) { |
141 | // try to create the file | 140 | // try to create the file |
142 | bool ok = file.open( IO_WriteOnly ); | 141 | bool ok = file.open( IO_WriteOnly ); |
143 | if ( ok ) | 142 | if ( ok ) |
144 | file.close(); | 143 | file.close(); |
145 | 144 | ||
@@ -326,64 +325,71 @@ bool ResourceOpie::lock( const QString &fileName ) | |||
326 | 325 | ||
327 | // TODO: check stat | 326 | // TODO: check stat |
328 | 327 | ||
329 | return false; | 328 | return false; |
330 | } | 329 | } |
331 | 330 | ||
332 | void ResourceOpie::unlock( const QString &fileName ) | 331 | void ResourceOpie::unlock( const QString &fileName ) |
333 | { | 332 | { |
334 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | 333 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); |
335 | 334 | ||
336 | QString fn = fileName; | 335 | QString fn = fileName; |
337 | //US change the implementation how the lockfilename is getting created | 336 | //US change the implementation how the lockfilename is getting created |
338 | //US fn.replace( QRegExp( "/" ), "_" ); | 337 | //US fn.replace( QRegExp( "/" ), "_" ); |
339 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 338 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
340 | //US QString lockName = fn + ".lock"; | 339 | //US QString lockName = fn + ".lock"; |
341 | KURL url(fn); | 340 | KURL url(fn); |
342 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 341 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
343 | 342 | ||
344 | QFile::remove( lockName ); | 343 | QFile::remove( lockName ); |
345 | QFile::remove( mLockUniqueName ); | 344 | QFile::remove( mLockUniqueName ); |
346 | addressBook()->emitAddressBookUnlocked(); | 345 | addressBook()->emitAddressBookUnlocked(); |
347 | } | 346 | } |
348 | 347 | ||
349 | void ResourceOpie::setFileName( const QString &fileName ) | 348 | void ResourceOpie::setFileName( const QString &fileName ) |
350 | { | 349 | { |
351 | mDirWatch.stopScan(); | 350 | mDirWatch.stopScan(); |
352 | mDirWatch.removeFile( mFileName ); | 351 | mDirWatch.removeFile( mFileName ); |
353 | 352 | ||
354 | mFileName = fileName; | 353 | mFileName = fileName; |
355 | 354 | ||
356 | mDirWatch.addFile( mFileName ); | 355 | mDirWatch.addFile( mFileName ); |
357 | mDirWatch.startScan(); | 356 | mDirWatch.startScan(); |
358 | 357 | ||
359 | //US simulate KDirWatch event | 358 | //US simulate KDirWatch event |
360 | //US fileChanged(); | 359 | //US fileChanged(); |
361 | } | 360 | } |
362 | 361 | ||
363 | QString ResourceOpie::fileName() const | 362 | QString ResourceOpie::fileName() const |
364 | { | 363 | { |
365 | return mFileName; | 364 | return mFileName; |
366 | } | 365 | } |
367 | 366 | ||
368 | void ResourceOpie::fileChanged() | 367 | void ResourceOpie::fileChanged() |
369 | { | 368 | { |
370 | // There is a small theoretical chance that KDirWatch calls us before | 369 | // There is a small theoretical chance that KDirWatch calls us before |
371 | // we are fully constructed | 370 | // we are fully constructed |
372 | if (!addressBook()) | 371 | if (!addressBook()) |
373 | return; | 372 | return; |
373 | |||
374 | QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | ||
375 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | ||
376 | load(); | ||
377 | addressBook()->emitAddressBookChanged(); | ||
378 | } | ||
379 | |||
374 | load(); | 380 | load(); |
375 | addressBook()->emitAddressBookChanged(); | 381 | addressBook()->emitAddressBookChanged(); |
376 | } | 382 | } |
377 | 383 | ||
378 | void ResourceOpie::removeAddressee( const Addressee &addr ) | 384 | void ResourceOpie::removeAddressee( const Addressee &addr ) |
379 | { | 385 | { |
380 | } | 386 | } |
381 | 387 | ||
382 | void ResourceOpie::cleanUp() | 388 | void ResourceOpie::cleanUp() |
383 | { | 389 | { |
384 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); | 390 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); |
385 | 391 | ||
386 | unlock( mFileName ); | 392 | unlock( mFileName ); |
387 | } | 393 | } |
388 | 394 | ||
389 | //US #include "resourceopie.moc" | 395 | //US #include "resourceopie.moc" |
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 4854197..7475685 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -1,90 +1,91 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | //US #include <qtimer.h> | 35 | //US #include <qtimer.h> |
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | ||
43 | 44 | ||
44 | #include <qpe/pim/addressbookaccess.h> | 45 | #include <qpe/pim/addressbookaccess.h> |
45 | 46 | ||
46 | 47 | ||
47 | #include "resourceqtopiaconfig.h" | 48 | #include "resourceqtopiaconfig.h" |
48 | #include "stdaddressbook.h" | 49 | #include "stdaddressbook.h" |
49 | 50 | ||
50 | #include "qtopiaconverter.h" | 51 | #include "qtopiaconverter.h" |
51 | 52 | ||
52 | #include "resourceqtopia.h" | 53 | #include "resourceqtopia.h" |
53 | 54 | ||
54 | using namespace KABC; | 55 | using namespace KABC; |
55 | extern "C" | 56 | extern "C" |
56 | { | 57 | { |
57 | void *init_microkabc_qtopia() | 58 | void *init_microkabc_qtopia() |
58 | { | 59 | { |
59 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); | 60 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); |
60 | } | 61 | } |
61 | } | 62 | } |
62 | 63 | ||
63 | ResourceQtopia::ResourceQtopia( const KConfig *config ) | 64 | ResourceQtopia::ResourceQtopia( const KConfig *config ) |
64 | : Resource( config ), mConverter (0) | 65 | : Resource( config ), mConverter (0) |
65 | { | 66 | { |
66 | // we can not choose the filename. Therefore use the default to display | 67 | // we can not choose the filename. Therefore use the default to display |
67 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 68 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
68 | 69 | ||
69 | init( fileName ); | 70 | init( fileName ); |
70 | } | 71 | } |
71 | 72 | ||
72 | ResourceQtopia::ResourceQtopia( const QString &fileName ) | 73 | ResourceQtopia::ResourceQtopia( const QString &fileName ) |
73 | : Resource( 0 ) | 74 | : Resource( 0 ) |
74 | { | 75 | { |
75 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 76 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
76 | init( fileName ); | 77 | init( fileName ); |
77 | } | 78 | } |
78 | 79 | ||
79 | void ResourceQtopia::init( const QString &fileName ) | 80 | void ResourceQtopia::init( const QString &fileName ) |
80 | { | 81 | { |
81 | 82 | ||
82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 83 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 85 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
85 | 86 | ||
86 | setFileName( fileName ); | 87 | setFileName( fileName ); |
87 | } | 88 | } |
88 | 89 | ||
89 | ResourceQtopia::~ResourceQtopia() | 90 | ResourceQtopia::~ResourceQtopia() |
90 | { | 91 | { |
@@ -290,62 +291,66 @@ bool ResourceQtopia::lock( const QString &fileName ) | |||
290 | return true; | 291 | return true; |
291 | } | 292 | } |
292 | 293 | ||
293 | // TODO: check stat | 294 | // TODO: check stat |
294 | 295 | ||
295 | return false; | 296 | return false; |
296 | } | 297 | } |
297 | 298 | ||
298 | void ResourceQtopia::unlock( const QString &fileName ) | 299 | void ResourceQtopia::unlock( const QString &fileName ) |
299 | { | 300 | { |
300 | QString fn = fileName; | 301 | QString fn = fileName; |
301 | //US change the implementation how the lockfilename is getting created | 302 | //US change the implementation how the lockfilename is getting created |
302 | //US fn.replace( QRegExp( "/" ), "_" ); | 303 | //US fn.replace( QRegExp( "/" ), "_" ); |
303 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 304 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
304 | //US QString lockName = fn + ".lock"; | 305 | //US QString lockName = fn + ".lock"; |
305 | KURL url(fn); | 306 | KURL url(fn); |
306 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 307 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
307 | 308 | ||
308 | QFile::remove( lockName ); | 309 | QFile::remove( lockName ); |
309 | QFile::remove( mLockUniqueName ); | 310 | QFile::remove( mLockUniqueName ); |
310 | addressBook()->emitAddressBookUnlocked(); | 311 | addressBook()->emitAddressBookUnlocked(); |
311 | } | 312 | } |
312 | 313 | ||
313 | void ResourceQtopia::setFileName( const QString &fileName ) | 314 | void ResourceQtopia::setFileName( const QString &fileName ) |
314 | { | 315 | { |
315 | mDirWatch.stopScan(); | 316 | mDirWatch.stopScan(); |
316 | mDirWatch.removeFile( mFileName ); | 317 | mDirWatch.removeFile( mFileName ); |
317 | 318 | ||
318 | mFileName = fileName; | 319 | mFileName = fileName; |
319 | 320 | ||
320 | mDirWatch.addFile( mFileName ); | 321 | mDirWatch.addFile( mFileName ); |
321 | mDirWatch.startScan(); | 322 | mDirWatch.startScan(); |
322 | 323 | ||
323 | //US simulate KDirWatch event | 324 | //US simulate KDirWatch event |
324 | //US fileChanged(); | 325 | //US fileChanged(); |
325 | } | 326 | } |
326 | 327 | ||
327 | QString ResourceQtopia::fileName() const | 328 | QString ResourceQtopia::fileName() const |
328 | { | 329 | { |
329 | return mFileName; | 330 | return mFileName; |
330 | } | 331 | } |
331 | 332 | ||
332 | void ResourceQtopia::fileChanged() | 333 | void ResourceQtopia::fileChanged() |
333 | { | 334 | { |
334 | // There is a small theoretical chance that KDirWatch calls us before | 335 | // There is a small theoretical chance that KDirWatch calls us before |
335 | // we are fully constructed | 336 | // we are fully constructed |
336 | if (!addressBook()) | 337 | if (!addressBook()) |
337 | return; | 338 | return; |
338 | load(); | 339 | |
339 | addressBook()->emitAddressBookChanged(); | 340 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); |
341 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | ||
342 | load(); | ||
343 | addressBook()->emitAddressBookChanged(); | ||
344 | } | ||
340 | } | 345 | } |
341 | 346 | ||
342 | void ResourceQtopia::removeAddressee( const Addressee &addr ) | 347 | void ResourceQtopia::removeAddressee( const Addressee &addr ) |
343 | { | 348 | { |
344 | } | 349 | } |
345 | 350 | ||
346 | void ResourceQtopia::cleanUp() | 351 | void ResourceQtopia::cleanUp() |
347 | { | 352 | { |
348 | unlock( mFileName ); | 353 | unlock( mFileName ); |
349 | } | 354 | } |
350 | 355 | ||
351 | //US #include "resourceqtopia.moc" | 356 | //US #include "resourceqtopia.moc" |