From 7c52284b294cb33bc2e5d747e2e3c14d8ab937ae Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Wed, 21 Jul 2010 07:45:29 +0000 Subject: Theme Editor: Implemented download and decompression of font pack in the preferences dialog. Dialog will also allow the user to set a directory for a custom target database, but the update button doesn't work yet. Also fixed the file filters for open file/open project actions and resized the preferences dialog git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27509 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/gui/fontdownloader.cpp | 158 ++++++++++++++++++++++++++++ utils/themeeditor/gui/fontdownloader.h | 59 +++++++++++ utils/themeeditor/gui/fontdownloader.ui | 87 +++++++++++++++ utils/themeeditor/gui/preferencesdialog.cpp | 32 ++++++ utils/themeeditor/gui/preferencesdialog.h | 2 + utils/themeeditor/gui/preferencesdialog.ui | 100 +++++++++++++++--- utils/themeeditor/gui/skindocument.h | 2 +- 7 files changed, 427 insertions(+), 13 deletions(-) create mode 100644 utils/themeeditor/gui/fontdownloader.cpp create mode 100644 utils/themeeditor/gui/fontdownloader.h create mode 100644 utils/themeeditor/gui/fontdownloader.ui (limited to 'utils/themeeditor/gui') diff --git a/utils/themeeditor/gui/fontdownloader.cpp b/utils/themeeditor/gui/fontdownloader.cpp new file mode 100644 index 0000000000..7aa4cd8d57 --- /dev/null +++ b/utils/themeeditor/gui/fontdownloader.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "fontdownloader.h" +#include "ui_fontdownloader.h" + +#include "quazip.h" +#include "quazipfile.h" +#include "quazipfileinfo.h" + +#include +#include +#include + +#include + +FontDownloader::FontDownloader(QWidget *parent, QString path) : + QDialog(parent), + ui(new Ui::FontDownloader), dir(path), reply(0) +{ + ui->setupUi(this); + + manager = new QNetworkAccessManager(); + + if(dir.isReadable()) + { + fout.setFileName(dir.absolutePath() + "/fonts.zip"); + if(fout.open(QFile::WriteOnly)) + { + ui->label->setText(tr("Downloading font pack")); + + QNetworkRequest request; + request.setUrl(QUrl("http://download.rockbox.org" + "/daily/fonts/rockbox-fonts.zip")); + 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 archive file")); + } + } + else + { + ui->label->setText(tr("Error: Fonts directory not readable")); + } + +} + +FontDownloader::~FontDownloader() +{ + delete ui; + fout.close(); + manager->deleteLater(); + + if(reply) + { + reply->abort(); + reply->deleteLater(); + } +} + +void FontDownloader::cancel() +{ + if(reply) + { + reply->abort(); + reply->deleteLater(); + reply = 0; + } +} + +void FontDownloader::dataReceived() +{ + fout.write(reply->readAll()); +} + +void FontDownloader::progress(qint64 bytes, qint64 available) +{ + if(available > 0) + { + ui->progressBar->setMaximum(available); + ui->progressBar->setValue(bytes); + } +} + +void FontDownloader::finished() +{ + fout.close(); + reply->deleteLater(); + reply = 0; + ui->label->setText(tr("Download complete")); + + /* Extracting the ZIP archive */ + QuaZip archive(fout.fileName()); + QuaZipFile zipFile(&archive); + archive.open(QuaZip::mdUnzip); + + bool more; + for(more = archive.goToFirstFile(); more; more = archive.goToNextFile()) + { + if(archive.getCurrentFileName().split("/").last() == "") + continue; + + QFile fontFile(dir.absolutePath() + "/" + + archive.getCurrentFileName().split("/").last()); + fontFile.open(QFile::WriteOnly); + + zipFile.open(QIODevice::ReadOnly); + fontFile.write(zipFile.readAll()); + zipFile.close(); + + fontFile.close(); + } + + archive.close(); + QFile::remove(dir.absolutePath() + "/fonts.zip"); + + hide(); + this->deleteLater(); +} + +void FontDownloader::netError(QNetworkReply::NetworkError code) +{ + ui->label->setText(tr("Network error: ") + reply->errorString()); +} + +void FontDownloader::closeEvent(QCloseEvent *event) +{ + cancel(); + event->accept(); +} diff --git a/utils/themeeditor/gui/fontdownloader.h b/utils/themeeditor/gui/fontdownloader.h new file mode 100644 index 0000000000..acd8ea54b3 --- /dev/null +++ b/utils/themeeditor/gui/fontdownloader.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * __________ __ ___. + * 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 FONTDOWNLOADER_H +#define FONTDOWNLOADER_H + +#include +#include +#include +#include + +namespace Ui { + class FontDownloader; +} + +class FontDownloader : public QDialog { + Q_OBJECT +public: + FontDownloader(QWidget *parent, QString dir); + virtual ~FontDownloader(); + +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::FontDownloader *ui; + + QNetworkAccessManager* manager; + QDir dir; + QFile fout; + QNetworkReply* reply; +}; + +#endif // FONTDOWNLOADER_H diff --git a/utils/themeeditor/gui/fontdownloader.ui b/utils/themeeditor/gui/fontdownloader.ui new file mode 100644 index 0000000000..53b69a8be7 --- /dev/null +++ b/utils/themeeditor/gui/fontdownloader.ui @@ -0,0 +1,87 @@ + + + FontDownloader + + + 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/gui/preferencesdialog.cpp b/utils/themeeditor/gui/preferencesdialog.cpp index dbb3249e9f..b8d0a0a6d6 100644 --- a/utils/themeeditor/gui/preferencesdialog.cpp +++ b/utils/themeeditor/gui/preferencesdialog.cpp @@ -21,6 +21,7 @@ #include "preferencesdialog.h" #include "ui_preferencesdialog.h" +#include "fontdownloader.h" #include #include @@ -124,6 +125,14 @@ void PreferencesDialog::loadRender() false).toBool()); settings.endGroup(); + + settings.beginGroup("TargetData"); + + ui->dbBox->setText(settings.value("targetDbPath", + QDir::homePath() + "/.targetdb") + .toString()); + + settings.endGroup(); } void PreferencesDialog::saveSettings() @@ -183,6 +192,10 @@ void PreferencesDialog::saveRender() settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked()); settings.endGroup(); + + settings.beginGroup("TargetData"); + settings.setValue("targetDbPath", ui->dbBox->text()); + settings.endGroup(); } void PreferencesDialog::setupUI() @@ -203,6 +216,10 @@ void PreferencesDialog::setupUI() QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()), this, SLOT(browseFont())); + QObject::connect(ui->browseDB, SIGNAL(clicked()), + this, SLOT(browseDB())); + QObject::connect(ui->dlFontsButton, SIGNAL(clicked()), + this, SLOT(dlFonts())); } void PreferencesDialog::colorClicked() @@ -243,6 +260,21 @@ void PreferencesDialog::browseFont() ui->fontBox->setText(path); } +void PreferencesDialog::browseDB() +{ + QString path = QFileDialog::getOpenFileName(this, tr("Target DB"), + QDir(ui->dbBox->text()). + absolutePath(), + "All Files (*)"); + ui->dbBox->setText(path); +} + +void PreferencesDialog::dlFonts() +{ + FontDownloader* dl = new FontDownloader(this, ui->fontBox->text()); + dl->show(); +} + void PreferencesDialog::accept() { saveSettings(); diff --git a/utils/themeeditor/gui/preferencesdialog.h b/utils/themeeditor/gui/preferencesdialog.h index cc1d7c75e3..16d239c18f 100644 --- a/utils/themeeditor/gui/preferencesdialog.h +++ b/utils/themeeditor/gui/preferencesdialog.h @@ -48,6 +48,8 @@ public slots: private slots: void colorClicked(); void browseFont(); + void browseDB(); + void dlFonts(); private: Ui::PreferencesDialog *ui; diff --git a/utils/themeeditor/gui/preferencesdialog.ui b/utils/themeeditor/gui/preferencesdialog.ui index c455ed0786..824862e025 100644 --- a/utils/themeeditor/gui/preferencesdialog.ui +++ b/utils/themeeditor/gui/preferencesdialog.ui @@ -7,7 +7,7 @@ 0 0 370 - 370 + 295 @@ -24,7 +24,7 @@ QTabWidget::North - 0 + 2 @@ -32,29 +32,31 @@ - - + + Font + + fontSelect + - + - - - - - + Size + + fontSize + - + 12 @@ -118,7 +120,7 @@ - + @@ -138,6 +140,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -256,6 +271,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -301,6 +329,54 @@ + + + + Download Fontpack + + + + + + + + + Target DB + + + + + + + + + + Browse... + + + + + + + + + Update Target DB + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h index f7ac2bbc2c..927a5cf9fc 100644 --- a/utils/themeeditor/gui/skindocument.h +++ b/utils/themeeditor/gui/skindocument.h @@ -50,7 +50,7 @@ public: "FMS Files (*.fms *.rfms);;" "All Skin Files (*.wps *.rwps *.sbs " "*.rsbs *.fms *.rfms);;" - "All Files (*.*)"); + "All Files (*)"); } SkinDocument(QLabel* statusLabel, ProjectModel* project = 0, -- cgit v1.2.3