Sat, 07 Dec 2013 00:01:20 +0200
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
426 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 Santeri Piippo | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
435
diff
changeset
|
4 | * |
426 | 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. | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
435
diff
changeset
|
9 | * |
426 | 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. | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
435
diff
changeset
|
14 | * |
426 | 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> | |
541
0e38beeb050a
- Renamed common.h to main.h, split the PROPERTY macro and supporting macros to property.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
540
diff
changeset
|
23 | #include "main.h" |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
24 | #include "types.h" |
426 | 25 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
26 | class LDFile; |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
27 | class QFile; |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
28 | class PartDownloadRequest; |
426 | 29 | class Ui_DownloadFrom; |
30 | class QNetworkAccessManager; | |
31 | class QNetworkRequest; | |
32 | class QNetworkReply; | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
33 | class QAbstractButton; |
426 | 34 | |
35 | // ============================================================================= | |
36 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
37 | class PartDownloader : public QDialog |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
38 | { typedefs: |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
39 | enum Source |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
40 | { PartsTracker, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
41 | CustomURL, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
42 | }; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
43 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
44 | enum Button |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
45 | { Download, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
46 | Abort, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
47 | Close |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
48 | }; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
49 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
50 | enum TableColumn |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
51 | { PartLabelColumn, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
52 | ProgressColumn, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
53 | }; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
54 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
55 | using RequestList = QList<PartDownloadRequest*>; |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
56 | |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
57 | properties: |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
58 | Q_OBJECT |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
59 | PROPERTY (public, LDFile*, PrimaryFile, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
60 | PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
61 | PROPERTY (private, Ui_DownloadFrom*, Interface, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
62 | PROPERTY (private, QStringList, FilesToDownload, LIST_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
63 | PROPERTY (private, RequestList, Requests, LIST_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
64 | PROPERTY (private, QPushButton*, DownloadButton, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
65 | |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
66 | public methods: |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
67 | explicit PartDownloader (QWidget* parent = null); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
68 | virtual ~PartDownloader(); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
69 | |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
70 | void downloadFile (str dest, str url, bool primary); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
71 | QPushButton* getButton (Button i); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
72 | str getURL() const; |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
73 | Source getSource() const; |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
74 | void modifyDestination (str& dest) const; |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
75 | |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
76 | static str getDownloadPath(); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
77 | static void staticBegin(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
78 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
79 | public slots: |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
80 | void buttonClicked (QAbstractButton* btn); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
81 | void checkIfFinished(); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
82 | void sourceChanged (int i); |
426 | 83 | }; |
84 | ||
85 | // ============================================================================= | |
86 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
87 | class PartDownloadRequest : public QObject |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
88 | { typedefs: |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
89 | enum EState |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
90 | { ERequesting, |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
91 | EDownloading, |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
92 | EFinished, |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
93 | EFailed, |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
94 | }; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
95 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
96 | properties: |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
97 | Q_OBJECT |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
98 | PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
99 | PROPERTY (private, EState, State, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
100 | PROPERTY (private, PartDownloader*, Prompt, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
101 | PROPERTY (private, str, URL, STR_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
102 | PROPERTY (private, str, Destinaton, STR_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
103 | PROPERTY (private, str, FilePath, STR_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
104 | PROPERTY (private, QNetworkAccessManager*, NAM, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
105 | PROPERTY (private, QNetworkReply*, Reply, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
106 | PROPERTY (private, bool, FirstUpdate, BOOL_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
107 | PROPERTY (private, int64, BytesRead, NUM_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
108 | PROPERTY (private, int64, BytesTotal, NUM_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
109 | PROPERTY (private, bool, Primary, BOOL_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
110 | PROPERTY (private, QFile*, FilePointer, NO_OPS, STOCK_WRITE) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
111 | |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
541
diff
changeset
|
112 | public methods: |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
113 | explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
114 | PartDownloadRequest (const PartDownloadRequest&) = delete; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
115 | virtual ~PartDownloadRequest(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
116 | void updateToTable(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
117 | bool isFinished() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
118 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
119 | void operator= (const PartDownloadRequest&) = delete; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
120 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
121 | public slots: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
122 | void downloadFinished(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
123 | void readyRead(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
124 | void downloadProgress (qint64 recv, qint64 total); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
125 | void abort(); |
426 | 126 | }; |
127 | ||
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
128 | #endif // LDFORGE_DOWNLOAD_H |