kpilot

kpilotdevicelink.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_KPILOTDEVICELINK_H
00002 #define _KPILOT_KPILOTDEVICELINK_H
00003 /*
00004 **
00005 ** Copyright (C) 1998-2001 by Dan Pilone
00006 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 ** Copyright (C) 2006 Adriaan de Groot <groot@kde.org>
00008 **
00009 */
00010 
00011 /*
00012 ** This program is free software; you can redistribute it and/or modify
00013 ** it under the terms of the GNU Lesser General Public License as published by
00014 ** the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00021 **
00022 ** You should have received a copy of the GNU Lesser General Public License
00023 ** along with this program in a file called COPYING; if not, write to
00024 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 ** MA 02110-1301, USA.
00026 */
00027 
00028 /*
00029 ** Bug reports and questions can be sent to kde-pim@kde.org
00030 */
00031 
00032 #include "kpilotlink.h"
00033 
00034 class QThread;
00035 
00036 class DeviceMap; 
00037 class Messages; 
00038 class DeviceCommThread; 
00039 
00045 enum LinkStatus {
00046     Init,
00047     WaitingForDevice,
00048     FoundDevice,
00049     CreatedSocket,
00050     DeviceOpen,
00051     AcceptedDevice,
00052     SyncDone,
00053     PilotLinkError,
00054     WorkaroundUSB
00055 } ;
00056 
00060 enum DeviceCustomEvents { 
00061     EventLogMessage = QEvent::User + 777,
00062     EventLogError,
00063     EventLogProgress,
00064     EventDeviceReady
00065 };
00066          
00072 class KDE_EXPORT KPilotDeviceLink : public KPilotLink
00073 {
00074 friend class PilotSerialDatabase;
00075 friend class DeviceCommThread;
00076 
00077 Q_OBJECT
00078 
00079 public:
00089     KPilotDeviceLink( QObject *parent = 0,
00090         const char *name = 0,
00091         const QString &tempDevice = QString::null );
00092 
00098     virtual ~KPilotDeviceLink();
00099 
00104     LinkStatus status() const
00105     {
00106         return fLinkStatus;
00107     }
00108 
00110     static QString statusString(LinkStatus l);
00111 
00112     // The following API is the actual implementation of
00113     // the KPilotLink API, for documentation see that file.
00114     //
00115     virtual QString statusString() const;
00116     virtual bool isConnected() const;
00117     virtual void reset( const QString & );
00118     virtual void close();
00119     virtual void reset();
00120     virtual bool event(QEvent *e);
00121     virtual bool tickle();
00122     virtual const KPilotCard *getCardInfo(int card);
00123     virtual void endSync( EndOfSyncFlags f );
00124     virtual int openConduit();
00125     virtual int getNextDatabase(int index,struct DBInfo *);
00126     virtual int findDatabase(const char *name, struct DBInfo*,
00127         int index=0, unsigned long type=0, unsigned long creator=0);
00128     virtual bool retrieveDatabase(const QString &path, struct DBInfo *db);
00129     virtual DBInfoList getDBList(int cardno=0, int flags=dlpDBListRAM);
00130     virtual PilotDatabase *database( const QString &name );
00131     virtual PilotDatabase *database( const DBInfo *info );
00132 
00133 protected:
00134     virtual bool installFile(const QString &, const bool deleteFile);
00135     virtual void addSyncLogEntryImpl( const QString &s );
00136     virtual int pilotSocket() const
00137     {
00138         return fPilotSocket;
00139     }
00140 
00141 
00142 private:
00143     LinkStatus fLinkStatus;
00144 
00145 
00146 public:
00147 
00154     void setWorkarounds(bool usb)
00155     {
00156         fWorkaroundUSB = usb;
00157     }
00158 
00164     void setTempDevice( const QString &device );
00165     
00171     void setDevice( const QString &device ) 
00172     { 
00173         fPilotPath = device;
00174     }
00175     
00176 
00177 protected:
00179     bool fWorkaroundUSB;
00180 
00181 
00187     void checkDevice();
00188 
00189 protected:
00194     QString fRealPilotPath;
00195 
00199     int fPilotSocket;
00200     QString fTempDevice;
00201 
00206     int fAcceptedCount;
00207     
00211     void startCommThread();
00212     void stopCommThread();
00213 
00214 protected:
00215     Messages *fMessages;
00216     DeviceCommThread *fDeviceCommThread;
00217 } ;
00218 
00219 #endif
00220