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

akonadi

resourcescheduler.cpp

00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "resourcescheduler.h"
00021 
00022 #include <kdebug.h>
00023 
00024 #include <QtCore/QTimer>
00025 
00026 using namespace Akonadi;
00027 
00028 //@cond PRIVATE
00029 
00030 ResourceScheduler::ResourceScheduler( QObject *parent ) :
00031     QObject( parent ),
00032     mOnline( false )
00033 {
00034 }
00035 
00036 void ResourceScheduler::scheduleFullSync()
00037 {
00038   Task t;
00039   t.type = SyncAll;
00040   mTaskList << t;
00041   scheduleNext();
00042 }
00043 
00044 void ResourceScheduler::scheduleCollectionTreeSync()
00045 {
00046   Task t;
00047   t.type = SyncCollectionTree;
00048   mTaskList << t;
00049   scheduleNext();
00050 }
00051 
00052 void ResourceScheduler::scheduleSync(const Collection & col)
00053 {
00054   Task t;
00055   t.type = SyncCollection;
00056   t.collection = col;
00057   mTaskList << t;
00058   scheduleNext();
00059 }
00060 
00061 void ResourceScheduler::scheduleItemFetch(const Item & item, const QSet<QByteArray> &parts, const QDBusMessage & msg)
00062 {
00063   Task t;
00064   t.type = FetchItem;
00065   t.item = item;
00066   t.itemParts = parts;
00067   t.dbusMsg = msg;
00068   mTaskList << t;
00069   scheduleNext();
00070 }
00071 
00072 void ResourceScheduler::scheduleResourceCollectionDeletion()
00073 {
00074   Task t;
00075   t.type = DeleteResourceCollection;
00076   mTaskList << t;
00077   scheduleNext();
00078 }
00079 
00080 void ResourceScheduler::scheduleChangeReplay()
00081 {
00082   Task t;
00083   t.type = ChangeReplay;
00084   if ( mTaskList.contains( t ) )
00085     return;
00086   mTaskList << t;
00087   scheduleNext();
00088 }
00089 
00090 void ResourceScheduler::taskDone()
00091 {
00092   if ( isEmpty() )
00093     emit status( AgentBase::Idle );
00094   mCurrentTask = Task();
00095   scheduleNext();
00096 }
00097 
00098 bool ResourceScheduler::isEmpty()
00099 {
00100   return mTaskList.isEmpty();
00101 }
00102 
00103 void ResourceScheduler::scheduleNext()
00104 {
00105   if ( mCurrentTask.type != Invalid || mTaskList.isEmpty() || !mOnline )
00106     return;
00107   QTimer::singleShot( 0, this, SLOT(executeNext()) );
00108 }
00109 
00110 void ResourceScheduler::executeNext()
00111 {
00112   if( mCurrentTask.type != Invalid || mTaskList.isEmpty() )
00113     return;
00114 
00115   mCurrentTask = mTaskList.takeFirst();
00116   switch ( mCurrentTask.type ) {
00117     case SyncAll:
00118       emit executeFullSync();
00119       break;
00120     case SyncCollectionTree:
00121       emit executeCollectionTreeSync();
00122       break;
00123     case SyncCollection:
00124       emit executeCollectionSync( mCurrentTask.collection );
00125       break;
00126     case FetchItem:
00127       emit executeItemFetch( mCurrentTask.item, mCurrentTask.itemParts );
00128       break;
00129     case DeleteResourceCollection:
00130       emit executeResourceCollectionDeletion();
00131       break;
00132     case ChangeReplay:
00133       emit executeChangeReplay();
00134       break;
00135     default:
00136       Q_ASSERT( false );
00137   }
00138 }
00139 
00140 ResourceScheduler::Task ResourceScheduler::currentTask() const
00141 {
00142   return mCurrentTask;
00143 }
00144 
00145 void ResourceScheduler::setOnline(bool state)
00146 {
00147   if ( mOnline == state )
00148     return;
00149   mOnline = state;
00150   if ( mOnline ) {
00151     scheduleNext();
00152   } else if ( mCurrentTask.type != Invalid ) {
00153     // abort running task
00154     mTaskList.prepend( mCurrentTask );
00155     mCurrentTask = Task();
00156   }
00157 }
00158 
00159 //@endcond
00160 
00161 #include "resourcescheduler.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
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7
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