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
00031 static const char *test_id =
00032 "$Id: main-test.cc,v 1.21.4.7 2003/03/12 23:31:14 adridg Exp $";
00033
00034 #include "options.h"
00035
00036 #include <stdlib.h>
00037 #include <time.h>
00038
00039 #include <qpushbutton.h>
00040 #include <qhbox.h>
00041 #include <qtimer.h>
00042
00043 #include <kapplication.h>
00044 #include <klocale.h>
00045 #include <kaboutdata.h>
00046 #include <kcmdlineargs.h>
00047 #include <kservice.h>
00048 #include <kservicetype.h>
00049 #include <kuserprofile.h>
00050
00051 #include <pi-version.h>
00052
00053 #include "logWidget.h"
00054 #include "kpilotConfig.h"
00055
00056 #include "syncStack.h"
00057
00058 static KCmdLineOptions kpilotoptions[] = {
00059 {"port <device>",
00060 I18N_NOOP("Path to Pilot device node"),
00061 "/dev/pilot"},
00062 {"l",0,0},
00063 {"list", I18N_NOOP("List DBs (default)"), 0},
00064 {"b",0,0},
00065 {"backup", I18N_NOOP("Backup instead of list DBs"), 0},
00066 {"r",0,0},
00067 {"restore", I18N_NOOP("Restore Pilot from backup"), 0},
00068 {"L",0,0},
00069 { "conduit-list", I18N_NOOP("List available conduits"), 0},
00070 {"E",0,0},
00071 { "conduit-exec <filename>",
00072 I18N_NOOP("Run conduit from desktop file <filename>"),
00073 0 },
00074 { "T",0,0},
00075 { "notest",
00076 I18N_NOOP("*Really* run the conduit, not in test mode."),
00077 0 } ,
00078 { "F",0,0},
00079 { "test-local",
00080 "Run the conduit in file-test mode.",
00081 0 } ,
00082 {0, 0, 0}
00083 };
00084
00085
00086 static LogWidget *logWidget = 0L;
00087 static QPushButton *resetButton = 0L;
00088
00089 void createLogWidget()
00090 {
00091 LogWidget *w = new LogWidget(0L);
00092
00093 w->resize(300, 300);
00094 w->show();
00095 w->setShowTime(true);
00096 kapp->setMainWidget(w);
00097 logWidget = w;
00098
00099 resetButton = new QPushButton(i18n("Reset"),w->buttonBox());
00100 }
00101
00102 static KPilotDeviceLink *deviceLink = 0L;
00103
00104 void createLink()
00105 {
00106 FUNCTIONSETUP;
00107
00108 deviceLink = KPilotDeviceLink::init(0, "deviceLink");
00109
00110 QObject::connect(deviceLink, SIGNAL(logError(const QString &)),
00111 logWidget, SLOT(addError(const QString &)));
00112 QObject::connect(deviceLink, SIGNAL(logMessage(const QString &)),
00113 logWidget, SLOT(addMessage(const QString &)));
00114 QObject::connect(deviceLink,SIGNAL(logProgress(const QString &,int)),
00115 logWidget, SLOT(addProgress(const QString &,int)));
00116 }
00117
00118 static ActionQueue *syncStack = 0L;
00119
00120 void connectStack()
00121 {
00122 FUNCTIONSETUP;
00123
00124 QObject::connect(syncStack, SIGNAL(logError(const QString &)),
00125 logWidget, SLOT(addError(const QString &)));
00126 QObject::connect(syncStack, SIGNAL(logMessage(const QString &)),
00127 logWidget, SLOT(addMessage(const QString &)));
00128 QObject::connect(syncStack,SIGNAL(logProgress(const QString &,int)),
00129 logWidget, SLOT(addProgress(const QString &,int)));
00130
00131 QObject::connect(deviceLink, SIGNAL(deviceReady()), syncStack, SLOT(execConduit()));
00132
00133 QObject::connect(syncStack, SIGNAL(syncDone(SyncAction *)),
00134 logWidget, SLOT(syncDone()));
00135 QObject::connect(syncStack, SIGNAL(syncDone(SyncAction *)),
00136 deviceLink, SLOT(close()));
00137
00138 QObject::connect(resetButton,SIGNAL(clicked()),deviceLink,SLOT(reset()));
00139 }
00140
00141 void createConnection(KCmdLineArgs *p)
00142 {
00143 FUNCTIONSETUP;
00144
00145 QString devicePath = p->getOption("port");
00146
00147 if (devicePath.isEmpty())
00148 {
00149 devicePath = "/dev/pilot";
00150 }
00151
00152 KPilotDeviceLink::DeviceType deviceType =
00153 KPilotDeviceLink::OldStyleUSB;
00154
00155 deviceLink->reset(deviceType, devicePath);
00156 }
00157
00158 int syncTest(KCmdLineArgs *p)
00159 {
00160 FUNCTIONSETUP;
00161
00162 createLogWidget();
00163 createLink();
00164
00165 syncStack = new ActionQueue(deviceLink,&KPilotConfig::getConfig());
00166
00167 if (p->isSet("backup"))
00168 {
00169 syncStack->prepare(ActionQueue::Backup | ActionQueue::WithUserCheck);
00170 }
00171 else if (p->isSet("restore"))
00172 {
00173 syncStack->prepareRestore();
00174 }
00175 else
00176 {
00177 syncStack->prepare(ActionQueue::Test);
00178 }
00179
00180 connectStack();
00181 createConnection(p);
00182 return kapp->exec();
00183 }
00184
00185 int execConduit(KCmdLineArgs *p)
00186 {
00187 FUNCTIONSETUP;
00188
00189
00190 QString s = p->getOption("conduit-exec");
00191 if (s.isEmpty()) return 1;
00192 QStringList l;
00193 l.append(s);
00194
00195 createLogWidget();
00196 createLink();
00197
00198 syncStack = new ActionQueue(deviceLink,&KPilotConfig::getConfig(),l);
00199
00200 if (p->isSet("test"))
00201 {
00202 syncStack->prepare(ActionQueue::HotSyncMode|ActionQueue::TestMode);
00203 }
00204 else
00205 {
00206 syncStack->prepareSync();
00207 }
00208
00209 connectStack();
00210 createConnection(p);
00211
00212 return kapp->exec();
00213 }
00214
00215 int testConduit(KCmdLineArgs *p)
00216 {
00217 FUNCTIONSETUP;
00218
00219
00220 QString s = p->getOption("conduit-exec");
00221 if (s.isEmpty()) return 1;
00222
00223 createLogWidget();
00224 createLink();
00225
00226 syncStack = new ActionQueue(deviceLink);
00227 syncStack->queueConduits(&KPilotConfig::getConfig(),
00228 QStringList(s),
00229 ActionQueue::FlagTest | ActionQueue::FlagLocal);
00230
00231 connectStack();
00232
00233 QTimer::singleShot(10,syncStack,SLOT(execConduit()));
00234
00235 return kapp->exec();
00236 }
00237
00238
00239 int listConduits(KCmdLineArgs *)
00240 {
00241 FUNCTIONSETUP;
00242
00243 KServiceTypeProfile::OfferList offers =
00244 KServiceTypeProfile::offers(CSL1("KPilotConduit"));
00245
00246
00247
00248
00249
00250 QValueListIterator < KServiceOffer > availList(offers.begin());
00251 while (availList != offers.end())
00252 {
00253 KSharedPtr < KService > o = (*availList).service();
00254
00255 cout << o->desktopEntryName().latin1() << endl;
00256 cout << "\t" << o->name().latin1() << endl;
00257 if (!o->library().isEmpty())
00258 {
00259 cout << "\tIn "
00260 << o->library().latin1()
00261 << endl;
00262 }
00263
00264 ++availList;
00265 }
00266
00267 return 0;
00268 }
00269
00270 int main(int argc, char **argv)
00271 {
00272 FUNCTIONSETUP;
00273 KAboutData about("kpilotTest",
00274 I18N_NOOP("KPilotTest"),
00275 KPILOT_VERSION,
00276 "KPilot Tester",
00277 KAboutData::License_GPL, "(C) 2001, Adriaan de Groot");
00278 about.addAuthor("Adriaan de Groot",
00279 I18N_NOOP("KPilot Maintainer"),
00280 "groot@kde.org", "http://www.cs.kun.nl/~adridg/kpilot/");
00281
00282 KCmdLineArgs::init(argc, argv, &about);
00283 #ifdef DEBUG
00284 KCmdLineArgs::addCmdLineOptions(debug_options, "debug", "debug");
00285 #endif
00286 KCmdLineArgs::addCmdLineOptions(kpilotoptions, "kpilottest", 0L,
00287 "debug");
00288 KApplication::addCmdLineOptions();
00289
00290 KCmdLineArgs *p = KCmdLineArgs::parsedArgs();
00291
00292
00293 KApplication a;
00294 #ifdef DEBUG
00295 debug_level = -1;
00296 #endif
00297
00298 if (p->isSet("backup") || p->isSet("restore") || p->isSet("list"))
00299 {
00300 return syncTest(p);
00301 }
00302
00303 if (p->isSet("conduit-list"))
00304 {
00305 return listConduits(p);
00306 }
00307
00308 if (p->isSet("conduit-exec"))
00309 {
00310 if (p->isSet("test-local"))
00311 {
00312 return testConduit(p);
00313 }
00314 else
00315 {
00316 return execConduit(p);
00317 }
00318 }
00319
00320
00321 return syncTest(p);
00322
00323 (void) test_id;
00324 }
00325
00326