summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/themesinstallwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/themesinstallwindow.cpp')
-rw-r--r--rbutil/rbutilqt/themesinstallwindow.cpp335
1 files changed, 335 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/themesinstallwindow.cpp b/rbutil/rbutilqt/themesinstallwindow.cpp
new file mode 100644
index 0000000000..fb3fbe4cb7
--- /dev/null
+++ b/rbutil/rbutilqt/themesinstallwindow.cpp
@@ -0,0 +1,335 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <QtGui>
21
22#include "ui_themesinstallfrm.h"
23#include "themesinstallwindow.h"
24#include "installzip.h"
25#include "progressloggergui.h"
26#include "utils.h"
27
28ThemesInstallWindow::ThemesInstallWindow(QWidget *parent) : QDialog(parent)
29{
30 ui.setupUi(this);
31 ui.listThemes->setAlternatingRowColors(true);
32 ui.listThemes->setSelectionMode(QAbstractItemView::ExtendedSelection);
33 ui.listThemes->setSortingEnabled(true);
34 ui.themePreview->clear();
35 ui.themePreview->setText(tr("no theme selected"));
36 ui.labelSize->setText(tr("no selection"));
37
38 connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(close()));
39 connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
40 connect(ui.listThemes, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
41 this, SLOT(updateDetails(QListWidgetItem*, QListWidgetItem*)));
42 connect(ui.listThemes, SIGNAL(itemSelectionChanged()), this, SLOT(updateSize()));
43 connect(&igetter, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
44}
45
46ThemesInstallWindow::~ThemesInstallWindow()
47{
48 if(infocachedir!="")
49 recRmdir(infocachedir);
50}
51
52
53void ThemesInstallWindow::downloadInfo()
54{
55 // try to get the current build information
56 getter = new HttpGet(this);
57
58 qDebug() << "downloading themes info";
59 themesInfo.open();
60 qDebug() << "file:" << themesInfo.fileName();
61 themesInfo.close();
62
63 QUrl url;
64 url = QUrl(settings->themeUrl() + "/rbutilqt.php?target="
65 + settings->curConfigure_Modelname());
66 qDebug() << "downloadInfo()" << url;
67 qDebug() << url.queryItems();
68 if(settings->cacheOffline())
69 getter->setCache(true);
70 getter->setFile(&themesInfo);
71
72 connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
73 connect(logger, SIGNAL(aborted()), getter, SLOT(abort()));
74 getter->getFile(url);
75}
76
77
78void ThemesInstallWindow::downloadDone(int id, bool error)
79{
80 downloadDone(error);
81 qDebug() << "downloadDone(bool) =" << id << error;
82}
83
84
85void ThemesInstallWindow::downloadDone(bool error)
86{
87 qDebug() << "downloadDone(bool) =" << error;
88
89 disconnect(logger, SIGNAL(aborted()), getter, SLOT(abort()));
90 disconnect(logger, SIGNAL(aborted()), this, SLOT(close()));
91 themesInfo.open();
92
93 QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
94 QStringList tl = iniDetails.childGroups();
95 qDebug() << iniDetails.value("error/code").toString()
96 << iniDetails.value("error/description").toString()
97 << iniDetails.value("error/query").toString();
98
99 if(error) {
100 logger->addItem(tr("Network error: %1.\n"
101 "Please check your network and proxy settings.")
102 .arg(getter->errorString()), LOGERROR);
103 getter->abort();
104 logger->abort();
105 disconnect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
106 connect(logger, SIGNAL(closed()), this, SLOT(close()));
107 return;
108 }
109 // handle possible error codes
110 if(iniDetails.value("error/code").toInt() != 0 || !iniDetails.contains("error/code")) {
111 qDebug() << "error!";
112 logger->addItem(tr("the following error occured:\n%1")
113 .arg(iniDetails.value("error/description", "unknown error").toString()), LOGERROR);
114 logger->abort();
115 connect(logger, SIGNAL(closed()), this, SLOT(close()));
116 return;
117 }
118 logger->addItem(tr("done."), LOGOK);
119 logger->abort();
120 logger->close();
121
122 // setup list
123 for(int i = 0; i < tl.size(); i++) {
124 iniDetails.beginGroup(tl.at(i));
125 // skip all themes without name field set (i.e. error section)
126 if(iniDetails.value("name").toString().isEmpty()) {
127 iniDetails.endGroup();
128 continue;
129 }
130 qDebug() << "adding theme:" << tl.at(i);
131 QListWidgetItem *w = new QListWidgetItem;
132 w->setData(Qt::DisplayRole, iniDetails.value("name").toString());
133 w->setData(Qt::UserRole, tl.at(i));
134 ui.listThemes->addItem(w);
135
136 iniDetails.endGroup();
137 }
138 // check if there's a themes "MOTD" available
139 if(iniDetails.contains("status/msg")) {
140 // check if there's a localized msg available
141 QString lang = settings->curLang().split("_").at(0);
142 QString msg;
143 if(iniDetails.contains("status/msg." + lang))
144 msg = iniDetails.value("status/msg." + lang).toString();
145 else
146 msg = iniDetails.value("status/msg").toString();
147 qDebug() << "[Themes] MOTD" << msg;
148 if(!msg.isEmpty())
149 QMessageBox::information(this, tr("Information"), msg);
150 }
151}
152
153
154void ThemesInstallWindow::updateSize(void)
155{
156 long size = 0;
157 // sum up size for all selected themes
158 QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
159 int items = ui.listThemes->selectedItems().size();
160 for(int i = 0; i < items; i++) {
161 iniDetails.beginGroup(ui.listThemes->selectedItems()
162 .at(i)->data(Qt::UserRole).toString());
163 size += iniDetails.value("size").toInt();
164 iniDetails.endGroup();
165 }
166 ui.labelSize->setText(tr("Download size %L1 kiB (%n item(s))", "", items)
167 .arg((size + 512) / 1024));
168}
169
170
171void ThemesInstallWindow::updateDetails(QListWidgetItem* cur, QListWidgetItem* prev)
172{
173 if(cur == prev)
174 return;
175
176 QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
177
178 QCoreApplication::processEvents();
179 ui.themeDescription->setText(tr("fetching details for %1")
180 .arg(cur->data(Qt::DisplayRole).toString()));
181 ui.themePreview->clear();
182 ui.themePreview->setText(tr("fetching preview ..."));
183
184 iniDetails.beginGroup(cur->data(Qt::UserRole).toString());
185
186 QUrl img, txt;
187 txt = QUrl(QString(settings->themeUrl() + "/"
188 + iniDetails.value("descriptionfile").toString()));
189 img = QUrl(QString(settings->themeUrl() + "/"
190 + iniDetails.value("image").toString()));
191
192 QString text;
193 text = tr("<b>Author:</b> %1<hr/>").arg(iniDetails.value("author",
194 tr("unknown")).toString());
195 text += tr("<b>Version:</b> %1<hr/>").arg(iniDetails.value("version",
196 tr("unknown")).toString());
197 text += tr("<b>Description:</b> %1<hr/>").arg(iniDetails.value("about",
198 tr("no description")).toString());
199
200 ui.themeDescription->setHtml(text);
201 iniDetails.endGroup();
202
203 igetter.abort();
204 if(!settings->cacheDisabled())
205 igetter.setCache(true);
206 else
207 {
208 if(infocachedir=="")
209 {
210 infocachedir = QDir::tempPath() + "rbutil-themeinfo";
211 QDir d = QDir::temp();
212 d.mkdir("rbutil-themeinfo");
213 }
214 igetter.setCache(infocachedir);
215 }
216
217 igetter.getFile(img);
218}
219
220
221void ThemesInstallWindow::updateImage(bool error)
222{
223 qDebug() << "updateImage(bool) =" << error;
224
225 if(error) {
226 ui.themePreview->clear();
227 ui.themePreview->setText(tr("Retrieving theme preview failed.\n"
228 "HTTP response code: %1").arg(igetter.httpResponse()));
229 return;
230 }
231
232 QPixmap p;
233 if(!error) {
234 imgData = igetter.readAll();
235 if(imgData.isNull()) return;
236 p.loadFromData(imgData);
237 if(p.isNull()) {
238 ui.themePreview->clear();
239 ui.themePreview->setText(tr("no theme preview"));
240 }
241 else
242 ui.themePreview->setPixmap(p);
243 }
244}
245
246
247void ThemesInstallWindow::resizeEvent(QResizeEvent* e)
248{
249 qDebug() << "resizeEvent(QResizeEvent*) =" << e;
250
251 QPixmap p, q;
252 QSize img;
253 img.setHeight(ui.themePreview->height());
254 img.setWidth(ui.themePreview->width());
255
256 p.loadFromData(imgData);
257 if(p.isNull()) return;
258 q = p.scaled(img, Qt::KeepAspectRatio, Qt::SmoothTransformation);
259 ui.themePreview->setScaledContents(false);
260 ui.themePreview->setPixmap(p);
261}
262
263
264
265void ThemesInstallWindow::show()
266{
267 QDialog::show();
268 logger = new ProgressLoggerGui(this);
269 logger->show();
270 logger->addItem(tr("getting themes information ..."), LOGINFO);
271
272 connect(logger, SIGNAL(aborted()), this, SLOT(close()));
273
274 downloadInfo();
275
276}
277
278
279void ThemesInstallWindow::abort()
280{
281 igetter.abort();
282 logger->abort();
283 this->close();
284}
285
286
287void ThemesInstallWindow::accept()
288{
289 if(ui.listThemes->selectedItems().size() == 0) {
290 this->close();
291 return;
292 }
293 QStringList themes;
294 QStringList names;
295 QStringList version;
296 QString zip;
297 QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
298 for(int i = 0; i < ui.listThemes->selectedItems().size(); i++) {
299 iniDetails.beginGroup(ui.listThemes->selectedItems().at(i)->data(Qt::UserRole).toString());
300 zip = settings->themeUrl()
301 + "/" + iniDetails.value("archive").toString();
302 themes.append(zip);
303 names.append("Theme: " +
304 ui.listThemes->selectedItems().at(i)->data(Qt::DisplayRole).toString());
305 // if no version info is available use installation (current) date
306 version.append(iniDetails.value("version",
307 QDate().currentDate().toString("yyyyMMdd")).toString());
308 iniDetails.endGroup();
309 }
310 qDebug() << "installing themes:" << themes;
311
312 logger = new ProgressLoggerGui(this);
313 logger->show();
314 QString mountPoint = settings->mountpoint();
315 qDebug() << "mountpoint:" << mountPoint;
316 // show dialog with error if mount point is wrong
317 if(!QFileInfo(mountPoint).isDir()) {
318 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
319 logger->abort();
320 return;
321 }
322
323 installer = new ZipInstaller(this);
324 installer->setUrl(themes);
325 installer->setLogSection(names);
326 installer->setLogVersion(version);
327 installer->setMountPoint(mountPoint);
328 if(!settings->cacheDisabled())
329 installer->setCache(true);
330
331 connect(logger, SIGNAL(closed()), this, SLOT(close()));
332 installer->install(logger);
333
334}
335