summaryrefslogtreecommitdiffstats
path: root/libkdepim
diff options
context:
space:
mode:
Diffstat (limited to 'libkdepim')
-rw-r--r--libkdepim/addresseeview.cpp2
-rw-r--r--libkdepim/kabcresourcecached.cpp122
-rw-r--r--libkdepim/kabcresourcecached.h100
3 files changed, 219 insertions, 5 deletions
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();
};
}