Sat, 17 Mar 2018 11:33:05 +0200
Part history can now be edited
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" |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1144
diff
changeset
|
26 | #include "lddocument.h" |
1144
4f226fd97826
Renamed glRenderer.cpp → glrenderer.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1125
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 | |
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
|
30 | const char* g_unofficialLibraryURL = "http://ldraw.org/library/unofficial/"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
32 | PartDownloader::PartDownloader (QWidget* parent) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
33 | : QDialog(parent) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
34 | , HierarchyElement(parent) |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
35 | , _ui(*new Ui_PartDownloader) |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
36 | , _source(SourceType{}) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
38 | _ui.setupUi(this); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
39 | _ui.progressTable->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
40 | _downloadButton = new QPushButton {tr("Download")}; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
41 | _ui.buttonBox->addButton(_downloadButton, QDialogButtonBox::ActionRole); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
42 | button(Abort)->setEnabled(false); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
43 | 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
|
44 | connect(_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | PartDownloader::~PartDownloader() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
49 | delete &_ui; |
655
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 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
52 | 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
|
53 | { |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
54 | 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
|
55 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
56 | 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
|
57 | { |
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
|
58 | 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
|
59 | 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
|
60 | |
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 | if (path.isEmpty()) |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
62 | reject(); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
63 | else |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
64 | 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
|
65 | } |
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 | } |
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
|
67 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
68 | QString PartDownloader::url() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
70 | switch (sourceType()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | { |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
72 | case PartsTracker: |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
73 | { |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
74 | QString destination; |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
75 | destination = _ui.filename->text(); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
76 | modifyDestination(destination); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
77 | _ui.filename->setText(destination); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
78 | return g_unofficialLibraryURL + destination; |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
79 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
81 | case CustomURL: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
82 | return _ui.filename->text(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | return ""; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
88 | void PartDownloader::modifyDestination(QString& destination) const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
90 | destination = destination.simplified(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | // 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
|
93 | if (not m_config->guessDownloadPaths()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | return; |
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 | // Ensure .dat extension |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
97 | if (destination.right (4) != ".dat") |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
99 | // 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
|
100 | int dotPosition = destination.lastIndexOf("."); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
102 | 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
|
103 | destination.chop(countof(destination) - dotPosition); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
105 | destination += ".dat"; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
108 | // 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
|
109 | if (isOneOf(destination.left(2), "s\\", "s/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
111 | destination.remove(0, 2); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
112 | destination.prepend("parts/s/"); |
816 | 113 | } |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
114 | else if (isOneOf(destination.left(3), "48\\", "48/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
116 | destination.remove(0, 3); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
117 | destination.prepend("p/48/"); |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | /* Try determine where to put this part. We have four directories: |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
121 | * 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
|
122 | * either parts/ or p/, we need to add it automatically. Part files |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
123 | * are numbers wit a possible u prefix for parts with unknown number |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
124 | * which can be followed by any of: |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
125 | * - c** (composites) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
126 | * - d** (formed stickers) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
127 | * - p** (patterns) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
128 | * - a lowercase alphabetic letter for variants |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
129 | * |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
130 | * 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
|
131 | * 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
|
132 | * given part file names. |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
133 | */ |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | 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
|
135 | QString subpartRegex = partRegex + "s[0-9][0-9]+"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | partRegex += "\\.dat$"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | subpartRegex += "\\.dat$"; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
140 | if (QRegExp {subpartRegex}.exactMatch(destination)) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
141 | destination.prepend("parts/s/"); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
142 | else if (QRegExp {partRegex}.exactMatch(destination)) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
143 | destination.prepend("parts/"); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
144 | else if (not destination.startsWith("parts/") and not destination.startsWith("p/")) |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
145 | destination.prepend("p/"); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
148 | PartDownloader::SourceType PartDownloader::sourceType() const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
150 | return _source; |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
151 | } |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
152 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
153 | 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
|
154 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
155 | _source = src; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
156 | _ui.source->setCurrentIndex(int {src}); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
159 | void PartDownloader::sourceChanged(int sourceType) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
161 | if (sourceType == CustomURL) |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
162 | _ui.fileNameLabel->setText(tr("URL:")); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | else |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
164 | _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
|
165 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
166 | _source = static_cast<SourceType>(sourceType); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
169 | void PartDownloader::buttonClicked(QAbstractButton* button) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
171 | if (button == this->button(Close)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | reject(); |
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 | else if (button == this->button(Abort)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
177 | _isAborted = true; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
179 | for (PartDownloadRequest* request : _requests) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
180 | request->abort(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | } |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
182 | else if (button == this->button(Download)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
184 | QString destination = _ui.filename->text(); |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
944
diff
changeset
|
185 | setPrimaryFile (nullptr); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
186 | _isAborted = false; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
188 | if (sourceType() == CustomURL) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
189 | destination = Basename(url()); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
191 | modifyDestination(destination); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
193 | if (QFile::exists(downloadPath() + DIRSLASH + destination)) |
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 | QString message = format(tr("%1 already exists in download directory. Overwrite?"), destination); |
1156
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1145
diff
changeset
|
196 | int answer = QMessageBox::question(this, tr("Overwrite"), message, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No); |
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1145
diff
changeset
|
197 | |
c20ee66b6705
Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents:
1145
diff
changeset
|
198 | if (answer != QMessageBox::Yes) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
202 | downloadFile (destination, url(), true); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
206 | void PartDownloader::downloadFile(QString destination, QString url, bool isPrimary) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
208 | int row = _ui.progressTable->rowCount(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | // Don't download files repeadetly. |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
211 | if (not _filesToDownload.contains(destination)) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
212 | { |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
213 | print ("Downloading %1 from %2\n", destination, url); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
214 | modifyDestination (destination); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
215 | 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
|
216 | _filesToDownload << destination; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
217 | _requests << request; |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
218 | _ui.progressTable->insertRow(row); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
219 | request->setTableRow(row); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
220 | request->updateToTable(); |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
221 | _downloadButton->setEnabled(false); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
222 | _ui.progressTable->setEnabled(true); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
223 | _ui.filename->setEnabled(false); |
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
224 | _ui.source->setEnabled(false); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
225 | button(Close)->setEnabled(false); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
226 | button(Abort)->setEnabled(true); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
227 | button(Download)->setEnabled(false); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
228 | } |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
229 | } |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
230 | |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
231 | void PartDownloader::downloadFromPartsTracker (QString file) |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
232 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
233 | modifyDestination(file); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
234 | downloadFile(file, g_unofficialLibraryURL + file, false); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | void PartDownloader::checkIfFinished() |
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 | bool failed = isAborted(); |
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 | // 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
|
242 | for (PartDownloadRequest* request : _requests) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
244 | if (not request->isFinished()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | return; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
247 | failed |= request->failed(); |
655
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 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
250 | for (PartDownloadRequest* request : _requests) |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
251 | delete request; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
253 | _requests.clear(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | |
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
255 | if (primaryFile()) |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
256 | emit primaryFileDownloaded(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | |
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
|
258 | if (m_config->autoCloseDownloadDialog() and not failed) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | // Close automatically if desired. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | accept(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | else |
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 | // Allow the prompt be closed now. |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
266 | button(Abort)->setEnabled(false); |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
267 | button(Close)->setEnabled(true); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | } |
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 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
271 | QAbstractButton* PartDownloader::button(PartDownloader::Button which) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
273 | switch (which) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | { |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
275 | case Download: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
276 | return _downloadButton; |
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 | case Abort: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
279 | return _ui.buttonBox->button(QDialogButtonBox::Abort); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
281 | case Close: |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
282 | return _ui.buttonBox->button(QDialogButtonBox::Close); |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
283 | |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
284 | default: |
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
285 | return nullptr; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
289 | void PartDownloader::addFile(LDDocument* file) |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
290 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
291 | _files.append(file); |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
292 | } |
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
293 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
294 | bool PartDownloader::isAborted() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
295 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
296 | return _isAborted; |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
297 | } |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
298 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
299 | LDDocument* PartDownloader::primaryFile() 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 _primaryFile; |
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 | void PartDownloader::setPrimaryFile (LDDocument* document) |
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 | _primaryFile = document; |
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 | QString PartDownloader::downloadPath() |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
310 | { |
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
|
311 | QString path = m_config->downloadFilePath(); |
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 | if (DIRSLASH[0] != '/') |
1046
f4a7b56c7eb2
Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
314 | path.replace(DIRSLASH, "/"); |
993
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 path; |
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 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
319 | QTableWidget* PartDownloader::progressTable() const |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
320 | { |
1048
7b778aa2eff2
Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents:
1046
diff
changeset
|
321 | return _ui.progressTable; |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
322 | } |