[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/akonadi/resources/vcard
From:       Bertjan Broeksema <b.broeksema () home ! nl>
Date:       2008-08-22 18:42:33
Message-ID: 1219430553.835157.14977.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 851012 by bbroeksema:

Make the vcard resource a bit more robuust by adding a (configurable) autosave 
function. When changes are made to the resource a timer with a configurable
timeout is started and on timeout the changes are saved.


 M  +19 -0     vcardresource.cpp  
 M  +6 -1      vcardresource.h  
 M  +8 -0      vcardresource.kcfg  


--- trunk/KDE/kdepim/akonadi/resources/vcard/vcardresource.cpp #851011:851012
@@ -39,6 +39,9 @@
   changeRecorder()->itemFetchScope().fetchFullPayload();
   connect( this, SIGNAL(reloadConfiguration()), SLOT(loadAddressees()) );
   loadAddressees();
+
+  connect( &mWriteWhenDirtyTimer, SIGNAL( timeout() ), this, SLOT( storeAddressees() ) );
+  mWriteWhenDirtyTimer.setSingleShot( true );
 }
 
 VCardResource::~VCardResource()
@@ -105,6 +108,8 @@
     Item i( item );
     i.setRemoteId( addressee.uid() );
     changeCommitted( i );
+
+    startAutoSaveTimer();
   } else {
     changeProcessed();
   }
@@ -122,6 +127,8 @@
     Item i( item );
     i.setRemoteId( addressee.uid() );
     changeCommitted( i );
+
+    startAutoSaveTimer();
   } else {
     changeProcessed();
   }
@@ -131,6 +138,9 @@
 {
   if ( mAddressees.contains( item.remoteId() ) )
     mAddressees.remove( item.remoteId() );
+
+  startAutoSaveTimer();
+
   changeProcessed();
 }
 
@@ -218,6 +228,15 @@
   return true;
 }
 
+void VCardResource::startAutoSaveTimer()
+{
+  if( Settings::self()->autosave() && !mWriteWhenDirtyTimer.isActive() )
+  {
+    mWriteWhenDirtyTimer.setInterval( Settings::self()->autosaveInterval() * 60 * 1000 );
+    mWriteWhenDirtyTimer.start();
+  }
+}
+
 AKONADI_RESOURCE_MAIN( VCardResource )
 
 #include "vcardresource.moc"
--- trunk/KDE/kdepim/akonadi/resources/vcard/vcardresource.h #851011:851012
@@ -20,6 +20,8 @@
 #ifndef VCARDRESOURCE_H
 #define VCARDRESOURCE_H
 
+#include <QtCore/QTimer>
+
 #include <akonadi/resourcebase.h>
 
 #include <kabc/addressee.h>
@@ -51,12 +53,15 @@
   private Q_SLOTS:
     bool loadAddressees();
 
-  private:
     bool storeAddressees();
 
   private:
+    void startAutoSaveTimer();
+
+  private:
     QMap<QString, KABC::Addressee> mAddressees;
     KABC::VCardConverter mConverter;
+		QTimer mWriteWhenDirtyTimer;
 };
 
 #endif
--- trunk/KDE/kdepim/akonadi/resources/vcard/vcardresource.kcfg #851011:851012
@@ -9,6 +9,14 @@
       <label>Path to vCard file.</label>
       <default></default>
     </entry>
+    <entry name="Autosave" type="Bool">
+      <label>Saves changes at given interval.</label>
+      <default></default>
+    </entry>
+    <entry name="AutosaveInterval" type="UInt">
+      <label>Autosave interval time (in minutes).</label>
+      <default>1</default>
+    </entry>
     <entry name="ReadOnly" type="Bool">
       <label>Do not change the actual backend data.</label>
       <default>false</default>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic