src/download.cpp

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

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

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

426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 452
diff changeset
4 *
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 452
diff changeset
9 *
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 452
diff changeset
14 *
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
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
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "download.h"
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "ui_downloadfrom.h"
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "types.h"
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
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
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
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
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
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();
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
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 dlg->exec();
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
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)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
72 { ui = new Ui_DownloadFrom;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 ui->setupUi (this);
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
74 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
75 ui->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
76
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
77 m_downloadButton = new QPushButton (tr ("Download"));
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
78 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
79 getButton (Abort)->setEnabled (false);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
80
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 connect (ui->source, SIGNAL (currentIndexChanged (int)), this, SLOT (sourceChanged (int)));
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
82 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), this, SLOT (buttonClicked (QAbstractButton*)));
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
87 PartDownloader::~PartDownloader()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
88 { delete ui;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
93 str PartDownloader::getURL() const
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
94 { 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
95 str dest;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
96
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
97 switch (src)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
98 { case PartsTracker:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
99 dest = ui->fname->text();
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 526
diff changeset
100 modifyDestination (dest);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
101 return str (k_UnofficialURL) + dest;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
102
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
103 case CustomURL:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
104 return ui->fname->text();
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
106
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 // Shouldn't happen
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 return "";
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 // -----------------------------------------------------------------------------
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 526
diff changeset
113 void PartDownloader::modifyDestination (str& dest) const
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
114 { dest = dest.simplified();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
115
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
116 // 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
117 if (net_guesspaths == false)
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
118 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
119
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
120 // Ensure .dat extension
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
121 if (dest.right (4) != ".dat")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
122 { // 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
123 // 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
124 const int dotpos = dest.lastIndexOf (".");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
125
430
8458cf2719d1 added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 429
diff changeset
126 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
127 dest.chop (dest.length() - dotpos);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
128
430
8458cf2719d1 added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 429
diff changeset
129 dest += ".dat";
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
130 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
131
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
132 // 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
133 // 48\ and p/48/.
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
134 if (dest.left (2) == "s\\" || dest.left (2) == "s/")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
135 { 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
136 dest.prepend ("parts/s/");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
137 } elif (dest.left (3) == "48\\" || dest.left (3) == "48/")
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
138
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
139 { 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
140 dest.prepend ("p/48/");
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
141 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
142
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
143 /* 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
144 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
145 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
146 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
147 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
148 - 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
149 - 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
150 - 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
151 - a lowercase alphabetic letter for variants
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
152
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
153 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
154 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
155 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
156 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
157 str subpartRegex = partRegex + "s[0-9][0-9]+";
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
158
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
159 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
160 subpartRegex += "\\.dat$";
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
161
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
162 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
163 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
164 elif (QRegExp (partRegex).exactMatch (dest))
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
165 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
166 elif (dest.left (6) != "parts/" && dest.left (2) != "p/")
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
167 dest.prepend ("p/");
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
168 }
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
172 PartDownloader::Source PartDownloader::getSource() const
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
173 { return (Source) ui->source->currentIndex();
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
174 }
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
178 void PartDownloader::sourceChanged (int i)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
179 { if (i == CustomURL)
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 ui->fileNameLabel->setText (tr ("URL:"));
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 else
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 ui->fileNameLabel->setText (tr ("File name:"));
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184
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
185 // =============================================================================
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
187 void PartDownloader::buttonClicked (QAbstractButton* btn)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
188 { if (btn == getButton (Close))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
189 { reject();
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
190 }
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
191 elif (btn == getButton (Abort))
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
192 { setAborted (true);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
193
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
194 for (PartDownloadRequest* req : m_requests)
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
195 req->abort();
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
196 }
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
197 elif (btn == getButton (Download))
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
198 { str dest = ui->fname->text();
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
199 setPrimaryFile (null);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
200 setAborted (false);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
201
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
202 if (getSource() == CustomURL)
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
203 dest = basename (getURL());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
204
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 526
diff changeset
205 modifyDestination (dest);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
206
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
207 if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
208 { 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
209 if (!confirm (tr ("Overwrite?"), overwritemsg))
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
210 return;
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
211 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
212
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
213 m_downloadButton->setEnabled (false);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
214 ui->progress->setEnabled (true);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
215 ui->fname->setEnabled (false);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
216 ui->source->setEnabled (false);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
217 downloadFile (dest, getURL(), true);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
218 getButton (Close)->setEnabled (false);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
219 getButton (Abort)->setEnabled (true);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
220 getButton (Download)->setEnabled (false);
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
221 }
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
222 }
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
226 void PartDownloader::downloadFile (str dest, str url, bool primary)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
227 { const int row = ui->progress->rowCount();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
228
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
229 // Don't download files repeadetly.
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
230 if (m_filesToDownload.indexOf (dest) != -1)
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
231 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
232
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 526
diff changeset
233 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
234 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
235 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
236
430
8458cf2719d1 added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 429
diff changeset
237 m_filesToDownload << dest;
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
238 m_requests << req;
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
239 ui->progress->insertRow (row);
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 req->setTableRow (row);
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 req->updateToTable();
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
246 void PartDownloader::checkIfFinished()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
247 { bool failed = aborted();
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
248
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
249 // 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
250 for (PartDownloadRequest* req : m_requests)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
251 { if (!req->isFinished())
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
252 return;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
253
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
254 if (req->state() == PartDownloadRequest::Failed)
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
255 failed = true;
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
256 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
257
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
258 for (PartDownloadRequest* req : m_requests)
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
259 delete req;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
260
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
261 m_requests.clear();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
262
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
263 // Update everything now
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
264 if (primaryFile())
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
265 { LDFile::setCurrent (primaryFile());
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
266 reloadAllSubfiles();
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 526
diff changeset
267 g_win->doFullRefresh();
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
268 g_win->R()->resetAngles();
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
269 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
270
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
271 if (net_autoclose && !failed)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
272 { // Close automatically if desired.
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
273 accept();
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
274 }
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
275 else
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
276 { // Allow the prompt be closed now.
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
277 getButton (Abort)->setEnabled (false);
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
278 getButton (Close)->setEnabled (true);
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
279 }
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
280 }
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
284 QPushButton* PartDownloader::getButton (PartDownloader::Button i)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
285 { typedef QDialogButtonBox QDBB;
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
286 alias btnbox = ui->buttonBox;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
287
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
288 switch (i)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
289 { case Download:
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
290 { return m_downloadButton;
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
291 }
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 Abort:
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
294 { return qobject_cast<QPushButton*> (btnbox->button (QDBB::Abort));
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
295 }
493
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:
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
298 { return qobject_cast<QPushButton*> (btnbox->button (QDBB::Close));
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
299 }
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
300 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
301
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
302 return null;
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 // =============================================================================
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
306 // -----------------------------------------------------------------------------
435
bc3a51394953 Merged PartDownloader into the prompt and renamed the prompt to PartDownloader
Santeri Piippo <crimsondusk64@gmail.com>
parents: 433
diff changeset
307 PartDownloadRequest::PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent) :
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 QObject (parent),
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 m_prompt (parent),
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
310 m_url (url),
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
311 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
312 m_fpath (PartDownloader::getDownloadPath() + DIRSLASH + dest),
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
313 m_nam (new QNetworkAccessManager),
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
314 m_firstUpdate (true),
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
315 m_state (Requesting),
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
316 m_primary (primary),
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
317 m_fp (null)
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
318 {
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
319 // Make sure that we have a valid destination.
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
320 str dirpath = dirname (m_fpath);
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 QDir dir (dirpath);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
323
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
324 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
325 { log ("Creating %1...\n", dirpath);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
326
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
327 if (!dir.mkpath (dirpath))
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
328 critical (fmt (tr ("Couldn't create the directory %1!"), dirpath));
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
329 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
330
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
331 m_reply = m_nam->get (QNetworkRequest (QUrl (url)));
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
332 connect (m_reply, SIGNAL (finished()), this, SLOT (downloadFinished()));
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
333 connect (m_reply, SIGNAL (readyRead()), this, SLOT (readyRead()));
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
334 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
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 // =============================================================================
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
338 // -----------------------------------------------------------------------------
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
339 PartDownloadRequest::~PartDownloadRequest() {}
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 // =============================================================================
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
343 void PartDownloadRequest::updateToTable()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
344 { const int labelcol = PartDownloader::PartLabelColumn,
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
345 progcol = PartDownloader::ProgressColumn;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 QTableWidget* table = m_prompt->ui->progress;
428
53e577061dc8 handle errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 427
diff changeset
347 QProgressBar* prog;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
348
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
349 switch (m_state)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
350 { case Requesting:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
351 case Downloading:
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
352 { prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol));
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 if (!prog)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
355 { prog = new QProgressBar;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
356 table->setCellWidget (tableRow(), progcol, prog);
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
359 prog->setRange (0, m_bytesTotal);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
360 prog->setValue (m_bytesRead);
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
361 } break;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
362
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
363 case Finished:
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
364 case Failed:
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
365 { QLabel* lb = new QLabel ((m_state == Finished) ? "<b><span style=\"color: #080\">FINISHED</span></b>" :
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
366 "<b><span style=\"color: #800\">FAILED</span></b>");
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
367 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
368 table->setCellWidget (tableRow(), progcol, lb);
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
369 } break;
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
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)
526
b29b6fc45ba9 style corrections
Santeri Piippo <crimsondusk64@gmail.com>
parents: 514
diff changeset
395 m_state = Finished;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
396
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
397 m_bytesRead = m_bytesTotal;
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
400 if (m_fp)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
401 { m_fp->close();
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
402 delete m_fp;
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
403 m_fp = null;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
404
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
405 if (m_state == Failed)
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
406 QFile::remove (m_fpath);
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
409 if (m_state != Finished)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
410 { m_prompt->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.
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
415 LDFile* f = openDATFile (m_fpath, 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
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
420 f->setImplicit (!m_primary);
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.
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
426 for (LDObject* obj : f->objects())
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
451
7ef26b45ed55 minor change
Santeri Piippo <crimsondusk64@gmail.com>
parents: 449
diff changeset
429 if (!err || err->fileRef().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
430
8458cf2719d1 added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 429
diff changeset
432 str dest = err->fileRef();
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 526
diff changeset
433 m_prompt->modifyDestination (dest);
430
8458cf2719d1 added config option, refined logic and regexps. This behaves coherently now. :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 429
diff changeset
434 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
435 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
436
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
437 if (m_primary)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
438 { addRecentFile (m_fpath);
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
439 m_prompt->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
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
442 m_prompt->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)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
448 { m_bytesRead = recv;
427
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
449 m_bytesTotal = total;
d308149fbc90 now actually downloads parts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 426
diff changeset
450 m_state = Downloading;
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()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
457 { if (state() == Failed)
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
460 if (m_fp == null)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
461 { m_fpath.replace ("\\", "/");
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.
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
465 m_fp = new QFile (m_fpath.toLocal8Bit());
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
466
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
467 if (!m_fp->open (QIODevice::WriteOnly))
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
468 { 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
469 m_state = Failed;
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
470 m_reply->abort();
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
471 updateToTable();
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
472 m_prompt->checkIfFinished();
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
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
477 m_fp->write (m_reply->readAll());
426
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 }
be5746bf0f12 added missing files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
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
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
483 { return m_state == Finished || m_state == Failed;
431
ec1e2059319b stability to downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 430
diff changeset
484 }
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
488 const PartDownloadRequest::State& PartDownloadRequest::state() const
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
489 { return m_state;
429
3488534b2b31 More work on downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 428
diff changeset
490 }
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
494 void PartDownloadRequest::abort()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
495 { m_reply->abort();
432
ef382b98a8af finalized downloading
Santeri Piippo <crimsondusk64@gmail.com>
parents: 431
diff changeset
496 }
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
500 DEFINE_ACTION (DownloadFrom, 0)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 491
diff changeset
501 { PartDownloader::k_download();
491
7d1b5ecd76c0 it's LDForge's 1st birthday!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 484
diff changeset
502 }

mercurial