akonadi
agentbase.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef AKONADI_AGENTBASE_H
00025 #define AKONADI_AGENTBASE_H
00026
00027 #include "akonadi_export.h"
00028
00029 #include <KDE/KApplication>
00030
00031 #include <QtDBus/QDBusContext>
00032
00033 class ControlAdaptor;
00034 class StatusAdaptor;
00035
00036 namespace Akonadi {
00037
00038 class AgentBasePrivate;
00039 class ChangeRecorder;
00040 class Collection;
00041 class Item;
00042 class Session;
00043
00058 class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
00059 {
00060 Q_OBJECT
00061
00062 public:
00159 class AKONADI_EXPORT Observer
00160 {
00161 public:
00165 Observer();
00166
00170 virtual ~Observer();
00171
00177 virtual void itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection );
00178
00184 virtual void itemChanged( const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers );
00185
00190 virtual void itemRemoved( const Akonadi::Item &item );
00191
00197 virtual void collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent );
00198
00203 virtual void collectionChanged( const Akonadi::Collection &collection );
00204
00209 virtual void collectionRemoved( const Akonadi::Collection &collection );
00210 };
00211
00218 class AKONADI_EXPORT ObserverV2 : public Observer
00219 {
00220 public:
00221 using Observer::collectionChanged;
00222
00233 virtual void itemMoved( const Akonadi::Item &item, const Akonadi::Collection &collectionSource,
00234 const Akonadi::Collection &collectionDestination );
00235
00242 virtual void itemLinked( const Akonadi::Item &item, const Akonadi::Collection &collection );
00243
00250 virtual void itemUnlinked( const Akonadi::Item &item, const Akonadi::Collection &collection );
00251
00262 virtual void collectionMoved( const Akonadi::Collection &collection, const Akonadi::Collection &collectionSource,
00263 const Akonadi::Collection &collectionDestination );
00264
00270 virtual void collectionChanged( const Akonadi::Collection &collection, const QSet<QByteArray> &changedAttributes );
00271 };
00272
00277 enum Status
00278 {
00279 Idle = 0,
00280 Running,
00281 Broken
00282 };
00283
00305 template <typename T>
00306 static int init( int argc, char **argv )
00307 {
00308 const QString id = parseArguments( argc, argv );
00309 KApplication app;
00310 T* r = new T( id );
00311
00312
00313
00314 Observer *observer = dynamic_cast<Observer*>( r );
00315 if ( observer != 0 )
00316 r->registerObserver( observer );
00317 return init( r );
00318 }
00319
00329 virtual int status() const;
00330
00334 virtual QString statusMessage() const;
00335
00339 virtual int progress() const;
00340
00344 virtual QString progressMessage() const;
00345
00356 virtual void configure( WId windowId );
00357
00361 WId winIdForDialogs() const;
00362
00363 #ifdef Q_OS_WIN
00364
00368 void configure( qlonglong windowId );
00369 #endif
00370
00374 QString identifier() const;
00375
00383 virtual void cleanup();
00384
00392 void registerObserver( Observer *observer );
00393
00399
00400 void setAgentName( const QString &name );
00401
00407 QString agentName() const;
00408
00409 Q_SIGNALS:
00417 void agentNameChanged( const QString &name );
00418
00424 void status( int status, const QString &message = QString() );
00425
00432 void percent( int progress );
00433
00439 void warning( const QString& message );
00440
00446 void error( const QString& message );
00447
00456 void abortRequested();
00457
00464 void reloadConfiguration();
00465
00471 void onlineChanged( bool b );
00472
00481 void configurationDialogAccepted();
00482
00491 void configurationDialogRejected();
00492
00493 protected:
00499 AgentBase( const QString & id );
00500
00504 ~AgentBase();
00505
00513 virtual void aboutToQuit();
00514
00519 ChangeRecorder* changeRecorder() const;
00520
00528 void changeProcessed();
00529
00533 bool isOnline() const;
00534
00542 void setNeedsNetwork( bool needsNetwork );
00543
00547 void setOnline( bool state );
00548
00549 protected:
00550
00551 AgentBasePrivate *d_ptr;
00552 explicit AgentBase( AgentBasePrivate* d, const QString &id );
00553
00554
00559 virtual void doSetOnline( bool online );
00560
00561 private:
00562
00563 static QString parseArguments( int, char** );
00564 static int init( AgentBase *r );
00565
00566
00567 void abort();
00568 void reconfigure();
00569 void quit();
00570
00571
00572 friend class ::StatusAdaptor;
00573 friend class ::ControlAdaptor;
00574
00575 Q_DECLARE_PRIVATE( AgentBase )
00576 Q_PRIVATE_SLOT( d_func(), void delayedInit() )
00577 Q_PRIVATE_SLOT( d_func(), void slotStatus( int, const QString& ) )
00578 Q_PRIVATE_SLOT( d_func(), void slotPercent( int ) )
00579 Q_PRIVATE_SLOT( d_func(), void slotWarning( const QString& ) )
00580 Q_PRIVATE_SLOT( d_func(), void slotError( const QString& ) )
00581 Q_PRIVATE_SLOT( d_func(), void slotNetworkStatusChange( Solid::Networking::Status ) )
00582
00583
00584 };
00585
00586 }
00587
00588 #ifndef AKONADI_AGENT_MAIN
00589
00592 #define AKONADI_AGENT_MAIN( agentClass ) \
00593 int main( int argc, char **argv ) \
00594 { \
00595 return Akonadi::AgentBase::init<agentClass>( argc, argv ); \
00596 }
00597 #endif
00598
00599 #endif