1
0
Fork 0
forked from len0rd/rockbox

Move manual tab contents to separate widget.

Create a new widget which holds the contents of the manual tab and its logic.
Unify its display / download code. Fixes FS#12587, which was caused by
duplicated code.

Change-Id: I5721d2a95ebeaf80481c1fd149eda22cf1328501
This commit is contained in:
Dominik Riebeling 2012-02-14 21:02:52 +01:00
parent 3933afcc09
commit f7fdf13468
8 changed files with 317 additions and 190 deletions

View file

@ -0,0 +1,140 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2012 by Dominik Riebeling
*
* 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 <QDebug>
#include "manualwidget.h"
#include "rbutilqt.h"
#include "rbsettings.h"
#include "serverinfo.h"
#include "systeminfo.h"
ManualWidget::ManualWidget(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
ui.radioPdf->setChecked(true);
connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
}
QString ManualWidget::manualUrl(ManualFormat format)
{
if(RbSettings::value(RbSettings::Platform).toString().isEmpty()) {
return QString();
}
QString buildservermodel = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
QString modelman = SystemInfo::value(SystemInfo::CurManual).toString();
QString manualbasename;
if(modelman.isEmpty()) {
manualbasename = "rockbox-" + buildservermodel;
}
else {
manualbasename = "rockbox-" + modelman;
}
QString manual = SystemInfo::value(SystemInfo::ManualUrl).toString();
switch(format) {
case ManualPdf:
manual.replace("%EXTENSION%", "pdf");
break;
case ManualHtml:
manual.replace("%EXTENSION%", "html");
manualbasename += "/rockbox-build";
break;
case ManualZip:
manual.replace("%EXTENSION%", "-html.zip");
manualbasename += "/rockbox-build";
break;
default:
break;
};
manual.replace("%MANUALBASENAME%", manualbasename);
return manual;
}
void ManualWidget::updateManual()
{
if(!RbSettings::value(RbSettings::Platform).toString().isEmpty())
{
ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
.arg(manualUrl(ManualPdf)));
ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
.arg(manualUrl(ManualHtml)));
}
else {
ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
.arg("http://www.rockbox.org/manual.shtml"));
}
}
void ManualWidget::downloadManual(void)
{
if(RbUtilQt::chkConfig(this)) {
return;
}
if(QMessageBox::question(this, tr("Confirm download"),
tr("Do you really want to download the manual? The manual will be saved "
"to the root folder of your player."),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
return;
}
QString manual = SystemInfo::value(SystemInfo::CurManual).toString();
if(manual.isEmpty()) {
manual = "rockbox-" + SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
}
QDate date = QDate::fromString(ServerInfo::value(
ServerInfo::DailyDate).toString(), Qt::ISODate);
QString manualurl;
ProgressLoggerGui* logger = new ProgressLoggerGui(this);
logger->show();
ZipInstaller *installer = new ZipInstaller(this);
installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
installer->setCache(true);
if(ui.radioPdf->isChecked()) {
manualurl = manualUrl(ManualPdf);
installer->setLogSection("Manual (PDF)");
installer->setTarget("/" + manual + ".pdf");
}
else {
manualurl = manualUrl(ManualZip);
installer->setLogSection("Manual (HTML)");
installer->setTarget("/" + manual + "-" + date.toString("yyyyMMdd") + "-html.zip");
}
qDebug() << "[ManualWidget] Manual URL:" << manualurl;
installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
installer->setUrl(manualurl);
installer->setUnzip(false);
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();
}

View file

@ -0,0 +1,46 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2012 by Dominik Riebeling
*
* 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 MANUALWIDGET_H
#define MANUALWIDGET_H
#include <QtGui>
#include "ui_manualwidgetfrm.h"
class ManualWidget : public QWidget
{
Q_OBJECT
public:
enum ManualFormat {
ManualPdf,
ManualHtml,
ManualZip,
};
ManualWidget(QWidget *parent = 0);
public slots:
void downloadManual(void);
void updateManual();
QString manualUrl(ManualFormat format);
private:
Ui::ManualWidgetFrm ui;
};
#endif

View file

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ManualWidgetFrm</class>
<widget class="QWidget" name="ManualWidgetFrm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>543</width>
<height>255</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Read the manual</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelPdfManual">
<property name="text">
<string>PDF manual</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelHtmlManual">
<property name="text">
<string>HTML manual</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Download the manual</string>
</property>
<layout class="QGridLayout" name="_2">
<item row="0" column="0">
<layout class="QVBoxLayout" name="_3">
<item>
<widget class="QRadioButton" name="radioPdf">
<property name="text">
<string>&amp;PDF version</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioHtmlzip">
<property name="text">
<string>&amp;HTML version (zip file)</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="buttonDownloadManual">
<property name="text">
<string>Down&amp;load</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -38,6 +38,7 @@
#include "serverinfo.h"
#include "systeminfo.h"
#include "ziputil.h"
#include "manualwidget.h"
#include "progressloggerinterface.h"
@ -113,8 +114,11 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
m_gotInfo = false;
m_auto = false;
// manual tab
ui.radioPdf->setChecked(true);
// insert ManualWidget() widget in manual tab
QGridLayout *mantablayout = new QGridLayout(this);
ui.manual->setLayout(mantablayout);
manual = new ManualWidget(this);
mantablayout->addWidget(manual);
// info tab
ui.treeInfo->setAlternatingRowColors(true);
@ -145,7 +149,6 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
@ -343,7 +346,7 @@ void RbUtilQt::updateSettings()
{
qDebug() << "[RbUtil] updating current settings";
updateDevice();
updateManual();
manual->updateManual();
HttpGet::setGlobalProxy(proxy());
HttpGet::setGlobalCache(RbSettings::value(RbSettings::CachePath).toString());
HttpGet::setGlobalDumbCache(RbSettings::value(RbSettings::CacheOffline).toBool());
@ -416,39 +419,6 @@ void RbUtilQt::updateDevice()
}
void RbUtilQt::updateManual()
{
if(RbSettings::value(RbSettings::Platform) != "")
{
QString manual = SystemInfo::value(SystemInfo::CurManual).toString();
QString buildservermodel = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
QString pdfmanual = SystemInfo::value(SystemInfo::ManualUrl).toString();
QString htmlmanual = pdfmanual;
pdfmanual.replace("%EXTENSION%", "pdf");
htmlmanual.replace("%EXTENSION%", "html");
if(manual.isEmpty()) {
pdfmanual.replace("%MANUALBASENAME%", "rockbox-" + buildservermodel);
htmlmanual.replace("%MANUALBASENAME%", "rockbox-" + buildservermodel + "/rockbox-build");
}
else {
pdfmanual.replace("%MANUALBASENAME%", "rockbox-" + manual);
htmlmanual.replace("%MANUALBASENAME%", "rockbox-" + manual + "/rockbox-build");
}
ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
.arg(pdfmanual));
ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
.arg(htmlmanual));
}
else {
ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
.arg("http://www.rockbox.org/manual.shtml"));
}
}
void RbUtilQt::completeInstall()
{
if(chkConfig(this)) return;
@ -1115,55 +1085,6 @@ void RbUtilQt::uninstallBootloader(void)
}
void RbUtilQt::downloadManual(void)
{
if(chkConfig(this)) return;
if(QMessageBox::question(this, tr("Confirm download"),
tr("Do you really want to download the manual? The manual will be saved "
"to the root folder of your player."),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return;
QString manual = SystemInfo::value(SystemInfo::CurManual).toString();
if(manual.isEmpty())
manual = "rockbox-"
+ SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
QDate date = QDate::fromString(ServerInfo::value(ServerInfo::DailyDate).toString(),Qt::ISODate);
QString manualurl;
QString target;
QString section;
if(ui.radioPdf->isChecked()) {
target = "/" + manual + ".pdf";
section = "Manual (PDF)";
}
else {
target = "/" + manual + "-" + date.toString("yyyyMMdd") + "-html.zip";
section = "Manual (HTML)";
}
manualurl = SystemInfo::value(SystemInfo::ManualUrl).toString() + "/" + target;
qDebug() << "[RbUtil] Manual URL:" << manualurl;
ProgressLoggerGui* logger = new ProgressLoggerGui(this);
logger->show();
installer = new ZipInstaller(this);
installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
installer->setCache(true);
installer->setLogSection(section);
installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
installer->setUrl(manualurl);
installer->setUnzip(false);
installer->setTarget(target);
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();
}
void RbUtilQt::installPortable(void)
{
if(QMessageBox::question(this, tr("Confirm installation"),

View file

@ -32,6 +32,7 @@
#include "zipinstaller.h"
#include "progressloggergui.h"
#include "bootloaderinstallbase.h"
#include "manualwidget.h"
class RbUtilQt : public QMainWindow
{
@ -43,6 +44,7 @@ class RbUtilQt : public QMainWindow
static bool chkConfig(QWidget *parent = 0);
private:
ManualWidget *manual;
Ui::RbUtilQtFrm ui;
void changeEvent(QEvent *e);
@ -55,7 +57,6 @@ class RbUtilQt : public QMainWindow
QString absolutePath;
QTemporaryFile buildInfo;
QTemporaryFile bleedingInfo;
void updateManual(void);
ProgressLoggerGui *logger;
ZipInstaller *installer;
QUrl proxy(void);
@ -109,7 +110,6 @@ class RbUtilQt : public QMainWindow
void installThemes(void);
void uninstall(void);
void uninstallBootloader(void);
void downloadManual(void);
void installPortable(void);
void updateInfo(void);
void updateTabs(int);

View file

@ -17,6 +17,7 @@
# common files
SOURCES += \
gui/manualwidget.cpp \
rbutilqt.cpp \
main.cpp \
installwindow.cpp \
@ -78,6 +79,7 @@ SOURCES += \
HEADERS += \
gui/manualwidget.h \
rbutilqt.h \
installwindow.h \
base/httpget.h \
@ -146,6 +148,7 @@ HEADERS += \
FORMS += \
gui/manualwidgetfrm.ui \
rbutilqtfrm.ui \
aboutbox.ui \
installwindowfrm.ui \

View file

@ -145,7 +145,8 @@ QMAKE_EXTRA_TARGETS += lrelease
# Needed by QT on Win
INCLUDEPATH = $$_PRO_FILE_PWD_ $$_PRO_FILE_PWD_/irivertools \
$$_PRO_FILE_PWD_/zlib $$_PRO_FILE_PWD_/base
$$_PRO_FILE_PWD_/zlib $$_PRO_FILE_PWD_/base \
$$_PRO_FILE_PWD_/zlib $$_PRO_FILE_PWD_/gui
INCLUDEPATH += $$RBBASE_DIR/rbutil/ipodpatcher $$RBBASE_DIR/rbutil/sansapatcher \
$$RBBASE_DIR/tools/rbspeex $$RBBASE_DIR/tools

View file

@ -650,103 +650,6 @@
<attribute name="toolTip">
<string>View and download the manual</string>
</attribute>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Read the manual</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelPdfManual">
<property name="text">
<string>PDF manual</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelHtmlManual">
<property name="text">
<string>HTML manual</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Download the manual</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout">
<item>
<widget class="QRadioButton" name="radioPdf">
<property name="text">
<string>&amp;PDF version</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioHtmlzip">
<property name="text">
<string>&amp;HTML version (zip file)</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="buttonDownloadManual">
<property name="text">
<string>Down&amp;load</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="info">
<attribute name="title">
@ -787,7 +690,7 @@
<x>0</x>
<y>0</y>
<width>650</width>
<height>18</height>
<height>27</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@ -1064,9 +967,6 @@
<tabstop>buttonGames</tabstop>
<tabstop>buttonRemoveBootloader</tabstop>
<tabstop>buttonRemoveRockbox</tabstop>
<tabstop>radioPdf</tabstop>
<tabstop>radioHtmlzip</tabstop>
<tabstop>buttonDownloadManual</tabstop>
<tabstop>buttonChangeDevice</tabstop>
<tabstop>buttonVoice</tabstop>
<tabstop>buttonCreateVoice</tabstop>