src/download.h

Tue, 07 Jan 2014 12:21:46 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 07 Jan 2014 12:21:46 +0200
changeset 606
3dd6f343ec06
parent 603
47e7773c7841
permissions
-rw-r--r--

- removed the 'str' typedef, use QString directly

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
600
209e3f1f7b2c - updated copyright year. Best wishes for 2014!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 553
diff changeset
3 * Copyright (C) 2013, 2014 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>
541
0e38beeb050a - Renamed common.h to main.h, split the PROPERTY macro and supporting macros to property.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 540
diff changeset
23 #include "main.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
553
2418d5955421 - LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 549
diff changeset
26 class LDDocument;
431
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
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
38 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
39 typedefs:
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
40 enum Source
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
41 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
42 PartsTracker,
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
43 CustomURL,
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
46 enum Button
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
47 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
48 Download,
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
49 Abort,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
50 Close
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
51 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
52
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
53 enum TableColumn
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
54 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
55 PartLabelColumn,
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
56 ProgressColumn,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
57 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
58
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
59 using RequestList = QList<PartDownloadRequest*>;
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
60
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
61 properties:
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
62 Q_OBJECT
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
63 PROPERTY (public, LDDocument*, PrimaryFile, NO_OPS, STOCK_WRITE)
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
64 PROPERTY (public, bool, Aborted, BOOL_OPS, STOCK_WRITE)
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
65 PROPERTY (private, Ui_DownloadFrom*, Interface, NO_OPS, STOCK_WRITE)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
66 PROPERTY (private, QStringList, FilesToDownload, LIST_OPS, STOCK_WRITE)
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
67 PROPERTY (private, RequestList, Requests, LIST_OPS, STOCK_WRITE)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
68 PROPERTY (private, QPushButton*, DownloadButton, NO_OPS, STOCK_WRITE)
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
69
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
70 public:
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
71 explicit PartDownloader (QWidget* parent = null);
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
72 virtual ~PartDownloader();
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
73
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
74 void downloadFile (QString dest, QString url, bool primary);
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
75 QPushButton* getButton (Button i);
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
76 QString getURL() const;
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
77 Source getSource() const;
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
78 void modifyDestination (QString& dest) const;
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
79
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
80 static QString getDownloadPath();
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
81 static void staticBegin();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
82
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
83 public slots:
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
84 void buttonClicked (QAbstractButton* btn);
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
85 void checkIfFinished();
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
86 void sourceChanged (int i);
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 };
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
91 class PartDownloadRequest : public QObject
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
92 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
93 typedefs:
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
94 enum EState
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
95 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
96 ERequesting,
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
97 EDownloading,
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
98 EFinished,
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
99 EFailed,
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
100 };
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
101
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
102 properties:
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
103 Q_OBJECT
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
104 PROPERTY (public, int, TableRow, NUM_OPS, STOCK_WRITE)
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
105 PROPERTY (private, EState, State, NO_OPS, STOCK_WRITE)
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
106 PROPERTY (private, PartDownloader*, Prompt, NO_OPS, STOCK_WRITE)
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
107 PROPERTY (private, QString, URL, STR_OPS, STOCK_WRITE)
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
108 PROPERTY (private, QString, Destinaton, STR_OPS, STOCK_WRITE)
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
109 PROPERTY (private, QString, FilePath, STR_OPS, STOCK_WRITE)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
110 PROPERTY (private, QNetworkAccessManager*, NAM, NO_OPS, STOCK_WRITE)
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
111 PROPERTY (private, QNetworkReply*, Reply, NO_OPS, STOCK_WRITE)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
112 PROPERTY (private, bool, FirstUpdate, BOOL_OPS, STOCK_WRITE)
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
113 PROPERTY (private, int64, BytesRead, NUM_OPS, STOCK_WRITE)
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
114 PROPERTY (private, int64, BytesTotal, NUM_OPS, STOCK_WRITE)
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
115 PROPERTY (private, bool, Primary, BOOL_OPS, STOCK_WRITE)
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
116 PROPERTY (private, QFile*, FilePointer, NO_OPS, STOCK_WRITE)
549
715d9a7f6598 Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
117
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
118 public:
606
3dd6f343ec06 - removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
119 explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
120 PartDownloadRequest (const PartDownloadRequest&) = delete;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
121 virtual ~PartDownloadRequest();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
122 void updateToTable();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
123 bool isFinished() const;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
124
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
125 void operator= (const PartDownloadRequest&) = delete;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
126
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
127 public slots:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
128 void downloadFinished();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
129 void readyRead();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
130 void downloadProgress (qint64 recv, qint64 total);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
131 void abort();
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 };
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
134 #endif // LDFORGE_DOWNLOAD_H

mercurial