• Skip to content
  • Skip to link menu
KDE 4.1 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 <QTimer>
00025 
00026 using namespace Akonadi;
00027 
00028 ResourceScheduler::ResourceScheduler( QObject *parent ) :
00029     QObject( parent ),
00030     mOnline( false )
00031 {
00032 }
00033 
00034 void ResourceScheduler::scheduleFullSync()
00035 {
00036   Task t;
00037   t.type = SyncAll;
00038   mTaskList << t;
00039   scheduleNext();
00040 }
00041 
00042 void ResourceScheduler::scheduleCollectionTreeSync()
00043 {
00044   Task t;
00045   t.type = SyncCollectionTree;
00046   mTaskList << t;
00047   scheduleNext();
00048 }
00049 
00050 void ResourceScheduler::scheduleSync(const Collection & col)
00051 {
00052   Task t;
00053   t.type = SyncCollection;
00054   t.collection = col;
00055   mTaskList << t;
00056   scheduleNext();
00057 }
00058 
00059 void ResourceScheduler::scheduleItemFetch(const Item & item, const QSet<QByteArray> &parts, const QDBusMessage & msg)
00060 {
00061   Task t;
00062   t.type = FetchItem;
00063   t.item = item;
00064   t.itemParts = parts;
00065   t.dbusMsg = msg;
00066   mTaskList << t;
00067   scheduleNext();
00068 }
00069 
00070 void ResourceScheduler::scheduleChangeReplay()
00071 {
00072   Task t;
00073   t.type = ChangeReplay;
00074   if ( mTaskList.contains( t ) )
00075     return;
00076   mTaskList << t;
00077   scheduleNext();
00078 }
00079 
00080 void ResourceScheduler::taskDone()
00081 {
00082   mCurrentTask = Task();
00083   scheduleNext();
00084 }
00085 
00086 bool ResourceScheduler::isEmpty()
00087 {
00088   return mTaskList.isEmpty();
00089 }
00090 
00091 void ResourceScheduler::scheduleNext()
00092 {
00093   if ( mCurrentTask.type != Invalid || mTaskList.isEmpty() || !mOnline )
00094     return;
00095   QTimer::singleShot( 0, this, SLOT(executeNext()) );
00096 }
00097 
00098 void ResourceScheduler::executeNext()
00099 {
00100   mCurrentTask = mTaskList.takeFirst();
00101   switch ( mCurrentTask.type ) {
00102     case SyncAll:
00103       emit executeFullSync();
00104       break;
00105     case SyncCollectionTree:
00106       emit executeCollectionTreeSync();
00107       break;
00108     case SyncCollection:
00109       emit executeCollectionSync( mCurrentTask.collection );
00110       break;
00111     case FetchItem:
00112       emit executeItemFetch( mCurrentTask.item, mCurrentTask.itemParts );
00113       break;
00114     case ChangeReplay:
00115       emit executeChangeReplay();
00116       break;
00117     default:
00118       Q_ASSERT( false );
00119   }
00120 }
00121 
00122 ResourceScheduler::Task ResourceScheduler::currentTask() const
00123 {
00124   return mCurrentTask;
00125 }
00126 
00127 void ResourceScheduler::setOnline(bool state)
00128 {
00129   if ( mOnline == state )
00130     return;
00131   mOnline = state;
00132   if ( mOnline ) {
00133     scheduleNext();
00134   } else if ( mCurrentTask.type != Invalid ) {
00135     // abort running task
00136     mTaskList.prepend( mCurrentTask );
00137     mCurrentTask = Task();
00138   }
00139 }
00140 
00141 #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
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
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