src/download.h

changeset 549
715d9a7f6598
parent 541
0e38beeb050a
child 553
2418d5955421
equal deleted inserted replaced
548:a99f41732cd2 549:715d9a7f6598
33 class QAbstractButton; 33 class QAbstractButton;
34 34
35 // ============================================================================= 35 // =============================================================================
36 // ----------------------------------------------------------------------------- 36 // -----------------------------------------------------------------------------
37 class PartDownloader : public QDialog 37 class PartDownloader : public QDialog
38 { Q_OBJECT 38 { typedefs:
39 PROPERTY (public, LDFile*, PrimaryFile, NO_OPS, STOCK_WRITE)
40 PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE)
41
42 public:
43 constexpr static const char* k_UnofficialURL = "http://ldraw.org/library/unofficial/";
44
45 enum Source 39 enum Source
46 { PartsTracker, 40 { PartsTracker,
47 CustomURL, 41 CustomURL,
48 }; 42 };
49 43
56 enum TableColumn 50 enum TableColumn
57 { PartLabelColumn, 51 { PartLabelColumn,
58 ProgressColumn, 52 ProgressColumn,
59 }; 53 };
60 54
61 explicit PartDownloader (QWidget* parent = null); 55 using RequestList = QList<PartDownloadRequest*>;
62 virtual ~PartDownloader(); 56
63 str getURL() const; 57 properties:
64 static str getDownloadPath(); 58 Q_OBJECT
65 Source getSource() const; 59 PROPERTY (public, LDFile*, PrimaryFile, NO_OPS, STOCK_WRITE)
66 void downloadFile (str dest, str url, bool primary); 60 PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE)
67 void modifyDestination (str& dest) const; 61 PROPERTY (private, Ui_DownloadFrom*, Interface, NO_OPS, STOCK_WRITE)
68 QPushButton* getButton (Button i); 62 PROPERTY (private, QStringList, FilesToDownload, LIST_OPS, STOCK_WRITE)
69 static void k_download(); 63 PROPERTY (private, RequestList, Requests, LIST_OPS, STOCK_WRITE)
64 PROPERTY (private, QPushButton*, DownloadButton, NO_OPS, STOCK_WRITE)
65
66 public methods:
67 explicit PartDownloader (QWidget* parent = null);
68 virtual ~PartDownloader();
69
70 void downloadFile (str dest, str url, bool primary);
71 QPushButton* getButton (Button i);
72 str getURL() const;
73 Source getSource() const;
74 void modifyDestination (str& dest) const;
75
76 static str getDownloadPath();
77 static void staticBegin();
70 78
71 public slots: 79 public slots:
72 void sourceChanged (int i); 80 void buttonClicked (QAbstractButton* btn);
73 void checkIfFinished(); 81 void checkIfFinished();
74 void buttonClicked (QAbstractButton* btn); 82 void sourceChanged (int i);
75
76 protected:
77 Ui_DownloadFrom* ui;
78 friend class PartDownloadRequest;
79
80 private:
81 QStringList m_filesToDownload;
82 QList<PartDownloadRequest*> m_requests;
83 QPushButton* m_downloadButton;
84 }; 83 };
85 84
86 // ============================================================================= 85 // =============================================================================
87 // ----------------------------------------------------------------------------- 86 // -----------------------------------------------------------------------------
88 class PartDownloadRequest : public QObject 87 class PartDownloadRequest : public QObject
89 { Q_OBJECT 88 { typedefs:
90 PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE) 89 enum EState
91 90 { ERequesting,
92 public: 91 EDownloading,
93 enum State 92 EFinished,
94 { Requesting, 93 EFailed,
95 Downloading,
96 Finished,
97 Failed,
98 }; 94 };
99 95
96 properties:
97 Q_OBJECT
98 PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE)
99 PROPERTY (private, EState, State, NO_OPS, STOCK_WRITE)
100 PROPERTY (private, PartDownloader*, Prompt, NO_OPS, STOCK_WRITE)
101 PROPERTY (private, str, URL, STR_OPS, STOCK_WRITE)
102 PROPERTY (private, str, Destinaton, STR_OPS, STOCK_WRITE)
103 PROPERTY (private, str, FilePath, STR_OPS, STOCK_WRITE)
104 PROPERTY (private, QNetworkAccessManager*, NAM, NO_OPS, STOCK_WRITE)
105 PROPERTY (private, QNetworkReply*, Reply, NO_OPS, STOCK_WRITE)
106 PROPERTY (private, bool, FirstUpdate, BOOL_OPS, STOCK_WRITE)
107 PROPERTY (private, int64, BytesRead, NUM_OPS, STOCK_WRITE)
108 PROPERTY (private, int64, BytesTotal, NUM_OPS, STOCK_WRITE)
109 PROPERTY (private, bool, Primary, BOOL_OPS, STOCK_WRITE)
110 PROPERTY (private, QFile*, FilePointer, NO_OPS, STOCK_WRITE)
111
112 public methods:
100 explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent); 113 explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent);
101 PartDownloadRequest (const PartDownloadRequest&) = delete; 114 PartDownloadRequest (const PartDownloadRequest&) = delete;
102 virtual ~PartDownloadRequest(); 115 virtual ~PartDownloadRequest();
103 void updateToTable(); 116 void updateToTable();
104 bool isFinished() const; 117 bool isFinished() const;
105 const State& state() const;
106 118
107 void operator= (const PartDownloadRequest&) = delete; 119 void operator= (const PartDownloadRequest&) = delete;
108 120
109 public slots: 121 public slots:
110 void downloadFinished(); 122 void downloadFinished();
111 void readyRead(); 123 void readyRead();
112 void downloadProgress (qint64 recv, qint64 total); 124 void downloadProgress (qint64 recv, qint64 total);
113 void abort(); 125 void abort();
114
115 private:
116 PartDownloader* m_prompt;
117 str m_url, m_dest, m_fpath;
118 QNetworkAccessManager* m_nam;
119 QNetworkReply* m_reply;
120 bool m_firstUpdate;
121 State m_state;
122 int64 m_bytesRead, m_bytesTotal;
123 bool m_primary;
124 QFile* m_fp;
125 }; 126 };
126 127
127 #endif // LDFORGE_DOWNLOAD_H 128 #endif // LDFORGE_DOWNLOAD_H

mercurial