summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/gui/manualwidget.cpp
blob: ae38980479c1df66654a8148d4938101b56059af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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%", "zip");
            manualbasename += "-html";
            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();
    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();
}