Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > by-pkgid > 05ea160c3e539040248c38fe5960670d > files > 7

kdepimlibs4-4.4.5-0.2mdv2010.2.src.rpm

Index: akonadi/kjobprivatebase.cpp
===================================================================
--- akonadi/kjobprivatebase.cpp	(révision 0)
+++ akonadi/kjobprivatebase.cpp	(révision 1108274)
@@ -0,0 +1,48 @@
+/*
+    Copyright (c) 2010 Volker Krause <vkrause@kde.org>
+
+    This library is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Library General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    This library is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
+    License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to the
+    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA.
+*/
+
+#include "kjobprivatebase_p.h"
+
+using namespace Akonadi;
+
+void KJobPrivateBase::start()
+{
+  ServerManager::State serverState = ServerManager::state();
+  if ( serverState == ServerManager::Running ) {
+    doStart();
+    return;
+  }
+
+  connect( ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State)),
+           SLOT(serverStateChanged(Akonadi::ServerManager::State)) );
+  if ( serverState == ServerManager::NotRunning )
+    ServerManager::start();
+}
+
+void KJobPrivateBase::serverStateChanged( Akonadi::ServerManager::State state )
+{
+  if ( state == ServerManager::Running ) {
+    disconnect( ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State)),
+                this, SLOT(serverStateChanged(Akonadi::ServerManager::State)) );
+    doStart();
+  }
+}
+
+#include "kjobprivatebase_p.moc"
+
Index: akonadi/kjobprivatebase_p.h
===================================================================
--- akonadi/kjobprivatebase_p.h	(révision 0)
+++ akonadi/kjobprivatebase_p.h	(révision 1108274)
@@ -0,0 +1,50 @@
+/*
+    Copyright (c) 2010 Volker Krause <vkrause@kde.org>
+
+    This library is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Library General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    This library is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
+    License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to the
+    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA.
+*/
+
+#ifndef AKONADI_KJOBPRIVATEBASE_P_H
+#define AKONADI_KJOBPRIVATEBASE_P_H 
+
+#include <QtCore/QObject>
+#include <akonadi/servermanager.h>
+
+namespace Akonadi {
+
+/**
+ * Base class for the private class of KJob but not Akonadi::Job based jobs that
+ * require the Akonadi server to be operational.
+ * Delays job execution until that is the case.
+ * @internal
+ */ 
+class KJobPrivateBase : public QObject
+{
+  Q_OBJECT
+  public:
+    /** Call from KJob::start() reimplementation. */
+    void start();
+
+    /** Reimplement and put here what was in KJob::start() before. */
+    virtual void doStart() = 0;
+
+  private slots:
+    void serverStateChanged(Akonadi::ServerManager::State state);
+};
+
+}
+
+#endif
Index: akonadi/resourcesynchronizationjob.cpp
===================================================================
--- akonadi/resourcesynchronizationjob.cpp	(révision 1108273)
+++ akonadi/resourcesynchronizationjob.cpp	(révision 1108274)
@@ -16,6 +16,7 @@
  */
 
 #include "resourcesynchronizationjob.h"
+#include "kjobprivatebase_p.h"
 
 #include <akonadi/agentinstance.h>
 #include <akonadi/agentmanager.h>
