From f7fdf134681a35950edeb1054a1e095f7acec058 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Tue, 14 Feb 2012 21:02:52 +0100 Subject: 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 --- rbutil/rbutilqt/gui/manualwidget.cpp | 140 +++++++++++++++++++++++++++++++++ rbutil/rbutilqt/gui/manualwidget.h | 46 +++++++++++ rbutil/rbutilqt/gui/manualwidgetfrm.ui | 116 +++++++++++++++++++++++++++ 3 files changed, 302 insertions(+) create mode 100644 rbutil/rbutilqt/gui/manualwidget.cpp create mode 100644 rbutil/rbutilqt/gui/manualwidget.h create mode 100644 rbutil/rbutilqt/gui/manualwidgetfrm.ui (limited to 'rbutil/rbutilqt/gui') diff --git a/rbutil/rbutilqt/gui/manualwidget.cpp b/rbutil/rbutilqt/gui/manualwidget.cpp new file mode 100644 index 0000000000..f84da69a2a --- /dev/null +++ b/rbutil/rbutilqt/gui/manualwidget.cpp @@ -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 +#include +#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("PDF Manual") + .arg(manualUrl(ManualPdf))); + ui.labelHtmlManual->setText(tr("HTML Manual (opens in browser)") + .arg(manualUrl(ManualHtml))); + } + else { + ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual")); + ui.labelHtmlManual->setText(tr("Manual Overview") + .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(); +} + diff --git a/rbutil/rbutilqt/gui/manualwidget.h b/rbutil/rbutilqt/gui/manualwidget.h new file mode 100644 index 0000000000..6de2de55bd --- /dev/null +++ b/rbutil/rbutilqt/gui/manualwidget.h @@ -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 +#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 + diff --git a/rbutil/rbutilqt/gui/manualwidgetfrm.ui b/rbutil/rbutilqt/gui/manualwidgetfrm.ui new file mode 100644 index 0000000000..8757c4569e --- /dev/null +++ b/rbutil/rbutilqt/gui/manualwidgetfrm.ui @@ -0,0 +1,116 @@ + + + ManualWidgetFrm + + + + 0 + 0 + 543 + 255 + + + + Form + + + + + + Read the manual + + + + + + PDF manual + + + true + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse + + + + + + + HTML manual + + + true + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse + + + + + + + + + + Download the manual + + + + + + + + &PDF version + + + + + + + &HTML version (zip file) + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Down&load + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + -- cgit v1.2.3