summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Wenger <domonoky@googlemail.com>2007-07-26 21:04:55 +0000
committerDominik Wenger <domonoky@googlemail.com>2007-07-26 21:04:55 +0000
commita78d51c07c621413c68fee84f24dcc64607c4338 (patch)
treea763f93c674e7cb4625d6efbb0aa79b1716a7d56
parent4a115d81da023fb5b9f3727cbe0aed469f369a89 (diff)
downloadrockbox-a78d51c07c621413c68fee84f24dcc64607c4338.tar.gz
rockbox-a78d51c07c621413c68fee84f24dcc64607c4338.zip
rbutil: wrapped the rockbox installation into a class, for easy reuse.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14012 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/rbutilqt/install.cpp116
-rw-r--r--rbutil/rbutilqt/install.h13
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro6
3 files changed, 20 insertions, 115 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
30Install::Install(QWidget *parent) : QDialog(parent) 25Install::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
174void 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} 157void Install::done(bool error)
182
183void 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
320void Install::updateDataReadProgress(int read, int total)
321{
322 dp.progressBar->setMaximum(total);
323 dp.progressBar->setValue(read);
324 qDebug() << "progress:" << read << "/" << total;
325}
326
327void Install::setUserSettings(QSettings *user) 233void Install::setUserSettings(QSettings *user)
328{ 234{
329 userSettings = user; 235 userSettings = user;
diff --git a/rbutil/rbutilqt/install.h b/rbutil/rbutilqt/install.h
index f84b6008e2..d453378c30 100644
--- a/rbutil/rbutilqt/install.h
+++ b/rbutil/rbutilqt/install.h
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * Copyright (C) 2007 by Dominik Riebeling 9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id:$ 10 * $Id$
11 * 11 *
12 * All files in this archive are subject to the GNU General Public License. 12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement. 13 * See the file COPYING in the source tree root for full license agreement.
@@ -21,13 +21,12 @@
21#define INSTALL_H 21#define INSTALL_H
22 22
23#include <QtGui> 23#include <QtGui>
24#include <QtNetwork>
25 24
26#include <QSettings> 25#include <QSettings>
27 26
28#include "ui_installfrm.h" 27#include "ui_installfrm.h"
29#include "ui_installprogressfrm.h" 28#include "ui_installprogressfrm.h"
30#include "httpget.h" 29#include "installrb.h"
31 30
32class Install : public QDialog 31class Install : public QDialog
33{ 32{
@@ -55,12 +54,11 @@ class Install : public QDialog
55 QDialog *downloadProgress; 54 QDialog *downloadProgress;
56 QHttp *download; 55 QHttp *download;
57 QFile *target; 56 QFile *target;
58 HttpGet *getter;
59 QString file; 57 QString file;
60 QString fileName; 58 QString fileName;
61 QString mountPoint; 59 QString mountPoint;
62 QString archived; 60 QString archived;
63 QTemporaryFile downloadFile; 61 RBInstaller* installer;
64 62
65 private slots: 63 private slots:
66 void setCached(bool); 64 void setCached(bool);
@@ -68,9 +66,8 @@ class Install : public QDialog
68 void setDetailsCurrent(bool); 66 void setDetailsCurrent(bool);
69 void setDetailsStable(bool); 67 void setDetailsStable(bool);
70 void setDetailsArchived(bool); 68 void setDetailsArchived(bool);
71 void updateDataReadProgress(int, int); 69 void done(bool);
72 void downloadDone(bool); 70
73 void downloadRequestFinished(int, bool);
74}; 71};
75 72
76 73
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index 4bda942514..1676ee422d 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -4,7 +4,8 @@ SOURCES += rbutilqt.cpp \
4 httpget.cpp \ 4 httpget.cpp \
5 configure.cpp \ 5 configure.cpp \
6 zip/zip.cpp \ 6 zip/zip.cpp \
7 zip/unzip.cpp 7 zip/unzip.cpp \
8 installrb.cpp
8 9
9HEADERS += rbutilqt.h \ 10HEADERS += rbutilqt.h \
10 settings.h \ 11 settings.h \
@@ -16,7 +17,8 @@ HEADERS += rbutilqt.h \
16 zip/zipentry_p.h \ 17 zip/zipentry_p.h \
17 zip/unzip_p.h \ 18 zip/unzip_p.h \
18 zip/zip_p.h \ 19 zip/zip_p.h \
19 version.h 20 version.h \
21 installrb.h
20 22
21TEMPLATE = app 23TEMPLATE = app
22CONFIG += release \ 24CONFIG += release \