When portable installation is finished set progress value to 100%.
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blobe768439a0d7778e80dcc38adab7a28b2cdac575d
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 #if defined(Q_OS_LINUX)
36 #include <stdio.h>
37 #endif
38 #if defined(Q_OS_WIN32)
39 #if defined(UNICODE)
40 #define _UNICODE
41 #endif
42 #include <stdio.h>
43 #include <tchar.h>
44 #include <windows.h>
45 #endif
47 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
49 absolutePath = qApp->applicationDirPath();
50 // use built-in rbutil.ini if no external file in binary folder
51 QString iniFile = absolutePath + "/rbutil.ini";
52 if(QFileInfo(iniFile).isFile()) {
53 qDebug() << "using external rbutil.ini";
54 devices = new QSettings(iniFile, QSettings::IniFormat, 0);
56 else {
57 qDebug() << "using built-in rbutil.ini";
58 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
61 ui.setupUi(this);
63 // portable installation:
64 // check for a configuration file in the program folder.
65 QFileInfo config;
66 config.setFile(absolutePath + "/RockboxUtility.ini");
67 if(config.isFile()) {
68 userSettings = new QSettings(absolutePath + "/RockboxUtility.ini",
69 QSettings::IniFormat, 0);
70 qDebug() << "config: portable";
72 else {
73 userSettings = new QSettings(QSettings::IniFormat,
74 QSettings::UserScope, "rockbox.org", "RockboxUtility");
75 qDebug() << "config: system";
78 // manual tab
79 updateManual();
80 updateDevice();
81 ui.radioPdf->setChecked(true);
83 // info tab
84 ui.treeInfo->setAlternatingRowColors(true);
85 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
86 ui.treeInfo->expandAll();
87 ui.treeInfo->setColumnCount(2);
89 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
90 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
91 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
92 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
93 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
94 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
95 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
96 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
97 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
98 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
99 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
100 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
101 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
102 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
103 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
104 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
105 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
106 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
108 // actions accessible from the menu
109 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
110 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
111 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
112 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
113 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
114 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
115 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
116 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
117 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
118 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
119 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
121 #if !defined(STATIC)
122 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
123 #else
124 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
125 #endif
127 initIpodpatcher();
128 initSansapatcher();
129 downloadInfo();
134 void RbUtilQt::updateTabs(int count)
136 switch(count) {
137 case 6:
138 updateInfo();
139 break;
140 default:
141 break;
146 void RbUtilQt::downloadInfo()
148 // try to get the current build information
149 daily = new HttpGet(this);
150 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
151 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
152 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
153 daily->setProxy(proxy());
154 if(userSettings->value("offline").toBool())
155 daily->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
156 qDebug() << "downloading build info";
157 daily->setFile(&buildInfo);
158 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
162 void RbUtilQt::downloadDone(bool error)
164 if(error) {
165 qDebug() << "network error:" << daily->error();
166 return;
168 qDebug() << "network status:" << daily->error();
170 buildInfo.open();
171 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
172 buildInfo.close();
173 versmap.insert("arch_rev", info.value("dailies/rev").toString());
174 versmap.insert("arch_date", info.value("dailies/date").toString());
176 bleeding = new HttpGet(this);
177 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
178 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
179 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
180 bleeding->setProxy(proxy());
181 if(userSettings->value("offline").toBool())
182 bleeding->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
183 bleeding->setFile(&bleedingInfo);
184 bleeding->getFile(QUrl(devices->value("bleeding_info").toString()));
186 if(chkConfig(false)) {
187 QApplication::processEvents();
188 QMessageBox::critical(this, tr("Configuration error"),
189 tr("Your configuration is invalid. This is most likely due "
190 "to a new installation of Rockbox Utility or a changed device "
191 "path. The configuation dialog will now open to allow you "
192 "correcting the problem."));
193 configDialog();
198 void RbUtilQt::downloadBleedingDone(bool error)
200 if(error) qDebug() << "network error:" << bleeding->error();
202 bleedingInfo.open();
203 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
204 bleedingInfo.close();
205 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
206 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
207 qDebug() << "versmap =" << versmap;
211 void RbUtilQt::downloadDone(int id, bool error)
213 QString errorString;
214 errorString = tr("Network error: %1. Please check your network and proxy settings.")
215 .arg(daily->errorString());
216 if(error) {
217 QMessageBox::about(this, "Network Error", errorString);
219 qDebug() << "downloadDone:" << id << error;
223 void RbUtilQt::about()
225 QDialog *window = new QDialog(this);
226 Ui::aboutBox about;
227 about.setupUi(window);
228 window->setModal(true);
230 QFile licence(":/docs/gpl-2.0.html");
231 licence.open(QIODevice::ReadOnly);
232 QTextStream c(&licence);
233 QString cline = c.readAll();
234 about.browserLicense->insertHtml(cline);
235 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
236 QFile credits(":/docs/CREDITS");
237 credits.open(QIODevice::ReadOnly);
238 QTextStream r(&credits);
239 QString rline = r.readAll();
240 about.browserCredits->insertPlainText(rline);
241 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
242 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
243 about.labelTitle->setText(title);
244 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
246 window->show();
251 void RbUtilQt::help()
253 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtilityQt");
254 QDesktopServices::openUrl(helpurl);
258 void RbUtilQt::configDialog()
260 Config *cw = new Config(this);
261 cw->setUserSettings(userSettings);
262 cw->setDevices(devices);
263 cw->show();
264 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
265 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
269 void RbUtilQt::updateSettings()
271 qDebug() << "updateSettings()";
272 updateDevice();
273 updateManual();
277 void RbUtilQt::updateDevice()
279 platform = userSettings->value("platform").toString();
280 // buttons
281 devices->beginGroup(platform);
282 if(devices->value("needsbootloader", "") == "no") {
283 ui.buttonBootloader->setEnabled(false);
284 ui.buttonRemoveBootloader->setEnabled(false);
285 ui.labelBootloader->setEnabled(false);
286 ui.labelRemoveBootloader->setEnabled(false);
288 else {
289 ui.buttonBootloader->setEnabled(true);
290 ui.labelBootloader->setEnabled(true);
291 if(devices->value("bootloadermethod") == "fwpatcher") {
292 ui.labelRemoveBootloader->setEnabled(false);
293 ui.buttonRemoveBootloader->setEnabled(false);
295 else {
296 ui.labelRemoveBootloader->setEnabled(true);
297 ui.buttonRemoveBootloader->setEnabled(true);
300 devices->endGroup();
301 // displayed device info
302 platform = userSettings->value("platform").toString();
303 QString mountpoint = userSettings->value("mountpoint").toString();
304 devices->beginGroup(platform);
305 QString brand = devices->value("brand").toString();
306 QString name = devices->value("name").toString();
307 devices->endGroup();
308 if(name.isEmpty()) name = "&lt;none&gt;";
309 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
310 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
311 .arg(brand, name, mountpoint));
315 void RbUtilQt::updateManual()
317 if(userSettings->value("platform").toString() != "")
319 devices->beginGroup(userSettings->value("platform").toString());
320 QString manual;
321 manual = devices->value("manualname", "").toString();
323 if(manual == "")
324 manual = "rockbox-" + devices->value("platform").toString();
325 devices->endGroup();
326 QString pdfmanual;
327 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
328 QString htmlmanual;
329 htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
330 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
331 .arg(pdfmanual));
332 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
333 .arg(htmlmanual));
335 else {
336 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
337 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
338 .arg("http://www.rockbox.org/manual.shtml"));
343 void RbUtilQt::completeInstall()
345 if(chkConfig(true)) return;
346 if(QMessageBox::question(this, tr("Confirm Installation"),
347 tr("Do you really want to make a complete Installation?"),
348 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
350 // create logger
351 logger = new ProgressLoggerGui(this);
352 logger->show();
354 if(smallInstallInner())
355 return;
357 // Fonts
358 m_error = false;
359 m_installed = false;
360 if(!installFontsAuto())
361 return;
362 else
364 // wait for installation finished
365 while(!m_installed)
366 QApplication::processEvents();
368 if(m_error) return;
369 logger->undoAbort();
371 // Doom
372 if(hasDoom())
374 m_error = false;
375 m_installed = false;
376 if(!installDoomAuto())
377 return;
378 else
380 // wait for installation finished
381 while(!m_installed)
382 QApplication::processEvents();
384 if(m_error) return;
387 // theme
388 // this is a window
389 // it has its own logger window,so close our.
390 logger->close();
391 installThemes();
395 void RbUtilQt::smallInstall()
397 if(chkConfig(true)) return;
398 if(QMessageBox::question(this, tr("Confirm Installation"),
399 tr("Do you really want to make a small Installation?"),
400 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
402 // create logger
403 logger = new ProgressLoggerGui(this);
404 logger->show();
406 smallInstallInner();
409 bool RbUtilQt::smallInstallInner()
411 QString mountpoint = userSettings->value("mountpoint").toString();
412 // show dialog with error if mount point is wrong
413 if(!QFileInfo(mountpoint).isDir()) {
414 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
415 logger->abort();
416 return true;
418 // Bootloader
419 devices->beginGroup(userSettings->value("platform").toString());
420 if(devices->value("needsbootloader", "") == "yes") {
421 m_error = false;
422 m_installed = false;
423 if(!installBootloaderAuto())
424 return true;
425 else
427 // wait for boot loader installation finished
428 while(!m_installed)
429 QApplication::processEvents();
431 if(m_error) return true;
432 logger->undoAbort();
434 devices->endGroup();
436 // Rockbox
437 m_error = false;
438 m_installed = false;
439 if(!installAuto())
440 return true;
441 else
443 // wait for installation finished
444 while(!m_installed)
445 QApplication::processEvents();
448 return false;
451 void RbUtilQt::installdone(bool error)
453 qDebug() << "install done";
454 m_installed = true;
455 m_error = error;
458 void RbUtilQt::installBtn()
460 if(chkConfig(true)) return;
461 install();
464 bool RbUtilQt::installAuto()
466 QString file = QString("%1%2/rockbox.zip")
467 .arg(devices->value("bleeding_url").toString(),
468 userSettings->value("platform").toString());
470 buildInfo.open();
471 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
472 buildInfo.close();
474 devices->beginGroup(platform);
475 QString released = devices->value("released").toString();
476 devices->endGroup();
477 if(released == "yes") {
478 // only set the keys if needed -- querying will yield an empty string
479 // if not set.
480 versmap.insert("rel_rev", devices->value("last_release").toString());
481 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
484 QString myversion = "r" + versmap.value("bleed_rev");
486 ZipInstaller* installer = new ZipInstaller(this);
487 installer->setUrl(file);
488 installer->setProxy(proxy());
489 installer->setLogSection("Rockbox (Base)");
490 installer->setLogVersion(myversion);
491 if(!userSettings->value("cachedisable").toBool())
492 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
493 installer->setMountPoint(userSettings->value("mountpoint").toString());
494 installer->install(logger);
496 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
498 return true;
501 void RbUtilQt::install()
503 Install *installWindow = new Install(this);
504 installWindow->setUserSettings(userSettings);
505 installWindow->setDeviceSettings(devices);
506 installWindow->setProxy(proxy());
508 buildInfo.open();
509 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
510 buildInfo.close();
512 devices->beginGroup(platform);
513 QString released = devices->value("released").toString();
514 devices->endGroup();
515 if(released == "yes") {
516 // only set the keys if needed -- querying will yield an empty string
517 // if not set.
518 versmap.insert("rel_rev", devices->value("last_release").toString());
519 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
521 installWindow->setVersionStrings(versmap);
523 installWindow->show();
526 bool RbUtilQt::installBootloaderAuto()
528 installBootloader();
529 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
530 return !m_error;
533 void RbUtilQt::installBootloaderBtn()
535 if(chkConfig(true)) return;
536 if(QMessageBox::question(this, tr("Confirm Installation"),
537 tr("Do you really want to install the Bootloader?"),
538 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
540 // create logger
541 logger = new ProgressLoggerGui(this);
542 logger->show();
544 installBootloader();
547 void RbUtilQt::installBootloader()
549 QString platform = userSettings->value("platform").toString();
551 // create installer
552 blinstaller = new BootloaderInstaller(this);
554 blinstaller->setMountPoint(userSettings->value("mountpoint").toString());
556 blinstaller->setProxy(proxy());
557 blinstaller->setDevice(platform);
558 blinstaller->setBootloaderMethod(devices->value(platform + "/bootloadermethod").toString());
559 blinstaller->setBootloaderName(devices->value(platform + "/bootloadername").toString());
560 blinstaller->setBootloaderBaseUrl(devices->value("bootloader_url").toString());
561 blinstaller->setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
562 if(!blinstaller->downloadInfo())
564 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
565 logger->abort();
566 m_error = true;
567 return;
570 if(blinstaller->uptodate())
572 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
573 tr("It seem your Bootloader is already up to date.\n"
574 "Do really want to install it?"),
575 QMessageBox::Ok | QMessageBox::Ignore |QMessageBox::Cancel,
576 QMessageBox::Cancel);
577 if(ret == QMessageBox::Cancel)
579 logger->addItem(tr("Bootloader installation canceled!"),LOGERROR);
580 logger->abort();
581 m_error = true;
582 return;
584 else if(ret == QMessageBox::Ignore)
586 logger->addItem(tr("Bootloader installation skipped!"),LOGERROR);
587 logger->abort();
588 m_installed = true;
589 return;
593 // if fwpatcher , ask for extra file
594 QString offirmware;
595 if(devices->value(platform + "/bootloadermethod").toString() == "fwpatcher")
597 BrowseOF ofbrowser(this);
598 ofbrowser.setFile(userSettings->value("ofpath").toString());
599 if(ofbrowser.exec() == QDialog::Accepted)
601 offirmware = ofbrowser.getFile();
602 qDebug() << offirmware;
603 if(!QFileInfo(offirmware).exists())
605 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
606 logger->abort();
607 m_error = true;
608 return;
610 else
612 userSettings->setValue("ofpath",offirmware);
613 userSettings->sync();
616 else
618 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
619 logger->abort();
620 m_error = true;
621 return;
624 blinstaller->setOrigFirmwarePath(offirmware);
626 blinstaller->install(logger);
629 void RbUtilQt::installFontsBtn()
631 if(chkConfig(true)) return;
632 if(QMessageBox::question(this, tr("Confirm Installation"),
633 tr("Do you really want to install the fonts package?"),
634 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
635 // create logger
636 logger = new ProgressLoggerGui(this);
637 logger->show();
638 installFonts();
641 bool RbUtilQt::installFontsAuto()
643 installFonts();
644 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
645 return !m_error;
648 void RbUtilQt::installFonts()
650 // create zip installer
651 installer = new ZipInstaller(this);
653 installer->setUrl(devices->value("font_url").toString());
654 installer->setProxy(proxy());
655 installer->setLogSection("Fonts");
656 installer->setLogVersion(versmap.value("arch_date"));
657 installer->setMountPoint(userSettings->value("mountpoint").toString());
658 if(!userSettings->value("cachedisable").toBool())
659 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
660 installer->install(logger);
664 void RbUtilQt::installVoice()
666 if(chkConfig(true)) return;
667 if(QMessageBox::question(this, tr("Confirm Installation"),
668 tr("Do you really want to install the voice file?"),
669 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
670 // create logger
671 logger = new ProgressLoggerGui(this);
672 logger->show();
674 // create zip installer
675 installer = new ZipInstaller(this);
676 installer->setUnzip(false);
678 QString voiceurl = devices->value("voice_url").toString() + "/" +
679 userSettings->value("platform").toString() + "-" +
680 versmap.value("arch_date") + "-english.voice";
681 qDebug() << voiceurl;
683 installer->setProxy(proxy());
684 installer->setUrl(voiceurl);
685 installer->setLogSection("Voice");
686 installer->setLogVersion(versmap.value("arch_date"));
687 installer->setMountPoint(userSettings->value("mountpoint").toString());
688 installer->setTarget("/.rockbox/langs/english.voice");
689 if(!userSettings->value("cachedisable").toBool())
690 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
691 installer->install(logger);
693 //connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
696 void RbUtilQt::installDoomBtn()
698 if(chkConfig(true)) return;
699 if(!hasDoom()){
700 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
701 return;
704 if(QMessageBox::question(this, tr("Confirm Installation"),
705 tr("Do you really want to install the game addon files?"),
706 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
707 // create logger
708 logger = new ProgressLoggerGui(this);
709 logger->show();
711 installDoom();
713 bool RbUtilQt::installDoomAuto()
715 installDoom();
716 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
717 return !m_error;
720 bool RbUtilQt::hasDoom()
722 QFile doomrock(userSettings->value("mountpoint").toString()+"/.rockbox/rocks/games/doom.rock");
723 return doomrock.exists();
726 void RbUtilQt::installDoom()
728 // create zip installer
729 installer = new ZipInstaller(this);
731 installer->setUrl(devices->value("doom_url").toString());
732 installer->setProxy(proxy());
733 installer->setLogSection("Game Addons");
734 installer->setLogVersion(versmap.value("arch_date"));
735 installer->setMountPoint(userSettings->value("mountpoint").toString());
736 if(!userSettings->value("cachedisable").toBool())
737 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
738 installer->install(logger);
743 void RbUtilQt::installThemes()
745 if(chkConfig(true)) return;
746 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
747 tw->setDeviceSettings(devices);
748 tw->setUserSettings(userSettings);
749 tw->setProxy(proxy());
750 tw->setModal(true);
751 tw->show();
755 void RbUtilQt::createTalkFiles(void)
757 if(chkConfig(true)) return;
758 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
759 installWindow->setUserSettings(userSettings);
760 installWindow->setDeviceSettings(devices);
761 installWindow->show();
765 void RbUtilQt::uninstall(void)
767 if(chkConfig(true)) return;
768 UninstallWindow *uninstallWindow = new UninstallWindow(this);
769 uninstallWindow->setUserSettings(userSettings);
770 uninstallWindow->setDeviceSettings(devices);
771 uninstallWindow->show();
774 void RbUtilQt::uninstallBootloader(void)
776 if(chkConfig(true)) return;
777 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
778 tr("Do you really want to uninstall the Bootloader?"),
779 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
780 // create logger
781 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
782 logger->show();
784 QString plattform = userSettings->value("platform").toString();
785 BootloaderInstaller blinstaller(this);
786 blinstaller.setProxy(proxy());
787 blinstaller.setMountPoint(userSettings->value("mountpoint").toString());
788 blinstaller.setDevice(userSettings->value("platform").toString());
789 blinstaller.setBootloaderMethod(devices->value(plattform + "/bootloadermethod").toString());
790 blinstaller.setBootloaderName(devices->value(plattform + "/bootloadername").toString());
791 blinstaller.setBootloaderBaseUrl(devices->value("bootloader_url").toString());
792 blinstaller.setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
793 if(!blinstaller.downloadInfo())
795 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
796 logger->abort();
797 return;
800 blinstaller.uninstall(logger);
805 void RbUtilQt::downloadManual(void)
807 if(chkConfig(true)) return;
808 if(QMessageBox::question(this, tr("Confirm download"),
809 tr("Do you really want to download the manual? The manual will be saved "
810 "to the root folder of your player."),
811 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
812 return;
814 buildInfo.open();
815 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
816 buildInfo.close();
818 devices->beginGroup(userSettings->value("platform").toString());
819 QString manual;
820 manual = devices->value("manualname", "rockbox-" + devices->value("platform").toString()).toString();
821 devices->endGroup();
823 QString date = (info.value("dailies/date").toString());
825 QString manualurl;
826 QString target;
827 QString section;
828 if(ui.radioPdf->isChecked()) {
829 target = "/" + manual + ".pdf";
830 section = "Manual (PDF)";
832 else {
833 target = "/" + manual + "-" + date + "-html.zip";
834 section = "Manual (HTML)";
836 manualurl = devices->value("manual_url").toString() + "/" + target;
837 qDebug() << "manualurl =" << manualurl;
839 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
840 logger->show();
841 installer = new ZipInstaller(this);
842 installer->setMountPoint(userSettings->value("mountpoint").toString());
843 if(!userSettings->value("cachedisable").toBool())
844 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
845 installer->setProxy(proxy());
846 installer->setLogSection(section);
847 installer->setLogVersion(date);
848 installer->setUrl(manualurl);
849 installer->setUnzip(false);
850 installer->setTarget(target);
851 installer->install(logger);
855 void RbUtilQt::installPortable(void)
857 if(QMessageBox::question(this, tr("Confirm installation"),
858 tr("Do you really want to install Rockbox Utility to your player? "
859 "After installation you can run it from the players hard drive."),
860 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
861 return;
863 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
864 logger->setProgressMax(0);
865 logger->setProgressValue(0);
866 logger->show();
867 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
869 // check mountpoint
870 if(!QFileInfo(userSettings->value("mountpoint").toString()).isDir()) {
871 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
872 logger->abort();
873 return;
876 // remove old files first.
877 QFile::remove(userSettings->value("mountpoint").toString() + "/RockboxUtility.exe");
878 QFile::remove(userSettings->value("mountpoint").toString() + "/RockboxUtility.ini");
879 // copy currently running binary and currently used settings file
880 if(!QFile::copy(qApp->applicationFilePath(), userSettings->value("mountpoint").toString() + "/RockboxUtility.exe")) {
881 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
882 logger->abort();
883 return;
885 logger->addItem(tr("Installing user configuration"), LOGINFO);
886 if(!QFile::copy(userSettings->fileName(), userSettings->value("mountpoint").toString() + "/RockboxUtility.ini")) {
887 logger->addItem(tr("Error installing user configuration"), LOGERROR);
888 logger->abort();
889 return;
891 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
892 logger->abort();
893 logger->setProgressMax(1);
894 logger->setProgressValue(1);
899 void RbUtilQt::updateInfo()
901 qDebug() << "RbUtilQt::updateInfo()";
903 QSettings log(userSettings->value("mountpoint").toString() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
904 QStringList groups = log.childGroups();
905 QList<QTreeWidgetItem *> items;
906 QTreeWidgetItem *w, *w2;
907 QString min, max;
908 int olditems = 0;
910 // remove old list entries (if any)
911 int l = ui.treeInfo->topLevelItemCount();
912 while(l--) {
913 QTreeWidgetItem *m;
914 m = ui.treeInfo->takeTopLevelItem(l);
915 // delete childs (single level deep, no recursion here)
916 int n = m->childCount();
917 while(n--)
918 delete m->child(n);
920 // get and populate new items
921 for(int a = 0; a < groups.size(); a++) {
922 log.beginGroup(groups.at(a));
923 QStringList keys = log.allKeys();
924 w = new QTreeWidgetItem;
925 w->setFlags(Qt::ItemIsEnabled);
926 w->setText(0, groups.at(a));
927 items.append(w);
928 // get minimum and maximum version information so we can hilight old files
929 min = max = log.value(keys.at(0)).toString();
930 for(int b = 0; b < keys.size(); b++) {
931 if(log.value(keys.at(b)).toString() > max)
932 max = log.value(keys.at(b)).toString();
933 if(log.value(keys.at(b)).toString() < min)
934 min = log.value(keys.at(b)).toString();
937 for(int b = 0; b < keys.size(); b++) {
938 QString file;
939 file = userSettings->value("mountpoint").toString() + "/" + keys.at(b);
940 if(QFileInfo(file).isDir())
941 continue;
942 w2 = new QTreeWidgetItem(w, QStringList() << "/"
943 + keys.at(b) << log.value(keys.at(b)).toString());
944 if(log.value(keys.at(b)).toString() != max) {
945 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
946 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
947 olditems++;
949 items.append(w2);
951 log.endGroup();
952 if(min != max)
953 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
954 else
955 w->setData(1, Qt::DisplayRole, max);
957 ui.treeInfo->insertTopLevelItems(0, items);
958 ui.treeInfo->resizeColumnToContents(0);
962 QUrl RbUtilQt::proxy()
964 if(userSettings->value("proxytype", "system").toString() == "manual")
965 return QUrl(userSettings->value("proxy").toString());
966 #if defined(Q_OS_LINUX)
967 else if(userSettings->value("proxytype", "system").toString() == "system")
968 return QUrl(getenv("http_proxy"));
969 #endif
970 #if defined(Q_OS_WIN32)
971 HKEY hk;
972 wchar_t proxyval[80];
973 DWORD buflen = 80;
974 long ret;
976 ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
977 0, KEY_QUERY_VALUE, &hk);
978 if(ret != ERROR_SUCCESS) return QUrl("");
980 ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
981 if(ret != ERROR_SUCCESS) return QUrl("");
983 RegCloseKey(hk);
984 qDebug() << QString::fromWCharArray(proxyval);
985 return QUrl("http://" + QString::fromWCharArray(proxyval));
987 #endif
988 return QUrl("");
992 bool RbUtilQt::chkConfig(bool warn)
994 bool error = false;
995 if(userSettings->value("platform").toString().isEmpty()
996 || userSettings->value("mountpoint").toString().isEmpty()
997 || !QFileInfo(userSettings->value("mountpoint").toString()).isWritable()) {
998 error = true;
1000 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1001 tr("Your configuration is invalid. Please go to the configuration "
1002 "dialog and make sure the selected values are correct."));
1004 return error;