diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-04-06 18:12:56 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-04-06 18:12:56 +0000 |
commit | c3969ed4c58d9c153bb95f6f70ad94dff1887495 (patch) | |
tree | 0bb9e820c55f16c7b8aac4eddb553c7fb0261341 /rbutil | |
parent | 5076dca58e40fe0f70620f43ac6e43120038d3cb (diff) | |
download | rockbox-c3969ed4c58d9c153bb95f6f70ad94dff1887495.tar.gz rockbox-c3969ed4c58d9c153bb95f6f70ad94dff1887495.zip |
create an UnZip derived class for zip file extraction to allow showing progress while unzipping. Makes the unzip process somewhat interruptable and the UI more responsible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16993 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/installzip.cpp | 15 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbunzip.cpp | 48 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbunzip.h | 44 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.pro | 6 |
4 files changed, 107 insertions, 6 deletions
diff --git a/rbutil/rbutilqt/installzip.cpp b/rbutil/rbutilqt/installzip.cpp index ae9cabdc24..6514c6d13d 100644 --- a/rbutil/rbutilqt/installzip.cpp +++ b/rbutil/rbutilqt/installzip.cpp | |||
@@ -18,9 +18,8 @@ | |||
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include "installzip.h" | 20 | #include "installzip.h" |
21 | #include "rbunzip.h" | ||
21 | 22 | ||
22 | #include "zip/zip.h" | ||
23 | #include "zip/unzip.h" | ||
24 | 23 | ||
25 | ZipInstaller::ZipInstaller(QObject* parent): QObject(parent) | 24 | ZipInstaller::ZipInstaller(QObject* parent): QObject(parent) |
26 | { | 25 | { |
@@ -135,21 +134,29 @@ void ZipInstaller::downloadDone(bool error) | |||
135 | 134 | ||
136 | qDebug() << "file to unzip: " << m_file; | 135 | qDebug() << "file to unzip: " << m_file; |
137 | UnZip::ErrorCode ec; | 136 | UnZip::ErrorCode ec; |
138 | UnZip uz; | 137 | RbUnZip uz; |
138 | connect(&uz, SIGNAL(unzipProgress(int, int)), this, SLOT(updateDataReadProgress(int, int))); | ||
139 | connect(m_dp, SIGNAL(aborted()), &uz, SLOT(abortUnzip())); | ||
139 | ec = uz.openArchive(m_file); | 140 | ec = uz.openArchive(m_file); |
140 | if(ec != UnZip::Ok) { | 141 | if(ec != UnZip::Ok) { |
141 | m_dp->addItem(tr("Opening archive failed: %1.") | 142 | m_dp->addItem(tr("Opening archive failed: %1.") |
142 | .arg(uz.formatError(ec)),LOGERROR); | 143 | .arg(uz.formatError(ec)),LOGERROR); |
144 | m_dp->setProgressMax(1); | ||
145 | m_dp->setProgressValue(1); | ||
143 | m_dp->abort(); | 146 | m_dp->abort(); |
144 | emit done(true); | 147 | emit done(true); |
145 | return; | 148 | return; |
146 | } | 149 | } |
147 | 150 | ||
148 | ec = uz.extractAll(m_mountpoint); | 151 | ec = uz.extractArchive(m_mountpoint); |
152 | // TODO: better handling of aborted unzip operation. | ||
149 | if(ec != UnZip::Ok) { | 153 | if(ec != UnZip::Ok) { |
150 | m_dp->addItem(tr("Extracting failed: %1.") | 154 | m_dp->addItem(tr("Extracting failed: %1.") |
151 | .arg(uz.formatError(ec)),LOGERROR); | 155 | .arg(uz.formatError(ec)),LOGERROR); |
152 | m_dp->abort(); | 156 | m_dp->abort(); |
157 | m_dp->setProgressMax(1); | ||
158 | m_dp->setProgressValue(1); | ||
159 | |||
153 | emit done(true); | 160 | emit done(true); |
154 | return; | 161 | return; |
155 | } | 162 | } |
diff --git a/rbutil/rbutilqt/rbunzip.cpp b/rbutil/rbutilqt/rbunzip.cpp new file mode 100644 index 0000000000..85d175c63d --- /dev/null +++ b/rbutil/rbutilqt/rbunzip.cpp | |||
@@ -0,0 +1,48 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2008 by Dominik Riebeling | ||
10 | * $Id$ | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "rbunzip.h" | ||
21 | #include <QtCore> | ||
22 | |||
23 | |||
24 | UnZip::ErrorCode RbUnZip::extractArchive(const QString& dest) | ||
25 | { | ||
26 | QStringList files = this->fileList(); | ||
27 | UnZip::ErrorCode error; | ||
28 | m_abortunzip = false; | ||
29 | |||
30 | int total = files.size(); | ||
31 | for(int i = 0; i < total; i++) { | ||
32 | qDebug() << __func__ << files.at(i); | ||
33 | error = this->extractFile(files.at(i), dest, UnZip::ExtractPaths); | ||
34 | emit unzipProgress(i, total); | ||
35 | QCoreApplication::processEvents(); // update UI | ||
36 | if(m_abortunzip) | ||
37 | error = SkipAll; | ||
38 | if(error != Ok) | ||
39 | break; | ||
40 | } | ||
41 | return error; | ||
42 | } | ||
43 | |||
44 | void RbUnZip::abortUnzip(void) | ||
45 | { | ||
46 | m_abortunzip = true; | ||
47 | } | ||
48 | |||
diff --git a/rbutil/rbutilqt/rbunzip.h b/rbutil/rbutilqt/rbunzip.h new file mode 100644 index 0000000000..074d145a97 --- /dev/null +++ b/rbutil/rbutilqt/rbunzip.h | |||
@@ -0,0 +1,44 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2008 by Dominik Riebeling | ||
10 | * $Id$ | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef RBUNZIP_H | ||
21 | #define RBUNZIP_H | ||
22 | |||
23 | #include <QtCore> | ||
24 | #include "zip/unzip.h" | ||
25 | #include "zip/zip.h" | ||
26 | |||
27 | class RbUnZip : public QObject, public UnZip | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | public: | ||
31 | UnZip::ErrorCode extractArchive(const QString&); | ||
32 | |||
33 | signals: | ||
34 | void unzipProgress(int, int); | ||
35 | |||
36 | public slots: | ||
37 | void abortUnzip(void); | ||
38 | |||
39 | private: | ||
40 | bool m_abortunzip; | ||
41 | }; | ||
42 | |||
43 | #endif | ||
44 | |||
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 1aa1c58a27..1485f4d8a9 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro | |||
@@ -55,7 +55,8 @@ SOURCES += rbutilqt.cpp \ | |||
55 | ../../tools/voicefont.c \ | 55 | ../../tools/voicefont.c \ |
56 | voicefile.cpp \ | 56 | voicefile.cpp \ |
57 | createvoicewindow.cpp \ | 57 | createvoicewindow.cpp \ |
58 | rbsettings.cpp | 58 | rbsettings.cpp \ |
59 | rbunzip.cpp | ||
59 | 60 | ||
60 | HEADERS += rbutilqt.h \ | 61 | HEADERS += rbutilqt.h \ |
61 | install.h \ | 62 | install.h \ |
@@ -100,7 +101,8 @@ HEADERS += rbutilqt.h \ | |||
100 | ../../tools/voicefont.h \ | 101 | ../../tools/voicefont.h \ |
101 | voicefile.h \ | 102 | voicefile.h \ |
102 | createvoicewindow.h \ | 103 | createvoicewindow.h \ |
103 | rbsettings.h | 104 | rbsettings.h \ |
105 | rbunzip.h | ||
104 | 106 | ||
105 | # Needed by QT on Win | 107 | # Needed by QT on Win |
106 | INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools | 108 | INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools |