2007-08-15 21:54:15 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Riebeling
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtGui>
|
|
|
|
|
2009-03-31 19:50:43 +00:00
|
|
|
#include "ui_themesinstallfrm.h"
|
|
|
|
#include "themesinstallwindow.h"
|
2009-04-27 19:58:24 +00:00
|
|
|
#include "zipinstaller.h"
|
2007-08-15 21:54:15 +00:00
|
|
|
#include "progressloggergui.h"
|
2007-09-14 22:16:22 +00:00
|
|
|
#include "utils.h"
|
2009-05-09 16:59:14 +00:00
|
|
|
#include "rbsettings.h"
|
2007-08-15 21:54:15 +00:00
|
|
|
|
|
|
|
ThemesInstallWindow::ThemesInstallWindow(QWidget *parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
ui.listThemes->setAlternatingRowColors(true);
|
|
|
|
ui.listThemes->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2009-03-30 21:15:38 +00:00
|
|
|
ui.listThemes->setSortingEnabled(true);
|
2007-08-15 21:54:15 +00:00
|
|
|
ui.themePreview->clear();
|
|
|
|
ui.themePreview->setText(tr("no theme selected"));
|
2009-03-30 21:15:43 +00:00
|
|
|
ui.labelSize->setText(tr("no selection"));
|
2009-10-31 17:16:34 +00:00
|
|
|
ui.themeDescription->setLayoutDirection(Qt::LeftToRight);
|
2007-09-14 22:16:22 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(close()));
|
|
|
|
connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
|
2009-03-30 21:15:43 +00:00
|
|
|
connect(ui.listThemes, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
|
|
|
this, SLOT(updateDetails(QListWidgetItem*, QListWidgetItem*)));
|
|
|
|
connect(ui.listThemes, SIGNAL(itemSelectionChanged()), this, SLOT(updateSize()));
|
2009-03-22 08:33:39 +00:00
|
|
|
connect(&igetter, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 22:16:22 +00:00
|
|
|
ThemesInstallWindow::~ThemesInstallWindow()
|
|
|
|
{
|
|
|
|
if(infocachedir!="")
|
|
|
|
recRmdir(infocachedir);
|
|
|
|
}
|
2007-08-15 21:54:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::downloadInfo()
|
|
|
|
{
|
|
|
|
// try to get the current build information
|
|
|
|
getter = new HttpGet(this);
|
2009-03-22 19:56:13 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
themesInfo.open();
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] downloading info to" << themesInfo.fileName();
|
2007-08-15 21:54:15 +00:00
|
|
|
themesInfo.close();
|
|
|
|
|
|
|
|
QUrl url;
|
2009-05-19 21:10:19 +00:00
|
|
|
url = QUrl(RbSettings::value(RbSettings::ThemesUrl).toString()
|
|
|
|
+ "/rbutilqt.php?target="
|
2009-05-09 16:59:14 +00:00
|
|
|
+ RbSettings::value(RbSettings::CurConfigureModel).toString());
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] Info URL:" << url << "Query:" << url.queryItems();
|
2009-05-09 16:59:14 +00:00
|
|
|
if(RbSettings::value(RbSettings::CacheOffline).toBool())
|
2008-03-05 21:12:24 +00:00
|
|
|
getter->setCache(true);
|
2007-08-15 21:54:15 +00:00
|
|
|
getter->setFile(&themesInfo);
|
2009-03-22 08:33:39 +00:00
|
|
|
|
2008-04-06 20:29:26 +00:00
|
|
|
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
|
|
|
connect(logger, SIGNAL(aborted()), getter, SLOT(abort()));
|
2007-08-15 21:54:15 +00:00
|
|
|
getter->getFile(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::downloadDone(int id, bool error)
|
|
|
|
{
|
|
|
|
downloadDone(error);
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] Download" << id << "done, error:" << error;
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::downloadDone(bool error)
|
|
|
|
{
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] Download done, error:" << error;
|
2007-08-15 21:54:15 +00:00
|
|
|
|
|
|
|
disconnect(logger, SIGNAL(aborted()), getter, SLOT(abort()));
|
|
|
|
disconnect(logger, SIGNAL(aborted()), this, SLOT(close()));
|
|
|
|
themesInfo.open();
|
|
|
|
|
|
|
|
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
|
|
|
QStringList tl = iniDetails.childGroups();
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] Theme site result:"
|
|
|
|
<< iniDetails.value("error/code").toString()
|
|
|
|
<< iniDetails.value("error/description").toString()
|
|
|
|
<< iniDetails.value("error/query").toString();
|
2007-08-15 21:54:15 +00:00
|
|
|
|
|
|
|
if(error) {
|
2009-03-22 08:33:49 +00:00
|
|
|
logger->addItem(tr("Network error: %1.\n"
|
|
|
|
"Please check your network and proxy settings.")
|
2007-08-15 21:54:15 +00:00
|
|
|
.arg(getter->errorString()), LOGERROR);
|
|
|
|
getter->abort();
|
2009-05-02 18:40:04 +00:00
|
|
|
logger->setFinished();
|
2007-08-15 21:54:15 +00:00
|
|
|
disconnect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
|
|
|
connect(logger, SIGNAL(closed()), this, SLOT(close()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// handle possible error codes
|
|
|
|
if(iniDetails.value("error/code").toInt() != 0 || !iniDetails.contains("error/code")) {
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] Theme site returned an error:"
|
|
|
|
<< iniDetails.value("error/code");
|
2007-08-15 21:54:15 +00:00
|
|
|
logger->addItem(tr("the following error occured:\n%1")
|
|
|
|
.arg(iniDetails.value("error/description", "unknown error").toString()), LOGERROR);
|
2009-05-02 18:40:04 +00:00
|
|
|
logger->setFinished();
|
2007-08-15 21:54:15 +00:00
|
|
|
connect(logger, SIGNAL(closed()), this, SLOT(close()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
logger->addItem(tr("done."), LOGOK);
|
2009-05-02 18:40:04 +00:00
|
|
|
logger->setFinished();
|
2007-08-15 21:54:15 +00:00
|
|
|
logger->close();
|
|
|
|
|
|
|
|
// setup list
|
|
|
|
for(int i = 0; i < tl.size(); i++) {
|
|
|
|
iniDetails.beginGroup(tl.at(i));
|
|
|
|
// skip all themes without name field set (i.e. error section)
|
2009-03-22 08:33:49 +00:00
|
|
|
if(iniDetails.value("name").toString().isEmpty()) {
|
|
|
|
iniDetails.endGroup();
|
|
|
|
continue;
|
|
|
|
}
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] adding to list:" << tl.at(i);
|
2009-04-27 17:48:49 +00:00
|
|
|
// convert to unicode and replace HTML-specific entities
|
|
|
|
QByteArray raw = iniDetails.value("name").toByteArray();
|
|
|
|
QTextCodec* codec = QTextCodec::codecForHtml(raw);
|
|
|
|
QString name = codec->toUnicode(raw);
|
|
|
|
name.replace(""", "\"").replace("&", "&");
|
|
|
|
name.replace("<", "<").replace(">", ">");
|
2007-08-15 21:54:15 +00:00
|
|
|
QListWidgetItem *w = new QListWidgetItem;
|
2009-04-27 17:48:49 +00:00
|
|
|
w->setData(Qt::DisplayRole, name.trimmed());
|
2007-08-15 21:54:15 +00:00
|
|
|
w->setData(Qt::UserRole, tl.at(i));
|
|
|
|
ui.listThemes->addItem(w);
|
|
|
|
|
|
|
|
iniDetails.endGroup();
|
|
|
|
}
|
2009-03-22 21:39:40 +00:00
|
|
|
// check if there's a themes "MOTD" available
|
|
|
|
if(iniDetails.contains("status/msg")) {
|
|
|
|
// check if there's a localized msg available
|
2009-05-09 16:59:14 +00:00
|
|
|
QString lang = RbSettings::value(RbSettings::Language).toString().split("_").at(0);
|
2009-03-22 21:39:40 +00:00
|
|
|
QString msg;
|
|
|
|
if(iniDetails.contains("status/msg." + lang))
|
|
|
|
msg = iniDetails.value("status/msg." + lang).toString();
|
|
|
|
else
|
|
|
|
msg = iniDetails.value("status/msg").toString();
|
2009-03-29 21:11:27 +00:00
|
|
|
qDebug() << "[Themes] MOTD" << msg;
|
|
|
|
if(!msg.isEmpty())
|
|
|
|
QMessageBox::information(this, tr("Information"), msg);
|
2009-03-22 21:39:40 +00:00
|
|
|
}
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-30 21:15:43 +00:00
|
|
|
void ThemesInstallWindow::updateSize(void)
|
2007-08-15 21:54:15 +00:00
|
|
|
{
|
2009-03-30 21:15:43 +00:00
|
|
|
long size = 0;
|
|
|
|
// sum up size for all selected themes
|
|
|
|
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
|
|
|
int items = ui.listThemes->selectedItems().size();
|
|
|
|
for(int i = 0; i < items; i++) {
|
|
|
|
iniDetails.beginGroup(ui.listThemes->selectedItems()
|
|
|
|
.at(i)->data(Qt::UserRole).toString());
|
|
|
|
size += iniDetails.value("size").toInt();
|
|
|
|
iniDetails.endGroup();
|
|
|
|
}
|
|
|
|
ui.labelSize->setText(tr("Download size %L1 kiB (%n item(s))", "", items)
|
|
|
|
.arg((size + 512) / 1024));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::updateDetails(QListWidgetItem* cur, QListWidgetItem* prev)
|
|
|
|
{
|
|
|
|
if(cur == prev)
|
|
|
|
return;
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
2009-03-30 21:15:43 +00:00
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
2007-08-15 21:54:15 +00:00
|
|
|
ui.themeDescription->setText(tr("fetching details for %1")
|
2009-03-30 21:15:43 +00:00
|
|
|
.arg(cur->data(Qt::DisplayRole).toString()));
|
2007-08-15 21:54:15 +00:00
|
|
|
ui.themePreview->clear();
|
|
|
|
ui.themePreview->setText(tr("fetching preview ..."));
|
2009-04-21 19:50:27 +00:00
|
|
|
imgData.clear();
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2009-03-30 21:15:43 +00:00
|
|
|
iniDetails.beginGroup(cur->data(Qt::UserRole).toString());
|
2007-08-15 21:54:15 +00:00
|
|
|
|
|
|
|
QUrl img, txt;
|
2009-05-09 16:59:14 +00:00
|
|
|
txt = QUrl(QString(RbSettings::value(RbSettings::ThemesUrl).toString() + "/"
|
2007-08-15 21:54:15 +00:00
|
|
|
+ iniDetails.value("descriptionfile").toString()));
|
2009-05-09 16:59:14 +00:00
|
|
|
img = QUrl(QString(RbSettings::value(RbSettings::ThemesUrl).toString() + "/"
|
2007-08-15 21:54:15 +00:00
|
|
|
+ iniDetails.value("image").toString()));
|
|
|
|
|
|
|
|
QString text;
|
2009-04-27 17:48:49 +00:00
|
|
|
QTextCodec* codec = QTextCodec::codecForName("UTF-8");
|
|
|
|
text = tr("<b>Author:</b> %1<hr/>").arg(codec->toUnicode(iniDetails
|
|
|
|
.value("author", tr("unknown")).toByteArray()));
|
|
|
|
text += tr("<b>Version:</b> %1<hr/>").arg(codec->toUnicode(iniDetails
|
|
|
|
.value("version", tr("unknown")).toByteArray()));
|
|
|
|
text += tr("<b>Description:</b> %1<hr/>").arg(codec->toUnicode(iniDetails
|
|
|
|
.value("about", tr("no description")).toByteArray()));
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2009-04-27 16:07:27 +00:00
|
|
|
text.trimmed();
|
|
|
|
text.replace("\n", "<br/>");
|
2007-08-15 21:54:15 +00:00
|
|
|
ui.themeDescription->setHtml(text);
|
|
|
|
iniDetails.endGroup();
|
|
|
|
|
|
|
|
igetter.abort();
|
2009-05-09 16:59:14 +00:00
|
|
|
if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
|
2008-03-05 21:12:24 +00:00
|
|
|
igetter.setCache(true);
|
2007-09-14 22:16:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(infocachedir=="")
|
|
|
|
{
|
2009-03-30 21:15:43 +00:00
|
|
|
infocachedir = QDir::tempPath() + "rbutil-themeinfo";
|
2007-09-14 22:16:22 +00:00
|
|
|
QDir d = QDir::temp();
|
|
|
|
d.mkdir("rbutil-themeinfo");
|
|
|
|
}
|
|
|
|
igetter.setCache(infocachedir);
|
|
|
|
}
|
2009-03-22 08:33:39 +00:00
|
|
|
|
2008-04-01 18:02:56 +00:00
|
|
|
igetter.getFile(img);
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::updateImage(bool error)
|
|
|
|
{
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] Updating image:"<< !error;
|
2008-09-14 19:56:58 +00:00
|
|
|
|
2009-03-22 19:56:13 +00:00
|
|
|
if(error) {
|
|
|
|
ui.themePreview->clear();
|
|
|
|
ui.themePreview->setText(tr("Retrieving theme preview failed.\n"
|
|
|
|
"HTTP response code: %1").arg(igetter.httpResponse()));
|
|
|
|
return;
|
|
|
|
}
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-21 18:24:55 +00:00
|
|
|
QPixmap p;
|
2007-08-15 21:54:15 +00:00
|
|
|
if(!error) {
|
|
|
|
imgData = igetter.readAll();
|
|
|
|
if(imgData.isNull()) return;
|
|
|
|
p.loadFromData(imgData);
|
2007-08-21 18:24:55 +00:00
|
|
|
if(p.isNull()) {
|
2007-08-15 21:54:15 +00:00
|
|
|
ui.themePreview->clear();
|
|
|
|
ui.themePreview->setText(tr("no theme preview"));
|
|
|
|
}
|
2007-09-15 22:57:07 +00:00
|
|
|
else
|
2007-08-21 18:24:55 +00:00
|
|
|
ui.themePreview->setPixmap(p);
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::resizeEvent(QResizeEvent* e)
|
|
|
|
{
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes]" << e;
|
2007-08-15 21:54:15 +00:00
|
|
|
|
|
|
|
QPixmap p, q;
|
|
|
|
QSize img;
|
|
|
|
img.setHeight(ui.themePreview->height());
|
|
|
|
img.setWidth(ui.themePreview->width());
|
|
|
|
|
|
|
|
p.loadFromData(imgData);
|
|
|
|
if(p.isNull()) return;
|
|
|
|
q = p.scaled(img, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
|
|
ui.themePreview->setScaledContents(false);
|
2007-08-23 17:38:39 +00:00
|
|
|
ui.themePreview->setPixmap(p);
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::show()
|
|
|
|
{
|
|
|
|
QDialog::show();
|
|
|
|
logger = new ProgressLoggerGui(this);
|
|
|
|
logger->show();
|
|
|
|
logger->addItem(tr("getting themes information ..."), LOGINFO);
|
2009-03-22 08:33:39 +00:00
|
|
|
|
|
|
|
connect(logger, SIGNAL(aborted()), this, SLOT(close()));
|
2008-04-06 19:50:38 +00:00
|
|
|
|
|
|
|
downloadInfo();
|
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::abort()
|
|
|
|
{
|
|
|
|
igetter.abort();
|
2009-05-02 18:40:04 +00:00
|
|
|
logger->setFinished();
|
2007-08-15 21:54:15 +00:00
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::accept()
|
|
|
|
{
|
|
|
|
if(ui.listThemes->selectedItems().size() == 0) {
|
|
|
|
this->close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QStringList themes;
|
|
|
|
QStringList names;
|
2007-08-26 16:03:56 +00:00
|
|
|
QStringList version;
|
2007-08-15 21:54:15 +00:00
|
|
|
QString zip;
|
|
|
|
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
|
|
|
for(int i = 0; i < ui.listThemes->selectedItems().size(); i++) {
|
|
|
|
iniDetails.beginGroup(ui.listThemes->selectedItems().at(i)->data(Qt::UserRole).toString());
|
2009-05-09 16:59:14 +00:00
|
|
|
zip = RbSettings::value(RbSettings::ThemesUrl).toString()
|
2007-08-26 16:03:56 +00:00
|
|
|
+ "/" + iniDetails.value("archive").toString();
|
2007-08-15 21:54:15 +00:00
|
|
|
themes.append(zip);
|
2007-08-26 16:03:56 +00:00
|
|
|
names.append("Theme: " +
|
|
|
|
ui.listThemes->selectedItems().at(i)->data(Qt::DisplayRole).toString());
|
|
|
|
// if no version info is available use installation (current) date
|
|
|
|
version.append(iniDetails.value("version",
|
|
|
|
QDate().currentDate().toString("yyyyMMdd")).toString());
|
2007-08-15 21:54:15 +00:00
|
|
|
iniDetails.endGroup();
|
|
|
|
}
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] installing:" << themes;
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
logger = new ProgressLoggerGui(this);
|
|
|
|
logger->show();
|
2009-05-09 16:59:14 +00:00
|
|
|
QString mountPoint = RbSettings::value(RbSettings::Mountpoint).toString();
|
2009-05-19 21:10:19 +00:00
|
|
|
qDebug() << "[Themes] mountpoint:" << mountPoint;
|
2007-08-15 21:54:15 +00:00
|
|
|
// show dialog with error if mount point is wrong
|
|
|
|
if(!QFileInfo(mountPoint).isDir()) {
|
|
|
|
logger->addItem(tr("Mount point is wrong!"),LOGERROR);
|
2009-05-02 18:40:04 +00:00
|
|
|
logger->setFinished();
|
2007-08-15 21:54:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
installer = new ZipInstaller(this);
|
|
|
|
installer->setUrl(themes);
|
|
|
|
installer->setLogSection(names);
|
2007-08-26 16:03:56 +00:00
|
|
|
installer->setLogVersion(version);
|
2007-08-15 21:54:15 +00:00
|
|
|
installer->setMountPoint(mountPoint);
|
2009-05-09 16:59:14 +00:00
|
|
|
if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
|
2008-03-05 21:12:24 +00:00
|
|
|
installer->setCache(true);
|
2009-03-22 08:33:39 +00:00
|
|
|
|
|
|
|
connect(logger, SIGNAL(closed()), this, SLOT(close()));
|
2009-05-02 18:50:31 +00:00
|
|
|
connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
|
|
|
|
connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
|
|
|
|
connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
|
|
|
|
connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
|
|
|
|
installer->install();
|
2009-03-22 08:33:39 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
}
|
|
|
|
|