src/partdownloader.cpp

Sun, 06 Sep 2015 16:57:22 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 06 Sep 2015 16:57:22 +0300
changeset 994
09e1a3e272ec
parent 993
src/partDownloader.cpp@23436e487f0c
child 1012
413ecd6b9801
permissions
-rw-r--r--

Split PartDownloadRequest into its own file
Moved ui/downloadfrom.ui to src/partdownloader.ui

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
968
4b93b7963456 Happy new year 2015
Teemu Piippo <crimsondusk64@gmail.com>
parents: 967
diff changeset
3 * Copyright (C) 2013 - 2015 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QDir>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QPushButton>
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
21 #include <QFileDialog>
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
22 #include <QMessageBox>
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
23 #include <QTableWidget>
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
24 #include "partdownloader.h"
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
25 #include "partdownloadrequest.h"
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
26 #include "ui_partdownloader.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "basics.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
28 #include "mainwindow.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "glRenderer.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
32 ConfigOption (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
33 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
34 ConfigOption (bool AutoCloseDownloadDialog = true)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
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
36 const char* g_unofficialLibraryURL = "http://ldraw.org/library/unofficial/";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
38 PartDownloader::PartDownloader (QWidget* parent) :
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
39 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
40 HierarchyElement (parent),
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
41 ui (*new Ui_PartDownloader),
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
42 m_source (SourceType (0))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 {
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
44 ui.setupUi (this);
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
45
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
46 #ifdef USE_QT5
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
47 ui.progressTable->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch);
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
48 #else
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
49 ui.progressTable->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch);
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
50 #endif
655
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 m_downloadButton = new QPushButton (tr ("Download"));
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
53 ui.buttonBox->addButton (m_downloadButton, QDialogButtonBox::ActionRole);
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
54 button (Abort)->setEnabled (false);
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
55 connect (ui.source, SIGNAL (currentIndexChanged (int)), this, SLOT (sourceChanged (int)));
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
56 connect (ui.buttonBox, SIGNAL (clicked (QAbstractButton*)), this, SLOT (buttonClicked (QAbstractButton*)));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 }
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 PartDownloader::~PartDownloader()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
61 delete &ui;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
64 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
65 {
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
66 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
67
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 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
69 {
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
70 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
71 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
72
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 if (path.isEmpty())
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
74 reject();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
75 else
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
76 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
77 }
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
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
80 QString PartDownloader::url()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
82 QString destination;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
84 switch (sourceType())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
86 case PartsTracker:
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
87 destination = ui.filename->text();
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
88 modifyDestination (destination);
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
89 ui.filename->setText (destination);
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
90 return g_unofficialLibraryURL + destination;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
92 case CustomURL:
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
93 return ui.filename->text();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 }
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 // Shouldn't happen
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
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 void PartDownloader::modifyDestination (QString& dest) const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 dest = dest.simplified();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 // If the user doesn't want us to guess, stop right here.
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
105 if (not m_config->guessDownloadPaths())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 // Ensure .dat extension
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 if (dest.right (4) != ".dat")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 // 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
112 // typo in the .dat extension.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 const int dotpos = dest.lastIndexOf (".");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 839
diff changeset
115 if ((dotpos != -1) and (dotpos >= dest.length() - 4))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 dest.chop (dest.length() - dotpos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 dest += ".dat";
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 // 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
122 // 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
123 if (isOneOf (dest.left (2), "s\\", "s/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 dest.remove (0, 2);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 dest.prepend ("parts/s/");
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 814
diff changeset
127 }
967
eb586d3e1a6a elif -> else if
Teemu Piippo <crimsondusk64@gmail.com>
parents: 966
diff changeset
128 else if (isOneOf (dest.left (3), "48\\", "48/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 dest.remove (0, 3);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 dest.prepend ("p/48/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 }
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 /* Try determine where to put this part. We have four directories:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 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
136 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
137 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
138 which can be followed by any of:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 - c** (composites)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 - d** (formed stickers)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 - p** (patterns)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 - a lowercase alphabetic letter for variants
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 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
145 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
146 given part file names. */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 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
148 QString subpartRegex = partRegex + "s[0-9][0-9]+";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 partRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 subpartRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 if (QRegExp (subpartRegex).exactMatch (dest))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 dest.prepend ("parts/s/");
967
eb586d3e1a6a elif -> else if
Teemu Piippo <crimsondusk64@gmail.com>
parents: 966
diff changeset
155 else if (QRegExp (partRegex).exactMatch (dest))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 dest.prepend ("parts/");
967
eb586d3e1a6a elif -> else if
Teemu Piippo <crimsondusk64@gmail.com>
parents: 966
diff changeset
157 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
158 dest.prepend ("p/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
161 PartDownloader::SourceType PartDownloader::sourceType() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 {
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
163 return m_source;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
164 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
165
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
166 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
167 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
168 m_source = src;
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
169 ui.source->setCurrentIndex (int (src));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 }
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 void PartDownloader::sourceChanged (int i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 if (i == CustomURL)
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
175 ui.fileNameLabel->setText (tr ("URL:"));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 else
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
177 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
178
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
179 m_source = SourceType (i);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 }
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 void PartDownloader::buttonClicked (QAbstractButton* btn)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 {
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
184 if (btn == button (Close))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 reject();
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 else if (btn == button (Abort))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 {
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
190 m_isAborted = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
192 for (PartDownloadRequest* req : m_requests)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 req->abort();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 }
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
195 else if (btn == button (Download))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
197 QString dest = ui.filename->text();
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
198 setPrimaryFile (nullptr);
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
199 m_isAborted = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
201 if (sourceType() == CustomURL)
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
202 dest = Basename (url());
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 modifyDestination (dest);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
206 if (QFile::exists (downloadPath() + DIRSLASH + dest))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 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
209 if (not Confirm (tr ("Overwrite?"), overwritemsg))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
213 downloadFile (dest, url(), true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 }
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 void PartDownloader::downloadFile (QString dest, QString url, bool primary)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
219 int row = ui.progressTable->rowCount();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 // Don't download files repeadetly.
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
222 if (m_filesToDownload.indexOf (dest) != -1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
225 print ("Downloading %1 from %2\n", dest, url);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 modifyDestination (dest);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 m_filesToDownload << dest;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 m_requests << req;
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
230 ui.progressTable->insertRow (row);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 req->setTableRow (row);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 req->updateToTable();
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
233 m_downloadButton->setEnabled (false);
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
234 ui.progressTable->setEnabled (true);
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
235 ui.filename->setEnabled (false);
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
236 ui.source->setEnabled (false);
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
237 button (Close)->setEnabled (false);
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
238 button (Abort)->setEnabled (true);
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
239 button (Download)->setEnabled (false);
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
240 }
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 void PartDownloader::downloadFromPartsTracker (QString file)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
243 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
244 modifyDestination (file);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
245 downloadFile (file, g_unofficialLibraryURL + file, false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 }
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 void PartDownloader::checkIfFinished()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 bool failed = isAborted();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 // If there is some download still working, we're not finished.
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
253 for (PartDownloadRequest* req : m_requests)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 {
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
255 if (not req->isFinished())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
258 if (req->failed())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 failed = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
262 for (PartDownloadRequest* req : m_requests)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 delete req;
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 m_requests.clear();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
267 if (primaryFile())
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
268 emit primaryFileDownloaded();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
270 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
271 f->reloadAllSubfiles();
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
272
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
273 if (m_config->autoCloseDownloadDialog() and not failed)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 // Close automatically if desired.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 accept();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 // Allow the prompt be closed now.
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
281 button (Abort)->setEnabled (false);
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
282 button (Close)->setEnabled (true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 }
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
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
286 QPushButton* PartDownloader::button (PartDownloader::Button i)
655
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 switch (i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 case Download:
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
291 return m_downloadButton;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 case Abort:
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
294 return qobject_cast<QPushButton*> (ui.buttonBox->button (QDialogButtonBox::Abort));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 case Close:
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
297 return qobject_cast<QPushButton*> (ui.buttonBox->button (QDialogButtonBox::Close));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
300 return nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
303 void PartDownloader::addFile (LDDocument* f)
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
304 {
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
305 m_files << f;
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
306 }
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
307
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
308 bool PartDownloader::isAborted() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
309 {
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
310 return m_isAborted;
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
311 }
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 LDDocument* PartDownloader::primaryFile() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
314 {
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
315 return m_primaryFile;
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
316 }
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 void PartDownloader::setPrimaryFile (LDDocument* document)
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
319 {
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
320 m_primaryFile = document;
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
321 }
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 QString PartDownloader::downloadPath()
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
324 {
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
325 QString path = m_config->downloadFilePath();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
326
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
327 if (DIRSLASH[0] != '/')
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
328 path.replace (DIRSLASH, "/");
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
329
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
330 return path;
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
331 }
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 QTableWidget* PartDownloader::progressTable() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
334 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
335 return ui.progressTable;
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
336 }

mercurial