src/PartDownloader.h

Sun, 23 Feb 2014 18:49:24 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 23 Feb 2014 18:49:24 +0200
changeset 684
8a56b1d4d44d
parent 629
b75c6cce02e2
child 639
851634b85893
permissions
-rw-r--r--

- greatly improved the GL compiler, now deals colors and object removal properly

629
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #ifndef LDFORGE_DOWNLOAD_H
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #define LDFORGE_DOWNLOAD_H
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QDialog>
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "Main.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "Types.h"
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 class LDDocument;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 class QFile;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 class PartDownloadRequest;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 class Ui_DownloadFrom;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 class QNetworkAccessManager;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 class QNetworkRequest;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 class QNetworkReply;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 class QAbstractButton;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 // =============================================================================
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 // -----------------------------------------------------------------------------
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 class PartDownloader : public QDialog
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 typedefs:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 enum Source
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 PartsTracker,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 CustomURL,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 };
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 enum Button
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 Download,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 Abort,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 Close
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 };
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 enum TableColumn
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 PartLabelColumn,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 ProgressColumn,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 };
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 using RequestList = QList<PartDownloadRequest*>;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 properties:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 Q_OBJECT
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 PROPERTY (public, LDDocument*, PrimaryFile, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 PROPERTY (private, Ui_DownloadFrom*, Interface, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 PROPERTY (private, QStringList, FilesToDownload, LIST_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 PROPERTY (private, RequestList, Requests, LIST_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 PROPERTY (private, QPushButton*, DownloadButton, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 public:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 explicit PartDownloader (QWidget* parent = null);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 virtual ~PartDownloader();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 void downloadFile (QString dest, QString url, bool primary);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 QPushButton* getButton (Button i);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 QString getURL() const;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 Source getSource() const;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 void modifyDestination (QString& dest) const;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 static QString getDownloadPath();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 static void staticBegin();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 public slots:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 void buttonClicked (QAbstractButton* btn);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 void checkIfFinished();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 void sourceChanged (int i);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 };
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 // =============================================================================
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 // -----------------------------------------------------------------------------
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 class PartDownloadRequest : public QObject
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 typedefs:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 enum EState
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 {
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 ERequesting,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 EDownloading,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 EFinished,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 EFailed,
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 };
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 properties:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 Q_OBJECT
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 PROPERTY (private, EState, State, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 PROPERTY (private, PartDownloader*, Prompt, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 PROPERTY (private, QString, URL, STR_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 PROPERTY (private, QString, Destinaton, STR_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 PROPERTY (private, QString, FilePath, STR_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 PROPERTY (private, QNetworkAccessManager*, NAM, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 PROPERTY (private, QNetworkReply*, Reply, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 PROPERTY (private, bool, FirstUpdate, BOOL_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 PROPERTY (private, int64, BytesRead, NUM_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 PROPERTY (private, int64, BytesTotal, NUM_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 PROPERTY (private, bool, Primary, BOOL_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 PROPERTY (private, QFile*, FilePointer, NO_OPS, STOCK_WRITE)
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 public:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 PartDownloadRequest (const PartDownloadRequest&) = delete;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 virtual ~PartDownloadRequest();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 void updateToTable();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 bool isFinished() const;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 void operator= (const PartDownloadRequest&) = delete;
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 public slots:
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 void downloadFinished();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 void readyRead();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 void downloadProgress (qint64 recv, qint64 total);
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 void abort();
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 };
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
b75c6cce02e2 - refactored filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 #endif // LDFORGE_DOWNLOAD_H

mercurial