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

List:       kde-commits
Subject:    KDE/kdepim/akonadi
From:       Tobias Koenig <tokoe () kde ! org>
Date:       2006-08-17 11:49:31
Message-ID: 1155815371.852125.13230.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 573870 by tokoe:

Added
  int status() const;
  QString statusMessage() const
methods and
  void statusChanged( int status, const QString &message )
signal to resource API to allow status notifications

Furthermore added a knut resource, which can be used for debugging.



 M  +10 -0     resources/include/org.kde.Akonadi.Resource.xml  
 M  +25 -0     resources/include/resource.h  
 M  +35 -0     resources/include/resourcebase.h  
 M  +1 -0      resources/src/CMakeLists.txt  
 A             resources/src/knut (directory)  
 A             resources/src/knut/CMakeLists.txt  
 A             resources/src/knut/knutresource.cpp   [License: LGPL (v2+)]
 A             resources/src/knut/knutresource.desktop  
 A             resources/src/knut/knutresource.h   [License: LGPL (v2+)]
 A             resources/src/knut/main.cpp   [License: LGPL (v2+)]
 M  +70 -0     resources/src/lib/resourcebase.cpp  
 M  +12 -0     server/control/agentmanager.cpp  
 M  +21 -0     server/control/agentmanager.h  
 M  +59 -1     server/control/pluginmanager.cpp  
 M  +22 -0     server/control/pluginmanager.h  
 M  +13 -0     server/interfaces/org.kde.Akonadi.AgentManager.xml  


--- trunk/KDE/kdepim/akonadi/resources/include/org.kde.Akonadi.Resource.xml \
#573869:573870 @@ -1,8 +1,18 @@
 <!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" \
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">  <node>
   <interface name="org.kde.Akonadi.Resource">
+    <signal name="statusChanged">
+      <arg name="status" type="i" direction="out"/>
+      <arg name="message" type="s" direction="out"/>
+    </signal>
     <method name="quit">
     </method>
+    <method name="status">
+      <arg type="i" direction="out"/>
+    </method>
+    <method name="statusMessage">
+      <arg type="s" direction="out"/>
+    </method>
     <method name="requestItemDelivery">
       <arg type="b" direction="out"/>
       <arg name="uid" type="s" direction="in"/>
--- trunk/KDE/kdepim/akonadi/resources/include/resource.h #573869:573870
@@ -54,6 +54,22 @@
     virtual void quit() = 0;
 
     /**
+     * This method returns the current status code of the resource.
+     *
+     * The following return values are possible:
+     *
+     *  0 - Ready
+     *  1 - Syncing
+     *  2 - Error
+     */
+    virtual int status() const = 0;
+
+    /**
+     * This method returns an i18n'ed description of the current status code.
+     */
+    virtual QString statusMessage() const = 0;
+
+    /**
      * This method is called whenever an external query for putting data in the
      * storage is received.
      *
@@ -63,6 +79,15 @@
      *             just a lightweight version.
      */
     virtual bool requestItemDelivery( const QString & uid, const QString & \
collection, int type ) = 0; +
+  Q_SIGNALS:
+    /**
+     * This signal is emitted whenever the status of the resource has changed.
+     *
+     * @param status The status id of the resource (@see Status).
+     * @param message An i18n'ed message which describes the status in detail.
+     */
+    void statusChanged( int status, const QString &message );
 };
 
 }
