add voice file installation. This also extends the ZipInstaller class a bit to handle copying the downloaded file instead of unzipping.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14256 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2007-08-09 16:06:27 +00:00
parent 965881fd85
commit 8dbc7e350b
4 changed files with 101 additions and 31 deletions

View file

@ -24,7 +24,7 @@
ZipInstaller::ZipInstaller(QObject* parent): QObject(parent)
{
m_unzip = true;
}
@ -62,7 +62,7 @@ void ZipInstaller::downloadRequestFinished(int id, bool error)
void ZipInstaller::downloadDone(bool error)
{
qDebug() << "Install::downloadDone, error:" << error;
QStringList zipContents; // needed later
// update progress bar
int max = m_dp->getProgressMax();
@ -85,36 +85,62 @@ void ZipInstaller::downloadDone(bool error)
}
else m_dp->addItem(tr("Download finished."),LOGOK);
// unzip downloaded file
qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint;
if(m_unzip) {
// unzip downloaded file
qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint;
m_dp->addItem(tr("Extracting file."),LOGINFO);
m_dp->addItem(tr("Extracting file."),LOGINFO);
qDebug() << "file to unzip: " << m_file;
UnZip::ErrorCode ec;
UnZip uz;
ec = uz.openArchive(m_file);
if(ec != UnZip::Ok) {
m_dp->addItem(tr("Opening archive failed: %1.")
.arg(uz.formatError(ec)),LOGERROR);
m_dp->abort();
emit done(false);
return;
qDebug() << "file to unzip: " << m_file;
UnZip::ErrorCode ec;
UnZip uz;
ec = uz.openArchive(m_file);
if(ec != UnZip::Ok) {
m_dp->addItem(tr("Opening archive failed: %1.")
.arg(uz.formatError(ec)),LOGERROR);
m_dp->abort();
downloadFile.remove();
emit done(false);
return;
}
ec = uz.extractAll(m_mountpoint);
if(ec != UnZip::Ok) {
m_dp->addItem(tr("Extracting failed: %1.")
.arg(uz.formatError(ec)),LOGERROR);
m_dp->abort();
downloadFile.remove();
emit done(false);
return;
}
// prepare file list for log
zipContents = uz.fileList();
}
else {
// only copy the downloaded file to the output location / name
m_dp->addItem(tr("Installing file."), LOGINFO);
qDebug() << "saving downloaded file (no extraction)";
downloadFile.open(); // copy fails if file is not opened (filename issue?)
// make sure the required path is existing
QString path = QFileInfo(m_mountpoint + m_target).absolutePath();
QDir p;
p.mkpath(path);
// QFile::copy() doesn't overwrite files, so remove old one first
QFile(m_mountpoint + m_target).remove();
if(!downloadFile.copy(m_mountpoint + m_target)) {
m_dp->addItem(tr("Installing file failed."), LOGERROR);
m_dp->abort();
downloadFile.remove();
emit done(false);
return;
}
// add file to log
zipContents.append(m_mountpoint + m_target);
}
ec = uz.extractAll(m_mountpoint);
if(ec != UnZip::Ok) {
m_dp->addItem(tr("Extracting failed: %1.")
.arg(uz.formatError(ec)),LOGERROR);
m_dp->abort();
emit done(false);
return;
}
m_dp->addItem(tr("creating installation log"),LOGINFO);
QStringList zipContents = uz.fileList();
m_dp->addItem(tr("Creating installation log"),LOGINFO);
QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
installlog.beginGroup(m_logsection);
@ -127,7 +153,7 @@ void ZipInstaller::downloadDone(bool error)
// remove temporary file
downloadFile.remove();
m_dp->addItem(tr("Extraction finished successfully."),LOGOK);
m_dp->addItem(tr("Installation finished successfully."),LOGOK);
m_dp->abort();
emit done(false);
}

View file

@ -41,6 +41,8 @@ public:
void setUrl(QString url){m_url = url;}
void setProxy(QUrl proxy) {m_proxy= proxy;}
void setLogSection(QString name) {m_logsection = name;}
void setUnzip(bool i) { m_unzip = i; }
void setTarget(QString t) { m_target = t; }
signals:
void done(bool error);
@ -53,6 +55,8 @@ private slots:
private:
QString m_url,m_file,m_mountpoint,m_logsection;
QUrl m_proxy;
bool m_unzip;
QString m_target;
HttpGet *getter;
QTemporaryFile downloadFile;

View file

@ -80,6 +80,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFonts()));
connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom()));
connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
// disable unimplemented stuff
@ -321,6 +322,44 @@ void RbUtilQt::installFonts()
}
void RbUtilQt::installVoice()
{
if(QMessageBox::question(this, tr("Confirm Installation"),
tr("Do you really want to install the voice file?"),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
// create logger
logger = new ProgressLoggerGui(this);
logger->show();
// create zip installer
installer = new ZipInstaller(this);
installer->setUnzip(false);
buildInfo.open();
QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
buildInfo.close();
QString datestring = info.value("dailies/date").toString();
QString voiceurl = devices->value("voice_url").toString() + "/" +
userSettings->value("defaults/platform").toString() + "-" +
datestring + "-english.voice";
qDebug() << voiceurl;
if(userSettings->value("defaults/proxytype") == "manual")
installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
#ifdef __linux
else if(userSettings->value("defaults/proxytype") == "system")
installer->setProxy(QUrl(getenv("http_proxy")));
#endif
installer->setUrl(voiceurl);
installer->setLogSection("Voice");
installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
installer->setTarget("/.rockbox/langs/english.lang");
installer->install(logger);
connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
}
void RbUtilQt::installDoom()
{
if(QMessageBox::question(this, tr("Confirm Installation"),

View file

@ -63,6 +63,7 @@ class RbUtilQt : public QMainWindow
void downloadDone(bool);
void downloadDone(int, bool);
void downloadInfo(void);
void installVoice(void);
};
#endif