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>
|
|
|
|
|
|
|
|
#include "ui_installthemesfrm.h"
|
|
|
|
#include "installthemes.h"
|
|
|
|
#include "installzip.h"
|
|
|
|
#include "progressloggergui.h"
|
2007-09-14 22:16:22 +00:00
|
|
|
#include "utils.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);
|
|
|
|
ui.themePreview->clear();
|
|
|
|
ui.themePreview->setText(tr("no theme selected"));
|
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()));
|
2007-09-15 21:58:31 +00:00
|
|
|
connect(ui.buttonOkAll, SIGNAL(clicked()), this, SLOT(acceptAll()));
|
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
|
|
|
|
|
|
|
QString ThemesInstallWindow::resolution()
|
|
|
|
{
|
|
|
|
QString resolution;
|
2007-09-03 14:37:00 +00:00
|
|
|
devices->beginGroup(userSettings->value("platform").toString());
|
2007-08-15 21:54:15 +00:00
|
|
|
resolution = devices->value("resolution").toString();
|
|
|
|
devices->endGroup();
|
|
|
|
return resolution;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::setDeviceSettings(QSettings *dev)
|
|
|
|
{
|
|
|
|
devices = dev;
|
|
|
|
qDebug() << "setDeviceSettings()" << devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::setUserSettings(QSettings *user)
|
|
|
|
{
|
|
|
|
userSettings = user;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::downloadInfo()
|
|
|
|
{
|
|
|
|
// try to get the current build information
|
|
|
|
getter = new HttpGet(this);
|
|
|
|
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
|
|
|
|
|
|
|
|
qDebug() << "downloading themes info";
|
|
|
|
themesInfo.open();
|
|
|
|
qDebug() << "file:" << themesInfo.fileName();
|
|
|
|
themesInfo.close();
|
|
|
|
|
|
|
|
QUrl url;
|
|
|
|
url = QUrl(devices->value("themes_url").toString() + "/rbutilqt.php?res=" + resolution());
|
|
|
|
qDebug() << "downloadInfo()" << url;
|
|
|
|
qDebug() << url.queryItems();
|
|
|
|
getter->setProxy(proxy);
|
2007-09-03 14:37:00 +00:00
|
|
|
if(userSettings->value("offline").toBool())
|
|
|
|
getter->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
|
2007-08-15 21:54:15 +00:00
|
|
|
getter->setFile(&themesInfo);
|
|
|
|
getter->getFile(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::downloadDone(int id, bool error)
|
|
|
|
{
|
|
|
|
downloadDone(error);
|
|
|
|
qDebug() << "downloadDone(bool) =" << id << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::downloadDone(bool error)
|
|
|
|
{
|
|
|
|
qDebug() << "downloadDone(bool) =" << error;
|
|
|
|
|
|
|
|
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();
|
|
|
|
qDebug() << tl.size();
|
|
|
|
qDebug() << iniDetails.value("error/code").toString()
|
|
|
|
<< iniDetails.value("error/description").toString()
|
|
|
|
<< iniDetails.value("error/query").toString();
|
|
|
|
|
|
|
|
if(error) {
|
|
|
|
logger->addItem(tr("Network error: %1.\nPlease check your network and proxy settings.")
|
|
|
|
.arg(getter->errorString()), LOGERROR);
|
|
|
|
getter->abort();
|
|
|
|
logger->abort();
|
|
|
|
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")) {
|
|
|
|
qDebug() << "error!";
|
|
|
|
logger->addItem(tr("the following error occured:\n%1")
|
|
|
|
.arg(iniDetails.value("error/description", "unknown error").toString()), LOGERROR);
|
|
|
|
logger->abort();
|
|
|
|
connect(logger, SIGNAL(closed()), this, SLOT(close()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
logger->addItem(tr("done."), LOGOK);
|
|
|
|
logger->abort();
|
|
|
|
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)
|
|
|
|
if(iniDetails.value("name").toString().isEmpty()) continue;
|
|
|
|
QListWidgetItem *w = new QListWidgetItem;
|
|
|
|
w->setData(Qt::DisplayRole, iniDetails.value("name").toString());
|
|
|
|
w->setData(Qt::UserRole, tl.at(i));
|
|
|
|
ui.listThemes->addItem(w);
|
|
|
|
|
|
|
|
iniDetails.endGroup();
|
|
|
|
}
|
|
|
|
connect(ui.listThemes, SIGNAL(currentRowChanged(int)), this, SLOT(updateDetails(int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::updateDetails(int row)
|
|
|
|
{
|
|
|
|
if(row == currentItem) return;
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
currentItem = row;
|
|
|
|
qDebug() << "updateDetails(int) =" << row;
|
|
|
|
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
|
|
|
ui.themeDescription->setText(tr("fetching details for %1")
|
|
|
|
.arg(ui.listThemes->item(row)->data(Qt::DisplayRole).toString()));
|
|
|
|
ui.themePreview->clear();
|
|
|
|
ui.themePreview->setText(tr("fetching preview ..."));
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
iniDetails.beginGroup(ui.listThemes->item(row)->data(Qt::UserRole).toString());
|
|
|
|
size += iniDetails.value("size").toInt();
|
|
|
|
qDebug() << ui.listThemes->item(row)->data(Qt::UserRole).toString() << size;
|
|
|
|
iniDetails.endGroup();
|
|
|
|
ui.labelSize->setText(tr("Download size %1 kiB").arg(size));
|
|
|
|
|
|
|
|
iniDetails.beginGroup(ui.listThemes->item(row)->data(Qt::UserRole).toString());
|
|
|
|
|
|
|
|
QUrl img, txt;
|
|
|
|
txt = QUrl(QString(devices->value("themes_url").toString() + "/"
|
|
|
|
+ iniDetails.value("descriptionfile").toString()));
|
|
|
|
img = QUrl(QString(devices->value("themes_url").toString() + "/"
|
|
|
|
+ iniDetails.value("image").toString()));
|
|
|
|
qDebug() << "txt:" << txt;
|
|
|
|
qDebug() << "img:" << img;
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
text = tr("<b>Author:</b> %1<hr/>").arg(iniDetails.value("author", tr("unknown")).toString());
|
|
|
|
text += tr("<b>Version:</b> %1<hr/>").arg(iniDetails.value("version", tr("unknown")).toString());
|
2007-08-26 16:03:56 +00:00
|
|
|
text += tr("<b>Description:</b> %1<hr/>").arg(iniDetails.value("about", tr("no description")).toString());
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
ui.themeDescription->setHtml(text);
|
|
|
|
iniDetails.endGroup();
|
|
|
|
|
|
|
|
igetter.abort();
|
|
|
|
igetter.setProxy(proxy);
|
2007-09-03 14:37:00 +00:00
|
|
|
if(!userSettings->value("cachedisable").toBool())
|
|
|
|
igetter.setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
|
2007-09-14 22:16:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(infocachedir=="")
|
|
|
|
{
|
|
|
|
infocachedir = QDir::tempPath()+"rbutil-themeinfo";
|
|
|
|
QDir d = QDir::temp();
|
|
|
|
d.mkdir("rbutil-themeinfo");
|
|
|
|
}
|
|
|
|
igetter.setCache(infocachedir);
|
|
|
|
}
|
2007-08-15 21:54:15 +00:00
|
|
|
igetter.getFile(img);
|
|
|
|
connect(&igetter, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::updateImage(bool error)
|
|
|
|
{
|
|
|
|
qDebug() << "updateImage(bool) =" << error;
|
|
|
|
if(error) 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)
|
|
|
|
{
|
|
|
|
qDebug() << "resizeEvent(QResizeEvent*) =" << e;
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
downloadInfo();
|
|
|
|
QDialog::show();
|
|
|
|
logger = new ProgressLoggerGui(this);
|
|
|
|
logger->show();
|
|
|
|
logger->addItem(tr("getting themes information ..."), LOGINFO);
|
|
|
|
connect(logger, SIGNAL(aborted()), getter, SLOT(abort()));
|
|
|
|
connect(logger, SIGNAL(aborted()), this, SLOT(close()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::abort()
|
|
|
|
{
|
|
|
|
igetter.abort();
|
|
|
|
logger->abort();
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThemesInstallWindow::setProxy(QUrl p)
|
|
|
|
{
|
|
|
|
proxy = p;
|
|
|
|
qDebug() << "setProxy()" << proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 21:58:31 +00:00
|
|
|
void ThemesInstallWindow::acceptAll()
|
|
|
|
{
|
|
|
|
ui.listThemes->selectAll();
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
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());
|
2007-08-26 16:03:56 +00:00
|
|
|
zip = devices->value("themes_url").toString()
|
|
|
|
+ "/" + 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();
|
|
|
|
}
|
|
|
|
qDebug() << "installing themes:" << themes;
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-15 21:54:15 +00:00
|
|
|
logger = new ProgressLoggerGui(this);
|
|
|
|
logger->show();
|
2007-09-03 14:37:00 +00:00
|
|
|
QString mountPoint = userSettings->value("mountpoint").toString();
|
|
|
|
qDebug() << "mountpoint:" << userSettings->value("mountpoint").toString();
|
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);
|
|
|
|
logger->abort();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
installer = new ZipInstaller(this);
|
|
|
|
installer->setUrl(themes);
|
|
|
|
installer->setProxy(proxy);
|
|
|
|
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);
|
2007-09-03 14:37:00 +00:00
|
|
|
if(!userSettings->value("cachedisable").toBool())
|
|
|
|
installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
|
2007-08-15 21:54:15 +00:00
|
|
|
installer->install(logger);
|
|
|
|
connect(logger, SIGNAL(closed()), this, SLOT(close()));
|
|
|
|
}
|
|
|
|
|