--- trunk/KDE/kdepim/akonadi/resources/include/resourcebase.h #573869:573870
@@ -45,6 +45,17 @@
 
   public:
     /**
+     * This enum describes the different states the
+     * resource can be in.
+     */
+    enum Status
+    {
+      Ready = 0,
+      Syncing,
+      Error
+    };
+
+    /**
      * Use this method in the main function of your resource
      * application to initialize your resource subclass.
      *
@@ -73,6 +84,22 @@
       new T( id );
     }
 
+    /**
+     * This method returns the current status code of the resource.
+     *
+     * The following return values are possible:
+     *
+     *  0 - Ready
+     *  1 - Syncing
+     *  2 - Error
+     */
+    virtual int status() const;
+
+    /**
+     * This method returns an i18n'ed description of the current status code.
+     */
+    virtual QString statusMessage() const;
+
   public Q_SLOTS:
     /**
      * This method is called to quit the resource.
@@ -107,6 +134,14 @@
     void error( const QString& message );
 
     /**
+     * This method shall be used to signal a state change.
+     *
+     * @param status The new status of the resource.
+     * @param message An i18n'ed description of the status.
+     */
+    void changeStatus( Status status, const QString &message = QString() );
+
+    /**
      * This method is called whenever the application is about to
      * quit.
      *
--- trunk/KDE/kdepim/akonadi/resources/src/CMakeLists.txt #573869:573870
@@ -1,3 +1,4 @@
 
 add_subdirectory( lib ) 
 add_subdirectory( ical ) 
+add_subdirectory( knut ) 
--- trunk/KDE/kdepim/akonadi/resources/src/lib/resourcebase.cpp #573869:573870
@@ -32,10 +32,38 @@
 class ResourceBase::Private
 {
   public:
+    Private()
+      : mStatusCode( Ready )
+    {
+      mStatusMessage = defaultReadyMessage();
+    }
+
+    QString defaultReadyMessage() const;
+    QString defaultSyncingMessage() const;
+    QString defaultErrorMessage() const;
+
     org::kde::Akonadi::Tracer *mTracer;
     QString mId;
+
+    int mStatusCode;
+    QString mStatusMessage;
 };
 
+QString ResourceBase::Private::defaultReadyMessage() const
+{
+  return tr( "Ready" );
+}
+
+QString ResourceBase::Private::defaultSyncingMessage() const
+{
+  return tr( "Syncing..." );
+}
+
+QString ResourceBase::Private::defaultErrorMessage() const
+{
+  return tr( "Error!" );
+}
+
 ResourceBase::ResourceBase( const QString & id )
   : d( new Private )
 {
@@ -56,6 +84,16 @@
   delete d;
 }
 
+int ResourceBase::status() const
+{
+  return d->mStatusCode;
+}
+
+QString ResourceBase::statusMessage() const
+{
+  return d->mStatusMessage;
+}
+
 void ResourceBase::warning( const QString& message )
 {
   d->mTracer->warning( QString( "ResourceBase(%1)" ).arg( d->mId ), message );
@@ -66,6 +104,38 @@
   d->mTracer->error( QString( "ResourceBase(%1)" ).arg( d->mId ), message );
 }
 
+void ResourceBase::changeStatus( Status status, const QString &message )
+{
+  d->mStatusMessage = message;
+  d->mStatusCode = 0;
+
+  switch ( status ) {
+    case Ready:
+      if ( d->mStatusMessage.isEmpty() )
+        d->mStatusMessage = d->defaultReadyMessage();
+
+      d->mStatusCode = 0;
+      break;
+    case Syncing:
+      if ( d->mStatusMessage.isEmpty() )
+        d->mStatusMessage = d->defaultSyncingMessage();
+
+      d->mStatusCode = 1;
+      break;
+    case Error:
+      if ( d->mStatusMessage.isEmpty() )
+        d->mStatusMessage = d->defaultErrorMessage();
+
+      d->mStatusCode = 2;
+      break;
+    default:
+      Q_ASSERT( !"Unknown status passed" );
+      break;
+  }
+
+  emit statusChanged( d->mStatusCode, d->mStatusMessage );
+}
+
 QString ResourceBase::parseArguments( int argc, char **argv )
 {
   if ( argc < 3 ) {
--- trunk/KDE/kdepim/akonadi/server/control/agentmanager.cpp #573869:573870
@@ -36,6 +36,8 @@
            this, SIGNAL( agentInstanceAdded( const QString& ) ) );
   connect( &mPluginManager, SIGNAL( agentInstanceRemoved( const QString& ) ),
            this, SIGNAL( agentInstanceRemoved( const QString& ) ) );
+  connect( &mPluginManager, SIGNAL( agentInstanceStatusChanged( const QString&, int, \
const QString& ) ), +           this, SIGNAL( agentInstanceStatusChanged( const \
QString&, int, const QString& ) ) );  
   connect( &mProfileManager, SIGNAL( profileAdded( const QString& ) ),
            this, SIGNAL( profileAdded( const QString& ) ) );
@@ -101,6 +103,16 @@
   return mPluginManager.agentInstances();
 }
 
+int AgentManager::agentInstanceStatus( const QString &identifier ) const
+{
+  return mPluginManager.agentInstanceStatus( identifier );
+}
+
+QString AgentManager::agentInstanceStatusMessage( const QString &identifier ) const
+{
+  return mPluginManager.agentInstanceStatusMessage( identifier );
+}
+
 bool AgentManager::requestItemDelivery( const QString &agentIdentifier, const \
                QString &itemIdentifier,
                                         const QString &collection, int type )
 {
--- trunk/KDE/kdepim/akonadi/server/control/agentmanager.h #573869:573870
@@ -122,6 +122,17 @@
     QStringList agentInstances() const;
 
     /**
+     * Returns the current status code of the agent with the given @p identifier.
+     */
+    int agentInstanceStatus( const QString &identifier ) const;
+
+    /**
+     * Returns the i18n'ed description of the current status of the agent with
+     * the given @p identifier.
+     */
+    QString agentInstanceStatusMessage( const QString &identifier ) const;
+
+    /**
      * Asks the agent to store the item with the given
      * identifier to the given @p collection as full or lightwight
      * version, depending on @p type.
@@ -211,6 +222,16 @@
     void agentInstanceRemoved( const QString &agentIdentifier );
 
     /**
+     * This signal is emitted whenever the status of an agent instance has
+     * changed.
+     *
+     * @param agentIdentifier The identifier of the agent that has changed.
+     * @param status The new status code.
+     * @param message The i18n'ed description of the new status.
+     */
+    void agentInstanceStatusChanged( const QString &agentIdentifier, int status, \
const QString &message ); +
+    /**
      * Profile specific signals
      */
 
