diff options
Diffstat (limited to 'rbutil/rbutilqt/install.cpp')
-rw-r--r-- | rbutil/rbutilqt/install.cpp | 116 |
1 files changed, 11 insertions, 105 deletions
diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp index 5f64261417..ee1b21c8e6 100644 --- a/rbutil/rbutilqt/install.cpp +++ b/rbutil/rbutilqt/install.cpp | |||
@@ -20,12 +20,7 @@ | |||
20 | #include "install.h" | 20 | #include "install.h" |
21 | #include "ui_installfrm.h" | 21 | #include "ui_installfrm.h" |
22 | #include "ui_installprogressfrm.h" | 22 | #include "ui_installprogressfrm.h" |
23 | #include "httpget.h" | ||
24 | #include "zip/zip.h" | ||
25 | #include "zip/unzip.h" | ||
26 | 23 | ||
27 | #include <QtGui> | ||
28 | #include <QtNetwork> | ||
29 | 24 | ||
30 | Install::Install(QWidget *parent) : QDialog(parent) | 25 | Install::Install(QWidget *parent) : QDialog(parent) |
31 | { | 26 | { |
@@ -150,108 +145,27 @@ void Install::accept() | |||
150 | } | 145 | } |
151 | userSettings->sync(); | 146 | userSettings->sync(); |
152 | 147 | ||
153 | dp.listProgress->addItem(tr("Downloading file %1.%2") | 148 | installer = new RBInstaller(this); |
154 | .arg(QFileInfo(file).baseName(), QFileInfo(file).completeSuffix())); | 149 | installer->install(file,fileName,mountPoint,proxy, &dp); |
155 | 150 | ||
156 | // temporary file needs to be opened to get the filename | 151 | connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool))); |
157 | downloadFile.open(); | 152 | |
158 | fileName = downloadFile.fileName(); | ||
159 | downloadFile.close(); | ||
160 | // get the real file. | ||
161 | getter = new HttpGet(this); | ||
162 | getter->setProxy(proxy); | ||
163 | getter->setFile(&downloadFile); | ||
164 | |||
165 | getter->getFile(QUrl(file)); | ||
166 | connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool))); | ||
167 | connect(dp.buttonAbort, SIGNAL(clicked()), getter, SLOT(abort())); | ||
168 | connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int))); | ||
169 | connect(getter, SIGNAL(downloadDone(int, bool)), this, SLOT(downloadRequestFinished(int, bool))); | ||
170 | |||
171 | downloadProgress->show(); | 153 | downloadProgress->show(); |
172 | } | 154 | } |
173 | 155 | ||
174 | void Install::downloadRequestFinished(int id, bool error) | ||
175 | { | ||
176 | qDebug() << "Install::downloadRequestFinished" << id << error; | ||
177 | qDebug() << "error:" << getter->errorString(); | ||
178 | |||
179 | downloadDone(error); | ||
180 | 156 | ||
181 | } | 157 | void Install::done(bool error) |
182 | |||
183 | void Install::downloadDone(bool error) | ||
184 | { | 158 | { |
185 | qDebug() << "Install::downloadDone, error:" << error; | 159 | qDebug() << "Install::done, error:" << error; |
186 | |||
187 | // update progress bar | ||
188 | int max = dp.progressBar->maximum(); | ||
189 | if(max == 0) { | ||
190 | max = 100; | ||
191 | dp.progressBar->setMaximum(max); | ||
192 | } | ||
193 | dp.progressBar->setValue(max); | ||
194 | if(getter->httpResponse() != 200) { | ||
195 | dp.listProgress->addItem(tr("Download error: received HTTP error %1.").arg(getter->httpResponse())); | ||
196 | dp.buttonAbort->setText(tr("&Ok")); | ||
197 | connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close())); | ||
198 | return; | ||
199 | } | ||
200 | if(error) { | ||
201 | dp.listProgress->addItem(tr("Download error: %1").arg(getter->errorString())); | ||
202 | dp.buttonAbort->setText(tr("&Ok")); | ||
203 | connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close())); | ||
204 | return; | ||
205 | } | ||
206 | else dp.listProgress->addItem(tr("Download finished.")); | ||
207 | |||
208 | // unzip downloaded file | ||
209 | qDebug() << "about to unzip the downloaded file" << fileName << "to" << mountPoint; | ||
210 | 160 | ||
211 | dp.listProgress->addItem(tr("Extracting file.")); | 161 | if(error) |
212 | 162 | { | |
213 | qDebug() << "file to unzip: " << fileName; | ||
214 | UnZip::ErrorCode ec; | ||
215 | UnZip uz; | ||
216 | ec = uz.openArchive(fileName); | ||
217 | if(ec != UnZip::Ok) { | ||
218 | dp.listProgress->addItem(tr("Opening archive failed: %1.") | ||
219 | .arg(uz.formatError(ec))); | ||
220 | dp.buttonAbort->setText(tr("&Ok")); | ||
221 | connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close())); | ||
222 | return; | ||
223 | } | ||
224 | ec = uz.extractAll(mountPoint); | ||
225 | if(ec != UnZip::Ok) { | ||
226 | dp.listProgress->addItem(tr("Extracting failed: %1.") | ||
227 | .arg(uz.formatError(ec))); | ||
228 | dp.buttonAbort->setText(tr("&Ok")); | ||
229 | connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close())); | 163 | connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close())); |
230 | return; | 164 | return; |
231 | } | 165 | } |
232 | 166 | ||
233 | dp.listProgress->addItem(tr("creating installation log")); | ||
234 | |||
235 | |||
236 | QStringList zipContents = uz.fileList(); | ||
237 | |||
238 | QSettings installlog(mountPoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); | ||
239 | |||
240 | installlog.beginGroup("rockboxbase"); | ||
241 | for(int i = 0; i < zipContents.size(); i++) | ||
242 | { | ||
243 | installlog.setValue(zipContents.at(i),installlog.value(zipContents.at(i),0).toInt()+1); | ||
244 | } | ||
245 | installlog.endGroup(); | ||
246 | |||
247 | |||
248 | // remove temporary file | ||
249 | downloadFile.remove(); | ||
250 | |||
251 | dp.listProgress->addItem(tr("Extraction finished successfully.")); | ||
252 | dp.buttonAbort->setText(tr("&Ok")); | ||
253 | connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close())); | 167 | connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close())); |
254 | 168 | delete installer; | |
255 | } | 169 | } |
256 | 170 | ||
257 | 171 | ||
@@ -316,14 +230,6 @@ void Install::setArchivedString(QString string) | |||
316 | qDebug() << "Install::setArchivedString" << archived; | 230 | qDebug() << "Install::setArchivedString" << archived; |
317 | } | 231 | } |
318 | 232 | ||
319 | |||
320 | void Install::updateDataReadProgress(int read, int total) | ||
321 | { | ||
322 | dp.progressBar->setMaximum(total); | ||
323 | dp.progressBar->setValue(read); | ||
324 | qDebug() << "progress:" << read << "/" << total; | ||
325 | } | ||
326 | |||
327 | void Install::setUserSettings(QSettings *user) | 233 | void Install::setUserSettings(QSettings *user) |
328 | { | 234 | { |
329 | userSettings = user; | 235 | userSettings = user; |