kpilot Library API Documentation

main-test.cc

00001 /* main-test.cc KPilot 00002 ** 00003 ** Copyright (C) 2001 by Dan Pilone 00004 ** 00005 ** This is the main program for kpilotTest, which shows a SyncLog and 00006 ** exercises the KPilotDeviceLink class. It's intended to test if the 00007 ** Palm hardware and the KPilot software are functioning correctly to 00008 ** some extent. 00009 */ 00010 00011 /* 00012 ** This program is free software; you can redistribute it and/or modify 00013 ** it under the terms of the GNU General Public License as published by 00014 ** the Free Software Foundation; either version 2 of the License, or 00015 ** (at your option) any later version. 00016 ** 00017 ** This program is distributed in the hope that it will be useful, 00018 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 ** GNU General Public License for more details. 00021 ** 00022 ** You should have received a copy of the GNU General Public License 00023 ** along with this program in a file called COPYING; if not, write to 00024 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00025 ** MA 02111-1307, USA. 00026 */ 00027 00028 /* 00029 ** Bug reports and questions can be sent to kde-pim@kde.org. 00030 */ 00031 static const char *test_id = 00032 "$Id: main-test.cc,v 1.32 2003/12/04 21:08:55 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 #include "syncStack.h" 00056 #include "hotSync.h" 00057 #include "interactiveSync.h" 00058 00059 static KCmdLineOptions kpilotoptions[] = { 00060 {"port <device>", 00061 I18N_NOOP("Path to Pilot device node"), 00062 "/dev/pilot"}, 00063 {"l",0,0}, 00064 {"list", I18N_NOOP("List DBs (default)"), 0}, 00065 {"b",0,0}, 00066 {"backup", I18N_NOOP("Backup instead of list DBs"), 0}, 00067 {"r",0,0}, 00068 {"restore", I18N_NOOP("Restore Pilot from backup"), 0}, 00069 {"L",0,0}, 00070 { "conduit-list", I18N_NOOP("List available conduits"), 0}, 00071 {"E",0,0}, 00072 { "conduit-exec <filename>", 00073 I18N_NOOP("Run conduit from desktop file <filename>"), 00074 0 }, 00075 { "T",0,0}, 00076 { "notest", 00077 I18N_NOOP("*Really* run the conduit, not in test mode."), 00078 0 } , 00079 { "F",0,0}, 00080 { "test-local", 00081 "Run the conduit in file-test mode.", 00082 0 } , 00083 #ifdef DEBUG 00084 {"debug <level>", I18N_NOOP("Set debugging level"), "0"}, 00085 #endif 00086 KCmdLineLastOption 00087 }; 00088 00089 00090 static LogWidget *logWidget = 0L; 00091 static QPushButton *resetButton = 0L; 00092 00093 void createLogWidget() 00094 { 00095 LogWidget *w = new LogWidget(0L); 00096 00097 w->resize(300, 300); 00098 w->show(); 00099 w->setShowTime(true); 00100 kapp->setMainWidget(w); 00101 logWidget = w; 00102 00103 resetButton = new QPushButton(i18n("Reset"),w->buttonBox()); 00104 } 00105 00106 static KPilotDeviceLink *deviceLink = 0L; 00107 00108 void createLink() 00109 { 00110 FUNCTIONSETUP; 00111 00112 deviceLink = KPilotDeviceLink::init(0, "deviceLink"); 00113 00114 QObject::connect(deviceLink, SIGNAL(logError(const QString &)), 00115 logWidget, SLOT(addError(const QString &))); 00116 QObject::connect(deviceLink, SIGNAL(logMessage(const QString &)), 00117 logWidget, SLOT(addMessage(const QString &))); 00118 QObject::connect(deviceLink,SIGNAL(logProgress(const QString &,int)), 00119 logWidget, SLOT(addProgress(const QString &,int))); 00120 00121 } 00122 00123 static ActionQueue *syncStack = 0L; 00124 00125 void connectStack() 00126 { 00127 FUNCTIONSETUP; 00128 00129 QObject::connect(syncStack, SIGNAL(logError(const QString &)), 00130 logWidget, SLOT(addError(const QString &))); 00131 QObject::connect(syncStack, SIGNAL(logMessage(const QString &)), 00132 logWidget, SLOT(addMessage(const QString &))); 00133 QObject::connect(syncStack,SIGNAL(logProgress(const QString &,int)), 00134 logWidget, SLOT(addProgress(const QString &,int))); 00135 00136 QObject::connect(deviceLink, SIGNAL(deviceReady()), syncStack, SLOT(execConduit())); 00137 00138 QObject::connect(syncStack, SIGNAL(syncDone(SyncAction *)), 00139 logWidget, SLOT(syncDone())); 00140 QObject::connect(syncStack, SIGNAL(syncDone(SyncAction *)), 00141 deviceLink, SLOT(close())); 00142 00143 QObject::connect(resetButton,SIGNAL(clicked()),deviceLink,SLOT(reset())); 00144 } 00145 00146 void createConnection(KCmdLineArgs *p) 00147 { 00148 FUNCTIONSETUP; 00149 00150 QString devicePath = p->getOption("port"); 00151 00152 if (devicePath.isEmpty()) 00153 { 00154 devicePath = "/dev/pilot"; 00155 } 00156 00157 KPilotDeviceLink::DeviceType deviceType = 00158 KPilotDeviceLink::OldStyleUSB; 00159 00160 deviceLink->reset(deviceType, devicePath); 00161 } 00162 00163 int syncTest(KCmdLineArgs *p) 00164 { 00165 FUNCTIONSETUP; 00166 00167 createLogWidget(); 00168 createLink(); 00169 00170 syncStack = new ActionQueue(deviceLink); 00171 00172 if (p->isSet("backup")) 00173 { 00174 syncStack->queueInit(); 00175 syncStack->addAction(new BackupAction(deviceLink)); 00176 } 00177 else if (p->isSet("restore")) 00178 { 00179 syncStack->queueInit(0); 00180 syncStack->addAction(new RestoreAction(deviceLink)); 00181 } 00182 else 00183 { 00184 syncStack->queueInit(); 00185 syncStack->addAction(new TestLink(deviceLink)); 00186 } 00187 syncStack->queueCleanup(); 00188 00189 connectStack(); 00190 createConnection(p); 00191 return kapp->exec(); 00192 } 00193 00194 int execConduit(KCmdLineArgs *p) 00195 { 00196 FUNCTIONSETUP; 00197 00198 // get --exec-conduit value 00199 QString s = p->getOption("conduit-exec"); 00200 if (s.isEmpty()) return 1; 00201 QStringList l; 00202 l.append(s); 00203 00204 createLogWidget(); 00205 createLink(); 00206 00207 syncStack = new ActionQueue(deviceLink); 00208 syncStack->queueInit(); 00209 syncStack->queueConduits(&KPilotConfig::getConfig(),l, 00210 p->isSet("test") ? (ActionQueue::HotSyncMode|ActionQueue::TestMode) : 00211 ActionQueue::HotSyncMode); 00212 syncStack->queueCleanup(); 00213 00214 connectStack(); 00215 createConnection(p); 00216 00217 return kapp->exec(); 00218 } 00219 00220 int testConduit(KCmdLineArgs *p) 00221 { 00222 FUNCTIONSETUP; 00223 00224 // get --exec-conduit value 00225 QString s = p->getOption("conduit-exec"); 00226 if (s.isEmpty()) return 1; 00227 00228 createLogWidget(); 00229 createLink(); 00230 00231 syncStack = new ActionQueue(deviceLink); 00232 syncStack->queueConduits(&KPilotConfig::getConfig(), 00233 QStringList(s), 00234 ActionQueue::FlagTest | ActionQueue::FlagLocal); 00235 00236 connectStack(); 00237 00238 QTimer::singleShot(10,syncStack,SLOT(execConduit())); 00239 00240 return kapp->exec(); 00241 } 00242 00243 00244 int listConduits(KCmdLineArgs *) 00245 { 00246 FUNCTIONSETUP; 00247 00248 KServiceTypeProfile::OfferList offers = 00249 KServiceTypeProfile::offers(CSL1("KPilotConduit")); 00250 00251 // Now actually fill the two list boxes, just make 00252 // sure that nothing gets listed in both. 00253 // 00254 // 00255 QValueListIterator < KServiceOffer > availList(offers.begin()); 00256 while (availList != offers.end()) 00257 { 00258 KSharedPtr < KService > o = (*availList).service(); 00259 00260 cout << o->desktopEntryName().latin1() << endl; 00261 cout << "\t" << o->name().latin1() << endl; 00262 if (!o->library().isEmpty()) 00263 { 00264 cout << "\tIn " 00265 << o->library().latin1() 00266 << endl; 00267 } 00268 00269 ++availList; 00270 } 00271 00272 return 0; 00273 } 00274 00275 int main(int argc, char **argv) 00276 { 00277 FUNCTIONSETUP; 00278 KAboutData about("kpilotTest", 00279 I18N_NOOP("KPilotTest"), 00280 KPILOT_VERSION, 00281 "KPilot Tester", 00282 KAboutData::License_GPL, "(C) 2001, Adriaan de Groot"); 00283 about.addAuthor("Adriaan de Groot", 00284 I18N_NOOP("KPilot Maintainer"), 00285 "groot@kde.org", "http://www.cs.kun.nl/~adridg/kpilot/"); 00286 00287 KCmdLineArgs::init(argc, argv, &about); 00288 KCmdLineArgs::addCmdLineOptions(kpilotoptions, "kpilottest"); 00289 KApplication::addCmdLineOptions(); 00290 00291 KCmdLineArgs *p = KCmdLineArgs::parsedArgs(); 00292 00293 00294 KApplication a; 00295 #ifdef DEBUG 00296 KPilotConfig::getDebugLevel(p); 00297 #endif 00298 00299 if (p->isSet("backup") || p->isSet("restore") || p->isSet("list")) 00300 { 00301 return syncTest(p); 00302 } 00303 00304 if (p->isSet("conduit-list")) 00305 { 00306 return listConduits(p); 00307 } 00308 00309 if (p->isSet("conduit-exec")) 00310 { 00311 if (p->isSet("test-local")) 00312 { 00313 return testConduit(p); 00314 } 00315 else 00316 { 00317 return execConduit(p); 00318 } 00319 } 00320 00321 // The default is supposed to be "list" 00322 return syncTest(p); 00323 /* NOTREACHED */ 00324 (void) test_id; 00325 } 00326 00327
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003