Oops.
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob9532ba1c991f29cadd9bea9cf2fe6c1f1ecba3f7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <QtGui>
22 #include "version.h"
23 #include "rbutilqt.h"
24 #include "ui_rbutilqtfrm.h"
25 #include "ui_aboutbox.h"
26 #include "configure.h"
27 #include "install.h"
28 #include "installbl.h"
29 #include "installtalkwindow.h"
30 #include "httpget.h"
31 #include "installbootloader.h"
33 #ifdef __linux
34 #include <stdio.h>
35 #endif
37 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
39 QString programPath = qApp->arguments().at(0);
40 absolutePath = QFileInfo(programPath).absolutePath() + "/";
41 // use built-in rbutil.ini if no external file in binary folder
42 QString iniFile = absolutePath + "rbutil.ini";
43 if(QFileInfo(iniFile).isFile()) {
44 qDebug() << "using external rbutil.ini";
45 devices = new QSettings(iniFile, QSettings::IniFormat, 0);
47 else {
48 qDebug() << "using built-in rbutil.ini";
49 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
52 ui.setupUi(this);
54 // portable installation:
55 // check for a configuration file in the program folder.
56 QFileInfo config;
57 config.setFile(absolutePath + "RockboxUtility.ini");
58 if(config.isFile()) {
59 userSettings = new QSettings(absolutePath + "RockboxUtility.ini",
60 QSettings::IniFormat, 0);
61 qDebug() << "config: portable";
63 else {
64 userSettings = new QSettings(QSettings::IniFormat,
65 QSettings::UserScope, "rockbox.org", "RockboxUtility");
66 qDebug() << "config: system";
69 // manual tab
70 ui.buttonDownloadManual->setEnabled(false);
71 updateManual();
72 updateDevice();
74 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
75 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
76 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
77 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
78 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(install()));
79 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBl()));
80 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFonts()));
81 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom()));
82 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
83 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
86 // disable unimplemented stuff
87 ui.buttonThemes->setEnabled(false);
88 ui.buttonSmall->setEnabled(false);
89 ui.buttonRemoveRockbox->setEnabled(false);
90 ui.buttonRemoveBootloader->setEnabled(false);
91 ui.buttonComplete->setEnabled(false);
93 initIpodpatcher();
94 initSansapatcher();
95 downloadInfo();
100 void RbUtilQt::downloadInfo()
102 // try to get the current build information
103 daily = new HttpGet(this);
104 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
105 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
106 if(userSettings->value("defaults/proxytype") == "manual")
107 daily->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
108 #ifdef __linux
109 else if(userSettings->value("defaults/proxytype") == "system")
110 daily->setProxy(QUrl(getenv("http_proxy")));
111 #endif
113 qDebug() << "downloading build info";
114 daily->setFile(&buildInfo);
115 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
119 void RbUtilQt::downloadDone(bool error)
121 if(error) qDebug() << "network error:" << daily->error();
122 qDebug() << "network status:" << daily->error();
127 void RbUtilQt::downloadDone(int id, bool error)
129 QString errorString;
130 errorString = tr("Network error: %1. Please check your network and proxy settings.")
131 .arg(daily->errorString());
132 if(error) QMessageBox::about(this, "Network Error", errorString);
133 qDebug() << "downloadDone:" << id << error;
137 void RbUtilQt::about()
139 QDialog *window = new QDialog(this);
140 Ui::aboutBox about;
141 about.setupUi(window);
142 window->setModal(true);
144 QFile licence(":/docs/gpl-2.0.html");
145 licence.open(QIODevice::ReadOnly);
146 QTextStream c(&licence);
147 QString cline = c.readAll();
148 about.browserLicense->insertHtml(cline);
149 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
150 QFile credits(":/docs/CREDITS");
151 credits.open(QIODevice::ReadOnly);
152 QTextStream r(&credits);
153 QString rline = r.readAll();
154 about.browserCredits->insertPlainText(rline);
155 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
156 QString title = QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION);
157 about.labelTitle->setText(title);
158 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
160 window->show();
165 void RbUtilQt::configDialog()
167 Config *cw = new Config(this);
168 cw->setUserSettings(userSettings);
169 cw->setDevices(devices);
170 cw->show();
171 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
172 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
176 void RbUtilQt::updateSettings()
178 qDebug() << "updateSettings()";
179 updateDevice();
180 updateManual();
184 void RbUtilQt::updateDevice()
186 platform = userSettings->value("defaults/platform").toString();
187 // buttons
188 devices->beginGroup(platform);
189 if(devices->value("needsbootloader", "") == "no") {
190 ui.buttonBootloader->setEnabled(false);
191 ui.buttonRemoveBootloader->setEnabled(false);
192 ui.labelBootloader->setEnabled(false);
193 ui.labelRemoveBootloader->setEnabled(false);
195 else {
196 ui.buttonBootloader->setEnabled(true);
197 ui.labelBootloader->setEnabled(true);
198 if(devices->value("bootloadermethod") == "fwpatcher") {
199 ui.labelRemoveBootloader->setEnabled(false);
200 ui.buttonRemoveBootloader->setEnabled(false);
202 else {
203 ui.labelRemoveBootloader->setEnabled(true);
204 ui.buttonRemoveBootloader->setEnabled(true);
207 devices->endGroup();
208 // displayed device info
209 platform = userSettings->value("defaults/platform").toString();
210 QString mountpoint = userSettings->value("defaults/mountpoint").toString();
211 devices->beginGroup(platform);
212 QString brand = devices->value("brand").toString();
213 QString name = devices->value("name").toString();
214 devices->endGroup();
215 if(name.isEmpty()) name = "&lt;none&gt;";
216 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
217 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
218 .arg(brand, name, mountpoint));
222 void RbUtilQt::updateManual()
224 if(userSettings->value("defaults/platform").toString() != "")
226 devices->beginGroup(userSettings->value("defaults/platform").toString());
227 QString manual;
228 manual = devices->value("manualname", "").toString();
230 if(manual == "")
231 manual = "rockbox-" + devices->value("platform").toString();
232 devices->endGroup();
233 QString pdfmanual;
234 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
235 QString htmlmanual;
236 htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
237 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
238 .arg(pdfmanual));
239 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
240 .arg(htmlmanual));
242 else {
243 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
244 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
245 .arg("http://www.rockbox.org/manual.shtml"));
251 void RbUtilQt::install()
253 Install *installWindow = new Install(this);
254 installWindow->setUserSettings(userSettings);
255 installWindow->setDeviceSettings(devices);
256 if(userSettings->value("defaults/proxytype") == "manual")
257 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
258 #ifdef __linux
259 else if(userSettings->value("defaults/proxytype") == "system")
260 installWindow->setProxy(QUrl(getenv("http_proxy")));
261 #endif
263 buildInfo.open();
264 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
265 buildInfo.close();
266 installWindow->setArchivedString(info.value("dailies/date").toString());
268 devices->beginGroup(platform);
269 QString released = devices->value("released").toString();
270 devices->endGroup();
271 if(released == "yes")
272 installWindow->setReleased(devices->value("last_release", "").toString());
273 else
274 installWindow->setReleased(0);
276 installWindow->show();
280 void RbUtilQt::installBl()
282 InstallBl *installWindow = new InstallBl(this);
283 installWindow->setUserSettings(userSettings);
284 installWindow->setDeviceSettings(devices);
285 if(userSettings->value("defaults/proxytype") == "manual")
286 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
287 #ifdef __linux
288 else if(userSettings->value("defaults/proxytype") == "system")
289 installWindow->setProxy(QUrl(getenv("http_proxy")));
290 #endif
291 installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
293 installWindow->show();
297 void RbUtilQt::installFonts()
299 if(QMessageBox::question(this, tr("Confirm Installation"),
300 tr("Do you really want to install the fonts package?"),
301 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
302 // create logger
303 logger = new ProgressLoggerGui(this);
304 logger->show();
306 // create zip installer
307 installer = new ZipInstaller(this);
309 installer->setUrl(devices->value("font_url").toString());
310 if(userSettings->value("defaults/proxytype") == "manual")
311 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
312 #ifdef __linux
313 else if(userSettings->value("defaults/proxytype") == "system")
314 installer->setProxy(QUrl(getenv("http_proxy")));
315 #endif
317 installer->setLogSection("Fonts");
318 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
319 installer->install(logger);
321 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
325 void RbUtilQt::installVoice()
327 if(QMessageBox::question(this, tr("Confirm Installation"),
328 tr("Do you really want to install the voice file?"),
329 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
330 // create logger
331 logger = new ProgressLoggerGui(this);
332 logger->show();
334 // create zip installer
335 installer = new ZipInstaller(this);
336 installer->setUnzip(false);
337 buildInfo.open();
338 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
339 buildInfo.close();
340 QString datestring = info.value("dailies/date").toString();
342 QString voiceurl = devices->value("voice_url").toString() + "/" +
343 userSettings->value("defaults/platform").toString() + "-" +
344 datestring + "-english.voice";
345 qDebug() << voiceurl;
346 if(userSettings->value("defaults/proxytype") == "manual")
347 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
348 #ifdef __linux
349 else if(userSettings->value("defaults/proxytype") == "system")
350 installer->setProxy(QUrl(getenv("http_proxy")));
351 #endif
353 installer->setUrl(voiceurl);
354 installer->setLogSection("Voice");
355 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
356 installer->setTarget("/.rockbox/langs/english.voice");
357 installer->install(logger);
359 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
363 void RbUtilQt::installDoom()
365 if(QMessageBox::question(this, tr("Confirm Installation"),
366 tr("Do you really want to install the game addon files?"),
367 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
368 // create logger
369 logger = new ProgressLoggerGui(this);
370 logger->show();
372 // create zip installer
373 installer = new ZipInstaller(this);
375 installer->setUrl(devices->value("doom_url").toString());
376 if(userSettings->value("defaults/proxytype") == "manual")
377 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
378 #ifdef __linux
379 else if(userSettings->value("defaults/proxytype") == "system")
380 installer->setProxy(QUrl(getenv("http_proxy")));
381 #endif
383 installer->setLogSection("Game Addons");
384 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
385 installer->install(logger);
387 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
392 void RbUtilQt::createTalkFiles(void)
394 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
395 installWindow->setUserSettings(userSettings);
396 installWindow->setDeviceSettings(devices);
397 installWindow->show();