author | zautrix <zautrix> | 2004-10-13 14:23:28 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-13 14:23:28 (UTC) |
commit | 2cfda2af7cba3c9aff2d7722421b5d33b7f56cb6 (patch) (side-by-side diff) | |
tree | f1e664ddf31aae347b1a119c9111cbd1c931bf89 | |
parent | d41893fb0a49fbb080326a4c1fd98e1a032a182a (diff) | |
download | kdepimpi-2cfda2af7cba3c9aff2d7722421b5d33b7f56cb6.zip kdepimpi-2cfda2af7cba3c9aff2d7722421b5d33b7f56cb6.tar.gz kdepimpi-2cfda2af7cba3c9aff2d7722421b5d33b7f56cb6.tar.bz2 |
more sync fixes
-rw-r--r-- | kabc/addressbook.cpp | 35 | ||||
-rw-r--r-- | kabc/addressbook.h | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 146 | ||||
-rw-r--r-- | microkde/kresources/configdialog.cpp | 5 | ||||
-rw-r--r-- | microkde/kresources/configdialog.h | 1 | ||||
-rw-r--r-- | microkde/kresources/resource.cpp | 14 | ||||
-rw-r--r-- | microkde/kresources/resource.h | 2 |
7 files changed, 119 insertions, 86 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 8882259..592d78d 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -283,327 +283,338 @@ void AddressBook::init(const QString &config, const QString &family ) KRES::Manager<Resource> *manager = d->mManager; KRES::Manager<Resource>::ActiveIterator it; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { (*it)->setAddressBook( this ); if ( !(*it)->open() ) error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); } Resource *res = standardResource(); if ( !res ) { qDebug("ERROR: no standard resource"); res = manager->createResource( "file" ); if ( res ) { addResource( res ); } else qDebug(" No resource available!!!"); } setStandardResource( res ); manager->writeConfig(); } addCustomField( i18n( "Department" ), KABC::Field::Organization, "X-Department", "KADDRESSBOOK" ); addCustomField( i18n( "Profession" ), KABC::Field::Organization, "X-Profession", "KADDRESSBOOK" ); addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, "X-AssistantsName", "KADDRESSBOOK" ); addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, "X-ManagersName", "KADDRESSBOOK" ); addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, "X-SpousesName", "KADDRESSBOOK" ); addCustomField( i18n( "Office" ), KABC::Field::Personal, "X-Office", "KADDRESSBOOK" ); addCustomField( i18n( "IM Address" ), KABC::Field::Personal, "X-IMAddress", "KADDRESSBOOK" ); addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, "X-Anniversary", "KADDRESSBOOK" ); //US added this field to become compatible with Opie/qtopia addressbook // values can be "female" or "male" or "". An empty field represents undefined. addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, "X-FreeBusyUrl", "KADDRESSBOOK" ); addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, "X-ExternalID", "KADDRESSBOOK" ); } AddressBook::~AddressBook() { delete d->mConfig; d->mConfig = 0; delete d->mManager; d->mManager = 0; //US delete d->mErrorHandler; d->mErrorHandler = 0; delete d; d = 0; } bool AddressBook::load() { clear(); KRES::Manager<Resource>::ActiveIterator it; bool ok = true; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) if ( !(*it)->load() ) { qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); ok = false; } else { qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); } // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { (*addrIt).setChanged( false ); QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); if ( !id.isEmpty() ) { //qDebug("setId aa %s ", id.latin1()); (*addrIt).setIDStr(id ); } } blockLSEchange = true; return ok; } bool AddressBook::save( Ticket *ticket ) { kdDebug(5700) << "AddressBook::save()"<< endl; if ( ticket->resource() ) { deleteRemovedAddressees(); return ticket->resource()->save( ticket ); } return false; } +// exports all Addressees, which are syncable void AddressBook::export2File( QString fileName ) { QFile outFile( fileName ); if ( !outFile.open( IO_WriteOnly ) ) { QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); KMessageBox::error( 0, text.arg( fileName ) ); return ; } QTextStream t( &outFile ); t.setEncoding( QTextStream::UnicodeUTF8 ); Iterator it; KABC::VCardConverter::Version version; version = KABC::VCardConverter::v3_0; - for ( it = begin(); it != end(); ++it ) { - if ( !(*it).IDStr().isEmpty() ) { - (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); + for ( it = begin(); it != end(); ++it ) { + if ( (*it).resource() && (*it).resource()->includeInSync() ) { + if ( !(*it).IDStr().isEmpty() ) { + (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); + } + KABC::VCardConverter converter; + QString vcard; + //Resource *resource() const; + converter.addresseeToVCard( *it, vcard, version ); + t << vcard << "\r\n"; } - KABC::VCardConverter converter; - QString vcard; - //Resource *resource() const; - converter.addresseeToVCard( *it, vcard, version ); - t << vcard << "\r\n"; } t << "\r\n\r\n"; outFile.close(); } // if QStringList uids is empty, all are exported bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) { KABC::VCardConverter converter; QString datastream; Iterator it; bool all = uids.isEmpty(); for ( it = begin(); it != end(); ++it ) { // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { if ( ! all ) { if ( ! ( uids.contains((*it).uid() ) )) continue; - } + } KABC::Addressee a = ( *it ); if ( a.isEmpty() ) continue; + if ( all && a.resource() && !a.resource()->includeInSync() ) + continue; a.simplifyEmails(); a.simplifyPhoneNumbers(); a.simplifyPhoneNumberTypes(); a.simplifyAddresses(); QString vcard; QString vcardnew; converter.addresseeToVCard( a, vcard ); int start = 0; int next; while ( (next = vcard.find("TYPE=", start) )>= 0 ) { int semi = vcard.find(";", next); int dopp = vcard.find(":", next); int sep; if ( semi < dopp && semi >= 0 ) sep = semi ; else sep = dopp; vcardnew +=vcard.mid( start, next - start); vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); start = sep; } vcardnew += vcard.mid( start,vcard.length() ); vcard = ""; start = 0; while ( (next = vcardnew.find("ADR", start) )>= 0 ) { int sep = vcardnew.find(":", next); vcard +=vcardnew.mid( start, next - start+3); start = sep; } vcard += vcardnew.mid( start,vcardnew.length() ); vcard.replace ( QRegExp(";;;") , "" ); vcard.replace ( QRegExp(";;") , "" ); datastream += vcard; } QFile outFile(fileName); if ( outFile.open(IO_WriteOnly) ) { datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); QTextStream t( &outFile ); // use a text stream t.setEncoding( QTextStream::UnicodeUTF8 ); t <<datastream; t << "\r\n\r\n"; outFile.close(); } else { qDebug("Error open temp file "); return false; } return true; } void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) { if ( removeOld ) - setUntagged(); + setUntagged( true ); KABC::Addressee::List list; QFile file( fileName ); file.open( IO_ReadOnly ); QByteArray rawData = file.readAll(); file.close(); QString data; if ( replaceLabel ) { data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); data.replace ( QRegExp("LABEL") , "ADR" ); data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); } else data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); if ( !id.isEmpty() ) (*it).setIDStr(id ); (*it).setResource( 0 ); if ( replaceLabel ) (*it).removeVoice(); if ( removeOld ) (*it).setTagged( true ); insertAddressee( (*it), false, true ); } if ( removeOld ) removeUntagged(); } -void AddressBook::setUntagged() +void AddressBook::setUntagged(bool setNonSyncTagged) // = false) { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { - (*ait).setTagged( false ); + if ( setNonSyncTagged ) { + if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { + (*ait).setTagged( true ); + } else + (*ait).setTagged( false ); + } else + (*ait).setTagged( false ); } } void AddressBook::removeUntagged() { Iterator ait; bool todelete = false; Iterator todel; for ( ait = begin(); ait != end(); ++ait ) { if ( todelete ) removeAddressee( todel ); if (!(*ait).tagged()) { todelete = true; todel = ait; } else todelete = false; } if ( todelete ) removeAddressee( todel ); deleteRemovedAddressees(); } void AddressBook::smplifyAddressees() { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { (*ait).simplifyEmails(); (*ait).simplifyPhoneNumbers(); (*ait).simplifyPhoneNumberTypes(); (*ait).simplifyAddresses(); } } void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { QString id = (*ait).IDStr(); (*ait).setIDStr( ":"); (*ait).setExternalUID( id ); (*ait).setOriginalExternalUID( id ); if ( isPreSync ) (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); else { (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); (*ait).setID( currentSyncDevice,id ); } } } void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) { setUntagged(); KABC::Addressee::List list; QFile file( fileName ); file.open( IO_ReadOnly ); QByteArray rawData = file.readAll(); file.close(); QString data; data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( !(*ait).tagged() ) { if ( (*ait).containsAdr(*it)) { (*ait).setTagged(true); QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); (*it).setIDStr( ":"); (*it).setID( currentSyncDevice,id ); (*it).setExternalUID( id ); (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); (*it).setUid( ( (*ait).uid() )); break; } } } if ( ait == end() ) qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); } clear(); for ( it = list.begin(); it != list.end(); ++it ) { insertAddressee( (*it) ); } } bool AddressBook::saveABphone( QString fileName ) { //smplifyAddressees(); qDebug("saveABphone:: saving AB... "); if ( ! export2PhoneFormat( QStringList() ,fileName ) ) return false; qDebug("saveABphone:: writing to phone... "); if ( !PhoneAccess::writeToPhone( fileName) ) { diff --git a/kabc/addressbook.h b/kabc/addressbook.h index a6bf451..23bba02 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -55,193 +55,193 @@ class AddressBook : public QObject friend QDataStream &operator>>( QDataStream &, AddressBook & ); friend class StdAddressBook; public: /** @short Address Book Iterator This class provides an iterator for address book entries. */ class Iterator { public: Iterator(); Iterator( const Iterator & ); ~Iterator(); Iterator &operator=( const Iterator & ); const Addressee &operator*() const; Addressee &operator*(); Addressee* operator->(); Iterator &operator++(); Iterator &operator++(int); Iterator &operator--(); Iterator &operator--(int); bool operator==( const Iterator &it ); bool operator!=( const Iterator &it ); struct IteratorData; IteratorData *d; }; /** @short Address Book Const Iterator This class provides a const iterator for address book entries. */ class ConstIterator { public: ConstIterator(); ConstIterator( const ConstIterator & ); ~ConstIterator(); ConstIterator &operator=( const ConstIterator & ); const Addressee &operator*() const; const Addressee* operator->() const; ConstIterator &operator++(); ConstIterator &operator++(int); ConstIterator &operator--(); ConstIterator &operator--(int); bool operator==( const ConstIterator &it ); bool operator!=( const ConstIterator &it ); struct ConstIteratorData; ConstIteratorData *d; }; /** Constructs a address book object. @param format File format class. */ AddressBook(); AddressBook( const QString &config ); AddressBook( const QString &config, const QString &family ); virtual ~AddressBook(); /** Requests a ticket for saving the addressbook. Calling this function locks the addressbook for all other processes. If the address book is already locked the function returns 0. You need the returned @ref Ticket object for calling the @ref save() function. @see save() */ Ticket *requestSaveTicket( Resource *resource=0 ); /** Load address book from file. */ bool load(); /** Save address book. The address book is saved to the file, the Ticket object has been requested for by @ref requestSaveTicket(). @param ticket a ticket object returned by @ref requestSaveTicket() */ bool save( Ticket *ticket ); bool saveAB( ); bool saveABphone( QString fileName ); void smplifyAddressees(); void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); void export2File( QString fileName ); bool export2PhoneFormat( QStringList uids ,QString fileName ); void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); - void setUntagged(); + void setUntagged( bool setNonSyncTagged = false ); void removeUntagged(); void findNewExtIds( QString fileName, QString currentSyncDevice ); /** Returns a iterator for first entry of address book. */ Iterator begin(); /** Returns a const iterator for first entry of address book. */ ConstIterator begin() const; /** Returns a iterator for first entry of address book. */ Iterator end(); /** Returns a const iterator for first entry of address book. */ ConstIterator end() const; /** Removes all entries from address book. */ void clear(); /** Insert an Addressee object into address book. If an object with the same unique id already exists in the address book it it replaced by the new one. If not the new object is appended to the address book. */ void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); /** Removes entry from the address book. */ void removeAddressee( const Addressee & ); /** This is like @ref removeAddressee() just above, with the difference that the first element is a iterator, returned by @ref begin(). */ void removeAddressee( const Iterator & ); /** Find the specified entry in address book. Returns end(), if the entry couldn't be found. */ Iterator find( const Addressee & ); /** Find the entry specified by an unique id. Returns an empty Addressee object, if the address book does not contain an entry with this id. */ Addressee findByUid( const QString & ); /** Returns a list of all addressees in the address book. This list can be sorted with @ref KABC::AddresseeList for example. */ Addressee::List allAddressees(); /** Find all entries with the specified name in the address book. Returns an empty list, if no entries could be found. */ Addressee::List findByName( const QString & ); /** Find all entries with the specified email address in the address book. Returns an empty list, if no entries could be found. */ Addressee::List findByEmail( const QString & ); /** Find all entries wich have the specified category in the address book. Returns an empty list, if no entries could be found. */ Addressee::List findByCategory( const QString & ); /** Return a string identifying this addressbook. */ virtual QString identifier(); /** Used for debug output. */ void dump() const; void emitAddressBookLocked() { emit addressBookLocked( this ); } void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } void emitAddressBookChanged() { emit addressBookChanged( this ); } diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index ea34be2..47ed858 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2458,318 +2458,322 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo int deletedAddresseeL = 0; int changedLocal = 0; int changedRemote = 0; QString mCurrentSyncName = syncManager->getCurrentSyncName(); QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); //QPtrList<Addressee> el = local->rawAddressees(); Addressee addresseeR; QString uid; int take; Addressee addresseeL; Addressee addresseeRSync; Addressee addresseeLSync; // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); bool fullDateRange = false; local->resetTempSyncStat(); mLastAddressbookSync = QDateTime::currentDateTime(); QDateTime modifiedCalendar = mLastAddressbookSync;; addresseeLSync = getLastSyncAddressee(); qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); if ( !addresseeR.isEmpty() ) { addresseeRSync = addresseeR; remote->removeAddressee(addresseeR ); } else { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { addresseeRSync = addresseeLSync ; } else { qDebug("FULLDATE 1"); fullDateRange = true; Addressee newAdd; addresseeRSync = newAdd; addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setCategories( i18n("SyncAddressee") ); } } if ( addresseeLSync.revision() == mLastAddressbookSync ) { qDebug("FULLDATE 2"); fullDateRange = true; } if ( ! fullDateRange ) { if ( addresseeLSync.revision() != addresseeRSync.revision() ) { // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); fullDateRange = true; qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); } } // fullDateRange = true; // debug only! if ( fullDateRange ) mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); else mLastAddressbookSync = addresseeLSync.revision(); // for resyncing if own file has changed // PENDING fixme later when implemented #if 0 if ( mCurrentSyncDevice == "deleteaftersync" ) { mLastAddressbookSync = loadedFileVersion; qDebug("setting mLastAddressbookSync "); } #endif //qDebug("*************************** "); // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); QStringList er = remote->uidList(); Addressee inR ;//= er.first(); Addressee inL; syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); int modulo = (er.count()/10)+1; int incCounter = 0; while ( incCounter < er.count()) { if (syncManager->isProgressBarCanceled()) return false; if ( incCounter % modulo == 0 ) syncManager->showProgressBar(incCounter); uid = er[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; QString idS,OidS; qApp->processEvents(); if ( !skipIncidence ) { inL = local->findByUid( uid ); inR = remote->findByUid( uid ); //inL.setResource( 0 ); //inR.setResource( 0 ); if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars - if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { - //qDebug("take %d %s ", take, inL.summary().latin1()); - if ( take == 3 ) - return false; - if ( take == 1 ) {// take local - if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { - inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); - inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); - local->insertAddressee( inL, false ); - idS = inR.externalUID(); - OidS = inR.originalExternalUID(); - } - else - idS = inR.IDStr(); - remote->removeAddressee( inR ); - inR = inL; - inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); - if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { - inR.setOriginalExternalUID( OidS ); - inR.setExternalUID( idS ); - } else { - inR.setIDStr( idS ); - } - inR.setResource( 0 ); - remote->insertAddressee( inR , false); - ++changedRemote; - } else { // take == 2 take remote - if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { - if ( inR.revision().date().year() < 2004 ) - inR.setRevision( modifiedCalendar ); - } - idS = inL.IDStr(); - local->removeAddressee( inL ); - inL = inR; - inL.setIDStr( idS ); - if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { - inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); - inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); + if ( !inL.resource() || inL.resource()->includeInSync() ) { + if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { + //qDebug("take %d %s ", take, inL.summary().latin1()); + if ( take == 3 ) + return false; + if ( take == 1 ) {// take local + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); + inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); + local->insertAddressee( inL, false ); + idS = inR.externalUID(); + OidS = inR.originalExternalUID(); + } + else + idS = inR.IDStr(); + remote->removeAddressee( inR ); + inR = inL; + inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + inR.setOriginalExternalUID( OidS ); + inR.setExternalUID( idS ); + } else { + inR.setIDStr( idS ); + } + inR.setResource( 0 ); + remote->insertAddressee( inR , false); + ++changedRemote; + } else { // take == 2 take remote + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + if ( inR.revision().date().year() < 2004 ) + inR.setRevision( modifiedCalendar ); + } + idS = inL.IDStr(); + local->removeAddressee( inL ); + inL = inR; + inL.setIDStr( idS ); + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); + inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); + } + inL.setResource( 0 ); + local->insertAddressee( inL , false ); + ++changedLocal; } - inL.setResource( 0 ); - local->insertAddressee( inL , false ); - ++changedLocal; } } } else { // no conflict if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = addresseeLSync.note(); if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); remote->insertAddressee( inR, false ); ++deletedAddresseeR; } else { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inL = inR; inL.setResource( 0 ); local->insertAddressee( inL , false); ++addedAddressee; } } else { if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inR.setResource( 0 ); local->insertAddressee( inR, false ); ++addedAddressee; } else { // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); remote->removeAddressee( inR ); ++deletedAddresseeR; } } } } ++incCounter; } er.clear(); QStringList el = local->uidList(); modulo = (el.count()/10)+1; syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); incCounter = 0; while ( incCounter < el.count()) { qApp->processEvents(); if (syncManager->isProgressBarCanceled()) return false; if ( incCounter % modulo == 0 ) syncManager->showProgressBar(incCounter); uid = el[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; if ( !skipIncidence ) { inL = local->findByUid( uid ); - inR = remote->findByUid( uid ); - if ( inR.isEmpty() ) { - if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { - if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { - // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); - local->removeAddressee( inL ); - ++deletedAddresseeL; - } else { - if ( ! syncManager->mWriteBackExistingOnly ) { - inL.removeID(mCurrentSyncDevice ); - ++addedAddresseeR; - inL.setRevision( modifiedCalendar ); - local->insertAddressee( inL, false ); - inR = inL; - inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); - inR.setResource( 0 ); - remote->insertAddressee( inR, false ); + if ( !inL.resource() || inL.resource()->includeInSync() ) { + inR = remote->findByUid( uid ); + if ( inR.isEmpty() ) { + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { + // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); + local->removeAddressee( inL ); + ++deletedAddresseeL; + } else { + if ( ! syncManager->mWriteBackExistingOnly ) { + inL.removeID(mCurrentSyncDevice ); + ++addedAddresseeR; + inL.setRevision( modifiedCalendar ); + local->insertAddressee( inL, false ); + inR = inL; + inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); + inR.setResource( 0 ); + remote->insertAddressee( inR, false ); + } } - } - } else { - if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { - // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); - local->removeAddressee( inL ); - ++deletedAddresseeL; } else { - if ( ! syncManager->mWriteBackExistingOnly ) { - ++addedAddresseeR; - inL.setRevision( modifiedCalendar ); - local->insertAddressee( inL, false ); - inR = inL; - inR.setResource( 0 ); - remote->insertAddressee( inR, false ); + if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { + // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); + local->removeAddressee( inL ); + ++deletedAddresseeL; + } else { + if ( ! syncManager->mWriteBackExistingOnly ) { + ++addedAddresseeR; + inL.setRevision( modifiedCalendar ); + local->insertAddressee( inL, false ); + inR = inL; + inR.setResource( 0 ); + remote->insertAddressee( inR, false ); + } } } } } } ++incCounter; } el.clear(); syncManager->hideProgressBar(); mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); // get rid of micro seconds QTime t = mLastAddressbookSync.time(); mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); addresseeLSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); addresseeRSync.setNote( "" ) ; addresseeLSync.setNote( "" ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) remote->insertAddressee( addresseeRSync, false ); local->insertAddressee( addresseeLSync, false ); QString mes; mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); if ( syncManager->mShowSyncSummary ) { KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); } qDebug( mes ); return syncOK; } //this is a overwritten callbackmethods from the syncinterface bool KABCore::sync(KSyncManager* manager, QString filename, int mode) { //pending prepare addresseeview for output //pending detect, if remote file has REV field. if not switch to external sync mGlobalSyncMode = SYNC_MODE_NORMAL; QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal(filename,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; isXML = true; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); } else { external = !manager->mIsKapiFile; if ( external ) { qDebug("Setting vcf mode to external "); mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { (*it).setID( mCurrentSyncDevice, (*it).uid() ); (*it).computeCsum( mCurrentSyncDevice ); } } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); if ( ! abLocal.saveAB()) qDebug("Error writing back AB to file "); if ( isXML ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } diff --git a/microkde/kresources/configdialog.cpp b/microkde/kresources/configdialog.cpp index f8240f9..030b547 100644 --- a/microkde/kresources/configdialog.cpp +++ b/microkde/kresources/configdialog.cpp @@ -1,241 +1,246 @@ /* 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. */ #include <klocale.h> #include <kglobal.h> #include <kmessagebox.h> #include <qgroupbox.h> #include <qlabel.h> #include <qlayout.h> #include <qpushbutton.h> #include <qvbox.h> #include <qcheckbox.h> #include <qscrollview.h> #include <kbuttonbox.h> #include <kdialog.h> #include <klineedit.h> #include "factory.h" #include "configwidget.h" #include "configdialog.h" #include "syncwidget.h" using namespace KRES; ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, Resource* resource, const char *name ) : KDialogBase( parent, name, true, resource->isSyncable()?i18n( "Sync Profile Configuration" ):i18n( "Resource Configuration" ), Ok|Cancel, Ok, true )/*, mConfig( config )*/, mSyncWidget_Settings(0), mSyncWidget_Conflicts(0),mSyncWidget_Remote(0), mResource( resource ), mPersistentReadOnly(false) { Factory *factory = Factory::self( resourceFamily ); //US resize( 250, 240 ); resize( KMIN(KGlobal::getDesktopWidth(), 250), KMIN(KGlobal::getDesktopHeight(), 240)); QFrame *main; if (!mResource->isSyncable()) main = plainPage(); else main = addPage("Profile"); QVBoxLayout *mainLayout = new QVBoxLayout( main, 0, spacingHint() ); QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); generalGroupBox->layout()->setSpacing( spacingHint() ); generalGroupBox->setTitle( i18n( "General Settings" ) ); new QLabel( mResource->isSyncable()?i18n( "Profile Name:" ):i18n( "Name:" ), generalGroupBox ); mName = new KLineEdit( generalGroupBox ); if (!mResource->isSyncable()) { + new QLabel("", generalGroupBox ); mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox ); mReadOnly->setChecked( mResource->readOnly() ); + new QLabel("", generalGroupBox ); + mIncludeInSync = new QCheckBox( i18n( "Include in sync" ), generalGroupBox ); + mIncludeInSync->setChecked( mResource->includeInSync() ); } mName->setText( mResource->resourceName() ); mainLayout->addWidget( generalGroupBox ); QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); resourceGroupBox->layout()->setSpacing( spacingHint()); resourceGroupBox->setTitle( i18n( "%1 Resource Settings" ) .arg( factory->typeName( resource->type() ) ) ); mainLayout->addWidget( resourceGroupBox ); mainLayout->addStretch(); mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox ); if ( mConfigWidget ) { connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ), SLOT( setReadOnly( bool ) ) ); connect( mConfigWidget, SIGNAL( setPersistentReadOnly( bool ) ), SLOT( setPersistentReadOnly( bool ) ) ); mConfigWidget->setInEditMode( false ); mConfigWidget->loadSettings( mResource ); mConfigWidget->show(); } if (mResource->isSyncable()) { SyncWidgetContainer* c = factory->syncWidgetContainer( resource->type() ); QFrame* syncPage = addPage("Settings"); QVBoxLayout *syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() ); mSyncWidget_Settings = c->generateSettingsTab(syncPage); syncLayout->addWidget( mSyncWidget_Settings ); syncPage = addPage("Conflicts"); syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() ); mSyncWidget_Conflicts = c->generateConflictsTab(syncPage); syncLayout->addWidget( mSyncWidget_Conflicts ); syncPage = addPage("Remote"); syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() ); mSyncWidget_Remote = c->generateRemoteTab(syncPage); syncLayout->addWidget( mSyncWidget_Remote ); mSyncWidget_Settings->setInEditMode( false ); mSyncWidget_Settings->loadSettings( mResource ); mSyncWidget_Settings->show(); mSyncWidget_Conflicts->setInEditMode( false ); mSyncWidget_Conflicts->loadSettings( mResource ); mSyncWidget_Conflicts->show(); mSyncWidget_Remote->setInEditMode( false ); mSyncWidget_Remote->loadSettings( mResource ); mSyncWidget_Remote->show(); delete c; // QGroupBox *syncGroupBox = new QGroupBox( 2, Qt::Horizontal, syncPage ); // syncGroupBox->layout()->setSpacing( spacingHint()); // syncGroupBox->setTitle( i18n( "Syncronize Preferences" ) ); // syncLayout->addWidget( syncGroupBox ); // syncLayout->addStretch(); /*US mSyncWidget = factory->syncWidget( resource->type(), syncPage ); syncLayout->addWidget( mSyncWidget ); if ( mSyncWidget ) { mSyncWidget->setInEditMode( false ); mSyncWidget->loadSettings( mResource ); mSyncWidget->show(); } */ } connect( mName, SIGNAL( textChanged(const QString &)), SLOT( slotNameChanged(const QString &))); slotNameChanged( mName->text() ); //US setMinimumSize( 400, 250 ); setMinimumSize( KMIN(KGlobal::getDesktopWidth(), 400), KMIN(KGlobal::getDesktopHeight(), 250)); } void ConfigDialog::setInEditMode( bool value ) { if ( mConfigWidget ) mConfigWidget->setInEditMode( value ); if ( mSyncWidget_Settings ) mSyncWidget_Settings->setInEditMode( value ); if ( mSyncWidget_Conflicts ) mSyncWidget_Conflicts->setInEditMode( value ); if ( mSyncWidget_Remote ) mSyncWidget_Remote->setInEditMode( value ); } void ConfigDialog::slotNameChanged( const QString &text) { enableButtonOK( !text.isEmpty() ); } void ConfigDialog::setReadOnly( bool value ) { if (!mResource->isSyncable()) { if (mPersistentReadOnly == false) mReadOnly->setChecked( value ); else mReadOnly->setChecked( true ); } } void ConfigDialog::setPersistentReadOnly( bool value ) { if (!mResource->isSyncable()) { mPersistentReadOnly = value; if (value == true) setReadOnly( true ); mReadOnly->setEnabled( !value ); } } void ConfigDialog::accept() { if ( mName->text().isEmpty() ) { KMessageBox::sorry( this, mResource->isSyncable()?i18n( "Please enter a profile name" ):i18n( "Please enter a resource name" ) ); return; } mResource->setResourceName( mName->text() ); if (!mResource->isSyncable()) mResource->setReadOnly( mReadOnly->isChecked() ); + mResource->setIncludeInSync( mIncludeInSync->isChecked() ); if ( mConfigWidget ) { // First save generic information // Also save setting of specific resource type mConfigWidget->saveSettings( mResource ); } if ( mSyncWidget_Settings ) mSyncWidget_Settings->saveSettings( mResource ); if ( mSyncWidget_Conflicts ) mSyncWidget_Conflicts->saveSettings( mResource ); if ( mSyncWidget_Remote ) mSyncWidget_Remote->saveSettings( mResource ); KDialog::accept(); } //US #include "configdialog.moc" diff --git a/microkde/kresources/configdialog.h b/microkde/kresources/configdialog.h index 63cd4e9..ed3ecab 100644 --- a/microkde/kresources/configdialog.h +++ b/microkde/kresources/configdialog.h @@ -1,67 +1,68 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.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. */ #ifndef KRESOURCES_CONFIGDIALOG_H #define KRESOURCES_CONFIGDIALOG_H #include <kdialogbase.h> class KLineEdit; class QCheckBox; class KButtonBox; namespace KRES { class Resource; class ConfigWidget; class SyncWidget; class ConfigDialog : public KDialogBase { Q_OBJECT public: // Resource=0: create new resource ConfigDialog( QWidget *parent, const QString& resourceFamily, Resource* resource, const char *name = 0); void setInEditMode( bool value ); protected slots: void accept(); void setReadOnly( bool value ); void setPersistentReadOnly( bool value ); void slotNameChanged( const QString &text); private: ConfigWidget *mConfigWidget; SyncWidget *mSyncWidget_Settings; SyncWidget *mSyncWidget_Conflicts; SyncWidget *mSyncWidget_Remote; Resource* mResource; KLineEdit *mName; QCheckBox *mReadOnly; + QCheckBox *mIncludeInSync; //US add a persistent readonly flag. We need that for opie and qtopia addressbooks. bool mPersistentReadOnly; }; } #endif diff --git a/microkde/kresources/resource.cpp b/microkde/kresources/resource.cpp index 4f69540..f79bcd0 100644 --- a/microkde/kresources/resource.cpp +++ b/microkde/kresources/resource.cpp @@ -1,194 +1,204 @@ /* This file is part of libkresources. Copyright (c) 2001 Cornelius Schumacher <schumacher@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. */ #include <kdebug.h> #include <kapplication.h> #include <kconfig.h> #include "resource.h" using namespace KRES; class Resource::ResourcePrivate { public: #ifdef QT_THREAD_SUPPORT QMutex mMutex; #endif int mOpenCount; QString mType; QString mIdentifier; bool mReadOnly; + bool mIncludeInSync; QString mName; bool mActive; bool mIsOpen; }; Resource::Resource( const KConfig* config ) : QObject( 0, "" ), d( new ResourcePrivate ) { d->mOpenCount = 0; d->mIsOpen = false; //US compiler claimed that const discards qualifier KConfig* cfg = (KConfig*)config; if ( cfg ) { #ifdef _WIN32_ // we use plugins on win32. the group is stored in a static variable // such that group info not available on win32 plugins // to fix that, it would be a looooot of work if ( !cfg->tempGroup().isEmpty() ) cfg->setGroup( cfg->tempGroup() ); #endif d->mType = cfg->readEntry( "ResourceType" ); d->mName = cfg->readEntry( "ResourceName" ); d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false ); + d->mIncludeInSync = cfg->readBoolEntry( "ResourceIncludeInSync", true );; d->mActive = cfg->readBoolEntry( "ResourceIsActive", true ); d->mIdentifier = cfg->readEntry( "ResourceIdentifier" ); } else { d->mType = "type"; d->mName = "resource-name"; d->mReadOnly = false; + d->mIncludeInSync = true; d->mActive = true; d->mIdentifier = KApplication::randomString( 10 ); } } Resource::~Resource() { delete d; d = 0; } void Resource::writeConfig( KConfig* config ) { - - config->writeEntry( "ResourceType", d->mType ); config->writeEntry( "ResourceName", d->mName ); config->writeEntry( "ResourceIsReadOnly", d->mReadOnly ); + config->writeEntry( "ResourceIncludeInSync", d->mIncludeInSync ); config->writeEntry( "ResourceIsActive", d->mActive ); config->writeEntry( "ResourceIdentifier", d->mIdentifier ); } bool Resource::open() { d->mIsOpen = true; #ifdef QT_THREAD_SUPPORT QMutexLocker guard( &(d->mMutex) ); #endif if ( !d->mOpenCount ) { kdDebug(5650) << "Opening resource " << resourceName() << endl; d->mIsOpen = doOpen(); } d->mOpenCount++; return d->mIsOpen; } void Resource::close() { #ifdef QT_THREAD_SUPPORT QMutexLocker guard( &(d->mMutex) ); #endif if ( !d->mOpenCount ) { kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl; return; } d->mOpenCount--; if ( !d->mOpenCount ) { kdDebug(5650) << "Closing resource " << resourceName() << endl; doClose(); d->mIsOpen = false; } else { kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl; } } bool Resource::isOpen() const { return d->mIsOpen; } void Resource::setIdentifier( const QString& identifier ) { d->mIdentifier = identifier; } QString Resource::identifier() const { return d->mIdentifier; } void Resource::setType( const QString& type ) { d->mType = type; } QString Resource::type() const { return d->mType; } +void Resource::setIncludeInSync( bool value ) +{ + d->mIncludeInSync = value; +} +bool Resource::includeInSync() const +{ + return d->mIncludeInSync; +} void Resource::setReadOnly( bool value ) { d->mReadOnly = value; } bool Resource::readOnly() const { return d->mReadOnly; } void Resource::setResourceName( const QString &name ) { d->mName = name; } QString Resource::resourceName() const { return d->mName; } void Resource::setActive( bool value ) { d->mActive = value; } bool Resource::isActive() const { return d->mActive; } void Resource::dump() const { qDebug("Resource::dump() "); kdDebug(5650) << "Resource:" << endl; kdDebug(5650) << " Name: " << d->mName << endl; kdDebug(5650) << " Identifier: " << d->mIdentifier << endl; kdDebug(5650) << " Type: " << d->mType << endl; kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl; kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl; kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl; kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl; } diff --git a/microkde/kresources/resource.h b/microkde/kresources/resource.h index 580b5d1..70b5613 100644 --- a/microkde/kresources/resource.h +++ b/microkde/kresources/resource.h @@ -217,192 +217,194 @@ X-KDE-Library=resourceexample <pre> kde_module_LTLIBRARIES = resourceexample.la resourceexample_la_SOURCES = resourceexample.cpp resourceexampleconfig.cpp resourceexample_la_LDFLAGS= $(all_libraries) -module $(KDE_PLUGIN) resourceexample_la_LIBADD= -lkderesources linkdir= $(kde_datadir)/resources/family link_DATA= resourceexample.desktop </pre> * * */ /** * A @ref Resource is a ... * * A subclass should reimplement at least the constructor and the * @ref writeConfig method. * */ class Resource : public QObject { Q_OBJECT public: typedef QValueList<Resource *> List; /** * Constructor. Construct resource from config. * @param config Configuration to read persistence information from. * If config==0, create object using default settings. */ Resource( const KConfig* config ); /** * Destructor. */ virtual ~Resource(); /** * Write configuration information for this resource to a configuration * file. If you override this method, remember to call Resource::writeConfig * or Terrible Things(TM) will happen. * @param config Configuration to write persistence information to. */ virtual void writeConfig( KConfig* config ); /** * Open this resource, if it not already open. Increase the open * count of this object, and open the resource by calling @ref doOpen(). * This method may block while another thread is concurrently opening * or closing the resource. * * Returns true if the resource was already opened or if it was opened * successfully; returns false if the resource was not opened successfully. */ bool open(); /** * Decrease the open count of this object, and if the count reaches * zero, close this resource by calling @ref doClose(). * This method may block while another thread is concurrently closing * or opening the resource. */ void close(); /** * Returns whether the resource is open or not. */ bool isOpen() const; /** * Returns a unique identifier. The identifier is unique for this resource. * It is created when the resource is first created, and it is retained * in the resource family configuration file for this resource. * @return This resource's identifier */ QString identifier() const; /** * Returns the type of this resource. */ QString type() const; /** * Mark the resource as read-only. You can override this method, * but also remember to call Resource::setReadOnly(). */ virtual void setReadOnly( bool value ); /** * Returns, if the resource is read-only. */ virtual bool readOnly() const; + void setIncludeInSync( bool value ); + bool includeInSync() const; /** * Set the name of resource.You can override this method, * but also remember to call Resource::setResourceName(). */ virtual void setResourceName( const QString &name ); /** * Returns the name of resource. */ virtual QString resourceName() const; virtual bool isSyncable() const = 0; /** Sets, if the resource is active. */ void setActive( bool active ); /** Return true, if the resource is active. */ bool isActive() const; friend class Factory; friend class ManagerImpl; /** Print resource information as debug output. */ virtual void dump() const; protected: /** * Open this resource. When called, the resource must be in * a closed state. * * Returns true if the resource was opened successfully; * returns false if the resource was not opened successfully. * * The result of this call can be accessed later by @ref isOpen() */ virtual bool doOpen() { return true; } /** * Close this resource. Pre-condition: resource is open. * Post-condition: resource is closed. */ virtual void doClose() {} void setIdentifier( const QString& identifier ); void setType( const QString& type ); private: class ResourcePrivate; ResourcePrivate *d; }; class PluginFactoryBase : public KLibFactory { public: virtual Resource *resource( const KConfig *config, bool syncable ) = 0; virtual ConfigWidget *configWidget( QWidget *parent ) = 0; virtual SyncWidgetContainer *syncWidgetContainer() = 0; protected: virtual QObject* createObject( QObject*, const char*, const char*, const QStringList & ) { return 0; } }; template<class TR,class TC, class TS> class PluginFactory : public PluginFactoryBase { public: Resource *resource( const KConfig *config, bool syncable ) { return new TR( config, syncable ); } ConfigWidget *configWidget( QWidget *parent ) { return new TC( parent ); } SyncWidgetContainer *syncWidgetContainer() { return new TS(); } |