add portable installation if built as static binary.
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob3b84c83c39bac0a0498aaa501b6edf5b66dd4618
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 "installtalkwindow.h"
29 #include "httpget.h"
30 #include "installbootloader.h"
31 #include "installthemes.h"
32 #include "uninstallwindow.h"
33 #include "browseof.h"
35 #ifdef __linux
36 #include <stdio.h>
37 #endif
39 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
41 absolutePath = qApp->applicationDirPath();
42 // use built-in rbutil.ini if no external file in binary folder
43 QString iniFile = absolutePath + "/rbutil.ini";
44 if(QFileInfo(iniFile).isFile()) {
45 qDebug() << "using external rbutil.ini";
46 devices = new QSettings(iniFile, QSettings::IniFormat, 0);
48 else {
49 qDebug() << "using built-in rbutil.ini";
50 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
53 ui.setupUi(this);
55 // portable installation:
56 // check for a configuration file in the program folder.
57 QFileInfo config;
58 config.setFile(absolutePath + "/RockboxUtility.ini");
59 if(config.isFile()) {
60 userSettings = new QSettings(absolutePath + "/RockboxUtility.ini",
61 QSettings::IniFormat, 0);
62 qDebug() << "config: portable";
64 else {
65 userSettings = new QSettings(QSettings::IniFormat,
66 QSettings::UserScope, "rockbox.org", "RockboxUtility");
67 qDebug() << "config: system";
70 // manual tab
71 updateManual();
72 updateDevice();
73 ui.radioPdf->setChecked(true);
75 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
76 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
77 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
78 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
79 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(install()));
80 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBl()));
81 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFonts()));
82 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom()));
83 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
84 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
85 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
86 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
87 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
88 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
89 // disable unimplemented stuff
90 ui.buttonSmall->setEnabled(false);
91 ui.buttonComplete->setEnabled(false);
92 #if !defined(STATIC)
93 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
94 #else
95 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
96 #endif
98 initIpodpatcher();
99 initSansapatcher();
100 downloadInfo();
107 void RbUtilQt::downloadInfo()
109 // try to get the current build information
110 daily = new HttpGet(this);
111 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
112 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
113 if(userSettings->value("defaults/proxytype") == "manual")
114 daily->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
115 #ifdef __linux
116 else if(userSettings->value("defaults/proxytype") == "system")
117 daily->setProxy(QUrl(getenv("http_proxy")));
118 #endif
120 qDebug() << "downloading build info";
121 daily->setFile(&buildInfo);
122 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
126 void RbUtilQt::downloadDone(bool error)
128 if(error) qDebug() << "network error:" << daily->error();
129 qDebug() << "network status:" << daily->error();
134 void RbUtilQt::downloadDone(int id, bool error)
136 QString errorString;
137 errorString = tr("Network error: %1. Please check your network and proxy settings.")
138 .arg(daily->errorString());
139 if(error) QMessageBox::about(this, "Network Error", errorString);
140 qDebug() << "downloadDone:" << id << error;
144 void RbUtilQt::about()
146 QDialog *window = new QDialog(this);
147 Ui::aboutBox about;
148 about.setupUi(window);
149 window->setModal(true);
151 QFile licence(":/docs/gpl-2.0.html");
152 licence.open(QIODevice::ReadOnly);
153 QTextStream c(&licence);
154 QString cline = c.readAll();
155 about.browserLicense->insertHtml(cline);
156 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
157 QFile credits(":/docs/CREDITS");
158 credits.open(QIODevice::ReadOnly);
159 QTextStream r(&credits);
160 QString rline = r.readAll();
161 about.browserCredits->insertPlainText(rline);
162 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
163 QString title = QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION);
164 about.labelTitle->setText(title);
165 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
167 window->show();
172 void RbUtilQt::configDialog()
174 Config *cw = new Config(this);
175 cw->setUserSettings(userSettings);
176 cw->setDevices(devices);
177 cw->show();
178 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
179 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
183 void RbUtilQt::updateSettings()
185 qDebug() << "updateSettings()";
186 updateDevice();
187 updateManual();
191 void RbUtilQt::updateDevice()
193 platform = userSettings->value("defaults/platform").toString();
194 // buttons
195 devices->beginGroup(platform);
196 if(devices->value("needsbootloader", "") == "no") {
197 ui.buttonBootloader->setEnabled(false);
198 ui.buttonRemoveBootloader->setEnabled(false);
199 ui.labelBootloader->setEnabled(false);
200 ui.labelRemoveBootloader->setEnabled(false);
202 else {
203 ui.buttonBootloader->setEnabled(true);
204 ui.labelBootloader->setEnabled(true);
205 if(devices->value("bootloadermethod") == "fwpatcher") {
206 ui.labelRemoveBootloader->setEnabled(false);
207 ui.buttonRemoveBootloader->setEnabled(false);
209 else {
210 ui.labelRemoveBootloader->setEnabled(true);
211 ui.buttonRemoveBootloader->setEnabled(true);
214 devices->endGroup();
215 // displayed device info
216 platform = userSettings->value("defaults/platform").toString();
217 QString mountpoint = userSettings->value("defaults/mountpoint").toString();
218 devices->beginGroup(platform);
219 QString brand = devices->value("brand").toString();
220 QString name = devices->value("name").toString();
221 devices->endGroup();
222 if(name.isEmpty()) name = "&lt;none&gt;";
223 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
224 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
225 .arg(brand, name, mountpoint));
229 void RbUtilQt::updateManual()
231 if(userSettings->value("defaults/platform").toString() != "")
233 devices->beginGroup(userSettings->value("defaults/platform").toString());
234 QString manual;
235 manual = devices->value("manualname", "").toString();
237 if(manual == "")
238 manual = "rockbox-" + devices->value("platform").toString();
239 devices->endGroup();
240 QString pdfmanual;
241 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
242 QString htmlmanual;
243 htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
244 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
245 .arg(pdfmanual));
246 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
247 .arg(htmlmanual));
249 else {
250 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
251 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
252 .arg("http://www.rockbox.org/manual.shtml"));
258 void RbUtilQt::install()
260 Install *installWindow = new Install(this);
261 installWindow->setUserSettings(userSettings);
262 installWindow->setDeviceSettings(devices);
263 if(userSettings->value("defaults/proxytype") == "manual")
264 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
265 #ifdef __linux
266 else if(userSettings->value("defaults/proxytype") == "system")
267 installWindow->setProxy(QUrl(getenv("http_proxy")));
268 #endif
270 buildInfo.open();
271 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
272 buildInfo.close();
273 installWindow->setArchivedString(info.value("dailies/date").toString());
275 devices->beginGroup(platform);
276 QString released = devices->value("released").toString();
277 devices->endGroup();
278 if(released == "yes")
279 installWindow->setReleased(devices->value("last_release", "").toString());
280 else
281 installWindow->setReleased(0);
283 installWindow->show();
287 void RbUtilQt::installBl()
289 if(QMessageBox::question(this, tr("Confirm Installation"),
290 tr("Do you really want to install the Bootloader?"),
291 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
293 // create logger
294 logger = new ProgressLoggerGui(this);
295 logger->show();
297 QString platform = userSettings->value("defaults/platform").toString();
299 // if fwpatcher , ask for extra file
300 QString offirmware;
301 if(devices->value(platform + "/bootloadermethod").toString() == "fwpatcher")
303 BrowseOF ofbrowser(this);
304 ofbrowser.setFile(userSettings->value("defaults/ofpath").toString());
305 if(ofbrowser.exec() == QDialog::Accepted)
307 offirmware = ofbrowser.getFile();
308 qDebug() << offirmware;
309 if(!QFileInfo(offirmware).exists())
311 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
312 logger->abort();
313 return;
315 else
317 userSettings->setValue("defaults/ofpath",offirmware);
318 userSettings->sync();
321 else
323 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
324 logger->abort();
325 return;
329 // create installer
330 blinstaller = new BootloaderInstaller(this);
332 blinstaller->setMountPoint(userSettings->value("defaults/mountpoint").toString());
334 if(userSettings->value("defaults/proxytype") == "manual")
335 blinstaller->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
336 #ifdef __linux
337 else if(userSettings->value("defaults/proxytype") == "system")
338 blinstaller->setProxy(QUrl(getenv("http_proxy")));
339 #endif
341 blinstaller->setDevice(platform);
342 blinstaller->setBootloaderMethod(devices->value(platform + "/bootloadermethod").toString());
343 blinstaller->setBootloaderName(devices->value(platform + "/bootloadername").toString());
344 blinstaller->setBootloaderBaseUrl(devices->value("bootloader_url").toString());
345 blinstaller->setOrigFirmwarePath(offirmware);
347 blinstaller->install(logger);
349 // connect(blinstaller, SIGNAL(done(bool)), this, SLOT(done(bool)));
353 void RbUtilQt::installFonts()
355 if(QMessageBox::question(this, tr("Confirm Installation"),
356 tr("Do you really want to install the fonts package?"),
357 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
358 // create logger
359 logger = new ProgressLoggerGui(this);
360 logger->show();
362 // create zip installer
363 installer = new ZipInstaller(this);
365 installer->setUrl(devices->value("font_url").toString());
366 if(userSettings->value("defaults/proxytype") == "manual")
367 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
368 #ifdef __linux
369 else if(userSettings->value("defaults/proxytype") == "system")
370 installer->setProxy(QUrl(getenv("http_proxy")));
371 #endif
373 installer->setLogSection("Fonts");
374 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
375 installer->install(logger);
377 // connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
381 void RbUtilQt::installVoice()
383 if(QMessageBox::question(this, tr("Confirm Installation"),
384 tr("Do you really want to install the voice file?"),
385 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
386 // create logger
387 logger = new ProgressLoggerGui(this);
388 logger->show();
390 // create zip installer
391 installer = new ZipInstaller(this);
392 installer->setUnzip(false);
393 buildInfo.open();
394 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
395 buildInfo.close();
396 QString datestring = info.value("dailies/date").toString();
398 QString voiceurl = devices->value("voice_url").toString() + "/" +
399 userSettings->value("defaults/platform").toString() + "-" +
400 datestring + "-english.voice";
401 qDebug() << voiceurl;
402 if(userSettings->value("defaults/proxytype") == "manual")
403 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
404 #ifdef __linux
405 else if(userSettings->value("defaults/proxytype") == "system")
406 installer->setProxy(QUrl(getenv("http_proxy")));
407 #endif
409 installer->setUrl(voiceurl);
410 installer->setLogSection("Voice");
411 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
412 installer->setTarget("/.rockbox/langs/english.voice");
413 installer->install(logger);
415 //connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
419 void RbUtilQt::installDoom()
421 if(QMessageBox::question(this, tr("Confirm Installation"),
422 tr("Do you really want to install the game addon files?"),
423 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
424 // create logger
425 logger = new ProgressLoggerGui(this);
426 logger->show();
428 // create zip installer
429 installer = new ZipInstaller(this);
431 installer->setUrl(devices->value("doom_url").toString());
432 if(userSettings->value("defaults/proxytype") == "manual")
433 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
434 #ifdef __linux
435 else if(userSettings->value("defaults/proxytype") == "system")
436 installer->setProxy(QUrl(getenv("http_proxy")));
437 #endif
439 installer->setLogSection("GameAddons");
440 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
441 installer->install(logger);
443 // connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
448 void RbUtilQt::installThemes()
450 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
451 tw->setDeviceSettings(devices);
452 tw->setUserSettings(userSettings);
453 if(userSettings->value("defaults/proxytype") == "manual")
454 tw->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
455 #ifdef __linux
456 else if(userSettings->value("defaults/proxytype") == "system")
457 tw->setProxy(QUrl(getenv("http_proxy")));
458 #endif
459 tw->setModal(true);
460 tw->show();
464 void RbUtilQt::createTalkFiles(void)
466 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
467 installWindow->setUserSettings(userSettings);
468 installWindow->setDeviceSettings(devices);
469 installWindow->show();
473 void RbUtilQt::uninstall(void)
475 UninstallWindow *uninstallWindow = new UninstallWindow(this);
476 uninstallWindow->setUserSettings(userSettings);
477 uninstallWindow->setDeviceSettings(devices);
478 uninstallWindow->show();
481 void RbUtilQt::uninstallBootloader(void)
483 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
484 tr("Do you really want to uninstall the Bootloader?"),
485 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
486 // create logger
487 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
488 logger->show();
490 QString plattform = userSettings->value("defaults/platform").toString();
491 BootloaderInstaller blinstaller(this);
492 blinstaller.setMountPoint(userSettings->value("defaults/mountpoint").toString());
493 blinstaller.setDevice(userSettings->value("defaults/platform").toString());
494 blinstaller.setBootloaderMethod(devices->value(plattform + "/bootloadermethod").toString());
495 blinstaller.setBootloaderName(devices->value(plattform + "/bootloadername").toString());
496 blinstaller.setBootloaderBaseUrl(devices->value("bootloader_url").toString());
497 blinstaller.uninstall(logger);
502 void RbUtilQt::downloadManual(void)
504 if(QMessageBox::question(this, tr("Confirm download"),
505 tr("Do you really want to download the manual? The manual will be saved "
506 "to the root folder of your player."),
507 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
508 return;
510 buildInfo.open();
511 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
512 buildInfo.close();
514 devices->beginGroup(userSettings->value("defaults/platform").toString());
515 QString manual;
516 manual = devices->value("manualname", "rockbox-" + devices->value("platform").toString()).toString();
517 devices->endGroup();
519 QString date = (info.value("dailies/date").toString());
521 QString manualurl;
522 QString target;
523 QString section;
524 if(ui.radioPdf->isChecked()) {
525 target = "/" + manual + ".pdf";
526 section = "Manual (PDF)";
528 else {
529 target = "/" + manual + "-" + date + "-html.zip";
530 section = "Manual (HTML)";
532 manualurl = devices->value("manual_url").toString() + "/" + target;
533 qDebug() << "manualurl =" << manualurl;
535 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
536 logger->show();
537 installer = new ZipInstaller(this);
538 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
539 if(userSettings->value("defaults/proxytype") == "manual")
540 installer->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
541 #ifdef __linux
542 else if(userSettings->value("defaults/proxytype") == "system")
543 installer->setProxy(QUrl(getenv("http_proxy")));
544 #endif
545 installer->setLogSection(section);
546 installer->setUrl(manualurl);
547 installer->setUnzip(false);
548 installer->setTarget(target);
549 installer->install(logger);
553 void RbUtilQt::installPortable(void)
555 if(QMessageBox::question(this, tr("Confirm installation"),
556 tr("Do you really want to install Rockbox Utility to your player? "
557 "After installation you can run it from the players hard drive."),
558 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
559 return;
561 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
562 logger->show();
563 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
565 // check mountpoint
566 if(!QFileInfo(userSettings->value("defaults/mountpoint").toString()).isDir()) {
567 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
568 logger->abort();
569 return;
572 // remove old files first.
573 QFile::remove(userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.exe");
574 QFile::remove(userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.ini");
575 // copy currently running binary and currently used settings file
576 if(!QFile::copy(qApp->applicationFilePath(), userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.exe")) {
577 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
578 logger->abort();
579 return;
581 logger->addItem(tr("Installing user configuration"), LOGINFO);
582 if(!QFile::copy(userSettings->fileName(), userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.ini")) {
583 logger->addItem(tr("Error installing user configuration"), LOGERROR);
584 logger->abort();
585 return;
587 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
588 logger->abort();