kpilot

actionQueue.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 **
00006 ** This defines the "ActionQueue", which is the pile of actions
00007 ** that will occur during a HotSync.
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU General Public License as published by
00013 ** the Free Software Foundation; either version 2 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 ** MA 02110-1301, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org
00029 */
00030 #include "options.h"
00031 
00032 #include <qtimer.h>
00033 
00034 #include "actions.h"
00035 #include "plugin.h"
00036 
00037 #include "actionQueue.moc"
00038 
00039 
00040 
00041 
00042 ActionQueue::ActionQueue(KPilotLink *d) :
00043     SyncAction(d,"ActionQueue")
00044     // The string lists have default constructors
00045 {
00046     FUNCTIONSETUP;
00047 }
00048 
00049 ActionQueue::~ActionQueue()
00050 {
00051     FUNCTIONSETUP;
00052     clear();
00053 }
00054 
00055 void ActionQueue::clear()
00056 {
00057     SyncAction *del = 0L;
00058     while ( (del = nextAction()) )
00059     {
00060         delete del;
00061     }
00062 
00063     Q_ASSERT(isEmpty());
00064 }
00065 
00066 void ActionQueue::queueInit()
00067 {
00068     FUNCTIONSETUP;
00069 
00070     addAction(new WelcomeAction(fHandle));
00071 }
00072 
00073 void ActionQueue::queueConduits(const QStringList &l,
00074     const SyncAction::SyncMode &m)
00075 {
00076     FUNCTIONSETUP;
00077 
00078     // Add conduits here ...
00079     //
00080     //
00081     for (QStringList::ConstIterator it = l.begin();
00082         it != l.end();
00083         ++it)
00084     {
00085         if ((*it).startsWith(CSL1("internal_")))
00086         {
00087 #ifdef DEBUG
00088             DEBUGKPILOT << fname <<
00089                 ": Ignoring conduit " << *it << endl;
00090 #endif
00091             continue;
00092         }
00093 
00094 #ifdef DEBUG
00095         DEBUGKPILOT << fname
00096             << ": Creating proxy with mode=" << m.name() << endl;
00097 #endif
00098         ConduitProxy *cp = new ConduitProxy(fHandle,*it,m);
00099         addAction(cp);
00100     }
00101 }
00102 
00103 void ActionQueue::queueCleanup()
00104 {
00105     addAction(new CleanupAction(fHandle));
00106 }
00107 
00108 bool ActionQueue::exec()
00109 {
00110     actionCompleted(0L);
00111     return true;
00112 }
00113 
00114 void ActionQueue::actionCompleted(SyncAction *b)
00115 {
00116     FUNCTIONSETUP;
00117 
00118     if (b)
00119     {
00120 #ifdef DEBUG
00121         DEBUGKPILOT << fname
00122             << ": Completed action "
00123             << b->name()
00124             << endl;
00125 #endif
00126         delete b;
00127     }
00128 
00129     if (isEmpty())
00130     {
00131         delayDone();
00132         return;
00133     }
00134     if ( deviceLink() && (!deviceLink()->tickle()) )
00135     {
00136         emit logError(i18n("The connection to the handheld "
00137             "was lost. Synchronization cannot continue."));
00138         clear();
00139         delayDone();
00140         return;
00141     }
00142 
00143     SyncAction *a = nextAction();
00144 
00145     if (!a)
00146     {
00147         WARNINGKPILOT << "NULL action on stack."
00148             << endl;
00149         return;
00150     }
00151 
00152 #ifdef DEBUG
00153     DEBUGKPILOT << fname
00154         << ": Will run action "
00155         << a->name()
00156         << endl;
00157 #endif
00158 
00159     QObject::connect(a, SIGNAL(logMessage(const QString &)),
00160         this, SIGNAL(logMessage(const QString &)));
00161     QObject::connect(a, SIGNAL(logError(const QString &)),
00162         this, SIGNAL(logMessage(const QString &)));
00163     QObject::connect(a, SIGNAL(logProgress(const QString &, int)),
00164         this, SIGNAL(logProgress(const QString &, int)));
00165     QObject::connect(a, SIGNAL(syncDone(SyncAction *)),
00166         this, SLOT(actionCompleted(SyncAction *)));
00167 
00168     // Run the action picked from the queue when we get back
00169     // to the event loop.
00170     QTimer::singleShot(0,a,SLOT(execConduit()));
00171 }
00172