1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include "ui_themesinstallfrm.h"
23 #include "themesinstallwindow.h"
24 #include "zipinstaller.h"
25 #include "progressloggergui.h"
27 #include "rbsettings.h"
29 ThemesInstallWindow::ThemesInstallWindow(QWidget
*parent
) : QDialog(parent
)
32 ui
.listThemes
->setAlternatingRowColors(true);
33 ui
.listThemes
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
34 ui
.listThemes
->setSortingEnabled(true);
35 ui
.themePreview
->clear();
36 ui
.themePreview
->setText(tr("no theme selected"));
37 ui
.labelSize
->setText(tr("no selection"));
39 connect(ui
.buttonCancel
, SIGNAL(clicked()), this, SLOT(close()));
40 connect(ui
.buttonOk
, SIGNAL(clicked()), this, SLOT(accept()));
41 connect(ui
.listThemes
, SIGNAL(currentItemChanged(QListWidgetItem
*, QListWidgetItem
*)),
42 this, SLOT(updateDetails(QListWidgetItem
*, QListWidgetItem
*)));
43 connect(ui
.listThemes
, SIGNAL(itemSelectionChanged()), this, SLOT(updateSize()));
44 connect(&igetter
, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
47 ThemesInstallWindow::~ThemesInstallWindow()
50 recRmdir(infocachedir
);
54 void ThemesInstallWindow::downloadInfo()
56 // try to get the current build information
57 getter
= new HttpGet(this);
59 qDebug() << "downloading themes info";
61 qDebug() << "file:" << themesInfo
.fileName();
65 url
= QUrl(RbSettings::value(RbSettings::ThemesUrl
).toString() + "/rbutilqt.php?target="
66 + RbSettings::value(RbSettings::CurConfigureModel
).toString());
67 qDebug() << "downloadInfo()" << url
;
68 qDebug() << url
.queryItems();
69 if(RbSettings::value(RbSettings::CacheOffline
).toBool())
70 getter
->setCache(true);
71 getter
->setFile(&themesInfo
);
73 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
74 connect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
79 void ThemesInstallWindow::downloadDone(int id
, bool error
)
82 qDebug() << "downloadDone(bool) =" << id
<< error
;
86 void ThemesInstallWindow::downloadDone(bool error
)
88 qDebug() << "downloadDone(bool) =" << error
;
90 disconnect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
91 disconnect(logger
, SIGNAL(aborted()), this, SLOT(close()));
94 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
95 QStringList tl
= iniDetails
.childGroups();
96 qDebug() << iniDetails
.value("error/code").toString()
97 << iniDetails
.value("error/description").toString()
98 << iniDetails
.value("error/query").toString();
101 logger
->addItem(tr("Network error: %1.\n"
102 "Please check your network and proxy settings.")
103 .arg(getter
->errorString()), LOGERROR
);
105 logger
->setFinished();
106 disconnect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
107 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
110 // handle possible error codes
111 if(iniDetails
.value("error/code").toInt() != 0 || !iniDetails
.contains("error/code")) {
112 qDebug() << "error!";
113 logger
->addItem(tr("the following error occured:\n%1")
114 .arg(iniDetails
.value("error/description", "unknown error").toString()), LOGERROR
);
115 logger
->setFinished();
116 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
119 logger
->addItem(tr("done."), LOGOK
);
120 logger
->setFinished();
124 for(int i
= 0; i
< tl
.size(); i
++) {
125 iniDetails
.beginGroup(tl
.at(i
));
126 // skip all themes without name field set (i.e. error section)
127 if(iniDetails
.value("name").toString().isEmpty()) {
128 iniDetails
.endGroup();
131 qDebug() << "adding theme:" << tl
.at(i
);
132 // convert to unicode and replace HTML-specific entities
133 QByteArray raw
= iniDetails
.value("name").toByteArray();
134 QTextCodec
* codec
= QTextCodec::codecForHtml(raw
);
135 QString name
= codec
->toUnicode(raw
);
136 name
.replace(""", "\"").replace("&", "&");
137 name
.replace("<", "<").replace(">", ">");
138 QListWidgetItem
*w
= new QListWidgetItem
;
139 w
->setData(Qt::DisplayRole
, name
.trimmed());
140 w
->setData(Qt::UserRole
, tl
.at(i
));
141 ui
.listThemes
->addItem(w
);
143 iniDetails
.endGroup();
145 // check if there's a themes "MOTD" available
146 if(iniDetails
.contains("status/msg")) {
147 // check if there's a localized msg available
148 QString lang
= RbSettings::value(RbSettings::Language
).toString().split("_").at(0);
150 if(iniDetails
.contains("status/msg." + lang
))
151 msg
= iniDetails
.value("status/msg." + lang
).toString();
153 msg
= iniDetails
.value("status/msg").toString();
154 qDebug() << "[Themes] MOTD" << msg
;
156 QMessageBox::information(this, tr("Information"), msg
);
161 void ThemesInstallWindow::updateSize(void)
164 // sum up size for all selected themes
165 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
166 int items
= ui
.listThemes
->selectedItems().size();
167 for(int i
= 0; i
< items
; i
++) {
168 iniDetails
.beginGroup(ui
.listThemes
->selectedItems()
169 .at(i
)->data(Qt::UserRole
).toString());
170 size
+= iniDetails
.value("size").toInt();
171 iniDetails
.endGroup();
173 ui
.labelSize
->setText(tr("Download size %L1 kiB (%n item(s))", "", items
)
174 .arg((size
+ 512) / 1024));
178 void ThemesInstallWindow::updateDetails(QListWidgetItem
* cur
, QListWidgetItem
* prev
)
183 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
185 QCoreApplication::processEvents();
186 ui
.themeDescription
->setText(tr("fetching details for %1")
187 .arg(cur
->data(Qt::DisplayRole
).toString()));
188 ui
.themePreview
->clear();
189 ui
.themePreview
->setText(tr("fetching preview ..."));
192 iniDetails
.beginGroup(cur
->data(Qt::UserRole
).toString());
195 txt
= QUrl(QString(RbSettings::value(RbSettings::ThemesUrl
).toString() + "/"
196 + iniDetails
.value("descriptionfile").toString()));
197 img
= QUrl(QString(RbSettings::value(RbSettings::ThemesUrl
).toString() + "/"
198 + iniDetails
.value("image").toString()));
201 QTextCodec
* codec
= QTextCodec::codecForName("UTF-8");
202 text
= tr("<b>Author:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
203 .value("author", tr("unknown")).toByteArray()));
204 text
+= tr("<b>Version:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
205 .value("version", tr("unknown")).toByteArray()));
206 text
+= tr("<b>Description:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
207 .value("about", tr("no description")).toByteArray()));
210 text
.replace("\n", "<br/>");
211 ui
.themeDescription
->setHtml(text
);
212 iniDetails
.endGroup();
215 if(!RbSettings::value(RbSettings::CacheDisabled
).toBool())
216 igetter
.setCache(true);
221 infocachedir
= QDir::tempPath() + "rbutil-themeinfo";
222 QDir d
= QDir::temp();
223 d
.mkdir("rbutil-themeinfo");
225 igetter
.setCache(infocachedir
);
228 igetter
.getFile(img
);
232 void ThemesInstallWindow::updateImage(bool error
)
234 qDebug() << "updateImage(bool) =" << error
;
237 ui
.themePreview
->clear();
238 ui
.themePreview
->setText(tr("Retrieving theme preview failed.\n"
239 "HTTP response code: %1").arg(igetter
.httpResponse()));
245 imgData
= igetter
.readAll();
246 if(imgData
.isNull()) return;
247 p
.loadFromData(imgData
);
249 ui
.themePreview
->clear();
250 ui
.themePreview
->setText(tr("no theme preview"));
253 ui
.themePreview
->setPixmap(p
);
258 void ThemesInstallWindow::resizeEvent(QResizeEvent
* e
)
260 qDebug() << "resizeEvent(QResizeEvent*) =" << e
;
264 img
.setHeight(ui
.themePreview
->height());
265 img
.setWidth(ui
.themePreview
->width());
267 p
.loadFromData(imgData
);
268 if(p
.isNull()) return;
269 q
= p
.scaled(img
, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
270 ui
.themePreview
->setScaledContents(false);
271 ui
.themePreview
->setPixmap(p
);
276 void ThemesInstallWindow::show()
279 logger
= new ProgressLoggerGui(this);
281 logger
->addItem(tr("getting themes information ..."), LOGINFO
);
283 connect(logger
, SIGNAL(aborted()), this, SLOT(close()));
290 void ThemesInstallWindow::abort()
293 logger
->setFinished();
298 void ThemesInstallWindow::accept()
300 if(ui
.listThemes
->selectedItems().size() == 0) {
308 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
309 for(int i
= 0; i
< ui
.listThemes
->selectedItems().size(); i
++) {
310 iniDetails
.beginGroup(ui
.listThemes
->selectedItems().at(i
)->data(Qt::UserRole
).toString());
311 zip
= RbSettings::value(RbSettings::ThemesUrl
).toString()
312 + "/" + iniDetails
.value("archive").toString();
314 names
.append("Theme: " +
315 ui
.listThemes
->selectedItems().at(i
)->data(Qt::DisplayRole
).toString());
316 // if no version info is available use installation (current) date
317 version
.append(iniDetails
.value("version",
318 QDate().currentDate().toString("yyyyMMdd")).toString());
319 iniDetails
.endGroup();
321 qDebug() << "installing themes:" << themes
;
323 logger
= new ProgressLoggerGui(this);
325 QString mountPoint
= RbSettings::value(RbSettings::Mountpoint
).toString();
326 qDebug() << "mountpoint:" << mountPoint
;
327 // show dialog with error if mount point is wrong
328 if(!QFileInfo(mountPoint
).isDir()) {
329 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
330 logger
->setFinished();
334 installer
= new ZipInstaller(this);
335 installer
->setUrl(themes
);
336 installer
->setLogSection(names
);
337 installer
->setLogVersion(version
);
338 installer
->setMountPoint(mountPoint
);
339 if(!RbSettings::value(RbSettings::CacheDisabled
).toBool())
340 installer
->setCache(true);
342 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
343 connect(installer
, SIGNAL(logItem(QString
, int)), logger
, SLOT(addItem(QString
, int)));
344 connect(installer
, SIGNAL(logProgress(int, int)), logger
, SLOT(setProgress(int, int)));
345 connect(installer
, SIGNAL(done(bool)), logger
, SLOT(setFinished()));
346 connect(logger
, SIGNAL(aborted()), installer
, SLOT(abort()));
347 installer
->install();