summaryrefslogtreecommitdiff
path: root/utils/themeeditor/gui/targetdownloader.cpp
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-25 21:59:35 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-25 21:59:35 +0000
commitd92f8174a1f838684645267e87b3afebfc48143f (patch)
treefe705adf4815eb38f7646ea7a0cb0a0841c74b43 /utils/themeeditor/gui/targetdownloader.cpp
parente1e51f99949f2a2967210342fcea6e8ae8495e0b (diff)
downloadrockbox-d92f8174a1f838684645267e87b3afebfc48143f.zip
rockbox-d92f8174a1f838684645267e87b3afebfc48143f.tar.gz
rockbox-d92f8174a1f838684645267e87b3afebfc48143f.tar.bz2
rockbox-d92f8174a1f838684645267e87b3afebfc48143f.tar.xz
Theme Editor: Added targetdb download to preferences dialog, fixed Cancel button on FontDownloader
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27565 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/gui/targetdownloader.cpp')
-rw-r--r--utils/themeeditor/gui/targetdownloader.cpp138
1 files changed, 138 insertions, 0 deletions
diff --git a/utils/themeeditor/gui/targetdownloader.cpp b/utils/themeeditor/gui/targetdownloader.cpp
new file mode 100644
index 0000000..c5b4bf1
--- /dev/null
+++ b/utils/themeeditor/gui/targetdownloader.cpp
@@ -0,0 +1,138 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "targetdownloader.h"
+#include "ui_targetdownloader.h"
+
+#include "quazip.h"
+#include "quazipfile.h"
+#include "quazipfileinfo.h"
+
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QCloseEvent>
+
+#include <QDebug>
+
+TargetDownloader::TargetDownloader(QWidget *parent, QString path) :
+ QDialog(parent),
+ ui(new Ui::TargetDownloader), reply(0), cancelled(false)
+{
+ ui->setupUi(this);
+
+ QObject::connect(ui->cancelButton, SIGNAL(clicked()),
+ this, SLOT(cancel()));
+
+ manager = new QNetworkAccessManager();
+
+ fout.setFileName(path);
+ if(fout.open(QFile::WriteOnly))
+ {
+ ui->label->setText(tr("Downloading targetdb"));
+
+ QNetworkRequest request;
+ request.setUrl(QUrl("http://svn.rockbox.org/viewvc.cgi/trunk/utils/"
+ "themeeditor/resources/targetdb"));
+ request.setRawHeader("User-Agent", "Rockbox Theme Editor");
+
+ reply = manager->get(request);
+
+ QObject::connect(reply, SIGNAL(readyRead()),
+ this, SLOT(dataReceived()));
+ QObject::connect(reply, SIGNAL(finished()),
+ this, SLOT(finished()));
+ QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SLOT(progress(qint64,qint64)));
+ }
+ else
+ {
+ ui->label->setText(tr("Error: Couldn't open output file"));
+ }
+
+}
+
+TargetDownloader::~TargetDownloader()
+{
+ delete ui;
+ fout.close();
+ manager->deleteLater();
+
+ if(reply)
+ {
+ reply->abort();
+ reply->deleteLater();
+ }
+}
+
+void TargetDownloader::cancel()
+{
+ cancelled = true;
+
+ if(reply)
+ {
+ reply->abort();
+ reply->deleteLater();
+ reply = 0;
+ }
+
+ fout.close();
+ fout.remove();
+
+ close();
+}
+
+void TargetDownloader::dataReceived()
+{
+ fout.write(reply->readAll());
+}
+
+void TargetDownloader::progress(qint64 bytes, qint64 available)
+{
+ if(available > 0)
+ {
+ ui->progressBar->setMaximum(available);
+ ui->progressBar->setValue(bytes);
+ }
+}
+
+void TargetDownloader::finished()
+{
+ if(cancelled)
+ return;
+
+ fout.close();
+ reply->deleteLater();
+ reply = 0;
+ ui->label->setText(tr("Download complete"));
+ hide();
+ this->deleteLater();
+}
+
+void TargetDownloader::netError(QNetworkReply::NetworkError code)
+{
+ ui->label->setText(tr("Network error: ") + reply->errorString());
+}
+
+void TargetDownloader::closeEvent(QCloseEvent *event)
+{
+ cancel();
+ event->accept();
+}