Sun, 06 Sep 2015 16:08:22 +0300
Refactor PartDownloadRequest
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
968 | 3 | * Copyright (C) 2013 - 2015 Teemu Piippo |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #pragma once |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QDialog> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "main.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "basics.h" |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
23 | #include "ldDocument.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | class LDDocument; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | class QFile; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | class PartDownloadRequest; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | class Ui_DownloadFrom; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | class QNetworkAccessManager; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | class QNetworkRequest; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | class QNetworkReply; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | class QAbstractButton; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | // |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
36 | class PartDownloader : public QDialog, public HierarchyElement |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
794 | 38 | public: |
39 | enum Source | |
40 | { | |
41 | PartsTracker, | |
42 | CustomURL, | |
43 | }; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | |
794 | 45 | enum Button |
46 | { | |
47 | Download, | |
48 | Abort, | |
49 | Close | |
50 | }; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
794 | 52 | enum TableColumn |
53 | { | |
54 | PartLabelColumn, | |
55 | ProgressColumn, | |
56 | }; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
794 | 58 | using RequestList = QList<PartDownloadRequest*>; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
794 | 60 | Q_OBJECT |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
888
diff
changeset
|
61 | PROPERTY (public, LDDocument*, primaryFile, setPrimaryFile, STOCK_WRITE) |
794 | 62 | PROPERTY (public, bool, isAborted, setAborted, STOCK_WRITE) |
855
e16f1587ef44
- fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
63 | PROPERTY (private, Ui_DownloadFrom*, form, setForm, STOCK_WRITE) |
794 | 64 | PROPERTY (private, QStringList, filesToDownload, setFilesToDownload, STOCK_WRITE) |
65 | PROPERTY (private, RequestList, requests, setRequests, STOCK_WRITE) | |
66 | PROPERTY (private, QPushButton*, downloadButton, setDownloadButton, STOCK_WRITE) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
794 | 68 | public: |
984 | 69 | explicit PartDownloader (QWidget* parent = nullptr); |
794 | 70 | virtual ~PartDownloader(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
888
diff
changeset
|
72 | void addFile (LDDocument* f); |
888
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
867
diff
changeset
|
73 | bool checkValidPath(); |
794 | 74 | void downloadFile (QString dest, QString url, bool primary); |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
75 | void downloadFromPartsTracker (QString file); |
794 | 76 | QPushButton* getButton (Button i); |
839
5f822ad61875
- part downloader: update the input widget with the corrected part name when guesswork is done
Teemu Piippo <crimsondusk64@gmail.com>
parents:
814
diff
changeset
|
77 | QString getURL(); |
794 | 78 | Source getSource() const; |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
79 | void setSource (Source src); |
794 | 80 | void modifyDestination (QString& dest) const; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
82 | QString getDownloadPath(); |
794 | 83 | static void staticBegin(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
794 | 85 | public slots: |
86 | void buttonClicked (QAbstractButton* btn); | |
87 | void checkIfFinished(); | |
88 | void sourceChanged (int i); | |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
89 | |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
90 | private: |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
91 | Source m_source; |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
888
diff
changeset
|
92 | QList<LDDocument*> m_files; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | class PartDownloadRequest : public QObject |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | { |
814
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
97 | Q_OBJECT |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
814
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
99 | public: |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
100 | enum class State |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
101 | { |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
102 | Requesting, |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
103 | Downloading, |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
104 | Finished, |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
105 | Failed, |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
106 | }; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
107 | |
814
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
108 | explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent); |
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
109 | virtual ~PartDownloadRequest(); |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
110 | |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
111 | QString destination() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
112 | bool failed() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
113 | QString filePath() const; |
814
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
114 | bool isFinished() const; |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
115 | bool isFirstUpdate() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
116 | bool isPrimary() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
117 | QNetworkReply* networkReply() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
118 | qint64 numBytesRead() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
119 | qint64 numBytesTotal() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
120 | PartDownloader* prompt() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
121 | void setTableRow (int value); |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
122 | int tableRow() const; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
123 | void updateToTable(); |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
124 | QString url() const; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
814
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
126 | public slots: |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
127 | void abort(); |
814
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
128 | void downloadFinished(); |
c8ef30fd0e54
- refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents:
794
diff
changeset
|
129 | void downloadProgress (qint64 recv, qint64 total); |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
130 | void readyRead(); |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
131 | |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
132 | private: |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
133 | int m_tableRow; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
134 | State m_state; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
135 | PartDownloader* m_prompt; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
136 | QString m_url; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
137 | QString m_destination; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
138 | QString m_filePath; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
139 | QNetworkAccessManager* m_networkManager; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
140 | QNetworkReply* m_networkReply; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
141 | bool m_isFirstUpdate; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
142 | bool m_isPrimary; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
143 | qint64 m_numBytesRead; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
144 | qint64 m_numBytesTotal; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
145 | QFile* m_filePointer; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | }; |