diff options
Diffstat (limited to 'utils/themeeditor')
-rw-r--r-- | utils/themeeditor/gui/fontdownloader.cpp | 15 | ||||
-rw-r--r-- | utils/themeeditor/gui/fontdownloader.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/gui/preferencesdialog.cpp | 9 | ||||
-rw-r--r-- | utils/themeeditor/gui/preferencesdialog.h | 1 | ||||
-rw-r--r-- | utils/themeeditor/gui/preferencesdialog.ui | 4 | ||||
-rw-r--r-- | utils/themeeditor/gui/targetdownloader.cpp | 138 | ||||
-rw-r--r-- | utils/themeeditor/gui/targetdownloader.h | 60 | ||||
-rw-r--r-- | utils/themeeditor/gui/targetdownloader.ui | 87 | ||||
-rw-r--r-- | utils/themeeditor/themeeditor.pro | 10 |
9 files changed, 319 insertions, 7 deletions
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 <QSettings> #include <QColorDialog> @@ -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 @@ <enum>QTabWidget::North</enum> </property> <property name="currentIndex"> - <number>2</number> + <number>0</number> </property> <widget class="QWidget" name="tab_2"> <attribute name="title"> @@ -358,7 +358,7 @@ </layout> </item> <item> - <widget class="QPushButton" name="pushButton_2"> + <widget class="QPushButton" name="dlTargetButton"> <property name="text"> <string>Update Target DB</string> </property> 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 <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(); +} 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 <QDialog> +#include <QDir> +#include <QNetworkAccessManager> +#include <QNetworkReply> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TargetDownloader</class> + <widget class="QDialog" name="TargetDownloader"> + <property name="windowModality"> + <enum>Qt::WindowModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>107</height> + </rect> + </property> + <property name="windowTitle"> + <string>Downloading Font Pack</string> + </property> + <property name="windowIcon"> + <iconset resource="../resources.qrc"> + <normaloff>:/resources/windowicon.png</normaloff>:/resources/windowicon.png</iconset> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QProgressBar" name="progressBar"> + <property name="value"> + <number>0</number> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Checking Directory</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="cancelButton"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources> + <include location="../resources.qrc"/> + </resources> + <connections/> +</ui> 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 { |