src/partdownloader.cpp

Sat, 28 Jan 2017 17:20:16 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 28 Jan 2017 17:20:16 +0200
changeset 1069
220cde0fa2d9
parent 1065
c8ecddbd99e9
child 1072
9ce9496427f2
permissions
-rw-r--r--

Removed the dangerous C-array constructor from the matrix - no need for it anyway since the matrix already is an array of doubles.

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
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 994
diff changeset
31 #include "documentmanager.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
33 ConfigOption(QString DownloadFilePath)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
34 ConfigOption(bool GuessDownloadPaths = true)
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
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
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
39 PartDownloader::PartDownloader (QWidget* parent)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
40 : QDialog(parent)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
41 , HierarchyElement(parent)
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
42 , _ui(*new Ui_PartDownloader)
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
43 , _source(SourceType{})
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
45 _ui.setupUi(this);
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
46 _ui.progressTable->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch);
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
47 _downloadButton = new QPushButton {tr("Download")};
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
48 _ui.buttonBox->addButton(_downloadButton, QDialogButtonBox::ActionRole);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
49 button(Abort)->setEnabled(false);
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
50 connect(_ui.source, SIGNAL(currentIndexChanged(int)), this, SLOT(sourceChanged(int)));
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
51 connect(_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 PartDownloader::~PartDownloader()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
56 delete &_ui;
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
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
59 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
60 {
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
61 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
62
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
63 if (path.isEmpty() or not QDir {path}.exists())
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
64 {
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
65 QMessageBox::information(this, "Notice", "Please input a path for files to download.");
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
66 path = QFileDialog::getExistingDirectory(this, "Path for downloaded files:");
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
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())
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
69 reject();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
70 else
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
71 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
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 }
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
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
75 QString PartDownloader::url()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
77 switch (sourceType())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
79 case PartsTracker:
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
80 {
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
81 QString destination;
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
82 destination = _ui.filename->text();
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
83 modifyDestination(destination);
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
84 _ui.filename->setText(destination);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
85 return g_unofficialLibraryURL + destination;
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
86 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
88 case CustomURL:
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
89 return _ui.filename->text();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
95 void PartDownloader::modifyDestination(QString& destination) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
97 destination = destination.simplified();
655
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 // If the user doesn't want us to guess, stop right here.
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
100 if (not m_config->guessDownloadPaths())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 return;
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 // Ensure .dat extension
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
104 if (destination.right (4) != ".dat")
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
106 // Remove the existing extension, if any. It may be we're here over a typo in the .dat extension.
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
107 int dotPosition = destination.lastIndexOf(".");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1064
diff changeset
109 if ((dotPosition != -1) and (dotPosition >= countof(destination) - 4))
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1064
diff changeset
110 destination.chop(countof(destination) - dotPosition);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
112 destination += ".dat";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
115 // If the part starts with s\ or s/, then use parts/s/. Same goes with 48\ and p/48/.
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
116 if (isOneOf(destination.left(2), "s\\", "s/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
118 destination.remove(0, 2);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
119 destination.prepend("parts/s/");
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 814
diff changeset
120 }
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
121 else if (isOneOf(destination.left(3), "48\\", "48/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
123 destination.remove(0, 3);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
124 destination.prepend("p/48/");
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 /* Try determine where to put this part. We have four directories:
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
128 * parts/, parts/s/, p/, and p/48/. If we haven't already specified
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
129 * either parts/ or p/, we need to add it automatically. Part files
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
130 * are numbers wit a possible u prefix for parts with unknown number
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
131 * which can be followed by any of:
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
132 * - c** (composites)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
133 * - d** (formed stickers)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
134 * - p** (patterns)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
135 * - a lowercase alphabetic letter for variants
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
136 *
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
137 * Subfiles (usually) have an s** prefix, in which case we use parts/s/.
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
138 * Note that the regex starts with a '^' so it won't catch already fully
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
139 * given part file names.
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
140 */
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 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
142 QString subpartRegex = partRegex + "s[0-9][0-9]+";
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 partRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 subpartRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
147 if (QRegExp {subpartRegex}.exactMatch(destination))
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
148 destination.prepend("parts/s/");
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
149 else if (QRegExp {partRegex}.exactMatch(destination))
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
150 destination.prepend("parts/");
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
151 else if (not destination.startsWith("parts/") and not destination.startsWith("p/"))
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
152 destination.prepend("p/");
655
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
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
155 PartDownloader::SourceType PartDownloader::sourceType() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
157 return _source;
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
158 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
159
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
160 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
161 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
162 _source = src;
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
163 _ui.source->setCurrentIndex(int {src});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
166 void PartDownloader::sourceChanged(int sourceType)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
168 if (sourceType == CustomURL)
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
169 _ui.fileNameLabel->setText(tr("URL:"));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 else
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
171 _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
172
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
173 _source = static_cast<SourceType>(sourceType);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
176 void PartDownloader::buttonClicked(QAbstractButton* button)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
178 if (button == this->button(Close))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 reject();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 }
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
182 else if (button == this->button(Abort))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
184 _isAborted = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
186 for (PartDownloadRequest* request : _requests)
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
187 request->abort();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 }
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
189 else if (button == this->button(Download))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
191 QString destination = _ui.filename->text();
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
192 setPrimaryFile (nullptr);
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
193 _isAborted = false;
655
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 if (sourceType() == CustomURL)
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
196 destination = Basename(url());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
198 modifyDestination(destination);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
200 if (QFile::exists(downloadPath() + DIRSLASH + destination))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
202 QString message = format(tr("%1 already exists in download directory. Overwrite?"), destination);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
203 if (not Confirm(tr("Overwrite?"), message))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
207 downloadFile (destination, url(), true);
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 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
211 void PartDownloader::downloadFile(QString destination, QString url, bool isPrimary)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
213 int row = _ui.progressTable->rowCount();
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 // Don't download files repeadetly.
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
216 if (not _filesToDownload.contains(destination))
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
217 {
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
218 print ("Downloading %1 from %2\n", destination, url);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
219 modifyDestination (destination);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
220 PartDownloadRequest* request = new PartDownloadRequest {url, destination, isPrimary, this};
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
221 _filesToDownload << destination;
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
222 _requests << request;
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
223 _ui.progressTable->insertRow(row);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
224 request->setTableRow(row);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
225 request->updateToTable();
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
226 _downloadButton->setEnabled(false);
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
227 _ui.progressTable->setEnabled(true);
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
228 _ui.filename->setEnabled(false);
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
229 _ui.source->setEnabled(false);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
230 button(Close)->setEnabled(false);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
231 button(Abort)->setEnabled(true);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
232 button(Download)->setEnabled(false);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
233 }
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
234 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
235
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
236 void PartDownloader::downloadFromPartsTracker (QString file)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
237 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
238 modifyDestination(file);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
239 downloadFile(file, g_unofficialLibraryURL + file, false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 void PartDownloader::checkIfFinished()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 bool failed = isAborted();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 // If there is some download still working, we're not finished.
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
247 for (PartDownloadRequest* request : _requests)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
249 if (not request->isFinished())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
252 failed |= request->failed();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
255 for (PartDownloadRequest* request : _requests)
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
256 delete request;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
258 _requests.clear();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
260 if (primaryFile())
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
261 emit primaryFileDownloaded();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
263 for (LDDocument* file : _files)
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
264 file->reloadAllSubfiles();
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
265
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
266 if (m_config->autoCloseDownloadDialog() and not failed)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 // Close automatically if desired.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 accept();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 // Allow the prompt be closed now.
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
274 button(Abort)->setEnabled(false);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
275 button(Close)->setEnabled(true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 }
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
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
279 QAbstractButton* PartDownloader::button(PartDownloader::Button which)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
281 switch (which)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
283 case Download:
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
284 return _downloadButton;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
286 case Abort:
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
287 return _ui.buttonBox->button(QDialogButtonBox::Abort);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
289 case Close:
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
290 return _ui.buttonBox->button(QDialogButtonBox::Close);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
291
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
292 default:
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
293 return nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 }
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
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
297 void PartDownloader::addFile(LDDocument* file)
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
298 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
299 _files.append(file);
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
300 }
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
301
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
302 bool PartDownloader::isAborted() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
303 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
304 return _isAborted;
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
305 }
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
306
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
307 LDDocument* PartDownloader::primaryFile() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
308 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
309 return _primaryFile;
993
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
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
312 void PartDownloader::setPrimaryFile (LDDocument* document)
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
313 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
314 _primaryFile = document;
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
315 }
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
316
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
317 QString PartDownloader::downloadPath()
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
318 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
319 QString path = m_config->downloadFilePath();
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
320
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
321 if (DIRSLASH[0] != '/')
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
322 path.replace(DIRSLASH, "/");
993
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 return path;
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
325 }
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 QTableWidget* PartDownloader::progressTable() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
328 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
329 return _ui.progressTable;
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
330 }

mercurial