summaryrefslogtreecommitdiff
path: root/utils/themeeditor/gui
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/gui')
-rw-r--r--utils/themeeditor/gui/fontdownloader.cpp158
-rw-r--r--utils/themeeditor/gui/fontdownloader.h59
-rw-r--r--utils/themeeditor/gui/fontdownloader.ui87
-rw-r--r--utils/themeeditor/gui/preferencesdialog.cpp32
-rw-r--r--utils/themeeditor/gui/preferencesdialog.h2
-rw-r--r--utils/themeeditor/gui/preferencesdialog.ui100
-rw-r--r--utils/themeeditor/gui/skindocument.h2
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 0000000000..7aa4cd8d57
--- /dev/null
+++ b/utils/themeeditor/gui/fontdownloader.cpp
@@ -0,0 +1,158 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "fontdownloader.h"
23#include "ui_fontdownloader.h"
24
25#include "quazip.h"
26#include "quazipfile.h"
27#include "quazipfileinfo.h"
28
29#include <QNetworkRequest>
30#include <QNetworkReply>
31#include <QCloseEvent>
32
33#include <QDebug>
34
35FontDownloader::FontDownloader(QWidget *parent, QString path) :
36 QDialog(parent),
37 ui(new Ui::FontDownloader), dir(path), reply(0)
38{
39 ui->setupUi(this);
40
41 manager = new QNetworkAccessManager();
42
43 if(dir.isReadable())
44 {
45 fout.setFileName(dir.absolutePath() + "/fonts.zip");
46 if(fout.open(QFile::WriteOnly))
47 {
48 ui->label->setText(tr("Downloading font pack"));
49
50 QNetworkRequest request;
51 request.setUrl(QUrl("http://download.rockbox.org"
52 "/daily/fonts/rockbox-fonts.zip"));
53 request.setRawHeader("User-Agent", "Rockbox Theme Editor");
54
55 reply = manager->get(request);
56
57 QObject::connect(reply, SIGNAL(readyRead()),
58 this, SLOT(dataReceived()));
59 QObject::connect(reply, SIGNAL(finished()),
60 this, SLOT(finished()));
61 QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
62 this, SLOT(progress(qint64,qint64)));
63 }
64 else
65 {
66 ui->label->setText(tr("Error: Couldn't open archive file"));
67 }
68 }
69 else
70 {
71 ui->label->setText(tr("Error: Fonts directory not readable"));
72 }
73
74}
75
76FontDownloader::~FontDownloader()
77{
78 delete ui;
79 fout.close();
80 manager->deleteLater();
81
82 if(reply)
83 {
84 reply->abort();
85 reply->deleteLater();
86 }
87}
88
89void FontDownloader::cancel()
90{
91 if(reply)
92 {
93 reply->abort();
94 reply->deleteLater();
95 reply = 0;
96 }
97}
98
99void FontDownloader::dataReceived()
100{
101 fout.write(reply->readAll());
102}
103
104void FontDownloader::progress(qint64 bytes, qint64 available)
105{
106 if(available > 0)
107 {
108 ui->progressBar->setMaximum(available);
109 ui->progressBar->setValue(bytes);
110 }
111}
112
113void FontDownloader::finished()
114{
115 fout.close();
116 reply->deleteLater();
117 reply = 0;
118 ui->label->setText(tr("Download complete"));
119
120 /* Extracting the ZIP archive */
121 QuaZip archive(fout.fileName());
122 QuaZipFile zipFile(&archive);
123 archive.open(QuaZip::mdUnzip);
124
125 bool more;
126 for(more = archive.goToFirstFile(); more; more = archive.goToNextFile())
127 {
128 if(archive.getCurrentFileName().split("/").last() == "")
129 continue;
130
131 QFile fontFile(dir.absolutePath() + "/" +
132 archive.getCurrentFileName().split("/").last());
133 fontFile.open(QFile::WriteOnly);
134
135 zipFile.open(QIODevice::ReadOnly);
136 fontFile.write(zipFile.readAll());
137 zipFile.close();
138
139 fontFile.close();
140 }
141
142 archive.close();
143 QFile::remove(dir.absolutePath() + "/fonts.zip");
144
145 hide();
146 this->deleteLater();
147}
148
149void FontDownloader::netError(QNetworkReply::NetworkError code)
150{
151 ui->label->setText(tr("Network error: ") + reply->errorString());
152}
153
154void FontDownloader::closeEvent(QCloseEvent *event)
155{
156 cancel();
157 event->accept();
158}
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef FONTDOWNLOADER_H
23#define FONTDOWNLOADER_H
24
25#include <QDialog>
26#include <QDir>
27#include <QNetworkAccessManager>
28#include <QNetworkReply>
29
30namespace Ui {
31 class FontDownloader;
32}
33
34class FontDownloader : public QDialog {
35 Q_OBJECT
36public:
37 FontDownloader(QWidget *parent, QString dir);
38 virtual ~FontDownloader();
39
40private slots:
41 void cancel();
42
43 void dataReceived();
44 void progress(qint64 bytes, qint64 available);
45 void finished();
46 void netError(QNetworkReply::NetworkError code);
47
48private:
49 void closeEvent(QCloseEvent *event);
50
51 Ui::FontDownloader *ui;
52
53 QNetworkAccessManager* manager;
54 QDir dir;
55 QFile fout;
56 QNetworkReply* reply;
57};
58
59#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 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>FontDownloader</class>
4 <widget class="QDialog" name="FontDownloader">
5 <property name="windowModality">
6 <enum>Qt::WindowModal</enum>
7 </property>
8 <property name="geometry">
9 <rect>
10 <x>0</x>
11 <y>0</y>
12 <width>400</width>
13 <height>107</height>
14 </rect>
15 </property>
16 <property name="windowTitle">
17 <string>Downloading Font Pack</string>
18 </property>
19 <property name="windowIcon">
20 <iconset resource="../resources.qrc">
21 <normaloff>:/resources/windowicon.png</normaloff>:/resources/windowicon.png</iconset>
22 </property>
23 <property name="sizeGripEnabled">
24 <bool>true</bool>
25 </property>
26 <property name="modal">
27 <bool>true</bool>
28 </property>
29 <layout class="QVBoxLayout" name="verticalLayout">
30 <item>
31 <widget class="QProgressBar" name="progressBar">
32 <property name="value">
33 <number>0</number>
34 </property>
35 </widget>
36 </item>
37 <item>
38 <widget class="QLabel" name="label">
39 <property name="text">
40 <string>Checking Directory</string>
41 </property>
42 </widget>
43 </item>
44 <item>
45 <spacer name="verticalSpacer">
46 <property name="orientation">
47 <enum>Qt::Vertical</enum>
48 </property>
49 <property name="sizeHint" stdset="0">
50 <size>
51 <width>20</width>
52 <height>40</height>
53 </size>
54 </property>
55 </spacer>
56 </item>
57 <item>
58 <layout class="QHBoxLayout" name="horizontalLayout">
59 <item>
60 <spacer name="horizontalSpacer">
61 <property name="orientation">
62 <enum>Qt::Horizontal</enum>
63 </property>
64 <property name="sizeHint" stdset="0">
65 <size>
66 <width>40</width>
67 <height>20</height>
68 </size>
69 </property>
70 </spacer>
71 </item>
72 <item>
73 <widget class="QPushButton" name="cancelButton">
74 <property name="text">
75 <string>Cancel</string>
76 </property>
77 </widget>
78 </item>
79 </layout>
80 </item>
81 </layout>
82 </widget>
83 <resources>
84 <include location="../resources.qrc"/>
85 </resources>
86 <connections/>
87</ui>
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 @@
21 21
22#include "preferencesdialog.h" 22#include "preferencesdialog.h"
23#include "ui_preferencesdialog.h" 23#include "ui_preferencesdialog.h"
24#include "fontdownloader.h"
24 25
25#include <QSettings> 26#include <QSettings>
26#include <QColorDialog> 27#include <QColorDialog>
@@ -124,6 +125,14 @@ void PreferencesDialog::loadRender()
124 false).toBool()); 125 false).toBool());
125 126
126 settings.endGroup(); 127 settings.endGroup();
128
129 settings.beginGroup("TargetData");
130
131 ui->dbBox->setText(settings.value("targetDbPath",
132 QDir::homePath() + "/.targetdb")
133 .toString());
134
135 settings.endGroup();
127} 136}
128 137
129void PreferencesDialog::saveSettings() 138void PreferencesDialog::saveSettings()
@@ -183,6 +192,10 @@ void PreferencesDialog::saveRender()
183 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked()); 192 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked());
184 193
185 settings.endGroup(); 194 settings.endGroup();
195
196 settings.beginGroup("TargetData");
197 settings.setValue("targetDbPath", ui->dbBox->text());
198 settings.endGroup();
186} 199}
187 200
188void PreferencesDialog::setupUI() 201void PreferencesDialog::setupUI()
@@ -203,6 +216,10 @@ void PreferencesDialog::setupUI()
203 216
204 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()), 217 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()),
205 this, SLOT(browseFont())); 218 this, SLOT(browseFont()));
219 QObject::connect(ui->browseDB, SIGNAL(clicked()),
220 this, SLOT(browseDB()));
221 QObject::connect(ui->dlFontsButton, SIGNAL(clicked()),
222 this, SLOT(dlFonts()));
206} 223}
207 224
208void PreferencesDialog::colorClicked() 225void PreferencesDialog::colorClicked()
@@ -243,6 +260,21 @@ void PreferencesDialog::browseFont()
243 ui->fontBox->setText(path); 260 ui->fontBox->setText(path);
244} 261}
245 262
263void PreferencesDialog::browseDB()
264{
265 QString path = QFileDialog::getOpenFileName(this, tr("Target DB"),
266 QDir(ui->dbBox->text()).
267 absolutePath(),
268 "All Files (*)");
269 ui->dbBox->setText(path);
270}
271
272void PreferencesDialog::dlFonts()
273{
274 FontDownloader* dl = new FontDownloader(this, ui->fontBox->text());
275 dl->show();
276}
277
246void PreferencesDialog::accept() 278void PreferencesDialog::accept()
247{ 279{
248 saveSettings(); 280 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:
48private slots: 48private slots:
49 void colorClicked(); 49 void colorClicked();
50 void browseFont(); 50 void browseFont();
51 void browseDB();
52 void dlFonts();
51 53
52private: 54private:
53 Ui::PreferencesDialog *ui; 55 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 @@
7 <x>0</x> 7 <x>0</x>
8 <y>0</y> 8 <y>0</y>
9 <width>370</width> 9 <width>370</width>
10 <height>370</height> 10 <height>295</height>
11 </rect> 11 </rect>
12 </property> 12 </property>
13 <property name="windowTitle"> 13 <property name="windowTitle">
@@ -24,7 +24,7 @@
24 <enum>QTabWidget::North</enum> 24 <enum>QTabWidget::North</enum>
25 </property> 25 </property>
26 <property name="currentIndex"> 26 <property name="currentIndex">
27 <number>0</number> 27 <number>2</number>
28 </property> 28 </property>
29 <widget class="QWidget" name="tab_2"> 29 <widget class="QWidget" name="tab_2">
30 <attribute name="title"> 30 <attribute name="title">
@@ -32,29 +32,31 @@
32 </attribute> 32 </attribute>
33 <layout class="QVBoxLayout" name="verticalLayout_2"> 33 <layout class="QVBoxLayout" name="verticalLayout_2">
34 <item> 34 <item>
35 <layout class="QHBoxLayout" name="horizontalLayout_7"> 35 <layout class="QFormLayout" name="formLayout">
36 <item> 36 <item row="0" column="0">
37 <widget class="QLabel" name="label_7"> 37 <widget class="QLabel" name="label_7">
38 <property name="text"> 38 <property name="text">
39 <string>Font</string> 39 <string>Font</string>
40 </property> 40 </property>
41 <property name="buddy">
42 <cstring>fontSelect</cstring>
43 </property>
41 </widget> 44 </widget>
42 </item> 45 </item>
43 <item> 46 <item row="0" column="1">
44 <widget class="QFontComboBox" name="fontSelect"/> 47 <widget class="QFontComboBox" name="fontSelect"/>
45 </item> 48 </item>
46 </layout> 49 <item row="1" column="0">
47 </item>
48 <item>
49 <layout class="QHBoxLayout" name="horizontalLayout_8">
50 <item>
51 <widget class="QLabel" name="label_8"> 50 <widget class="QLabel" name="label_8">
52 <property name="text"> 51 <property name="text">
53 <string>Size</string> 52 <string>Size</string>
54 </property> 53 </property>
54 <property name="buddy">
55 <cstring>fontSize</cstring>
56 </property>
55 </widget> 57 </widget>
56 </item> 58 </item>
57 <item> 59 <item row="1" column="1">
58 <widget class="QSpinBox" name="fontSize"> 60 <widget class="QSpinBox" name="fontSize">
59 <property name="value"> 61 <property name="value">
60 <number>12</number> 62 <number>12</number>
@@ -118,7 +120,7 @@
118 </layout> 120 </layout>
119 </item> 121 </item>
120 <item> 122 <item>
121 <layout class="QHBoxLayout" name="horizontalLayout_9"> 123 <layout class="QHBoxLayout" name="horizontalLayout_7">
122 <item> 124 <item>
123 <widget class="QLabel" name="label_9"> 125 <widget class="QLabel" name="label_9">
124 <property name="text"> 126 <property name="text">
@@ -138,6 +140,19 @@
138 </item> 140 </item>
139 </layout> 141 </layout>
140 </item> 142 </item>
143 <item>
144 <spacer name="verticalSpacer_3">
145 <property name="orientation">
146 <enum>Qt::Vertical</enum>
147 </property>
148 <property name="sizeHint" stdset="0">
149 <size>
150 <width>20</width>
151 <height>40</height>
152 </size>
153 </property>
154 </spacer>
155 </item>
141 </layout> 156 </layout>
142 </widget> 157 </widget>
143 <widget class="QWidget" name="prefsGroupsPage1"> 158 <widget class="QWidget" name="prefsGroupsPage1">
@@ -256,6 +271,19 @@
256 </item> 271 </item>
257 </layout> 272 </layout>
258 </item> 273 </item>
274 <item>
275 <spacer name="verticalSpacer_2">
276 <property name="orientation">
277 <enum>Qt::Vertical</enum>
278 </property>
279 <property name="sizeHint" stdset="0">
280 <size>
281 <width>20</width>
282 <height>40</height>
283 </size>
284 </property>
285 </spacer>
286 </item>
259 </layout> 287 </layout>
260 </widget> 288 </widget>
261 <widget class="QWidget" name="tab"> 289 <widget class="QWidget" name="tab">
@@ -301,6 +329,54 @@
301 </item> 329 </item>
302 </layout> 330 </layout>
303 </item> 331 </item>
332 <item>
333 <widget class="QPushButton" name="dlFontsButton">
334 <property name="text">
335 <string>Download Fontpack</string>
336 </property>
337 </widget>
338 </item>
339 <item>
340 <layout class="QHBoxLayout" name="horizontalLayout_11">
341 <item>
342 <widget class="QLabel" name="label_11">
343 <property name="text">
344 <string>Target DB</string>
345 </property>
346 </widget>
347 </item>
348 <item>
349 <widget class="QLineEdit" name="dbBox"/>
350 </item>
351 <item>
352 <widget class="QPushButton" name="browseDB">
353 <property name="text">
354 <string>Browse...</string>
355 </property>
356 </widget>
357 </item>
358 </layout>
359 </item>
360 <item>
361 <widget class="QPushButton" name="pushButton_2">
362 <property name="text">
363 <string>Update Target DB</string>
364 </property>
365 </widget>
366 </item>
367 <item>
368 <spacer name="verticalSpacer">
369 <property name="orientation">
370 <enum>Qt::Vertical</enum>
371 </property>
372 <property name="sizeHint" stdset="0">
373 <size>
374 <width>20</width>
375 <height>40</height>
376 </size>
377 </property>
378 </spacer>
379 </item>
304 </layout> 380 </layout>
305 </widget> 381 </widget>
306 </widget> 382 </widget>
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:
50 "FMS Files (*.fms *.rfms);;" 50 "FMS Files (*.fms *.rfms);;"
51 "All Skin Files (*.wps *.rwps *.sbs " 51 "All Skin Files (*.wps *.rwps *.sbs "
52 "*.rsbs *.fms *.rfms);;" 52 "*.rsbs *.fms *.rfms);;"
53 "All Files (*.*)"); 53 "All Files (*)");
54 } 54 }
55 55
56 SkinDocument(QLabel* statusLabel, ProjectModel* project = 0, 56 SkinDocument(QLabel* statusLabel, ProjectModel* project = 0,