Sat, 13 Feb 2016 04:14:43 +0200
Fixed line length warnings
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 |
1014
f0a8ecb6a357
Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1012
diff
changeset
|
3 | * Copyright (C) 2013 - 2016 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 | |
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
|
33 | ConfigOption (QString DownloadFilePath) |
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 | ConfigOption (bool GuessDownloadPaths = true) |
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
|
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 | |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
39 | PartDownloader::PartDownloader (QWidget* parent) : |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
40 | QDialog (parent), |
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
|
41 | HierarchyElement (parent), |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
42 | ui (*new Ui_PartDownloader), |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
43 | m_source (SourceType (0)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | { |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
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 |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
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 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
53 | m_downloadButton = new QPushButton (tr ("Download")); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
54 | ui.buttonBox->addButton (m_downloadButton, QDialogButtonBox::ActionRole); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
55 | button (Abort)->setEnabled (false); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
56 | connect (ui.source, SIGNAL (currentIndexChanged (int)), this, SLOT (sourceChanged (int))); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
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 | if (path.isEmpty() or not QDir (path).exists()) |
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."); |
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
|
72 | path = QFileDialog::getExistingDirectory (this, "Path for downloaded files:"); |
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 |
1012 | 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 | |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
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(); |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
89 | modifyDestination (destination); |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
90 | ui.filename->setText (destination); |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | void PartDownloader::modifyDestination (QString& dest) const |
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. |
1012 | 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 |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | if (dest.right (4) != ".dat") |
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. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | const int dotpos = dest.lastIndexOf ("."); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
840
d077dd19bf9a
- changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
839
diff
changeset
|
116 | if ((dotpos != -1) and (dotpos >= dest.length() - 4)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | dest.chop (dest.length() - dotpos); |
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/. |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
962
diff
changeset
|
124 | if (isOneOf (dest.left (2), "s\\", "s/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | dest.remove (0, 2); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | dest.prepend ("parts/s/"); |
816 | 128 | } |
967 | 129 | else if (isOneOf (dest.left (3), "48\\", "48/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | dest.remove (0, 3); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | dest.prepend ("p/48/"); |
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: |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | - c** (composites) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | - d** (formed stickers) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | - p** (patterns) |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | Subfiles (usually) have an s** prefix, in which case we use parts/s/. |
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | if (QRegExp (subpartRegex).exactMatch (dest)) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | dest.prepend ("parts/s/"); |
967 | 156 | else if (QRegExp (partRegex).exactMatch (dest)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | dest.prepend ("parts/"); |
967 | 158 | else if (not dest.startsWith ("parts/") and not dest.startsWith ("p/")) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | dest.prepend ("p/"); |
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 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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; |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | void PartDownloader::sourceChanged (int i) |
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) |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
176 | ui.fileNameLabel->setText (tr ("URL:")); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | else |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | void PartDownloader::buttonClicked (QAbstractButton* btn) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | { |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | } |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | } |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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(); |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
944
diff
changeset
|
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) |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
203 | dest = Basename (url()); |
655
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 | modifyDestination (dest); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
207 | if (QFile::exists (downloadPath() + DIRSLASH + dest)) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
855
diff
changeset
|
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 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | void PartDownloader::downloadFile (QString dest, QString url, bool primary) |
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. |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
867
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
226 | print ("Downloading %1 from %2\n", dest, url); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | modifyDestination (dest); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); |
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; |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
231 | ui.progressTable->insertRow (row); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | req->setTableRow (row); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | req->updateToTable(); |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
234 | m_downloadButton->setEnabled (false); |
994
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
235 | ui.progressTable->setEnabled (true); |
09e1a3e272ec
Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents:
993
diff
changeset
|
236 | ui.filename->setEnabled (false); |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
237 | ui.source->setEnabled (false); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
238 | button (Close)->setEnabled (false); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
239 | button (Abort)->setEnabled (true); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
243 | void PartDownloader::downloadFromPartsTracker (QString file) |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
244 | { |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
245 | modifyDestination (file); |
557cb07dbe57
- now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
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 | |
1012 | 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. |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
282 | button (Abort)->setEnabled (false); |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
287 | QPushButton* PartDownloader::button (PartDownloader::Button i) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | switch (i) |
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: |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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: |
993
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
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 | |
992
5a10b4e7bf4a
Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
304 | void PartDownloader::addFile (LDDocument* f) |
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 | |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
319 | void PartDownloader::setPrimaryFile (LDDocument* document) |
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 | { |
1012 | 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] != '/') |
23436e487f0c
Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents:
992
diff
changeset
|
329 | path.replace (DIRSLASH, "/"); |
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 | } |