-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 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #ifndef _WIN32_ #include <unistd.h> #endif #include <qregexp.h> #include <qtimer.h> #include <qwidget.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> //US #include <kgenericfactory.h> #include <kglobal.h> #include <klocale.h> #include <kstandarddirs.h> #include <kurlrequester.h> +#include <kmessagebox.h> #include "addressbook.h" #include "formatfactory.h" #include "resourcedirconfig.h" #include "stdaddressbook.h" //US #include <qdir.h> -//US #include "../../formats/vcardformatplugin2.h" -//US #include "../../formats/binaryformat.h" #include "resourcedir.h" using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif //US void *init_kabc_dir() void *init_microkabc_dir() { return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); } #ifndef _WIN32_ } #endif ResourceDir::ResourceDir( const KConfig *config ) : Resource( config ) { QString path; KConfig *cfg = (KConfig *)config; if ( cfg ) { //US path = config->readEntry( "FilePath" ); path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); //US mFormatName = config->readEntry( "FileFormat" ); mFormatName = cfg->readEntry( "FileFormat", "vcard" ); } else { path = StdAddressBook::directoryName(); mFormatName = "vcard"; } FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); if ( !mFormat ) { mFormatName = "vcard"; mFormat = factory->format( mFormatName ); } /*US //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); @@ -300,63 +299,66 @@ void ResourceDir::setPath( const QString &path ) mDirWatch.removeDir( mPath ); mPath = path; mDirWatch.addDir( mPath, true ); mDirWatch.startScan(); //US simulate KDirWatch event //US pathChanged(); } QString ResourceDir::path() const { return mPath; } void ResourceDir::setFormat( const QString &format ) { mFormatName = format; if ( mFormat ) delete mFormat; FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); /*US qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); if (mFormatName == "vcard") mFormat = new VCardFormatPlugin2(); else if (mFormatName == "binary") mFormat = new BinaryFormat(); else qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); */ } QString ResourceDir::format() const { return mFormatName; } void ResourceDir::pathChanged() { if ( !addressBook() ) return; - load(); - addressBook()->emitAddressBookChanged(); + QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); + if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { + load(); + addressBook()->emitAddressBookChanged(); + } } void ResourceDir::removeAddressee( const Addressee& addr ) { QFile::remove( mPath + "/" + addr.uid() ); } void ResourceDir::cleanUp() { unlock( mPath ); } //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 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #ifndef _WIN32_ #include <unistd.h> #endif #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> +#include <kmessagebox.h> #include "formatfactory.h" #include "resource.h" #include "resourcefileconfig.h" #include "stdaddressbook.h" #include "resourcefile.h" using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif //US void *init_kabc_file() void *init_microkabc_file() { return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); } #ifndef _WIN32_ } #endif ResourceFile::ResourceFile( const KConfig *config ) : Resource( config ) , mFormat( 0 ) { QString fileName, formatName; KConfig *cfg = (KConfig *)config; if ( cfg ) { fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); formatName = cfg->readEntry( "FileFormat", "vcard" ); // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); } else { fileName = StdAddressBook::fileName(); formatName = "vcard"; // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); } init( fileName, formatName ); } ResourceFile::ResourceFile( const QString &fileName, const QString &formatName ) @@ -327,65 +328,70 @@ void ResourceFile::setFileName( const QString &fileName ) mDirWatch.addFile( mFileName ); mDirWatch.startScan(); //US simulate KDirWatch event //US fileChanged(); } QString ResourceFile::fileName() const { return mFileName; } void ResourceFile::setFormat( const QString &format ) { mFormatName = format; delete mFormat; FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); /*US //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); if (mFormatName == "vcard") { mFormat = new VCardFormatPlugin2(); // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); } else if (mFormatName == "binary") { mFormat = new BinaryFormat(); // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); } else qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); */ } QString ResourceFile::format() const { return mFormatName; } void ResourceFile::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; - load(); - addressBook()->emitAddressBookChanged(); + + + QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); + if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { + load(); + addressBook()->emitAddressBookChanged(); + } } void ResourceFile::removeAddressee( const Addressee &addr ) { QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); } void ResourceFile::cleanUp() { unlock( mFileName ); } //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 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> +#include <kmessagebox.h> //US #include "formatfactory.h" //US #include <qpe/qpeapplication.h> #include <opie/ocontactaccess.h> #include <opie/ocontactaccessbackend_xml.h> #include "resourceopieconfig.h" #include "stdaddressbook.h" #include "opieconverter.h" #include "resourceopie.h" using namespace KABC; extern "C" { void *init_microkabc_opie() { return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); } } ResourceOpie::ResourceOpie( const KConfig *config ) : Resource( config ), mConverter (0) { QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; KConfig *cfg = (KConfig *)config; if ( cfg ) { fileName = cfg->readEntry( "FileName", fileName ); } // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); init( fileName ); } ResourceOpie::ResourceOpie( const QString &fileName ) : Resource( 0 ) { // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); init( fileName ); } void ResourceOpie::init( const QString &fileName ) { connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); - - //US opie addressbook is always readonly -//US setReadOnly( true ); + setFileName( fileName ); } ResourceOpie::~ResourceOpie() { if (mConverter != 0) delete mConverter; } void ResourceOpie::writeConfig( KConfig *config ) { Resource::writeConfig( config ); config->writeEntry( "FileName", mFileName ); // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); } Ticket *ResourceOpie::requestSaveTicket() { kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; if ( !addressBook() ) return 0; if ( !lock( mFileName ) ) { kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" << mFileName << "'" << endl; return 0; } return createTicket( this ); } bool ResourceOpie::doOpen() { // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); /*US QFile file( mFileName ); if ( !file.exists() ) { // try to create the file bool ok = file.open( IO_WriteOnly ); if ( ok ) file.close(); @@ -326,64 +325,71 @@ bool ResourceOpie::lock( const QString &fileName ) // TODO: check stat return false; } void ResourceOpie::unlock( const QString &fileName ) { // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); QString fn = fileName; //US change the implementation how the lockfilename is getting created //US fn.replace( QRegExp( "/" ), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); //US QString lockName = fn + ".lock"; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceOpie::setFileName( const QString &fileName ) { mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); mFileName = fileName; mDirWatch.addFile( mFileName ); mDirWatch.startScan(); //US simulate KDirWatch event //US fileChanged(); } QString ResourceOpie::fileName() const { return mFileName; } void ResourceOpie::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; + + QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); + if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { + load(); + addressBook()->emitAddressBookChanged(); + } + load(); addressBook()->emitAddressBookChanged(); } void ResourceOpie::removeAddressee( const Addressee &addr ) { } void ResourceOpie::cleanUp() { // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); unlock( mFileName ); } //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 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> //US #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> +#include <kmessagebox.h> #include <qpe/pim/addressbookaccess.h> #include "resourceqtopiaconfig.h" #include "stdaddressbook.h" #include "qtopiaconverter.h" #include "resourceqtopia.h" using namespace KABC; extern "C" { void *init_microkabc_qtopia() { return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); } } ResourceQtopia::ResourceQtopia( const KConfig *config ) : Resource( config ), mConverter (0) { // we can not choose the filename. Therefore use the default to display QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; init( fileName ); } ResourceQtopia::ResourceQtopia( const QString &fileName ) : Resource( 0 ) { // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); init( fileName ); } void ResourceQtopia::init( const QString &fileName ) { connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); setFileName( fileName ); } ResourceQtopia::~ResourceQtopia() { @@ -290,62 +291,66 @@ bool ResourceQtopia::lock( const QString &fileName ) return true; } // TODO: check stat return false; } void ResourceQtopia::unlock( const QString &fileName ) { QString fn = fileName; //US change the implementation how the lockfilename is getting created //US fn.replace( QRegExp( "/" ), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); //US QString lockName = fn + ".lock"; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceQtopia::setFileName( const QString &fileName ) { mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); mFileName = fileName; mDirWatch.addFile( mFileName ); mDirWatch.startScan(); //US simulate KDirWatch event //US fileChanged(); } QString ResourceQtopia::fileName() const { return mFileName; } void ResourceQtopia::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; - load(); - addressBook()->emitAddressBookChanged(); + + QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); + if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { + load(); + addressBook()->emitAddressBookChanged(); + } } void ResourceQtopia::removeAddressee( const Addressee &addr ) { } void ResourceQtopia::cleanUp() { unlock( mFileName ); } //US #include "resourceqtopia.moc" |