kpilot Library API Documentation

kpilotlink.h

00001 #ifndef _KPILOT_KPILOTLINK_H
00002 #define _KPILOT_KPILOTLINK_H
00003 /* kpilotlink.h                 KPilot
00004 **
00005 ** Copyright (C) 1998-2001 by Dan Pilone
00006 **
00007 ** Encapsulates all the communication with the pilot. Also
00008 ** does daemon-like polling of the Pilot. Interesting status
00009 ** changes are signalled.
00010 */
00011 
00012 /*
00013 ** This program is free software; you can redistribute it and/or modify
00014 ** it under the terms of the GNU Lesser General Public License as published by
00015 ** the Free Software Foundation; either version 2.1 of the License, or
00016 ** (at your option) any later version.
00017 **
00018 ** This program is distributed in the hope that it will be useful,
00019 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 ** GNU Lesser General Public License for more details.
00022 **
00023 ** You should have received a copy of the GNU Lesser General Public License
00024 ** along with this program in a file called COPYING; if not, write to
00025 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00026 ** MA 02111-1307, USA.
00027 */
00028 
00029 /*
00030 ** Bug reports and questions can be sent to kde-pim@kde.org
00031 */
00032 
00033 #include <time.h>
00034 #include <pi-dlp.h>
00035 
00036 #ifndef QOBJECT_H
00037 #include <qobject.h>
00038 #endif
00039 
00040 
00041 class QTimer;
00042 class QDateTime;
00043 class QSocketNotifier;
00044 class KPilotUser;
00045 struct DBInfo;
00046 
00047 /*
00048 ** The KPilotLink class was originally a kind of C++ wrapper
00049 ** for the pilot-link library. It grew and grew and mutated
00050 ** until it was finally cleaned up again in 2001. In the meantime
00051 ** it had become something that wrapped a lot more than just
00052 ** pilot-link. This class currently does:
00053 ** 
00054 ** * Client (ie. conduit) handling of kpilotlink protocol connections
00055 ** * Pilot-link handling
00056 **
00057 ** Which is exactly what is needed: something that conduits can
00058 ** plug onto to talk to the pilot.
00059 */
00060 
00061 /*
00062 ** The struct db is a description class for Pilot databases
00063 ** by Kenneth Albanowski. It's not really clear why it's *here*.
00064 ** The macro pi_mktag is meant to be given four char (8-bit)
00065 ** quantities, which are arranged into an unsigned long; for example
00066 ** pi_mktag('l','n','c','h'). This is called the creator tag
00067 ** of a database, and db.creator can be compared with such a
00068 ** tag. The tag lnch is used by the Pilot's launcher app. Some
00069 ** parts of KPilot require such a tag.
00070 */
00071 struct db 
00072 {
00073         char name[256];
00074         int flags;
00075         unsigned long creator;
00076         unsigned long type;
00077         int maxblock;
00078 };
00079 
00080 #define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4))
00081 
00085 QDateTime readTm(const struct tm &t);
00089 struct tm writeTm(const QDateTime &dt);
00090 
00091 
00092 class KPilotDeviceLink : public QObject
00093 {
00094 friend class SyncAction;
00095 Q_OBJECT
00096 
00097 /*
00098 ** Constructors and destructors.
00099 */
00100 protected:
00106         KPilotDeviceLink(QObject *parent, const char *name);
00107 private:
00108         static KPilotDeviceLink *fDeviceLink;
00109 
00110 public:
00111         virtual ~KPilotDeviceLink();
00112         static KPilotDeviceLink *link() { return fDeviceLink; } ;
00113         static KPilotDeviceLink *init(QObject *parent=0L,const char *n=0L);
00114 
00115 /*
00116 ** Status information
00117 */
00118 
00119 public:
00125         typedef enum {
00126                 Init,
00127                 WaitingForDevice,
00128                 FoundDevice,
00129                 CreatedSocket,
00130                 DeviceOpen,
00131                 AcceptedDevice,
00132                 SyncDone,
00133                 PilotLinkError
00134                 } LinkStatus;
00135 
00136         LinkStatus status() const { return fStatus; } ;
00137         virtual QString statusString() const;
00138 
00143         bool getConnected() const { return fStatus == AcceptedDevice; }
00144         
00145 public slots:
00149         void tickle() const;
00150 
00151 private:
00152         LinkStatus fStatus;
00153 
00154 
00155 /*
00156 ** Used for initially attaching to the device.
00157 ** deviceReady() is emitted when the device has been opened
00158 ** and a Sync can start.
00159 */
00160 public:
00164         typedef enum { None,
00165                 Serial,
00166                 OldStyleUSB,
00167                 DevFSUSB
00168                 } DeviceType;
00169 
00170         DeviceType deviceType() const { return fDeviceType; } ;
00171         QString deviceTypeString(int i) const;
00172         bool isTransient() const
00173         {
00174                 return (fDeviceType==OldStyleUSB) ||
00175                         (fDeviceType==DevFSUSB);
00176         }
00177 
00178         QString pilotPath() const { return fPilotPath; } ;
00179 
00184         void reset(DeviceType t,const QString &pilotPath = QString::null);
00185 
00186 
00187 public slots:
00192         void close();
00193 
00199         void reset();
00200 
00201 protected slots:
00206         void openDevice();
00207 
00212         void acceptDevice();
00213 
00214 protected:
00219         bool open();
00220         
00226         void checkDevice();
00227 
00233         enum { OpenMessage=1, OpenFailMessage=2 } ;
00234         int messages;
00235         int messagesMask;
00236         static const int messagesType;
00237         
00238         void shouldPrint(int,const QString &);
00239 
00240 signals:
00245         void deviceReady();
00246 
00247 protected:
00248         int pilotSocket() const { return fCurrentPilotSocket; } ;
00249 
00250 
00251 private:
00256         QString fPilotPath;
00257 
00261         DeviceType fDeviceType;
00262 
00266         int fRetries;
00267 
00271         QTimer *fOpenTimer;
00272         QSocketNotifier *fSocketNotifier;
00273         bool fSocketNotifierActive;
00274 
00278         int fPilotMasterSocket;
00279         int fCurrentPilotSocket;
00280 
00281 signals:
00287         void logEntry(const char *);
00288 
00289 /*
00290 ** File installation.
00291 */
00292 public:
00293         int installFiles(const QStringList &, const bool deleteFiles=true);
00294 protected:
00295         bool installFile(const QString &, const bool deleteFile=true);
00296 
00303         void addSyncLogEntry(const QString &entry,bool log=true);
00304 
00305 signals:
00311         void logMessage(const QString &);
00312         void logError(const QString &);
00313         void logProgress(const QString &, int);
00314 
00315 
00316 /*
00317 ** Pilot User Identity functions.
00318 */
00319 public:
00327         KPilotUser *getPilotUser() { return fPilotUser; }
00328         void finishSync();
00329 
00330 protected:
00331         KPilotUser  *fPilotUser;
00332 
00333 /*
00334 ** Actions intended just to abstract away the pilot-link library interface.
00335 */
00336 protected:
00340         int openConduit();
00341 public:
00342         int getNextDatabase(int index,struct DBInfo *);
00343         int findDatabase(const char *name, struct DBInfo*, 
00344                 int index=0, long type=0, long creator=0);
00345 
00350         bool retrieveDatabase(const QString &path, struct DBInfo *db);
00351         
00352 public:
00356         QDateTime getTime();
00360         bool setTime(const time_t &pctime);
00361         
00365         unsigned long ROMversion() const;
00369         unsigned long majorVersion() const;
00373         unsigned long minorVersion() const;
00374          
00375         
00376 } ;
00377 
00378 bool operator < ( const struct db &, const struct db &) ;
00379 
00380 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:44 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001