• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

agentbase.cpp

00001 /*
00002     Copyright (c) 2006 Till Adam <adam@kde.org>
00003     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00004     Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
00005     Copyright (c) 2008 Kevin Krammer <kevin.krammer@gmx.at>
00006 
00007     This library is free software; you can redistribute it and/or modify it
00008     under the terms of the GNU Library General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or (at your
00010     option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful, but WITHOUT
00013     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015     License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to the
00019     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020     02110-1301, USA.
00021 */
00022 
00023 #include "agentbase.h"
00024 #include "agentbase_p.h"
00025 
00026 #include "changerecorder.h"
00027 #include "controladaptor.h"
00028 #include "itemfetchjob.h"
00029 #include "monitor_p.h"
00030 #include "session.h"
00031 #include "session_p.h"
00032 #include "statusadaptor.h"
00033 #include "xdgbasedirs_p.h"
00034 
00035 #include <kaboutdata.h>
00036 #include <kcmdlineargs.h>
00037 #include <kdebug.h>
00038 #include <klocale.h>
00039 #include <kstandarddirs.h>
00040 
00041 #include <QtCore/QDir>
00042 #include <QtCore/QSettings>
00043 #include <QtCore/QTimer>
00044 #include <QtDBus/QtDBus>
00045 #include <QtGui/QApplication>
00046 
00047 #include <signal.h>
00048 #include <stdlib.h>
00049 
00050 using namespace Akonadi;
00051 
00052 static AgentBase *sAgentBase = 0;
00053 
00054 AgentBase::Observer::Observer()
00055 {
00056 }
00057 
00058 AgentBase::Observer::~Observer()
00059 {
00060 }
00061 
00062 void AgentBase::Observer::itemAdded( const Item &item, const Collection &collection )
00063 {
00064   Q_UNUSED( item );
00065   Q_UNUSED( collection );
00066   if ( sAgentBase != 0 )
00067     sAgentBase->d_ptr->changeProcessed();
00068 }
00069 
00070 void AgentBase::Observer::itemChanged( const Item &item, const QSet<QByteArray> &partIdentifiers )
00071 {
00072   Q_UNUSED( item );
00073   Q_UNUSED( partIdentifiers );
00074   if ( sAgentBase != 0 )
00075     sAgentBase->d_ptr->changeProcessed();
00076 }
00077 
00078 void AgentBase::Observer::itemRemoved( const Item &item )
00079 {
00080   Q_UNUSED( item );
00081   if ( sAgentBase != 0 )
00082     sAgentBase->d_ptr->changeProcessed();
00083 }
00084 
00085 void AgentBase::Observer::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent )
00086 {
00087   Q_UNUSED( collection );
00088   Q_UNUSED( parent );
00089   if ( sAgentBase != 0 )
00090     sAgentBase->d_ptr->changeProcessed();
00091 }
00092 
00093 void AgentBase::Observer::collectionChanged( const Collection &collection )
00094 {
00095   Q_UNUSED( collection );
00096   if ( sAgentBase != 0 )
00097     sAgentBase->d_ptr->changeProcessed();
00098 }
00099 
00100 void AgentBase::Observer::collectionRemoved( const Collection &collection )
00101 {
00102   Q_UNUSED( collection );
00103   if ( sAgentBase != 0 )
00104     sAgentBase->d_ptr->changeProcessed();
00105 }
00106 
00107 void AgentBase::ObserverV2::itemMoved( const Akonadi::Item &item, const Akonadi::Collection &source, const Akonadi::Collection &dest )
00108 {
00109   Q_UNUSED( item );
00110   Q_UNUSED( source );
00111   Q_UNUSED( dest );
00112   if ( sAgentBase != 0 )
00113     sAgentBase->d_ptr->changeProcessed();
00114 }
00115 
00116 void AgentBase::ObserverV2::itemLinked( const Akonadi::Item& item, const Akonadi::Collection& collection )
00117 {
00118   Q_UNUSED( item );
00119   Q_UNUSED( collection );
00120   if ( sAgentBase != 0 )
00121     sAgentBase->d_ptr->changeProcessed();
00122 }
00123 
00124 void AgentBase::ObserverV2::itemUnlinked( const Akonadi::Item& item, const Akonadi::Collection& collection )
00125 {
00126   Q_UNUSED( item );
00127   Q_UNUSED( collection );
00128   if ( sAgentBase != 0 )
00129     sAgentBase->d_ptr->changeProcessed();
00130 }
00131 
00132 void AgentBase::ObserverV2::collectionMoved( const Akonadi::Collection &collection, const Akonadi::Collection &source, const Akonadi::Collection &dest )
00133 {
00134   Q_UNUSED( collection );
00135   Q_UNUSED( source );
00136   Q_UNUSED( dest );
00137   if ( sAgentBase != 0 )
00138     sAgentBase->d_ptr->changeProcessed();
00139 }
00140 
00141 void AgentBase::ObserverV2::collectionChanged( const Akonadi::Collection &collection, const QSet<QByteArray> &partIdentifiers )
00142 {
00143   Q_UNUSED( partIdentifiers );
00144   collectionChanged( collection );
00145 }
00146 
00147 //@cond PRIVATE
00148 
00149 AgentBasePrivate::AgentBasePrivate( AgentBase *parent )
00150   : q_ptr( parent ),
00151     mStatusCode( AgentBase::Idle ),
00152     mProgress( 0 ),
00153     mNeedsNetwork( false ),
00154     mOnline( false ),
00155     mSettings( 0 ),
00156     mObserver( 0 )
00157 {
00158 }
00159 
00160 AgentBasePrivate::~AgentBasePrivate()
00161 {
00162   mMonitor->setConfig( 0 );
00163   delete mSettings;
00164 }
00165 
00166 void AgentBasePrivate::init()
00167 {
00168   Q_Q( AgentBase );
00169 
00173   SessionPrivate::createDefaultSession( mId.toLatin1() );
00174 
00175   mTracer = new org::freedesktop::Akonadi::Tracer( QLatin1String( "org.freedesktop.Akonadi" ), QLatin1String( "/tracing" ),
00176                                            QDBusConnection::sessionBus(), q );
00177 
00178   new ControlAdaptor( q );
00179   new StatusAdaptor( q );
00180   if ( !QDBusConnection::sessionBus().registerObject( QLatin1String( "/" ), q, QDBusConnection::ExportAdaptors ) )
00181     q->error( QString::fromLatin1( "Unable to register object at dbus: %1" ).arg( QDBusConnection::sessionBus().lastError().message() ) );
00182 
00183   mSettings = new QSettings( QString::fromLatin1( "%1/agent_config_%2" ).arg( XdgBaseDirs::saveDir( "config", QLatin1String( "akonadi" ) ), mId ), QSettings::IniFormat );
00184 
00185   mMonitor = new ChangeRecorder( q );
00186   mMonitor->ignoreSession( Session::defaultSession() );
00187   mMonitor->itemFetchScope().setCacheOnly( true );
00188   mMonitor->setConfig( mSettings );
00189 
00190   mOnline = mSettings->value( QLatin1String( "Agent/Online" ), true ).toBool();
00191 
00192   // reinitialize the status message now that online state is available
00193   mStatusMessage = defaultReadyMessage();
00194 
00195   mName = mSettings->value( QLatin1String( "Agent/Name" ) ).toString();
00196   if ( mName.isEmpty() ) {
00197     mName = mSettings->value( QLatin1String( "Resource/Name" ) ).toString();
00198     if ( !mName.isEmpty() ) {
00199       mSettings->remove( QLatin1String( "Resource/Name" ) );
00200       mSettings->setValue( QLatin1String( "Agent/Name" ), mName );
00201     }
00202   }
00203 
00204   connect( mMonitor, SIGNAL( itemAdded( const Akonadi::Item&, const Akonadi::Collection& ) ),
00205            SLOT( itemAdded( const Akonadi::Item&, const Akonadi::Collection& ) ) );
00206   connect( mMonitor, SIGNAL( itemChanged( const Akonadi::Item&, const QSet<QByteArray>& ) ),
00207            SLOT( itemChanged( const Akonadi::Item&, const QSet<QByteArray>& ) ) );
00208   connect( mMonitor, SIGNAL( itemMoved( const Akonadi::Item&, const Akonadi::Collection&, const Akonadi::Collection& ) ),
00209            SLOT( itemMoved( const Akonadi::Item&, const Akonadi::Collection&, const Akonadi::Collection& ) ) );
00210   connect( mMonitor, SIGNAL( itemRemoved( const Akonadi::Item& ) ),
00211            SLOT( itemRemoved( const Akonadi::Item& ) ) );
00212   connect( mMonitor, SIGNAL( collectionAdded( const Akonadi::Collection&, const Akonadi::Collection& ) ),
00213            SLOT( collectionAdded( const Akonadi::Collection&, const Akonadi::Collection& ) ) );
00214   connect( mMonitor, SIGNAL( itemLinked( const Akonadi::Item&, const Akonadi::Collection& ) ),
00215            SLOT( itemLinked( const Akonadi::Item&, const Akonadi::Collection& ) ) );
00216   connect( mMonitor, SIGNAL( itemUnlinked( const Akonadi::Item&, const Akonadi::Collection& ) ),
00217            SLOT( itemUnlinked( const Akonadi::Item&, const Akonadi::Collection& ) ) );
00218   connect( mMonitor, SIGNAL( collectionChanged( const Akonadi::Collection& ) ),
00219            SLOT( collectionChanged( const Akonadi::Collection& ) ) );
00220   connect( mMonitor, SIGNAL( collectionChanged( const Akonadi::Collection&, const QSet<QByteArray>& ) ),
00221            SLOT( collectionChanged( const Akonadi::Collection&, const QSet<QByteArray>& ) ) );
00222   connect( mMonitor, SIGNAL( collectionMoved( const Akonadi::Collection&, const Akonadi::Collection&, const Akonadi::Collection& ) ),
00223            SLOT( collectionMoved( const Akonadi::Collection&, const Akonadi::Collection&, const Akonadi::Collection& ) ) );
00224   connect( mMonitor, SIGNAL( collectionRemoved( const Akonadi::Collection& ) ),
00225            SLOT( collectionRemoved( const Akonadi::Collection& ) ) );
00226 
00227   connect( q, SIGNAL( status( int, const QString& ) ), q, SLOT( slotStatus( int, const QString& ) ) );
00228   connect( q, SIGNAL( percent( int ) ), q, SLOT( slotPercent( int ) ) );
00229   connect( q, SIGNAL( warning( const QString& ) ), q, SLOT( slotWarning( const QString& ) ) );
00230   connect( q, SIGNAL( error( const QString& ) ), q, SLOT( slotError( const QString& ) ) );
00231 
00232   // Use reference counting to allow agents to finish internal jobs when the
00233   // agent is stopped.
00234   KGlobal::ref();
00235   KGlobal::setAllowQuit( true );
00236 
00237   // disable session management
00238   if ( KApplication::kApplication() )
00239     KApplication::kApplication()->disableSessionManagement();
00240 
00241   QTimer::singleShot( 0, q, SLOT( delayedInit() ) );
00242 }
00243 
00244 void AgentBasePrivate::delayedInit()
00245 {
00246   Q_Q( AgentBase );
00247   if ( !QDBusConnection::sessionBus().registerService( QLatin1String( "org.freedesktop.Akonadi.Agent." ) + mId ) )
00248     kFatal() << "Unable to register service at dbus:" << QDBusConnection::sessionBus().lastError().message();
00249   q->setOnline( mOnline );
00250 }
00251 
00252 void AgentBasePrivate::itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection )
00253 {
00254   if ( mObserver != 0 )
00255     mObserver->itemAdded( item, collection );
00256 }
00257 
00258 void AgentBasePrivate::itemChanged( const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers )
00259 {
00260   if ( mObserver != 0 )
00261     mObserver->itemChanged( item, partIdentifiers );
00262 }
00263 
00264 void AgentBasePrivate::itemMoved( const Akonadi::Item &item, const Akonadi::Collection &source, const Akonadi::Collection &dest )
00265 {
00266   AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
00267   if ( mObserver ) {
00268     // inter-resource moves, requires we know which resources the source and destination are in though
00269     if ( !source.resource().isEmpty() && !dest.resource().isEmpty() ) {
00270       if ( source.resource() != dest.resource() ) {
00271         if ( source.resource() == q_ptr->identifier() ) // moved away from us
00272           mObserver->itemRemoved( item );
00273         else if ( dest.resource() == q_ptr->identifier() ) // moved to us
00274           mObserver->itemAdded( item, dest );
00275         else if ( observer2 )
00276           observer2->itemMoved( item, source, dest );
00277         else
00278           // not for us, not sure if we should get here at all
00279           changeProcessed();
00280         return;
00281       }
00282     }
00283     // intra-resource move
00284     if ( observer2 ) {
00285       observer2->itemMoved( item, source, dest );
00286     } else {
00287       // ### we cannot just call itemRemoved here as this will already trigger changeProcessed()
00288       // so, just itemAdded() is good enough as no resource can have implemented intra-resource moves anyway
00289       // without using ObserverV2
00290       mObserver->itemAdded( item, dest );
00291       // mObserver->itemRemoved( item );
00292     }
00293   }
00294 }
00295 
00296 void AgentBasePrivate::itemRemoved( const Akonadi::Item &item )
00297 {
00298   if ( mObserver != 0 )
00299     mObserver->itemRemoved( item );
00300 }
00301 
00302 void AgentBasePrivate::itemLinked( const Akonadi::Item &item, const Akonadi::Collection &collection )
00303 {
00304   AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
00305   if ( observer2 )
00306     observer2->itemLinked( item, collection );
00307   else
00308     changeProcessed();
00309 }
00310 
00311 void AgentBasePrivate::itemUnlinked( const Akonadi::Item &item, const Akonadi::Collection &collection )
00312 {
00313   AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
00314   if ( observer2 )
00315     observer2->itemUnlinked( item, collection );
00316   else
00317     changeProcessed();
00318 }
00319 
00320 void AgentBasePrivate::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent )
00321 {
00322   if ( mObserver != 0 )
00323     mObserver->collectionAdded( collection, parent );
00324 }
00325 
00326 void AgentBasePrivate::collectionChanged( const Akonadi::Collection &collection )
00327 {
00328   AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
00329   if ( mObserver != 0 && observer2 == 0 ) // For ObserverV2 we use the variant with the part identifiers
00330     mObserver->collectionChanged( collection );
00331 }
00332 
00333 void AgentBasePrivate::collectionChanged( const Akonadi::Collection &collection, const QSet<QByteArray> &partIdentifiers )
00334 {
00335   AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
00336   if ( observer2 != 0 )
00337     observer2->collectionChanged( collection, partIdentifiers );
00338 }
00339 
00340 void AgentBasePrivate::collectionMoved( const Akonadi::Collection &collection, const Akonadi::Collection &source, const Akonadi::Collection &dest )
00341 {
00342   AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
00343   if ( mObserver ) {
00344     // inter-resource moves, requires we know which resources the source and destination are in though
00345     if ( !source.resource().isEmpty() && !dest.resource().isEmpty() ) {
00346       if ( source.resource() != dest.resource() ) {
00347         if ( source.resource() == q_ptr->identifier() ) // moved away from us
00348           mObserver->collectionRemoved( collection );
00349         else if ( dest.resource() == q_ptr->identifier() ) // moved to us
00350           mObserver->collectionAdded( collection, dest );
00351         else if ( observer2 )
00352           observer2->collectionMoved( collection, source, dest );
00353         else // not for us, not sure if we should get here at all
00354           changeProcessed();
00355         return;
00356       }
00357     }
00358     // intra-resource move
00359     if ( observer2 ) {
00360       observer2->collectionMoved( collection, source, dest );
00361     } else {
00362       // ### we cannot just call collectionRemoved here as this will already trigger changeProcessed()
00363       // so, just collectionAdded() is good enough as no resource can have implemented intra-resource moves anyway
00364       // without using ObserverV2
00365       mObserver->collectionAdded( collection, dest );
00366     }
00367   }
00368 }
00369 
00370 void AgentBasePrivate::collectionRemoved( const Akonadi::Collection &collection )
00371 {
00372   if ( mObserver != 0 )
00373     mObserver->collectionRemoved( collection );
00374 }
00375 
00376 void AgentBasePrivate::changeProcessed()
00377 {
00378   mMonitor->changeProcessed();
00379   QTimer::singleShot( 0, mMonitor, SLOT( replayNext() ) );
00380 }
00381 
00382 void AgentBasePrivate::slotStatus( int status, const QString &message )
00383 {
00384   mStatusMessage = message;
00385   mStatusCode = 0;
00386 
00387   switch ( status ) {
00388     case AgentBase::Idle:
00389       if ( mStatusMessage.isEmpty() )
00390         mStatusMessage = defaultReadyMessage();
00391 
00392       mStatusCode = 0;
00393       break;
00394     case AgentBase::Running:
00395       if ( mStatusMessage.isEmpty() )
00396         mStatusMessage = defaultSyncingMessage();
00397 
00398       mStatusCode = 1;
00399       break;
00400     case AgentBase::Broken:
00401       if ( mStatusMessage.isEmpty() )
00402         mStatusMessage = defaultErrorMessage();
00403 
00404       mStatusCode = 2;
00405       break;
00406     default:
00407       Q_ASSERT( !"Unknown status passed" );
00408       break;
00409   }
00410 }
00411 
00412 void AgentBasePrivate::slotPercent( int progress )
00413 {
00414   mProgress = progress;
00415 }
00416 
00417 void AgentBasePrivate::slotWarning( const QString& message )
00418 {
00419   mTracer->warning( QString::fromLatin1( "AgentBase(%1)" ).arg( mId ), message );
00420 }
00421 
00422 void AgentBasePrivate::slotError( const QString& message )
00423 {
00424   mTracer->error( QString::fromLatin1( "AgentBase(%1)" ).arg( mId ), message );
00425 }
00426 
00427 void AgentBasePrivate::slotNetworkStatusChange( Solid::Networking::Status stat )
00428 {
00429   Q_Q( AgentBase );
00430   q->setOnline( stat == Solid::Networking::Connected );
00431 }
00432 
00433 
00434 AgentBase::AgentBase( const QString & id )
00435   : d_ptr( new AgentBasePrivate( this ) )
00436 {
00437   sAgentBase = this;
00438   d_ptr->mId = id;
00439   d_ptr->init();
00440 }
00441 
00442 AgentBase::AgentBase( AgentBasePrivate* d, const QString &id ) :
00443     d_ptr( d )
00444 {
00445   sAgentBase = this;
00446   d_ptr->mId = id;
00447   d_ptr->init();
00448 }
00449 
00450 AgentBase::~AgentBase()
00451 {
00452   delete d_ptr;
00453 }
00454 
00455 QString AgentBase::parseArguments( int argc, char **argv )
00456 {
00457   QString identifier;
00458   if ( argc < 3 ) {
00459     kDebug() << "Not enough arguments passed...";
00460     exit( 1 );
00461   }
00462 
00463   for ( int i = 1; i < argc - 1; ++i ) {
00464     if ( QLatin1String( argv[ i ] ) == QLatin1String( "--identifier" ) )
00465       identifier = QLatin1String( argv[ i + 1 ] );
00466   }
00467 
00468   if ( identifier.isEmpty() ) {
00469     kDebug() << "Identifier argument missing";
00470     exit( 1 );
00471   }
00472 
00473   QByteArray catalog;
00474   char *p = strrchr( argv[0], '/' );
00475   if ( p )
00476     catalog = QByteArray( p + 1 );
00477   else
00478     catalog = QByteArray( argv[0] );
00479 
00480   KCmdLineArgs::init( argc, argv, identifier.toLatin1(), catalog, ki18n( "Akonadi Agent" ), "0.1",
00481                       ki18n( "Akonadi Agent" ) );
00482 
00483   KCmdLineOptions options;
00484   options.add( "identifier <argument>", ki18n( "Agent identifier" ) );
00485   KCmdLineArgs::addCmdLineOptions( options );
00486 
00487   return identifier;
00488 }
00489 
00490 // @endcond
00491 
00492 int AgentBase::init( AgentBase *r )
00493 {
00494   QApplication::setQuitOnLastWindowClosed( false );
00495   KGlobal::locale()->insertCatalog( QLatin1String( "libakonadi" ) );
00496   int rv = kapp->exec();
00497   delete r;
00498   return rv;
00499 }
00500 
00501 int AgentBase::status() const
00502 {
00503   Q_D( const AgentBase );
00504 
00505   return d->mStatusCode;
00506 }
00507 
00508 QString AgentBase::statusMessage() const
00509 {
00510   Q_D( const AgentBase );
00511 
00512   return d->mStatusMessage;
00513 }
00514 
00515 int AgentBase::progress() const
00516 {
00517   Q_D( const AgentBase );
00518 
00519   return d->mProgress;
00520 }
00521 
00522 QString AgentBase::progressMessage() const
00523 {
00524   Q_D( const AgentBase );
00525 
00526   return d->mProgressMessage;
00527 }
00528 
00529 bool AgentBase::isOnline() const
00530 {
00531   Q_D( const AgentBase );
00532 
00533   return d->mOnline;
00534 }
00535 
00536 void AgentBase::setNeedsNetwork( bool needsNetwork )
00537 {
00538   Q_D( AgentBase );
00539   d->mNeedsNetwork = needsNetwork;
00540 
00541   if ( d->mNeedsNetwork ) {
00542     connect( Solid::Networking::notifier()
00543            , SIGNAL( statusChanged( Solid::Networking::Status ) )
00544            , this, SLOT( slotNetworkStatusChange( Solid::Networking::Status ) ) );
00545   } else {
00546     disconnect( Solid::Networking::notifier(), 0, 0, 0 );
00547     setOnline( true );
00548   }
00549 }
00550 
00551 void AgentBase::setOnline( bool state )
00552 {
00553   Q_D( AgentBase );
00554   d->mOnline = state;
00555   d->mSettings->setValue( QLatin1String( "Agent/Online" ), state );
00556   doSetOnline( state );
00557   emit onlineChanged( state );
00558 }
00559 
00560 void AgentBase::doSetOnline( bool online )
00561 {
00562   Q_UNUSED( online );
00563 }
00564 
00565 void AgentBase::configure( WId windowId )
00566 {
00567   Q_UNUSED( windowId );
00568   emit configurationDialogAccepted();
00569 }
00570 
00571 #ifdef Q_OS_WIN //krazy:exclude=cpp
00572 void AgentBase::configure( qlonglong windowId )
00573 {
00574   configure( reinterpret_cast<WId>( windowId ) );
00575 }
00576 #endif
00577 
00578 WId AgentBase::winIdForDialogs() const
00579 {
00580   const bool registered = QDBusConnection::sessionBus().interface()->isServiceRegistered( QLatin1String( "org.freedesktop.akonaditray" ) );
00581   if ( !registered )
00582     return 0;
00583 
00584   QDBusInterface dbus( QLatin1String( "org.freedesktop.akonaditray" ), QLatin1String( "/Actions" ),
00585                        QLatin1String( "org.freedesktop.Akonadi.Tray" ) );
00586   const QDBusMessage reply = dbus.call( QLatin1String( "getWinId" ) );
00587 
00588   if ( reply.type() == QDBusMessage::ErrorMessage )
00589     return 0;
00590 
00591   const WId winid = (WId)reply.arguments().at( 0 ).toLongLong();
00592 
00593   return winid;
00594 }
00595 
00596 void AgentBase::quit()
00597 {
00598   Q_D( AgentBase );
00599   aboutToQuit();
00600 
00601   if ( d->mSettings ) {
00602     d->mMonitor->setConfig( 0 );
00603     d->mSettings->sync();
00604   }
00605 
00606   KGlobal::deref();
00607 }
00608 
00609 void AgentBase::aboutToQuit()
00610 {
00611 }
00612 
00613 void AgentBase::cleanup()
00614 {
00615   Q_D( AgentBase );
00616   // prevent the monitor from picking up deletion signals for our own data if we are a resource
00617   // and thus avoid that we kill our own data as last act before our own death
00618   d->mMonitor->blockSignals( true );
00619 
00620   aboutToQuit();
00621 
00622   const QString fileName = d->mSettings->fileName();
00623 
00624   /*
00625    * First destroy the settings object...
00626    */
00627   d->mMonitor->setConfig( 0 );
00628   delete d->mSettings;
00629   d->mSettings = 0;
00630 
00631   /*
00632    * ... then remove the file from hd.
00633    */
00634   QFile::remove( fileName );
00635 
00636   /*
00637    * ... and also remove the agent configuration file if there is one.
00638    */
00639   QString configFile = KStandardDirs::locateLocal( "config", KGlobal::config()->name() );
00640   QFile::remove( configFile );
00641 
00642   KGlobal::deref();
00643 }
00644 
00645 void AgentBase::registerObserver( Observer *observer )
00646 {
00647   d_ptr->mObserver = observer;
00648 }
00649 
00650 QString AgentBase::identifier() const
00651 {
00652   return d_ptr->mId;
00653 }
00654 
00655 void AgentBase::setAgentName( const QString &name )
00656 {
00657   Q_D( AgentBase );
00658   if ( name == d->mName )
00659     return;
00660 
00661   // TODO: rename collection
00662   d->mName = name;
00663 
00664   if ( d->mName.isEmpty() || d->mName == d->mId ) {
00665     d->mSettings->remove( QLatin1String( "Resource/Name" ) );
00666     d->mSettings->remove( QLatin1String( "Agent/Name" ) );
00667   } else
00668     d->mSettings->setValue( QLatin1String( "Agent/Name" ), d->mName );
00669 
00670   d->mSettings->sync();
00671 
00672   emit agentNameChanged( d->mName );
00673 }
00674 
00675 QString AgentBase::agentName() const
00676 {
00677   Q_D( const AgentBase );
00678   if ( d->mName.isEmpty() )
00679     return d->mId;
00680   else
00681     return d->mName;
00682 }
00683 
00684 void AgentBase::changeProcessed()
00685 {
00686   Q_D( AgentBase );
00687   d->changeProcessed();
00688 }
00689 
00690 ChangeRecorder * AgentBase::changeRecorder() const
00691 {
00692   return d_ptr->mMonitor;
00693 }
00694 
00695 void AgentBase::abort()
00696 {
00697   emit abortRequested();
00698 }
00699 
00700 void AgentBase::reconfigure()
00701 {
00702   emit reloadConfiguration();
00703 }
00704 
00705 #include "agentbase.moc"
00706 #include "agentbase_p.moc"

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal