src/partdownloader.cpp

Mon, 04 Jun 2018 23:22:52 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 04 Jun 2018 23:22:52 +0300
changeset 1392
0541d9b21968
parent 1332
1fffb24d4ffe
permissions
-rw-r--r--

fix compiler warnings

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QPushButton>
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
20 #include <QFileDialog>
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
21 #include <QMessageBox>
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
22 #include "partdownloader.h"
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
23 #include "partdownloadrequest.h"
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
24 #include "ui_partdownloader.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
25 #include "mainwindow.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1144
diff changeset
26 #include "lddocument.h"
1144
4f226fd97826 Renamed glRenderer.cpp → glrenderer.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
27 #include "glrenderer.h"
1012
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 994
diff changeset
28 #include "documentmanager.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
30 const char* g_unofficialLibraryURL = "http://ldraw.org/library/unofficial/";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
32 PartDownloader::PartDownloader (QWidget* parent)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
33 : QDialog(parent)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
34 , HierarchyElement(parent)
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
35 , _ui(*new Ui_PartDownloader)
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
36 , _source(SourceType{})
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
38 _ui.setupUi(this);
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
39 _ui.progressTable->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch);
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
40 _downloadButton = new QPushButton {tr("Download")};
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
41 _ui.buttonBox->addButton(_downloadButton, QDialogButtonBox::ActionRole);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
42 button(Abort)->setEnabled(false);
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
43 connect(_ui.source, SIGNAL(currentIndexChanged(int)), this, SLOT(sourceChanged(int)));
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
44 connect(_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 PartDownloader::~PartDownloader()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
49 delete &_ui;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
52 void PartDownloader::checkValidPath()
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
53 {
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
54 QString path = downloadPath();
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
55
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
56 if (path.isEmpty() or not QDir {path}.exists())
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
57 {
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
58 QMessageBox::information(this, "Notice", "Please input a path for files to download.");
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
59 path = QFileDialog::getExistingDirectory(this, "Path for downloaded files:");
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
60
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
61 if (path.isEmpty())
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
62 reject();
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
63 else
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1263
diff changeset
64 config::setDownloadFilePath(path);
888
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
65 }
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
66 }
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
67
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
68 QString PartDownloader::url()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
70 switch (sourceType())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 {
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
72 case PartsTracker:
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
73 {
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
74 QString destination;
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
75 destination = _ui.filename->text();
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
76 modifyDestination(destination);
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
77 _ui.filename->setText(destination);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
78 return g_unofficialLibraryURL + destination;
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
79 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
994
09e1a3e272ec Split PartDownloadRequest into its own file
Teemu Piippo <crimsondusk64@gmail.com>
parents: 993
diff changeset
81 case CustomURL:
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
82 return _ui.filename->text();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
88 void PartDownloader::modifyDestination(QString& destination) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
90 destination = destination.simplified();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 // If the user doesn't want us to guess, stop right here.
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1263
diff changeset
93 if (not config::guessDownloadPaths())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 // Ensure .dat extension
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
97 if (destination.right (4) != ".dat")
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
99 // Remove the existing extension, if any. It may be we're here over a typo in the .dat extension.
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
100 int dotPosition = destination.lastIndexOf(".");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1064
diff changeset
102 if ((dotPosition != -1) and (dotPosition >= countof(destination) - 4))
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1064
diff changeset
103 destination.chop(countof(destination) - dotPosition);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
105 destination += ".dat";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
108 // If the part starts with s\ or s/, then use parts/s/. Same goes with 48\ and p/48/.
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
109 if (isOneOf(destination.left(2), "s\\", "s/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
111 destination.remove(0, 2);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
112 destination.prepend("parts/s/");
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 814
diff changeset
113 }
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
114 else if (isOneOf(destination.left(3), "48\\", "48/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
116 destination.remove(0, 3);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
117 destination.prepend("p/48/");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 }
1330
9155a6b153f3 Used more Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
119 else if (isOneOf(destination.left(2), "8\\", "8/"))
9155a6b153f3 Used more Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
120 {
9155a6b153f3 Used more Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
121 destination.remove(0, 2);
9155a6b153f3 Used more Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
122 destination.prepend("p/8/");
9155a6b153f3 Used more Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
123 }
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 /* Try determine where to put this part. We have four directories:
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
126 * 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
127 * either parts/ or p/, we need to add it automatically. Part files
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
128 * are numbers wit a possible u prefix for parts with unknown number
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
129 * which can be followed by any of:
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
130 * - c** (composites)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
131 * - d** (formed stickers)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
132 * - p** (patterns)
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
133 * - a lowercase alphabetic letter for variants
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
134 *
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
135 * 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
136 * 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
137 * given part file names.
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
138 */
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 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
140 QString subpartRegex = partRegex + "s[0-9][0-9]+";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 partRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 subpartRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
145 if (QRegExp {subpartRegex}.exactMatch(destination))
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
146 destination.prepend("parts/s/");
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
147 else if (QRegExp {partRegex}.exactMatch(destination))
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
148 destination.prepend("parts/");
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
149 else if (not destination.startsWith("parts/") and not destination.startsWith("p/"))
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
150 destination.prepend("p/");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
153 PartDownloader::SourceType PartDownloader::sourceType() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
155 return _source;
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
156 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
157
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
158 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
159 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
160 _source = src;
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
161 _ui.source->setCurrentIndex(int {src});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
164 void PartDownloader::sourceChanged(int sourceType)
655
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 if (sourceType == CustomURL)
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
167 _ui.fileNameLabel->setText(tr("URL:"));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 else
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
169 _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
170
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
171 _source = static_cast<SourceType>(sourceType);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
174 void PartDownloader::buttonClicked(QAbstractButton* button)
655
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 if (button == this->button(Close))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 reject();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 }
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
180 else if (button == this->button(Abort))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
182 _isAborted = true;
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 for (PartDownloadRequest* request : _requests)
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
185 request->abort();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 }
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
187 else if (button == this->button(Download))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
189 QString destination = _ui.filename->text();
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
190 setPrimaryFile (nullptr);
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
191 _isAborted = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
193 if (sourceType() == CustomURL)
1332
1fffb24d4ffe replaced remaining DIRSLASH, Dirname and Basename uses with Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1330
diff changeset
194 destination = QUrl {url()}.fileName();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
196 modifyDestination(destination);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
1332
1fffb24d4ffe replaced remaining DIRSLASH, Dirname and Basename uses with Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1330
diff changeset
198 if (QDir {downloadPath()}.exists(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 QString message = format(tr("%1 already exists in download directory. Overwrite?"), destination);
1156
c20ee66b6705 Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
201 int answer = QMessageBox::question(this, tr("Overwrite"), message, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No);
c20ee66b6705 Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
202
c20ee66b6705 Removed the Critical and Question functions, replaced with direct QMessageBox uses. Removed unused code from mainwindow.h.
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
203 if (answer != QMessageBox::Yes)
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
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1263
diff changeset
263 if (config::autoCloseDownloadDialog() and not failed)
655
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 // Close automatically if desired.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 accept();
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 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 // Allow the prompt be closed now.
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
271 button(Abort)->setEnabled(false);
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
272 button(Close)->setEnabled(true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 }
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
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
276 QAbstractButton* PartDownloader::button(PartDownloader::Button which)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
278 switch (which)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 {
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
280 case Download:
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
281 return _downloadButton;
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 Abort:
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
284 return _ui.buttonBox->button(QDialogButtonBox::Abort);
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 Close:
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::Close);
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
288
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
289 default:
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
290 return nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291 }
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
1046
f4a7b56c7eb2 Cleanup PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
294 void PartDownloader::addFile(LDDocument* file)
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
295 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
296 _files.append(file);
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
297 }
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
298
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
299 bool PartDownloader::isAborted() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
300 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
301 return _isAborted;
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
302 }
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
303
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
304 LDDocument* PartDownloader::primaryFile() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
305 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
306 return _primaryFile;
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
307 }
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
308
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
309 void PartDownloader::setPrimaryFile (LDDocument* document)
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
310 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
311 _primaryFile = document;
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
312 }
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
313
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
314 QString PartDownloader::downloadPath()
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
315 {
1332
1fffb24d4ffe replaced remaining DIRSLASH, Dirname and Basename uses with Qt file info stuff
Teemu Piippo <teemu@hecknology.net>
parents: 1330
diff changeset
316 return config::downloadFilePath();
993
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
317 }
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
318
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
319 QTableWidget* PartDownloader::progressTable() const
23436e487f0c Refactor PartDownloader
Teemu Piippo <crimsondusk64@gmail.com>
parents: 992
diff changeset
320 {
1048
7b778aa2eff2 Change "m_" prefix to "_" in members of PartDownloader
Teemu Piippo <teemu@hecknology.net>
parents: 1046
diff changeset
321 return _ui.progressTable;
992
5a10b4e7bf4a Refactor PartDownloadRequest
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
322 }

mercurial