From a78d51c07c621413c68fee84f24dcc64607c4338 Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Thu, 26 Jul 2007 21:04:55 +0000 Subject: 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 --- rbutil/rbutilqt/install.cpp | 116 ++++--------------------------------------- rbutil/rbutilqt/install.h | 13 ++--- rbutil/rbutilqt/rbutilqt.pro | 6 ++- 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 @@ #include "install.h" #include "ui_installfrm.h" #include "ui_installprogressfrm.h" -#include "httpget.h" -#include "zip/zip.h" -#include "zip/unzip.h" -#include -#include 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) -{ - qDebug() << "Install::downloadRequestFinished" << id << error; - qDebug() << "error:" << getter->errorString(); - - downloadDone(error); -} - -void Install::downloadDone(bool error) +void Install::done(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; + qDebug() << "Install::done, error:" << error; - 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")); + if(error) + { 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++) - { - installlog.setValue(zipContents.at(i),installlog.value(zipContents.at(i),0).toInt()+1); - } - 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; 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 @@ * \/ \/ \/ \/ \/ * * 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 -#include #include #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); + }; 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 \ 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 \ -- cgit v1.2.3