From d92f8174a1f838684645267e87b3afebfc48143f Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Sun, 25 Jul 2010 21:59:35 +0000 Subject: [PATCH] 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 --- utils/themeeditor/gui/fontdownloader.cpp | 15 ++- utils/themeeditor/gui/fontdownloader.h | 2 + utils/themeeditor/gui/preferencesdialog.cpp | 9 ++ utils/themeeditor/gui/preferencesdialog.h | 1 + utils/themeeditor/gui/preferencesdialog.ui | 4 +- utils/themeeditor/gui/targetdownloader.cpp | 138 ++++++++++++++++++++ utils/themeeditor/gui/targetdownloader.h | 60 +++++++++ utils/themeeditor/gui/targetdownloader.ui | 87 ++++++++++++ utils/themeeditor/themeeditor.pro | 10 +- 9 files changed, 319 insertions(+), 7 deletions(-) create mode 100644 utils/themeeditor/gui/targetdownloader.cpp create mode 100644 utils/themeeditor/gui/targetdownloader.h create mode 100644 utils/themeeditor/gui/targetdownloader.ui diff --git a/utils/themeeditor/gui/fontdownloader.cpp b/utils/themeeditor/gui/fontdownloader.cpp index 693f4a5b20..adc2e98ab3 100644 --- a/utils/themeeditor/gui/fontdownloader.cpp +++ b/utils/themeeditor/gui/fontdownloader.cpp @@ -34,10 +34,13 @@ FontDownloader::FontDownloader(QWidget *parent, QString path) : QDialog(parent), - ui(new Ui::FontDownloader), dir(path), reply(0) + ui(new Ui::FontDownloader), dir(path), reply(0), cancelled(false) { ui->setupUi(this); + QObject::connect(ui->cancelButton, SIGNAL(clicked()), + this, SLOT(cancel())); + manager = new QNetworkAccessManager(); if(!dir.exists()) @@ -91,12 +94,18 @@ FontDownloader::~FontDownloader() void FontDownloader::cancel() { + cancelled = true; + if(reply) { reply->abort(); reply->deleteLater(); reply = 0; } + fout.close(); + fout.remove(); + + close(); } void FontDownloader::dataReceived() @@ -115,7 +124,11 @@ void FontDownloader::progress(qint64 bytes, qint64 available) void FontDownloader::finished() { + if(cancelled) + return; + fout.close(); + reply->deleteLater(); reply = 0; ui->label->setText(tr("Download complete")); diff --git a/utils/themeeditor/gui/fontdownloader.h b/utils/themeeditor/gui/fontdownloader.h index acd8ea54b3..2b8ae1980a 100644 --- a/utils/themeeditor/gui/fontdownloader.h +++ b/utils/themeeditor/gui/fontdownloader.h @@ -54,6 +54,8 @@ private: QDir dir; QFile fout; QNetworkReply* reply; + + bool cancelled; }; #endif // FONTDOWNLOADER_H diff --git a/utils/themeeditor/gui/preferencesdialog.cpp b/utils/themeeditor/gui/preferencesdialog.cpp index d28b21345d..34ee8c9b22 100644 --- a/utils/themeeditor/gui/preferencesdialog.cpp +++ b/utils/themeeditor/gui/preferencesdialog.cpp @@ -22,6 +22,7 @@ #include "preferencesdialog.h" #include "ui_preferencesdialog.h" #include "fontdownloader.h" +#include "targetdownloader.h" #include #include @@ -223,6 +224,8 @@ void PreferencesDialog::setupUI() this, SLOT(browseDB())); QObject::connect(ui->dlFontsButton, SIGNAL(clicked()), this, SLOT(dlFonts())); + QObject::connect(ui->dlTargetButton, SIGNAL(clicked()), + this, SLOT(dlTargetDB())); } void PreferencesDialog::colorClicked() @@ -278,6 +281,12 @@ void PreferencesDialog::dlFonts() dl->show(); } +void PreferencesDialog::dlTargetDB() +{ + TargetDownloader* dl = new TargetDownloader(this, ui->dbBox->text()); + dl->show(); +} + void PreferencesDialog::accept() { saveSettings(); diff --git a/utils/themeeditor/gui/preferencesdialog.h b/utils/themeeditor/gui/preferencesdialog.h index 16d239c18f..1701a8c4c2 100644 --- a/utils/themeeditor/gui/preferencesdialog.h +++ b/utils/themeeditor/gui/preferencesdialog.h @@ -50,6 +50,7 @@ private slots: void browseFont(); void browseDB(); void dlFonts(); + void dlTargetDB(); private: Ui::PreferencesDialog *ui; diff --git a/utils/themeeditor/gui/preferencesdialog.ui b/utils/themeeditor/gui/preferencesdialog.ui index 824862e025..384f7fced3 100644 --- a/utils/themeeditor/gui/preferencesdialog.ui +++ b/utils/themeeditor/gui/preferencesdialog.ui @@ -24,7 +24,7 @@ QTabWidget::North - 2 + 0 @@ -358,7 +358,7 @@ - + Update Target DB diff --git a/utils/themeeditor/gui/targetdownloader.cpp b/utils/themeeditor/gui/targetdownloader.cpp new file mode 100644 index 0000000000..c5b4bf1fe4 --- /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 +#include +#include + +#include + +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(); +} diff --git a/utils/themeeditor/gui/targetdownloader.h b/utils/themeeditor/gui/targetdownloader.h new file mode 100644 index 0000000000..0d2c4578b6 --- /dev/null +++ b/utils/themeeditor/gui/targetdownloader.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ + +#ifndef TARGETDOWNLOADER_H +#define TARGETDOWNLOADER_H + +#include +#include +#include +#include + +namespace Ui { + class TargetDownloader; +} + +class TargetDownloader : public QDialog { + Q_OBJECT +public: + TargetDownloader(QWidget *parent, QString dir); + virtual ~TargetDownloader(); + +private slots: + void cancel(); + + void dataReceived(); + void progress(qint64 bytes, qint64 available); + void finished(); + void netError(QNetworkReply::NetworkError code); + +private: + void closeEvent(QCloseEvent *event); + + Ui::TargetDownloader *ui; + + QNetworkAccessManager* manager; + QFile fout; + QNetworkReply* reply; + + bool cancelled; +}; + +#endif // TARGETDOWNLOADER_H diff --git a/utils/themeeditor/gui/targetdownloader.ui b/utils/themeeditor/gui/targetdownloader.ui new file mode 100644 index 0000000000..d714e7e61a --- /dev/null +++ b/utils/themeeditor/gui/targetdownloader.ui @@ -0,0 +1,87 @@ + + + TargetDownloader + + + Qt::WindowModal + + + + 0 + 0 + 400 + 107 + + + + Downloading Font Pack + + + + :/resources/windowicon.png:/resources/windowicon.png + + + true + + + true + + + + + + 0 + + + + + + + Checking Directory + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + + + + + + diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index c7bde1fa1a..bd994c602a 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -23,7 +23,6 @@ INCLUDEPATH += models INCLUDEPATH += graphics INCLUDEPATH += quazip INCLUDEPATH += qtfindreplacedialog - DEFINES += FINDREPLACE_NOLIB cross { message("Crossbuilding for W32 binary") @@ -95,7 +94,8 @@ HEADERS += models/parsetreemodel.h \ qtfindreplacedialog/findreplacedialog.h \ qtfindreplacedialog/findform.h \ qtfindreplacedialog/finddialog.h \ - gui/projectexporter.h + gui/projectexporter.h \ + gui/targetdownloader.h SOURCES += main.cpp \ models/parsetreemodel.cpp \ models/parsetreenode.cpp \ @@ -134,7 +134,8 @@ SOURCES += main.cpp \ qtfindreplacedialog/findreplacedialog.cpp \ qtfindreplacedialog/findform.cpp \ qtfindreplacedialog/finddialog.cpp \ - gui/projectexporter.cpp + gui/projectexporter.cpp \ + gui/targetdownloader.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ @@ -169,7 +170,8 @@ FORMS += gui/editorwindow.ui \ gui/fontdownloader.ui \ qtfindreplacedialog/findreplaceform.ui \ qtfindreplacedialog/findreplacedialog.ui \ - gui/projectexporter.ui + gui/projectexporter.ui \ + gui/targetdownloader.ui RESOURCES += resources.qrc win32:RC_FILE = themeeditor.rc macx {