src/partDownloader.h

Wed, 03 Sep 2014 01:44:51 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 03 Sep 2014 01:44:51 +0300
changeset 876
f040f0fb3795
parent 867
557cb07dbe57
child 888
7ad8fb667084
permissions
-rw-r--r--

- renamed line loop to line path, updated changelog

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
844
11587d419d2f - changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents: 839
diff changeset
3 * Copyright (C) 2013, 2014 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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 class PartDownloader : public QDialog
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
38 public:
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
39 enum Source
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
40 {
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
41 PartsTracker,
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
42 CustomURL,
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
43 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
45 enum Button
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
46 {
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
47 Download,
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
48 Abort,
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
49 Close
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
50 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
52 enum TableColumn
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
53 {
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
54 PartLabelColumn,
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
55 ProgressColumn,
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
56 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
58 using RequestList = QList<PartDownloadRequest*>;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
60 Q_OBJECT
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
61 PROPERTY (public, LDDocumentPtr, primaryFile, setPrimaryFile, STOCK_WRITE)
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
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
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
64 PROPERTY (private, QStringList, filesToDownload, setFilesToDownload, STOCK_WRITE)
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
65 PROPERTY (private, RequestList, requests, setRequests, STOCK_WRITE)
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
66 PROPERTY (private, QPushButton*, downloadButton, setDownloadButton, STOCK_WRITE)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
68 public:
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
69 explicit PartDownloader (QWidget* parent = null);
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
70 virtual ~PartDownloader();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
72 void addFile (LDDocumentPtr f);
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
73 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
74 void downloadFromPartsTracker (QString file);
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
75 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
76 QString getURL();
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
77 Source getSource() const;
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
78 void setSource (Source src);
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
79 void modifyDestination (QString& dest) const;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
81 static QString getDownloadPath();
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
82 static void staticBegin();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
84 public slots:
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
85 void buttonClicked (QAbstractButton* btn);
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
86 void checkIfFinished();
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
87 void sourceChanged (int i);
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
88
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
89 private:
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
90 Source m_source;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
91 QList<LDDocumentPtr> m_files;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 };
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 class PartDownloadRequest : public QObject
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 {
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
98 public:
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
99 enum class State
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
100 {
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
101 Requesting,
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
102 Downloading,
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
103 Finished,
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
104 Failed,
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
105 };
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
106
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
107 Q_OBJECT
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
108 PROPERTY (public, int, tableRow, setTableRow, STOCK_WRITE)
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
109 PROPERTY (private, State, state, setState, STOCK_WRITE)
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
110 PROPERTY (private, PartDownloader*, prompt, setPrompt, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
111 PROPERTY (private, QString, url, setURL, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
112 PROPERTY (private, QString, destinaton, setDestination, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
113 PROPERTY (private, QString, filePath, setFilePath, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
114 PROPERTY (private, QNetworkAccessManager*, networkManager, setNetworkManager, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
115 PROPERTY (private, QNetworkReply*, networkReply, setNetworkReply, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
116 PROPERTY (private, bool, isFirstUpdate, setFirstUpdate, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
117 PROPERTY (private, int64, numBytesRead, setNumBytesRead, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
118 PROPERTY (private, int64, numBytesTotal, setNumBytesTotal, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
119 PROPERTY (private, bool, isPrimary, setPrimary, STOCK_WRITE)
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
120 PROPERTY (private, QFile*, filePointer, setFilePointer, STOCK_WRITE)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
122 public:
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
123 explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent);
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
124 PartDownloadRequest (const PartDownloadRequest&) = delete;
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
125 virtual ~PartDownloadRequest();
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
126 void updateToTable();
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
127 bool isFinished() const;
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
128 void operator= (const PartDownloadRequest&) = delete;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
130 public slots:
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
131 void downloadFinished();
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
132 void readyRead();
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
133 void downloadProgress (qint64 recv, qint64 total);
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
134 void abort();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 };

mercurial