00001 #ifndef FILETRANSFERLIST_H 00002 #define FILETRANSFERLIST_H 00003 00004 #include <QMutex> 00005 #include <QList> 00006 #include <QHash> 00007 #include <QThread> 00008 00009 #include "filetransfer.h" 00010 00012 class FileTransferProcessingThread : public QThread 00013 { 00014 Q_OBJECT 00015 private: 00016 bool m_terminate; 00017 bool m_pause; 00018 public: 00020 FileTransferProcessingThread(); 00021 00023 void shutdown(); 00024 00026 void pause(); 00027 00029 void resume(); 00030 00031 private: 00032 void run(); 00033 }; 00034 00036 class FileTransferList : public QObject 00037 { 00038 Q_OBJECT 00039 private: 00040 QList<FileTransfer*> m_transferList; 00041 QList<FileTransfer*> m_activeTransferList; 00042 QHash<QString, FileTransfer*> m_transferDict; 00043 QHash<QString, FileTransfer*> m_activeTransferDict; 00044 FileTransferProcessingThread* m_fileProcessingThread; 00045 QMutex m_accessMutex; 00046 int m_maxTransfers; 00047 public: 00049 static FileTransferList* instance() 00050 { 00051 static QMutex mutex; 00052 if (!m_instance) 00053 { 00054 mutex.lock(); 00055 00056 if (!m_instance) 00057 m_instance = new FileTransferList; 00058 00059 mutex.unlock(); 00060 } 00061 00062 return m_instance; 00063 } 00064 00066 static void drop() 00067 { 00068 static QMutex mutex; 00069 mutex.lock(); 00070 delete m_instance; 00071 m_instance = 0; 00072 mutex.unlock(); 00073 } 00074 00076 00080 void processTransfers(); 00081 00083 void setProcessingThread(FileTransferProcessingThread* processingThread); 00084 00086 void addTransfer(FileTransfer* fileTransfer); 00087 00089 void removeTransfer(FileTransfer* fileTransfer); 00090 00092 00096 FileTransfer* getTransfer(int i); 00097 00099 int getTransferCount(); 00100 00102 00107 FileTransfer* getTransfer(QString id); 00108 00110 00114 void cancelAllTransfers(); 00115 00117 00124 void updateStatus(QString id, unsigned long transferred, unsigned long totalSize); 00125 00127 00131 void pauseProcessing(); 00132 00134 00137 void resumeProcessing(); 00138 00139 private: 00141 FileTransferList(); 00142 00143 FileTransferList(const FileTransferList &); // hide copy constructor 00144 FileTransferList& operator=(const FileTransferList &); // hide assign op 00145 // we leave just the declarations, so the compiler will warn us 00146 // if we try to use those two functions by accident 00147 00148 static FileTransferList* m_instance; 00149 00150 Q_SIGNALS: 00152 void onUpdateStatus(QString id); 00153 00155 void onAddTransfer(QString id); 00156 00158 void onRemoveTransfer(QString id); 00159 }; 00160 00161 #endif // FILETRANSFERLIST_H