summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/installrb.cpp
diff options
context:
space:
mode:
authorDominik Wenger <domonoky@googlemail.com>2007-07-26 21:06:09 +0000
committerDominik Wenger <domonoky@googlemail.com>2007-07-26 21:06:09 +0000
commit992ffc83be2be19d337f8a7970597730f560e684 (patch)
tree54749cf6dbcb6981e0d1857e3017f52481ad9bc4 /rbutil/rbutilqt/installrb.cpp
parenta78d51c07c621413c68fee84f24dcc64607c4338 (diff)
downloadrockbox-992ffc83be2be19d337f8a7970597730f560e684.tar.gz
rockbox-992ffc83be2be19d337f8a7970597730f560e684.zip
rbutilqt: forgot the new files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14013 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/installrb.cpp')
-rw-r--r--rbutil/rbutilqt/installrb.cpp144
1 files changed, 144 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/installrb.cpp b/rbutil/rbutilqt/installrb.cpp
new file mode 100644
index 0000000000..401722deb1
--- /dev/null
+++ b/rbutil/rbutilqt/installrb.cpp
@@ -0,0 +1,144 @@
1/***************************************************************************
2 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
3 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
4 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
5 * \/ \/ \/ \/ \/
6 *
7 * Copyright (C) 2007 by Dominik Riebeling
8 * $Id: installrb.cpp 13990 2007-07-25 22:26:10Z Dominik Wenger $
9 *
10 * All files in this archive are subject to the GNU General Public License.
11 * See the file COPYING in the source tree root for full license agreement.
12 *
13 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
14 * KIND, either express or implied.
15 *
16 ****************************************************************************/
17
18#include "installrb.h"
19
20#include "zip/zip.h"
21#include "zip/unzip.h"
22
23RBInstaller::RBInstaller(QObject* parent): QObject(parent)
24{
25
26}
27
28
29void RBInstaller::install(QString url,QString file,QString mountpoint, QUrl proxy,Ui::InstallProgressFrm* dp)
30{
31 m_url=url;
32 m_mountpoint = mountpoint;
33 m_file = file;
34 m_dp = dp;
35
36 m_dp->listProgress->addItem(tr("Downloading file %1.%2")
37 .arg(QFileInfo(m_url).baseName(), QFileInfo(m_url).completeSuffix()));
38
39 // temporary file needs to be opened to get the filename
40 downloadFile.open();
41 m_file = downloadFile.fileName();
42 downloadFile.close();
43 // get the real file.
44 getter = new HttpGet(this);
45 getter->setProxy(proxy);
46 getter->setFile(&downloadFile);
47 getter->getFile(QUrl(url));
48
49 connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
50 connect(getter, SIGNAL(downloadDone(int, bool)), this, SLOT(downloadRequestFinished(int, bool)));
51 connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
52
53}
54
55void RBInstaller::downloadRequestFinished(int id, bool error)
56{
57 qDebug() << "Install::downloadRequestFinished" << id << error;
58 qDebug() << "error:" << getter->errorString();
59
60 downloadDone(error);
61}
62
63void RBInstaller::downloadDone(bool error)
64{
65 qDebug() << "Install::downloadDone, error:" << error;
66
67
68 // update progress bar
69 int max = m_dp->progressBar->maximum();
70 if(max == 0) {
71 max = 100;
72 m_dp->progressBar->setMaximum(max);
73 }
74 m_dp->progressBar->setValue(max);
75 if(getter->httpResponse() != 200) {
76 m_dp->listProgress->addItem(tr("Download error: received HTTP error %1.").arg(getter->httpResponse()));
77 m_dp->buttonAbort->setText(tr("&Ok"));
78 emit done(true);
79 return;
80 }
81 if(error) {
82 m_dp->listProgress->addItem(tr("Download error: %1").arg(getter->errorString()));
83 m_dp->buttonAbort->setText(tr("&Ok"));
84 emit done(true);
85 return;
86 }
87 else m_dp->listProgress->addItem(tr("Download finished."));
88
89 // unzip downloaded file
90 qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint;
91
92 m_dp->listProgress->addItem(tr("Extracting file."));
93
94 qDebug() << "file to unzip: " << m_file;
95 UnZip::ErrorCode ec;
96 UnZip uz;
97 ec = uz.openArchive(m_file);
98 if(ec != UnZip::Ok) {
99 m_dp->listProgress->addItem(tr("Opening archive failed: %1.")
100 .arg(uz.formatError(ec)));
101 m_dp->buttonAbort->setText(tr("&Ok"));
102 emit done(false);
103 return;
104 }
105
106 ec = uz.extractAll(m_mountpoint);
107 if(ec != UnZip::Ok) {
108 m_dp->listProgress->addItem(tr("Extracting failed: %1.")
109 .arg(uz.formatError(ec)));
110 m_dp->buttonAbort->setText(tr("&Ok"));
111 emit done(false);
112 return;
113 }
114
115 m_dp->listProgress->addItem(tr("creating installation log"));
116
117 QStringList zipContents = uz.fileList();
118
119 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
120
121 installlog.beginGroup("rockboxbase");
122 for(int i = 0; i < zipContents.size(); i++)
123 {
124 installlog.setValue(zipContents.at(i),installlog.value(zipContents.at(i),0).toInt()+1);
125 }
126 installlog.endGroup();
127
128 // remove temporary file
129 downloadFile.remove();
130
131 m_dp->listProgress->addItem(tr("Extraction finished successfully."));
132 m_dp->buttonAbort->setText(tr("&Ok"));
133
134 emit done(false);
135}
136
137void RBInstaller::updateDataReadProgress(int read, int total)
138{
139 m_dp->progressBar->setMaximum(total);
140 m_dp->progressBar->setValue(read);
141 qDebug() << "progress:" << read << "/" << total;
142
143}
144