Thu, 09 Feb 2017 13:13:46 +0200
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1072 | 3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QPushButton> |
888
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
20 | #include <QFileDialog> |
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
21 | #include <QMessageBox> |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
22 | #include "partdownloader.h" |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
23 | #include "partdownloadrequest.h" |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
24 | #include "ui_partdownloader.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
25 | #include "mainwindow.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "ldDocument.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include "glRenderer.h" |
1012 | 28 | #include "documentmanager.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
30 | ConfigOption(QString DownloadFilePath) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
31 | ConfigOption(bool GuessDownloadPaths = true) |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
32 | ConfigOption (bool AutoCloseDownloadDialog = true) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
970
c8aae45afd85
Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
969
diff
changeset
|
34 | const char* g_unofficialLibraryURL = "http://ldraw.org/library/unofficial/"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
36 | PartDownloader::PartDownloader (QWidget* parent) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
37 | : QDialog(parent) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
38 | , HierarchyElement(parent) |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
39 | , _ui(*new Ui_PartDownloader) |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
40 | , _source(SourceType{}) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
42 | _ui.setupUi(this); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
43 | _ui.progressTable->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
44 | _downloadButton = new QPushButton {tr("Download")}; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
45 | _ui.buttonBox->addButton(_downloadButton, QDialogButtonBox::ActionRole); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
46 | button(Abort)->setEnabled(false); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
47 | connect(_ui.source, SIGNAL(currentIndexChanged(int)), this, SLOT(sourceChanged(int))); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
48 | connect(_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | PartDownloader::~PartDownloader() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
53 | delete &_ui; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
56 | void PartDownloader::checkValidPath() |
888
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
57 | { |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
58 | QString path = downloadPath(); |
888
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
59 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
60 | if (path.isEmpty() or not QDir {path}.exists()) |
888
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
61 | { |
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
62 | QMessageBox::information(this, "Notice", "Please input a path for files to download."); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
63 | path = QFileDialog::getExistingDirectory(this, "Path for downloaded files:"); |
888
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
64 | |
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
65 | if (path.isEmpty()) |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
66 | reject(); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
67 | else |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
68 | m_config->setDownloadFilePath(path); |
888
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
69 | } |
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
70 | } |
7ad8fb667084
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents:
882
diff
changeset
|
71 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
72 | QString PartDownloader::url() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
74 | switch (sourceType()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
76 | case PartsTracker: |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
77 | { |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
78 | QString destination; |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
79 | destination = _ui.filename->text(); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
80 | modifyDestination(destination); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
81 | _ui.filename->setText(destination); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
82 | return g_unofficialLibraryURL + destination; |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
83 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
85 | case CustomURL: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
86 | return _ui.filename->text(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | return ""; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
92 | void PartDownloader::modifyDestination(QString& destination) const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
94 | destination = destination.simplified(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | // If the user doesn't want us to guess, stop right here. |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
97 | if (not m_config->guessDownloadPaths()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | // Ensure .dat extension |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
101 | if (destination.right (4) != ".dat") |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
103 | // Remove the existing extension, if any. It may be we're here over a typo in the .dat extension. |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
104 | int dotPosition = destination.lastIndexOf("."); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
106 | if ((dotPosition != -1) and (dotPosition >= countof(destination) - 4)) |
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
107 | destination.chop(countof(destination) - dotPosition); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
109 | destination += ".dat"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
112 | // If the part starts with s\ or s/, then use parts/s/. Same goes with 48\ and p/48/. |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
113 | if (isOneOf(destination.left(2), "s\\", "s/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
115 | destination.remove(0, 2); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
116 | destination.prepend("parts/s/"); |
816 | 117 | } |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
118 | else if (isOneOf(destination.left(3), "48\\", "48/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
120 | destination.remove(0, 3); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
121 | destination.prepend("p/48/"); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | /* Try determine where to put this part. We have four directories: |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
125 | * parts/, parts/s/, p/, and p/48/. If we haven't already specified |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
126 | * either parts/ or p/, we need to add it automatically. Part files |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
127 | * are numbers wit a possible u prefix for parts with unknown number |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
128 | * which can be followed by any of: |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
129 | * - c** (composites) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
130 | * - d** (formed stickers) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
131 | * - p** (patterns) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
132 | * - a lowercase alphabetic letter for variants |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
133 | * |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
134 | * Subfiles (usually) have an s** prefix, in which case we use parts/s/. |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
135 | * Note that the regex starts with a '^' so it won't catch already fully |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
136 | * given part file names. |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
137 | */ |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | QString partRegex = "^u?[0-9]+(c[0-9][0-9]+)*(d[0-9][0-9]+)*[a-z]?(p[0-9a-z][0-9a-z]+)*"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | QString subpartRegex = partRegex + "s[0-9][0-9]+"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | partRegex += "\\.dat$"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | subpartRegex += "\\.dat$"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
144 | if (QRegExp {subpartRegex}.exactMatch(destination)) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
145 | destination.prepend("parts/s/"); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
146 | else if (QRegExp {partRegex}.exactMatch(destination)) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
147 | destination.prepend("parts/"); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
148 | else if (not destination.startsWith("parts/") and not destination.startsWith("p/")) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
149 | destination.prepend("p/"); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
152 | PartDownloader::SourceType PartDownloader::sourceType() const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
154 | return _source; |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
155 | } |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
156 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
157 | void PartDownloader::setSourceType(SourceType src) |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
158 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
159 | _source = src; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
160 | _ui.source->setCurrentIndex(int {src}); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
163 | void PartDownloader::sourceChanged(int sourceType) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
165 | if (sourceType == CustomURL) |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
166 | _ui.fileNameLabel->setText(tr("URL:")); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | else |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
168 | _ui.fileNameLabel->setText(tr("File name:")); |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
169 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
170 | _source = static_cast<SourceType>(sourceType); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
173 | void PartDownloader::buttonClicked(QAbstractButton* button) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
175 | if (button == this->button(Close)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | reject(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
179 | else if (button == this->button(Abort)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
181 | _isAborted = true; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
183 | for (PartDownloadRequest* request : _requests) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
184 | request->abort(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | } |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
186 | else if (button == this->button(Download)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
188 | QString destination = _ui.filename->text(); |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
944
diff
changeset
|
189 | setPrimaryFile (nullptr); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
190 | _isAborted = false; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
192 | if (sourceType() == CustomURL) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
193 | destination = Basename(url()); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
195 | modifyDestination(destination); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
197 | if (QFile::exists(downloadPath() + DIRSLASH + destination)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
199 | QString message = format(tr("%1 already exists in download directory. Overwrite?"), destination); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
200 | if (not Confirm(tr("Overwrite?"), message)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
204 | downloadFile (destination, url(), true); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
208 | void PartDownloader::downloadFile(QString destination, QString url, bool isPrimary) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
210 | int row = _ui.progressTable->rowCount(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | // Don't download files repeadetly. |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
213 | if (not _filesToDownload.contains(destination)) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
214 | { |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
215 | print ("Downloading %1 from %2\n", destination, url); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
216 | modifyDestination (destination); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
217 | PartDownloadRequest* request = new PartDownloadRequest {url, destination, isPrimary, this}; |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
218 | _filesToDownload << destination; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
219 | _requests << request; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
220 | _ui.progressTable->insertRow(row); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
221 | request->setTableRow(row); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
222 | request->updateToTable(); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
223 | _downloadButton->setEnabled(false); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
224 | _ui.progressTable->setEnabled(true); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
225 | _ui.filename->setEnabled(false); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
226 | _ui.source->setEnabled(false); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
227 | button(Close)->setEnabled(false); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
228 | button(Abort)->setEnabled(true); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
229 | button(Download)->setEnabled(false); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
230 | } |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
231 | } |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
232 | |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
233 | void PartDownloader::downloadFromPartsTracker (QString file) |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
234 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
235 | modifyDestination(file); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
236 | downloadFile(file, g_unofficialLibraryURL + file, false); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | void PartDownloader::checkIfFinished() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | bool failed = isAborted(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | // If there is some download still working, we're not finished. |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
244 | for (PartDownloadRequest* request : _requests) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
246 | if (not request->isFinished()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
249 | failed |= request->failed(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
252 | for (PartDownloadRequest* request : _requests) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
253 | delete request; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
255 | _requests.clear(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
257 | if (primaryFile()) |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
258 | emit primaryFileDownloaded(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
260 | for (LDDocument* file : _files) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
261 | file->reloadAllSubfiles(); |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
262 | |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
263 | if (m_config->autoCloseDownloadDialog() and not failed) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | // Close automatically if desired. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | accept(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | // Allow the prompt be closed now. |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
271 | button(Abort)->setEnabled(false); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
272 | button(Close)->setEnabled(true); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
276 | QAbstractButton* PartDownloader::button(PartDownloader::Button which) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
278 | switch (which) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
280 | case Download: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
281 | return _downloadButton; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
283 | case Abort: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
284 | return _ui.buttonBox->button(QDialogButtonBox::Abort); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
285 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
286 | case Close: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
287 | return _ui.buttonBox->button(QDialogButtonBox::Close); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
288 | |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
289 | default: |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
290 | return nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
294 | void PartDownloader::addFile(LDDocument* file) |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
295 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
296 | _files.append(file); |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
297 | } |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
298 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
299 | bool PartDownloader::isAborted() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
300 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
301 | return _isAborted; |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
302 | } |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
303 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
304 | LDDocument* PartDownloader::primaryFile() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
305 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
306 | return _primaryFile; |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
307 | } |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
308 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
309 | void PartDownloader::setPrimaryFile (LDDocument* document) |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
310 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
311 | _primaryFile = document; |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
312 | } |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
313 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
314 | QString PartDownloader::downloadPath() |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
315 | { |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
316 | QString path = m_config->downloadFilePath(); |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
317 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
318 | if (DIRSLASH[0] != '/') |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
319 | path.replace(DIRSLASH, "/"); |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
320 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
321 | return path; |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
322 | } |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
323 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
324 | QTableWidget* PartDownloader::progressTable() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
325 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
326 | return _ui.progressTable; |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
327 | } |