src/MyFtp/myftptransfercontrol.h

00001 /****************************************************************************
00002 ** Gestion simplifié des listes de transferts ftp
00003 ** Créé par Anacr0x : anacr0x@free.fr
00004 **
00005 ** Sous licence GPL v2 ou plus
00006  ****************************************************************************/
00007 
00008 #ifndef MYFTP_TRANSFER_CONTROL_H
00009 #define MYFTP_TRANSFER_CONTROL_H
00010 
00011 #include <QtCore>
00012 #include <QtGui>
00013 #include <QtNetwork>
00014 
00015 /*************************************************************************/
00017 
00022 /*************************************************************************/
00023 
00024 class MyTransfer
00025 {
00027         int id;
00028 
00029 public:
00031         enum TransferCmd {Download, Upload};
00032 
00034         TransferCmd cmd;
00035 
00037         QString origFilePath, destFilePath;
00038 
00043         MyTransfer(const QString &OrigFilePath, const QString &DestFilePath, TransferCmd Cmd)
00044         {
00045                 origFilePath = OrigFilePath;
00046                 destFilePath = DestFilePath;
00047                 cmd = Cmd;
00048                 id = -1;
00049         }
00050 
00052         inline void setId(int Id)
00053         {
00054                 id = Id;
00055         }
00056 
00058         inline int getId() const
00059         {
00060                 return id;
00061         }
00062 
00064         inline bool isInProgress() const
00065         {
00066                 return (id != -1);
00067         }
00068 
00070         bool operator== (const MyTransfer &t) const
00071         {
00072                 return (cmd==t.cmd && id==t.id && origFilePath==t.origFilePath && destFilePath==t.destFilePath);
00073         }
00074 
00076         inline QString fileName() const
00077         {
00078                 return QFileInfo(origFilePath).fileName();
00079         }
00080 
00082         inline QString transferType() const
00083         {
00084                 if (cmd == Download)
00085                         return "Download";
00086                 else
00087                         return "Upload";
00088         }
00089 };
00090 
00091 
00092 /*************************************************************************/
00094 
00101 /*************************************************************************/
00102 
00103 class MyFtpTransferControl : public QFtp
00104 {
00105         Q_OBJECT
00106 
00108         QList<MyTransfer> transferList;
00109 
00111         QFile file;
00112 
00114         bool autoLaunch;
00115 
00117         int doneOctet;
00118 
00120         int totalOctet;
00121 
00123         int progress;
00124 
00126         int totalSize;
00127 
00129         int vitesse;
00130 
00132         int temps;
00133 
00135         int sec;
00136 
00138         int min;
00139 
00141         QTimer tmpVitTimer;
00142 
00144         int koVitesseDone;
00145 
00146 public:
00148         MyFtpTransferControl ( QObject * parent = 0 );
00149 
00151         bool startTransfers();
00152 
00154         bool startTransfer(const MyTransfer &transfer);
00155 
00157         bool transferInProgress();
00158 
00160         void addTransfer(const MyTransfer &transfer);
00161 
00163         bool removeTransfer(int index);
00164 
00166         bool removeTransfer(const MyTransfer &transfer);
00167 
00169         void removeAllTransfers();
00170 
00172         bool moveTransfer(int from, int to);
00173 
00175         void setAutoLaunch(bool AutoLaunch);
00176 
00178         bool upTransfer(const MyTransfer &transfer);
00179 
00181         bool downTransfer(const MyTransfer &transfer);
00182 
00183 private slots:
00185         void slotCommandFinished(int id, bool error);
00186 
00188         void slotDataTransferProgress(qint64 done, qint64 total);
00189 
00192         void slotTmpVit();
00193 
00195         void slotTimerInit();
00196 
00198         void slotTimerDel();
00199 
00200 signals:
00202         void otherCommandFinished(int id, bool error);
00203 
00205         void downloadFinished(const QString &destPath, int id, bool error);
00206 
00208         void uploadFinished(const QString &destPath, int id, bool error);
00209 
00211         void transferListModified (const QList<MyTransfer> &transferList);
00212 
00215         void transferRapidityAndRemainTime(int vitesseInKoSec, int remainMin, int remainSec, float pourcentage);
00216 };
00217 
00218 #endif

Generated on Wed Jan 2 20:39:34 2008 for Scythia by  doxygen 1.5.4