kpilot

pilotDaemon.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_PILOTDAEMON_H
00002 #define _KPILOT_PILOTDAEMON_H
00003 /* pilotDaemon.h            KPilot
00004 **
00005 ** Copyright (C) 1998-2001 by Dan Pilone
00006 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 **
00008 ** See the .cc file for an explanation of what this file is for.
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., 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 
00033 #include <ksystemtray.h>
00034 
00035 #include "kpilotlink.h"
00036 #include "syncAction.h"
00037 #include "pilotDaemonDCOP.h"
00038 
00039 class QPixmap;
00040 class QTimer;
00041 class KAboutApplication;
00042 class QPopupMenu;
00043 
00044 class PilotDaemon;
00045 class ActionQueue;
00046 class FileInstaller;
00047 class LoggerDCOP_stub;
00048 class KPilotDCOP_stub;
00049 class LogFile;
00050 
00051 class KPilotLink;
00052 class KPilotDeviceLink;
00053 
00054 class PilotDaemonTray : public KSystemTray
00055 {
00056     Q_OBJECT
00057 
00058 friend class PilotDaemon;
00059 
00060 public:
00061     PilotDaemonTray(PilotDaemon *p);
00062 
00063     typedef enum { Normal, Busy, NotListening } IconShape ;
00064     void changeIcon(IconShape);
00065 
00066     void enableRunKPilot(bool);
00067 
00068     virtual void dragEnterEvent(QDragEnterEvent *);
00069     virtual void dropEvent(QDropEvent *);
00070 
00071 
00072 protected:
00073     void setupWidget();
00077     QPopupMenu *fSyncTypeMenu;
00078 
00079 protected slots:
00080     void slotShowAbout();
00081     void slotShowBusy();
00082     void slotShowNormal();
00083     void slotShowNotListening();
00084     void slotBusyTimer();
00085 
00086     // "Regular" QT actions
00087     //
00088     //
00089     virtual void mousePressEvent(QMouseEvent* e);
00090     virtual void closeEvent(QCloseEvent *e);
00091 
00092 protected:
00093     void startHotSync();
00094     void endHotSync();
00095 
00096 private:
00097     QPixmap icons[((int) NotListening) + 1];
00098     IconShape fCurrentIcon;
00099     PilotDaemon *daemon;
00100 
00106     int menuKPilotItem;
00107 
00113     int menuConfigureConduitsItem;
00114 
00118     KAboutApplication *kap;
00119 
00123     QTimer *fBlinkTimer;
00124 
00125 } ;
00126 
00127 class PilotDaemon : public QObject, virtual public PilotDaemonDCOP
00128 {
00129 Q_OBJECT
00130 
00131 // The tray must be our friend so that we can let it stop the daemon.
00132 friend class PilotDaemonTray;
00133 
00134 
00135 public:
00136     PilotDaemon();
00137     ~PilotDaemon();
00138 
00139     enum DaemonStatus
00140     {
00141         HOTSYNC_START,    // Hotsync is running
00142         HOTSYNC_END,      // Hotsync is cleaning up
00143         FILE_INSTALL_REQ, // A file is being saved for installation
00144         ERROR,
00145         READY,            // Connected to device and ready for Sync
00146         INIT,
00147         NOT_LISTENING
00148     };
00149 
00150     DaemonStatus status() const { return fDaemonStatus; } ;
00151     /* DCOP */ virtual QString statusString();
00152     /* DCOP */ virtual QString shortStatusString();
00153 
00159     void showTray();
00160     virtual void addInstallFiles(const QStringList &);
00161 
00162     // The next few functions are the DCOP interface.
00163     // Some are also slots.
00164     //
00165 public slots:
00166     virtual ASYNC requestSync(int);
00167 public:
00168     virtual ASYNC requestSyncType(QString);
00169     virtual ASYNC requestRegularSyncNext();
00170     virtual int nextSyncType() const;
00171     virtual ASYNC requestSyncOptions(bool,bool);
00172 
00173     virtual ASYNC quitNow();
00174     virtual ASYNC reloadSettings();
00175     virtual ASYNC setTempDevice(QString d);
00176 
00177     virtual void stopListening();
00178     virtual void startListening();
00179     virtual bool isListening() { return fIsListening; }
00183     virtual QDateTime lastSyncDate();
00184     virtual QStringList configuredConduitList();
00185     virtual QString logFileName();
00186     virtual QString userName();
00187     virtual QString pilotDevice();
00188     virtual bool killDaemonOnExit();
00189 
00190 protected:
00191     DaemonStatus fDaemonStatus;
00192 
00193     enum postSyncActions {
00194         None=0,
00195         ReloadSettings = 1,
00196         Quit = 2
00197         } ;
00198     int fPostSyncAction;
00199 
00200 protected slots:
00201     void startHotSync( KPilotLink* lnk );
00202     void endHotSync();
00203 
00204     void logMessage(const QString &);
00205     void logError(const QString &);
00206     void logProgress(const QString &,int);
00207 
00208 private:
00209     int getPilotSpeed();
00210 
00217     bool shouldBackup();
00218 
00219     bool setupPilotLink();
00220 
00221     KPilotDeviceLink &getPilotLink() { return *fPilotLink; }
00222     KPilotDeviceLink *fPilotLink;
00223 
00224     SyncAction::SyncMode fNextSyncType;
00225 
00226     ActionQueue *fSyncStack;
00227 
00232     PilotDaemonTray *fTray;
00233 
00237     void updateTrayStatus(const QString &s=QString::null);
00238 
00239     FileInstaller *fInstaller;
00240 
00241 protected slots:
00248     void slotFilesChanged();
00249 
00253     void slotRunKPilot();
00254 
00258     void slotRunConfig();
00259 
00263 protected:
00264     LoggerDCOP_stub &getLogger() { return *fLogStub; } ;
00265     LoggerDCOP_stub &getFileLogger() { return *fLogFileStub; } ;
00266     KPilotDCOP_stub &getKPilot() { return *fKPilotStub; } ;
00267 
00268     LogFile *fLogFile;
00269     bool fIsListening;
00270 
00271 private:
00272     LoggerDCOP_stub *fLogStub;
00273     LoggerDCOP_stub *fLogFileStub;
00274     KPilotDCOP_stub *fKPilotStub;
00275     QString fTempDevice;
00276 };
00277 
00278 
00279 #endif