summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-25 21:59:35 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-25 21:59:35 +0000
commitd92f8174a1f838684645267e87b3afebfc48143f (patch)
treefe705adf4815eb38f7646ea7a0cb0a0841c74b43
parente1e51f99949f2a2967210342fcea6e8ae8495e0b (diff)
downloadrockbox-d92f8174a1f838684645267e87b3afebfc48143f.tar.gz
rockbox-d92f8174a1f838684645267e87b3afebfc48143f.zip
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
-rw-r--r--utils/themeeditor/gui/fontdownloader.cpp15
-rw-r--r--utils/themeeditor/gui/fontdownloader.h2
-rw-r--r--utils/themeeditor/gui/preferencesdialog.cpp9
-rw-r--r--utils/themeeditor/gui/preferencesdialog.h1
-rw-r--r--utils/themeeditor/gui/preferencesdialog.ui4
-rw-r--r--utils/themeeditor/gui/targetdownloader.cpp138
-rw-r--r--utils/themeeditor/gui/targetdownloader.h60
-rw-r--r--utils/themeeditor/gui/targetdownloader.ui87
-rw-r--r--utils/themeeditor/themeeditor.pro10
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 @@
34 34
35FontDownloader::FontDownloader(QWidget *parent, QString path) : 35FontDownloader::FontDownloader(QWidget *parent, QString path) :
36 QDialog(parent), 36 QDialog(parent),
37 ui(new Ui::FontDownloader), dir(path), reply(0) 37 ui(new Ui::FontDownloader), dir(path), reply(0), cancelled(false)
38{ 38{
39 ui->setupUi(this); 39 ui->setupUi(this);
40 40
41 QObject::connect(ui->cancelButton, SIGNAL(clicked()),
42 this, SLOT(cancel()));
43
41 manager = new QNetworkAccessManager(); 44 manager = new QNetworkAccessManager();
42 45
43 if(!dir.exists()) 46 if(!dir.exists())
@@ -91,12 +94,18 @@ FontDownloader::~FontDownloader()
91 94
92void FontDownloader::cancel() 95void FontDownloader::cancel()
93{ 96{
97 cancelled = true;
98
94 if(reply) 99 if(reply)
95 { 100 {
96 reply->abort(); 101 reply->abort();
97 reply->deleteLater(); 102 reply->deleteLater();
98 reply = 0; 103 reply = 0;
99 } 104 }
105 fout.close();
106 fout.remove();
107
108 close();
100} 109}
101 110
102void FontDownloader::dataReceived() 111void FontDownloader::dataReceived()
@@ -115,7 +124,11 @@ void FontDownloader::progress(qint64 bytes, qint64 available)
115 124
116void FontDownloader::finished() 125void FontDownloader::finished()
117{ 126{
127 if(cancelled)
128 return;
129
118 fout.close(); 130 fout.close();
131
119 reply->deleteLater(); 132 reply->deleteLater();
120 reply = 0; 133 reply = 0;
121 ui->label->setText(tr("Download complete")); 134 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:
54 QDir dir; 54 QDir dir;
55 QFile fout; 55 QFile fout;
56 QNetworkReply* reply; 56 QNetworkReply* reply;
57
58 bool cancelled;
57}; 59};
58 60
59#endif // FONTDOWNLOADER_H 61#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 @@
22#include "preferencesdialog.h" 22#include "preferencesdialog.h"
23#include "ui_preferencesdialog.h" 23#include "ui_preferencesdialog.h"
24#include "fontdownloader.h" 24#include "fontdownloader.h"
25#include "targetdownloader.h"
25 26
26#include <QSettings> 27#include <QSettings>
27#include <QColorDialog> 28#include <QColorDialog>
@@ -223,6 +224,8 @@ void PreferencesDialog::setupUI()
223 this, SLOT(browseDB())); 224 this, SLOT(browseDB()));
224 QObject::connect(ui->dlFontsButton, SIGNAL(clicked()), 225 QObject::connect(ui->dlFontsButton, SIGNAL(clicked()),
225 this, SLOT(dlFonts())); 226 this, SLOT(dlFonts()));
227 QObject::connect(ui->dlTargetButton, SIGNAL(clicked()),
228 this, SLOT(dlTargetDB()));
226} 229}
227 230
228void PreferencesDialog::colorClicked() 231void PreferencesDialog::colorClicked()
@@ -278,6 +281,12 @@ void PreferencesDialog::dlFonts()
278 dl->show(); 281 dl->show();
279} 282}
280 283
284void PreferencesDialog::dlTargetDB()
285{
286 TargetDownloader* dl = new TargetDownloader(this, ui->dbBox->text());
287 dl->show();
288}
289
281void PreferencesDialog::accept() 290void PreferencesDialog::accept()
282{ 291{
283 saveSettings(); 292 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:
50 void browseFont(); 50 void browseFont();
51 void browseDB(); 51 void browseDB();
52 void dlFonts(); 52 void dlFonts();
53 void dlTargetDB();
53 54
54private: 55private:
55 Ui::PreferencesDialog *ui; 56 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 @@
24 <enum>QTabWidget::North</enum> 24 <enum>QTabWidget::North</enum>
25 </property> 25 </property>
26 <property name="currentIndex"> 26 <property name="currentIndex">
27 <number>2</number> 27 <number>0</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">
@@ -358,7 +358,7 @@
358 </layout> 358 </layout>
359 </item> 359 </item>
360 <item> 360 <item>
361 <widget class="QPushButton" name="pushButton_2"> 361 <widget class="QPushButton" name="dlTargetButton">
362 <property name="text"> 362 <property name="text">
363 <string>Update Target DB</string> 363 <string>Update Target DB</string>
364 </property> 364 </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 @@
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 "targetdownloader.h"
23#include "ui_targetdownloader.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
35TargetDownloader::TargetDownloader(QWidget *parent, QString path) :
36 QDialog(parent),
37 ui(new Ui::TargetDownloader), reply(0), cancelled(false)
38{
39 ui->setupUi(this);
40
41 QObject::connect(ui->cancelButton, SIGNAL(clicked()),
42 this, SLOT(cancel()));
43
44 manager = new QNetworkAccessManager();
45
46 fout.setFileName(path);
47 if(fout.open(QFile::WriteOnly))
48 {
49 ui->label->setText(tr("Downloading targetdb"));
50
51 QNetworkRequest request;
52 request.setUrl(QUrl("http://svn.rockbox.org/viewvc.cgi/trunk/utils/"
53 "themeeditor/resources/targetdb"));
54 request.setRawHeader("User-Agent", "Rockbox Theme Editor");
55
56 reply = manager->get(request);
57
58 QObject::connect(reply, SIGNAL(readyRead()),
59 this, SLOT(dataReceived()));
60 QObject::connect(reply, SIGNAL(finished()),
61 this, SLOT(finished()));
62 QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
63 this, SLOT(progress(qint64,qint64)));
64 }
65 else
66 {
67 ui->label->setText(tr("Error: Couldn't open output file"));
68 }
69
70}
71
72TargetDownloader::~TargetDownloader()
73{
74 delete ui;
75 fout.close();
76 manager->deleteLater();
77
78 if(reply)
79 {
80 reply->abort();
81 reply->deleteLater();
82 }
83}
84
85void TargetDownloader::cancel()
86{
87 cancelled = true;
88
89 if(reply)
90 {
91 reply->abort();
92 reply->deleteLater();
93 reply = 0;
94 }
95
96 fout.close();
97 fout.remove();
98
99 close();
100}
101
102void TargetDownloader::dataReceived()
103{
104 fout.write(reply->readAll());
105}
106
107void TargetDownloader::progress(qint64 bytes, qint64 available)
108{
109 if(available > 0)
110 {
111 ui->progressBar->setMaximum(available);
112 ui->progressBar->setValue(bytes);
113 }
114}
115
116void TargetDownloader::finished()
117{
118 if(cancelled)
119 return;
120
121 fout.close();
122 reply->deleteLater();
123 reply = 0;
124 ui->label->setText(tr("Download complete"));
125 hide();
126 this->deleteLater();
127}
128
129void TargetDownloader::netError(QNetworkReply::NetworkError code)
130{
131 ui->label->setText(tr("Network error: ") + reply->errorString());
132}
133
134void TargetDownloader::closeEvent(QCloseEvent *event)
135{
136 cancel();
137 event->accept();
138}
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 @@
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 TARGETDOWNLOADER_H
23#define TARGETDOWNLOADER_H
24
25#include <QDialog>
26#include <QDir>
27#include <QNetworkAccessManager>
28#include <QNetworkReply>
29
30namespace Ui {
31 class TargetDownloader;
32}
33
34class TargetDownloader : public QDialog {
35 Q_OBJECT
36public:
37 TargetDownloader(QWidget *parent, QString dir);
38 virtual ~TargetDownloader();
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::TargetDownloader *ui;
52
53 QNetworkAccessManager* manager;
54 QFile fout;
55 QNetworkReply* reply;
56
57 bool cancelled;
58};
59
60#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 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>TargetDownloader</class>
4 <widget class="QDialog" name="TargetDownloader">
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/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
23INCLUDEPATH += graphics 23INCLUDEPATH += graphics
24INCLUDEPATH += quazip 24INCLUDEPATH += quazip
25INCLUDEPATH += qtfindreplacedialog 25INCLUDEPATH += qtfindreplacedialog
26
27DEFINES += FINDREPLACE_NOLIB 26DEFINES += FINDREPLACE_NOLIB
28cross { 27cross {
29 message("Crossbuilding for W32 binary") 28 message("Crossbuilding for W32 binary")
@@ -95,7 +94,8 @@ HEADERS += models/parsetreemodel.h \
95 qtfindreplacedialog/findreplacedialog.h \ 94 qtfindreplacedialog/findreplacedialog.h \
96 qtfindreplacedialog/findform.h \ 95 qtfindreplacedialog/findform.h \
97 qtfindreplacedialog/finddialog.h \ 96 qtfindreplacedialog/finddialog.h \
98 gui/projectexporter.h 97 gui/projectexporter.h \
98 gui/targetdownloader.h
99SOURCES += main.cpp \ 99SOURCES += main.cpp \
100 models/parsetreemodel.cpp \ 100 models/parsetreemodel.cpp \
101 models/parsetreenode.cpp \ 101 models/parsetreenode.cpp \
@@ -134,7 +134,8 @@ SOURCES += main.cpp \
134 qtfindreplacedialog/findreplacedialog.cpp \ 134 qtfindreplacedialog/findreplacedialog.cpp \
135 qtfindreplacedialog/findform.cpp \ 135 qtfindreplacedialog/findform.cpp \
136 qtfindreplacedialog/finddialog.cpp \ 136 qtfindreplacedialog/finddialog.cpp \
137 gui/projectexporter.cpp 137 gui/projectexporter.cpp \
138 gui/targetdownloader.cpp
138OTHER_FILES += README \ 139OTHER_FILES += README \
139 resources/windowicon.png \ 140 resources/windowicon.png \
140 resources/appicon.xcf \ 141 resources/appicon.xcf \
@@ -169,7 +170,8 @@ FORMS += gui/editorwindow.ui \
169 gui/fontdownloader.ui \ 170 gui/fontdownloader.ui \
170 qtfindreplacedialog/findreplaceform.ui \ 171 qtfindreplacedialog/findreplaceform.ui \
171 qtfindreplacedialog/findreplacedialog.ui \ 172 qtfindreplacedialog/findreplacedialog.ui \
172 gui/projectexporter.ui 173 gui/projectexporter.ui \
174 gui/targetdownloader.ui
173RESOURCES += resources.qrc 175RESOURCES += resources.qrc
174win32:RC_FILE = themeeditor.rc 176win32:RC_FILE = themeeditor.rc
175macx { 177macx {