00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef NQUEUE_H
00010 #define NQUEUE_H
00011
00012 #include "nhostinfo.h"
00013 #include "nnet.h"
00014
00015 #include <qlistview.h>
00016 #include <qurl.h>
00017 #include <qdatetime.h>
00018 #include <qmap.h>
00019 #include <qintdict.h>
00020 #include <qpopupmenu.h>
00021 #include <nqptrlist.h>
00022
00023 class NNet;
00024 class QUrlInfo;
00025
00031 class NQueueHost : public QListViewItem
00032 {
00033 public:
00035 NQueueHost( QListView *parent, int hostId, NHostInfo hostInfo);
00040 virtual ~NQueueHost();
00045 void dieNow();
00046
00048 virtual QString text( int c ) const;
00050 virtual const QPixmap* pixmap( int c ) const;
00052 virtual int rtti() const { return 2301; }
00053
00055 const int id() const { return _id; }
00057 const NHostInfo hostInfo() const { return _hostInfo; }
00063 const bool isDone() const { return _done; }
00069 const bool inUse() const { return _inuse; }
00074 const bool failed() const { return _failed; }
00076 const int numCurrentConns() const { return _currentConnections; }
00077
00081 inline void setInUse(bool s = true);
00086 inline void setDone(bool s = true);
00090 inline void setFailed(bool s = true) { _failed = s; }
00095 inline void incCurrentConns();
00100 inline void decCurrentConns();
00107 inline void setXferStats(uint size, int time, double rate)
00108 { _xferSize = size; _xferTime = time; _xferRate = rate; }
00112 void reset();
00118 void childDone(bool removed = false);
00123 void addChild();
00130 void childReset();
00139 void killChildren(int prune = 0);
00140
00141 private:
00142 int _id;
00143 NHostInfo _hostInfo;
00144 bool _inuse;
00145 bool _done;
00146 bool _failed;
00147 QDateTime _placementTime;
00148 QDateTime _startTime;
00149 QDateTime _finishTime;
00150 uint _xferSize;
00151 double _xferRate;
00152 int _xferTime;
00153 int _currentConnections;
00154 int childRemain;
00155 int childTotal;
00156 };
00157
00164 class NQueueItem : public QListViewItem
00165 {
00166 public:
00179 NQueueItem( QListViewItem *parent, int id,
00180 int hid, QUrl src, QString srcName,
00181 QUrl dst, QString dstName,
00182 uint size, bool dir = false);
00187 virtual ~NQueueItem();
00192 void dieNow();
00193
00195 virtual int compare( QListViewItem * i, int col, bool ascending ) const;
00197 virtual QString text( int c ) const;
00199 virtual const QPixmap* pixmap( int c ) const;
00201 virtual int rtti() const { return 2302; }
00202
00204 const int id() const { return _id; }
00206 const int hostid() const { return _hostid; }
00208 const QUrl source() const { return _source; }
00210 const QUrl dest() const { return _dest; }
00212 const QString sourceFileName() const { return _sourceName; }
00214 const QString destFileName() const { return _destName; }
00216 const uint size() const { return _totalSize; }
00218 const uint progress() const { return _currentSize; }
00220 const bool isDir() const { return _dir; }
00226 const bool isDone() const { return _done;; }
00231 const bool inUse() const { return _inuse; }
00236 const bool failed() const { return _failed; }
00244 const int whichRemote() const;
00245
00250 void totals(int *mytot, int *myrem);
00257 void childReset();
00266 void killChildren(int prune = 0);
00270 void setProgress(uint progress) { _currentSize = progress; }
00274 void setInUse(bool s = true);
00279 void setDone(bool s = true);
00284 void setFailed(bool s = true);
00291 void childDone(bool removed = false);
00297 void addChild();
00302 void reset(int *mytot = 0, int *myrem = 0);
00309 void setXferStats(uint size, int time, double rate)
00310 { _xferSize = size; _xferTime = time; _xferRate = rate; }
00311
00312 private:
00313 int _id;
00314 int _hostid;
00315 QUrl _source;
00316 QUrl _dest;
00317 QString _sourceName;
00318 QString _destName;
00319 uint _totalSize;
00320 uint _currentSize;
00321 bool _dir;
00322 bool _inuse;
00323 bool _done;
00324 bool _failed;
00325 QDateTime _placementTime;
00326 QDateTime _startTime;
00327 QDateTime _finishTime;
00328 uint _xferSize;
00329 double _xferRate;
00330 int _xferTime;
00331 int childRemain;
00332 int childTotal;
00333 };
00334
00340 class NQueue : public QListView
00341 {
00342 Q_OBJECT
00343 public:
00347 NQueue(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
00349 virtual ~NQueue();
00350
00352 enum Side { Left=0, Right, Other };
00354 void cd(Side side, QString path);
00356 void get(Side side, QString name, QString localname);
00358 void put(Side side, QString name, QString localname);
00366 void queue(const QUrl srcUrl, const QUrlInfo srcInfo, const QUrl dstUrl, const QString dstName);
00368 NNet *newNNet(Side side, QString protocol);
00370 void delNNet(Side side);
00371
00372 public slots:
00374 void startQueue();
00376 void stopQueue();
00378 void pauseQueue();
00379
00380 signals:
00382 void log(NNet::logType, QString);
00383
00384 private:
00385 int addObject(QString);
00386 void setupSlots(NQueue::Side, NNet *);
00387 int matchHostId(NHostInfo hostInfo, bool create = true);
00388 void scheduleItem(NQueueItem *item);
00389 void scheduleItemPool(NQueueItem *item);
00390 void scheduleItemGui(NQueueItem *item);
00391 void scheduleNextItem(int nnetId);
00392 NQPtrList selectedItems() const;
00393 int checkConnections(NHostInfo checkHost);
00394 void autoClear(QListViewItem *litem);
00395
00396 private slots:
00397 void scheduleNextItem(NQueueHost *nextHost = NULL);
00398 void slotConnected(int, NHostInfo);
00399 void slotConnectionClosed(int, NHostInfo);
00400 void slotDirectoryListing(int, const QValueList<QUrlInfo> &);
00401 void slotLoginComplete(int);
00402 void slotTransferProgress(int, unsigned int, unsigned int);
00403 void slotTransferComplete(int, bool, uint, int, double);
00404 void slotMenuItemActivated(int);
00405 void slotContextMenuRequested( QListViewItem *, const QPoint&, int );
00406 void slotLog(int, NNet::logType, QString);
00407
00408 private:
00409 NNet *leftNNet, *rightNNet;
00410
00411 int lastId;
00412 int nnetId;
00413 int hostId;
00414 QIntDict<NNet> objList;
00415 QIntDict<NQueueHost> hostDict;
00416 QIntDict<NQueueItem> itemDict;
00417 QMap<int, int> queueMap;
00418 QMap< int, QValueList<int> > hostMap;
00419 QPopupMenu *context;
00420 int numXfered;
00421 int numInUse;
00422 unsigned long totalSizeXfered;
00423 QDateTime queueStart;
00424 bool inProgress;
00425 int currConns;
00426
00427 friend class NQueueItem;
00428 friend class NQueueHost;
00429
00430 enum MenuIds {
00431 Remove=0,
00432 Reset,
00433 Prune,
00434 Clear,
00435 Start
00436 };
00437 };
00438
00439 #endif // NQUEUE_H