Update for single build-info file.
[maemo-rb.git] / rbutil / rbutilqt / gui / manualwidget.cpp
blob7be9145162e9d4dfba84adc638698dcc6838b551
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2012 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QtGui>
20 #include <QDebug>
21 #include "manualwidget.h"
22 #include "rbutilqt.h"
23 #include "rbsettings.h"
24 #include "serverinfo.h"
25 #include "systeminfo.h"
27 ManualWidget::ManualWidget(QWidget *parent) : QWidget(parent)
29 ui.setupUi(this);
30 ui.radioPdf->setChecked(true);
31 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
35 QString ManualWidget::manualUrl(ManualFormat format)
37 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()) {
38 return QString();
41 QString buildservermodel = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
42 QString modelman = SystemInfo::value(SystemInfo::CurManual).toString();
43 QString manualbasename;
45 if(modelman.isEmpty()) {
46 manualbasename = "rockbox-" + buildservermodel;
48 else {
49 manualbasename = "rockbox-" + modelman;
52 QString manual = SystemInfo::value(SystemInfo::ManualUrl).toString();
53 switch(format) {
54 case ManualPdf:
55 manual.replace("%EXTENSION%", "pdf");
56 break;
57 case ManualHtml:
58 manual.replace("%EXTENSION%", "html");
59 manualbasename += "/rockbox-build";
60 break;
61 case ManualZip:
62 manual.replace("%EXTENSION%", "zip");
63 manualbasename += "-html";
64 break;
65 default:
66 break;
69 manual.replace("%MANUALBASENAME%", manualbasename);
70 return manual;
74 void ManualWidget::updateManual()
76 if(!RbSettings::value(RbSettings::Platform).toString().isEmpty())
78 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
79 .arg(manualUrl(ManualPdf)));
80 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
81 .arg(manualUrl(ManualHtml)));
83 else {
84 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
85 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
86 .arg("http://www.rockbox.org/manual.shtml"));
91 void ManualWidget::downloadManual(void)
93 if(RbUtilQt::chkConfig(this)) {
94 return;
96 if(QMessageBox::question(this, tr("Confirm download"),
97 tr("Do you really want to download the manual? The manual will be saved "
98 "to the root folder of your player."),
99 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
100 return;
102 QString manual = SystemInfo::value(SystemInfo::CurManual).toString();
103 if(manual.isEmpty()) {
104 manual = "rockbox-" + SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
107 QString manualurl;
109 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
110 logger->show();
111 ZipInstaller *installer = new ZipInstaller(this);
112 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
113 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
114 installer->setCache(true);
116 if(ui.radioPdf->isChecked()) {
117 manualurl = manualUrl(ManualPdf);
118 installer->setLogSection("Manual (PDF)");
119 installer->setTarget("/" + manual + ".pdf");
121 else {
122 manualurl = manualUrl(ManualZip);
123 installer->setLogSection("Manual (HTML)");
124 installer->setTarget("/" + manual + "-" + "-html.zip");
126 qDebug() << "[ManualWidget] Manual URL:" << manualurl;
128 installer->setLogVersion();
129 installer->setUrl(manualurl);
130 installer->setUnzip(false);
132 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
133 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
134 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
135 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
136 installer->install();