Thu, 12 Dec 2013 19:44:09 +0200
- LDFile renamed to LDDocument, file.h -> document.h
- Added the INSTALL document
426 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
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:
452
diff
changeset
|
4 | * |
426 | 5 | * This program is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
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:
452
diff
changeset
|
9 | * |
426 | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
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:
452
diff
changeset
|
14 | * |
426 | 15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
19 | #include <QNetworkAccessManager> |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
20 | #include <QNetworkRequest> |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
21 | #include <QNetworkReply> |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
22 | #include <QDir> |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
23 | #include <QProgressBar> |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
24 | #include <QPushButton> |
426 | 25 | #include "download.h" |
26 | #include "ui_downloadfrom.h" | |
27 | #include "types.h" | |
28 | #include "gui.h" | |
553
2418d5955421
- LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
552
diff
changeset
|
29 | #include "document.h" |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
30 | #include "gldraw.h" |
482
5e96648f416f
redirect the user to configuration if the download path is not given
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
31 | #include "configDialog.h" |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
32 | #include "moc_download.cpp" |
426 | 33 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
34 | cfg (String, net_downloadpath, ""); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
35 | cfg (Bool, net_guesspaths, true); |
552
454f8b730946
net_autoclose is now true by default
Santeri Piippo <crimsondusk64@gmail.com>
parents:
549
diff
changeset
|
36 | cfg (Bool, net_autoclose, true); |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
37 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
38 | const str g_unofficialLibraryURL ("http://ldraw.org/library/unofficial/"); |
426 | 39 | |
40 | // ============================================================================= | |
41 | // ----------------------------------------------------------------------------- | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
42 | void PartDownloader::staticBegin() |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
43 | { str path = getDownloadPath(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
44 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
45 | if (path == "" || QDir (path).exists() == false) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
46 | { critical (PartDownloader::tr ("You need to specify a valid path for " |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
47 | "downloaded files in the configuration to download paths.")); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
48 | |
482
5e96648f416f
redirect the user to configuration if the download path is not given
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
49 | (new ConfigDialog (ConfigDialog::DownloadTab, null))->exec(); |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
50 | return; |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
51 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
52 | |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
53 | PartDownloader* dlg = new PartDownloader; |
426 | 54 | dlg->exec(); |
55 | } | |
56 | ||
57 | // ============================================================================= | |
58 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
59 | str PartDownloader::getDownloadPath() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
60 | { str path = net_downloadpath; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
61 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
62 | #if DIRSLASH_CHAR != '/' |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
63 | path.replace (DIRSLASH, "/"); |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
64 | #endif |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
65 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
66 | return path; |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
67 | } |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
68 | |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
69 | // ============================================================================= |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
70 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
71 | PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent) |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
72 | { setInterface (new Ui_DownloadFrom); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
73 | getInterface()->setupUi (this); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
74 | getInterface()->fname->setFocus(); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
75 | getInterface()->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
76 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
77 | setDownloadButton (new QPushButton (tr ("Download"))); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
78 | getInterface()->buttonBox->addButton (getDownloadButton(), QDialogButtonBox::ActionRole); |
452
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
79 | getButton (Abort)->setEnabled (false); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
80 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
81 | connect (getInterface()->source, SIGNAL (currentIndexChanged (int)), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
82 | this, SLOT (sourceChanged (int))); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
83 | connect (getInterface()->buttonBox, SIGNAL (clicked (QAbstractButton*)), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
84 | this, SLOT (buttonClicked (QAbstractButton*))); |
426 | 85 | } |
86 | ||
87 | // ============================================================================= | |
88 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
89 | PartDownloader::~PartDownloader() |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
90 | { delete getInterface(); |
426 | 91 | } |
92 | ||
93 | // ============================================================================= | |
94 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
95 | str PartDownloader::getURL() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
96 | { const Source src = getSource(); |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
97 | str dest; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
98 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
99 | switch (src) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
100 | { case PartsTracker: |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
101 | dest = getInterface()->fname->text(); |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
526
diff
changeset
|
102 | modifyDestination (dest); |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
103 | return g_unofficialLibraryURL + dest; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
104 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
105 | case CustomURL: |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
106 | return getInterface()->fname->text(); |
426 | 107 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
108 | |
426 | 109 | // Shouldn't happen |
110 | return ""; | |
111 | } | |
112 | ||
113 | // ============================================================================= | |
114 | // ----------------------------------------------------------------------------- | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
526
diff
changeset
|
115 | void PartDownloader::modifyDestination (str& dest) const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
116 | { dest = dest.simplified(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
117 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
118 | // If the user doesn't want us to guess, stop right here. |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
119 | if (net_guesspaths == false) |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
120 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
121 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
122 | // Ensure .dat extension |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
123 | if (dest.right (4) != ".dat") |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
124 | { // Remove the existing extension, if any. It may be we're here over a |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
125 | // typo in the .dat extension. |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
126 | const int dotpos = dest.lastIndexOf ("."); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
127 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
128 | if (dotpos != -1 && dotpos >= dest.length() - 4) |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
129 | dest.chop (dest.length() - dotpos); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
130 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
131 | dest += ".dat"; |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
132 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
133 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
134 | // If the part starts with s\ or s/, then use parts/s/. Same goes with |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
135 | // 48\ and p/48/. |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
136 | if (dest.left (2) == "s\\" || dest.left (2) == "s/") |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
137 | { dest.remove (0, 2); |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
138 | dest.prepend ("parts/s/"); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
139 | } elif (dest.left (3) == "48\\" || dest.left (3) == "48/") |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
140 | { dest.remove (0, 3); |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
141 | dest.prepend ("p/48/"); |
428 | 142 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
143 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
144 | /* Try determine where to put this part. We have four directories: |
452
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
145 | parts/, parts/s/, p/, and p/48/. If we haven't already specified |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
146 | either parts/ or p/, we need to add it automatically. Part files |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
147 | are numbers wit a possible u prefix for parts with unknown number |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
148 | which can be followed by any of: |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
149 | - c** (composites) |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
150 | - d** (formed stickers) |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
151 | - p** (patterns) |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
152 | - a lowercase alphabetic letter for variants |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
153 | |
452
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
154 | Subfiles (usually) have an s** prefix, in which case we use parts/s/. |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
155 | Note that the regex starts with a '^' so it won't catch already fully |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
156 | given part file names. */ |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
157 | str partRegex = "^u?[0-9]+(c[0-9][0-9]+)*(d[0-9][0-9]+)*[a-z]?(p[0-9a-z][0-9a-z]+)*"; |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
158 | str subpartRegex = partRegex + "s[0-9][0-9]+"; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
159 | |
452
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
160 | partRegex += "\\.dat$"; |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
161 | subpartRegex += "\\.dat$"; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
162 | |
452
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
163 | if (QRegExp (subpartRegex).exactMatch (dest)) |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
164 | dest.prepend ("parts/s/"); |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
165 | elif (QRegExp (partRegex).exactMatch (dest)) |
526 | 166 | dest.prepend ("parts/"); |
452
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
167 | elif (dest.left (6) != "parts/" && dest.left (2) != "p/") |
526 | 168 | dest.prepend ("p/"); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
169 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
170 | |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
171 | // ============================================================================= |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
172 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
173 | PartDownloader::Source PartDownloader::getSource() const |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
174 | { return (Source) getInterface()->source->currentIndex(); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
175 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
176 | |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
177 | // ============================================================================= |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
178 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
179 | void PartDownloader::sourceChanged (int i) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
180 | { if (i == CustomURL) |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
181 | getInterface()->fileNameLabel->setText (tr ("URL:")); |
426 | 182 | else |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
183 | getInterface()->fileNameLabel->setText (tr ("File name:")); |
426 | 184 | } |
185 | ||
452
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
186 | // ============================================================================= |
47cc663e4ff4
ask the user for ext prog paths instead of telling to go to configuration if no path is defined
Santeri Piippo <crimsondusk64@gmail.com>
parents:
451
diff
changeset
|
187 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
188 | void PartDownloader::buttonClicked (QAbstractButton* btn) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
189 | { if (btn == getButton (Close)) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
190 | { reject(); |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
191 | } |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
192 | elif (btn == getButton (Abort)) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
193 | { setAborted (true); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
194 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
195 | for (PartDownloadRequest* req : getRequests()) |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
196 | req->abort(); |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
197 | } |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
198 | elif (btn == getButton (Download)) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
199 | { str dest = getInterface()->fname->text(); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
200 | setPrimaryFile (null); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
201 | setAborted (false); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
202 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
203 | if (getSource() == CustomURL) |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
204 | dest = basename (getURL()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
205 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
526
diff
changeset
|
206 | modifyDestination (dest); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
207 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
208 | if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest)) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
209 | { const str overwritemsg = fmt (tr ("%1 already exists in download directory. Overwrite?"), dest); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
210 | if (!confirm (tr ("Overwrite?"), overwritemsg)) |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
211 | return; |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
212 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
213 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
214 | getDownloadButton()->setEnabled (false); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
215 | getInterface()->progress->setEnabled (true); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
216 | getInterface()->fname->setEnabled (false); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
217 | getInterface()->source->setEnabled (false); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
218 | downloadFile (dest, getURL(), true); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
219 | getButton (Close)->setEnabled (false); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
220 | getButton (Abort)->setEnabled (true); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
221 | getButton (Download)->setEnabled (false); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
222 | } |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
223 | } |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
224 | |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
225 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
226 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
227 | void PartDownloader::downloadFile (str dest, str url, bool primary) |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
228 | { const int row = getInterface()->progress->rowCount(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
229 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
230 | // Don't download files repeadetly. |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
231 | if (getFilesToDownload().indexOf (dest) != -1) |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
232 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
233 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
526
diff
changeset
|
234 | modifyDestination (dest); |
513
29eb671b34f6
Added a crash catcher which trigger under Linux. It calls GDB and tries to get a backtrace. Also integrated assertion failure handling to this new system. Removed the print() function in the process (because the new bomb box uses a text edit and QTextDocuments's print method clashes with the macro and I figured it was a good idea to rid it anyway) and replaced all calls with log().
Santeri Piippo <crimsondusk64@gmail.com>
parents:
504
diff
changeset
|
235 | log ("DOWNLOAD: %1 -> %2\n", url, PartDownloader::getDownloadPath() + DIRSLASH + dest); |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
236 | PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
237 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
238 | pushToFilesToDownload (dest); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
239 | pushToRequests (req); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
240 | getInterface()->progress->insertRow (row); |
426 | 241 | req->setTableRow (row); |
242 | req->updateToTable(); | |
243 | } | |
244 | ||
245 | // ============================================================================= | |
246 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
247 | void PartDownloader::checkIfFinished() |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
248 | { bool failed = isAborted(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
249 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
250 | // If there is some download still working, we're not finished. |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
251 | for (PartDownloadRequest* req : getRequests()) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
252 | { if (!req->isFinished()) |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
253 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
254 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
255 | if (req->getState() == PartDownloadRequest::EFailed) |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
256 | failed = true; |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
257 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
258 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
259 | for (PartDownloadRequest* req : getRequests()) |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
260 | delete req; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
261 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
262 | clearRequests(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
263 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
264 | // Update everything now |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
265 | if (getPrimaryFile()) |
553
2418d5955421
- LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
552
diff
changeset
|
266 | { LDDocument::setCurrent (getPrimaryFile()); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
267 | reloadAllSubfiles(); |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
526
diff
changeset
|
268 | g_win->doFullRefresh(); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
269 | g_win->R()->resetAngles(); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
270 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
271 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
272 | if (net_autoclose && !failed) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
273 | { // Close automatically if desired. |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
274 | accept(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
275 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
276 | else |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
277 | { // Allow the prompt be closed now. |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
278 | getButton (Abort)->setEnabled (false); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
279 | getButton (Close)->setEnabled (true); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
280 | } |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
281 | } |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
282 | |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
283 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
284 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
285 | QPushButton* PartDownloader::getButton (PartDownloader::Button i) |
548 | 286 | { switch (i) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
287 | { case Download: |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
288 | return getDownloadButton(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
289 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
290 | case Abort: |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
291 | return qobject_cast<QPushButton*> (getInterface()->buttonBox->button (QDialogButtonBox::Abort)); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
292 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
293 | case Close: |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
294 | return qobject_cast<QPushButton*> (getInterface()->buttonBox->button (QDialogButtonBox::Close)); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
295 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
296 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
297 | return null; |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
298 | } |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
299 | |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
300 | // ============================================================================= |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
301 | // ----------------------------------------------------------------------------- |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
302 | PartDownloadRequest::PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent) : |
426 | 303 | QObject (parent), |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
304 | m_State (ERequesting), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
305 | m_Prompt (parent), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
306 | m_URL (url), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
307 | m_Destinaton (dest), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
308 | m_FilePath (PartDownloader::getDownloadPath() + DIRSLASH + dest), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
309 | m_NAM (new QNetworkAccessManager), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
310 | m_FirstUpdate (true), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
311 | m_Primary (primary), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
312 | m_FilePointer (null) |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
313 | { |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
314 | // Make sure that we have a valid destination. |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
315 | str dirpath = dirname (getFilePath()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
316 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
317 | QDir dir (dirpath); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
318 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
319 | if (!dir.exists()) |
513
29eb671b34f6
Added a crash catcher which trigger under Linux. It calls GDB and tries to get a backtrace. Also integrated assertion failure handling to this new system. Removed the print() function in the process (because the new bomb box uses a text edit and QTextDocuments's print method clashes with the macro and I figured it was a good idea to rid it anyway) and replaced all calls with log().
Santeri Piippo <crimsondusk64@gmail.com>
parents:
504
diff
changeset
|
320 | { log ("Creating %1...\n", dirpath); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
321 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
322 | if (!dir.mkpath (dirpath)) |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
323 | critical (fmt (tr ("Couldn't create the directory %1!"), dirpath)); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
324 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
325 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
326 | setReply (getNAM()->get (QNetworkRequest (QUrl (url)))); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
327 | connect (getReply(), SIGNAL (finished()), this, SLOT (downloadFinished())); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
328 | connect (getReply(), SIGNAL (readyRead()), this, SLOT (readyRead())); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
329 | connect (getReply(), SIGNAL (downloadProgress (qint64, qint64)), |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
330 | this, SLOT (downloadProgress (qint64, qint64))); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
331 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
332 | |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
333 | // ============================================================================= |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
334 | // ----------------------------------------------------------------------------- |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
335 | PartDownloadRequest::~PartDownloadRequest() {} |
426 | 336 | |
337 | // ============================================================================= | |
338 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
339 | void PartDownloadRequest::updateToTable() |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
340 | { const int labelcol = PartDownloader::PartLabelColumn, |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
341 | progcol = PartDownloader::ProgressColumn; |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
342 | QTableWidget* table = getPrompt()->getInterface()->progress; |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
343 | QProgressBar* prog; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
344 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
345 | switch (getState()) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
346 | { case ERequesting: |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
347 | case EDownloading: |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
348 | { prog = qobject_cast<QProgressBar*> (table->cellWidget (getTableRow(), progcol)); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
349 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
350 | if (!prog) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
351 | { prog = new QProgressBar; |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
352 | table->setCellWidget (getTableRow(), progcol, prog); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
353 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
354 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
355 | prog->setRange (0, getBytesTotal()); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
356 | prog->setValue (getBytesRead()); |
526 | 357 | } break; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
358 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
359 | case EFinished: |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
360 | case EFailed: |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
361 | { const str text = (getState() == EFinished) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
362 | ? "<b><span style=\"color: #080\">FINISHED</span></b>" |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
363 | : "<b><span style=\"color: #800\">FAILED</span></b>"; |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
364 | |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
365 | QLabel* lb = new QLabel (text); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
366 | lb->setAlignment (Qt::AlignCenter); |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
367 | table->setCellWidget (getTableRow(), progcol, lb); |
526 | 368 | } break; |
426 | 369 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
370 | |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
371 | QLabel* lb = qobject_cast<QLabel*> (table->cellWidget (getTableRow(), labelcol)); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
372 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
373 | if (isFirstUpdate()) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
374 | { lb = new QLabel (fmt ("<b>%1</b>", getDestinaton()), table); |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
375 | table->setCellWidget (getTableRow(), labelcol, lb); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
376 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
377 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
378 | // Make sure that the cell is big enough to contain the label |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
379 | if (table->columnWidth (labelcol) < lb->width()) |
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
380 | table->setColumnWidth (labelcol, lb->width()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
381 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
382 | setFirstUpdate (true); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
383 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
384 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
385 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
386 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
387 | void PartDownloadRequest::downloadFinished() |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
388 | { if (getReply()->error() != QNetworkReply::NoError) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
389 | { if (isPrimary() && !getPrompt()->isAborted()) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
390 | critical (getReply()->errorString()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
391 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
392 | setState (EFailed); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
393 | } |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
394 | elif (getState() != EFailed) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
395 | setState (EFinished); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
396 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
397 | setBytesRead (getBytesTotal()); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
398 | updateToTable(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
399 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
400 | if (getFilePointer()) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
401 | { getFilePointer()->close(); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
402 | delete getFilePointer(); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
403 | setFilePointer (null); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
404 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
405 | if (getState() == EFailed) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
406 | QFile::remove (getFilePath()); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
407 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
408 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
409 | if (getState() != EFinished) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
410 | { getPrompt()->checkIfFinished(); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
411 | return; |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
412 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
413 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
414 | // Try to load this file now. |
553
2418d5955421
- LDFile renamed to LDDocument, file.h -> document.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
552
diff
changeset
|
415 | LDDocument* f = openDocument (getFilePath(), false); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
416 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
417 | if (!f) |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
418 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
419 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
420 | f->setImplicit (!isPrimary()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
421 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
422 | // Iterate through this file and check for errors. If there's any that stems |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
423 | // from unknown file references, try resolve that by downloading the reference. |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
424 | // This is why downloading a part may end up downloading multiple files, as |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
425 | // it resolves dependencies. |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
426 | for (LDObject* obj : f->getObjects()) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
427 | { LDError* err = dynamic_cast<LDError*> (obj); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
428 | |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
429 | if (!err || err->getFileReferenced().isEmpty()) |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
430 | continue; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
431 | |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
432 | str dest = err->getFileReferenced(); |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
433 | getPrompt()->modifyDestination (dest); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
434 | getPrompt()->downloadFile (dest, g_unofficialLibraryURL + dest, false); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
435 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
436 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
437 | if (isPrimary()) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
438 | { addRecentFile (getFilePath()); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
439 | getPrompt()->setPrimaryFile (f); |
449
f462f0bd3c51
made downloaded files be stored into recent files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
435
diff
changeset
|
440 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
441 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
442 | getPrompt()->checkIfFinished(); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
443 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
444 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
445 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
446 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
447 | void PartDownloadRequest::downloadProgress (int64 recv, int64 total) |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
448 | { setBytesRead (recv); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
449 | setBytesTotal (total); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
450 | setState (EDownloading); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
451 | updateToTable(); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
452 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
453 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
454 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
455 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
456 | void PartDownloadRequest::readyRead() |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
457 | { if (getState() == EFailed) |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
458 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
459 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
460 | if (getFilePointer() == null) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
461 | { replaceInFilePath ("\\", "/"); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
462 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
463 | // We have already asked the user whether we can overwrite so we're good |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
464 | // to go here. |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
465 | setFilePointer (new QFile (getFilePath().toLocal8Bit())); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
466 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
467 | if (!getFilePointer()->open (QIODevice::WriteOnly)) |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
468 | { critical (fmt (tr ("Couldn't open %1 for writing: %2"), getFilePath(), strerror (errno))); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
469 | setState (EFailed); |
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
470 | getReply()->abort(); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
471 | updateToTable(); |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
472 | getPrompt()->checkIfFinished(); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
473 | return; |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
474 | } |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
475 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
476 | |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
477 | getFilePointer()->write (getReply()->readAll()); |
426 | 478 | } |
479 | ||
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
480 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
481 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
482 | bool PartDownloadRequest::isFinished() const |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
483 | { return getState() == EFinished || getState() == EFailed; |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
484 | } |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
485 | |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
486 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
487 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
488 | void PartDownloadRequest::abort() |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
489 | { getReply()->abort(); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
490 | } |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
491 | |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
492 | // ============================================================================= |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
493 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
494 | DEFINE_ACTION (DownloadFrom, 0) |
549
715d9a7f6598
Cleaned up download.cpp/.h, used PROPERTY. Added LIST_OPS to PROPERTY
Santeri Piippo <crimsondusk64@gmail.com>
parents:
548
diff
changeset
|
495 | { PartDownloader::staticBegin(); |
491
7d1b5ecd76c0
it's LDForge's 1st birthday!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
484
diff
changeset
|
496 | } |