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

List:       kde-commits
Subject:    branches/work/akonadi-ports/kdepim/akonadi/agents/maildispatcher
From:       Constantin Berzan <exit3219 () gmail ! com>
Date:       2009-08-27 10:23:00
Message-ID: 1251368580.489111.13205.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1016261 by cberzan:

Adapt to new LocalFolders API.


 M  +8 -0      maildispatcheragent.cpp  
 M  +1 -0      maildispatcheragent.h  
 M  +42 -13    outboxqueue.cpp  
 M  +3 -1      outboxqueue.h  
 M  +4 -1      sendjob.cpp  
 M  +7 -5      tests/aborttest.cpp  
 A             tests/unittestenv/kdehome/share/config/kdedrc  


--- branches/work/akonadi-ports/kdepim/akonadi/agents/maildispatcher/maildispatcheragent.cpp \
#1016260:1016261 @@ -68,6 +68,7 @@
     void abort();
     void dispatch();
     void itemFetched( Item &item );
+    void queueError( const QString &message );
     void sendPercent( KJob *job, unsigned long percent );
     void sendResult( KJob *job );
     void emitStatusReady();
@@ -160,6 +161,7 @@
   connect( d->queue, SIGNAL( newItems() ), this, SLOT( dispatch() ) );
   connect( d->queue, SIGNAL( itemReady( Akonadi::Item& ) ),
       this, SLOT( itemFetched( Akonadi::Item& ) ) );
+  connect( d->queue, SIGNAL(error(QString)), this, SLOT(queueError(QString)) );
   connect( this, SIGNAL(itemProcessed(Akonadi::Item,bool)),
       d->queue, SLOT(itemProcessed(Akonadi::Item,bool)) );
   connect( this, SIGNAL(abortRequested()), this, SLOT(abort()) );
@@ -213,6 +215,12 @@
   currentJob->start();
 }
 
+void MailDispatcherAgent::Private::queueError( const QString &message )
+{
+  emit q->error( message );
+  // FIXME figure out why this does not set the status to Broken, etc.
+}
+
 void MailDispatcherAgent::Private::sendPercent( KJob *job, unsigned long percent )
 {
   Q_ASSERT( sendingInProgress );
--- branches/work/akonadi-ports/kdepim/akonadi/agents/maildispatcher/maildispatcheragent.h \
#1016260:1016261 @@ -56,6 +56,7 @@
     Q_PRIVATE_SLOT( d, void abort() )
     Q_PRIVATE_SLOT( d, void dispatch() )
     Q_PRIVATE_SLOT( d, void itemFetched( Akonadi::Item& ) )
+    Q_PRIVATE_SLOT( d, void queueError( QString ) )
     Q_PRIVATE_SLOT( d, void sendPercent( KJob*, unsigned long ) )
     Q_PRIVATE_SLOT( d, void sendResult( KJob* ) )
     Q_PRIVATE_SLOT( d, void emitStatusReady() )
--- branches/work/akonadi-ports/kdepim/akonadi/agents/maildispatcher/outboxqueue.cpp \
#1016260:1016261 @@ -24,6 +24,7 @@
 #include <QTimer>
 
 #include <KDebug>
+#include <KLocalizedString>
 
 #include <Akonadi/Attribute>
 #include <Akonadi/Item>
@@ -32,6 +33,7 @@
 #include <Akonadi/Monitor>
 #include <akonadi/kmime/addressattribute.h>
 #include <akonadi/kmime/localfolders.h>
+#include <akonadi/kmime/localfoldersrequestjob.h>
 
 #include <kmime/kmime_message.h>
 #include <boost/shared_ptr.hpp>
@@ -88,7 +90,8 @@
     void checkFuture();
     void collectionFetched( KJob *job );
     void itemFetched( KJob *job );
-    void outboxChanged();
+    void localFoldersChanged();
+    void localFoldersRequestResult( KJob *job );
     void itemAdded( const Item &item );
     void itemChanged( const Item &item );
     void itemMoved( const Item &item, const Collection &source, const Collection \
&dest ); @@ -260,20 +263,47 @@
   emit q->itemReady( fjob->items().first() );
 }
 