--- trunk/KDE/kdepim/akonadi/server/control/pluginmanager.cpp #573869:573870
@@ -202,6 +202,40 @@
   return mInstances.keys();
 }
 
+int PluginManager::agentInstanceStatus( const QString &identifier ) const
+{
+  if ( !mInstances.contains( identifier ) ) {
+    mTracer->warning( QLatin1String( \
"akonadi_control::PluginManager::agentInstanceStatus" ), +                      \
QString( "Agent instance with identifier '%1' does not exist" ).arg( identifier ) ); \
+    return 2; +  }
+
+  if ( !mInstances[ identifier ].interface ) {
+    mTracer->error( QLatin1String( \
"akonadi_control::PluginManager::agentInstanceStatus" ), +                    \
QString( "Agent instance '%1' has no interface!" ).arg( identifier ) ); +    return \
2; +  }
+
+  return mInstances[ identifier ].interface->status();
+}
+
+QString PluginManager::agentInstanceStatusMessage( const QString &identifier ) const
+{
+  if ( !mInstances.contains( identifier ) ) {
+    mTracer->warning( QLatin1String( \
"akonadi_control::PluginManager::agentInstanceStatusMessage" ), +                     \
QString( "Agent instance with identifier '%1' does not exist" ).arg( identifier ) ); \
+    return QString(); +  }
+
+  if ( !mInstances[ identifier ].interface ) {
+    mTracer->error( QLatin1String( \
"akonadi_control::PluginManager::agentInstanceStatusMessage" ), +                    \
QString( "Agent instance '%1' has no interface!" ).arg( identifier ) ); +    return \
QString(); +  }
+
+  return mInstances[ identifier ].interface->statusMessage();
+}
+
 void PluginManager::updatePluginInfos()
 {
   QMap<QString, PluginInfo> oldInfos = mPluginInfos;
@@ -424,7 +458,7 @@
   }
 }
 
