Fri, 18 Oct 2013 21:52:09 +0300
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().
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" | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
29 | #include "file.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 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
34 | cfg (String, net_downloadpath, ""); |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
35 | cfg (Bool, net_guesspaths, true); |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
460
diff
changeset
|
36 | cfg (Bool, net_autoclose, false); |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
37 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
38 | constexpr const char *PartDownloader::k_UnofficialURL; |
426 | 39 | |
40 | // ============================================================================= | |
41 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
42 | void PartDownloader::k_download() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
43 | { str path = getDownloadPath(); |
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
|
44 | assert (false); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
45 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
46 | if (path == "" || QDir (path).exists() == false) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
47 | { 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
|
48 | "downloaded files in the configuration to download paths.")); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
49 | |
482
5e96648f416f
redirect the user to configuration if the download path is not given
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
50 | (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
|
51 | return; |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
52 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
53 | |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
54 | PartDownloader* dlg = new PartDownloader; |
426 | 55 | dlg->exec(); |
56 | } | |
57 | ||
58 | // ============================================================================= | |
59 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
60 | str PartDownloader::getDownloadPath() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
61 | { str path = net_downloadpath; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
62 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
63 | #if DIRSLASH_CHAR != '/' |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
64 | path.replace (DIRSLASH, "/"); |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
65 | #endif |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
66 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
67 | return path; |
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 | // ============================================================================= |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
71 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
72 | PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
73 | { ui = new Ui_DownloadFrom; |
426 | 74 | ui->setupUi (this); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
75 | ui->fname->setFocus(); |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
76 | ui->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
77 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
78 | m_downloadButton = new QPushButton (tr ("Download")); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
79 | ui->buttonBox->addButton (m_downloadButton, 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
|
80 | getButton (Abort)->setEnabled (false); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
81 | |
426 | 82 | connect (ui->source, SIGNAL (currentIndexChanged (int)), this, SLOT (sourceChanged (int))); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
83 | connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), this, SLOT (buttonClicked (QAbstractButton*))); |
426 | 84 | } |
85 | ||
86 | // ============================================================================= | |
87 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
88 | PartDownloader::~PartDownloader() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
89 | { delete ui; |
426 | 90 | } |
91 | ||
92 | // ============================================================================= | |
93 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
94 | str PartDownloader::getURL() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
95 | { 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
|
96 | str dest; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
97 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
98 | switch (src) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
99 | { case PartsTracker: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
100 | dest = ui->fname->text(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
101 | modifyDest (dest); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
102 | return str (k_UnofficialURL) + dest; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
103 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
104 | case CustomURL: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
105 | return ui->fname->text(); |
426 | 106 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
107 | |
426 | 108 | // Shouldn't happen |
109 | return ""; | |
110 | } | |
111 | ||
112 | // ============================================================================= | |
113 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
114 | void PartDownloader::modifyDest (str& dest) const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
115 | { dest = dest.simplified(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
116 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
117 | // 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
|
118 | if (net_guesspaths == false) |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
119 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
120 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
121 | // Ensure .dat extension |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
122 | if (dest.right (4) != ".dat") |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
123 | { // 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
|
124 | // 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
|
125 | const int dotpos = dest.lastIndexOf ("."); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
126 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
127 | 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
|
128 | dest.chop (dest.length() - dotpos); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
129 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
130 | dest += ".dat"; |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
131 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
132 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
133 | // 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
|
134 | // 48\ and p/48/. |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
135 | if (dest.left (2) == "s\\" || dest.left (2) == "s/") |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
136 | { 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
|
137 | dest.prepend ("parts/s/"); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
138 | } elif (dest.left (3) == "48\\" || dest.left (3) == "48/") |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
139 | |
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/"); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
165 | |
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
|
166 | elif (QRegExp (partRegex).exactMatch (dest)) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
167 | 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
|
168 | elif (dest.left (6) != "parts/" && dest.left (2) != "p/") |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
169 | dest.prepend ("p/"); |
427
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 | // ============================================================================= |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
173 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
174 | PartDownloader::Source PartDownloader::getSource() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
175 | { return (Source) ui->source->currentIndex(); |
427
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 | // ============================================================================= |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
179 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
180 | void PartDownloader::sourceChanged (int i) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
181 | { if (i == CustomURL) |
426 | 182 | ui->fileNameLabel->setText (tr ("URL:")); |
183 | else | |
184 | ui->fileNameLabel->setText (tr ("File name:")); | |
185 | } | |
186 | ||
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
|
187 | // ============================================================================= |
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
|
188 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
189 | void PartDownloader::buttonClicked (QAbstractButton* btn) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
190 | { if (btn == getButton (Close)) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
191 | { reject(); |
504
6a1fa662bfc1
Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
503
diff
changeset
|
192 | } |
6a1fa662bfc1
Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
503
diff
changeset
|
193 | elif (btn == getButton (Abort)) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
194 | { setAborted (true); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
195 | |
504
6a1fa662bfc1
Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
503
diff
changeset
|
196 | for (PartDownloadRequest* req : m_requests) |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
197 | req->abort(); |
504
6a1fa662bfc1
Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
503
diff
changeset
|
198 | } |
6a1fa662bfc1
Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
503
diff
changeset
|
199 | elif (btn == getButton (Download)) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
200 | { str dest = ui->fname->text(); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
201 | setPrimaryFile (null); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
202 | setAborted (false); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
203 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
204 | if (getSource() == CustomURL) |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
205 | dest = basename (getURL()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
206 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
207 | modifyDest (dest); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
208 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
209 | if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest)) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
210 | { 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
|
211 | if (!confirm (tr ("Overwrite?"), overwritemsg)) |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
212 | return; |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
213 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
214 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
215 | m_downloadButton->setEnabled (false); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
216 | ui->progress->setEnabled (true); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
217 | ui->fname->setEnabled (false); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
218 | ui->source->setEnabled (false); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
219 | downloadFile (dest, getURL(), true); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
220 | getButton (Close)->setEnabled (false); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
221 | getButton (Abort)->setEnabled (true); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
222 | getButton (Download)->setEnabled (false); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
223 | } |
429
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 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
227 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
228 | void PartDownloader::downloadFile (str dest, str url, bool primary) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
229 | { const int row = ui->progress->rowCount(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
230 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
231 | // Don't download files repeadetly. |
503
bebe09014dd6
removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
232 | if (m_filesToDownload.indexOf (dest) != -1) |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
233 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
234 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
235 | modifyDest (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
|
236 | 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
|
237 | PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
238 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
239 | m_filesToDownload << dest; |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
240 | m_requests << req; |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
241 | ui->progress->insertRow (row); |
426 | 242 | req->setTableRow (row); |
243 | req->updateToTable(); | |
244 | } | |
245 | ||
246 | // ============================================================================= | |
247 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
248 | void PartDownloader::checkIfFinished() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
249 | { bool failed = aborted(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
250 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
251 | // If there is some download still working, we're not finished. |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
252 | for (PartDownloadRequest* req : m_requests) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
253 | { if (!req->isFinished()) |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
254 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
255 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
256 | if (req->state() == PartDownloadRequest::Failed) |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
257 | failed = true; |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
258 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
259 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
260 | for (PartDownloadRequest* req : m_requests) |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
261 | delete req; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
262 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
263 | m_requests.clear(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
264 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
265 | // Update everything now |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
266 | if (primaryFile()) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
267 | { LDFile::setCurrent (primaryFile()); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
268 | reloadAllSubfiles(); |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
269 | g_win->fullRefresh(); |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
270 | g_win->R()->resetAngles(); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
271 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
272 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
273 | if (net_autoclose && !failed) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
274 | { // Close automatically if desired. |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
275 | accept(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
276 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
277 | else |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
278 | { // Allow the prompt be closed now. |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
279 | getButton (Abort)->setEnabled (false); |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
280 | getButton (Close)->setEnabled (true); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
281 | } |
429
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 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
285 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
286 | QPushButton* PartDownloader::getButton (PartDownloader::Button i) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
287 | { typedef QDialogButtonBox QDBB; |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
288 | alias btnbox = ui->buttonBox; |
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 | switch (i) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
291 | { case Download: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
292 | return m_downloadButton; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
293 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
294 | case Abort: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
295 | return qobject_cast<QPushButton*> (btnbox->button (QDBB::Abort)); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
296 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
297 | case Close: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
298 | return qobject_cast<QPushButton*> (btnbox->button (QDBB::Close)); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
299 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
300 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
301 | return null; |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
302 | } |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
303 | |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
304 | // ============================================================================= |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
305 | // ----------------------------------------------------------------------------- |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
306 | PartDownloadRequest::PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent) : |
426 | 307 | QObject (parent), |
308 | m_prompt (parent), | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
309 | m_url (url), |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
310 | m_dest (dest), |
482
5e96648f416f
redirect the user to configuration if the download path is not given
Santeri Piippo <crimsondusk64@gmail.com>
parents:
475
diff
changeset
|
311 | m_fpath (PartDownloader::getDownloadPath() + DIRSLASH + dest), |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
312 | m_nam (new QNetworkAccessManager), |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
313 | m_firstUpdate (true), |
428 | 314 | m_state (Requesting), |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
315 | m_primary (primary), |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
316 | m_fp (null) |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
317 | { |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
318 | // Make sure that we have a valid destination. |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
319 | str dirpath = dirname (m_fpath); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
320 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
321 | QDir dir (dirpath); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
322 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
323 | 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
|
324 | { log ("Creating %1...\n", dirpath); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
325 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
326 | if (!dir.mkpath (dirpath)) |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
327 | critical (fmt (tr ("Couldn't create the directory %1!"), dirpath)); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
328 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
329 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
330 | m_reply = m_nam->get (QNetworkRequest (QUrl (url))); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
331 | connect (m_reply, SIGNAL (finished()), this, SLOT (downloadFinished())); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
332 | connect (m_reply, SIGNAL (readyRead()), this, SLOT (readyRead())); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
333 | connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)), this, SLOT (downloadProgress (qint64, qint64))); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
334 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
335 | |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
336 | // ============================================================================= |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
337 | // ----------------------------------------------------------------------------- |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
338 | PartDownloadRequest::~PartDownloadRequest() {} |
426 | 339 | |
340 | // ============================================================================= | |
341 | // ----------------------------------------------------------------------------- | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
342 | void PartDownloadRequest::updateToTable() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
343 | { const int labelcol = PartDownloader::PartLabelColumn, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
344 | progcol = PartDownloader::ProgressColumn; |
426 | 345 | QTableWidget* table = m_prompt->ui->progress; |
428 | 346 | QProgressBar* prog; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
347 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
348 | switch (m_state) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
349 | { case Requesting: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
350 | case Downloading: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
351 | prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol)); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
352 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
353 | if (!prog) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
354 | { prog = new QProgressBar; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
355 | table->setCellWidget (tableRow(), progcol, prog); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
356 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
357 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
358 | prog->setRange (0, m_bytesTotal); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
359 | prog->setValue (m_bytesRead); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
360 | break; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
361 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
362 | case Finished: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
363 | case Failed: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
364 | { QLabel* lb = new QLabel ( (m_state == Finished) ? "<b><span style=\"color: #080\">FINISHED</span></b>" : |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
365 | "<b><span style=\"color: #800\">FAILED</span></b>"); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
366 | lb->setAlignment (Qt::AlignCenter); |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
367 | table->setCellWidget (tableRow(), progcol, lb); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
368 | } |
428 | 369 | break; |
426 | 370 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
371 | |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
372 | QLabel* lb = qobject_cast<QLabel*> (table->cellWidget (tableRow(), labelcol)); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
373 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
374 | if (m_firstUpdate) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
375 | { lb = new QLabel (fmt ("<b>%1</b>", m_dest), table); |
435
bc3a51394953
Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents:
433
diff
changeset
|
376 | table->setCellWidget (tableRow(), labelcol, lb); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
377 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
378 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
379 | // 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
|
380 | 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
|
381 | table->setColumnWidth (labelcol, lb->width()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
382 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
383 | m_firstUpdate = false; |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
384 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
385 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
386 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
387 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
388 | void PartDownloadRequest::downloadFinished() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
389 | { if (m_reply->error() != QNetworkReply::NoError) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
390 | { if (m_primary && !m_prompt->aborted()) |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
391 | critical (m_reply->errorString()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
392 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
393 | m_state = Failed; |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
394 | } elif (state() != Failed) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
395 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
396 | m_state = Finished; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
397 | |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
398 | m_bytesRead = m_bytesTotal; |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
399 | updateToTable(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
400 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
401 | if (m_fp) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
402 | { m_fp->close(); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
403 | delete m_fp; |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
404 | m_fp = null; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
405 | |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
406 | if (m_state == Failed) |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
407 | QFile::remove (m_fpath); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
408 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
409 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
410 | if (m_state != Finished) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
411 | { m_prompt->checkIfFinished(); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
412 | return; |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
413 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
414 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
415 | // Try to load this file now. |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
416 | LDFile* f = openDATFile (m_fpath, false); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
417 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
418 | if (!f) |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
419 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
420 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
421 | f->setImplicit (!m_primary); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
422 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
423 | // 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
|
424 | // 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
|
425 | // 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
|
426 | // it resolves dependencies. |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
427 | for (LDObject* obj : f->objects()) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
428 | { LDError* err = dynamic_cast<LDError*> (obj); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
429 | |
451 | 430 | if (!err || err->fileRef().isEmpty()) |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
431 | continue; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
432 | |
430
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
433 | str dest = err->fileRef(); |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
434 | m_prompt->modifyDest (dest); |
8458cf2719d1
added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
429
diff
changeset
|
435 | m_prompt->downloadFile (dest, str (PartDownloader::k_UnofficialURL) + dest, false); |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
436 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
437 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
438 | if (m_primary) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
439 | { addRecentFile (m_fpath); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
440 | m_prompt->setPrimaryFile (f); |
449
f462f0bd3c51
made downloaded files be stored into recent files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
435
diff
changeset
|
441 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
442 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
443 | m_prompt->checkIfFinished(); |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
444 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
445 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
446 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
447 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
448 | void PartDownloadRequest::downloadProgress (int64 recv, int64 total) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
449 | { m_bytesRead = recv; |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
450 | m_bytesTotal = total; |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
451 | m_state = Downloading; |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
452 | updateToTable(); |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
453 | } |
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
454 | |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
455 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
456 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
457 | void PartDownloadRequest::readyRead() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
458 | { if (state() == Failed) |
427
d308149fbc90
now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
426
diff
changeset
|
459 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
460 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
461 | if (m_fp == null) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
462 | { m_fpath.replace ("\\", "/"); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
463 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
464 | // 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
|
465 | // to go here. |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
466 | m_fp = new QFile (m_fpath.toLocal8Bit()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
467 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
468 | if (!m_fp->open (QIODevice::WriteOnly)) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
469 | { critical (fmt (tr ("Couldn't open %1 for writing: %2"), m_fpath, strerror (errno))); |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
470 | m_state = Failed; |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
471 | m_reply->abort(); |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
472 | updateToTable(); |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
473 | m_prompt->checkIfFinished(); |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
474 | return; |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
475 | } |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
476 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
477 | |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
478 | m_fp->write (m_reply->readAll()); |
426 | 479 | } |
480 | ||
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
481 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
482 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
483 | bool PartDownloadRequest::isFinished() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
484 | { return m_state == Finished || m_state == Failed; |
431
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
485 | } |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
486 | |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
487 | // ============================================================================= |
ec1e2059319b
stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
488 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
489 | const PartDownloadRequest::State& PartDownloadRequest::state() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
490 | { return m_state; |
429
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
491 | } |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
492 | |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
493 | // ============================================================================= |
3488534b2b31
More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
428
diff
changeset
|
494 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
495 | void PartDownloadRequest::abort() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
496 | { m_reply->abort(); |
432
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
497 | } |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
498 | |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
499 | // ============================================================================= |
ef382b98a8af
finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents:
431
diff
changeset
|
500 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
501 | DEFINE_ACTION (DownloadFrom, 0) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
502 | { PartDownloader::k_download(); |
491
7d1b5ecd76c0
it's LDForge's 1st birthday!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
484
diff
changeset
|
503 | } |