summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/rbutilqt.cpp
blob: 14f34824f7abf76da274a25558dec79b2c688771 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/***************************************************************************
 *             __________               __   ___.
 *   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 "version.h"
#include "rbutilqt.h"
#include "ui_rbutilqtfrm.h"
#include "ui_aboutbox.h"
#include "configure.h"
#include "install.h"
#include "installbl.h"
#include "httpget.h"
#include "installbootloader.h"
#include "installzipwindow.h"

#ifdef __linux
#include <stdio.h>
#endif

RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
{
    QString programPath = qApp->arguments().at(0);
    absolutePath = QFileInfo(programPath).absolutePath() + "/";
    // use built-in rbutil.ini if no external file in binary folder
    QString iniFile = absolutePath + "rbutil.ini";
    if(QFileInfo(iniFile).isFile()) {
        qDebug() << "using external rbutil.ini";
        devices = new QSettings(iniFile, QSettings::IniFormat, 0);
    }
    else {
        qDebug() << "using built-in rbutil.ini";
        devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
    }

    ui.setupUi(this);
    initDeviceNames();

    // portable installation:
    // check for a configuration file in the program folder.
    QFileInfo config;
    config.setFile(absolutePath + "RockboxUtility.ini");
    if(config.isFile()) {
        userSettings = new QSettings(absolutePath + "RockboxUtility.ini",
            QSettings::IniFormat, 0);
        qDebug() << "config: portable";
    }
    else {
        userSettings = new QSettings(QSettings::IniFormat,
            QSettings::UserScope, "rockbox.org", "RockboxUtility");
        qDebug() << "config: system";
    }

    userSettings->beginGroup("defaults");
    platform = userSettings->value("platform").toString();
    userSettings->endGroup();
    ui.comboBoxDevice->setCurrentIndex(ui.comboBoxDevice->findData(platform));
    updateDevice(ui.comboBoxDevice->currentIndex());
    
    // manual tab
    ui.buttonDownloadManual->setEnabled(false);
    updateManual();

    connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
    connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
    connect(ui.comboBoxDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(updateDevice(int)));
    connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(install()));
    connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBl()));
    connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFonts()));
    connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom()));

    // disable unimplemented stuff
    ui.buttonThemes->setEnabled(false);
    ui.buttonSmall->setEnabled(false);
    ui.buttonRemoveRockbox->setEnabled(false);
    ui.buttonRemoveBootloader->setEnabled(false);
    ui.buttonComplete->setEnabled(false);
    ui.buttonDetect->setEnabled(false);

    initIpodpatcher();
    downloadInfo();

}


void RbUtilQt::downloadInfo()
{
    // try to get the current build information
    daily = new HttpGet(this);
    connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
    connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
    if(userSettings->value("defaults/proxytype") == "manual")
        daily->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
#ifdef __linux
    else if(userSettings->value("defaults/proxytype") == "system")
        daily->setProxy(QUrl(getenv("http_proxy")));
#endif

    qDebug() << "downloading build info";
    daily->setFile(&buildInfo);
    daily->getFile(QUrl(devices->value("server_conf_url").toString()));
}


void RbUtilQt::downloadDone(bool error)
{
    if(error) qDebug() << "network error:" << daily->error();
    qDebug() << "network status:" << daily->error();

}


void RbUtilQt::downloadDone(int id, bool error)
{
    QString errorString;
    errorString = tr("Network error: %1. Please check your network and proxy settings.").arg(daily->errorString());
    if(error) QMessageBox::about(this, "Network Error", errorString);
    qDebug() << "downloadDone:" << id << error;
}


void RbUtilQt::about()
{
    QDialog *window = new QDialog(this);
    Ui::aboutBox about;
    about.setupUi(window);
    window->setModal(true);
    
    QFile licence(":/docs/gpl-2.0.html");
    licence.open(QIODevice::ReadOnly);
    QTextStream c(&licence);
    QString cline = c.readAll();
    about.browserLicense->insertHtml(cline);
    about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
    QFile credits(":/docs/CREDITS");
    credits.open(QIODevice::ReadOnly);
    QTextStream r(&credits);
    QString rline = r.readAll();
    about.browserCredits->insertPlainText(rline);
    about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
    QString title = QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION);
    about.labelTitle->setText(title);
    about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");

    window->show();

}


void RbUtilQt::configDialog()
{
    Config *cw = new Config(this);
    cw->setUserSettings(userSettings);
    cw->show();
    connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
}


void RbUtilQt::initDeviceNames()
{
    qDebug() << "RbUtilQt::initDeviceNames()";
    devices->beginGroup("platforms");
    QStringList a = devices->childKeys();
    devices->endGroup();

    for(int it = 0; it < a.size(); it++) {
        QString curdev;
        devices->beginGroup("platforms");
        curdev = devices->value(a.at(it), "null").toString();
        devices->endGroup();
        QString curname;
        devices->beginGroup(curdev);
        curname = devices->value("name", "null").toString();
        devices->endGroup();
        ui.comboBoxDevice->addItem(curname, curdev);
    }
}


void RbUtilQt::updateDevice(int index)
{
    platform = ui.comboBoxDevice->itemData(index).toString();
    userSettings->setValue("defaults/platform", platform);
    userSettings->sync();

    devices->beginGroup(platform);
    if(devices->value("needsbootloader", "") == "no") {
        ui.buttonBootloader->setEnabled(false);
        ui.buttonRemoveBootloader->setEnabled(false);
        ui.labelBootloader->setEnabled(false);
        ui.labelRemoveBootloader->setEnabled(false);
    }
    else {
        ui.buttonBootloader->setEnabled(true);
        ui.labelBootloader->setEnabled(true);
        if(devices->value("bootloadermethod") == "fwpatcher") {
            ui.labelRemoveBootloader->setEnabled(false);
            ui.buttonRemoveBootloader->setEnabled(false);
        }
        else {
            ui.labelRemoveBootloader->setEnabled(true);
            ui.buttonRemoveBootloader->setEnabled(true);
        }
    }
    devices->endGroup();

    qDebug() << "new device selected:" << platform;
    // update manual from here to make sure new device is already selected
    updateManual();
}


void RbUtilQt::updateManual()
{
    if(userSettings->value("defaults/platform").toString() != "")
    {
        devices->beginGroup(userSettings->value("defaults/platform").toString());
        QString manual;
        manual = devices->value("manualname", "").toString();
        
        if(manual == "")
            manual = "rockbox-" + devices->value("platform").toString();
        devices->endGroup();
        QString pdfmanual;
        pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
        QString htmlmanual;
        htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
        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::install()
{
    Install *installWindow = new Install(this);
    installWindow->setUserSettings(userSettings);
    installWindow->setDeviceSettings(devices);
    if(userSettings->value("defaults/proxytype") == "manual")
        installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
#ifdef __linux
    else if(userSettings->value("defaults/proxytype") == "system")
        installWindow->setProxy(QUrl(getenv("http_proxy")));
#endif
    installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());

    buildInfo.open();
    QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
    buildInfo.close();
    installWindow->setArchivedString(info.value("dailies/date").toString());

    devices->beginGroup(platform);
    QString released = devices->value("released").toString();
    devices->endGroup();
    if(released == "yes")
        installWindow->setReleased(devices->value("last_release", "").toString());
    else
        installWindow->setReleased(0);

    installWindow->show();
}

void RbUtilQt::installBl()
{
    InstallBl *installWindow = new InstallBl(this);
    installWindow->setUserSettings(userSettings);
    installWindow->setDeviceSettings(devices);
    if(userSettings->value("defaults/proxytype") == "manual")
        installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
#ifdef __linux
    else if(userSettings->value("defaults/proxytype") == "system")
        installWindow->setProxy(QUrl(getenv("http_proxy")));
#endif
    installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());

    installWindow->show();
}

void RbUtilQt::installFonts()
{
    InstallZipWindow* installWindow = new InstallZipWindow(this);
    installWindow->setUserSettings(userSettings);
    installWindow->setDeviceSettings(devices);
    if(userSettings->value("defaults/proxytype") == "manual")
        installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
#ifdef __linux
    else if(userSettings->value("defaults/proxytype") == "system")
        installWindow->setProxy(QUrl(getenv("http_proxy")));
#endif
    installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
    installWindow->setLogSection("Fonts");
    installWindow->setUrl(devices->value("font_url").toString());
    installWindow->setWindowTitle("Font Installation");
    installWindow->show();

}

void RbUtilQt::installDoom()
{
    InstallZipWindow* installWindow = new InstallZipWindow(this);
    installWindow->setUserSettings(userSettings);
    installWindow->setDeviceSettings(devices);
    if(userSettings->value("defaults/proxytype") == "manual")
        installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
#ifdef __linux
    else if(userSettings->value("defaults/proxytype") == "system")
        installWindow->setProxy(QUrl(getenv("http_proxy")));
#endif
    installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
    installWindow->setLogSection("Doom");
    installWindow->setUrl(devices->value("doom_url").toString());
    installWindow->setWindowTitle("Doom Installation");
    installWindow->show();

}