00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef NNET_H
00012 #define NNET_H
00013
00014 #include <qstring.h>
00015 #include <qcstring.h>
00016 #include <qcache.h>
00017 #include <qdatetime.h>
00018 #include <qurlinfo.h>
00019 #include <qsocket.h>
00020 #include <qsocketdevice.h>
00021 #include "nhostinfo.h"
00022
00027 class NNet : public QObject
00028 {
00029 Q_OBJECT
00030 public:
00035 struct DirCache {
00036 QDateTime time;
00037 QCString dirListing;
00038 };
00039
00046 NNet( int id, QObject *parent = 0, const char *name = 0 );
00047
00051 virtual ~NNet();
00052
00054 enum logType {
00055 NERR=0,
00056 NINFO,
00057 NREPLY,
00058 NCOMMAND,
00059 NCUSTOM,
00060 NOTHER
00061 };
00063 enum errorType {
00064 ErrNo=0,
00065 ErrHostInvalid,
00066 ErrHostNotFound,
00067 ErrConnectionRefused,
00068 ErrNotConnected,
00069 ErrConnected,
00070 ErrSocketBusy,
00071 ErrFileSeek,
00072 ErrUnknown
00073 };
00075 enum Operations {
00076 OpList=0,
00077 OpGet,
00078 OpPut,
00079 OpCWD,
00080 OpFxp,
00081 OpRemove,
00082 OpRaw,
00083 OpIdle,
00084 OpConnecting,
00085 OpInvalid
00086 };
00087
00091 virtual const char* protocol() const = 0;
00092
00097 virtual const char* name() const { return protocol(); };
00098
00108 virtual int connectToHost(NHostInfo hInfo, bool batch = false) = 0;
00109
00120 virtual int sendRawCommand(QString command) = 0;
00121
00134 virtual int get(QString file, QString destfile, bool resume = false) = 0;
00135
00148 virtual int put(QString file, QString sourcefile, bool resume = false) = 0;
00149
00160 virtual int list() = 0;
00161
00171 virtual int cd(QString dir) = 0;
00172
00181 virtual int move(QString newname, QString oldname) = 0;
00182
00192 virtual int remove(QString name, bool recursive = false) = 0;
00193
00202 virtual int makedir(QString dir) = 0;
00203
00212 virtual int abort() = 0;
00213
00219 virtual const NHostInfo getHostInfo() const { return hostInfo; };
00220
00225 virtual bool isConnected() const { return commandReady; };
00226
00231 virtual int currentOperation() const { return currentOp; };
00232
00233 public slots:
00239 virtual int closeConnection() = 0;
00240
00241 signals:
00249 void log(int id, NNet::logType type, QString msg);
00250
00256 void connectionClosed(int id, NHostInfo hInfo);
00257
00263 void changedDirectory(int id, const QString& dirname);
00264
00270 void connected(int id, NHostInfo hInfo);
00271
00278 void transferProgress(int id, unsigned int current, unsigned int total);
00279
00288 void transferComplete(int id, bool finished, uint bytes, int time, double rate);
00289
00295 void directoryListing(int id, const QValueList<QUrlInfo> &dirList);
00296
00303 void loginComplete(int id);
00304
00305 protected:
00312 virtual QCString findDirCache(QString dir, int timeout = -1) const;
00313
00319 virtual void addDirCache(QString dir, QCString dirListing);
00320
00324 virtual void clearDirCache();
00325
00331 QString getAppSetting(QString setName, QString defVal = "") const;
00332
00338 int getAppSetting(QString setName, int defVal) const;
00339
00345 QString getProtSetting(QString setName, QString defVal = "") const;
00346
00352 int getProtSetting(QString setName, int defVal) const;
00353
00361 QString getHostSetting(QString setName, QString defVal = "") const;
00362
00370 int getHostSetting(QString setName, int defVal) const;
00371
00372 int _id;
00373 QSocket *commandSock;
00374 QSocket *dataSock;
00375 NHostInfo hostInfo;
00376 bool commandDelayedClose;
00377 bool dataDelayedClose;
00378 bool commandReady;
00379 bool expectedClose;
00380 bool _batch;
00381 QCString currentDirListing;
00382 Operations currentOp;
00383
00384 private:
00385 mutable QCache<DirCache> dirCache;
00386 };
00387
00388 #endif // NNET_H