Thu, 04 Jan 2018 19:44:26 +0200
fix paren style
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 |
968 | 3 | * Copyright (C) 2013 - 2015 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 <QDir> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #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
|
21 | #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
|
22 | #include <QMessageBox> |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
23 | #include <QTableWidget> |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
24 | #include "partdownloader.h" |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
25 | #include "partdownloadrequest.h" |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
26 | #include "ui_partdownloader.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include "basics.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
28 | #include "mainwindow.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "ldDocument.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "glRenderer.h" |
1012 | 31 | #include "documentmanager.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
1217 | 33 | ConfigOption(QString DownloadFilePath) |
34 | ConfigOption(bool GuessDownloadPaths = true) | |
35 | ConfigOption(bool AutoCloseDownloadDialog = true) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
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
|
37 | const char* g_unofficialLibraryURL = "http://ldraw.org/library/unofficial/"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | |
1217 | 39 | PartDownloader::PartDownloader(QWidget* parent) : |
40 | QDialog(parent), | |
41 | HierarchyElement(parent), | |
42 | ui(*new Ui_PartDownloader), | |
43 | m_source(SourceType(0)) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | { |
1217 | 45 | ui.setupUi(this); |
855
e16f1587ef44
- fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
852
diff
changeset
|
46 | |
e16f1587ef44
- fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
852
diff
changeset
|
47 | #ifdef USE_QT5 |
1217 | 48 | ui.progressTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
855
e16f1587ef44
- fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
852
diff
changeset
|
49 | #else |
1217 | 50 | ui.progressTable->horizontalHeader()->setResizeMode(PartLabelColumn, QHeaderView::Stretch); |
855
e16f1587ef44
- fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
852
diff
changeset
|
51 | #endif |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
1217 | 53 | m_downloadButton = new QPushButton(tr("Download")); |
54 | ui.buttonBox->addButton(m_downloadButton, QDialogButtonBox::ActionRole); | |
55 | button(Abort)->setEnabled(false); | |
56 | connect(ui.source, SIGNAL(currentIndexChanged(int)), this, SLOT(sourceChanged(int))); | |
57 | connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | PartDownloader::~PartDownloader() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | { |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
62 | delete &ui; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
65 | 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
|
66 | { |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
67 | 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
|
68 | |
1217 | 69 | 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
|
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 | QMessageBox::information(this, "Notice", "Please input a path for files to download."); |
1217 | 72 | 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
|
73 | |
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
|
74 | if (path.isEmpty()) |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
75 | reject(); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
76 | else |
1217 | 77 | 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
|
78 | } |
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
|
79 | } |
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
|
80 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
81 | QString PartDownloader::url() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
83 | QString destination; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
1217 | 85 | switch(sourceType()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
87 | case PartsTracker: |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
88 | destination = ui.filename->text(); |
1217 | 89 | modifyDestination(destination); |
90 | ui.filename->setText(destination); | |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
91 | return g_unofficialLibraryURL + destination; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
93 | case CustomURL: |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
94 | return ui.filename->text(); |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | // Shouldn't happen |
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 | |
1217 | 101 | void PartDownloader::modifyDestination(QString& dest) const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | dest = dest.simplified(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | // If the user doesn't want us to guess, stop right here. |
1215 | 106 | if (not config.guessDownloadPaths()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | // Ensure .dat extension |
1217 | 110 | if (dest.right(4) != ".dat") |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | // Remove the existing extension, if any. It may be we're here over a |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | // typo in the .dat extension. |
1217 | 114 | const int dotpos = dest.lastIndexOf("."); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
1217 | 116 | if ((dotpos != -1) and(dotpos >= dest.length() - 4)) |
117 | dest.chop(dest.length() - dotpos); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | dest += ".dat"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | // If the part starts with s\ or s/, then use parts/s/. Same goes with |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | // 48\ and p/48/. |
1217 | 124 | if (isOneOf(dest.left(2), "s\\", "s/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | { |
1217 | 126 | dest.remove(0, 2); |
127 | dest.prepend("parts/s/"); | |
816 | 128 | } |
1217 | 129 | else if (isOneOf(dest.left(3), "48\\", "48/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | { |
1217 | 131 | dest.remove(0, 3); |
132 | dest.prepend("p/48/"); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | /* Try determine where to put this part. We have four directories: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | parts/, parts/s/, p/, and p/48/. If we haven't already specified |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | either parts/ or p/, we need to add it automatically. Part files |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | are numbers wit a possible u prefix for parts with unknown number |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | which can be followed by any of: |
1217 | 140 | - c**(composites) |
141 | - d**(formed stickers) | |
142 | - p**(patterns) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | - a lowercase alphabetic letter for variants |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | |
1217 | 145 | Subfiles(usually) have an s** prefix, in which case we use parts/s/. |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | Note that the regex starts with a '^' so it won't catch already fully |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | given part file names. */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | 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
|
149 | QString subpartRegex = partRegex + "s[0-9][0-9]+"; |
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 | partRegex += "\\.dat$"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | subpartRegex += "\\.dat$"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | |
1217 | 154 | if (QRegExp(subpartRegex).exactMatch(dest)) |
155 | dest.prepend("parts/s/"); | |
156 | else if (QRegExp(partRegex).exactMatch(dest)) | |
157 | dest.prepend("parts/"); | |
158 | else if (not dest.startsWith("parts/") and not dest.startsWith("p/")) | |
159 | dest.prepend("p/"); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
162 | PartDownloader::SourceType PartDownloader::sourceType() const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | { |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
164 | return m_source; |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
165 | } |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
166 | |
1217 | 167 | 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
|
168 | { |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
169 | m_source = src; |
1217 | 170 | ui.source->setCurrentIndex(int(src)); |
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 | |
1217 | 173 | void PartDownloader::sourceChanged(int i) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | if (i == CustomURL) |
1217 | 176 | ui.fileNameLabel->setText(tr("URL:")); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | else |
1217 | 178 | 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
|
179 | |
1217 | 180 | m_source = SourceType(i); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | |
1217 | 183 | void PartDownloader::buttonClicked(QAbstractButton* btn) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | { |
1217 | 185 | if (btn == button(Close)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | reject(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | } |
1217 | 189 | else if (btn == button(Abort)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | { |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
191 | m_isAborted = true; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
193 | for (PartDownloadRequest* req : m_requests) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | req->abort(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | } |
1217 | 196 | else if (btn == button(Download)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
198 | QString dest = ui.filename->text(); |
1217 | 199 | setPrimaryFile(nullptr); |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
200 | m_isAborted = false; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
202 | if (sourceType() == CustomURL) |
1217 | 203 | dest = Basename(url()); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | |
1217 | 205 | modifyDestination(dest); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | |
1217 | 207 | if (QFile::exists(downloadPath() + DIRSLASH + dest)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | { |
1217 | 209 | const QString overwritemsg = format(tr("%1 already exists in download directory. Overwrite?"), dest); |
210 | if (not Confirm(tr("Overwrite?"), overwritemsg)) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | |
1217 | 214 | downloadFile(dest, url(), true); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | |
1217 | 218 | void PartDownloader::downloadFile(QString dest, QString url, bool primary) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
220 | int row = ui.progressTable->rowCount(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | // Don't download files repeadetly. |
1217 | 223 | if (m_filesToDownload.indexOf(dest) != -1) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | |
1217 | 226 | print("Downloading %1 from %2\n", dest, url); |
227 | modifyDestination(dest); | |
228 | PartDownloadRequest* req = new PartDownloadRequest(url, dest, primary, this); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | m_filesToDownload << dest; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | m_requests << req; |
1217 | 231 | ui.progressTable->insertRow(row); |
232 | req->setTableRow(row); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | req->updateToTable(); |
1217 | 234 | m_downloadButton->setEnabled(false); |
235 | ui.progressTable->setEnabled(true); | |
236 | ui.filename->setEnabled(false); | |
237 | ui.source->setEnabled(false); | |
238 | button(Close)->setEnabled(false); | |
239 | button(Abort)->setEnabled(true); | |
240 | button(Download)->setEnabled(false); | |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
241 | } |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
242 | |
1217 | 243 | void PartDownloader::downloadFromPartsTracker(QString file) |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
244 | { |
1217 | 245 | modifyDestination(file); |
246 | downloadFile(file, g_unofficialLibraryURL + file, false); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | void PartDownloader::checkIfFinished() |
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 | bool failed = isAborted(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | // If there is some download still working, we're not finished. |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
254 | for (PartDownloadRequest* req : m_requests) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | { |
662
2f1bd9112408
- use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
256 | if (not req->isFinished()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
259 | if (req->failed()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | failed = true; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
263 | for (PartDownloadRequest* req : m_requests) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | delete req; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | m_requests.clear(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
268 | if (primaryFile()) |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
269 | emit primaryFileDownloaded(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
271 | for (LDDocument* f : m_files) |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
272 | f->reloadAllSubfiles(); |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
273 | |
1215 | 274 | if (config.autoCloseDownloadDialog() and not failed) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | // Close automatically if desired. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | accept(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | else |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | // Allow the prompt be closed now. |
1217 | 282 | button(Abort)->setEnabled(false); |
283 | button(Close)->setEnabled(true); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
285 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | |
1217 | 287 | QPushButton* PartDownloader::button(PartDownloader::Button i) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | { |
1217 | 289 | switch(i) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | case Download: |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
292 | return m_downloadButton; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | case Abort: |
1217 | 295 | return qobject_cast<QPushButton*>(ui.buttonBox->button(QDialogButtonBox::Abort)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | case Close: |
1217 | 298 | return qobject_cast<QPushButton*>(ui.buttonBox->button(QDialogButtonBox::Close)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | |
984 | 301 | return nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | |
1217 | 304 | void PartDownloader::addFile(LDDocument* f) |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
305 | { |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
306 | m_files << f; |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
307 | } |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
308 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
309 | bool PartDownloader::isAborted() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
310 | { |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
311 | return m_isAborted; |
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 | LDDocument* PartDownloader::primaryFile() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
315 | { |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
316 | return m_primaryFile; |
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 | |
1217 | 319 | void PartDownloader::setPrimaryFile(LDDocument* document) |
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 | m_primaryFile = document; |
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 | QString PartDownloader::downloadPath() |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
325 | { |
1215 | 326 | QString path = config.downloadFilePath(); |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
327 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
328 | if (DIRSLASH[0] != '/') |
1217 | 329 | path.replace(DIRSLASH, "/"); |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
330 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
331 | return path; |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
332 | } |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
333 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
334 | QTableWidget* PartDownloader::progressTable() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
335 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
336 | return ui.progressTable; |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
337 | } |