@@ -30,7 +31,7 @@
 namespace Akonadi
 {
 
-class ResourceSynchronizationJobPrivate
+class ResourceSynchronizationJobPrivate : public KJobPrivateBase
 {
   public:
     ResourceSynchronizationJobPrivate( ResourceSynchronizationJob* parent ) :
@@ -40,6 +41,8 @@
       timeoutCount( 0 )
     {}
 
+    void doStart();
+
     ResourceSynchronizationJob *q;
     AgentInstance instance;
     QDBusInterface* interface;
@@ -71,25 +74,30 @@
 
 void ResourceSynchronizationJob::start()
 {
-  if ( !d->instance.isValid() ) {
-    setError( UserDefinedError );
-    setErrorText( i18n( "Invalid resource instance." ) );
-    emitResult();
+  d->start();
+}
+
+void ResourceSynchronizationJobPrivate::doStart()
+{
+  if ( !instance.isValid() ) {
+    q->setError( KJob::UserDefinedError );
+    q->setErrorText( i18n( "Invalid resource instance." ) );
+    q->emitResult();
     return;
   }
 
-  d->interface = new QDBusInterface( QString::fromLatin1( "org.freedesktop.Akonadi.Resource.%1" ).arg( d->instance.identifier() ),
+  interface = new QDBusInterface( QString::fromLatin1( "org.freedesktop.Akonadi.Resource.%1" ).arg( instance.identifier() ),
                                       QString::fromLatin1( "/" ),
                                       QString::fromLatin1( "org.freedesktop.Akonadi.Resource" ), QDBusConnection::sessionBus(), this );
-  connect( d->interface, SIGNAL(synchronized()), SLOT(slotSynchronized()) );
+  connect( interface, SIGNAL(synchronized()), SLOT(slotSynchronized()) );
 
-  if ( d->interface->isValid() ) {
-    d->instance.synchronize();
-    d->safetyTimer->start();
+  if ( interface->isValid() ) {
+    instance.synchronize();
+    safetyTimer->start();
   } else {
-    setError( UserDefinedError );
-    setErrorText( i18n( "Unable to obtain D-Bus interface for resource '%1'", d->instance.identifier() ) );
-    emitResult();
+    q->setError( KJob::UserDefinedError );
+    q->setErrorText( i18n( "Unable to obtain D-Bus interface for resource '%1'", instance.identifier() ) );
+    q->emitResult();
     return;
   }
 }
Index: akonadi/agentinstancecreatejob.cpp
===================================================================
--- akonadi/agentinstancecreatejob.cpp	(révision 1108273)
+++ akonadi/agentinstancecreatejob.cpp	(révision 1108274)
@@ -20,6 +20,7 @@
 #include "agentinstancecreatejob.h"
 #include "agentmanager.h"
 #include "agentmanager_p.h"
+#include "kjobprivatebase_p.h"
 
 #include "agentinstance.h"
 #include "controlinterface.h"
@@ -41,7 +42,7 @@
 /**
  * @internal
  */
-class AgentInstanceCreateJob::Private
+class AgentInstanceCreateJob::Private : public KJobPrivateBase
 {
   public:
     Private( AgentInstanceCreateJob* parent ) : q( parent ),
@@ -122,6 +123,8 @@
       q->emitResult();
     }
 
+    void doStart();
+
     AgentInstanceCreateJob* q;
     AgentType agentType;
     AgentInstance agentInstance;
@@ -161,20 +164,25 @@
 
 void AgentInstanceCreateJob::start()
 {
-  d->agentInstance = AgentManager::self()->d->createInstance( d->agentType );
-  if ( !d->agentInstance.isValid() ) {
-    setError( KJob::UserDefinedError );
-    setErrorText( i18n("Unable to create agent instance." ) );
-    QTimer::singleShot( 0, this , SLOT( emitResult() ) );
+  d->start();
+}
+
+void AgentInstanceCreateJob::Private::doStart()
+{
+  agentInstance = AgentManager::self()->d->createInstance( agentType );
+  if ( !agentInstance.isValid() ) {
+    q->setError( KJob::UserDefinedError );
+    q->setErrorText( i18n("Unable to create agent instance." ) );
+    QTimer::singleShot( 0, q, SLOT( emitResult() ) );
   } else {
     int timeout = safetyTimeout;
 #ifdef Q_OS_UNIX
     // Increate the timeout when valgrinding the agent, because that slows down things a log.
     QString agentValgrind = QString::fromLocal8Bit( qgetenv( "AKONADI_VALGRIND" ) );
-    if ( !agentValgrind.isEmpty() && d->agentType.identifier().contains( agentValgrind ) )
+    if ( !agentValgrind.isEmpty() && agentType.identifier().contains( agentValgrind ) )
       timeout *= 15;
 #endif
-    d->safetyTimer->start( timeout );
+    safetyTimer->start( timeout );
   }
 }
 
Index: akonadi/CMakeLists.txt
===================================================================
--- akonadi/CMakeLists.txt	(révision 1108273)
+++ akonadi/CMakeLists.txt	(révision 1108274)
@@ -114,6 +114,7 @@
   itemview.cpp
   job.cpp
   kdescendantsproxymodel.cpp
+  kjobprivatebase.cpp
   krecursivefilterproxymodel.cpp
   linkjob.cpp
   mimetypechecker.cpp