Add theme installation. This relies on a modified server script so the themes site need to incorporate the changes.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14363 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2007-08-15 21:54:15 +00:00
parent 53fbd6d01d
commit 653b996828
9 changed files with 527 additions and 5 deletions

View file

@ -0,0 +1,296 @@
/***************************************************************************
* __________ __ ___.
* 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"
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"));
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(close()));
connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
}
QString ThemesInstallWindow::resolution()
{
QString resolution;
devices->beginGroup(userSettings->value("defaults/platform").toString());
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);
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;
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 ..."));
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());
text += tr("<b>Description:</b> %1<br/>").arg(iniDetails.value("about", tr("no description")).toString());
ui.themeDescription->setHtml(text);
iniDetails.endGroup();
igetter.abort();
igetter.setProxy(proxy);
igetter.getFile(img);
connect(&igetter, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
}
void ThemesInstallWindow::updateImage(bool error)
{
qDebug() << "updateImage(bool) =" << error;
if(error) return;
QPixmap p, q;
QSize img;
img.setHeight(ui.themePreview->height());
img.setWidth(ui.themePreview->width());
if(!error) {
imgData = igetter.readAll();
if(imgData.isNull()) return;
p.loadFromData(imgData);
q = p.scaled(img, Qt::KeepAspectRatio, Qt::SmoothTransformation);
ui.themePreview->setScaledContents(false);
if(q.isNull()) {
ui.themePreview->clear();
ui.themePreview->setText(tr("no theme preview"));
}
else ui.themePreview->setPixmap(q);
}
}
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);
ui.themePreview->setPixmap(q);
}
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;
}
void ThemesInstallWindow::accept()
{
if(ui.listThemes->selectedItems().size() == 0) {
this->close();
return;
}
QStringList themes;
QStringList names;
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());
zip = devices->value("themes_url").toString() + "/" + iniDetails.value("archive").toString();
themes.append(zip);
names.append("Theme: " + ui.listThemes->selectedItems().at(i)->data(Qt::DisplayRole).toString());
iniDetails.endGroup();
}
qDebug() << "installing themes:" << themes;
logger = new ProgressLoggerGui(this);
logger->show();
QString mountPoint = userSettings->value("defaults/mountpoint").toString();
qDebug() << "mountpoint:" << userSettings->value("defaults/mountpoint").toString();
// 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);
installer->setMountPoint(mountPoint);
installer->install(logger);
connect(logger, SIGNAL(closed()), this, SLOT(close()));
}

View file

@ -0,0 +1,72 @@
/***************************************************************************
* __________ __ ___.
* 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.
*
****************************************************************************/
#ifndef INSTALLTHEMES_H
#define INSTALLTHEMES_H
#include <QtGui>
#include <QTemporaryFile>
#include "ui_installthemesfrm.h"
#include "httpget.h"
#include "installzip.h"
#include "progressloggergui.h"
class ThemesInstallWindow : public QDialog
{
Q_OBJECT
public:
ThemesInstallWindow(QWidget* parent = 0);
void setDeviceSettings(QSettings*);
void setUserSettings(QSettings *);
void setProxy(QUrl);
void downloadInfo(void);
void show(void);
void accept(void);
public slots:
private:
Ui::ThemeInstallFrm ui;
QSettings *devices;
QSettings *userSettings;
HttpGet *getter;
HttpGet igetter;
QTemporaryFile themesInfo;
QString resolution(void);
QUrl proxy;
int currentItem;
void resizeEvent(QResizeEvent*);
QByteArray imgData;
ProgressLoggerGui *logger;
ZipInstaller *installer;
QString file;
QString fileName;
private slots:
void downloadDone(bool);
void downloadDone(int, bool);
void updateDetails(int);
void updateImage(bool);
void abort(void);
};
#endif

View file

