1 #ifndef FTPTHREAD_H 2 #define FTPTHREAD_H 3 4 #include "ftpevents.h" 5 6 #include <QObject> 7 #include <QEvent> 8 #include <QTimer> 9 #include <QThread> 10 11 #include "qftp.h" 12 13 #define FTPTIMEOUTTIME 12000 14 15 class QFtp; 16 class QFile; 17 18 enum eftpError {FTPOK,FTPERROR,FTPTIMEOUT}; 19 20 class ftpThread : public QObject 21 { 22 Q_OBJECT 23 public: 24 explicit ftpThread(QString id); 25 ~ftpThread(); 26 27 void setHostParams(QString tHost, int tPort, QString tUser, QString tPasswd, QString tDirectory); 28 public slots: 29 // void slotStart(); 30 void customEvent( QEvent * ev ); getList()31 QList <QUrlInfo> getList() 32 { 33 return listingResults; 34 } 35 void disconnectFtp(); 36 37 private slots: 38 void slotInit(); 39 void slotTimeout(); 40 void slotDisconnect(); 41 void slotCommandStarted(int); 42 void slotCommandFinished(int,bool); 43 void slotDone(bool); 44 void slotStateChanged(int state); 45 void slotListInfo(const QUrlInfo &); 46 void slotRawCommandReply(int, const QString &); 47 void slotProgress(qint64,qint64); 48 49 signals: 50 void finished(); 51 void commandsDone(int error,QString errorStr); 52 void listingComplete(bool err); 53 void downloadFinished(bool err,QString fn); 54 void ftpQuit(); 55 56 private: 57 QString idName; 58 bool canCloseWhenDone; 59 bool displayProgress; 60 QFtp *qftpPtr; 61 62 void setupConnection(QString tHost,int tPort,QString tUser,QString tPasswd,QString tDirectory); 63 void destroy(); 64 void doConnect(); 65 void connectToHost(); 66 void changePath( const QString &newPath ); 67 int listFiles(QString mask); 68 void uploadFile(QString source, QString destination); 69 void downloadFile(QString source, QString destination); 70 void rename(QString source, QString destination); 71 void remove(QString source); 72 void wait(int timeout); 73 74 QString host; 75 int port; 76 QString user; 77 QString passwd; 78 QString directory; 79 QString source; 80 QString destination; 81 82 bool ftpDone; 83 bool connectPending; 84 bool ftpCommandSuccess; 85 bool aborting; 86 bool stopThread; 87 88 QTimer *timeoutTimerPtr; 89 QTimer *disconnectTimerPtr; 90 QTimer *notifyTimerPtr; 91 92 bool timeoutExpired; 93 int timeoutValue; 94 95 // void slotStateChanged( int ); 96 void dumpState( int state ); 97 98 99 bool isLoggedIn(); 100 bool isUnconnected(); 101 bool isBusy(); 102 103 104 // void execFTPTest(); 105 106 eftpError lastError; 107 QString lastErrorStr; 108 QFile *sourceFn; 109 QFile *destFn; 110 QList <QUrlInfo> listingResults; 111 bool removeFiles; 112 }; 113 114 #endif // FTPTHREAD_H 115