Commit d90c828a authored by Tobias Koenig's avatar Tobias Koenig
Browse files

* Splitted org.kde.Akonadi.Agent into org.kde.Akonadi.Agent.Control and...

* Splitted org.kde.Akonadi.Agent into org.kde.Akonadi.Agent.Control and org.kde.Akonadi.Agent.Status
* Moved all marked methods from ResourceBase to AgentBase
* Renamed Akonadi::Monitor::monitorXYZ() to Akonadi::Monitor::setXYZMonitored()

svn path=/trunk/KDE/kdepimlibs/; revision=791940
parent 351a44b2
......@@ -127,13 +127,12 @@ set( akonadikde_LIB_SRC
)
# DBus interfaces and adaptors
qt4_generate_dbus_interface( resource.h org.kde.Akonadi.Resource.xml )
qt4_generate_dbus_interface( agent.h org.kde.Akonadi.Agent.xml )
qt4_add_dbus_interface2( akonadikde_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.NotificationManager.xml notificationmanagerinterface notificationmessage_p.h )
qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.AgentManager.xml )
qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Tracer.xml )
qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Resource.xml resourcebase.h Akonadi::ResourceBase )
qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Agent.xml agentbase.h Akonadi::AgentBase )
qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Agent.Status.xml agentbase.h Akonadi::AgentBase )
qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Agent.Control.xml agentbase.h Akonadi::AgentBase )
kde4_add_ui_files( akonadikde_LIB_SRC
cachepolicypage.ui
......@@ -223,8 +222,9 @@ install( FILES
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.AgentManager.xml
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.NotificationManager.xml
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Tracer.xml
${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.Agent.xml
${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.Resource.xml
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Agent.Control.xml
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Agent.Status.xml
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.kde.Akonadi.Resource.xml
DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} )
install( FILES
......
......@@ -23,7 +23,8 @@
#include "agentbase.h"
#include "agentbase_p.h"
#include "agentadaptor.h"
#include "controladaptor.h"
#include "statusadaptor.h"
#include "monitor_p.h"
#include "xdgbasedirs_p.h"
......@@ -63,7 +64,7 @@ void AgentBase::Observer::itemAdded( const Item &item, const Collection &collect
Q_UNUSED( item );
Q_UNUSED( collection );
if ( sAgentBase != 0 )
sAgentBase->changeProcessed();
sAgentBase->d_ptr->changeProcessed();
}
void AgentBase::Observer::itemChanged( const Item &item, const QStringList &partIdentifiers )
......@@ -72,7 +73,7 @@ void AgentBase::Observer::itemChanged( const Item &item, const QStringList &part
Q_UNUSED( item );
Q_UNUSED( partIdentifiers );
if ( sAgentBase != 0 )
sAgentBase->changeProcessed();
sAgentBase->d_ptr->changeProcessed();
}
void AgentBase::Observer::itemRemoved( const Item &item )
......@@ -80,7 +81,7 @@ void AgentBase::Observer::itemRemoved( const Item &item )
kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this;
Q_UNUSED( item );
if ( sAgentBase != 0 )
sAgentBase->changeProcessed();
sAgentBase->d_ptr->changeProcessed();
}
void AgentBase::Observer::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent )
......@@ -89,7 +90,7 @@ void AgentBase::Observer::collectionAdded( const Akonadi::Collection &collection
Q_UNUSED( collection );
Q_UNUSED( parent );
if ( sAgentBase != 0 )
sAgentBase->changeProcessed();
sAgentBase->d_ptr->changeProcessed();
}
void AgentBase::Observer::collectionChanged( const Collection &collection )
......@@ -97,7 +98,7 @@ void AgentBase::Observer::collectionChanged( const Collection &collection )
kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this;
Q_UNUSED( collection );
if ( sAgentBase != 0 )
sAgentBase->changeProcessed();
sAgentBase->d_ptr->changeProcessed();
}
void AgentBase::Observer::collectionRemoved( const Collection &collection )
......@@ -105,13 +106,16 @@ void AgentBase::Observer::collectionRemoved( const Collection &collection )
kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this;
Q_UNUSED( collection );
if ( sAgentBase != 0 )
sAgentBase->changeProcessed();
sAgentBase->d_ptr->changeProcessed();
}
//@cond PRIVATE
AgentBasePrivate::AgentBasePrivate( AgentBase *parent )
: q_ptr( parent ),
mStatusCode( AgentBase::Idle ),
mProgress( 0 ),
mOnline( true ),
mSettings( 0 ),
mObserver( 0 )
{
......@@ -119,7 +123,7 @@ AgentBasePrivate::AgentBasePrivate( AgentBase *parent )
AgentBasePrivate::~AgentBasePrivate()
{
monitor->setConfig( 0 );
mMonitor->setConfig( 0 );
delete mSettings;
}
......@@ -129,31 +133,39 @@ void AgentBasePrivate::init()
mTracer = new org::kde::Akonadi::Tracer( QLatin1String( "org.kde.Akonadi" ), QLatin1String( "/tracing" ),
QDBusConnection::sessionBus(), q );
new AgentAdaptor( q );
new ControlAdaptor( q );
new StatusAdaptor( q );
if ( !QDBusConnection::sessionBus().registerObject( QLatin1String( "/" ), q, QDBusConnection::ExportAdaptors ) )
q->error( QString::fromLatin1( "Unable to register object at dbus: %1" ).arg( QDBusConnection::sessionBus().lastError().message() ) );
mSettings = new QSettings( QString::fromLatin1( "%1/agent_config_%2" ).arg( XdgBaseDirs::saveDir( "config", QLatin1String( "akonadi" ) ), mId ), QSettings::IniFormat );
session = new Session( mId.toLatin1(), q );
monitor = new ChangeRecorder( q );
monitor->ignoreSession( session );
monitor->setConfig( mSettings );
mSession = new Session( mId.toLatin1(), q );
mMonitor = new ChangeRecorder( q );
mMonitor->ignoreSession( mSession );
mMonitor->setConfig( mSettings );
connect( monitor, SIGNAL( itemAdded( const Akonadi::Item&, const Akonadi::Collection& ) ),
mOnline = mSettings->value( QLatin1String( "Agent/Online" ), true ).toBool();
if ( mOnline )
mMonitor->itemFetchScope().setFetchAllParts( true );
connect( mMonitor, SIGNAL( itemAdded( const Akonadi::Item&, const Akonadi::Collection& ) ),
SLOT( itemAdded( const Akonadi::Item&, const Akonadi::Collection& ) ) );
connect( monitor, SIGNAL( itemChanged( const Akonadi::Item&, const QStringList& ) ),
connect( mMonitor, SIGNAL( itemChanged( const Akonadi::Item&, const QStringList& ) ),
SLOT( itemChanged( const Akonadi::Item&, const QStringList& ) ) );
connect( monitor, SIGNAL( itemRemoved( const Akonadi::Item& ) ),
connect( mMonitor, SIGNAL( itemRemoved( const Akonadi::Item& ) ),
SLOT( itemRemoved( const Akonadi::Item& ) ) );
connect( monitor, SIGNAL(collectionAdded(Akonadi::Collection,Akonadi::Collection)),
connect( mMonitor, SIGNAL(collectionAdded(Akonadi::Collection,Akonadi::Collection)),
SLOT(collectionAdded(Akonadi::Collection,Akonadi::Collection)) );
connect( monitor, SIGNAL( collectionChanged( const Akonadi::Collection& ) ),
connect( mMonitor, SIGNAL( collectionChanged( const Akonadi::Collection& ) ),
SLOT( collectionChanged( const Akonadi::Collection& ) ) );
connect( monitor, SIGNAL( collectionRemoved( const Akonadi::Collection& ) ),
connect( mMonitor, SIGNAL( collectionRemoved( const Akonadi::Collection& ) ),
SLOT( collectionRemoved( const Akonadi::Collection& ) ) );
QTimer::singleShot( 0, q, SLOT(delayedInit()) );
connect( q, SIGNAL( status( int, QString ) ), q, SLOT( slotStatus( int, QString ) ) );
connect( q, SIGNAL( percent( int ) ), q, SLOT( slotPercent( int ) ) );
QTimer::singleShot( 0, q, SLOT( delayedInit() ) );
}
void AgentBasePrivate::delayedInit()
......@@ -204,6 +216,48 @@ void AgentBasePrivate::collectionRemoved( const Akonadi::Collection &collection
mObserver->collectionRemoved( collection );
}
void AgentBasePrivate::changeProcessed()
{
mMonitor->changeProcessed();
QTimer::singleShot( 0, mMonitor, SLOT( replayNext() ) );
}
void AgentBasePrivate::slotStatus( int status, const QString &message )
{
mStatusMessage = message;
mStatusCode = 0;
switch ( status ) {
case AgentBase::Idle:
if ( mStatusMessage.isEmpty() )
mStatusMessage = defaultReadyMessage();
mStatusCode = 0;
break;
case AgentBase::Running:
if ( mStatusMessage.isEmpty() )
mStatusMessage = defaultSyncingMessage();
mStatusCode = 1;
break;
case AgentBase::Broken:
if ( mStatusMessage.isEmpty() )
mStatusMessage = defaultErrorMessage();
mStatusCode = 2;
break;
default:
Q_ASSERT( !"Unknown status passed" );
break;
}
}
void AgentBasePrivate::slotPercent( int progress )
{
mProgress = progress;
}
AgentBase::AgentBase( const QString & id )
: d_ptr( new AgentBasePrivate( this ) )
{
......@@ -267,6 +321,55 @@ int AgentBase::init( AgentBase *r )
return rv;
}
int AgentBase::status() const
{
Q_D( const AgentBase );
return d->mStatusCode;
}
QString AgentBase::statusMessage() const
{
Q_D( const AgentBase );
return d->mStatusMessage;
}
int AgentBase::progress() const
{
Q_D( const AgentBase );
return d->mProgress;
}
QString AgentBase::progressMessage() const
{
Q_D( const AgentBase );
return d->mProgressMessage;
}
bool AgentBase::isOnline() const
{
Q_D( const AgentBase );
return d->mOnline;
}
void AgentBase::setOnline( bool state )
{
Q_D( AgentBase );
d->mOnline = state;
d->mSettings->setValue( QLatin1String( "Agent/Online" ), state );
d->mMonitor->fetchCollection( state );
// TODO: d->monitor->fetchItemData( state );
}
void AgentBase::doSetOnline( bool online )
{
Q_UNUSED( online );
}
void AgentBase::configure( WId windowId )
{
Q_UNUSED( windowId );
......@@ -295,7 +398,7 @@ void AgentBase::quit()
aboutToQuit();
if ( d->mSettings ) {
d->monitor->setConfig( 0 );
d->mMonitor->setConfig( 0 );
d->mSettings->sync();
}
......@@ -314,7 +417,7 @@ void AgentBase::cleanup()
/**
* First destroy the settings object...
*/
d->monitor->setConfig( 0 );
d->mMonitor->setConfig( 0 );
delete d->mSettings;
d->mSettings = 0;
......@@ -339,7 +442,7 @@ QString AgentBase::identifier() const
Session* AgentBase::session() const
{
return d_ptr->session;
return d_ptr->mSession;
}
void AgentBase::warning( const QString& message )
......@@ -354,15 +457,15 @@ void AgentBase::error( const QString& message )
d->mTracer->error( QString::fromLatin1( "AgentBase(%1)" ).arg( d->mId ), message );
}
ChangeRecorder * AgentBase::changeRecorder() const
void AgentBase::changeProcessed()
{
return d_ptr->monitor;
Q_D( AgentBase );
d->changeProcessed();
}
void AgentBase::changeProcessed()
ChangeRecorder * AgentBase::changeRecorder() const
{
d_ptr->monitor->changeProcessed();
QTimer::singleShot( 0, d_ptr->monitor, SLOT(replayNext()) );
return d_ptr->mMonitor;
}
#include "agentbase.moc"
......
......@@ -30,7 +30,8 @@
#include <QtDBus/QDBusContext>
class AgentAdaptor;
class ControlAdaptor;
class StatusAdaptor;
namespace Akonadi {
......@@ -197,6 +198,17 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
virtual void collectionRemoved( const Akonadi::Collection &collection );
};
/**
* This enum describes the different states the
* agent can be in.
*/
enum Status
{
Idle = 0,
Running,
Broken
};
/**
* Use this method in the main function of your agent
* application to initialize your agent subclass.
......@@ -233,6 +245,32 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
return init( r );
}
/**
* This method returns the current status code of the resource.
*
* The following return values are possible:
*
* 0 - Idle
* 1 - Running
* 2 - Broken
*/
virtual int status() const;
/**
* This method returns an i18n'ed description of the current status code.
*/
virtual QString statusMessage() const;
/**
* This method returns the current progress of the resource in percentage.
*/
virtual int progress() const;
/**
* This method returns an i18n'ed description of the current progress.
*/
virtual QString progressMessage() const;
/**
* This method is called whenever the resource shall show its configuration dialog
* to the user. It will be automatically called when the resource is started for
......@@ -275,6 +313,15 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
*/
void registerObserver( Observer *observer );
Q_SIGNALS:
/**
*/
void status( int status, const QString &message = QString() );
/**
*/
void percent( int progress );
protected:
/**
* Creates a base agent.
......@@ -329,10 +376,11 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
* required when not using change recording, it is nevertheless recommended to
* to call this method when done with processing a change notification.
*/
//FIXME_API: move implementation to private class and make it virtual
virtual void changeProcessed();
void changeProcessed();
bool isOnline() const;
//FIXME_API: make setOnline virtual + template method
void setOnline( bool state );
protected:
//@cond PRIVATE
......@@ -340,6 +388,11 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
explicit AgentBase( AgentBasePrivate* d, const QString &id );
//@endcond
/**
* This method is called whenever the @p online status has changed.
*/
virtual void doSetOnline( bool online );
private Q_SLOTS: //FIXME_API: accessed privately by adapter
/**
* This method is called to quit the agent.
......@@ -354,10 +407,13 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
static int init( AgentBase *r );
// dbus resource interface
friend class ::AgentAdaptor;
friend class ::StatusAdaptor;
friend class ::ControlAdaptor;
Q_DECLARE_PRIVATE( AgentBase )
Q_PRIVATE_SLOT( d_func(), void delayedInit() )
Q_PRIVATE_SLOT( d_func(), void slotStatus( int, const QString& ) )
Q_PRIVATE_SLOT( d_func(), void slotPercent( int ) )
};
}
......
......@@ -40,6 +40,23 @@ class AgentBasePrivate : public QObject
void init();
virtual void delayedInit();
void slotStatus( int status, const QString &message );
void slotPercent( int progress );
virtual void changeProcessed();
QString defaultReadyMessage() const
{
if ( mOnline )
return i18nc( "@info:status, application ready for work", "Ready" );
return i18nc( "@info:status", "Offline" );
}
QString defaultSyncingMessage() const
{
return i18nc( "@info:status", "Syncing..." );
}
QString defaultErrorMessage() const
{
return i18nc( "@info:status", "Error!" );
......@@ -50,10 +67,18 @@ class AgentBasePrivate : public QObject
QString mId;
int mStatusCode;
QString mStatusMessage;
uint mProgress;
QString mProgressMessage;
bool mOnline;
QSettings *mSettings;
Session *session;
ChangeRecorder *monitor;
Session *mSession;
ChangeRecorder *mMonitor;
org::kde::Akonadi::Tracer *mTracer;
......
......@@ -243,7 +243,7 @@ void CollectionModelPrivate::init()
// monitor collection changes
monitor = new Monitor();
monitor->monitorCollection( Collection::root() );
monitor->setCollectionMonitored( Collection::root() );
monitor->fetchCollection( true );
// ### Hack to get the kmail resource folder icons
......
......@@ -206,3 +206,5 @@ void CollectionStatisticsDelegate::paint( QPainter *painter,
painter->drawText( textRect, option4.displayAlignment, text );
}
#include "collectionstatisticsdelegate.moc"
<!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.Agent.Control">
<method name="quit">
</method>
<method name="cleanup">
</method>
<method name="configure">
<arg name="windowId" type="x" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
</interface>
</node>
<!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.Agent.Status">
<signal name="status">
<arg name="status" type="i" direction="out"/>
<arg name="message" type="s" direction="out"/>
</signal>
<signal name="percent">
<arg name="percent" type="i" direction="out"/>
</signal>
<method name="status">
<arg type="i" direction="out"/>
</method>
<method name="statusMessage">
<arg type="s" direction="out"/>
</method>
<method name="progress">
<arg type="i" direction="out"/>
</method>
<method name="isOnline">
<arg type="b" direction="out"/>
</method>
<method name="setOnline">
<arg name="state" type="b" direction="in"/>
</method>
</interface>
</node>
<!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="nameChanged">
<arg name="name" type="s" direction="out"/>
</signal>
<method name="requestItemDelivery">
<arg type="b" direction="out"/>
<arg name="uid" type="x" direction="in"/>
<arg name="remoteId" type="s" direction="in"/>
<arg name="parts" type="as" direction="in"/>
</method>
<method name="synchronize">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="synchronizeCollectionTree">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="synchronizeCollection">
<arg name="collectionId" type="x" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setName">
<arg name="name" type="s" direction="in"/>
</method>
<method name="name">
<arg type="s" direction="out"/>
</method>
</interface>
</node>
......@@ -102,7 +102,7 @@ void ItemModel::Private::listingDone( KJob * job )
monitor->setItemFetchScope( mFetchScope );
monitor->ignoreSession( session );
monitor->monitorCollection( collection );
monitor->setCollectionMonitored( collection );
mParent->connect( monitor, SIGNAL(itemChanged( const Akonadi::Item&, const QStringList& )),
mParent, SLOT(itemChanged( const Akonadi::Item&, const QStringList& )) );
mParent->connect( monitor, SIGNAL(itemMoved( const Akonadi::Item&, const Akonadi::Collection&, const Akonadi::Collection& )),
......
......@@ -60,7 +60,7 @@ void ItemMonitor::setItem( const Item &item )
}
d->mMonitor->setItemFetchScope( fetchScope );
d->mMonitor->monitorItem( d->mItem );
d->mMonitor->setItemMonitored( d->mItem );
// start initial fetch of the new item
ItemFetchJob* job = new ItemFetchJob( d->mItem );
......
......@@ -56,29 +56,41 @@ Monitor::~Monitor()
delete d;
}
void Monitor::monitorCollection( const Collection &collection )
void Monitor::setCollectionMonitored( const Collection &collection, bool monitored )
{
d->collections << collection;
if ( monitored )
d->collections << collection;
else
d->collections.removeAll( collection );
}
void Monitor::monitorItem( const Item & item )
void Monitor::setItemMonitored( const Item & item, bool monitored )
{
d->items.insert( item.id() );
if ( monitored )
d->items.insert( item.id() );
else
d->items.remove( item.id() );
}
void Monitor::monitorResource(const QByteArray & resource)
void Monitor::setResourceMonitored( const QByteArray & resource, bool monitored )
{
d->resources.insert( resource );
if ( monitored )
d->resources.insert( resource );
else
d->resources.remove( resource );
}
void Monitor::monitorMimeType(const QString & mimetype)
void Monitor::setMimeTypeMonitored( const QString & mimetype, bool monitored )
{
d->mimetypes.insert( mimetype );
if ( monitored )
d->mimetypes.insert( mimetype );
else
d->mimetypes.remove( mimetype );
}