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

List:       kde-commits
Subject:    KDE/kdepim/akonadi/resources/kabc
From:       Kevin Krammer <kevin.krammer () gmx ! at>
Date:       2008-08-27 9:17:40
Message-ID: 1219828660.980556.29862.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 853119 by krake:

Implemented online/offline state handling:
- open, connect signals and load the resource on offline -> online
- close and disconnect signals on online -> offline


 M  +49 -4     kabcresource.cpp  
 M  +5 -1      kabcresource.h  


--- trunk/KDE/kdepim/akonadi/resources/kabc/kabcresource.cpp #853118:853119
@@ -132,7 +132,7 @@
 
   mAddressBook->addResource( mBaseResource );
 
-  if ( !initConfiguration() ) {
+  if ( !openConfiguration() ) {
     const QString message = i18nc( "@info:status", "Initialization based on newly \
created configuration failed." );  emit error( message );
     emit status( Broken, message );
@@ -271,6 +271,19 @@
   saveAddressBook();
 }
 
+void KABCResource::doSetOnline( bool online )
+{
+  kDebug() << "online" << online << "resource" << (void*) mBaseResource;
+
+  if ( online ) {
+    reloadConfiguration();
+  } else {
+    closeConfiguration();
+  }
+
+  ResourceBase::doSetOnline( online );
+}
+
 void KABCResource::itemAdded( const Akonadi::Item &item, const Akonadi::Collection& \
col )  {
   kDebug() << "item id=" << item.id() << ", remoteId=" << item.remoteId();
@@ -358,7 +371,7 @@
     mBaseResource->setAddressBook( mAddressBook );
 }
 
-bool KABCResource::initConfiguration()
+bool KABCResource::openConfiguration()
 {
   if ( mBaseResource != 0 ) {
     if ( !mBaseResource->isOpen() ) {
@@ -391,6 +404,33 @@
   return true;
 }
 
+void KABCResource::closeConfiguration()
+{
+  // do not react on addressbook changes until we have finished its initial loading
+  mAddressBook->blockSignals( true );
+
+  if ( mBaseResource != 0 ) {
+    disconnect( mBaseResource, SIGNAL( loadingError( Resource*, const QString& ) ),
+                this, SLOT( loadingError( Resource*, const QString& ) ) );
+
+    disconnect( mBaseResource, SIGNAL( loadingFinished( Resource* ) ),
+                this, SLOT( initialLoadingFinished( Resource* ) ) );
+
+    if ( mFolderResource != 0 ) {
+        disconnect( mFolderResource,
+                    SIGNAL( signalSubresourceAdded( KABC::ResourceABC*, const \
QString&, const QString& ) ), +                    this, SLOT( subResourceAdded( \
KABC::ResourceABC*, const QString&, const QString& ) ) ); +
+        disconnect( mFolderResource,
+                    SIGNAL( signalSubresourceRemoved( KABC::ResourceABC*, const \
QString&, const QString& ) ), +                    this, SLOT( subResourceRemoved( \
KABC::ResourceABC*, const QString&, const QString& ) ) ); +
+    if ( mBaseResource->isOpen() )
+      mBaseResource->close();
+    }
+  }
+}
+
 bool KABCResource::saveAddressBook()
 {
   if ( !mBaseResource || mBaseResource->readOnly() )
@@ -474,6 +514,8 @@
 {
   mAddressBook->setErrorHandler( mErrorHandler );
 
+  closeConfiguration();
+
   KSharedConfig::Ptr config = KGlobal::config();
   Q_ASSERT( !config.isNull() );
 
@@ -486,9 +528,12 @@
   if ( mBaseResource == 0 )
     return;
 
-  if ( !initConfiguration() ) {
-    kError() << "initConfiguration() failed";
+  if ( !isOnline() )
+    return;
 
+  if ( !openConfiguration() ) {
+    kError() << "openConfiguration() failed";
+
     const QString message = i18nc( "@info:status", "Initialization based on stored \
configuration failed." );  emit error( message );
     emit status( Broken, message );
--- trunk/KDE/kdepim/akonadi/resources/kabc/kabcresource.h #853118:853119
@@ -47,6 +47,8 @@
   protected:
     virtual void aboutToQuit();
 
+    virtual void doSetOnline( bool online );
+
     virtual void itemAdded( const Akonadi::Item &item, const Akonadi::Collection \
                &collection );
     virtual void itemChanged( const Akonadi::Item &item, const QSet<QByteArray> \
&parts );  virtual void itemRemoved( const Akonadi::Item &item );
@@ -63,8 +65,10 @@
   private:
     void setResourcePointers( KABC::Resource *resource );
 
-    bool initConfiguration();
+    bool openConfiguration();
 
+    void closeConfiguration();
+
     bool saveAddressBook();
 
     typedef KABC::Resource Resource;


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

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