kpilot/lib

syncAction.h

00001 #ifndef _KPILOT_SYNCACTION_H
00002 #define _KPILOT_SYNCACTION_H
00003 /* syncAction.h         KPilot
00004 **
00005 ** Copyright (C) 1998-2001 by Dan Pilone
00006 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 **
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU Lesser General Public License as published by
00013 ** the Free Software Foundation; either version 2.1 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU Lesser General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU Lesser General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 ** MA 02110-1301, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org
00029 */
00030 
00031 #include <time.h>
00032 
00033 #include <pi-dlp.h>
00034 
00035 
00036 #include <qobject.h>
00037 #include <qstring.h>
00038 #include <qstringlist.h>
00039 
00040 #include "kpilotlink.h"
00041 
00042 class QTimer;
00043 class QSocketNotifier;
00044 class KPilotUser;
00045 class SyncAction;
00046 
00047 class KDE_EXPORT SyncAction : public QObject
00048 {
00049 Q_OBJECT
00050 
00051 public:
00052     SyncAction(KPilotDeviceLink *p,
00053         const char *name=0L);
00054     SyncAction(KPilotDeviceLink *p,
00055         QWidget *visibleparent,
00056         const char *name=0L);
00057     ~SyncAction();
00058 
00059     typedef enum { Error=-1 } Status;
00060 
00061     int status() const { return fActionStatus; } ;
00062     virtual QString statusString() const;
00063 
00064 protected:
00078     virtual bool exec() = 0;
00079 
00080 public slots:
00085     void execConduit();
00086 
00087 signals:
00088     void syncDone(SyncAction *);
00089     void logMessage(const QString &);
00090     void logError(const QString &);
00091     void logProgress(const QString &,int);
00092 
00102 protected slots:
00103     void delayedDoneSlot();
00104 
00105 protected:
00106     bool delayDone();
00107 
00108 public:
00109     void addSyncLogEntry(const QString &e,bool log=true)
00110         { if (deviceLink()) { deviceLink()->addSyncLogEntry(e,log); } } ;
00111     void addLogMessage( const QString &msg ) { emit logMessage( msg ); }
00112     void addLogError( const QString &msg ) { emit logError( msg ); }
00113     void addLogProgress( const QString &msg, int prog ) { emit logProgress( msg, prog ); }
00114 protected:
00116     KPilotDeviceLink *fHandle;
00117     int fActionStatus;
00118 
00120     inline KPilotDeviceLink *deviceLink() const { return fHandle; } ;
00121 
00126     int pilotSocket() const { return deviceLink() ? deviceLink()->pilotSocket() : -1 ; } ;
00127 
00132     int openConduit() { return deviceLink() ? deviceLink()->openConduit() : -1; } ;
00133 public:
00144     class SyncMode
00145     {
00146     public:
00148         enum Mode {
00149         eFastSync=1,
00150         eHotSync=2,
00151         eFullSync=3,
00152         eCopyPCToHH=4,
00153         eCopyHHToPC=5,
00154         eBackup=6,
00155         eRestore=7
00156         } ;
00157 
00164         SyncMode(Mode m, bool test=false, bool local=false);
00165 
00171         SyncMode(const QStringList &l);
00172 
00176         Mode mode() const { return fMode; };
00177 
00183         bool setMode(int);
00187         bool setMode(Mode m);
00188 
00191         bool setOptions(bool test, bool local) { fTest=test; fLocal=local; return true; } ;
00192 
00196         bool operator ==(const Mode &m) const { return mode() == m; } ;
00197         bool operator ==(const SyncMode &m) const
00198         {
00199             return ( mode() == m.mode() ) &&
00200                 ( isTest() == m.isTest() ) &&
00201                 ( isLocal() == m.isLocal() );
00202         } ;
00203 
00207         bool isTest() const { return fTest; };
00208 
00212         bool isLocal() const { return fLocal; };
00213 
00214 
00215         bool isFullSync() const
00216         {
00217             return  ( fMode==eFullSync  ) ||
00218                 ( fMode==eCopyPCToHH) ||
00219                 ( fMode==eCopyHHToPC) ;
00220         } ;
00221         bool isFirstSync() const
00222         {
00223             return ( fMode==eCopyHHToPC ) || ( fMode==eCopyPCToHH ) ;
00224         };
00225 
00227         bool isSync() const
00228         {
00229             return ( fMode==eFullSync ) ||
00230                 ( fMode == eHotSync ) ||
00231                 ( fMode == eFastSync );
00232         } ;
00233 
00235         bool isCopy() const
00236         {
00237             return ( fMode==eBackup ) ||
00238                 ( fMode==eRestore ) ||
00239                 ( fMode==eCopyPCToHH ) ||
00240                 ( fMode==eCopyHHToPC );
00241         } ;
00242 
00246         static QString name(Mode);
00251         QString name() const;
00252 
00258         QStringList list() const;
00259 
00260     private:
00261         Mode fMode;
00262         bool fTest;
00263         bool fLocal;
00264     };
00265 
00266 
00267     enum ConflictResolution
00268     {
00269         eUseGlobalSetting=-1,
00270         eAskUser=0,
00271         eDoNothing,
00272         eHHOverrides,
00273         ePCOverrides,
00274         ePreviousSyncOverrides,
00275         eDuplicate,
00276         eDelete,
00277         eCROffset=-1
00278     };
00279 
00280 protected:
00292     void startTickle(unsigned count=0);
00293     void stopTickle();
00294 signals:
00295     void timeout();
00296 
00297 
00298 
00299 
00300 protected:
00301     QWidget *fParent;
00302 
00315     int questionYesNo(const QString &question ,
00316         const QString &caption = QString::null,
00317         const QString &key = QString::null,
00318         unsigned timeout = 20,
00319         const QString &yes = QString::null,
00320         const QString &no = QString::null );
00321     int questionYesNoCancel(const QString &question ,
00322         const QString &caption = QString::null,
00323         const QString &key = QString::null,
00324         unsigned timeout = 20,
00325         const QString &yes = QString::null,
00326         const QString &no = QString::null ) ;
00327 };
00328 
00329 
00330 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys