diff options
-rw-r--r-- | kaddressbook/kabcore.cpp | 10 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 5 | ||||
-rw-r--r-- | kaddressbook/kaddressbook_part.cpp | 6 | ||||
-rw-r--r-- | kaddressbook/kaddressbook_part.h | 1 | ||||
-rw-r--r-- | kaddressbook/kaddressbookiface.h | 2 | ||||
-rw-r--r-- | kaddressbook/kaddressbookmain.cpp | 6 | ||||
-rw-r--r-- | kaddressbook/kaddressbookmain.h | 1 | ||||
-rw-r--r-- | kontact/plugins/kaddressbook/kaddressbook_plugin.cpp | 4 | ||||
-rw-r--r-- | kontact/plugins/korganizer/korganizerplugin.cpp | 4 | ||||
-rw-r--r-- | korganizer/actionmanager.cpp | 11 | ||||
-rw-r--r-- | korganizer/actionmanager.h | 5 | ||||
-rw-r--r-- | korganizer/korganizeriface.h | 1 | ||||
-rw-r--r-- | korganizer/korganizerifaceimpl.cpp | 6 | ||||
-rw-r--r-- | korganizer/korganizerifaceimpl.h | 1 | ||||
-rw-r--r-- | kresources/carddav/configwidgets.cpp | 26 | ||||
-rw-r--r-- | kresources/carddav/resource.cpp | 10 | ||||
-rw-r--r-- | libkdepim/addresseeview.cpp | 2 | ||||
-rw-r--r-- | libkdepim/kabcresourcecached.cpp | 122 | ||||
-rw-r--r-- | libkdepim/kabcresourcecached.h | 100 |
19 files changed, 289 insertions, 34 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index e15854768..427cb79ab 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -877,6 +877,16 @@ void KABCore::save() } } +void KABCore::load() +{ + TQPtrList<KABC::Resource> resources = mAddressBook->resources(); + TQPtrListIterator<KABC::Resource> it( resources ); + while ( it.current() ) { + mAddressBook->load(); + ++it; + } +} + void KABCore::setJumpButtonBarVisible( bool visible ) { if ( visible ) { diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 5a3b0c4b1..ac2975106 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -332,6 +332,11 @@ class KDE_EXPORT KABCore : public KAB::Core void save(); /** + Loads the contents of the AddressBook from disk. + */ + void load(); + + /** Shows the edit dialog for the given uid. If the uid is TQString::null, the method will try to find a selected addressee in the view. */ diff --git a/kaddressbook/kaddressbook_part.cpp b/kaddressbook/kaddressbook_part.cpp index 3acb85aab..34e651846 100644 --- a/kaddressbook/kaddressbook_part.cpp +++ b/kaddressbook/kaddressbook_part.cpp @@ -154,6 +154,12 @@ bool KAddressbookPart::handleCommandLine() return mCore->handleCommandLine( this ); } +void KAddressbookPart::syncAllResources() +{ + mCore->save(); + mCore->load(); +} + void KAddressbookPart::guiActivateEvent( KParts::GUIActivateEvent *e ) { kdDebug(5720) << "KAddressbookPart::guiActivateEvent" << endl; diff --git a/kaddressbook/kaddressbook_part.h b/kaddressbook/kaddressbook_part.h index 43691f7e4..b0a2c391c 100644 --- a/kaddressbook/kaddressbook_part.h +++ b/kaddressbook/kaddressbook_part.h @@ -59,6 +59,7 @@ class KAddressbookPart: public KParts::ReadOnlyPart, virtual public KAddressBook virtual void exit(); virtual bool openURL( const KURL &url ); virtual bool handleCommandLine(); + virtual void syncAllResources(); protected: virtual bool openFile(); diff --git a/kaddressbook/kaddressbookiface.h b/kaddressbook/kaddressbookiface.h index 448955e81..ffdf941ec 100644 --- a/kaddressbook/kaddressbookiface.h +++ b/kaddressbook/kaddressbookiface.h @@ -67,6 +67,8 @@ class KDE_EXPORT KAddressBookIface : virtual public DCOPObject virtual void loadProfile( const TQString& path ) = 0; virtual void saveToProfile( const TQString& path ) const = 0; + + virtual void syncAllResources() = 0; }; #endif diff --git a/kaddressbook/kaddressbookmain.cpp b/kaddressbook/kaddressbookmain.cpp index 7f521a0c6..f54c18828 100644 --- a/kaddressbook/kaddressbookmain.cpp +++ b/kaddressbook/kaddressbookmain.cpp @@ -129,6 +129,12 @@ bool KAddressBookMain::handleCommandLine() return mCore->handleCommandLine( this ); } +void KAddressBookMain::syncAllResources() +{ + mCore->save(); + mCore->load(); +} + void KAddressBookMain::saveProperties( KConfig* ) { } diff --git a/kaddressbook/kaddressbookmain.h b/kaddressbook/kaddressbookmain.h index 4c9f69fe6..aa1bb4ebd 100644 --- a/kaddressbook/kaddressbookmain.h +++ b/kaddressbook/kaddressbookmain.h @@ -61,6 +61,7 @@ class KAddressBookMain : public KMainWindow, virtual public KAddressBookIface virtual void save(); virtual void exit(); virtual bool handleCommandLine(); + virtual void syncAllResources(); protected: void initActions(); diff --git a/kontact/plugins/kaddressbook/kaddressbook_plugin.cpp b/kontact/plugins/kaddressbook/kaddressbook_plugin.cpp index be1fb08de..e3128cdfb 100644 --- a/kontact/plugins/kaddressbook/kaddressbook_plugin.cpp +++ b/kontact/plugins/kaddressbook/kaddressbook_plugin.cpp @@ -120,8 +120,8 @@ void KAddressbookPlugin::slotNewDistributionList() void KAddressbookPlugin::slotSyncContacts() { - DCOPRef ref( "kmail", "KMailICalIface" ); - ref.send( "triggerSync", TQString("Contact") ); + DCOPRef ref( "kaddressbook", "KAddressBookIface" ); + ref.send( "syncAllResources" ); } bool KAddressbookPlugin::createDCOPInterface( const TQString& serviceType ) diff --git a/kontact/plugins/korganizer/korganizerplugin.cpp b/kontact/plugins/korganizer/korganizerplugin.cpp index a73e551ef..f0f88c7ca 100644 --- a/kontact/plugins/korganizer/korganizerplugin.cpp +++ b/kontact/plugins/korganizer/korganizerplugin.cpp @@ -132,8 +132,8 @@ void KOrganizerPlugin::slotNewEvent() void KOrganizerPlugin::slotSyncEvents() { - DCOPRef ref( "kmail", "KMailICalIface" ); - ref.send( "triggerSync", TQString("Calendar") ); + DCOPRef ref( "korganizer", "KOrganizerIface" ); + ref.send( "syncAllResources" ); } bool KOrganizerPlugin::createDCOPInterface( const TQString& serviceType ) diff --git a/korganizer/actionmanager.cpp b/korganizer/actionmanager.cpp index 8d1bb0aef..99939ef1c 100644 --- a/korganizer/actionmanager.cpp +++ b/korganizer/actionmanager.cpp @@ -1860,6 +1860,17 @@ bool ActionManager::saveResourceCalendar() return true; } +void ActionManager::loadResourceCalendar() +{ + if ( !mCalendarResources ) return; + CalendarResourceManager *m = mCalendarResources->resourceManager(); + + CalendarResourceManager::ActiveIterator it; + for ( it = m->activeBegin(); it != m->activeEnd(); ++it ) { + (*it)->load(); + } +} + void ActionManager::importCalendar( const KURL &url ) { if ( !url.isValid() ) { diff --git a/korganizer/actionmanager.h b/korganizer/actionmanager.h index f19f7b4bb..25fd6fabb 100644 --- a/korganizer/actionmanager.h +++ b/korganizer/actionmanager.h @@ -106,6 +106,11 @@ class KDE_EXPORT ActionManager : public TQObject, public KCalendarIface */ bool saveResourceCalendar(); + /** + Load the resource based calendar. + */ + void loadResourceCalendar(); + public slots: /** Add a new resource */ bool addResource( const KURL &mUrl ); diff --git a/korganizer/korganizeriface.h b/korganizer/korganizeriface.h index b3be3c64a..f3d8a15ea 100644 --- a/korganizer/korganizeriface.h +++ b/korganizer/korganizeriface.h @@ -36,6 +36,7 @@ class KOrganizerIface : virtual public DCOPObject virtual TQString getCurrentURLasString() const = 0; virtual bool editIncidence(const TQString &uid) = 0; virtual bool deleteIncidence(const TQString &uid) = 0; + virtual void syncAllResources() = 0; /** Delete the incidence with the given unique ID from the active calendar. @param uid The incidence's unique ID. diff --git a/korganizer/korganizerifaceimpl.cpp b/korganizer/korganizerifaceimpl.cpp index 7b61f8cf7..77db1afc7 100644 --- a/korganizer/korganizerifaceimpl.cpp +++ b/korganizer/korganizerifaceimpl.cpp @@ -60,6 +60,12 @@ void KOrganizerIfaceImpl::closeURL() return mActionManager->closeURL(); } +void KOrganizerIfaceImpl::syncAllResources() +{ + mActionManager->saveResourceCalendar(); + mActionManager->loadResourceCalendar(); +} + bool KOrganizerIfaceImpl::saveURL() { return mActionManager->saveURL(); diff --git a/korganizer/korganizerifaceimpl.h b/korganizer/korganizerifaceimpl.h index c49d36bb4..03f02a9e8 100644 --- a/korganizer/korganizerifaceimpl.h +++ b/korganizer/korganizerifaceimpl.h @@ -52,6 +52,7 @@ public: bool canQueryClose(); bool saveAsURL( const TQString &url ); TQString getCurrentURLasString() const; + void syncAllResources(); bool editIncidence( const TQString &uid ); /** @reimp from KOrganizerIface::deleteIncidence() */ diff --git a/kresources/carddav/configwidgets.cpp b/kresources/carddav/configwidgets.cpp index baa70b403..90da1831c 100644 --- a/kresources/carddav/configwidgets.cpp +++ b/kresources/carddav/configwidgets.cpp @@ -119,9 +119,6 @@ CardDavReloadConfig::CardDavReloadConfig( TQWidget *parent ) vbox->addWidget(automaticReloadOnStartup); vbox->addWidget(noAutomaticReload); vbox->addStretch(1); - - // FIXME KABC - groupBox->hide(); } CardDavReloadConfig::~CardDavReloadConfig() @@ -131,16 +128,14 @@ CardDavReloadConfig::~CardDavReloadConfig() void CardDavReloadConfig::loadSettings( ResourceCached *resource ) { - // FIXME KABC - //d->mIntervalSpin->setValue( resource->reloadInterval() ); - //d->mGroup->setButton( resource->reloadPolicy() ); + d->mIntervalSpin->setValue( resource->reloadInterval() ); + d->mGroup->setButton( resource->reloadPolicy() ); } void CardDavReloadConfig::saveSettings( ResourceCached *resource ) { - // FIXME KABC - //resource->setReloadInterval( d->mIntervalSpin->value() ); - //resource->setReloadPolicy( d->mGroup->selectedId() ); + resource->setReloadInterval( d->mIntervalSpin->value() ); + resource->setReloadPolicy( d->mGroup->selectedId() ); } void CardDavReloadConfig::slotIntervalToggled( bool checked ) @@ -219,9 +214,6 @@ CardDavSaveConfig::CardDavSaveConfig( TQWidget *parent ) vbox->addWidget(onExit); vbox->addWidget(never); vbox->addStretch(1); - - // FIXME KABC - groupBox->hide(); } CardDavSaveConfig::~CardDavSaveConfig() @@ -231,16 +223,14 @@ CardDavSaveConfig::~CardDavSaveConfig() void CardDavSaveConfig::loadSettings( ResourceCached *resource ) { - // FIXME KABC - //d->mIntervalSpin->setValue( resource->saveInterval() ); - //d->mGroup->setButton( resource->savePolicy() ); + d->mIntervalSpin->setValue( resource->saveInterval() ); + d->mGroup->setButton( resource->savePolicy() ); } void CardDavSaveConfig::saveSettings( ResourceCached *resource ) { - // FIXME KABC - //resource->setSaveInterval( d->mIntervalSpin->value() ); - //resource->setSavePolicy( d->mGroup->selectedId() ); + resource->setSaveInterval( d->mIntervalSpin->value() ); + resource->setSavePolicy( d->mGroup->selectedId() ); } void CardDavSaveConfig::slotIntervalToggled( bool checked ) diff --git a/kresources/carddav/resource.cpp b/kresources/carddav/resource.cpp index 315b6270d..a5172d9e5 100644 --- a/kresources/carddav/resource.cpp +++ b/kresources/carddav/resource.cpp @@ -54,8 +54,8 @@ const int ResourceCardDav::CACHE_DAYS = 90; const int ResourceCardDav::DEFAULT_RELOAD_INTERVAL = 10; const int ResourceCardDav::DEFAULT_SAVE_INTERVAL = 10; -//const int ResourceCardDav::DEFAULT_RELOAD_POLICY = ResourceCached::ReloadInterval; -//const int ResourceCardDav::DEFAULT_SAVE_POLICY = ResourceCached::SaveDelayed; +const int ResourceCardDav::DEFAULT_RELOAD_POLICY = ResourceCached::ReloadInterval; +const int ResourceCardDav::DEFAULT_SAVE_POLICY = ResourceCached::SaveDelayed; /*========================================================================= | UTILITY @@ -237,7 +237,7 @@ CardDavPrefs* ResourceCardDav::createPrefs() const { } void ResourceCardDav::init() { - // default settings +// // default settings // setReloadInterval(DEFAULT_RELOAD_INTERVAL); // setReloadPolicy(DEFAULT_RELOAD_POLICY); // setSaveInterval(DEFAULT_SAVE_INTERVAL); @@ -338,10 +338,6 @@ void ResourceCardDav::loadingQueuePop() { mLoader->setType(0); mLoader->setUseURI(mPrefs->getUseURI()); - //TQDateTime dt(TQDate::currentDate()); - //mLoader->setRange(dt.addDays(-CACHE_DAYS), dt.addDays(CACHE_DAYS)); - //mLoader->setGetAll(); - mLoadingQueueReady = false; log("starting actual download job"); diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp index c250aa495..cde5efe82 100644 --- a/libkdepim/addresseeview.cpp +++ b/libkdepim/addresseeview.cpp @@ -782,7 +782,7 @@ TQString AddresseeView::strippedNumber( const TQString &number ) for ( uint i = 0; i < number.length(); ++i ) { TQChar c = number[ i ]; - if ( c.isDigit() || c == '*' || c == '#' || c == '+' && i == 0 ) + if ( (c.isDigit() || (c == '*') || (c == '#') || (c == '+')) && (i == 0) ) retval.append( c ); } diff --git a/libkdepim/kabcresourcecached.cpp b/libkdepim/kabcresourcecached.cpp index 88d83dcf8..26648e762 100644 --- a/libkdepim/kabcresourcecached.cpp +++ b/libkdepim/kabcresourcecached.cpp @@ -30,19 +30,139 @@ using namespace KABC; ResourceCached::ResourceCached( const KConfig *config ) - : KABC::Resource( config ), mIdMapper( "kabc/uidmaps/" ) + : KABC::Resource( config ), mIdMapper( "kabc/uidmaps/" ), + mReloadPolicy( ReloadInterval ), mReloadInterval( 10 ), + mKABCReloadTimer( 0, "mKABCReloadTimer" ), mReloaded( false ), + mSavePolicy( SaveDelayed ), mSaveInterval( 10 ), + mKABCSaveTimer( 0, "mKABCSaveTimer" ) { + connect( &mKABCReloadTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotKABCReload() ) ); + connect( &mKABCSaveTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotKABCSave() ) ); + + if (config) + this->readConfig(const_cast<KConfig *>(config)); } ResourceCached::~ResourceCached() { } +void ResourceCached::setReloadPolicy( int i ) +{ + mReloadPolicy = i; + + setupReloadTimer(); +} + +int ResourceCached::reloadPolicy() const +{ + return mReloadPolicy; +} + +void ResourceCached::setReloadInterval( int minutes ) +{ + mReloadInterval = minutes; +} + +int ResourceCached::reloadInterval() const +{ + return mReloadInterval; +} + +void ResourceCached::setSavePolicy( int i ) +{ + mSavePolicy = i; + + setupSaveTimer(); +} + +int ResourceCached::savePolicy() const +{ + return mSavePolicy; +} + +void ResourceCached::setSaveInterval( int minutes ) +{ + mSaveInterval = minutes; +} + +int ResourceCached::saveInterval() const +{ + return mSaveInterval; +} + void ResourceCached::writeConfig( KConfig *config ) { + config->writeEntry( "ReloadPolicy", mReloadPolicy ); + config->writeEntry( "ReloadInterval", mReloadInterval ); + + config->writeEntry( "SavePolicy", mSavePolicy ); + config->writeEntry( "SaveInterval", mSaveInterval ); + + config->writeEntry( "LastLoad", mLastLoad ); + config->writeEntry( "LastSave", mLastSave ); + KABC::Resource::writeConfig( config ); } +void ResourceCached::readConfig( KConfig *config ) +{ + mReloadPolicy = config->readNumEntry( "ReloadPolicy", ReloadNever ); + mReloadInterval = config->readNumEntry( "ReloadInterval", 10 ); + + mSaveInterval = config->readNumEntry( "SaveInterval", 10 ); + mSavePolicy = config->readNumEntry( "SavePolicy", SaveNever ); + + mLastLoad = config->readDateTimeEntry( "LastLoad" ); + mLastSave = config->readDateTimeEntry( "LastSave" ); + + setupSaveTimer(); + setupReloadTimer(); +} + +void ResourceCached::setupSaveTimer() +{ + if ( mSavePolicy == SaveInterval ) { + kdDebug(5800) << "ResourceCached::setSavePolicy(): start save timer (interval " + << mSaveInterval << " minutes)." << endl; + mKABCSaveTimer.start( mSaveInterval * 60 * 1000 ); // n minutes + } else { + mKABCSaveTimer.stop(); + } +} + +void ResourceCached::setupReloadTimer() +{ + if ( mReloadPolicy == ReloadInterval ) { + kdDebug(5800) << "ResourceCached::setSavePolicy(): start reload timer " + "(interval " << mReloadInterval << " minutes)" << endl; + mKABCReloadTimer.start( mReloadInterval * 60 * 1000 ); // n minutes + } else { + mKABCReloadTimer.stop(); + } +} + +void ResourceCached::slotKABCReload() +{ + if ( !isActive() ) return; + + kdDebug(5800) << "ResourceCached::slotKABCReload()" << endl; + + load(); +} + +void ResourceCached::slotKABCSave() +{ + if ( !isActive() ) return; + + kdDebug(5800) << "ResourceCached::slotKABCSave()" << endl; + + KABC::Ticket *ticket = requestSaveTicket(); + if ( ticket ) { + save( ticket ); + } +} + void ResourceCached::insertAddressee( const Addressee &addr ) { if ( !mAddrMap.contains( addr.uid() ) ) { // new contact diff --git a/libkdepim/kabcresourcecached.h b/libkdepim/kabcresourcecached.h index c7ea30fe4..00d6f4e8b 100644 --- a/libkdepim/kabcresourcecached.h +++ b/libkdepim/kabcresourcecached.h @@ -24,6 +24,9 @@ #include <kabc/resource.h> #include <kdepimmacros.h> +#include <tqdatetime.h> +#include <tqtimer.h> + #include "libemailfunctions/idmapper.h" namespace KABC { @@ -33,11 +36,86 @@ class KDE_EXPORT ResourceCached : public Resource Q_OBJECT public: + /** + Reload policy. + + @see setReloadPolicy(), reloadPolicy() + */ + enum { ReloadNever, ReloadOnStartup, ReloadInterval }; + /** + Save policy. + + @see setSavePolicy(), savePolicy() + */ + enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways }; + ResourceCached( const KConfig* ); ~ResourceCached(); /** - Writes the resource specific config to file. + Set reload policy. This controls when the cache is refreshed. + + ReloadNever never reload + ReloadOnStartup reload when resource is started + ReloadInterval reload regularly after given interval + */ + void setReloadPolicy( int policy ); + /** + Return reload policy. + + @see setReloadPolicy() + */ + int reloadPolicy() const; + + /** + Set reload interval in minutes which is used when reload policy is + ReloadInterval. + */ + void setReloadInterval( int minutes ); + + /** + Return reload interval in minutes. + */ + int reloadInterval() const; + + /** + Set save policy. This controls when the cache is refreshed. + + SaveNever never save + SaveOnExit save when resource is exited + SaveInterval save regularly after given interval + SaveDelayed save after small delay + SaveAlways save on every change + */ + void setSavePolicy( int policy ); + /** + Return save policy. + + @see setsavePolicy() + */ + int savePolicy() const; + + /** + Set save interval in minutes which is used when save policy is + SaveInterval. + */ + void setSaveInterval( int minutes ); + + /** + Return save interval in minutes. + */ + int saveInterval() const; + + void setupSaveTimer(); + void setupReloadTimer(); + + /** + Reads the resource specific config from disk. + */ + virtual void readConfig( KConfig *config ); + + /** + Writes the resource specific config to disk. */ virtual void writeConfig( KConfig *config ); @@ -85,14 +163,30 @@ class KDE_EXPORT ResourceCached : public Resource void setIdMapperIdentifier(); private: - KPIM::IdMapper mIdMapper; - TQMap<TQString, KABC::Addressee> mAddedAddressees; TQMap<TQString, KABC::Addressee> mChangedAddressees; TQMap<TQString, KABC::Addressee> mDeletedAddressees; + KPIM::IdMapper mIdMapper; + class ResourceCachedPrivate; ResourceCachedPrivate *d; + + int mReloadPolicy; + int mReloadInterval; + TQTimer mKABCReloadTimer; + bool mReloaded; + + int mSavePolicy; + int mSaveInterval; + TQTimer mKABCSaveTimer; + + TQDateTime mLastLoad; + TQDateTime mLastSave; + + protected slots: + void slotKABCReload(); + void slotKABCSave(); }; } |