diff options
Diffstat (limited to 'utils/themeeditor/gui')
| -rw-r--r-- | utils/themeeditor/gui/fontdownloader.cpp | 158 | ||||
| -rw-r--r-- | utils/themeeditor/gui/fontdownloader.h | 59 | ||||
| -rw-r--r-- | utils/themeeditor/gui/fontdownloader.ui | 87 | ||||
| -rw-r--r-- | utils/themeeditor/gui/preferencesdialog.cpp | 32 | ||||
| -rw-r--r-- | utils/themeeditor/gui/preferencesdialog.h | 2 | ||||
| -rw-r--r-- | utils/themeeditor/gui/preferencesdialog.ui | 100 | ||||
| -rw-r--r-- | utils/themeeditor/gui/skindocument.h | 2 |
7 files changed, 427 insertions, 13 deletions
diff --git a/utils/themeeditor/gui/fontdownloader.cpp b/utils/themeeditor/gui/fontdownloader.cpp new file mode 100644 index 0000000..7aa4cd8 --- /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 <QNetworkRequest> +#include <QNetworkReply> +#include <QCloseEvent> + +#include <QDebug> + +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 0000000..acd8ea5 --- /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 <QDialog> +#include <QDir> +#include <QNetworkAccessManager> +#include <QNetworkReply> + +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 0000000..53b69a8 --- /dev/null +++ b/utils/themeeditor/gui/fontdownloader.ui @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>FontDownloader</class> + <widget class="QDialog" name="FontDownloader"> + <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/gui/preferencesdialog.cpp b/utils/themeeditor/gui/preferencesdialog.cpp index dbb3249..b8d0a0a 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 <QSettings> #include <QColorDialog> @@ -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 cc1d7c7..16d239c 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 c455ed0..824862e 100644 --- a/utils/themeeditor/gui/preferencesdialog.ui +++ b/utils/themeeditor/gui/preferencesdialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>370</width> - <height>370</height> + <height>295</height> </rect> </property> <property name="windowTitle"> @@ -24,7 +24,7 @@ <enum>QTabWidget::North</enum> </property> <property name="currentIndex"> - <number>0</number> + <number>2</number> </property> <widget class="QWidget" name="tab_2"> <attribute name="title"> @@ -32,29 +32,31 @@ </attribute> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <layout class="QHBoxLayout" name="horizontalLayout_7"> - <item> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> <widget class="QLabel" name="label_7"> <property name="text"> <string>Font</string> </property> + <property name="buddy"> + <cstring>fontSelect</cstring> + </property> </widget> </item> - <item> + <item row="0" column="1"> <widget class="QFontComboBox" name="fontSelect"/> </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_8"> - <item> + <item row="1" column="0"> <widget class="QLabel" name="label_8"> <property name="text"> <string>Size</string> </property> + <property name="buddy"> + <cstring>fontSize</cstring> + </property> </widget> </item> - <item> + <item row="1" column="1"> <widget class="QSpinBox" name="fontSize"> <property name="value"> <number>12</number> @@ -118,7 +120,7 @@ </layout> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_9"> + <layout class="QHBoxLayout" name="horizontalLayout_7"> <item> <widget class="QLabel" name="label_9"> <property name="text"> @@ -138,6 +140,19 @@ </item> </layout> </item> + <item> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> </layout> </widget> <widget class="QWidget" name="prefsGroupsPage1"> @@ -256,6 +271,19 @@ </item> </layout> </item> + <item> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> </layout> </widget> <widget class="QWidget" name="tab"> @@ -301,6 +329,54 @@ </item> </layout> </item> + <item> + <widget class="QPushButton" name="dlFontsButton"> + <property name="text"> + <string>Download Fontpack</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_11"> + <item> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>Target DB</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="dbBox"/> + </item> + <item> + <widget class="QPushButton" name="browseDB"> + <property name="text"> + <string>Browse...</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QPushButton" name="pushButton_2"> + <property name="text"> + <string>Update Target DB</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> </layout> </widget> </widget> diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h index f7ac2bb..927a5cf 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, |