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 #include "options.h"
00030
00031 static const char *syncStack_id = "$Id: syncStack.cc,v 1.9.4.8 2003/03/15 10:29:01 adridg Exp $";
00032
00033 #include <qtimer.h>
00034 #include <qfile.h>
00035
00036 #include <kservice.h>
00037 #include <kservicetype.h>
00038 #include <kuserprofile.h>
00039 #include <klibloader.h>
00040
00041 #include "hotSync.h"
00042 #include "interactiveSync.h"
00043 #include "fileInstaller.h"
00044
00045 #include "syncStack.moc"
00046
00047
00048
00049 WelcomeAction::WelcomeAction(KPilotDeviceLink *p) :
00050 SyncAction(p,"welcomeAction")
00051 {
00052 FUNCTIONSETUP;
00053
00054 (void) syncStack_id;
00055 }
00056
00057 bool WelcomeAction::exec()
00058 {
00059 FUNCTIONSETUP;
00060
00061 addSyncLogEntry(i18n("KPilot %1 HotSync starting...\n")
00062 .arg(QString::fromLatin1(KPILOT_VERSION)));
00063 emit syncDone(this);
00064 return true;
00065 }
00066
00067 ConduitProxy::ConduitProxy(KPilotDeviceLink *p,
00068 const QString &name,
00069 int m) :
00070 ConduitAction(p,name.latin1()),
00071 fDesktopName(name),
00072 fMode(m)
00073 {
00074 FUNCTIONSETUP;
00075 }
00076
00077 bool ConduitProxy::exec()
00078 {
00079 FUNCTIONSETUP;
00080
00081
00082 KSharedPtr < KService > o = KService::serviceByDesktopName(fDesktopName);
00083 if (!o)
00084 {
00085 kdWarning() << k_funcinfo
00086 << ": Can't find desktop file for conduit "
00087 << fDesktopName
00088 << endl;
00089 addSyncLogEntry(i18n("Couldn't find conduit %1.").arg(fDesktopName));
00090 emit syncDone(this);
00091 return true;
00092 }
00093
00094
00095
00096 #ifdef DEBUG
00097 DEBUGKPILOT << fname
00098 << ": Loading desktop "
00099 << fDesktopName
00100 << " with lib "
00101 << o->library()
00102 << endl;
00103 #endif
00104
00105 fLibraryName = o->library();
00106 KLibFactory *factory = KLibLoader::self()->factory(
00107 QFile::encodeName(o->library()));
00108 if (!factory)
00109 {
00110 kdWarning() << k_funcinfo
00111 << ": Can't load library "
00112 << o->library()
00113 << endl;
00114 addSyncLogEntry(i18n("Couldn't load conduit %1.").arg(fDesktopName));
00115 emit syncDone(this);
00116 return true;
00117 }
00118
00119 QStringList l;
00120 switch(fMode & ActionQueue::ActionMask)
00121 {
00122 case ActionQueue::Backup :
00123 l.append(CSL1("--backup"));
00124 break;
00125 default:
00126 ;
00127 }
00128 if (fMode & ActionQueue::FlagTest)
00129 {
00130 l.append(CSL1("--test"));
00131 }
00132 if (fMode & ActionQueue::FlagLocal)
00133 {
00134 l.append(CSL1("--local"));
00135 }
00136
00137
00138 QObject *object = factory->create(fHandle,name(),"SyncAction",l);
00139
00140 if (!object)
00141 {
00142 kdWarning() << k_funcinfo
00143 << ": Can't create SyncAction."
00144 << endl;
00145 addSyncLogEntry(i18n("Couldn't create conduit %1.").arg(fDesktopName));
00146 emit syncDone(this);
00147 return true;
00148 }
00149
00150 fConduit = dynamic_cast<ConduitAction *>(object);
00151
00152 if (!fConduit)
00153 {
00154 kdWarning() << k_funcinfo
00155 << ": Can't cast to ConduitAction."
00156 << endl;
00157 addSyncLogEntry(i18n("Couldn't create conduit %1.").arg(fDesktopName));
00158 emit syncDone(this);
00159 return true;
00160 }
00161 fConduit->setConfig(fConfig);
00162
00163 logMessage(i18n("[Conduit %1]").arg(fDesktopName));
00164
00165 QString conduitFlags = TODO_I18N("Running with flags: ");
00166 for (QStringList::ConstIterator i = l.begin() ; i!=l.end(); ++i)
00167 {
00168 conduitFlags.append(*i);
00169 conduitFlags.append(CSL1(" "));
00170 }
00171
00172 logMessage(conduitFlags);
00173
00174
00175 QObject::connect(fConduit,SIGNAL(syncDone(SyncAction *)),
00176 this,SLOT(execDone(SyncAction *)));
00177
00178 QObject::connect(fConduit,SIGNAL(logMessage(const QString &)),
00179 this,SIGNAL(logMessage(const QString &)));
00180 QObject::connect(fConduit,SIGNAL(logError(const QString &)),
00181 this,SIGNAL(logError(const QString &)));
00182 QObject::connect(fConduit,SIGNAL(logProgress(const QString &,int)),
00183 this,SIGNAL(logProgress(const QString &,int)));
00184
00185 QTimer::singleShot(0,fConduit,SLOT(execConduit()));
00186 return true;
00187 }
00188
00189 void ConduitProxy::execDone(SyncAction *p)
00190 {
00191 FUNCTIONSETUP;
00192
00193 if (p!=fConduit)
00194 {
00195 kdError() << k_funcinfo
00196 << ": Unknown conduit @"
00197 << (int) p
00198 << " finished."
00199 << endl;
00200 emit syncDone(this);
00201 return;
00202 }
00203
00204 delete p;
00205 emit syncDone(this);
00206 }
00207
00208 ActionQueue::ActionQueue(KPilotDeviceLink *d,
00209 KConfig *config,
00210 const QStringList &conduits,
00211 const QString &dir,
00212 const QStringList &files) :
00213 SyncAction(d,"ActionQueue"),
00214 fReady(false),
00215 fConfig(config),
00216 fInstallerDir(dir),
00217 fInstallerFiles(files),
00218 fConduits(conduits)
00219 {
00220 FUNCTIONSETUP;
00221
00222 #ifdef DEBUG
00223 if (!conduits.count())
00224 {
00225 DEBUGCONDUIT << fname << ": No conduits." << endl;
00226 }
00227 else
00228 {
00229 DEBUGCONDUIT << fname << ": Conduits : " << conduits.join(CSL1(" + ")) << endl;
00230 }
00231 #endif
00232
00233 kdWarning() << "SyncStack usage is deprecated." << endl;
00234 }
00235
00236 ActionQueue::ActionQueue(KPilotDeviceLink *d) :
00237 SyncAction(d,"ActionQueue"),
00238 fReady(false),
00239 fConfig(0L)
00240
00241 {
00242 FUNCTIONSETUP;
00243 }
00244
00245 ActionQueue::~ActionQueue()
00246 {
00247 FUNCTIONSETUP;
00248 }
00249
00250 void ActionQueue::prepare(int m)
00251 {
00252 FUNCTIONSETUP;
00253
00254 #ifdef DEBUG
00255 DEBUGDAEMON << fname
00256 << ": Using sync mode " << m
00257 << endl;
00258 #endif
00259
00260 switch ( m & (Test | Backup | Restore | HotSync))
00261 {
00262 case Test:
00263 case Backup:
00264 case Restore:
00265 case HotSync:
00266 fReady=true;
00267 break;
00268 default:
00269 kdWarning() << k_funcinfo
00270 << ": Strange sync mode " << m << " set. Aborting."
00271 << endl;
00272 return;
00273 }
00274
00275 queueInit(m);
00276 if (m & WithConduits)
00277 queueConduits(fConfig,fConduits,m);
00278
00279 switch ( m & (Test | Backup | Restore | HotSync))
00280 {
00281 case Test:
00282 addAction(new TestLink(fHandle));
00283 break;
00284 case Backup:
00285 addAction(new BackupAction(fHandle));
00286 break;
00287 case Restore:
00288 addAction(new RestoreAction(fHandle));
00289 break;
00290 case HotSync:
00291 break;
00292 default:
00293
00294 fReady=false;
00295 return;
00296 }
00297
00298 if (m & WithInstaller)
00299 queueInstaller(fInstallerDir,fInstallerFiles);
00300
00301 queueCleanup();
00302 }
00303
00304 void ActionQueue::queueInit(int m)
00305 {
00306 FUNCTIONSETUP;
00307
00308 addAction(new WelcomeAction(fHandle));
00309
00310 if (m & WithUserCheck)
00311 {
00312 addAction(new CheckUser(fHandle));
00313 }
00314 }
00315
00316 void ActionQueue::queueConduits(KConfig *config,const QStringList &l,int m)
00317 {
00318 FUNCTIONSETUP;
00319
00320
00321
00322
00323 for (QStringList::ConstIterator it = l.begin();
00324 it != l.end();
00325 ++it)
00326 {
00327 ConduitProxy *cp = new ConduitProxy(fHandle,*it,m);
00328 cp->setConfig(config);
00329 addAction(cp);
00330 }
00331 }
00332
00333 void ActionQueue::queueInstaller(const QString &dir, const QStringList &files)
00334 {
00335 addAction(new FileInstallAction(fHandle,dir,files));
00336 }
00337
00338 void ActionQueue::queueCleanup()
00339 {
00340 addAction(new CleanupAction(fHandle));
00341 }
00342
00343 bool ActionQueue::exec()
00344 {
00345 actionCompleted(0L);
00346 return true;
00347 }
00348
00349 void ActionQueue::actionCompleted(SyncAction *b)
00350 {
00351 FUNCTIONSETUP;
00352
00353 if (b)
00354 {
00355 #ifdef DEBUG
00356 DEBUGDAEMON << fname
00357 << ": Completed action "
00358 << b->name()
00359 << endl;
00360 #endif
00361 delete b;
00362 }
00363
00364 if (isEmpty())
00365 {
00366 emit syncDone(this);
00367 return;
00368 }
00369
00370 SyncAction *a = nextAction();
00371
00372 if (!a)
00373 {
00374 kdWarning() << k_funcinfo
00375 << ": NULL action on stack."
00376 << endl;
00377 return;
00378 }
00379
00380 #ifdef DEBUG
00381 DEBUGDAEMON << fname
00382 << ": Will run action "
00383 << a->name()
00384 << endl;
00385 #endif
00386
00387 QObject::connect(a, SIGNAL(logMessage(const QString &)),
00388 this, SIGNAL(logMessage(const QString &)));
00389 QObject::connect(a, SIGNAL(logError(const QString &)),
00390 this, SIGNAL(logMessage(const QString &)));
00391 QObject::connect(a, SIGNAL(logProgress(const QString &, int)),
00392 this, SIGNAL(logProgress(const QString &, int)));
00393 QObject::connect(a, SIGNAL(syncDone(SyncAction *)),
00394 this, SLOT(actionCompleted(SyncAction *)));
00395
00396 QTimer::singleShot(0,a,SLOT(execConduit()));
00397 }
00398