diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-07-25 21:59:35 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-25 21:59:35 +0000 |
commit | d92f8174a1f838684645267e87b3afebfc48143f (patch) | |
tree | fe705adf4815eb38f7646ea7a0cb0a0841c74b43 /utils/themeeditor/gui/targetdownloader.cpp | |
parent | e1e51f99949f2a2967210342fcea6e8ae8495e0b (diff) | |
download | rockbox-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
Diffstat (limited to 'utils/themeeditor/gui/targetdownloader.cpp')
-rw-r--r-- | utils/themeeditor/gui/targetdownloader.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
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 | |||
35 | TargetDownloader::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 | |||
72 | TargetDownloader::~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 | |||
85 | void 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 | |||
102 | void TargetDownloader::dataReceived() | ||
103 | { | ||
104 | fout.write(reply->readAll()); | ||
105 | } | ||
106 | |||
107 | void 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 | |||
116 | void 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 | |||
129 | void TargetDownloader::netError(QNetworkReply::NetworkError code) | ||
130 | { | ||
131 | ui->label->setText(tr("Network error: ") + reply->errorString()); | ||
132 | } | ||
133 | |||
134 | void TargetDownloader::closeEvent(QCloseEvent *event) | ||
135 | { | ||
136 | cancel(); | ||
137 | event->accept(); | ||
138 | } | ||