kpilot Library API Documentation

pilotDaemon.cc

00001 /* pilotDaemon.cc                       KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 **
00005 ** This is the KPilot Daemon, which does the actual communication with
00006 ** the Pilot and with the conduits.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00023 ** MA 02111-1307, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 static const char *pilotdaemon_id =
00030         "$Id: pilotDaemon.cc,v 1.66.4.7 2003/03/30 14:41:34 adridg Exp $";
00031 
00032 #ifndef _KPILOT_OPTIONS_H
00033 #include "options.h"
00034 #endif
00035 
00036 #include <time.h>
00037 
00038 #ifdef TIME_WITH_SYS_TIME
00039 #include <sys/time.h>
00040 #endif
00041 
00042 #include <sys/types.h>
00043 #include <sys/stat.h>
00044 #include <dirent.h>
00045 #include <fcntl.h>
00046 #include <unistd.h>
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <signal.h>
00050 #include <errno.h>
00051 
00052 #include <qdir.h>
00053 #include <qptrlist.h>
00054 #include <qcursor.h>
00055 #include <qdragobject.h>
00056 #include <qptrstack.h>
00057 #include <qtimer.h>
00058 #include <qtooltip.h>
00059 
00060 #include <kuniqueapplication.h>
00061 #include <kaboutdata.h>
00062 #include <kaboutapplication.h>
00063 #include <kcmdlineargs.h>
00064 #include <kwin.h>
00065 #include <ksimpleconfig.h>
00066 #include <kurl.h>
00067 #include <ksock.h>
00068 #include <kmessagebox.h>
00069 #include <kstandarddirs.h>
00070 #include <kpopupmenu.h>
00071 #include <kiconloader.h>
00072 #include <kio/netaccess.h>
00073 #include <kdebug.h>
00074 #include <ktempfile.h>
00075 #include <kprocess.h>
00076 #include <dcopclient.h>
00077 
00078 #include "pilotAppCategory.h"
00079 
00080 #include "fileInstaller.h"
00081 #include "kpilotConfig.h"
00082 
00083 #include "hotSync.h"
00084 #include "interactiveSync.h"
00085 #include "syncStack.h"
00086 
00087 #include "kpilotDCOP_stub.h"
00088 #include "kpilotDCOP.h"
00089 #include "logWidgetDCOP_stub.h"
00090 
00091 #include "pilotDaemon.moc"
00092 
00093 
00094 PilotDaemonTray::PilotDaemonTray(PilotDaemon * p) :
00095         KSystemTray(0, "pilotDaemon"),
00096         daemon(p),
00097         kap(0L)
00098 {
00099         FUNCTIONSETUP;
00100         setupWidget();
00101         setAcceptDrops(true);
00102 
00103 
00104         /* NOTREACHED */
00105         (void) pilotdaemon_id;
00106 }
00107 
00108 /* virtual */ void PilotDaemonTray::dragEnterEvent(QDragEnterEvent * e)
00109 {
00110         FUNCTIONSETUP;
00111         e->accept(QUriDrag::canDecode(e));
00112 }
00113 
00114 /* virtual */ void PilotDaemonTray::dropEvent(QDropEvent * e)
00115 {
00116         FUNCTIONSETUP;
00117 
00118         QStrList list;
00119 
00120         QUriDrag::decode(e, list);
00121 
00122         daemon->addInstallFiles(list);
00123 //      fInstaller->addFiles(list);
00124 }
00125 
00126 /* virtual */ void PilotDaemonTray::mousePressEvent(QMouseEvent * e)
00127 {
00128         FUNCTIONSETUP;
00129 
00130         switch (e->button()) 
00131         {
00132                 case RightButton: 
00133                         {
00134                                 KPopupMenu *menu = contextMenu();
00135                                 contextMenuAboutToShow(menu);
00136                                 menu->popup(e->globalPos());
00137                         }
00138                         break;
00139                 case LeftButton:
00140                         if (daemon) daemon->slotRunKPilot();
00141                         break;
00142                 default:
00143                         KSystemTray::mousePressEvent(e);
00144         }
00145 }
00146 
00147 /* virtual */ void PilotDaemonTray::closeEvent(QCloseEvent *)
00148 {
00149         FUNCTIONSETUP;
00150         daemon->quitNow();
00151 }
00152 
00153 void PilotDaemonTray::setupWidget()
00154 {
00155         FUNCTIONSETUP;
00156 
00157         KGlobal::iconLoader()->addAppDir(CSL1("kpilot"));
00158         icon = KGlobal::iconLoader()->loadIcon(CSL1("hotsync"), KIcon::Toolbar,
00159                 0, KIcon::DefaultState, 0, false);
00160         busyicon = KGlobal::iconLoader()->loadIcon(CSL1("busysync"), KIcon::Toolbar,
00161                 0, KIcon::DefaultState, 0, false);
00162 
00163         slotShowBusy();
00164         QTimer::singleShot(2000,this,SLOT(slotShowNormal()));
00165 
00166         KPopupMenu *menu = contextMenu();
00167 
00168         menu->insertItem(i18n("&About"), this, SLOT(slotShowAbout()));
00169         menuKPilotItem = menu->insertItem(i18n("Start &KPilot"), daemon,
00170                 SLOT(slotRunKPilot()));
00171 
00172 #ifdef DEBUG
00173         DEBUGDAEMON << fname << ": Finished getting icons" << endl;
00174 #endif
00175 }
00176 
00177 void PilotDaemonTray::slotShowAbout()
00178 {
00179         FUNCTIONSETUP;
00180 
00181         if (!kap)
00182         {
00183                 kap = new KAboutApplication(0, "kpdab", false);
00184         }
00185 
00186         kap->show();
00187 }
00188 
00189 
00190 void PilotDaemonTray::enableRunKPilot(bool b)
00191 {
00192         FUNCTIONSETUP;
00193         contextMenu()->setItemEnabled(menuKPilotItem, b);
00194 }
00195 
00196 
00197 void PilotDaemonTray::changeIcon(IconShape i)
00198 {
00199         FUNCTIONSETUP;
00200 
00201         switch (i)
00202         {
00203         case Normal:
00204                 if (icon.isNull())
00205                 {
00206                         kdWarning() << k_funcinfo
00207                                 << ": Regular icon is NULL!" << endl;
00208                 }
00209                 setPixmap(icon);
00210                 break;
00211         case Busy:
00212                 if (busyicon.isNull())
00213                 {
00214                         kdWarning() << k_funcinfo
00215                                 << ": Busy icon is NULL!" << endl;
00216                 }
00217                 setPixmap(busyicon);
00218                 break;
00219         default:
00220                 kdWarning() << k_funcinfo
00221                         << ": Bad icon number " << (int) i << endl;
00222         }
00223 }
00224 
00225 void PilotDaemonTray::slotShowNormal()
00226 {
00227         FUNCTIONSETUP;
00228         changeIcon(Normal);
00229 }
00230 
00231 void PilotDaemonTray::slotShowBusy()
00232 {
00233         FUNCTIONSETUP;
00234         changeIcon(Busy);
00235 }
00236 
00237 
00238 
00239 PilotDaemon::PilotDaemon() :
00240         DCOPObject("KPilotDaemonIface"),
00241         fStatus(INIT),
00242         fPostSyncAction(None),
00243         fPilotLink(0L),
00244         fPilotDevice(QString::null),
00245         fNextSyncType(PilotDaemonDCOP::HotSync),
00246         fSyncStack(0L),
00247         fTray(0L),
00248         fInstaller(0L),
00249         fLogStub(new LoggerDCOP_stub("kpilot", "LogIface")),
00250         fKPilotStub(new KPilotDCOP_stub("kpilot", "KPilotIface"))
00251 {
00252         FUNCTIONSETUP;
00253 
00254         fInstaller = new FileInstaller;
00255         connect(fInstaller, SIGNAL(filesChanged()),
00256                 this, SLOT(slotFilesChanged()));
00257 
00258         setupPilotLink();
00259         reloadSettings();
00260 
00261         if (fStatus == ERROR)
00262         {
00263                 kdWarning() << k_funcinfo
00264                         << ": Connecting to device failed." << endl;
00265                 return;
00266         }
00267 
00268 
00269 #ifdef DEBUG
00270         DEBUGDAEMON << fname
00271                 << ": The daemon is ready with status "
00272                 << statusString() << " (" << (int) fStatus << ")" << endl;
00273 #endif
00274 }
00275 
00276 PilotDaemon::~PilotDaemon()
00277 {
00278         FUNCTIONSETUP;
00279 
00280         KPILOT_DELETE(fPilotLink);
00281         KPILOT_DELETE(fSyncStack);
00282         KPILOT_DELETE(fInstaller);
00283 }
00284 
00285 void PilotDaemon::addInstallFiles(QStrList l)
00286 {
00287         FUNCTIONSETUP;
00288 
00289         fInstaller->addFiles(l);
00290 }
00291 
00292 int PilotDaemon::getPilotSpeed(KPilotConfigSettings & config)
00293 {
00294         FUNCTIONSETUP;
00295 
00296         int speed = config.getPilotSpeed();
00297 
00298         // Translate the speed entry in the
00299         // config file to something we can
00300         // put in the environment (for who?)
00301         //
00302         //
00303         const char *speedname = 0L;
00304 
00305         switch (speed)
00306         {
00307         case 0:
00308                 speedname = "PILOTRATE=9600";
00309                 break;
00310         case 1:
00311                 speedname = "PILOTRATE=19200";
00312                 break;
00313         case 2:
00314                 speedname = "PILOTRATE=38400";
00315                 break;
00316         case 3:
00317                 speedname = "PILOTRATE=57600";
00318                 break;
00319         case 4:
00320                 speedname = "PILOTRATE=115200";
00321                 break;
00322         default:
00323                 speedname = "PILOTRATE=9600";
00324         }
00325 
00326 #ifdef DEBUG
00327         DEBUGDAEMON << fname
00328                 << ": Speed set to "
00329                 << speedname << " (" << speed << ")" << endl;
00330 #endif
00331 
00332         putenv((char *) speedname);
00333 
00334         return speed;
00335 }
00336 
00337 
00338 void PilotDaemon::showTray()
00339 {
00340         FUNCTIONSETUP;
00341 
00342         if (!fTray)
00343         {
00344 #ifdef DEBUG
00345                 DEBUGDAEMON << fname << ": No tray icon to display!" << endl;
00346 #endif
00347 
00348                 return;
00349         }
00350 
00351         // Copied from Klipper
00352         KWin::setSystemTrayWindowFor(fTray->winId(), 0);
00353         fTray->setGeometry(-100, -100, 42, 42);
00354         fTray->show();
00355 
00356 #ifdef DEBUG
00357         DEBUGDAEMON << fname << ": Tray icon displayed." << endl;
00358 #endif
00359 
00360         updateTrayStatus();
00361 }
00362 
00363 /* DCOP ASYNC */ void PilotDaemon::reloadSettings()
00364 {
00365         FUNCTIONSETUP;
00366 
00367         switch (fStatus)
00368         {
00369         case INIT:
00370         case HOTSYNC_END:
00371         case ERROR:
00372         case READY:
00373                 // It's OK to reload settings in these states.
00374                 break;
00375         case HOTSYNC_START:
00376         case FILE_INSTALL_REQ:
00377                 // Postpone the reload till the sync finishes.
00378                 fPostSyncAction |= ReloadSettings;
00379                 return;
00380                 break;
00381         }
00382 
00383         KPilotConfigSettings & config = KPilotConfig::getConfig();
00384         config.reparseConfiguration();
00385 
00386         getPilotSpeed(config);
00387 
00388         fPilotDevice = config.getPilotDevice();
00389         fPilotType = KPilotDeviceLink::None;
00390         int t = config.getPilotType();
00391         
00392         (void) PilotAppCategory::setupPilotCodec(config.getEncoding());
00393 
00394 #ifdef DEBUG
00395         DEBUGDAEMON << fname
00396                 << ": Got configuration "
00397                 << fPilotDevice
00398                 << " ("
00399                 << fPilotType
00400                 << ")"
00401                 << endl;
00402 #endif
00403 
00404         switch (t)
00405         {
00406         case 0:
00407                 fPilotType = KPilotDeviceLink::Serial;
00408                 break;
00409         case 1:
00410                 fPilotType = KPilotDeviceLink::OldStyleUSB;
00411                 break;
00412         case 2:
00413                 fPilotType = KPilotDeviceLink::DevFSUSB;
00414                 break;
00415         default:
00416 #ifdef DEBUG
00417                 DEBUGDAEMON << fname << ": Unknown device type " << t << endl;
00418 #endif
00419                 break;
00420         }
00421 
00422         /*
00423         ** Override the kind of device, since OldStyleUSB
00424         ** works with everything and it saves the user from
00425         ** havind to choose the right kind.
00426         */
00427         fPilotType = KPilotDeviceLink::OldStyleUSB;
00428 
00429         if (fPilotLink)
00430         {
00431 #ifdef DEBUG
00432                 DEBUGDAEMON << fname
00433                         << ": Resetting with device "
00434                         << fPilotDevice
00435                         << " and type "
00436                         << fPilotLink->deviceTypeString(fPilotType) << endl;
00437 #endif
00438 
00439                 fPilotLink->reset(fPilotType, fPilotDevice);
00440         }
00441 
00442         if (config.getDockDaemon())
00443         {
00444                 if (!fTray)
00445                 {
00446                         fTray = new PilotDaemonTray(this);
00447                         fTray->show();
00448                 }
00449                 else
00450                 {
00451                         fTray->show();
00452                 }
00453         }
00454         else
00455         {
00456                 if (fTray)
00457                 {
00458                         fTray->hide();
00459                         delete fTray;
00460 
00461                         fTray = 0L;
00462                 }
00463         }
00464         
00465         updateTrayStatus();
00466 }
00467 
00468 /* DCOP */ QString PilotDaemon::statusString()
00469 {
00470         FUNCTIONSETUP;
00471 
00472         QString s = CSL1("PilotDaemon=");
00473 
00474         switch (status())
00475         {
00476         case INIT:
00477                 s.append(QString(CSL1("Initializing")));
00478                 break;
00479         case READY:
00480                 s.append(QString(CSL1("Found device")));
00481                 break;
00482         case ERROR:
00483                 s.append(QString(CSL1("Error")));
00484                 break;
00485         case FILE_INSTALL_REQ:
00486                 s.append(QString(CSL1("Installing File")));
00487                 break;
00488         case HOTSYNC_END:
00489                 s.append(QString(CSL1("End of Hotsync")));
00490                 break;
00491         case HOTSYNC_START:
00492                 s.append(QString(CSL1("Syncing")));
00493                 break;
00494         }
00495 
00496         s.append(CSL1(" NextSync="));
00497         s.append(syncTypeString(fNextSyncType));
00498 
00499         s.append(CSL1(" ("));
00500         if (fPilotLink)
00501         {
00502                 s.append(fPilotLink->statusString());
00503         }
00504         s.append(CSL1(")"));
00505 
00506         return s;
00507 }
00508 
00509 
00510 
00511 bool PilotDaemon::setupPilotLink()
00512 {
00513         FUNCTIONSETUP;
00514 
00515         if (fPilotLink)
00516         {
00517                 delete fPilotLink;
00518 
00519                 fPilotLink = 0;
00520         }
00521 
00522         fPilotLink = KPilotDeviceLink::init();
00523         if (!fPilotLink)
00524         {
00525                 kdWarning() << k_funcinfo
00526                         << ": Can't get pilot link." << endl;
00527                 return false;
00528         }
00529 
00530         QObject::connect(fPilotLink, SIGNAL(deviceReady()),
00531                 this, SLOT(startHotSync()));
00532         // connect the signals emitted by the pilotDeviceLink
00533         QObject::connect(fPilotLink, SIGNAL(logError(const QString &)),
00534                 this, SLOT(logError(const QString &)));
00535         QObject::connect(fPilotLink, SIGNAL(logMessage(const QString &)),
00536                 this, SLOT(logMessage(const QString &)));
00537         QObject::connect(fPilotLink, 
00538                 SIGNAL(logProgress(const QString &,int)),
00539                 this, SLOT(logProgress(const QString &,int)));
00540 
00541 
00542         return true;
00543 }
00544 
00545 
00546 /* DCOP ASYNC */ void PilotDaemon::quitNow()
00547 {
00548         FUNCTIONSETUP;
00549         // Using switch to make sure we cover all the cases.
00550         //
00551         //
00552         switch (fStatus)
00553         {
00554         case INIT:
00555         case HOTSYNC_END:
00556         case ERROR:
00557                 getKPilot().daemonStatus(KPilotDCOP::DaemonQuit);
00558                 kapp->quit();
00559                 break;
00560         case READY:
00561         case HOTSYNC_START:
00562         case FILE_INSTALL_REQ:
00563                 fPostSyncAction |= Quit;
00564                 break;
00565         }
00566 }
00567 
00568 /* DCOP ASYNC */ void PilotDaemon::requestRegularSyncNext()
00569 {
00570         requestSync(PilotDaemonDCOP::HotSync);
00571 }
00572 
00573 /* DCOP ASYNC */ void PilotDaemon::requestFastSyncNext()
00574 {
00575         requestSync(PilotDaemonDCOP::FastSync);
00576 }
00577 
00578 
00579 /* DCOP ASYNC */ void PilotDaemon::requestSync(int mode)
00580 {
00581         FUNCTIONSETUP;
00582 
00583 #ifdef DEBUG
00584         DEBUGDAEMON << fname
00585                 << ": Next sync is: "
00586                 << syncTypeString(mode)
00587                 << endl ;
00588 #endif
00589 
00590         fNextSyncType = mode;
00591 
00592         updateTrayStatus();
00593 }
00594 
00595 /* DCOP */ int PilotDaemon::nextSyncType() const
00596 {
00597         return fNextSyncType;
00598 }
00599 
00600 QString PilotDaemon::syncTypeString(int i) const
00601 {
00602         FUNCTIONSETUP;
00603         switch (i)
00604         {
00605         case PilotDaemonDCOP::Test:
00606                 return QString(CSL1("Test"));
00607         case PilotDaemonDCOP::HotSync:
00608                 return QString(CSL1("HotSync"));
00609         case PilotDaemonDCOP::FastSync:
00610                 return QString(CSL1("FastSync"));
00611         case PilotDaemonDCOP::Backup:
00612                 return QString(CSL1("Backup"));
00613         case PilotDaemonDCOP::Restore:
00614                 return QString(CSL1("Restore"));
00615         default:
00616                 return QString(CSL1("<unknown>"));
00617         }
00618 }
00619 
00620 /* slot */ void PilotDaemon::startHotSync()
00621 {
00622         FUNCTIONSETUP;
00623 
00624 
00625         if (fTray)
00626         {
00627 #ifdef DEBUG
00628                 DEBUGKPILOT << fname << ": Changing tray icon." << endl;
00629 #endif
00630 
00631                 fTray->changeIcon(PilotDaemonTray::Busy);
00632         }
00633 
00634         getKPilot().daemonStatus(KPilotDCOP::StartOfHotSync);
00635         
00636         fStatus = HOTSYNC_START ;
00637 
00638 #ifdef DEBUG
00639         DEBUGDAEMON << fname
00640                 << ": Starting Sync with type "
00641                 << syncTypeString(fNextSyncType)
00642                 << " (" << fNextSyncType << ")" << endl;
00643 #endif
00644 
00645         KPilotConfigSettings &c = KPilotConfig::getConfig();
00646         QStringList conduits ;
00647         bool installFiles = false;
00648 
00649         if ((fNextSyncType == PilotDaemonDCOP::HotSync)
00650                 /* || other sync types */
00651                 )
00652         {
00653                 conduits = c.getInstalledConduits();
00654                 installFiles = c.getSyncFiles();
00655         }
00656 
00657         fSyncStack = new ActionQueue(fPilotLink);
00658         fSyncStack->queueInit(ActionQueue::WithUserCheck);
00659         
00660         switch (fNextSyncType)
00661         {
00662         case PilotDaemonDCOP::Test:
00663                 fSyncStack->addAction(new TestLink(fPilotLink));
00664                 // No conduits, nothing.
00665                 break;
00666         case PilotDaemonDCOP::Backup:
00667                 if (conduits.count() > 0)
00668                 {
00669                         fSyncStack->queueConduits(&KPilotConfig::getConfig(),
00670                                 conduits,
00671                                 ActionQueue::Backup);
00672                 }
00673                 fSyncStack->addAction(new BackupAction(fPilotLink));
00674                 break;
00675         case PilotDaemonDCOP::Restore:
00676                 fSyncStack->addAction(new RestoreAction(fPilotLink));
00677                 break;
00678         case PilotDaemonDCOP::HotSync:
00679                 if (conduits.count() > 0)
00680                 {
00681                         fSyncStack->queueConduits(&KPilotConfig::getConfig(),
00682                                 conduits,
00683                                 ActionQueue::HotSync);
00684                 }
00685                 if (installFiles && fInstaller)
00686                 {
00687                         fSyncStack->queueInstaller(fInstaller->dir(),
00688                                 fInstaller->fileNames());
00689                 }
00690                 break;
00691         default:
00692 #ifdef DEBUG
00693                 DEBUGDAEMON << fname
00694                         << ": Can't handle sync type "
00695                         << syncTypeString(fNextSyncType) << endl;
00696 #endif
00697                 break;
00698         }
00699 
00700         fSyncStack->queueCleanup();
00701         
00702         QObject::connect(fSyncStack, SIGNAL(logError(const QString &)),
00703                 this, SLOT(logError(const QString &)));
00704         QObject::connect(fSyncStack, SIGNAL(logMessage(const QString &)),
00705                 this, SLOT(logMessage(const QString &)));
00706         QObject::connect(fSyncStack, 
00707                 SIGNAL(logProgress(const QString &,int)),
00708                 this, SLOT(logProgress(const QString &,int)));
00709 
00710         QObject::connect(fSyncStack, SIGNAL(syncDone(SyncAction *)),
00711                 this, SLOT(endHotSync()));
00712 
00713         QTimer::singleShot(0,fSyncStack,SLOT(execConduit()));
00714         
00715         updateTrayStatus();
00716 }
00717 
00718 /* slot */ void PilotDaemon::logMessage(const QString & s)
00719 {
00720         FUNCTIONSETUPL(2);
00721 
00722         getLogger().logMessage(s);
00723         updateTrayStatus(s);
00724 }
00725 
00726 /* slot */ void PilotDaemon::logError(const QString & s)
00727 {
00728         FUNCTIONSETUP;
00729 
00730         getLogger().logMessage(s);
00731         updateTrayStatus(s);
00732 }
00733 
00734 /* slot */ void PilotDaemon::logProgress(const QString & s, int i)
00735 {
00736         FUNCTIONSETUPL(2);
00737 
00738         getLogger().logProgress(s, i);
00739         if (!s.isEmpty()) updateTrayStatus(s);
00740 }
00741 /* slot */ void PilotDaemon::endHotSync()
00742 {
00743         FUNCTIONSETUP;
00744 
00745         if (fTray)
00746         {
00747                 QTimer::singleShot(2000,fTray,SLOT(slotShowNormal()));
00748         }
00749 
00750         KPILOT_DELETE(fSyncStack);
00751         fPilotLink->close();
00752 
00753         getLogger().logProgress(i18n("HotSync Completed.<br>"), 100);
00754         getKPilot().daemonStatus(KPilotDCOP::EndOfHotSync);
00755         
00756         fStatus = HOTSYNC_END;
00757 
00758         if (fPostSyncAction & Quit)
00759         {
00760                 getKPilot().daemonStatus(KPilotDCOP::DaemonQuit);
00761                 kapp->quit();
00762         }
00763         if (fPostSyncAction & ReloadSettings)
00764         {
00765                 reloadSettings();
00766         }
00767         else
00768         {
00769                 QTimer::singleShot(2000,fPilotLink,SLOT(reset()));
00770         }
00771 
00772         fPostSyncAction = None;
00773         
00774         updateTrayStatus();
00775 }
00776 
00777 
00778 void PilotDaemon::slotFilesChanged()
00779 {
00780         FUNCTIONSETUP;
00781 }
00782 
00783 void PilotDaemon::slotRunKPilot()
00784 {
00785         FUNCTIONSETUP;
00786 
00787         QString kpilotError;
00788         QCString kpilotDCOP;
00789         int kpilotPID;
00790 
00791         if (KApplication::startServiceByDesktopName(CSL1("kpilot"),
00792                         QString::null, &kpilotError, &kpilotDCOP, &kpilotPID
00793 #if (KDE_VERSION >= 220)
00794                         // Startup notification added in 2.2
00795                         , ""
00796 #endif
00797                 ))
00798         {
00799                 kdWarning() << k_funcinfo
00800                         << ": Couldn't start KPilot! " << kpilotError << endl;
00801         }
00802         else
00803         {
00804 #ifdef DEBUG
00805                 DEBUGDAEMON << fname
00806                         << ": Started KPilot with DCOP name "
00807                         << kpilotDCOP << " (pid " << kpilotPID << ")" << endl;
00808 #endif
00809         }
00810 }
00811 
00812 void PilotDaemon::updateTrayStatus(const QString &s)
00813 {
00814         if (!fTray) return;
00815 
00816         QToolTip::remove(fTray);
00817         QToolTip::add(fTray,
00818                 i18n("<qt>%1<br/>%2</qt>")
00819                         .arg(statusString())
00820                         .arg(s)
00821                 );
00822 }
00823 
00824 
00825 int main(int argc, char **argv)
00826 {
00827         FUNCTIONSETUP;
00828 
00829         KAboutData about("kpilotDaemon",
00830                 I18N_NOOP("KPilot Daemon"),
00831                 KPILOT_VERSION,
00832                 "KPilot - Hot-sync software for unix\n\n",
00833                 KAboutData::License_GPL, "(c) 1998-2001, Dan Pilone");
00834         about.addAuthor("Dan Pilone",
00835                 I18N_NOOP("Project Leader"),
00836                 "pilone@slac.com", "http://www.slac.com/pilone/kpilot_home/");
00837         about.addAuthor("Adriaan de Groot",
00838                 I18N_NOOP("Maintainer"),
00839                 "groot@kde.org", "http://www.cs.kun.nl/~adridg/kpilot/");
00840 
00841         KCmdLineArgs::init(argc, argv, &about);
00842         KUniqueApplication::addCmdLineOptions();
00843         
00844         if (!KUniqueApplication::start())
00845         {
00846                 return 0;
00847         }
00848         KUniqueApplication a(true, true);
00849 
00850         // No options besides debug
00851         // KPilotConfig::getDebugLevel(false);
00852 
00853         // A block just to keep variables local.
00854         //
00855         //
00856         {
00857                 KPilotConfigSettings & c = KPilotConfig::getConfig();
00858                 c.setReadOnly(false);
00859 
00860                 if (c.getVersion() < KPilotConfig::ConfigurationVersion)
00861                 {
00862                         kdError() << k_funcinfo
00863                                 << ": Is still not configured for use."
00864                                 << endl;
00865                         return 1;
00866                 }
00867 
00868 #ifdef DEBUG
00869                 DEBUGDAEMON << fname
00870                         << ": Configuration version "
00871                         << c.getVersion() << endl;
00872 #endif
00873         }
00874 
00875 
00876         PilotDaemon *gPilotDaemon = new PilotDaemon();
00877 
00878         if (gPilotDaemon->status() == PilotDaemon::ERROR)
00879         {
00880                 delete gPilotDaemon;
00881 
00882                 gPilotDaemon = 0;
00883                 kdError() << k_funcinfo
00884                         << ": **\n"
00885                         ": Failed to start up daemon\n"
00886                         ": due to errors constructing it.\n" ": **" << endl;
00887                 return 2;
00888         }
00889 
00890         gPilotDaemon->showTray();
00891 
00892         return a.exec();
00893 
00894         /* NOTREACHED */
00895         (void) pilotdaemon_id;
00896 }
00897 
00898 
00899 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:14 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001