kpilot
actionQueue.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "options.h"
00031
00032 #include <QtCore/QTimer>
00033
00034 #include "actions.h"
00035 #include "plugin.h"
00036
00037 #include "actionQueue.moc"
00038
00039 ActionQueue::ActionQueue(KPilotLink *d) :
00040 SyncAction(d, "ActionQueue")
00041
00042 {
00043 FUNCTIONSETUP;
00044 }
00045
00046 ActionQueue::~ActionQueue()
00047 {
00048 FUNCTIONSETUP;
00049 clear();
00050 }
00051
00052 void ActionQueue::clear()
00053 {
00054 SyncAction *del = 0L;
00055 while ( (del = nextAction()) )
00056 {
00057 delete del;
00058 }
00059
00060 Q_ASSERT(isEmpty());
00061 }
00062
00063 void ActionQueue::queueInit()
00064 {
00065 FUNCTIONSETUP;
00066
00067 addAction(new WelcomeAction(fHandle));
00068 }
00069
00070 void ActionQueue::queueConduits(const QStringList &l,
00071 const SyncAction::SyncMode &m)
00072 {
00073 FUNCTIONSETUP;
00074
00075
00076
00077
00078 for (QStringList::ConstIterator it = l.begin();
00079 it != l.end();
00080 ++it)
00081 {
00082 if ((*it).startsWith(CSL1("internal_")))
00083 {
00084 DEBUGKPILOT << ": Ignoring conduit " << *it;
00085 continue;
00086 }
00087
00088 DEBUGKPILOT << ": Creating proxy with mode=" << m.name();
00089 ConduitProxy *cp = new ConduitProxy(fHandle,*it,m);
00090 addAction(cp);
00091 }
00092 }
00093
00094 void ActionQueue::queueCleanup()
00095 {
00096 addAction(new CleanupAction(fHandle));
00097 }
00098
00099 bool ActionQueue::exec()
00100 {
00101 actionCompleted(0L);
00102 return true;
00103 }
00104
00105 void ActionQueue::actionCompleted(SyncAction *b)
00106 {
00107 FUNCTIONSETUP;
00108
00109 if (b)
00110 {
00111 DEBUGKPILOT << ": Completed action " << b->objectName();
00112 b->deleteLater();
00113 }
00114
00115 if (isEmpty())
00116 {
00117 delayDone();
00118 return;
00119 }
00120 if ( deviceLink() && (!deviceLink()->tickle()) )
00121 {
00122 emit logError(i18n("The connection to the handheld "
00123 "was lost. Synchronization cannot continue."));
00124 clear();
00125 delayDone();
00126 return;
00127 }
00128
00129 SyncAction *a = nextAction();
00130
00131 if (!a)
00132 {
00133 WARNINGKPILOT << "NULL action on stack.";
00134 return;
00135 }
00136
00137 DEBUGKPILOT << ": Will run action " << a->objectName();
00138
00139 QObject::connect(a, SIGNAL(logMessage(const QString &)),
00140 this, SIGNAL(logMessage(const QString &)));
00141 QObject::connect(a, SIGNAL(logError(const QString &)),
00142 this, SIGNAL(logMessage(const QString &)));
00143 QObject::connect(a, SIGNAL(logProgress(const QString &, int)),
00144 this, SIGNAL(logProgress(const QString &, int)));
00145 QObject::connect(a, SIGNAL(syncDone(SyncAction *)),
00146 this, SLOT(actionCompleted(SyncAction *)));
00147
00148
00149
00150 QTimer::singleShot(0,a,SLOT(execConduit()));
00151 }
00152