kpilot

syncAction.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_SYNCACTION_H
00002 #define _KPILOT_SYNCACTION_H
00003 /* KPilot
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 <time.h>
00033 
00034 #include <pi-dlp.h>
00035 
00036 #include <qobject.h>
00037 #include <qstring.h>
00038 #include <qstringlist.h>
00039 
00040 #include "kpilotlink.h"
00041 
00046 class QTimer;
00047 class KPilotUser;
00048 class SyncAction;
00049 
00050 class KDE_EXPORT SyncAction : public QObject
00051 {
00052 Q_OBJECT
00053 
00054 public:
00055     SyncAction(KPilotLink *p,
00056         const char *name=0L);
00057     SyncAction(KPilotLink *p,
00058         QWidget *visibleparent,
00059         const char *name=0L);
00060     ~SyncAction();
00061 
00062     typedef enum { Error=-1 } Status;
00063 
00068     int status() const
00069     {
00070         return fActionStatus;
00071     }
00073     virtual QString statusString() const;
00074 
00075 protected:
00089     virtual bool exec() = 0;
00090 
00091 public slots:
00096     void execConduit();
00097 
00098 signals:
00099     void syncDone(SyncAction *);
00100     void logMessage(const QString &);
00101     void logError(const QString &);
00102     void logProgress(const QString &,int);
00103 
00104 protected slots:
00109     void delayedDoneSlot();
00110 
00111 protected:
00121     bool delayDone();
00122 
00123 public:
00131     void addSyncLogEntry(const QString &e,bool log=true)
00132     {
00133         if (deviceLink())
00134         {
00135             deviceLink()->addSyncLogEntry(e,log);
00136         }
00137     }
00141     void addLogMessage( const QString &msg )
00142     {
00143         emit logMessage( msg );
00144     }
00146     void addLogError( const QString &msg )
00147     {
00148         emit logError( msg );
00149     }
00151     void addLogProgress( const QString &msg, int prog )
00152     {
00153         emit logProgress( msg, prog );
00154     }
00155 protected:
00157     KPilotLink *fHandle;
00158     int fActionStatus;
00159 
00161     inline KPilotLink *deviceLink() const
00162     {
00163         return fHandle;
00164     }
00165 
00170     int pilotSocket() const
00171     {
00172         return deviceLink() ? deviceLink()->pilotSocket() : -1 ;
00173     }
00174 
00179     int openConduit()
00180     {
00181         return deviceLink() ? deviceLink()->openConduit() : -1;
00182     }
00183 public:
00194     class SyncMode
00195     {
00196     public:
00198         enum Mode {
00199             eHotSync=1,
00200             eFullSync=2,
00201             eCopyPCToHH=3,
00202             eCopyHHToPC=4,
00203             eBackup=5,
00204             eRestore=6
00205         } ;
00206 
00213         SyncMode(Mode m, bool test=false, bool local=false);
00214 
00220         SyncMode(const QStringList &l);
00221 
00225         Mode mode() const
00226         {
00227             return fMode;
00228         }
00229 
00235         bool setMode(int);
00236 
00240         bool setMode(Mode m);
00241 
00244         bool setOptions(bool test, bool local)
00245         {
00246             fTest=test;
00247             fLocal=local;
00248             return true;
00249         }
00250 
00254         bool operator ==(const Mode &m) const
00255         {
00256             return mode() == m;
00257         }
00261         bool operator ==(const SyncMode &m) const
00262         {
00263             return ( mode() == m.mode() ) &&
00264                 ( isTest() == m.isTest() ) &&
00265                 ( isLocal() == m.isLocal() );
00266         } ;
00267 
00271         bool isTest() const
00272         {
00273             return fTest;
00274         }
00275 
00279         bool isLocal() const
00280         {
00281             return fLocal;
00282         }
00283 
00284         bool isFullSync() const
00285         {
00286             return  ( fMode==eFullSync  ) ||
00287                 ( fMode==eCopyPCToHH) ||
00288                 ( fMode==eCopyHHToPC) ;
00289         } ;
00290         bool isFirstSync() const
00291         {
00292             return ( fMode==eCopyHHToPC ) || ( fMode==eCopyPCToHH ) ;
00293         };
00294 
00296         bool isSync() const
00297         {
00298             return ( fMode==eFullSync ) ||
00299                 ( fMode == eHotSync );
00300         } ;
00301 
00303         bool isCopy() const
00304         {
00305             return ( fMode==eBackup ) ||
00306                 ( fMode==eRestore ) ||
00307                 ( fMode==eCopyPCToHH ) ||
00308                 ( fMode==eCopyHHToPC );
00309         } ;
00310 
00314         static QString name(Mode);
00315 
00320         QString name() const;
00321 
00327         QStringList list() const;
00328 
00329     private:
00330         Mode fMode;
00331         bool fTest;
00332         bool fLocal;
00333     };
00334 
00335 
00336     enum ConflictResolution
00337     {
00338         eUseGlobalSetting=-1,
00339         eAskUser=0,
00340         eDoNothing,
00341         eHHOverrides,
00342         ePCOverrides,
00343         ePreviousSyncOverrides,
00344         eDuplicate,
00345         eDelete,
00346         eCROffset=-1
00347     };
00348 
00354     enum BackupFrequency
00355     {
00356         eEveryHotSync=0,
00357         eOnRequestOnly
00358     };
00359 
00360 protected:
00372     void startTickle(unsigned count=0);
00373     void stopTickle();
00374 signals:
00375     void timeout();
00376 
00377 
00378 
00379 
00380 protected:
00381     QWidget *fParent;
00382 
00395     int questionYesNo(const QString &question ,
00396         const QString &caption = QString::null,
00397         const QString &key = QString::null,
00398         unsigned timeout = 20,
00399         const QString &yes = QString::null,
00400         const QString &no = QString::null );
00401     int questionYesNoCancel(const QString &question ,
00402         const QString &caption = QString::null,
00403         const QString &key = QString::null,
00404         unsigned timeout = 20,
00405         const QString &yes = QString::null,
00406         const QString &no = QString::null ) ;
00407 };
00408 
00409 
00410 #endif