--- a/src/download.h Fri Dec 06 21:30:58 2013 +0200 +++ b/src/download.h Sat Dec 07 00:01:20 2013 +0200 @@ -35,13 +35,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- class PartDownloader : public QDialog -{ Q_OBJECT - PROPERTY (public, LDFile*, PrimaryFile, NO_OPS, STOCK_WRITE) - PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE) - - public: - constexpr static const char* k_UnofficialURL = "http://ldraw.org/library/unofficial/"; - +{ typedefs: enum Source { PartsTracker, CustomURL, @@ -58,51 +52,69 @@ ProgressColumn, }; - explicit PartDownloader (QWidget* parent = null); - virtual ~PartDownloader(); - str getURL() const; - static str getDownloadPath(); - Source getSource() const; - void downloadFile (str dest, str url, bool primary); - void modifyDestination (str& dest) const; - QPushButton* getButton (Button i); - static void k_download(); + using RequestList = QList<PartDownloadRequest*>; + + properties: + Q_OBJECT + PROPERTY (public, LDFile*, PrimaryFile, NO_OPS, STOCK_WRITE) + PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE) + PROPERTY (private, Ui_DownloadFrom*, Interface, NO_OPS, STOCK_WRITE) + PROPERTY (private, QStringList, FilesToDownload, LIST_OPS, STOCK_WRITE) + PROPERTY (private, RequestList, Requests, LIST_OPS, STOCK_WRITE) + PROPERTY (private, QPushButton*, DownloadButton, NO_OPS, STOCK_WRITE) + + public methods: + explicit PartDownloader (QWidget* parent = null); + virtual ~PartDownloader(); + + void downloadFile (str dest, str url, bool primary); + QPushButton* getButton (Button i); + str getURL() const; + Source getSource() const; + void modifyDestination (str& dest) const; + + static str getDownloadPath(); + static void staticBegin(); public slots: - void sourceChanged (int i); - void checkIfFinished(); - void buttonClicked (QAbstractButton* btn); - - protected: - Ui_DownloadFrom* ui; - friend class PartDownloadRequest; - - private: - QStringList m_filesToDownload; - QList<PartDownloadRequest*> m_requests; - QPushButton* m_downloadButton; + void buttonClicked (QAbstractButton* btn); + void checkIfFinished(); + void sourceChanged (int i); }; // ============================================================================= // ----------------------------------------------------------------------------- class PartDownloadRequest : public QObject -{ Q_OBJECT - PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE) - - public: - enum State - { Requesting, - Downloading, - Finished, - Failed, +{ typedefs: + enum EState + { ERequesting, + EDownloading, + EFinished, + EFailed, }; + properties: + Q_OBJECT + PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE) + PROPERTY (private, EState, State, NO_OPS, STOCK_WRITE) + PROPERTY (private, PartDownloader*, Prompt, NO_OPS, STOCK_WRITE) + PROPERTY (private, str, URL, STR_OPS, STOCK_WRITE) + PROPERTY (private, str, Destinaton, STR_OPS, STOCK_WRITE) + PROPERTY (private, str, FilePath, STR_OPS, STOCK_WRITE) + PROPERTY (private, QNetworkAccessManager*, NAM, NO_OPS, STOCK_WRITE) + PROPERTY (private, QNetworkReply*, Reply, NO_OPS, STOCK_WRITE) + PROPERTY (private, bool, FirstUpdate, BOOL_OPS, STOCK_WRITE) + PROPERTY (private, int64, BytesRead, NUM_OPS, STOCK_WRITE) + PROPERTY (private, int64, BytesTotal, NUM_OPS, STOCK_WRITE) + PROPERTY (private, bool, Primary, BOOL_OPS, STOCK_WRITE) + PROPERTY (private, QFile*, FilePointer, NO_OPS, STOCK_WRITE) + + public methods: explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent); PartDownloadRequest (const PartDownloadRequest&) = delete; virtual ~PartDownloadRequest(); void updateToTable(); bool isFinished() const; - const State& state() const; void operator= (const PartDownloadRequest&) = delete; @@ -111,17 +123,6 @@ void readyRead(); void downloadProgress (qint64 recv, qint64 total); void abort(); - - private: - PartDownloader* m_prompt; - str m_url, m_dest, m_fpath; - QNetworkAccessManager* m_nam; - QNetworkReply* m_reply; - bool m_firstUpdate; - State m_state; - int64 m_bytesRead, m_bytesTotal; - bool m_primary; - QFile* m_fp; }; #endif // LDFORGE_DOWNLOAD_H