src/download.h

Thu, 05 Dec 2013 13:51:52 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 05 Dec 2013 13:51:52 +0200
changeset 538
2f85d4d286e5
parent 504
6a1fa662bfc1
child 539
72ad83a67165
permissions
-rw-r--r--

- ensured header files' guards start with LDFORGE_
- removed typedef "qchar" (use QChar instead), removed use of short, long and size_t (use int instead)
- use C++11-using syntax instead of typedefs in types.h

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
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
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.
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
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.
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
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
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
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 class Ui_DownloadFrom;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 class QNetworkAccessManager;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 class QNetworkRequest;
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 class QNetworkReply;
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
33 class QAbstractButton;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
37 class PartDownloader : public QDialog
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
38 { Q_OBJECT
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
39 PROPERTY (LDFile*, primaryFile, setPrimaryFile)
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
40 PROPERTY (bool, aborted, setAborted)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
41
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
42 public:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
43 constexpr static const char* k_UnofficialURL = "http://ldraw.org/library/unofficial/";
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
44
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
45 enum Source
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
46 { PartsTracker,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
47 CustomURL,
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 Button
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
51 { Download,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
52 Abort,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
53 Close
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
54 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
55
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
56 enum TableColumn
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
57 { PartLabelColumn,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
58 ProgressColumn,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
59 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
60
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
61 explicit PartDownloader (QWidget* parent = null);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
62 virtual ~PartDownloader();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
63 str getURL() const;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
64 static str getDownloadPath();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
65 Source getSource() const;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
66 void downloadFile (str dest, str url, bool primary);
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
67 void modifyDestination (str& dest) const;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
68 QPushButton* getButton (Button i);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
69 static void k_download();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
70
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
71 public slots:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
72 void sourceChanged (int i);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
73 void checkIfFinished();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
74 void buttonClicked (QAbstractButton* btn);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
75
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
76 protected:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
77 Ui_DownloadFrom* ui;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
78 friend class PartDownloadRequest;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
79
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
80 private:
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
81 QStringList m_filesToDownload;
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
82 QList<PartDownloadRequest*> m_requests;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
83 QPushButton* m_downloadButton;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 };
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
88 class PartDownloadRequest : public QObject
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
89 { Q_OBJECT
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 PROPERTY (int, tableRow, setTableRow)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
91
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
92 public:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
93 enum State
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
94 { Requesting,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
95 Downloading,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
96 Finished,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
97 Failed,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
98 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
99
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
100 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
101 PartDownloadRequest (const PartDownloadRequest&) = delete;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
102 virtual ~PartDownloadRequest();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
103 void updateToTable();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
104 bool isFinished() const;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
105 const State& state() const;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
106
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
107 void operator= (const PartDownloadRequest&) = delete;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
108
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
109 public slots:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
110 void downloadFinished();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
111 void readyRead();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
112 void downloadProgress (qint64 recv, qint64 total);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
113 void abort();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
114
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
115 private:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
116 PartDownloader* m_prompt;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
117 str m_url, m_dest, m_fpath;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
118 QNetworkAccessManager* m_nam;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
119 QNetworkReply* m_reply;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
120 bool m_firstUpdate;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
121 State m_state;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
122 int64 m_bytesRead, m_bytesTotal;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
123 bool m_primary;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
124 QFile* m_fp;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 };
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
127 #endif // LDFORGE_DOWNLOAD_H

mercurial