src/partDownloader.cc

Sat, 22 Aug 2015 13:04:58 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 22 Aug 2015 13:04:58 +0300
branch
scripting
changeset 942
afbd122f3eff
parent 888
7ad8fb667084
child 891
00d76b281021
child 927
409b82a4765e
child 944
1a6f1997fcbe
permissions
-rw-r--r--

Commit work on scripting

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
844
11587d419d2f - changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents: 840
diff changeset
3 * Copyright (C) 2013, 2014 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 <QNetworkAccessManager>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QNetworkRequest>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QNetworkReply>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QDir>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QProgressBar>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #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
25 #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
26 #include <QMessageBox>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "partDownloader.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "ui_downloadfrom.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "basics.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "mainWindow.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "glRenderer.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
852
cbd89b33f70d - down with all these unnecessary semicolons!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
34 CFGENTRY (String, DownloadFilePath, "")
cbd89b33f70d - down with all these unnecessary semicolons!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
35 CFGENTRY (Bool, GuessDownloadPaths, true)
cbd89b33f70d - down with all these unnecessary semicolons!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
36 CFGENTRY (Bool, AutoCloseDownloadDialog, true)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 const QString g_unofficialLibraryURL ("http://ldraw.org/library/unofficial/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 void PartDownloader::staticBegin()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 {
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
44 PartDownloader dlg;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
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
46 if (not dlg.checkValidPath())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
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
49 dlg.exec();
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
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 QString PartDownloader::getDownloadPath()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
56 QString path = cfg::DownloadFilePath;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
58 if (DIRSLASH[0] != '/')
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
59 path.replace (DIRSLASH, "/");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 return path;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 //
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
66 PartDownloader::PartDownloader (QWidget* parent) :
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
67 QDialog (parent),
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
68 m_source (Source (0))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
70 setForm (new Ui_DownloadFrom);
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
71 form()->setupUi (this);
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
72 form()->fname->setFocus();
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
73
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
74 #ifdef USE_QT5
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
75 form()->progress->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch);
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
76 #else
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
77 form()->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch);
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
78 #endif
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 setDownloadButton (new QPushButton (tr ("Download")));
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
81 form()->buttonBox->addButton (downloadButton(), QDialogButtonBox::ActionRole);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 getButton (Abort)->setEnabled (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
84 connect (form()->source, SIGNAL (currentIndexChanged (int)),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 this, SLOT (sourceChanged (int)));
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
86 connect (form()->buttonBox, SIGNAL (clicked (QAbstractButton*)),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 this, SLOT (buttonClicked (QAbstractButton*)));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
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 PartDownloader::~PartDownloader()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
94 delete form();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 //
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
99 bool PartDownloader::checkValidPath()
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
100 {
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
101 QString path = getDownloadPath();
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
102
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
103 if (path.isEmpty() or not QDir (path).exists())
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
104 {
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
105 QMessageBox::information(this, "Notice", "Please input a path for files to download.");
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
106 path = QFileDialog::getExistingDirectory (this, "Path for downloaded files:");
7ad8fb667084 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
107
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
108 if (path.isEmpty())
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
109 return false;
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
110
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
111 cfg::DownloadFilePath = path;
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
112 }
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
113
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
114 return true;
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
115 }
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
116
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
117 // =============================================================================
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
118 //
839
5f822ad61875 - part downloader: update the input widget with the corrected part name when guesswork is done
Teemu Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
119 QString PartDownloader::getURL()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 const Source src = getSource();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 QString dest;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 switch (src)
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 case PartsTracker:
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
127 dest = form()->fname->text();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 modifyDestination (dest);
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
129 form()->fname->setText (dest);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 return g_unofficialLibraryURL + dest;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 case CustomURL:
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
133 return form()->fname->text();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 // Shouldn't happen
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 // =============================================================================
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 void PartDownloader::modifyDestination (QString& dest) const
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 dest = dest.simplified();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 // If the user doesn't want us to guess, stop right here.
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
147 if (not cfg::GuessDownloadPaths)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 // Ensure .dat extension
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 if (dest.right (4) != ".dat")
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 // Remove the existing extension, if any. It may be we're here over a
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 // typo in the .dat extension.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 const int dotpos = dest.lastIndexOf (".");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 839
diff changeset
157 if ((dotpos != -1) and (dotpos >= dest.length() - 4))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 dest.chop (dest.length() - dotpos);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 dest += ".dat";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 }
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 // If the part starts with s\ or s/, then use parts/s/. Same goes with
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 // 48\ and p/48/.
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
165 if (Eq (dest.left (2), "s\\", "s/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 dest.remove (0, 2);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 dest.prepend ("parts/s/");
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 814
diff changeset
169 }
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
170 elif (Eq (dest.left (3), "48\\", "48/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 dest.remove (0, 3);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 dest.prepend ("p/48/");
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 /* Try determine where to put this part. We have four directories:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 parts/, parts/s/, p/, and p/48/. If we haven't already specified
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 either parts/ or p/, we need to add it automatically. Part files
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 are numbers wit a possible u prefix for parts with unknown number
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 which can be followed by any of:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 - c** (composites)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 - d** (formed stickers)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 - p** (patterns)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 - a lowercase alphabetic letter for variants
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 Subfiles (usually) have an s** prefix, in which case we use parts/s/.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 Note that the regex starts with a '^' so it won't catch already fully
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 given part file names. */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 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
190 QString subpartRegex = partRegex + "s[0-9][0-9]+";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 partRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 subpartRegex += "\\.dat$";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 if (QRegExp (subpartRegex).exactMatch (dest))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 dest.prepend ("parts/s/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 elif (QRegExp (partRegex).exactMatch (dest))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 dest.prepend ("parts/");
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 839
diff changeset
199 elif (not dest.startsWith ("parts/") and not dest.startsWith ("p/"))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 dest.prepend ("p/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 PartDownloader::Source PartDownloader::getSource() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 {
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
207 return m_source;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
208 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
209
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
210 // =============================================================================
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
211 //
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
212 void PartDownloader::setSource (Source src)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
213 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
214 m_source = src;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
215 form()->source->setCurrentIndex (int (src));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 void PartDownloader::sourceChanged (int i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 if (i == CustomURL)
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
223 form()->fileNameLabel->setText (tr ("URL:"));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 else
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
225 form()->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
226
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
227 m_source = Source (i);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 void PartDownloader::buttonClicked (QAbstractButton* btn)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 if (btn == getButton (Close))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 reject();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 elif (btn == getButton (Abort))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 setAborted (true);
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 for (PartDownloadRequest* req : requests())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 req->abort();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 elif (btn == getButton (Download))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
247 QString dest = form()->fname->text();
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
248 setPrimaryFile (LDDocumentPtr());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 setAborted (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 if (getSource() == CustomURL)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
252 dest = Basename (getURL());
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 modifyDestination (dest);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest))
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
259 if (not Confirm (tr ("Overwrite?"), overwritemsg))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 downloadFile (dest, getURL(), true);
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 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266
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 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 void PartDownloader::downloadFile (QString dest, QString url, bool primary)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
271 const int row = form()->progress->rowCount();
655
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 // Don't download files repeadetly.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 if (filesToDownload().indexOf (dest) != -1)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
277 print ("Downloading %1 from %2\n", dest, url);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 modifyDestination (dest);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 m_filesToDownload << dest;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 m_requests << req;
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
282 form()->progress->insertRow (row);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 req->setTableRow (row);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 req->updateToTable();
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
285 downloadButton()->setEnabled (false);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
286 form()->progress->setEnabled (true);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
287 form()->fname->setEnabled (false);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
288 form()->source->setEnabled (false);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
289 getButton (Close)->setEnabled (false);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
290 getButton (Abort)->setEnabled (true);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
291 getButton (Download)->setEnabled (false);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
292 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
293
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
294 // =============================================================================
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
295 //
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
296 void PartDownloader::downloadFromPartsTracker (QString file)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
297 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
298 modifyDestination (file);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
299 downloadFile (file, g_unofficialLibraryURL + file, false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 void PartDownloader::checkIfFinished()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 bool failed = isAborted();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 // If there is some download still working, we're not finished.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 for (PartDownloadRequest* req : requests())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
311 if (not req->isFinished())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
314 if (req->state() == PartDownloadRequest::State::Failed)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 failed = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318 for (PartDownloadRequest* req : requests())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 delete req;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 m_requests.clear();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 // Update everything now
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 if (primaryFile() != null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 LDDocument::setCurrent (primaryFile());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 g_win->doFullRefresh();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 g_win->R()->resetAngles();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
331 for (LDDocumentPtr f : m_files)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
332 f->reloadAllSubfiles();
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
333
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
334 if (cfg::AutoCloseDownloadDialog and not failed)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 // Close automatically if desired.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 accept();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 // Allow the prompt be closed now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 getButton (Abort)->setEnabled (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 getButton (Close)->setEnabled (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 QPushButton* PartDownloader::getButton (PartDownloader::Button i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 switch (i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 case Download:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 return downloadButton();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 case Abort:
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
357 return qobject_cast<QPushButton*> (form()->buttonBox->button (QDialogButtonBox::Abort));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 case Close:
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
360 return qobject_cast<QPushButton*> (form()->buttonBox->button (QDialogButtonBox::Close));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 return null;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) :
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 QObject (parent),
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
370 m_state (State::Requesting),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 m_prompt (parent),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 m_url (url),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 m_destinaton (dest),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 m_filePath (PartDownloader::getDownloadPath() + DIRSLASH + dest),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 m_networkManager (new QNetworkAccessManager),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 m_isFirstUpdate (true),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 m_isPrimary (primary),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 m_filePointer (null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 // Make sure that we have a valid destination.
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
381 QString dirpath = Dirname (filePath());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 QDir dir (dirpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
385 if (not dir.exists())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 print ("Creating %1...\n", dirpath);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
389 if (not dir.mkpath (dirpath))
882
2f3cc8e045d5 - fixed compilation on windows
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
390 Critical (format (tr ("Couldn't create the directory %1!"), dirpath));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 setNetworkReply (networkManager()->get (QNetworkRequest (QUrl (url))));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 connect (networkReply(), SIGNAL (finished()), this, SLOT (downloadFinished()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 connect (networkReply(), SIGNAL (readyRead()), this, SLOT (readyRead()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 connect (networkReply(), SIGNAL (downloadProgress (qint64, qint64)),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 this, SLOT (downloadProgress (qint64, qint64)));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 PartDownloadRequest::~PartDownloadRequest() {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 void PartDownloadRequest::updateToTable()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 {
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
408 int const labelcol = PartDownloader::PartLabelColumn;
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
409 int const progcol = PartDownloader::ProgressColumn;
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
410 QTableWidget* table = prompt()->form()->progress;
814
c8ef30fd0e54 - refactored stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
411 QProgressBar* prog;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 switch (state())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 {
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
415 case State::Requesting:
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
416 case State::Downloading:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
420 if (not prog)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422 prog = new QProgressBar;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 table->setCellWidget (tableRow(), progcol, prog);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426 prog->setRange (0, numBytesTotal());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 prog->setValue (numBytesRead());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 } break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
430 case State::Finished:
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
431 case State::Failed:
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 {
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
433 const QString text = (state() == State::Finished)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 ? "<b><span style=\"color: #080\">FINISHED</span></b>"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 : "<b><span style=\"color: #800\">FAILED</span></b>";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 QLabel* lb = new QLabel (text);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 lb->setAlignment (Qt::AlignCenter);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 table->setCellWidget (tableRow(), progcol, lb);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 } break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 QLabel* lb = qobject_cast<QLabel*> (table->cellWidget (tableRow(), labelcol));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 if (isFirstUpdate())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447 lb = new QLabel (format ("<b>%1</b>", destinaton()), table);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 table->setCellWidget (tableRow(), labelcol, lb);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
450
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 // Make sure that the cell is big enough to contain the label
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 if (table->columnWidth (labelcol) < lb->width())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 table->setColumnWidth (labelcol, lb->width());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 setFirstUpdate (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 void PartDownloadRequest::downloadFinished()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 if (networkReply()->error() != QNetworkReply::NoError)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 839
diff changeset
464 if (isPrimary() and not prompt()->isAborted())
882
2f3cc8e045d5 - fixed compilation on windows
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
465 Critical (networkReply()->errorString());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
467 print ("Unable to download %1: %2\n", m_destinaton, networkReply()->errorString());
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
468 setState (State::Failed);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 }
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
470 elif (state() != State::Failed)
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
471 {
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
472 setState (State::Finished);
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
473 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
474
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 setNumBytesRead (numBytesTotal());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476 updateToTable();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478 if (filePointer())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
479 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 filePointer()->close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 delete filePointer();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482 setFilePointer (null);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
484 if (state() == State::Failed)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 QFile::remove (filePath());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
487
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
488 if (state() != State::Finished)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 prompt()->checkIfFinished();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494 // Try to load this file now.
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
495 LDDocumentPtr f = OpenDocument (filePath(), false, not isPrimary());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
497 if (f == null)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 // Iterate through this file and check for errors. If there's any that stems
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501 // from unknown file references, try resolve that by downloading the reference.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 // This is why downloading a part may end up downloading multiple files, as
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503 // it resolves dependencies.
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
504 for (LDObjectPtr obj : f->objects())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
505 {
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
506 LDErrorPtr err = obj.dynamicCast<LDError>();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 839
diff changeset
508 if ((err == null) or (err->fileReferenced().isEmpty()))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
509 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
510
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
511 QString dest = err->fileReferenced();
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
512 prompt()->downloadFromPartsTracker (dest);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
515 prompt()->addFile (f);
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
516
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
517 if (isPrimary())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518 {
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
519 AddRecentFile (filePath());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520 prompt()->setPrimaryFile (f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
522
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523 prompt()->checkIfFinished();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527 //
867
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
528 void PartDownloader::addFile (LDDocumentPtr f)
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
529 {
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
530 m_files << f;
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
531 }
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
532
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
533 // =============================================================================
557cb07dbe57 - now tries to download missing files off ldraw.org
Teemu Piippo <crimsondusk64@gmail.com>
parents: 865
diff changeset
534 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535 void PartDownloadRequest::downloadProgress (int64 recv, int64 total)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
536 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537 setNumBytesRead (recv);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538 setNumBytesTotal (total);
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
539 setState (State::Downloading);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540 updateToTable();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 void PartDownloadRequest::readyRead()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546 {
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
547 if (state() == State::Failed)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550 if (filePointer() == null)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
551 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
552 m_filePath.replace ("\\", "/");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554 // We have already asked the user whether we can overwrite so we're good
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
555 // to go here.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556 setFilePointer (new QFile (filePath().toLocal8Bit()));
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
557
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
558 if (not filePointer()->open (QIODevice::WriteOnly))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
559 {
882
2f3cc8e045d5 - fixed compilation on windows
Teemu Piippo <crimsondusk64@gmail.com>
parents: 867
diff changeset
560 Critical (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno)));
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
561 setState (State::Failed);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 networkReply()->abort();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 updateToTable();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564 prompt()->checkIfFinished();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
567 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
568
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
569 filePointer()->write (networkReply()->readAll());
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
570 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
571
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 bool PartDownloadRequest::isFinished() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
575 {
865
6d68840fcb26 - circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
576 return Eq (state(), State::Finished, State::Failed);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 void PartDownloadRequest::abort()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 networkReply()->abort();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
584 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 //
806
4240f47aa2d4 - moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
588 void MainWindow::slot_actionDownloadFrom()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 PartDownloader::staticBegin();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591 }

mercurial