author | ulf69 <ulf69> | 2004-07-02 15:38:16 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-02 15:38:16 (UTC) |
commit | 30988fc010930d5c43ca7bc51ba64d57210c3985 (patch) (side-by-side diff) | |
tree | 360ccd0055cb11d669f03baa350843e864746785 | |
parent | ead0dcba2c607297137e2b47418eb17864e0caaa (diff) | |
download | kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.zip kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.tar.gz kdepimpi-30988fc010930d5c43ca7bc51ba64d57210c3985.tar.bz2 |
bugfix: choosen filenames where not used while import/export and for resources
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/xxport/opie/opie_xxport.cpp | 10 |
2 files changed, 14 insertions, 3 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index f992301..a4f8d8a 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp @@ -1,96 +1,97 @@ /* 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 <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> //US #include "formatfactory.h" //US #include <qpe/qpeapplication.h> #include <opie/ocontactaccess.h> +#include <opie/ocontactaccessbackend_xml.h> #include "resource.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 ) { /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); @@ -135,131 +136,135 @@ Ticket *ResourceOpie::requestSaveTicket() 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(); return ok; } else { if ( !file.open( IO_ReadWrite ) ) return false; if ( file.size() == 0 ) { file.close(); return true; } //US bool ok = mFormat->checkFormat( &file ); bool ok = true; file.close(); return ok; } */ qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); return true; } void ResourceOpie::doClose() { // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); } bool ResourceOpie::load() { // qDebug("ResourceOpie::load() %s", mFileName.latin1()); kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; - OContactAccess* access = new OContactAccess("KDEPim/Pi", mFileName, 0l, false); + qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); + + OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); + OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); if ( !access ) { qDebug("Unable to load file() %s", mFileName.latin1()); addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); return false; } access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available if (mConverter == 0) mConverter = new OpieConverter(); OContactAccess::List::Iterator it; OContactAccess::List allList = access->allRecords(); bool res = false; for ( it = allList.begin(); it != allList.end(); ++it ) { OContact c = (*it); KABC::Addressee addressee; res = mConverter->opieToAddressee( c, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } // qDebug("found %s", c.fullName().latin1()); } delete access; + delete backend; return true; } bool ResourceOpie::save( Ticket *ticket ) { qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); /*US qDebug("ResourceOpie::save %s", mFileName.latin1()); kdDebug(5700) << "ResourceOpie::save()" << endl; // create backup file QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); */ /*US we use a simpler method to create a backupfile (void) KSaveFile::backupFile( mFileName, QString::null ,extension ); KSaveFile saveFile( mFileName ); bool ok = false; if ( saveFile.status() == 0 && saveFile.file() ) { mFormat->saveAll( addressBook(), this, saveFile.file() ); ok = saveFile.close(); } */ /*US //US ToDo: write backupfile QFile info; info.setName( mFileName ); bool ok = info.open( IO_WriteOnly ); if ( ok ) { //US mFormat->saveAll( addressBook(), this, &info ); info.close(); ok = true; } else { } if ( !ok ) addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); delete ticket; unlock( mFileName ); diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp index 90d05cd..f30a205 100644 --- a/kaddressbook/xxport/opie/opie_xxport.cpp +++ b/kaddressbook/xxport/opie/opie_xxport.cpp @@ -1,196 +1,202 @@ /* This file is part of KAddressbook. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <qdir.h> #include <kfiledialog.h> #include <kmessagebox.h> #include <opie/ocontactaccess.h> +#include <opie/ocontactaccessbackend_xml.h> + #include "stdaddressbook.h" /*US #include <qfile.h> #include <qtextstream.h> #include <kabc/vcardconverter.h> #ifndef KAB_EMBEDDED #include <kio/netaccess.h> #endif //KAB_EMBEDDED #include <klocale.h> #include <kmessagebox.h> #include <ktempfile.h> #include <kurl.h> */ #include "xxportmanager.h" #include "opieconverter.h" #include "opie_xxport.h" class OpieXXPortFactory : public XXPortFactory { public: XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) { return new OpieXXPort( ab, parent, name ); } }; extern "C" { void *init_kaddrbk_opie_xxport() { return ( new OpieXXPortFactory() ); } } OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) : XXPortObject( ab, parent, name ) { createImportAction( i18n( "Import Opie..." ) ); createExportAction( i18n( "Export Opie..." ) ); } bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) { QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; #ifndef KAB_EMBEDDED QString fileName = KFileDialog::getSaveFileName( name ); #else //KAB_EMBEDDED QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); #endif //KAB_EMBEDDED if ( fileName.isEmpty() ) return true; - OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false); + OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); + OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); if ( !access ) { qDebug("Unable to access file() %s", fileName.latin1()); addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); return false; } //Now check if the file has already entries, and ask the user if he wants to delete them first. OContactAccess::List contactList = access->allRecords(); if (contactList.count() > 0) { QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { // Clean the database.. access->clear(); } } KABC::OpieConverter mConverter; bool res; KABC::Addressee::List::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) { OContact c; KABC::Addressee addressee = (*it); res = mConverter.addresseeToOpie( *it, c ); if (res == true) { res = access->add(c); if (res == false) qDebug("Unable to append Contact %s", c.fullName().latin1()); } else { qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } } access->save(); delete access; + delete backend; return true; } KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const { KABC::AddresseeList adrlst; QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; #ifndef KAB_EMBEDDED QString fileName = KFileDialog::getOpenFileName( name ); #else //KAB_EMBEDDED QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() ); #endif //KAB_EMBEDDED if ( fileName.isEmpty() ) return KABC::AddresseeList(); - OContactAccess* access = new OContactAccess("KA/Pi", fileName, 0l, false); + OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName ); + OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false); if ( !access ) { qDebug("Unable to access file() %s", fileName.latin1()); addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) ); return KABC::AddresseeList(); } access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available KABC::OpieConverter mConverter; bool res = false; OContactAccess::List::Iterator it; OContactAccess::List allList = access->allRecords(); for ( it = allList.begin(); it != allList.end(); ++it ) { OContact c = (*it); KABC::Addressee addressee; res = mConverter.opieToAddressee( c, addressee ); if ( !addressee.isEmpty() && res ) { adrlst.append( addressee ); } // qDebug("found %s", c.fullName().latin1()); } delete access; + delete backend; return adrlst; } |