--- a/src/download.h Thu Oct 03 18:07:06 2013 +0300 +++ b/src/download.h Thu Oct 03 20:56:20 2013 +0300 @@ -34,95 +34,94 @@ // ============================================================================= // ----------------------------------------------------------------------------- -class PartDownloader : public QDialog { - Q_OBJECT - PROPERTY (LDFile*, primaryFile, setPrimaryFile) - PROPERTY (bool, aborted, setAborted) - -public: - constexpr static const char* k_OfficialURL = "http://ldraw.org/library/official/", - *k_UnofficialURL = "http://ldraw.org/library/unofficial/"; - - enum Source { - PartsTracker, - CustomURL, - }; - - enum Button { - Download, - Abort, - Close - }; - - enum TableColumn { - PartLabelColumn, - 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 modifyDest (str& dest) const; - QPushButton* getButton (Button i); - static void k_download(); - -public slots: - void sourceChanged (int i); - void checkIfFinished(); - void buttonClicked (QAbstractButton* btn); - -protected: - Ui_DownloadFrom* ui; - friend class PartDownloadRequest; - -private: - List<str> m_filesToDownload; - List<PartDownloadRequest*> m_requests; - QPushButton* m_downloadButton; +class PartDownloader : public QDialog +{ Q_OBJECT + PROPERTY (LDFile*, primaryFile, setPrimaryFile) + PROPERTY (bool, aborted, setAborted) + + public: + constexpr static const char* k_UnofficialURL = "http://ldraw.org/library/unofficial/"; + + enum Source + { PartsTracker, + CustomURL, + }; + + enum Button + { Download, + Abort, + Close + }; + + enum TableColumn + { PartLabelColumn, + 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 modifyDest (str& dest) const; + QPushButton* getButton (Button i); + static void k_download(); + + public slots: + void sourceChanged (int i); + void checkIfFinished(); + void buttonClicked (QAbstractButton* btn); + + protected: + Ui_DownloadFrom* ui; + friend class PartDownloadRequest; + + private: + List<str> m_filesToDownload; + List<PartDownloadRequest*> m_requests; + QPushButton* m_downloadButton; }; // ============================================================================= // ----------------------------------------------------------------------------- -class PartDownloadRequest : public QObject { - Q_OBJECT +class PartDownloadRequest : public QObject +{ Q_OBJECT PROPERTY (int, tableRow, setTableRow) - -public: - enum State { - Requesting, - Downloading, - Finished, - Failed, - }; - - 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; - -public slots: - void downloadFinished(); - 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; + + public: + enum State + { Requesting, + Downloading, + Finished, + Failed, + }; + + 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; + + public slots: + void downloadFinished(); + 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 \ No newline at end of file +#endif // LDFORGE_DOWNLOAD_H