src/PartDownloader.h

changeset 629
b75c6cce02e2
child 639
851634b85893
equal deleted inserted replaced
628:6b13e4c2e97b 629:b75c6cce02e2
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013, 2014 Santeri Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef LDFORGE_DOWNLOAD_H
20 #define LDFORGE_DOWNLOAD_H
21
22 #include <QDialog>
23 #include "Main.h"
24 #include "Types.h"
25
26 class LDDocument;
27 class QFile;
28 class PartDownloadRequest;
29 class Ui_DownloadFrom;
30 class QNetworkAccessManager;
31 class QNetworkRequest;
32 class QNetworkReply;
33 class QAbstractButton;
34
35 // =============================================================================
36 // -----------------------------------------------------------------------------
37 class PartDownloader : public QDialog
38 {
39 typedefs:
40 enum Source
41 {
42 PartsTracker,
43 CustomURL,
44 };
45
46 enum Button
47 {
48 Download,
49 Abort,
50 Close
51 };
52
53 enum TableColumn
54 {
55 PartLabelColumn,
56 ProgressColumn,
57 };
58
59 using RequestList = QList<PartDownloadRequest*>;
60
61 properties:
62 Q_OBJECT
63 PROPERTY (public, LDDocument*, PrimaryFile, NO_OPS, STOCK_WRITE)
64 PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE)
65 PROPERTY (private, Ui_DownloadFrom*, Interface, NO_OPS, STOCK_WRITE)
66 PROPERTY (private, QStringList, FilesToDownload, LIST_OPS, STOCK_WRITE)
67 PROPERTY (private, RequestList, Requests, LIST_OPS, STOCK_WRITE)
68 PROPERTY (private, QPushButton*, DownloadButton, NO_OPS, STOCK_WRITE)
69
70 public:
71 explicit PartDownloader (QWidget* parent = null);
72 virtual ~PartDownloader();
73
74 void downloadFile (QString dest, QString url, bool primary);
75 QPushButton* getButton (Button i);
76 QString getURL() const;
77 Source getSource() const;
78 void modifyDestination (QString& dest) const;
79
80 static QString getDownloadPath();
81 static void staticBegin();
82
83 public slots:
84 void buttonClicked (QAbstractButton* btn);
85 void checkIfFinished();
86 void sourceChanged (int i);
87 };
88
89 // =============================================================================
90 // -----------------------------------------------------------------------------
91 class PartDownloadRequest : public QObject
92 {
93 typedefs:
94 enum EState
95 {
96 ERequesting,
97 EDownloading,
98 EFinished,
99 EFailed,
100 };
101
102 properties:
103 Q_OBJECT
104 PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE)
105 PROPERTY (private, EState, State, NO_OPS, STOCK_WRITE)
106 PROPERTY (private, PartDownloader*, Prompt, NO_OPS, STOCK_WRITE)
107 PROPERTY (private, QString, URL, STR_OPS, STOCK_WRITE)
108 PROPERTY (private, QString, Destinaton, STR_OPS, STOCK_WRITE)
109 PROPERTY (private, QString, FilePath, STR_OPS, STOCK_WRITE)
110 PROPERTY (private, QNetworkAccessManager*, NAM, NO_OPS, STOCK_WRITE)
111 PROPERTY (private, QNetworkReply*, Reply, NO_OPS, STOCK_WRITE)
112 PROPERTY (private, bool, FirstUpdate, BOOL_OPS, STOCK_WRITE)
113 PROPERTY (private, int64, BytesRead, NUM_OPS, STOCK_WRITE)
114 PROPERTY (private, int64, BytesTotal, NUM_OPS, STOCK_WRITE)
115 PROPERTY (private, bool, Primary, BOOL_OPS, STOCK_WRITE)
116 PROPERTY (private, QFile*, FilePointer, NO_OPS, STOCK_WRITE)
117
118 public:
119 explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent);
120 PartDownloadRequest (const PartDownloadRequest&) = delete;
121 virtual ~PartDownloadRequest();
122 void updateToTable();
123 bool isFinished() const;
124
125 void operator= (const PartDownloadRequest&) = delete;
126
127 public slots:
128 void downloadFinished();
129 void readyRead();
130 void downloadProgress (qint64 recv, qint64 total);
131 void abort();
132 };
133
134 #endif // LDFORGE_DOWNLOAD_H

mercurial