@ -0,0 +1,133 @@
<ui version="4.0" >
<class>ThemeInstallFrm</class>
<widget class="QDialog" name="ThemeInstallFrm" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>750</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle" >
<string>Theme Installation</string>
</property>
<layout class="QGridLayout" >
<item rowspan="2" row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string/>
</property>
<property name="pixmap" >
<pixmap resource="rbutilqt.qrc" >:/icons/icons/wizard.xpm</pixmap>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QListWidget" name="listThemes" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2" colspan="2" >
<widget class="QGroupBox" name="groupBox" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title" >
<string>Selected Theme</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="themePreview" >
<property name="sizePolicy" >
<sizepolicy vsizetype="MinimumExpanding" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string/>
</property>
<property name="scaledContents" >
<bool>true</bool>
</property>
<property name="alignment" >
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Description</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QTextBrowser" name="themeDescription" />
</item>
<item row="3" column="0" >
<widget class="QLabel" name="labelSize" >
<property name="text" >
<string>Download size:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>368</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="3" >
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="buttonOk" >
<property name="text" >
<string>&amp;Ok</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/go-next.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCancel" >
<property name="text" >
<string>&amp;Cancel</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/process-stop.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="rbutilqt.qrc" />
</resources>
<connections/>
</ui>

View file

@ -46,6 +46,7 @@ void ZipInstaller::installContinue()
qDebug() << "installContinue()";
runner++; // this gets called when a install finished, so increase first.
qDebug() << "runner is now at" << runner << "size is" << m_urllist.size();
if(runner < m_urllist.size()) {
qDebug() << "==> runner at" << runner;
m_dp->addItem(tr("done."), LOGOK);
@ -196,7 +197,7 @@ void ZipInstaller::updateDataReadProgress(int read, int total)
{
m_dp->setProgressMax(total);
m_dp->setProgressValue(read);
qDebug() << "progress:" << read << "/" << total;
//qDebug() << "progress:" << read << "/" << total;
}

View file

@ -8,7 +8,8 @@ font_url=http://www.rockbox.org/daily/fonts/rockbox-fonts.zip
last_release=2.5
prog_name=rockbox
bootloader_url=http://download.rockbox.org/bootloader
themes_url=http://www.rockbox-themes.org/
themes_url=http://copy.rockbox-themes.org
#themes_url=http://www.rockbox-themes.org
manual_url=http://download.rockbox.org/manual
doom_url=http://download.rockbox.org/useful/rockdoom.zip
voice_url=http://www.rockbox.org/voices/

View file

@ -28,6 +28,7 @@
#include "installtalkwindow.h"
#include "httpget.h"
#include "installbootloader.h"
#include "installthemes.h"
#include "uninstallwindow.h"
#include "browseof.h"
@ -81,11 +82,10 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom()));
connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
// disable unimplemented stuff
ui.buttonThemes->setEnabled(false);
ui.buttonSmall->setEnabled(false);
ui.buttonComplete->setEnabled(false);
@ -439,6 +439,22 @@ void RbUtilQt::installDoom()
}
void RbUtilQt::installThemes()
{
ThemesInstallWindow* tw = new ThemesInstallWindow(this);
tw->setDeviceSettings(devices);
tw->setUserSettings(userSettings);
if(userSettings->value("defaults/proxytype") == "manual")
tw->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
#ifdef __linux
else if(userSettings->value("defaults/proxytype") == "system")
tw->setProxy(QUrl(getenv("http_proxy")));
#endif
tw->setModal(true);
tw->show();
}
void RbUtilQt::createTalkFiles(void)
{
InstallTalkWindow *installWindow = new InstallTalkWindow(this);

View file

@ -66,6 +66,7 @@ class RbUtilQt : public QMainWindow
void downloadDone(int, bool);
void downloadInfo(void);
void installVoice(void);
void installThemes(void);
void uninstall(void);
void uninstallBootloader(void);
};

View file

@ -30,12 +30,12 @@ SOURCES += rbutilqt.cpp \
irivertools/irivertools.cpp \
irivertools/md5sum.cpp \
browsedirtree.cpp \
installthemes.cpp \
uninstall.cpp \
uninstallwindow.cpp \
browseof.cpp
HEADERS += rbutilqt.h \
settings.h \
install.h \
httpget.h \
configure.h \
@ -64,6 +64,7 @@ HEADERS += rbutilqt.h \
irivertools/h300sums.h \
irivertools/checksums.h \
browsedirtree.h \
installthemes.h \
uninstall.h \
uninstallwindow.h \
browseof.h
@ -85,6 +86,7 @@ FORMS += rbutilqtfrm.ui \
configurefrm.ui \
browsedirtreefrm.ui \
installtalkfrm.ui \
installthemesfrm.ui \
uninstallfrm.ui \
browseoffrm.ui