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 static const char *kpilot_id =
00031 "$Id: kpilot.cc,v 1.114 2003/12/04 21:11:24 adridg Exp $";
00032
00033
00034 #include "options.h"
00035
00036 #include <qfile.h>
00037 #include <qptrlist.h>
00038 #include <qstring.h>
00039 #include <qvbox.h>
00040 #include <qtimer.h>
00041
00042 #include <kjanuswidget.h>
00043 #include <kurl.h>
00044 #include <kmessagebox.h>
00045 #include <kstatusbar.h>
00046 #include <kconfig.h>
00047 #include <kwin.h>
00048 #include <kcombobox.h>
00049 #include <kmenubar.h>
00050 #include <kstddirs.h>
00051 #include <kaboutdata.h>
00052 #include <kcmdlineargs.h>
00053 #include <kiconloader.h>
00054 #include <kdebug.h>
00055 #include <kaction.h>
00056 #include <kstdaction.h>
00057 #include <kuniqueapp.h>
00058 #include <kkeydialog.h>
00059 #include <kedittoolbar.h>
00060
00061 #include <kprogress.h>
00062
00063
00064 #include "kpilotConfigDialog.h"
00065 #include "kpilotConfig.h"
00066
00067 #include "pilotComponent.h"
00068
00069 #include "addressWidget.h"
00070 #include "memoWidget.h"
00071 #include "fileInstallWidget.h"
00072 #include "logWidget.h"
00073 #include "dbviewerWidget.h"
00074 #include "datebookWidget.h"
00075 #include "todoWidget.h"
00076
00077 #include "conduitConfigDialog.h"
00078
00079 #ifndef _KPILOT_PILOTDAEMON_H
00080 #include "pilotDaemonDCOP.h"
00081 #endif
00082
00083 #ifndef __PILOTDAEMONDCOP_STUB__
00084 #include "pilotDaemonDCOP_stub.h"
00085 #endif
00086
00087 #include "kpilot.moc"
00088
00089 class KPilotInstaller::KPilotPrivate
00090 {
00091 public:
00092 typedef QPtrList<PilotComponent> ComponentList;
00093
00094 private:
00095 ComponentList fPilotComponentList;
00096
00097 public:
00098 ComponentList &list() { return fPilotComponentList; } ;
00099 } ;
00100
00101 KPilotInstaller::KPilotInstaller() :
00102 DCOPObject("KPilotIface"),
00103 KMainWindow(0),
00104 fDaemonStub(new PilotDaemonDCOP_stub("kpilotDaemon",
00105 "KPilotDaemonIface")),
00106 fP(new KPilotPrivate),
00107 fQuitAfterCopyComplete(false),
00108 fManagingWidget(0L),
00109 fKillDaemonOnExit(false),
00110 fDaemonWasRunning(true),
00111 fStatus(Startup),
00112 fFileInstallWidget(0L),
00113 fLogWidget(0L)
00114 {
00115 FUNCTIONSETUP;
00116
00117 readConfig();
00118 setupWidget();
00119
00120 #ifdef DEBUG
00121 PilotRecord::allocationInfo();
00122 #endif
00123 fConfigureKPilotDialogInUse = false;
00124 fConfigureConduitDialogInUse = false;
00125
00126
00127 (void) kpilot_id;
00128 }
00129
00130 KPilotInstaller::~KPilotInstaller()
00131 {
00132 FUNCTIONSETUP;
00133 killDaemonIfNeeded();
00134 delete fDaemonStub;
00135 #ifdef DEBUG
00136 PilotRecord::allocationInfo();
00137 #endif
00138 }
00139
00140 void KPilotInstaller::killDaemonIfNeeded()
00141 {
00142 FUNCTIONSETUP;
00143 if (fKillDaemonOnExit)
00144 {
00145 if (!fDaemonWasRunning)
00146 {
00147 #ifdef DEBUG
00148 DEBUGKPILOT << fname << ": Killing daemon." << endl;
00149 #endif
00150
00151 getDaemon().quitNow();
00152 }
00153 }
00154 }
00155
00156 void KPilotInstaller::startDaemonIfNeeded()
00157 {
00158 FUNCTIONSETUP;
00159
00160 fStatus=WaitingForDaemon;
00161
00162 QString daemonError;
00163 QCString daemonDCOP;
00164 int daemonPID;
00165
00166 QString s = getDaemon().statusString();
00167
00168 #ifdef DEBUG
00169 DEBUGKPILOT << fname << ": Daemon status is " << s.latin1() << endl;
00170 #endif
00171
00172 if ((s.isEmpty()) || (!getDaemon().ok()))
00173 {
00174 #ifdef DEBUG
00175 DEBUGKPILOT << fname
00176 << ": Daemon not responding, trying to start it."
00177 << endl;
00178 #endif
00179 fLogWidget->addMessage(i18n("Starting the KPilot daemon ..."));
00180 fDaemonWasRunning = false;
00181 }
00182 else
00183 {
00184 fDaemonWasRunning = true;
00185 }
00186
00187 if (!fDaemonWasRunning && KApplication::startServiceByDesktopName(
00188 CSL1("kpilotdaemon"),
00189 QString::null, &daemonError, &daemonDCOP, &daemonPID
00190 #if (KDE_VERSION >= 220)
00191
00192 , "0"
00193 #endif
00194 ))
00195 {
00196 kdError() << k_funcinfo
00197 << ": Can't start daemon : " << daemonError << endl;
00198 if (fLogWidget)
00199 {
00200 fLogWidget->addMessage(i18n("Could not start the "
00201 "KPilot daemon. The system error message "
00202 "was: "%1"").arg(daemonError));
00203 }
00204 fStatus=Error;
00205 }
00206 else
00207 {
00208 #ifdef DEBUG
00209 s = getDaemon().statusString();
00210 DEBUGKPILOT << fname << ": Daemon status is " << s << endl;
00211 #endif
00212 if (fLogWidget)
00213 {
00214 int wordoffset;
00215 s.remove(0,12);
00216 wordoffset=s.find(' ');
00217 if (wordoffset>0) s.remove(wordoffset,60);
00218
00219 fLogWidget->addMessage(
00220 i18n("Daemon status is `%1'")
00221 .arg(s));
00222 }
00223 fStatus=Normal;
00224 }
00225 }
00226
00227 void KPilotInstaller::readConfig()
00228 {
00229 FUNCTIONSETUP;
00230
00231 KPilotConfigSettings & c = KPilotConfig::getConfig();
00232 fKillDaemonOnExit = c.getKillDaemonOnExit();
00233
00234 (void) PilotAppCategory::setupPilotCodec(c.getEncoding());
00235 if (fLogWidget)
00236 {
00237 fLogWidget->addMessage(i18n("Using character set %1 on "
00238 "the handheld.")
00239 .arg(PilotAppCategory::codecName()));
00240 }
00241 }
00242
00243
00244 void KPilotInstaller::setupWidget()
00245 {
00246 FUNCTIONSETUP;
00247
00248 #ifdef DEBUG
00249 DEBUGKPILOT << fname << ": Creating central widget." << endl;
00250 #endif
00251
00252 setCaption(CSL1("KPilot"));
00253 setMinimumSize(500, 405);
00254
00255
00256 fManagingWidget = new KJanusWidget(this,"mainWidget",
00257 KJanusWidget::IconList);
00258 fManagingWidget->setMinimumSize(500, 330);
00259 fManagingWidget->show();
00260 setCentralWidget(fManagingWidget);
00261 connect( fManagingWidget, SIGNAL( aboutToShowPage ( QWidget* ) ),
00262 this, SLOT( slotAboutToShowComponent( QWidget* ) ) );
00263
00264 initIcons();
00265 initMenu();
00266 initComponents();
00267
00268 createGUI(CSL1("kpilotui.rc"), false);
00269 #ifdef DEBUG
00270 DEBUGKPILOT << fname
00271 << ": Got XML from "
00272 << xmlFile() << " and " << localXMLFile() << endl;
00273 #endif
00274 setAutoSaveSettings();
00275 }
00276
00277
00278 void KPilotInstaller::initComponents()
00279 {
00280 FUNCTIONSETUP;
00281
00282 QString defaultDBPath = KPilotConfig::getDefaultDBPath();
00283
00284 #ifdef DEBUG
00285 DEBUGKPILOT << fname << ": Creating component pages." << endl;
00286 #endif
00287
00288 QString pixfile;
00289 QWidget *w;
00290
00291 #define VIEWICON(a) KGlobal::dirs()->findResource("data",(a))
00292
00293 #define ADDICONPAGE(a,b) pixfile = VIEWICON(b); \
00294 w = getManagingWidget()->addVBoxPage(a,QString::null, \
00295 (pixfile.isEmpty() ? QPixmap() : QPixmap(pixfile))) ;
00296
00297 ADDICONPAGE(i18n("HotSync"),CSL1("kpilot/kpilot-hotsync.png"));
00298 fLogWidget = new LogWidget(w);
00299 addComponentPage(fLogWidget, i18n("HotSync"));
00300 fLogWidget->setShowTime(true);
00301
00302
00303
00304
00305
00306
00307 ADDICONPAGE(i18n("Todo Viewer"),CSL1("kpilot/kpilot-todo.png"));
00308 addComponentPage(new TodoWidget(w,defaultDBPath),
00309 i18n("Todo Viewer"));
00310
00311 ADDICONPAGE(i18n("Address Viewer"),CSL1("kpilot/kpilot-address.png"));
00312 addComponentPage(new AddressWidget(w,defaultDBPath),
00313 i18n("Address Viewer"));
00314
00315 ADDICONPAGE(i18n("Memo Viewer"),CSL1("kpilot/kpilot-knotes.png"));
00316 addComponentPage(new MemoWidget(w, defaultDBPath),
00317 i18n("Memo Viewer"));
00318
00319 ADDICONPAGE(i18n("Generic DB Viewer"),CSL1("kpilot/kpilot-db.png"));
00320 addComponentPage(new GenericDBWidget(w,defaultDBPath),
00321 i18n("Generic DB Viewer"));
00322
00323 ADDICONPAGE(i18n("File Installer"),CSL1("kpilot/kpilot-fileinstaller.png"));
00324 fFileInstallWidget = new FileInstallWidget(
00325 w,defaultDBPath);
00326 addComponentPage(fFileInstallWidget, i18n("File Installer"));
00327
00328 #undef ADDICONPAGE
00329 #undef VIEWICON
00330
00331 QTimer::singleShot(500,this,SLOT(initializeComponents()));
00332 }
00333
00334
00335
00336 void KPilotInstaller::initIcons()
00337 {
00338 FUNCTIONSETUP;
00339
00340 }
00341
00342
00343
00344 void KPilotInstaller::slotAboutToShowComponent( QWidget *c )
00345 {
00346 FUNCTIONSETUP;
00347 int ix = fManagingWidget->pageIndex( c );
00348 PilotComponent*compToShow = fP->list().at(ix);
00349 DEBUGKPILOT<<"Index: "<<ix<<", Widget="<<c<<", ComToShow="<<compToShow<<endl;
00350 for ( PilotComponent *comp = fP->list().first(); comp; comp = fP->list().next() )
00351 {
00352 DEBUGKPILOT<<"comp="<<comp<<endl;
00353
00354 comp->showKPilotComponent( comp == compToShow );
00355 }
00356 }
00357
00358 void KPilotInstaller::slotSelectComponent(PilotComponent * c)
00359 {
00360 FUNCTIONSETUP;
00361 if (!c)
00362 {
00363 kdWarning() << k_funcinfo << ": Not a widget." << endl;
00364 return;
00365 }
00366
00367 QObject *o = c->parent();
00368 if (!o)
00369 {
00370 kdWarning() << k_funcinfo << ": No parent." << endl;
00371 return;
00372 }
00373
00374 QWidget *parent = dynamic_cast<QWidget *>(o);
00375 if (!parent)
00376 {
00377 kdWarning() << k_funcinfo << ": No widget parent." << endl;
00378 return;
00379 }
00380
00381 int index = fManagingWidget->pageIndex(parent);
00382
00383 if (index < 0)
00384 {
00385 kdWarning() << k_funcinfo << ": Index " << index << endl;
00386 return;
00387 }
00388
00389 for ( PilotComponent *comp = fP->list().first(); comp; comp = fP->list().next() )
00390 {
00391
00392 comp->showKPilotComponent( comp == c );
00393 }
00394 fManagingWidget->showPage(index);
00395 }
00396
00397
00398
00399
00400 void KPilotInstaller::slotBackupRequested()
00401 {
00402 FUNCTIONSETUP;
00403 setupSync(PilotDaemonDCOP::Backup,
00404 i18n("Backing up Pilot. ") +
00405 i18n("Please press the HotSync button."));
00406 }
00407
00408 void KPilotInstaller::slotRestoreRequested()
00409 {
00410 FUNCTIONSETUP;
00411 setupSync(PilotDaemonDCOP::Restore,
00412 i18n("Restoring Pilot. ") +
00413 i18n("Please press the HotSync button."));
00414 }
00415
00416 void KPilotInstaller::slotHotSyncRequested()
00417 {
00418 FUNCTIONSETUP;
00419 setupSync(PilotDaemonDCOP::HotSync,
00420 i18n("HotSyncing. ") +
00421 i18n("Please press the HotSync button."));
00422 }
00423
00424 #if 0
00425 void KPilotInstaller::slotFastSyncRequested()
00426 {
00427 FUNCTIONSETUP;
00428 setupSync(PilotDaemonDCOP::FastSync,
00429 i18n("FastSyncing. ") +
00430 i18n("Please press the HotSync button."));
00431 }
00432 #endif
00433
00434 void KPilotInstaller::slotListSyncRequested()
00435 {
00436 FUNCTIONSETUP;
00437 setupSync(PilotDaemonDCOP::Test,
00438 QString::fromLatin1("Listing Pilot databases."));
00439 }
00440
00441 ASYNC KPilotInstaller::daemonStatus(int i)
00442 {
00443 FUNCTIONSETUP;
00444 #ifdef DEBUG
00445 DEBUGKPILOT << fname << ": Received daemon message " << i << endl;
00446 #endif
00447
00448 switch(i)
00449 {
00450 case KPilotDCOP::StartOfHotSync :
00451 if (fStatus==Normal)
00452 {
00453 fStatus=WaitingForDaemon;
00454 componentPreSync();
00455 }
00456 break;
00457 case KPilotDCOP::EndOfHotSync :
00458 if (fStatus==WaitingForDaemon)
00459 {
00460 componentPostSync();
00461 fStatus=Normal;
00462 }
00463 break;
00464 default :
00465 kdWarning() << k_funcinfo << ": Unhandled status message " << i << endl;
00466 break;
00467 }
00468 }
00469
00470 int KPilotInstaller::kpilotStatus()
00471 {
00472 return status();
00473 }
00474
00475 ASYNC KPilotInstaller::configure()
00476 {
00477 FUNCTIONSETUP;
00478 #ifdef DEBUG
00479 DEBUGKPILOT << fname << ": Daemon requested configure" << endl;
00480 #endif
00481
00482 if (!fConfigureKPilotDialogInUse)
00483 slotConfigureKPilot();
00484 }
00485
00486 ASYNC KPilotInstaller::configureConduits()
00487 {
00488 FUNCTIONSETUP;
00489 #ifdef DEBUG
00490 DEBUGKPILOT << fname << ": Daemon requested configure conduits" << endl;
00491 #endif
00492
00493 if (!fConfigureConduitDialogInUse)
00494 slotConfigureConduits();
00495 }
00496
00497 bool KPilotInstaller::componentPreSync()
00498 {
00499 FUNCTIONSETUP;
00500
00501 QString reason;
00502 QString rprefix(i18n("Can't start a Sync now. %1"));
00503
00504 for (fP->list().first();
00505 fP->list().current(); fP->list().next())
00506 {
00507 #ifdef DEBUG
00508 DEBUGKPILOT << fname
00509 << ": Pre-sync for builtin "
00510 << fP->list().current()->name() << endl;
00511 #endif
00512 if (!fP->list().current()->preHotSync(reason))
00513 break;
00514 }
00515
00516 if (!reason.isNull())
00517 {
00518 KMessageBox::sorry(this,
00519 rprefix.arg(reason),
00520 i18n("Can't start Sync"));
00521 return false;
00522 }
00523 return true;
00524 }
00525
00526 void KPilotInstaller::componentPostSync()
00527 {
00528 FUNCTIONSETUP;
00529
00530 for (fP->list().first();
00531 fP->list().current(); fP->list().next())
00532 {
00533 #ifdef DEBUG
00534 DEBUGKPILOT << fname
00535 << ": Post-sync for builtin "
00536 << fP->list().current()->name() << endl;
00537 #endif
00538 fP->list().current()->postHotSync();
00539 }
00540 }
00541
00542 void KPilotInstaller::setupSync(int kind, const QString & message)
00543 {
00544 FUNCTIONSETUP;
00545
00546 if (!componentPreSync())
00547 {
00548 return;
00549 }
00550 if (!message.isEmpty())
00551 {
00552 QString m(message);
00553 if (fLogWidget)
00554 {
00555 fLogWidget->logMessage(m);
00556 }
00557 }
00558 getDaemon().requestSync(kind);
00559 }
00560
00561
00562 void KPilotInstaller::closeEvent(QCloseEvent * e)
00563 {
00564 FUNCTIONSETUP;
00565
00566 quit();
00567 e->accept();
00568 }
00569
00570 void KPilotInstaller::initMenu()
00571 {
00572 FUNCTIONSETUP;
00573
00574
00575 (void )new KAction(i18n("&HotSync"), CSL1("hotsync"), 0,
00576 this, SLOT(slotHotSyncRequested()),
00577 actionCollection(), "file_hotsync");
00578 #if 0
00579 (void) new KAction(i18n("&FastSync"), CSL1("fastsync"), 0,
00580 this, SLOT(slotHotSyncRequested()),
00581 actionCollection(), "file_fastsync");
00582 #endif
00583 #ifdef DEBUG
00584 (void) new KAction(TODO_I18N("List only"),CSL1("list"),0,
00585 this,SLOT(slotListSyncRequested()),
00586 actionCollection(), "file_list");
00587 #endif
00588 (void) new KAction(i18n("&Backup"), CSL1("backup"), 0,
00589 this, SLOT(slotBackupRequested()),
00590 actionCollection(), "file_backup");
00591 (void) new KAction(i18n("&Restore"), CSL1("restore"), 0,
00592 this, SLOT(slotRestoreRequested()),
00593 actionCollection(), "file_restore");
00594 (void) KStdAction::quit(this, SLOT(quit()), actionCollection());
00595
00596
00597
00598
00599 #if KDE_VERSION >= 0x30180
00600 createStandardStatusBarAction();
00601 #endif
00602
00603 #if KDE_VERSION >= 0x30080
00604 setStandardToolBarMenuEnabled(true);
00605 #else
00606 m_toolbarAction =
00607 KStdAction::showToolbar(this, SLOT(optionsShowToolbar()),
00608 actionCollection());
00609 #endif
00610
00611 (void) KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()),
00612 actionCollection());
00613 (void) KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()),
00614 actionCollection());
00615 (void) KStdAction::preferences(this, SLOT(slotConfigureKPilot()),
00616 actionCollection());
00617 (void) new KAction(i18n("C&onfigure Conduits..."), CSL1("configure"), 0, this,
00618 SLOT(slotConfigureConduits()), actionCollection(),
00619 "options_configure_conduits");
00620 }
00621
00622 void KPilotInstaller::fileInstalled(int)
00623 {
00624 FUNCTIONSETUP;
00625 }
00626
00627 void KPilotInstaller::quit()
00628 {
00629 FUNCTIONSETUP;
00630
00631 for (fP->list().first();
00632 fP->list().current(); fP->list().next())
00633 {
00634 QString reason;
00635 if (!fP->list().current()->preHotSync(reason))
00636 {
00637 kdWarning() << k_funcinfo
00638 << ": Couldn't save "
00639 << fP->list().current()->name()
00640 << endl;
00641 }
00642 }
00643
00644 killDaemonIfNeeded();
00645 kapp->quit();
00646 }
00647
00648 void KPilotInstaller::addComponentPage(PilotComponent * p,
00649 const QString & name)
00650 {
00651 FUNCTIONSETUP;
00652
00653 if (!p)
00654 {
00655 kdWarning() << k_funcinfo
00656 << ": Adding NULL component?" << endl;
00657 return;
00658 }
00659
00660 #ifdef DEBUG
00661 DEBUGKPILOT << fname
00662 << ": Adding component @"
00663 << (int) p << " called " << p->name("(none)") << endl;
00664 #endif
00665
00666 fP->list().append(p);
00667
00668
00669
00670
00671
00672
00673
00674 const char *componentname = p->name("(none)");
00675 char *actionname = 0L;
00676
00677 if (strncmp(componentname, "component_", 10) == 0)
00678 {
00679 actionname = new char[strlen(componentname) - 10 + 8];
00680
00681 strcpy(actionname, "view_");
00682 strcat(actionname, componentname + 10);
00683 }
00684 else
00685 {
00686 actionname = new char[8 + strlen(componentname)];
00687
00688 strcpy(actionname, "view_");
00689 strcat(actionname, componentname);
00690 }
00691
00692 #ifdef DEBUG
00693 DEBUGKPILOT << fname
00694 << ": Using component action name "
00695 << name << " for " << actionname << endl;
00696 #endif
00697
00698 KToggleAction *pt =
00699 new KToggleAction(name, 0,
00700 p, SLOT(slotShowComponent()),
00701 actionCollection(), actionname);
00702
00703 pt->setExclusiveGroup(CSL1("view_menu"));
00704
00705 connect(p, SIGNAL(showComponent(PilotComponent *)),
00706 this, SLOT(slotSelectComponent(PilotComponent *)));
00707 }
00708
00709 void KPilotInstaller::initializeComponents()
00710 {
00711 FUNCTIONSETUP;
00712
00713
00714
00715
00716
00717
00718 }
00719
00720 #if KDE_VERSION >= 0x30080
00721
00722
00723 void KPilotInstaller::optionsShowToolbar()
00724 {
00725 }
00726 #else
00727 void KPilotInstaller::optionsShowToolbar()
00728 {
00729 FUNCTIONSETUP;
00730 if (m_toolbarAction->isChecked())
00731 {
00732 toolBar()->show();
00733 }
00734 else
00735 {
00736 toolBar()->hide();
00737 }
00738
00739 kapp->processEvents();
00740 resizeEvent(0);
00741 }
00742 #endif
00743
00744 void KPilotInstaller::optionsConfigureKeys()
00745 {
00746 FUNCTIONSETUP;
00747 KKeyDialog::configure( actionCollection() );
00748 }
00749
00750 void KPilotInstaller::optionsConfigureToolbars()
00751 {
00752 FUNCTIONSETUP;
00753
00754 #if KDE_VERSION >= 0x030100
00755
00756 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
00757 #endif
00758 KEditToolbar dlg(actionCollection());
00759 connect(&dlg, SIGNAL(newToolbarConfig()), this, SLOT(slotNewToolbarConfig()));
00760 dlg.exec();
00761 }
00762
00763
00764 void KPilotInstaller::slotNewToolbarConfig()
00765 {
00766 FUNCTIONSETUP;
00767
00768 createGUI();
00769 #if KDE_VERSION >= 0x030100
00770 applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
00771 #endif
00772 }
00773
00774 void KPilotInstaller::slotConfigureKPilot()
00775 {
00776 FUNCTIONSETUP;
00777
00778 if (fStatus!=Normal) return;
00779 fStatus=UIBusy;
00780 fConfigureKPilotDialogInUse = true;
00781
00782
00783
00784 int rememberedSync = getDaemon().nextSyncType();
00785 getDaemon().requestSync(0);
00786
00787 KPilotConfig::getConfig().reparseConfiguration();
00788 KPilotConfigDialog *options = new KPilotConfigDialog(this,
00789 "configDialog", true);
00790
00791 if (!options)
00792 {
00793 kdError() << k_funcinfo
00794 << ": Can't allocate KPilotOptions object" << endl;
00795 getDaemon().requestSync(rememberedSync);
00796 fConfigureKPilotDialogInUse = false;
00797 fStatus=Normal;
00798 return;
00799 }
00800
00801 options->exec();
00802
00803 if (options->result())
00804 {
00805 #ifdef DEBUG
00806 DEBUGKPILOT << fname << ": Updating link." << endl;
00807 #endif
00808
00809 KPilotConfig::getConfig().sync();
00810 readConfig();
00811
00812
00813
00814
00815 getDaemon().reloadSettings();
00816
00817
00818
00819
00820 for (fP->list().first();
00821 fP->list().current();
00822 fP->list().next())
00823 {
00824
00825
00826 }
00827 }
00828
00829 KPILOT_DELETE(options);
00830 getDaemon().requestSync(rememberedSync);
00831
00832 #ifdef DEBUG
00833 DEBUGKPILOT << fname << ": Done with options." << endl;
00834 #endif
00835 fConfigureKPilotDialogInUse = false;
00836 fStatus=Normal;
00837 }
00838
00839 void KPilotInstaller::slotConfigureConduits()
00840 {
00841 FUNCTIONSETUP;
00842
00843 if (fStatus!=Normal) return;
00844 fStatus=UIBusy;
00845 fConfigureConduitDialogInUse = true;
00846
00847 ConduitConfigDialog *conSetup = 0L;
00848
00849 conSetup = new ConduitConfigDialog(this,0L,true);
00850 int r = conSetup->exec();
00851 if (r)
00852 {
00853 KPilotConfig::getConfig().sync();
00854 getDaemon().reloadSettings();
00855 }
00856 delete conSetup;
00857
00858 fConfigureConduitDialogInUse = false;
00859 fStatus=Normal;
00860 }
00861
00862
00863 const char *KPilotInstaller::version(int kind)
00864 {
00865 FUNCTIONSETUP;
00866
00867
00868
00869 if (kind)
00870 {
00871 return ::kpilot_id;
00872 }
00873 else
00874 {
00875 return "KPilot v" KPILOT_VERSION;
00876 }
00877 }
00878
00879
00880
00881
00882
00883
00884 static KCmdLineOptions kpilotoptions[] = {
00885 {"s", 0, 0},
00886 {"setup",
00887 I18N_NOOP("Setup the Pilot device and other parameters"),
00888 0L},
00889 {"c", 0, 0},
00890 {"conduit-setup", I18N_NOOP("Run conduit setup"), 0L},
00891 #ifdef DEBUG
00892 {"debug <level>", I18N_NOOP("Set debugging level"), "0"},
00893 #endif
00894 KCmdLineLastOption
00895 };
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909 enum { Normal, ConfigureKPilot, ConfigureConduits, ConfigureAndContinue } run_mode = Normal;
00910
00911
00912 int main(int argc, char **argv)
00913 {
00914 FUNCTIONSETUP;
00915
00916 KAboutData about("kpilot", I18N_NOOP("KPilot"),
00917 KPILOT_VERSION,
00918 "KPilot - HotSync software for KDE\n\n",
00919 KAboutData::License_GPL, "(c) 1998-2000,2001, Dan Pilone");
00920 about.addAuthor("Dan Pilone",
00921 I18N_NOOP("Project Leader"),
00922 "pilone@slac.com", "http://www.slac.com/pilone/kpilot_home/");
00923 about.addAuthor("Adriaan de Groot",
00924 I18N_NOOP("Maintainer"),
00925 "groot@kde.org", "http://www.cs.kun.nl/~adridg/kpilot/");
00926 about.addAuthor("Reinhold Kainhofer",
00927 I18N_NOOP("Conduits developer"), "reinhold@kainhofer.com", "http://reinhold.kainhofer.com/Linux/");
00928 about.addCredit("Preston Brown", I18N_NOOP("VCal conduit"));
00929 about.addCredit("Greg Stern", I18N_NOOP("Abbrowser conduit"));
00930 about.addCredit("Chris Molnar", I18N_NOOP("Expenses conduit"));
00931 about.addCredit("Heiko Purnhagen", I18N_NOOP("Bugfixer"));
00932 about.addCredit("Joerg Habenicht", I18N_NOOP("Bugfixer"));
00933 about.addCredit("Martin Junius",
00934 I18N_NOOP("XML GUI"),
00935 "mj@m-j-s.net", "http://www.m-j-s.net/kde/");
00936 about.addCredit("David Bishop",
00937 I18N_NOOP(".ui files"));
00938 about.addCredit("Aaron J. Seigo",
00939 I18N_NOOP("Bugfixer, coolness"));
00940
00941
00942 KCmdLineArgs::init(argc, argv, &about);
00943 KCmdLineArgs::addCmdLineOptions(kpilotoptions, "kpilot");
00944 KUniqueApplication::addCmdLineOptions();
00945 KCmdLineArgs *p = KCmdLineArgs::parsedArgs();
00946
00947 #ifdef DEBUG
00948 KPilotConfig::getDebugLevel(p);
00949 #endif
00950
00951 if (p->isSet("setup"))
00952 {
00953 run_mode = ConfigureKPilot;
00954 }
00955 if (p->isSet("conduit-setup"))
00956 {
00957 run_mode = ConfigureConduits;
00958 }
00959
00960 if (!KUniqueApplication::start())
00961 {
00962 return 0;
00963 }
00964 KUniqueApplication a(true, true);
00965
00966 KPilotConfigSettings & c = KPilotConfig::getConfig();
00967 if (c.getVersion() < KPilotConfig::ConfigurationVersion)
00968 {
00969 kdWarning() << ": KPilot configuration version "
00970 << KPilotConfig::ConfigurationVersion
00971 << " newer than stored version "
00972 << c.getVersion() << endl;
00973
00974
00975
00976 if (Normal==run_mode) run_mode = ConfigureAndContinue;
00977 }
00978
00979 if (run_mode == ConfigureConduits)
00980 {
00981 ConduitConfigDialog *cs = new ConduitConfigDialog(0L,0L,true);
00982 int r = cs->exec();
00983
00984 if (r)
00985 {
00986 return 1;
00987 }
00988 else
00989 {
00990 return 0;
00991 }
00992 }
00993
00994 if ((run_mode == ConfigureKPilot) || (run_mode == ConfigureAndContinue))
00995 {
00996 #ifdef DEBUG
00997 DEBUGKPILOT << fname
00998 << ": Running setup first."
00999 << " (mode " << run_mode << ")" << endl;
01000 #endif
01001 bool outdated = false;
01002 if (c.getVersion() < KPilotConfig::ConfigurationVersion)
01003 {
01004 outdated = true;
01005 KPilotConfig::interactiveUpdate();
01006 }
01007 KPilotConfigDialog *options = new KPilotConfigDialog(0L,
01008 "configDialog", true);
01009 int r = options->exec();
01010
01011
01012 if (!r) return 1;
01013
01014 if (run_mode == ConfigureKPilot)
01015 {
01016 return 0;
01017 }
01018
01019
01020
01021
01022
01023 c.resetGroup();
01024 }
01025
01026 if (c.getVersion() < KPilotConfig::ConfigurationVersion)
01027 {
01028 kdWarning() << k_funcinfo <<
01029 ": Is still not configured for use." << endl;
01030 KPilotConfig::sorryVersionOutdated(c.getVersion());
01031 return 1;
01032 }
01033
01034
01035 KPilotInstaller *tp = new KPilotInstaller();
01036
01037 if (tp->status() == KPilotInstaller::Error)
01038 {
01039 delete tp;
01040
01041 tp = 0;
01042 return 1;
01043 }
01044
01045 tp->startDaemonIfNeeded();
01046
01047 KGlobal::dirs()->addResourceType("pilotdbs",
01048 CSL1("share/apps/kpilot/DBBackup"));
01049 tp->show();
01050 a.setMainWidget(tp);
01051 return a.exec();
01052 }
01053
01054