-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 24 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 98 | ||||
-rw-r--r-- | microkde/kresources/managerimpl.cpp | 9 |
3 files changed, 45 insertions, 86 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index 040226c..106596f 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp @@ -198,303 +198,307 @@ bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) adr.setRole( el.attribute( "JobTitle" ) ); if ( !el.attribute( "FileAs" ).isEmpty() ) adr.setFormattedName( el.attribute( "FileAs" ) ); adr.setOrganization( el.attribute( "Company" ) ); KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ), KABC::PhoneNumber::Work ); KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ), KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ), KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ), KABC::PhoneNumber::Work | KABC::PhoneNumber::Pager ); if ( !businessPhoneNum.number().isEmpty() ) adr.insertPhoneNumber( businessPhoneNum ); if ( !businessFaxNum.number().isEmpty() ) adr.insertPhoneNumber( businessFaxNum ); if ( !businessMobile.number().isEmpty() ) adr.insertPhoneNumber( businessMobile ); if ( !businessPager.number().isEmpty() ) adr.insertPhoneNumber( businessPager ); // Handle multiple mail addresses QString DefaultEmail = el.attribute( "DefaultEmail" ); if ( !DefaultEmail.isEmpty() ) adr.insertEmail( DefaultEmail, true ); // preferred QStringList Emails = QStringList::split(" ",el.attribute("Emails")); int i; for (i = 0;i < Emails.count();++i) { if ( Emails[i] != DefaultEmail ) adr.insertEmail( Emails[i], false ); } KABC::PhoneNumber homePhoneNum( el.attribute( "HomePhone" ), KABC::PhoneNumber::Home ); KABC::PhoneNumber homeFax( el.attribute( "HomeFax" ), KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); KABC::PhoneNumber homeMobile( el.attribute( "HomeMobile" ), KABC::PhoneNumber::Cell ); if ( !homePhoneNum.number().isEmpty() ) adr.insertPhoneNumber( homePhoneNum ); if ( !homeFax.number().isEmpty() ) adr.insertPhoneNumber( homeFax ); if ( !homeMobile.number().isEmpty() ) adr.insertPhoneNumber( homeMobile ); KABC::Address business( KABC::Address::Work ); business.setStreet( el.attribute( "BusinessStreet" ) ); business.setLocality( el.attribute( "BusinessCity" ) ); business.setRegion( el.attribute( "BusinessState" ) ); business.setPostalCode( el.attribute( "BusinessZip" ) ); business.setCountry( el.attribute( "BusinessCountry" ) ); if ( !business.isEmpty() ) adr.insertAddress( business ); KABC::Address home( KABC::Address::Home ); home.setStreet( el.attribute( "HomeStreet" ) ); home.setLocality( el.attribute( "HomeCity" ) ); home.setRegion( el.attribute( "HomeState" ) ); home.setPostalCode( el.attribute( "HomeZip" ) ); home.setCountry( el.attribute( "HomeCountry" ) ); if ( !home.isEmpty() ) adr.insertAddress( home ); adr.setNickName( el.attribute( "Nickname" ) ); adr.setNote( el.attribute( "Notes" ) ); { QStringList categories = QStringList::split(";", el.attribute("Categories" ) ); QString cat; QStringList added; for ( uint i = 0; i < categories.count(); i++ ) { cat = m_edit->categoryById( categories[ i ], "Contacts" ); // if name is not empty and we did not add the // cat try to repair broken files if ( !cat.isEmpty() && !added.contains( cat ) ) { adr.insertCategory( cat ); added << cat; } } } if ( !el.attribute( "Department" ).isEmpty() ) adr.insertCustom( "KADDRESSBOOK", "X-Department", el.attribute( "Department" ) ); if ( !el.attribute( "HomeWebPage" ).isEmpty() ) adr.insertCustom( "opie", "HomeWebPage", el.attribute( "HomeWebPage" ) ); if ( !el.attribute( "Spouse" ).isEmpty() ) adr.insertCustom( "KADDRESSBOOK", "X-SpousesName", el.attribute( "Spouse" ) ); - if ( !el.attribute( "Gender" ).isEmpty() ) - adr.insertCustom( "opie", "Gender", el.attribute( "Gender" ) ); - + if ( !el.attribute( "Gender" ).isEmpty() ) { + if ( el.attribute( "Gender" ) == "1" ) + adr.insertCustom( "KADDRESSBOOK", "X-Gender", "male" ); + else if ( el.attribute( "Gender" ) == "2" ) + adr.insertCustom( "KADDRESSBOOK", "X-Gender", "female" ); + } QDate ann = dateFromString( el.attribute( "Anniversary" ) ); if ( ann.isValid() ) { QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); adr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt ); } if ( !el.attribute( "Children" ).isEmpty() ) - adr.insertCustom("opie", "Children", el.attribute("Children") ); + adr.insertCustom("KADDRESSBOOK", "X-Children", el.attribute("Children") ); if ( !el.attribute( "Office" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") ); if ( !el.attribute( "Profession" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") ); if ( !el.attribute( "Assistant" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") ); if ( !el.attribute( "Manager" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") ); } return true; } bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, QTextStream *stream ) { *stream << "<Contact "; *stream << "FirstName=\"" << escape(ab.givenName()) << "\" "; *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" "; *stream << "LastName=\"" << escape(ab.familyName()) << "\" "; *stream << "Suffix=\"" << escape(ab.suffix()) << "\" "; QString sortStr; sortStr = ab.formattedName(); /* is formattedName is empty we use the assembled name as fallback */ if (sortStr.isEmpty() ) sortStr = ab.assembledName(); *stream << "FileAs=\"" << escape(sortStr) << "\" "; *stream << "JobTitle=\"" << escape(ab.role()) << "\" "; *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" "; *stream << "Company=\"" << escape(ab.organization()) << "\" "; KABC::PhoneNumber businessPhoneNum = ab.phoneNumber(KABC::PhoneNumber::Work ); *stream << "BusinessPhone=\"" << escape( businessPhoneNum.number() ) << "\" "; KABC::PhoneNumber businessFaxNum = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); *stream << "BusinessFax=\"" << escape( businessFaxNum.number() )<< "\" "; KABC::PhoneNumber businessMobile = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); *stream << "BusinessMobile=\"" << escape( businessMobile.number() ) << "\" "; *stream << "DefaultEmail=\"" << escape( ab.preferredEmail() ) << "\" "; QStringList list = ab.emails(); if ( list.count() > 0 ) { QStringList::Iterator it = list.begin(); *stream << "Emails=\"" << escape( *it ); while (++it != list.end()) *stream << ' ' << escape( *it ); *stream << "\" "; } KABC::PhoneNumber homePhoneNum = ab.phoneNumber(KABC::PhoneNumber::Home ); *stream << "HomePhone=\"" << escape( homePhoneNum.number() ) << "\" "; KABC::PhoneNumber homeFax = ab.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); *stream << "HomeFax=\"" << escape( homeFax.number() ) << "\" "; KABC::PhoneNumber homeMobile = ab.phoneNumber( KABC::PhoneNumber::Cell ); *stream << "HomeMobile=\"" << escape( homeMobile.number() ) << "\" "; KABC::Address business = ab.address(KABC::Address::Work ); *stream << "BusinessStreet=\"" << escape( business.street() ) << "\" "; *stream << "BusinessCity=\"" << escape( business.locality() ) << "\" "; *stream << "BusinessZip=\"" << escape( business.postalCode() ) << "\" "; *stream << "BusinessCountry=\"" << escape( business.country() ) << "\" "; *stream << "BusinessState=\"" << escape( business.region() ) << "\" "; //stream << "BusinessPager=\"" << << "\" "; *stream << "Office=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Office" ) ) << "\" "; *stream << "Profession=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Profession" ) ) << "\" "; *stream << "Assistant=\"" << escape( ab.custom( "KADDRESSBOOK", "X-AssistantsName") ) << "\" "; *stream << "Manager=\"" << escape( ab.custom( "KADDRESSBOOK", "X-ManagersName" ) ) << "\" "; KABC::Address home = ab.address( KABC::Address::Home ); *stream << "HomeStreet=\"" << escape( home.street() ) << "\" "; *stream << "HomeCity=\"" << escape( home.locality() ) << "\" "; *stream << "HomeState=\"" << escape( home.region() ) << "\" "; *stream << "HomeZip=\"" << escape( home.postalCode() ) << "\" "; *stream << "HomeCountry=\"" << escape( home.country() ) << "\" "; *stream << "HomeWebPage=\"" << escape( ab.custom( "opie", "HomeWebPage" ) ) << "\" "; *stream << "Spouse=\"" << escape( ab.custom( "KADDRESSBOOK", "X-SpousesName") ) << "\" "; - *stream << "Gender=\"" << escape( ab.custom( "opie", "Gender") ) << "\" "; + QString gen = "0"; + if ( ab.custom( "KADDRESSBOOK", "X-Gender") == "male" ) + gen = "1"; + else if ( ab.custom( "KADDRESSBOOK", "X-Gender") == "female" ) + gen = "2"; + *stream << "Gender=\"" << escape( gen ) << "\" "; if ( ab.birthday().date().isValid() ) *stream << "Birthday=\"" << escape( dateToString(ab.birthday().date() ) ) << "\" "; - /* - * Anniversary block again - * Go from ISO -> QDate -> toString and then escape - */ { QDate ann = KGlobal::locale()->readDate( ab.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); if (ann.isValid() ) { *stream << "Anniversary=\"" << escape( dateToString( ann ) ) << "\" "; } } *stream << "Nickname=\"" << escape( ab.nickName() ) << "\" "; - *stream << "Children=\"" << escape( ab.custom("opie", "Children" ) ) << "\" "; + *stream << "Children=\"" << escape( ab.custom("KADDRESSBOOK", "X-Children" ) ) << "\" "; *stream << "Notes=\"" << escape( ab.note() ) << "\" "; *stream << "Categories=\"" << categoriesToNumber( ab.categories(), "Contacts") << "\" "; QString uid = ab.uid(); *stream << "Uid=\"" << uid << "\" "; //*stream << map.toString( "addressbook", uid ); *stream << " />" << "\n"; return true; } #if 0 KTempFile* AddressBook::fromKDE( KSync::AddressBookSyncee *syncee, ExtraMap& map ) { } QStringList AddressBook::attributes()const { QStringList lst; lst << "FirstName"; lst << "MiddleName"; lst << "LastName"; lst << "Suffix"; lst << "FileAs"; lst << "JobTitle"; lst << "Department"; lst << "Company"; lst << "BusinessPhone"; lst << "BusinessFax"; lst << "BusinessMobile"; lst << "DefaultEmail"; lst << "Emails"; lst << "HomePhone"; lst << "HomeFax"; lst << "HomeMobile"; lst << "BusinessStreet"; lst << "BusinessCity"; lst << "BusinessZip"; lst << "BusinessCountry"; lst << "BusinessState"; lst << "Office"; lst << "Profession"; lst << "Assistant"; lst << "Manager"; lst << "HomeStreet"; lst << "HomeCity"; lst << "HomeState"; lst << "HomeZip"; lst << "HomeCountry"; lst << "HomeWebPage"; lst << "Spouse"; lst << "Gender"; lst << "Anniversary"; lst << "Nickname"; lst << "Children"; lst << "Notes"; lst << "Categories"; lst << "Uid"; lst << "Birthday"; return lst; } #endif CategoryEdit::CategoryEdit(){ } CategoryEdit::CategoryEdit(const QString &fileName){ parse( fileName ); } CategoryEdit::~CategoryEdit(){ } void CategoryEdit::save(const QString& fileName)const{ QFile file( fileName ); QString endl = "\n"; if ( file.open( IO_WriteOnly ) ) { QTextStream stream( &file ); stream.setEncoding( QTextStream::UnicodeUTF8 ); stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; stream << "<!DOCTYPE CategoryList>" << endl; stream << "<Categories>" << endl; for ( QValueList<OpieCategories>::ConstIterator it = m_categories.begin(); it != m_categories.end(); ++it ) { stream << "<Category id=\""<< ( (*it).id() ) << "\" "; if ( !(*it).app().isEmpty() ) stream << " app=\""<< ( (*it).app() ) << "\" "; stream << "name=\"" << ( (*it).name() ) << "\" "; stream << " />" << endl; diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index b7263bb..4ee3c3c 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -1,382 +1,330 @@ /* 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 <qtextstream.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 ) { init( fileName ); } void ResourceQtopia::init( const QString &fileName ) { - +#ifdef _USE_DIRWATCH_ connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); - +#endif setFileName( fileName ); } ResourceQtopia::~ResourceQtopia() { if (mConverter != 0) delete mConverter; } void ResourceQtopia::writeConfig( KConfig *config ) { Resource::writeConfig( config ); } Ticket *ResourceQtopia::requestSaveTicket() { kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); if ( !addressBook() ) return 0; if ( !lock( fileName() ) ) { kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" << fileName() << "'" << endl; return 0; } return createTicket( this ); } bool ResourceQtopia::doOpen() { qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); if (mConverter == 0) { mConverter = new QtopiaConverter(); bool res = mConverter->init(); if ( !res ) { QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); qDebug(msg); return false; } } return true; } void ResourceQtopia::doClose() { qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); // it seems so, that deletion of access deletes backend as well //delete backend; return; } bool ResourceQtopia::load() { QFile file( fileName() ); if ( !file.open(IO_ReadOnly ) ) { return false; } QDomDocument doc("mydocument" ); if ( !doc.setContent( &file ) ) { file.close(); return false; } bool res; QDomElement docElem = doc.documentElement( ); QDomNode n = docElem.firstChild(); while ( !n.isNull() ) { QDomElement e = n.toElement(); if ( !e.isNull() ) { - if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { // we're looking for them + if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { QDomNode no = e.firstChild(); while ( !no.isNull() ) { QDomElement el = no.toElement(); if ( !el.isNull() ) { KABC::Addressee addressee; res = mConverter->qtopiaToAddressee( el, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } no = no.nextSibling(); } } } n = n.nextSibling(); } - -#if 0 -/ old code - qDebug("ResourceQtopia::load: %s", fileName().latin1()); - - AddressBookIterator it(*mAccess); - const PimContact* contact; - bool res; - - for (contact=it.toFirst(); it.current(); ++it) - { - contact = it.current(); - - KABC::Addressee addressee; - - //LRres = mConverter->qtopiaToAddressee( (*contact), addressee ); - - if ( !addressee.isEmpty() && res ) - { - addressee.setResource( this ); - addressBook()->insertAddressee( addressee ); - } - } -#endif return true; } bool ResourceQtopia::save( Ticket *ticket ) { - +#ifdef _USE_DIRWATCH_ mDirWatch.stopScan(); +#endif KABC::AddressBook::Iterator it; - bool res; - //pending open file for stream - QTextStream *stream;// = tempFile->textStream(); + bool res; + QFile file( fileName() ); + if (!file.open( IO_WriteOnly ) ) { + return false; + } + QTextStream ts( &file ); + QTextStream *stream = &ts; stream->setEncoding( QTextStream::UnicodeUTF8 ); *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; *stream << " <Groups>" << endl; *stream << " </Groups>" << endl; *stream << " <Contacts> " << endl; // for all entries KABC::Addressee ab; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { KABC::Addressee addressee = (*it); res = mConverter->addresseeToQtopia( addressee, stream ); if (!res == true) { qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } } - - *stream << "</Contacts>" << endl; *stream << "</AddressBook>" << endl; - //pending close file + file.close(); +#ifdef _USE_DIRWATCH_ mDirWatch.startScan(); - +#endif delete ticket; unlock( fileName() ); - - -#if 0 - //old code - qDebug("ResourceQtopia::save: %s", fileName().latin1()); - - mDirWatch.stopScan(); - - KABC::AddressBook::Iterator it; - bool res; - - for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { - PimContact c; - KABC::Addressee addressee = (*it); - - //res = mConverter->addresseeToQtopia( *it, c ); - if (res == true) - { - mAccess->addContact(c); -// if (res == false) -// qDebug("Unable to append Contact %s", c.fullName().latin1()); - } - else - { - qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); - } - } - -// mAccess->addressBookUpdated(); - - mDirWatch.startScan(); - - delete ticket; - unlock( fileName() ); -#endif return true; } bool ResourceQtopia::lock( const QString &lockfileName ) { + //disabled + return true; qDebug("ResourceQtopia::lock: %s", fileName().latin1()); - - kdDebug(5700) << "ResourceQtopia::lock()" << endl; - QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); - kdDebug(5700) << "-- lock name: " << lockName << endl; - if (QFile::exists( lockName )) { qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); #endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; } void ResourceQtopia::unlock( const QString &fileName ) { + //disabled + return; qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); QString fn = fileName; 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 &newFileName ) { +#ifdef _USE_DIRWATCH_ mDirWatch.stopScan(); +#endif mDirWatch.removeFile( fileName() ); Resource::setFileName( newFileName ); mDirWatch.addFile( fileName() ); +#ifdef _USE_DIRWATCH_ mDirWatch.startScan(); +#endif } void ResourceQtopia::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } } void ResourceQtopia::removeAddressee( const Addressee &addr ) { } void ResourceQtopia::cleanUp() { unlock( fileName() ); } //US #include "resourceqtopia.moc" diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp index 81bbbec..5bd9eb7 100644 --- a/microkde/kresources/managerimpl.cpp +++ b/microkde/kresources/managerimpl.cpp @@ -1,166 +1,173 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> Copyright (c) 2003 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 <kglobal.h> #include <kapplication.h> #include <kdebug.h> #include <kconfig.h> #include <kstandarddirs.h> +#include <qfile.h> #include "resource.h" #include "factory.h" #include "managerimpl.h" using namespace KRES; ManagerImpl::ManagerImpl( const QString &family ) : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), mFactory( 0 ) { kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; } ManagerImpl::~ManagerImpl() { kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; Resource::List::ConstIterator it; for ( it = mResources.begin(); it != mResources.end(); ++it ) { delete *it; } delete mStdConfig; } void ManagerImpl::createStandardConfig() { if ( !mStdConfig ) { QString file = locateLocal( "data", KGlobal::getAppName() - + "/kresources/" + mFamily + "rc" ); + + "/kresources/" + mFamily + "rc" ); + if ( mFamily == "tmpcontact" ) { + if (QFile::exists ( file ) ){ + QFile::remove ( file ); + qDebug("removed tmp rc file: %s ", file.latin1()); + } + } mStdConfig = new KConfig( file ); } mConfig = mStdConfig; } void ManagerImpl::readConfig( KConfig *cfg ) { kdDebug(5650) << "ManagerImpl::readConfig()" << endl; delete mFactory; mFactory = Factory::self( mFamily ); if ( !cfg ) { createStandardConfig(); } else { mConfig = cfg; } mStandard = 0; mConfig->setGroup( "General" ); QStringList keys = mConfig->readListEntry( "ResourceKeys" ); keys += mConfig->readListEntry( "PassiveResourceKeys" ); QString standardKey = mConfig->readEntry( "Standard" ); for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { readResourceConfig( *it, false ); } } void ManagerImpl::writeConfig( KConfig *cfg ) { //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; if ( !cfg ) { createStandardConfig(); } else { mConfig = cfg; } QStringList activeKeys; QStringList passiveKeys; // First write all keys, collect active and passive keys on the way Resource::List::Iterator it; for ( it = mResources.begin(); it != mResources.end(); ++it ) { writeResourceConfig( *it, false ); QString key = (*it)->identifier(); if( (*it)->isActive() ) activeKeys.append( key ); else passiveKeys.append( key ); } // And then the general group kdDebug(5650) << "Saving general info" << endl; mConfig->setGroup( "General" ); mConfig->writeEntry( "ResourceKeys", activeKeys ); mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); if ( mStandard ) mConfig->writeEntry( "Standard", mStandard->identifier() ); else mConfig->writeEntry( "Standard", "" ); mConfig->sync(); kdDebug(5650) << "ManagerImpl::save() finished" << endl; //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); } void ManagerImpl::add( Resource *resource, bool useDCOP ) { qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); resource->setActive( true ); if ( mResources.isEmpty() ) { mStandard = resource; } mResources.append( resource ); writeResourceConfig( resource, true ); qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); |