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

List:       kde-commits
Subject:    KDE/kdepim/runtime/resources/maildir
From:       Till Adam <adam () kde ! org>
Date:       2010-02-28 21:13:05
Message-ID: 1267391585.465686.3687.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1097295 by tilladam:

Check for an unusable config at write time, rather than startup.

 M  +56 -5     maildirresource.cpp  
 M  +1 -0      maildirresource.h  


--- trunk/KDE/kdepim/runtime/resources/maildir/maildirresource.cpp #1097294:1097295
@@ -66,6 +66,7 @@
   new SettingsAdaptor( Settings::self() );
   QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
                               Settings::self(), QDBusConnection::ExportAdaptors );
+  connect( this, SIGNAL(reloadConfiguration()), SLOT(ensureSaneConfiguration()) );
   connect( this, SIGNAL(reloadConfiguration()), SLOT(ensureDirExists()) );
 
   // We need to enable this here, otherwise we neither get the remote ID of the
@@ -78,10 +79,6 @@
 
   setHierarchicalRemoteIdentifiersEnabled( true );
 
-  if ( Settings::self()->path().isEmpty() ) {
-      emit status( Broken, i18n( "No usable storage location configured.") );
-      setOnline( false );
-  }
 }
 
 MaildirResource::~ MaildirResource()
@@ -139,6 +136,10 @@
 
 void MaildirResource::itemAdded( const Akonadi::Item & item, const \
Akonadi::Collection& collection )  {
+    if ( !ensureSaneConfiguration() ) {
+      cancelTask( i18n("Unusable configuration.") );
+      return;
+    }
     Maildir dir = maildirForCollection( collection );
     QString errMsg;
     if ( Settings::readOnly() || !dir.isValid( errMsg ) ) {
@@ -160,6 +161,11 @@
 
 void MaildirResource::itemChanged( const Akonadi::Item& item, const \
QSet<QByteArray>& parts )  {
+    if ( !ensureSaneConfiguration() ) {
+      cancelTask( i18n("Unusable configuration.") );
+      return;
+    }
+
     if ( Settings::self()->readOnly() || !parts.contains( MessagePart::Body ) ) {
       changeProcessed();
       return;
@@ -188,6 +194,11 @@
     return;
   }
 
+  if ( !ensureSaneConfiguration() ) {
+    cancelTask( i18n("Unusable configuration.") );
+    return;
+  }
+
   Maildir sourceDir = maildirForCollection( source );
   QString errMsg;
   if ( !sourceDir.isValid( errMsg ) ) {
@@ -214,6 +225,11 @@
 
 void MaildirResource::itemRemoved(const Akonadi::Item & item)
 {
+  if ( !ensureSaneConfiguration() ) {
+    cancelTask( i18n("Unusable configuration.") );
+    return;
+  }
+
   if ( !Settings::self()->readOnly() ) {
     Maildir dir = maildirForCollection( item.parentCollection() );
     // !dir.isValid() means that our parent folder has been deleted already,
@@ -300,6 +316,12 @@
 
 void MaildirResource::collectionAdded(const Collection & collection, const \
Collection &parent)  {
+  if ( !ensureSaneConfiguration() ) {
+    emit error( i18n("Unusable configuration.") );
+    changeProcessed();
+    return;
+  }
+
   Maildir md = maildirForCollection( parent );
   kDebug( 5254 ) << md.subFolderList() << md.entryList();
   if ( Settings::self()->readOnly() || !md.isValid() ) {
@@ -324,7 +346,13 @@
 }
 
 void MaildirResource::collectionChanged(const Collection & collection)
-{
+{    
+  if ( !ensureSaneConfiguration() ) {
+    emit error( i18n("Unusable configuration.") );
+    changeProcessed();
+    return;
+  }
+
   if ( collection.parentCollection() == Collection::root() ) {
     if ( collection.name() != name() )
       setName( collection.name() );
@@ -350,6 +378,13 @@
 void MaildirResource::collectionMoved( const Collection &collection, const \
Collection &source, const Collection &dest )  {
   kDebug() << collection << source << dest;
+
+  if ( !ensureSaneConfiguration() ) {
+    emit error( i18n("Unusable configuration.") );
+    changeProcessed();
+    return;
+  }
+
   if ( collection.parentCollection() == Collection::root() ) {
     emit error( i18n( "Cannot move root maildir folder '%1'." ,collection.remoteId() \
) );  changeProcessed();
@@ -375,6 +410,12 @@
 
 void MaildirResource::collectionRemoved( const Akonadi::Collection &collection )
 {
+   if ( !ensureSaneConfiguration() ) {
+    emit error( i18n("Unusable configuration.") );
+    changeProcessed();
+    return;
+  }
+
   if ( collection.parentCollection() == Collection::root() ) {
     emit error( i18n("Cannot delete top-level maildir folder '%1'.", \
Settings::self()->path() ) );  changeProcessed();
@@ -398,4 +439,14 @@
   }
 }
 
+bool MaildirResource::ensureSaneConfiguration()
+{
+  if ( Settings::self()->path().isEmpty() ) {
+    emit status( Broken, i18n( "No usable storage location configured.") );
+    setOnline( false );
+    return false;
+  }
+  return true;
+}
+
 #include "maildirresource.moc"
--- trunk/KDE/kdepim/runtime/resources/maildir/maildirresource.h #1097294:1097295
@@ -61,6 +61,7 @@
 
   private slots:
     void ensureDirExists();
+    bool ensureSaneConfiguration();
 
   private:
     Akonadi::Collection::List listRecursive( const Akonadi::Collection &root, const \
KPIM::Maildir &dir );


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

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