small simplification.
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob35b227f6e108332ed488a21872fc79de9fe6536e
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 "installbootloaderwindow.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 absolutePath = qApp->applicationDirPath();
40 // use built-in rbutil.ini if no external file in binary folder
41 QString iniFile = absolutePath + "/rbutil.ini";
42 if(QFileInfo(iniFile).isFile()) {
43 qDebug() << "using external rbutil.ini";
44 devices = new QSettings(iniFile, QSettings::IniFormat, 0);
46 else {
47 qDebug() << "using built-in rbutil.ini";
48 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
51 ui.setupUi(this);
53 // portable installation:
54 // check for a configuration file in the program folder.
55 QFileInfo config;
56 config.setFile(absolutePath + "/RockboxUtility.ini");
57 if(config.isFile()) {
58 userSettings = new QSettings(absolutePath + "/RockboxUtility.ini",
59 QSettings::IniFormat, 0);
60 qDebug() << "config: portable";
62 else {
63 userSettings = new QSettings(QSettings::IniFormat,
64 QSettings::UserScope, "rockbox.org", "RockboxUtility");
65 qDebug() << "config: system";
68 // manual tab
69 ui.buttonDownloadManual->setEnabled(false);
70 updateManual();
71 updateDevice();
73 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
74 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
75 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
76 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
77 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(install()));
78 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBl()));
79 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFonts()));
80 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom()));
81 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
82 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
85 // disable unimplemented stuff
86 ui.buttonThemes->setEnabled(false);
87 ui.buttonSmall->setEnabled(false);
88 ui.buttonRemoveRockbox->setEnabled(false);
89 ui.buttonRemoveBootloader->setEnabled(false);
90 ui.buttonComplete->setEnabled(false);
92 initIpodpatcher();
93 initSansapatcher();
94 downloadInfo();
99 void RbUtilQt::downloadInfo()
101 // try to get the current build information
102 daily = new HttpGet(this);
103 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
104 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
105 if(userSettings->value("defaults/proxytype") == "manual")
106 daily->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
107 #ifdef __linux
108 else if(userSettings->value("defaults/proxytype") == "system")
109 daily->setProxy(QUrl(getenv("http_proxy")));
110 #endif
112 qDebug() << "downloading build info";
113 daily->setFile(&buildInfo);
114 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
118 void RbUtilQt::downloadDone(bool error)
120 if(error) qDebug() << "network error:" << daily->error();
121 qDebug() << "network status:" << daily->error();
126 void RbUtilQt::downloadDone(int id, bool error)
128 QString errorString;
129 errorString = tr("Network error: %1. Please check your network and proxy settings.")
130 .arg(daily->errorString());
131 if(error) QMessageBox::about(this, "Network Error", errorString);
132 qDebug() << "downloadDone:" << id << error;
136 void RbUtilQt::about()
138 QDialog *window = new QDialog(this);
139 Ui::aboutBox about;
140 about.setupUi(window);
141 window->setModal(true);
143 QFile licence(":/docs/gpl-2.0.html");
144 licence.open(QIODevice::ReadOnly);
145 QTextStream c(&licence);
146 QString cline = c.readAll();
147 about.browserLicense->insertHtml(cline);
148 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
149 QFile credits(":/docs/CREDITS");
150 credits.open(QIODevice::ReadOnly);
151 QTextStream r(&credits);
152 QString rline = r.readAll();
153 about.browserCredits->insertPlainText(rline);
154 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
155 QString title = QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION);
156 about.labelTitle->setText(title);
157 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
159 window->show();
164 void RbUtilQt::configDialog()
166 Config *cw = new Config(this);
167 cw->setUserSettings(userSettings);
168 cw->setDevices(devices);
169 cw->show();
170 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
171 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
175 void RbUtilQt::updateSettings()
177 qDebug() << "updateSettings()";
178 updateDevice();
179 updateManual();
183 void RbUtilQt::updateDevice()
185 platform = userSettings->value("defaults/platform").toString();
186 // buttons
187 devices->beginGroup(platform);
188 if(devices->value("needsbootloader", "") == "no") {
189 ui.buttonBootloader->setEnabled(false);
190 ui.buttonRemoveBootloader->setEnabled(false);
191 ui.labelBootloader->setEnabled(false);
192 ui.labelRemoveBootloader->setEnabled(false);
194 else {
195 ui.buttonBootloader->setEnabled(true);
196 ui.labelBootloader->setEnabled(true);
197 if(devices->value("bootloadermethod") == "fwpatcher") {
198 ui.labelRemoveBootloader->setEnabled(false);
199 ui.buttonRemoveBootloader->setEnabled(false);
201 else {
202 ui.labelRemoveBootloader->setEnabled(true);
203 ui.buttonRemoveBootloader->setEnabled(true);
206 devices->endGroup();
207 // displayed device info
208 platform = userSettings->value("defaults/platform").toString();
209 QString mountpoint = userSettings->value("defaults/mountpoint").toString();
210 devices->beginGroup(platform);
211 QString brand = devices->value("brand").toString();
212 QString name = devices->value("name").toString();
213 devices->endGroup();
214 if(name.isEmpty()) name = "&lt;none&gt;";
215 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
216 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
217 .arg(brand, name, mountpoint));
221 void RbUtilQt::updateManual()
223 if(userSettings->value("defaults/platform").toString() != "")
225 devices->beginGroup(userSettings->value("defaults/platform").toString());
226 QString manual;
227 manual = devices->value("manualname", "").toString();
229 if(manual == "")
230 manual = "rockbox-" + devices->value("platform").toString();
231 devices->endGroup();
232 QString pdfmanual;
233 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
234 QString htmlmanual;
235 htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
236 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
237 .arg(pdfmanual));
238 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
239 .arg(htmlmanual));
241 else {
242 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
243 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
244 .arg("http://www.rockbox.org/manual.shtml"));
250 void RbUtilQt::install()
252 Install *installWindow = new Install(this);
253 installWindow->setUserSettings(userSettings);
254 installWindow->setDeviceSettings(devices);
255 if(userSettings->value("defaults/proxytype") == "manual")
256 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
257 #ifdef __linux
258 else if(userSettings->value("defaults/proxytype") == "system")
259 installWindow->setProxy(QUrl(getenv("http_proxy")));
260 #endif
262 buildInfo.open();
263 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
264 buildInfo.close();
265 installWindow->setArchivedString(info.value("dailies/date").toString());
267 devices->beginGroup(platform);
268 QString released = devices->value("released").toString();
269 devices->endGroup();
270 if(released == "yes")
271 installWindow->setReleased(devices->value("last_release", "").toString());
272 else
273 installWindow->setReleased(0);
275 installWindow->show();
279 void RbUtilQt::installBl()
281 InstallBootloaderWindow *installWindow = new InstallBootloaderWindow(this);
282 installWindow->setUserSettings(userSettings);
283 installWindow->setDeviceSettings(devices);
284 if(userSettings->value("defaults/proxytype") == "manual")
285 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
286 #ifdef __linux
287 else if(userSettings->value("defaults/proxytype") == "system")
288 installWindow->setProxy(QUrl(getenv("http_proxy")));
289 #endif
290 installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
292 installWindow->show();
296 void RbUtilQt::installFonts()
298 if(QMessageBox::question(this, tr("Confirm Installation"),
299 tr("Do you really want to install the fonts package?"),
300 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
301 // create logger
302 logger = new ProgressLoggerGui(this);
303 logger->show();
305 // create zip installer
306 installer = new ZipInstaller(this);
308 installer->setUrl(devices->value("font_url").toString());
309 if(userSettings->value("defaults/proxytype") == "manual")
310 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
311 #ifdef __linux
312 else if(userSettings->value("defaults/proxytype") == "system")
313 installer->setProxy(QUrl(getenv("http_proxy")));
314 #endif
316 installer->setLogSection("Fonts");
317 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
318 installer->install(logger);
320 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
324 void RbUtilQt::installVoice()
326 if(QMessageBox::question(this, tr("Confirm Installation"),
327 tr("Do you really want to install the voice file?"),
328 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
329 // create logger
330 logger = new ProgressLoggerGui(this);
331 logger->show();
333 // create zip installer
334 installer = new ZipInstaller(this);
335 installer->setUnzip(false);
336 buildInfo.open();
337 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
338 buildInfo.close();
339 QString datestring = info.value("dailies/date").toString();
341 QString voiceurl = devices->value("voice_url").toString() + "/" +
342 userSettings->value("defaults/platform").toString() + "-" +
343 datestring + "-english.voice";
344 qDebug() << voiceurl;
345 if(userSettings->value("defaults/proxytype") == "manual")
346 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
347 #ifdef __linux
348 else if(userSettings->value("defaults/proxytype") == "system")
349 installer->setProxy(QUrl(getenv("http_proxy")));
350 #endif
352 installer->setUrl(voiceurl);
353 installer->setLogSection("Voice");
354 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
355 installer->setTarget("/.rockbox/langs/english.voice");
356 installer->install(logger);
358 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
362 void RbUtilQt::installDoom()
364 if(QMessageBox::question(this, tr("Confirm Installation"),
365 tr("Do you really want to install the game addon files?"),
366 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
367 // create logger
368 logger = new ProgressLoggerGui(this);
369 logger->show();
371 // create zip installer
372 installer = new ZipInstaller(this);
374 installer->setUrl(devices->value("doom_url").toString());
375 if(userSettings->value("defaults/proxytype") == "manual")
376 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
377 #ifdef __linux
378 else if(userSettings->value("defaults/proxytype") == "system")
379 installer->setProxy(QUrl(getenv("http_proxy")));
380 #endif
382 installer->setLogSection("Game Addons");
383 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
384 installer->install(logger);
386 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
391 void RbUtilQt::createTalkFiles(void)
393 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
394 installWindow->setUserSettings(userSettings);
395 installWindow->setDeviceSettings(devices);
396 installWindow->show();