-void PluginManager::resourceRegistered( const QString &name, const QString \
&oldOwner, const QString &newOwner ) +void PluginManager::resourceRegistered( const \
QString &name, const QString&, const QString &newOwner )  {
   if ( newOwner.isEmpty() ) // interface was unregistered
     return;
@@ -446,7 +480,31 @@
     return;
   }
 
+  interface->setObjectName( identifier );
+
+  connect( interface, SIGNAL( statusChanged( int, const QString& ) ),
+           this, SLOT( resourceStatusChanged( int, const QString& ) ) );
+
   mInstances[ identifier ].interface = interface;
 }
 
+void PluginManager::resourceStatusChanged( int status, const QString &message )
+{
+  org::kde::Akonadi::Resource *resource = static_cast<org::kde::Akonadi::Resource*>( \
sender() ); +  if ( !resource ) {
+    mTracer->error( QLatin1String( \
"akonadi_control::PluginManager::resourceStatusChanged" ), +                    \
QLatin1String( "Got signal from unknown sender" ) ); +    return;
+  }
+
+  const QString identifier = resource->objectName();
+  if ( identifier.isEmpty() ) {
+    mTracer->error( QLatin1String( \
"akonadi_control::PluginManager::resourceStatusChanged" ), +                    \
QLatin1String( "Sender of statusChanged signal has no identifier" ) ); +    return;
+  }
+
+  emit agentInstanceStatusChanged( identifier, status, message );
+}
+
 #include "pluginmanager.moc"
--- trunk/KDE/kdepim/akonadi/server/control/pluginmanager.h #573869:573870
@@ -111,6 +111,17 @@
     QStringList agentInstances() const;
 
     /**
+     * Returns the current status code of the agent with the given @p identifier.
+     */
+    int agentInstanceStatus( const QString &identifier ) const;
+
+    /**
+     * Returns the i18n'ed description of the current status of the agent with
+     * the given @p identifier.
+     */
+    QString agentInstanceStatusMessage( const QString &identifier ) const;
+
+    /**
      * Asks the agent to store the item with the given
      * identifier to the given @p collection as full or lightwight
      * version, depending on @p type.
@@ -147,9 +158,20 @@
      */
     void agentInstanceRemoved( const QString &agentIdentifier );
 
+    /**
+     * This signal is emitted whenever the status of an agent instance has
+     * changed.
+     *
+     * @param agentIdentifier The identifier of the agent that has changed.
+     * @param status The new status code.
+     * @param message The i18n'ed description of the new status.
+     */
+    void agentInstanceStatusChanged( const QString &agentIdentifier, int status, \
const QString &message ); +
   private Q_SLOTS:
     void updatePluginInfos();
     void resourceRegistered( const QString&, const QString&, const QString& );
+    void resourceStatusChanged( int status, const QString &message );
 
   private:
     /**
--- trunk/KDE/kdepim/akonadi/server/interfaces/org.kde.Akonadi.AgentManager.xml \
#573869:573870 @@ -13,6 +13,11 @@
     <signal name="agentInstanceRemoved">
       <arg name="agentIdentifier" type="s" direction="out"/>
     </signal>
+    <signal name="agentInstanceStatusChanged">
+      <arg name="agentIdentifier" type="s" direction="out"/>
+      <arg name="status" type="i" direction="out"/>
+      <arg name="message" type="s" direction="out"/>
+    </signal>
     <signal name="profileAdded">
       <arg name="profileIdentifier" type="s" direction="out"/>
     </signal>
@@ -64,6 +69,14 @@
     <method name="agentInstances">
       <arg type="as" direction="out"/>
     </method>
+    <method name="agentInstanceStatus">
+      <arg type="i" direction="out"/>
+      <arg name="identifier" type="s" direction="in"/>
+    </method>
+    <method name="agentInstanceStatusMessage">
+      <arg type="s" direction="out"/>
+      <arg name="identifier" type="s" direction="in"/>
+    </method>
     <method name="requestItemDelivery">
       <arg type="b" direction="out"/>
       <arg name="agentIdentifier" type="s" direction="in"/>


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

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