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
This commit is contained in:
Dominik Wenger 2007-07-26 21:04:55 +00:00
parent 4a115d81da
commit a78d51c07c
3 changed files with 22 additions and 117 deletions

View file

@ -20,12 +20,7 @@
#include "install.h"
#include "ui_installfrm.h"
#include "ui_installprogressfrm.h"
#include "httpget.h"
#include "zip/zip.h"
#include "zip/unzip.h"
#include <QtGui>
#include <QtNetwork>
Install::Install(QWidget *parent) : QDialog(parent)
{
@ -150,108 +145,27 @@ void Install::accept()
}
userSettings->sync();
dp.listProgress->addItem(tr("Downloading file %1.%2")
.arg(QFileInfo(file).baseName(), QFileInfo(file).completeSuffix()));
// temporary file needs to be opened to get the filename
downloadFile.open();
fileName = downloadFile.fileName();
downloadFile.close();
// get the real file.
getter = new HttpGet(this);
getter->setProxy(proxy);
getter->setFile(&downloadFile);
getter->getFile(QUrl(file));
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
connect(dp.buttonAbort, SIGNAL(clicked()), getter, SLOT(abort()));
connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
connect(getter, SIGNAL(downloadDone(int, bool)), this, SLOT(downloadRequestFinished(int, bool)));
installer = new RBInstaller(this);
installer->install(file,fileName,mountPoint,proxy, &dp);
connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
downloadProgress->show();
}
void Install::downloadRequestFinished(int id, bool error)
void Install::done(bool error)
{
qDebug() << "Install::downloadRequestFinished" << id << error;
qDebug() << "error:" << getter->errorString();
qDebug() << "Install::done, error:" << error;
downloadDone(error);
}
void Install::downloadDone(bool error)
{
qDebug() << "Install::downloadDone, error:" << error;
// update progress bar
int max = dp.progressBar->maximum();
if(max == 0) {
max = 100;
dp.progressBar->setMaximum(max);
}
dp.progressBar->setValue(max);
if(getter->httpResponse() != 200) {
dp.listProgress->addItem(tr("Download error: received HTTP error %1.").arg(getter->httpResponse()));
dp.buttonAbort->setText(tr("&Ok"));
connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
return;
}
if(error) {
dp.listProgress->addItem(tr("Download error: %1").arg(getter->errorString()));
dp.buttonAbort->setText(tr("&Ok"));
connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
return;
}
else dp.listProgress->addItem(tr("Download finished."));
// unzip downloaded file
qDebug() << "about to unzip the downloaded file" << fileName << "to" << mountPoint;
dp.listProgress->addItem(tr("Extracting file."));
qDebug() << "file to unzip: " << fileName;
UnZip::ErrorCode ec;
UnZip uz;
ec = uz.openArchive(fileName);
if(ec != UnZip::Ok) {
dp.listProgress->addItem(tr("Opening archive failed: %1.")
.arg(uz.formatError(ec)));
dp.buttonAbort->setText(tr("&Ok"));
connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
return;
}
ec = uz.extractAll(mountPoint);
if(ec != UnZip::Ok) {
dp.listProgress->addItem(tr("Extracting failed: %1.")
.arg(uz.formatError(ec)));
dp.buttonAbort->setText(tr("&Ok"));
connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
return;
}
dp.listProgress->addItem(tr("creating installation log"));
QStringList zipContents = uz.fileList();
QSettings installlog(mountPoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
installlog.beginGroup("rockboxbase");
for(int i = 0; i < zipContents.size(); i++)
if(error)
{
installlog.setValue(zipContents.at(i),installlog.value(zipContents.at(i),0).toInt()+1);
connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
return;
}
installlog.endGroup();
// remove temporary file
downloadFile.remove();
dp.listProgress->addItem(tr("Extraction finished successfully."));
dp.buttonAbort->setText(tr("&Ok"));
connect(dp.buttonAbort, SIGNAL(clicked()), this, SLOT(close()));
delete installer;
}
@ -316,14 +230,6 @@ void Install::setArchivedString(QString string)
qDebug() << "Install::setArchivedString" << archived;
}
void Install::updateDataReadProgress(int read, int total)
{
dp.progressBar->setMaximum(total);
dp.progressBar->setValue(read);
qDebug() << "progress:" << read << "/" << total;
}
void Install::setUserSettings(QSettings *user)
{
userSettings = user;

View file

@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Riebeling
* $Id:$
* $Id$
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
@ -21,13 +21,12 @@
#define INSTALL_H
#include <QtGui>
#include <QtNetwork>
#include <QSettings>
#include "ui_installfrm.h"
#include "ui_installprogressfrm.h"
#include "httpget.h"
#include "installrb.h"
class Install : public QDialog
{
@ -55,12 +54,11 @@ class Install : public QDialog
QDialog *downloadProgress;
QHttp *download;
QFile *target;
HttpGet *getter;
QString file;
QString fileName;
QString mountPoint;
QString archived;
QTemporaryFile downloadFile;
RBInstaller* installer;
private slots:
void setCached(bool);
@ -68,9 +66,8 @@ class Install : public QDialog
void setDetailsCurrent(bool);
void setDetailsStable(bool);
void setDetailsArchived(bool);
void updateDataReadProgress(int, int);
void downloadDone(bool);
void downloadRequestFinished(int, bool);
void done(bool);
};

View file

@ -4,7 +4,8 @@ SOURCES += rbutilqt.cpp \
httpget.cpp \
configure.cpp \
zip/zip.cpp \
zip/unzip.cpp
zip/unzip.cpp \
installrb.cpp
HEADERS += rbutilqt.h \
settings.h \
@ -16,7 +17,8 @@ HEADERS += rbutilqt.h \
zip/zipentry_p.h \
zip/unzip_p.h \
zip/zip_p.h \
version.h
version.h \
installrb.h
TEMPLATE = app
CONFIG += release \