-void OutboxQueue::Private::outboxChanged()
+void OutboxQueue::Private::localFoldersChanged()
 {
   // Called on startup, and whenever the local folders change.
-  Collection col = LocalFolders::self()->outbox();
-  Q_ASSERT( col.isValid() );
-  if( col == outbox ) {
+
+  if( LocalFolders::self()->hasDefaultFolder( LocalFolders::Outbox ) ) {
+    // Outbox is ready, init the queue from it.
+    Collection col = LocalFolders::self()->defaultFolder( LocalFolders::Outbox );
+    Q_ASSERT( col.isValid() );
+
+    if( outbox != col ) {
+      monitor->setCollectionMonitored( outbox, false );
+      monitor->setCollectionMonitored( col, true );
+      outbox = col;
+      kDebug() << "Changed outbox to" << outbox.id();
+      initQueue();
+    }
+  } else {
+    // Outbox is not ready. Request it, since otherwise we will not know when
+    // new messages appear.
+    // (Note that we are a separate process, so we get no notification when
+    // MessageQueueJob requests the Outbox.)
+    monitor->setCollectionMonitored( outbox, false );
+    outbox = Collection( -1 );
+    LocalFoldersRequestJob *rjob = new LocalFoldersRequestJob( q );
+    rjob->requestDefaultFolder( LocalFolders::Outbox );
+    connect( rjob, SIGNAL(result(KJob*)), q, SLOT(localFoldersRequestResult(KJob*)) \
); +    kDebug() << "Requesting outbox folder.";
+    rjob->start();
+  }
+}
+
+void OutboxQueue::Private::localFoldersRequestResult( KJob *job )
+{
+  if( job->error() ) {
+    kWarning() << "Failed to get outbox folder.";
+    emit q->error( i18n( "Could not access the outbox folder (%1).", \
job->errorString() ) );  return;
   }
 
-  monitor->setCollectionMonitored( outbox, false );
-  monitor->setCollectionMonitored( col, true );
-  outbox = col;
-  kDebug() << "Changed outbox to" << outbox.id();
-  initQueue();
+  Q_ASSERT( LocalFolders::self()->hasDefaultFolder( LocalFolders::Outbox ) );
+  localFoldersChanged();
 }
 
 void OutboxQueue::Private::itemAdded( const Item &item )
@@ -338,9 +368,8 @@
   connect( d->monitor, SIGNAL( itemRemoved( Akonadi::Item ) ),
       this, SLOT( itemRemoved( Akonadi::Item ) ) );
 
-  connect( LocalFolders::self(), SIGNAL( foldersReady() ),
-      this, SLOT( outboxChanged() ) );
-  LocalFolders::self()->fetch();
+  connect( LocalFolders::self(), SIGNAL(defaultFoldersChanged()), this, \
SLOT(localFoldersChanged()) ); +  d->localFoldersChanged();
 
   d->futureTimer = new QTimer( this );
   connect( d->futureTimer, SIGNAL(timeout()), this, SLOT(checkFuture()) );
--- branches/work/akonadi-ports/kdepim/akonadi/agents/maildispatcher/outboxqueue.h \
#1016260:1016261 @@ -56,6 +56,7 @@
   signals:
     void itemReady( Akonadi::Item &item );
     void newItems();
+    void error( const QString &error );
 
   private:
     class Private;
@@ -64,7 +65,8 @@
     Q_PRIVATE_SLOT( d, void checkFuture() )
     Q_PRIVATE_SLOT( d, void collectionFetched( KJob* ) )
     Q_PRIVATE_SLOT( d, void itemFetched( KJob* ) )
-    Q_PRIVATE_SLOT( d, void outboxChanged() )
+    Q_PRIVATE_SLOT( d, void localFoldersChanged() )
+    Q_PRIVATE_SLOT( d, void localFoldersRequestResult( KJob* ) )
     Q_PRIVATE_SLOT( d, void itemAdded( Akonadi::Item ) )
     Q_PRIVATE_SLOT( d, void itemChanged( Akonadi::Item ) )
     Q_PRIVATE_SLOT( d, void itemMoved( Akonadi::Item, Akonadi::Collection, \
                Akonadi::Collection ) )
--- branches/work/akonadi-ports/kdepim/akonadi/agents/maildispatcher/sendjob.cpp \
#1016260:1016261 @@ -110,7 +110,10 @@
     return;
   }
   TransportType type = tA->transport()->transportType();
-  Q_ASSERT( type.isValid() );
+  if( !type.isValid() ) {
+    storeResult( false, i18n( "Could not send message. Invalid transport." ) );
+    return;
+  }
   if( type.type() == Transport::EnumType::Akonadi ) {
     // Send the item directly to the resource that will send it.
     resourceId = tA->transport()->host();
--- branches/work/akonadi-ports/kdepim/akonadi/agents/maildispatcher/tests/aborttest.cpp \
#1016260:1016261 @@ -36,6 +36,7 @@
 #include <akonadi/qtest_akonadi.h>
 #include <akonadi/private/collectionpathresolver_p.h>
 #include <akonadi/kmime/localfolders.h>
+#include <akonadi/kmime/localfoldersrequestjob.h>
 
 #include <mailtransport/dispatcherinterface.h>
 #include <mailtransport/errorattribute.h>
@@ -60,12 +61,13 @@
 {
   QVERIFY( Control::start() );
   QTest::qWait( 1000 );
-  LocalFolders::self()->fetch();
-  QTest::kWaitForSignal( LocalFolders::self(), SIGNAL(foldersReady()) );
 
-  // Clear outbox.
-  QVERIFY( LocalFolders::self()->isReady() );
-  outbox = LocalFolders::self()->outbox();
+  // Get the outbox and clear it.
+  LocalFoldersRequestJob *rjob = new LocalFoldersRequestJob( this );
+  rjob->requestDefaultFolder( LocalFolders::Outbox );
+  QTest::kWaitForSignal( rjob, SIGNAL(result(KJob*)) );
+  outbox = LocalFolders::self()->defaultFolder( LocalFolders::Outbox );
+  QVERIFY( outbox.isValid() );
   ItemDeleteJob *djob = new ItemDeleteJob( outbox );
   djob->exec(); // may give error if outbox empty
 


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

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