From 092c178784ca5ebf13feaf4a2d63f46e19dc1c37 Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Fri, 27 Jul 2007 17:42:49 +0000 Subject: rbutilqt: reworked and renamed the installrb class/files to generic installzip, so it can be used for things like Fonts. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14027 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/install.cpp | 9 ++- rbutil/rbutilqt/install.h | 4 +- rbutil/rbutilqt/installrb.cpp | 146 ----------------------------------------- rbutil/rbutilqt/installrb.h | 60 ----------------- rbutil/rbutilqt/installzip.cpp | 144 ++++++++++++++++++++++++++++++++++++++++ rbutil/rbutilqt/installzip.h | 66 +++++++++++++++++++ rbutil/rbutilqt/rbutilqt.pro | 4 +- 7 files changed, 221 insertions(+), 212 deletions(-) delete mode 100644 rbutil/rbutilqt/installrb.cpp delete mode 100644 rbutil/rbutilqt/installrb.h create mode 100644 rbutil/rbutilqt/installzip.cpp create mode 100644 rbutil/rbutilqt/installzip.h diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp index ee1b21c..948cf20 100644 --- a/rbutil/rbutilqt/install.cpp +++ b/rbutil/rbutilqt/install.cpp @@ -145,8 +145,13 @@ void Install::accept() } userSettings->sync(); - installer = new RBInstaller(this); - installer->install(file,fileName,mountPoint,proxy, &dp); + installer = new ZipInstaller(this); + installer->setFilename(fileName); + installer->setUrl(file); + installer->setProxy(proxy); + installer->setLogSection("rockboxbase"); + installer->setMountPoint(mountPoint); + installer->install(&dp); connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool))); diff --git a/rbutil/rbutilqt/install.h b/rbutil/rbutilqt/install.h index d453378..79dcf0c 100644 --- a/rbutil/rbutilqt/install.h +++ b/rbutil/rbutilqt/install.h @@ -26,7 +26,7 @@ #include "ui_installfrm.h" #include "ui_installprogressfrm.h" -#include "installrb.h" +#include "installzip.h" class Install : public QDialog { @@ -58,7 +58,7 @@ class Install : public QDialog QString fileName; QString mountPoint; QString archived; - RBInstaller* installer; + ZipInstaller* installer; private slots: void setCached(bool); diff --git a/rbutil/rbutilqt/installrb.cpp b/rbutil/rbutilqt/installrb.cpp deleted file mode 100644 index 8fa977f..0000000 --- a/rbutil/rbutilqt/installrb.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Riebeling - * $Id: installrb.cpp 13990 2007-07-25 22:26:10Z Dominik Wenger $ - * - * 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. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "installrb.h" - -#include "zip/zip.h" -#include "zip/unzip.h" - -RBInstaller::RBInstaller(QObject* parent): QObject(parent) -{ - -} - - -void RBInstaller::install(QString url,QString file,QString mountpoint, QUrl proxy,Ui::InstallProgressFrm* dp) -{ - m_url=url; - m_mountpoint = mountpoint; - m_file = file; - m_dp = dp; - - m_dp->listProgress->addItem(tr("Downloading file %1.%2") - .arg(QFileInfo(m_url).baseName(), QFileInfo(m_url).completeSuffix())); - - // temporary file needs to be opened to get the filename - downloadFile.open(); - m_file = downloadFile.fileName(); - downloadFile.close(); - // get the real file. - getter = new HttpGet(this); - getter->setProxy(proxy); - getter->setFile(&downloadFile); - getter->getFile(QUrl(url)); - - connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool))); - connect(getter, SIGNAL(downloadDone(int, bool)), this, SLOT(downloadRequestFinished(int, bool))); - connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int))); - -} - -void RBInstaller::downloadRequestFinished(int id, bool error) -{ - qDebug() << "Install::downloadRequestFinished" << id << error; - qDebug() << "error:" << getter->errorString(); - - downloadDone(error); -} - -void RBInstaller::downloadDone(bool error) -{ - qDebug() << "Install::downloadDone, error:" << error; - - - // update progress bar - int max = m_dp->progressBar->maximum(); - if(max == 0) { - max = 100; - m_dp->progressBar->setMaximum(max); - } - m_dp->progressBar->setValue(max); - if(getter->httpResponse() != 200) { - m_dp->listProgress->addItem(tr("Download error: received HTTP error %1.").arg(getter->httpResponse())); - m_dp->buttonAbort->setText(tr("&Ok")); - emit done(true); - return; - } - if(error) { - m_dp->listProgress->addItem(tr("Download error: %1").arg(getter->errorString())); - m_dp->buttonAbort->setText(tr("&Ok")); - emit done(true); - return; - } - else m_dp->listProgress->addItem(tr("Download finished.")); - - // unzip downloaded file - qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint; - - m_dp->listProgress->addItem(tr("Extracting file.")); - - qDebug() << "file to unzip: " << m_file; - UnZip::ErrorCode ec; - UnZip uz; - ec = uz.openArchive(m_file); - if(ec != UnZip::Ok) { - m_dp->listProgress->addItem(tr("Opening archive failed: %1.") - .arg(uz.formatError(ec))); - m_dp->buttonAbort->setText(tr("&Ok")); - emit done(false); - return; - } - - ec = uz.extractAll(m_mountpoint); - if(ec != UnZip::Ok) { - m_dp->listProgress->addItem(tr("Extracting failed: %1.") - .arg(uz.formatError(ec))); - m_dp->buttonAbort->setText(tr("&Ok")); - emit done(false); - return; - } - - m_dp->listProgress->addItem(tr("creating installation log")); - - QStringList zipContents = uz.fileList(); - - QSettings installlog(m_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(); - - m_dp->listProgress->addItem(tr("Extraction finished successfully.")); - m_dp->buttonAbort->setText(tr("&Ok")); - - emit done(false); -} - -void RBInstaller::updateDataReadProgress(int read, int total) -{ - m_dp->progressBar->setMaximum(total); - m_dp->progressBar->setValue(read); - qDebug() << "progress:" << read << "/" << total; - -} - diff --git a/rbutil/rbutilqt/installrb.h b/rbutil/rbutilqt/installrb.h deleted file mode 100644 index c940fd8..0000000 --- a/rbutil/rbutilqt/installrb.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Riebeling - * $Id: installrb.h 13990 2007-07-25 22:26:10Z Dominik Wenger $ - * - * 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. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - - -#ifndef INSTALLRB_H -#define INSTALLRB_H - - - -#include -#include - -#include "ui_installprogressfrm.h" -#include "httpget.h" - -class RBInstaller : public QObject -{ - Q_OBJECT -public: - RBInstaller(QObject* parent) ; - ~RBInstaller(){} - void install(QString url,QString filename,QString mountpoint, QUrl proxy,Ui::InstallProgressFrm* dp); - -signals: - void done(bool error); - -private slots: - void updateDataReadProgress(int, int); - void downloadDone(bool); - void downloadRequestFinished(int, bool); - -private: - QString m_url,m_file,m_mountpoint; - - HttpGet *getter; - QTemporaryFile downloadFile; - - Ui::InstallProgressFrm* m_dp; -}; - - - -#endif - diff --git a/rbutil/rbutilqt/installzip.cpp b/rbutil/rbutilqt/installzip.cpp new file mode 100644 index 0000000..82e9486 --- /dev/null +++ b/rbutil/rbutilqt/installzip.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: installzip.cpp 13990 2007-07-25 22:26:10Z Dominik Wenger $ + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "installzip.h" + +#include "zip/zip.h" +#include "zip/unzip.h" + +ZipInstaller::ZipInstaller(QObject* parent): QObject(parent) +{ + +} + + +void ZipInstaller::install(Ui::InstallProgressFrm* dp) +{ + m_dp = dp; + + m_dp->listProgress->addItem(tr("Downloading file %1.%2") + .arg(QFileInfo(m_url).baseName(), QFileInfo(m_url).completeSuffix())); + + // temporary file needs to be opened to get the filename + downloadFile.open(); + m_file = downloadFile.fileName(); + downloadFile.close(); + // get the real file. + getter = new HttpGet(this); + getter->setProxy(m_proxy); + getter->setFile(&downloadFile); + getter->getFile(QUrl(m_url)); + + connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool))); + connect(getter, SIGNAL(downloadDone(int, bool)), this, SLOT(downloadRequestFinished(int, bool))); + connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int))); + +} + +void ZipInstaller::downloadRequestFinished(int id, bool error) +{ + qDebug() << "Install::downloadRequestFinished" << id << error; + qDebug() << "error:" << getter->errorString(); + + downloadDone(error); +} + +void ZipInstaller::downloadDone(bool error) +{ + qDebug() << "Install::downloadDone, error:" << error; + + + // update progress bar + + int max = m_dp->progressBar->maximum(); + if(max == 0) { + max = 100; + m_dp->progressBar->setMaximum(max); + } + m_dp->progressBar->setValue(max); + if(getter->httpResponse() != 200) { + m_dp->listProgress->addItem(tr("Download error: received HTTP error %1.").arg(getter->httpResponse())); + m_dp->buttonAbort->setText(tr("&Ok")); + emit done(true); + return; + } + if(error) { + m_dp->listProgress->addItem(tr("Download error: %1").arg(getter->errorString())); + m_dp->buttonAbort->setText(tr("&Ok")); + emit done(true); + return; + } + else m_dp->listProgress->addItem(tr("Download finished.")); + + // unzip downloaded file + qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint; + + m_dp->listProgress->addItem(tr("Extracting file.")); + + qDebug() << "file to unzip: " << m_file; + UnZip::ErrorCode ec; + UnZip uz; + ec = uz.openArchive(m_file); + if(ec != UnZip::Ok) { + m_dp->listProgress->addItem(tr("Opening archive failed: %1.") + .arg(uz.formatError(ec))); + m_dp->buttonAbort->setText(tr("&Ok")); + emit done(false); + return; + } + + ec = uz.extractAll(m_mountpoint); + if(ec != UnZip::Ok) { + m_dp->listProgress->addItem(tr("Extracting failed: %1.") + .arg(uz.formatError(ec))); + m_dp->buttonAbort->setText(tr("&Ok")); + emit done(false); + return; + } + + m_dp->listProgress->addItem(tr("creating installation log")); + + QStringList zipContents = uz.fileList(); + + QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); + + installlog.beginGroup(m_logsection); + 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(); + + m_dp->listProgress->addItem(tr("Extraction finished successfully.")); + m_dp->buttonAbort->setText(tr("&Ok")); + + emit done(false); +} + +void ZipInstaller::updateDataReadProgress(int read, int total) +{ + m_dp->progressBar->setMaximum(total); + m_dp->progressBar->setValue(read); + qDebug() << "progress:" << read << "/" << total; + +} + diff --git a/rbutil/rbutilqt/installzip.h b/rbutil/rbutilqt/installzip.h new file mode 100644 index 0000000..e3f3b5a --- /dev/null +++ b/rbutil/rbutilqt/installzip.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: installzip.h 13990 2007-07-25 22:26:10Z Dominik Wenger $ + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#ifndef INSTALLRB_H +#define INSTALLRB_H + + + +#include +#include + +#include "ui_installprogressfrm.h" +#include "httpget.h" + +class ZipInstaller : public QObject +{ + Q_OBJECT +public: + ZipInstaller(QObject* parent) ; + ~ZipInstaller(){} + void install(Ui::InstallProgressFrm* dp); + void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;} + void setFilename(QString filename){m_file = filename;} + void setUrl(QString url){m_url = url;} + void setProxy(QUrl proxy) {m_proxy= proxy;} + void setLogSection(QString name) {m_logsection = name;} + +signals: + void done(bool error); + +private slots: + void updateDataReadProgress(int, int); + void downloadDone(bool); + void downloadRequestFinished(int, bool); + +private: + QString m_url,m_file,m_mountpoint,m_logsection; + QUrl m_proxy; + + HttpGet *getter; + QTemporaryFile downloadFile; + + Ui::InstallProgressFrm* m_dp; +}; + + + +#endif + diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 1676ee4..1491ab9 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro @@ -5,7 +5,7 @@ SOURCES += rbutilqt.cpp \ configure.cpp \ zip/zip.cpp \ zip/unzip.cpp \ - installrb.cpp + installzip.cpp HEADERS += rbutilqt.h \ settings.h \ @@ -18,7 +18,7 @@ HEADERS += rbutilqt.h \ zip/unzip_p.h \ zip/zip_p.h \ version.h \ - installrb.h + installzip.h TEMPLATE = app CONFIG += release \ -- cgit v1.1