src/download.h

Fri, 02 Aug 2013 22:36:51 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 02 Aug 2013 22:36:51 +0300
changeset 428
53e577061dc8
parent 427
d308149fbc90
child 429
3488534b2b31
permissions
-rw-r--r--

handle errors

426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #ifndef LDFORGE_DOWNLOAD_H
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #define LDFORGE_DOWNLOAD_H
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QDialog>
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "common.h"
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
24 #include "types.h"
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 class Ui_DownloadFrom;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 class QNetworkAccessManager;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 class QNetworkRequest;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 class QNetworkReply;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 // -----------------------------------------------------------------------------
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 extern class PartDownloader {
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 public:
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 constexpr static const char* k_OfficialURL = "http://ldraw.org/library/official/",
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 *k_UnofficialURL = "http://ldraw.org/library/unofficial/";
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 PartDownloader() {}
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 void download();
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 void operator()() { download(); }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 } g_PartDownloader;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 // -----------------------------------------------------------------------------
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 class PartDownloadPrompt : public QDialog {
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 Q_OBJECT
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 public:
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 enum Source {
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
50 /* OfficialLibrary,
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
51 */ PartsTracker,
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 CustomURL,
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 };
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 explicit PartDownloadPrompt (QWidget* parent = null);
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 virtual ~PartDownloadPrompt();
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
57 str getURL() const;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
58 str fullFilePath() const;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
59 str getDest() const;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
60 Source getSource() const;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 public slots:
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 void sourceChanged (int i);
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 void startDownload();
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 protected:
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 Ui_DownloadFrom* ui;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 friend class PartDownloadRequest;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 };
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 // -----------------------------------------------------------------------------
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 class PartDownloadRequest : public QObject {
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
74 Q_OBJECT
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 PROPERTY (int, tableRow, setTableRow)
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 public:
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
78 enum TableColumn {
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
79 PartLabelColumn,
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
80 ProgressColumn,
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
81 };
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
82
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
83 enum State {
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
84 Requesting,
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
85 Downloading,
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
86 Finished,
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
87 Error,
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
88 Aborted,
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
89 };
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
90
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
91 explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloadPrompt* parent);
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
92 PartDownloadRequest (const PartDownloadRequest&) = delete;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
93 virtual ~PartDownloadRequest();
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 void updateToTable();
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
96 void operator= (const PartDownloadRequest&) = delete;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
97
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
98 public slots:
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
99 void downloadFinished();
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
100 void readyRead();
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
101 void downloadProgress (qint64 recv, qint64 total);
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
102 void downloadError();
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
103
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 private:
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 PartDownloadPrompt* m_prompt;
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
106 str m_url, m_dest, m_fpath;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 QNetworkAccessManager* m_nam;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 QNetworkReply* m_reply;
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
109 bool m_firstUpdate;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
110 State m_state;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
111 int64 m_bytesRead, m_bytesTotal;
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
112 bool m_primary;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 };
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 #endif // LDFORGE_DOWNLOAD_H

mercurial