Add a useful note regarding USB connection to the iAudio X5 installation chapter.
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blobb7231977b252c9f4a08b1e3f7fe09581adf92eb7
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 "createvoicewindow.h"
30 #include "httpget.h"
31 #include "installbootloader.h"
32 #include "installthemes.h"
33 #include "uninstallwindow.h"
34 #include "browseof.h"
35 #include "utils.h"
36 #include "rbzip.h"
37 #include "sysinfo.h"
40 #if defined(Q_OS_LINUX)
41 #include <stdio.h>
42 #endif
43 #if defined(Q_OS_WIN32)
44 #if defined(UNICODE)
45 #define _UNICODE
46 #endif
47 #include <stdio.h>
48 #include <tchar.h>
49 #include <windows.h>
50 #endif
52 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
54 absolutePath = qApp->applicationDirPath();
56 ui.setupUi(this);
58 settings = new RbSettings();
59 settings->open();
61 m_gotInfo = false;
63 // manual tab
64 updateSettings();
65 ui.radioPdf->setChecked(true);
67 // info tab
68 ui.treeInfo->setAlternatingRowColors(true);
69 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
70 ui.treeInfo->expandAll();
71 ui.treeInfo->setColumnCount(2);
73 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
74 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
75 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
76 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
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(installBtn()));
80 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
81 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
82 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
83 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
84 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
85 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
86 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
87 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
88 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
89 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
90 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
91 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
93 // actions accessible from the menu
94 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
95 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
96 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
97 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
98 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
99 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
100 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
101 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
102 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
103 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
104 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
105 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
106 connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
108 #if !defined(STATIC)
109 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
110 #else
111 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
112 #endif
114 initIpodpatcher();
115 initSansapatcher();
116 downloadInfo();
121 void RbUtilQt::sysinfo(void)
123 Sysinfo *info = new Sysinfo(this);
124 info->show();
127 void RbUtilQt::updateTabs(int count)
129 switch(count) {
130 case 6:
131 updateInfo();
132 break;
133 default:
134 break;
139 void RbUtilQt::downloadInfo()
141 // try to get the current build information
142 daily = new HttpGet(this);
143 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
144 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
145 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
146 if(settings->cacheOffline())
147 daily->setCache(true);
148 else
149 daily->setCache(false);
150 qDebug() << "downloading build info";
151 daily->setFile(&buildInfo);
152 daily->getFile(QUrl(settings->serverConfUrl()));
156 void RbUtilQt::downloadDone(bool error)
158 if(error) {
159 qDebug() << "network error:" << daily->error();
160 return;
162 qDebug() << "network status:" << daily->error();
164 buildInfo.open();
165 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
166 buildInfo.close();
167 versmap.insert("arch_rev", info.value("dailies/rev").toString());
168 versmap.insert("arch_date", info.value("dailies/date").toString());
170 bleeding = new HttpGet(this);
171 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
172 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
173 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
174 if(settings->cacheOffline())
175 bleeding->setCache(true);
176 bleeding->setFile(&bleedingInfo);
177 bleeding->getFile(QUrl(settings->bleedingInfo()));
179 if(chkConfig(false)) {
180 QApplication::processEvents();
181 QMessageBox::critical(this, tr("Configuration error"),
182 tr("Your configuration is invalid. This is most likely due "
183 "to a new installation of Rockbox Utility or a changed device "
184 "path. The configuration dialog will now open to allow you "
185 "correcting the problem."));
186 configDialog();
191 void RbUtilQt::downloadBleedingDone(bool error)
193 if(error) qDebug() << "network error:" << bleeding->error();
195 bleedingInfo.open();
196 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
197 bleedingInfo.close();
198 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
199 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
200 qDebug() << "versmap =" << versmap;
202 m_gotInfo = true;
206 void RbUtilQt::downloadDone(int id, bool error)
208 QString errorString;
209 errorString = tr("Network error: %1. Please check your network and proxy settings.")
210 .arg(daily->errorString());
211 if(error) {
212 QMessageBox::about(this, "Network Error", errorString);
214 qDebug() << "downloadDone:" << id << error;
218 void RbUtilQt::about()
220 QDialog *window = new QDialog(this);
221 Ui::aboutBox about;
222 about.setupUi(window);
223 window->setModal(true);
225 QFile licence(":/docs/gpl-2.0.html");
226 licence.open(QIODevice::ReadOnly);
227 QTextStream c(&licence);
228 QString cline = c.readAll();
229 about.browserLicense->insertHtml(cline);
230 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
231 QFile credits(":/docs/CREDITS");
232 credits.open(QIODevice::ReadOnly);
233 QTextStream r(&credits);
234 QString rline = r.readAll();
235 about.browserCredits->insertPlainText(rline);
236 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
237 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
238 about.labelTitle->setText(title);
239 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
241 window->show();
246 void RbUtilQt::help()
248 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
249 QDesktopServices::openUrl(helpurl);
253 void RbUtilQt::configDialog()
255 Config *cw = new Config(this);
256 cw->setSettings(settings);
257 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
258 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
259 cw->show();
263 void RbUtilQt::updateSettings()
265 qDebug() << "updateSettings()";
266 updateDevice();
267 updateManual();
268 if(settings->proxyType() == "system") {
269 HttpGet::setGlobalProxy(systemProxy());
271 else if(settings->proxyType() == "manual") {
272 HttpGet::setGlobalProxy(settings->proxy());
274 else {
275 HttpGet::setGlobalProxy(QUrl(""));
277 HttpGet::setGlobalCache(settings->cachePath());
278 HttpGet::setGlobalDumbCache(settings->cacheOffline());
282 void RbUtilQt::updateDevice()
284 if(!settings->curNeedsBootloader() ) {
285 ui.buttonBootloader->setEnabled(false);
286 ui.buttonRemoveBootloader->setEnabled(false);
287 ui.labelBootloader->setEnabled(false);
288 ui.labelRemoveBootloader->setEnabled(false);
290 else {
291 ui.buttonBootloader->setEnabled(true);
292 ui.labelBootloader->setEnabled(true);
293 if(settings->curBootloaderMethod() == "fwpatcher") {
294 ui.labelRemoveBootloader->setEnabled(false);
295 ui.buttonRemoveBootloader->setEnabled(false);
297 else {
298 ui.labelRemoveBootloader->setEnabled(true);
299 ui.buttonRemoveBootloader->setEnabled(true);
303 // displayed device info
304 QString mountpoint = settings->mountpoint();
305 QString brand = settings->curBrand();
306 QString name = settings->curName();
307 if(name.isEmpty()) name = "&lt;none&gt;";
308 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
309 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
310 .arg(brand, name, QDir::toNativeSeparators(mountpoint)));
314 void RbUtilQt::updateManual()
316 if(settings->curPlatform() != "")
318 QString manual= settings->curManual();
320 if(manual == "")
321 manual = "rockbox-" + settings->curPlatform();
322 QString pdfmanual;
323 pdfmanual = settings->manualUrl() + "/" + manual + ".pdf";
324 QString htmlmanual;
325 htmlmanual = settings->manualUrl() + "/" + manual + "/rockbox-build.html";
326 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
327 .arg(pdfmanual));
328 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
329 .arg(htmlmanual));
331 else {
332 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
333 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
334 .arg("http://www.rockbox.org/manual.shtml"));
339 void RbUtilQt::completeInstall()
341 if(chkConfig(true)) return;
342 if(QMessageBox::question(this, tr("Confirm Installation"),
343 tr("Do you really want to make a complete Installation?"),
344 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
346 // create logger
347 logger = new ProgressLoggerGui(this);
348 logger->show();
350 if(smallInstallInner())
351 return;
352 logger->undoAbort();
353 // Fonts
354 m_error = false;
355 m_installed = false;
356 if(!installFontsAuto())
357 return;
358 else
360 // wait for installation finished
361 while(!m_installed)
362 QApplication::processEvents();
364 if(m_error) return;
365 logger->undoAbort();
367 // Doom
368 if(hasDoom())
370 m_error = false;
371 m_installed = false;
372 if(!installDoomAuto())
373 return;
374 else
376 // wait for installation finished
377 while(!m_installed)
378 QApplication::processEvents();
380 if(m_error) return;
383 // theme
384 // this is a window
385 // it has its own logger window,so close our.
386 logger->close();
387 installThemes();
391 void RbUtilQt::smallInstall()
393 if(chkConfig(true)) return;
394 if(QMessageBox::question(this, tr("Confirm Installation"),
395 tr("Do you really want to make a small Installation?"),
396 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
398 // create logger
399 logger = new ProgressLoggerGui(this);
400 logger->show();
402 smallInstallInner();
405 bool RbUtilQt::smallInstallInner()
407 QString mountpoint = settings->mountpoint();
408 // show dialog with error if mount point is wrong
409 if(!QFileInfo(mountpoint).isDir()) {
410 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
411 logger->abort();
412 return true;
414 // Bootloader
415 if(settings->curNeedsBootloader())
417 m_error = false;
418 m_installed = false;
419 if(!installBootloaderAuto())
420 return true;
421 else
423 // wait for boot loader installation finished
424 while(!m_installed)
425 QApplication::processEvents();
427 if(m_error) return true;
428 logger->undoAbort();
431 // Rockbox
432 m_error = false;
433 m_installed = false;
434 if(!installAuto())
435 return true;
436 else
438 // wait for installation finished
439 while(!m_installed)
440 QApplication::processEvents();
443 return false;
446 void RbUtilQt::installdone(bool error)
448 qDebug() << "install done";
449 m_installed = true;
450 m_error = error;
453 void RbUtilQt::installBtn()
455 if(chkConfig(true)) return;
456 install();
459 bool RbUtilQt::installAuto()
461 QString file = QString("%1%2/rockbox.zip")
462 .arg(settings->bleedingUrl(), settings->curPlatform());
464 buildInfo.open();
465 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
466 buildInfo.close();
468 if(settings->curReleased()) {
469 // only set the keys if needed -- querying will yield an empty string
470 // if not set.
471 versmap.insert("rel_rev", settings->lastRelease());
472 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
475 QString myversion = "r" + versmap.value("bleed_rev");
477 // check installed Version and Target
478 QString rbVersion = installedVersion(settings->mountpoint());
479 int rbTarget = installedTargetId(settings->mountpoint());
480 if(rbTarget != -1 && rbTarget != settings->curTargetId())
482 if(QMessageBox::question(this, tr("Target mismatch detected"),
483 tr("Target mismatch detected. \n\n"
484 "Installed target: %1.\n"
485 "New Target: %2.\n\n"
486 "Do you want to continue?").arg(settings->nameOfTargetId(rbTarget),settings->curName()),
487 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
489 logger->addItem(tr("Aborted!"),LOGERROR);
490 logger->abort();
491 return false;
495 // check version
496 if(rbVersion != "")
498 if(QMessageBox::question(this, tr("Installed Rockbox detected"),
499 tr("Rockbox installation detected. Do you want to backup first?"),
500 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
502 logger->addItem(tr("Beginning Backup..."),LOGINFO);
503 QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip";
505 //! create dir, if it doesnt exist
506 QFileInfo backupFile(backupName);
507 if(!QDir(backupFile.path()).exists())
509 QDir a;
510 a.mkpath(backupFile.path());
513 //! create backup
514 RbZip backup;
515 connect(&backup,SIGNAL(zipProgress(int,int)),this,SLOT(updateDataReadProgress(int,int)));
516 if(backup.createZip(backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
518 logger->addItem(tr("Backup successfull"),LOGOK);
520 else
522 logger->addItem(tr("Backup failed!"),LOGERROR);
523 logger->abort();
524 return false;
529 //! install current build
530 ZipInstaller* installer = new ZipInstaller(this);
531 installer->setUrl(file);
532 installer->setLogSection("Rockbox (Base)");
533 installer->setLogVersion(myversion);
534 if(!settings->cacheDisabled())
535 installer->setCache(true);
536 installer->setMountPoint(settings->mountpoint());
538 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
540 installer->install(logger);
541 return true;
544 void RbUtilQt::updateDataReadProgress(int read, int total)
546 logger->setProgressMax(total);
547 logger->setProgressValue(read);
548 //qDebug() << "progress:" << read << "/" << total;
552 void RbUtilQt::install()
554 Install *installWindow = new Install(settings,this);
556 buildInfo.open();
557 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
558 buildInfo.close();
560 if(settings->curReleased()) {
561 // only set the keys if needed -- querying will yield an empty string
562 // if not set.
563 versmap.insert("rel_rev", settings->lastRelease());
564 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
566 installWindow->setVersionStrings(versmap);
568 installWindow->show();
571 bool RbUtilQt::installBootloaderAuto()
573 installBootloader();
574 return !m_error;
577 void RbUtilQt::installBootloaderBtn()
579 if(chkConfig(true)) return;
580 if(QMessageBox::question(this, tr("Confirm Installation"),
581 tr("Do you really want to install the Bootloader?"),
582 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
584 // create logger
585 logger = new ProgressLoggerGui(this);
586 logger->show();
588 installBootloader();
591 void RbUtilQt::installBootloader()
593 QString platform = settings->curPlatform();
595 // create installer
596 blinstaller = new BootloaderInstaller(this);
598 blinstaller->setMountPoint(settings->mountpoint());
600 blinstaller->setDevice(platform);
601 blinstaller->setBootloaderMethod(settings->curBootloaderMethod());
602 blinstaller->setBootloaderName(settings->curBootloaderName());
603 blinstaller->setBootloaderBaseUrl(settings->bootloaderUrl());
604 blinstaller->setBootloaderInfoUrl(settings->bootloaderInfoUrl());
605 if(!blinstaller->downloadInfo())
607 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
608 logger->abort();
609 m_error = true;
610 return;
613 if(blinstaller->uptodate())
615 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
616 tr("The bootloader is already installed and up to date.\n"
617 "Do want to replace the current bootloader?"),
618 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
619 if(ret == QMessageBox::No)
621 logger->addItem(tr("Bootloader installation skipped!"), LOGINFO);
622 logger->abort();
623 m_installed = true;
624 return;
628 // if fwpatcher , ask for extra file
629 QString offirmware;
630 if(settings->curBootloaderMethod() == "fwpatcher")
632 BrowseOF ofbrowser(this);
633 ofbrowser.setFile(settings->ofPath());
634 if(ofbrowser.exec() == QDialog::Accepted)
636 offirmware = ofbrowser.getFile();
637 qDebug() << offirmware;
638 if(!QFileInfo(offirmware).exists())
640 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
641 logger->abort();
642 m_error = true;
643 return;
645 else
647 settings->setOfPath(offirmware);
648 settings->sync();
651 else
653 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
654 logger->abort();
655 m_error = true;
656 return;
659 blinstaller->setOrigFirmwarePath(offirmware);
660 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
661 blinstaller->install(logger);
664 void RbUtilQt::installFontsBtn()
666 if(chkConfig(true)) return;
667 if(QMessageBox::question(this, tr("Confirm Installation"),
668 tr("Do you really want to install the fonts package?"),
669 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
670 // create logger
671 logger = new ProgressLoggerGui(this);
672 logger->show();
673 installFonts();
676 bool RbUtilQt::installFontsAuto()
678 installFonts();
680 return !m_error;
683 void RbUtilQt::installFonts()
685 // create zip installer
686 installer = new ZipInstaller(this);
688 installer->setUrl(settings->fontUrl());
689 installer->setLogSection("Fonts");
690 installer->setLogVersion(versmap.value("arch_date"));
691 installer->setMountPoint(settings->mountpoint());
692 if(!settings->cacheDisabled())
693 installer->setCache(true);
695 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
696 installer->install(logger);
700 void RbUtilQt::installVoice()
702 if(chkConfig(true)) return;
704 if(m_gotInfo == false)
706 QMessageBox::warning(this, tr("Warning"),
707 tr("The Application is still downloading Information about new Builds. Please try again shortly."));
708 return;
711 if(QMessageBox::question(this, tr("Confirm Installation"),
712 tr("Do you really want to install the voice file?"),
713 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
714 // create logger
715 logger = new ProgressLoggerGui(this);
716 logger->show();
718 // create zip installer
719 installer = new ZipInstaller(this);
721 QString voiceurl = settings->voiceUrl();
723 voiceurl += settings->curVoiceName() + "-" +
724 versmap.value("arch_date") + "-english.zip";
725 qDebug() << voiceurl;
727 installer->setUrl(voiceurl);
728 installer->setLogSection("Voice");
729 installer->setLogVersion(versmap.value("arch_date"));
730 installer->setMountPoint(settings->mountpoint());
731 if(!settings->cacheDisabled())
732 installer->setCache(true);
733 installer->install(logger);
737 void RbUtilQt::installDoomBtn()
739 if(chkConfig(true)) return;
740 if(!hasDoom()){
741 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
742 return;
745 if(QMessageBox::question(this, tr("Confirm Installation"),
746 tr("Do you really want to install the game addon files?"),
747 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
748 // create logger
749 logger = new ProgressLoggerGui(this);
750 logger->show();
752 installDoom();
754 bool RbUtilQt::installDoomAuto()
756 installDoom();
757 return !m_error;
760 bool RbUtilQt::hasDoom()
762 QFile doomrock(settings->mountpoint() +"/.rockbox/rocks/games/doom.rock");
763 return doomrock.exists();
766 void RbUtilQt::installDoom()
768 // create zip installer
769 installer = new ZipInstaller(this);
771 installer->setUrl(settings->doomUrl());
772 installer->setLogSection("Game Addons");
773 installer->setLogVersion(versmap.value("arch_date"));
774 installer->setMountPoint(settings->mountpoint());
775 if(!settings->cacheDisabled())
776 installer->setCache(true);
777 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
778 installer->install(logger);
782 void RbUtilQt::installThemes()
784 if(chkConfig(true)) return;
785 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
786 tw->setSettings(settings);
787 tw->setModal(true);
788 tw->show();
791 void RbUtilQt::createTalkFiles(void)
793 if(chkConfig(true)) return;
794 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
795 installWindow->setSettings(settings);
797 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
798 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
799 installWindow->show();
803 void RbUtilQt::createVoiceFile(void)
805 if(chkConfig(true)) return;
806 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
807 installWindow->setSettings(settings);
809 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
810 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
811 installWindow->show();
814 void RbUtilQt::uninstall(void)
816 if(chkConfig(true)) return;
817 UninstallWindow *uninstallWindow = new UninstallWindow(this);
818 uninstallWindow->setSettings(settings);
819 uninstallWindow->show();
823 void RbUtilQt::uninstallBootloader(void)
825 if(chkConfig(true)) return;
826 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
827 tr("Do you really want to uninstall the Bootloader?"),
828 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
829 // create logger
830 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
831 logger->show();
833 BootloaderInstaller blinstaller(this);
834 blinstaller.setMountPoint(settings->mountpoint());
835 blinstaller.setDevice(settings->curPlatform());
836 blinstaller.setBootloaderMethod(settings->curBootloaderMethod());
837 blinstaller.setBootloaderName(settings->curBootloaderName());
838 blinstaller.setBootloaderBaseUrl(settings->bootloaderUrl());
839 blinstaller.setBootloaderInfoUrl(settings->bootloaderInfoUrl());
840 if(!blinstaller.downloadInfo())
842 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
843 logger->abort();
844 return;
847 blinstaller.uninstall(logger);
852 void RbUtilQt::downloadManual(void)
854 if(chkConfig(true)) return;
855 if(QMessageBox::question(this, tr("Confirm download"),
856 tr("Do you really want to download the manual? The manual will be saved "
857 "to the root folder of your player."),
858 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
859 return;
861 buildInfo.open();
862 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
863 buildInfo.close();
865 QString manual = settings->curManual();
867 QString date = (info.value("dailies/date").toString());
869 QString manualurl;
870 QString target;
871 QString section;
872 if(ui.radioPdf->isChecked()) {
873 target = "/" + manual + ".pdf";
874 section = "Manual (PDF)";
876 else {
877 target = "/" + manual + "-" + date + "-html.zip";
878 section = "Manual (HTML)";
880 manualurl = settings->manualUrl() + "/" + target;
881 qDebug() << "manualurl =" << manualurl;
883 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
884 logger->show();
885 installer = new ZipInstaller(this);
886 installer->setMountPoint(settings->mountpoint());
887 if(!settings->cacheDisabled())
888 installer->setCache(true);
889 installer->setLogSection(section);
890 installer->setLogVersion(date);
891 installer->setUrl(manualurl);
892 installer->setUnzip(false);
893 installer->setTarget(target);
894 installer->install(logger);
898 void RbUtilQt::installPortable(void)
900 if(QMessageBox::question(this, tr("Confirm installation"),
901 tr("Do you really want to install Rockbox Utility to your player? "
902 "After installation you can run it from the players hard drive."),
903 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
904 return;
906 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
907 logger->setProgressMax(0);
908 logger->setProgressValue(0);
909 logger->show();
910 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
912 // check mountpoint
913 if(!QFileInfo(settings->mountpoint()).isDir()) {
914 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
915 logger->abort();
916 return;
919 // remove old files first.
920 QFile::remove(settings->mountpoint() + "/RockboxUtility.exe");
921 QFile::remove(settings->mountpoint() + "/RockboxUtility.ini");
922 // copy currently running binary and currently used settings file
923 if(!QFile::copy(qApp->applicationFilePath(), settings->mountpoint() + "/RockboxUtility.exe")) {
924 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
925 logger->abort();
926 return;
928 logger->addItem(tr("Installing user configuration"), LOGINFO);
929 if(!QFile::copy(settings->userSettingFilename(), settings->mountpoint() + "/RockboxUtility.ini")) {
930 logger->addItem(tr("Error installing user configuration"), LOGERROR);
931 logger->abort();
932 return;
934 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
935 logger->abort();
936 logger->setProgressMax(1);
937 logger->setProgressValue(1);
942 void RbUtilQt::updateInfo()
944 qDebug() << "RbUtilQt::updateInfo()";
946 QSettings log(settings->mountpoint() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
947 QStringList groups = log.childGroups();
948 QList<QTreeWidgetItem *> items;
949 QTreeWidgetItem *w, *w2;
950 QString min, max;
951 int olditems = 0;
953 // remove old list entries (if any)
954 int l = ui.treeInfo->topLevelItemCount();
955 while(l--) {
956 QTreeWidgetItem *m;
957 m = ui.treeInfo->takeTopLevelItem(l);
958 // delete childs (single level deep, no recursion here)
959 int n = m->childCount();
960 while(n--)
961 delete m->child(n);
963 // get and populate new items
964 for(int a = 0; a < groups.size(); a++) {
965 log.beginGroup(groups.at(a));
966 QStringList keys = log.allKeys();
967 w = new QTreeWidgetItem;
968 w->setFlags(Qt::ItemIsEnabled);
969 w->setText(0, groups.at(a));
970 items.append(w);
971 // get minimum and maximum version information so we can hilight old files
972 min = max = log.value(keys.at(0)).toString();
973 for(int b = 0; b < keys.size(); b++) {
974 if(log.value(keys.at(b)).toString() > max)
975 max = log.value(keys.at(b)).toString();
976 if(log.value(keys.at(b)).toString() < min)
977 min = log.value(keys.at(b)).toString();
980 for(int b = 0; b < keys.size(); b++) {
981 QString file;
982 file = settings->mountpoint() + "/" + keys.at(b);
983 if(QFileInfo(file).isDir())
984 continue;
985 w2 = new QTreeWidgetItem(w, QStringList() << "/"
986 + keys.at(b) << log.value(keys.at(b)).toString());
987 if(log.value(keys.at(b)).toString() != max) {
988 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
989 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
990 olditems++;
992 items.append(w2);
994 log.endGroup();
995 if(min != max)
996 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
997 else
998 w->setData(1, Qt::DisplayRole, max);
1000 ui.treeInfo->insertTopLevelItems(0, items);
1001 ui.treeInfo->resizeColumnToContents(0);
1005 QUrl RbUtilQt::proxy()
1007 if(settings->proxyType() == "manual")
1008 return QUrl(settings->proxy());
1009 else if(settings->proxy() == "system")
1011 return systemProxy();
1013 return QUrl("");
1017 bool RbUtilQt::chkConfig(bool warn)
1019 bool error = false;
1020 if(settings->curPlatform().isEmpty()
1021 || settings->mountpoint().isEmpty()
1022 || !QFileInfo(settings->mountpoint()).isWritable()) {
1023 error = true;
1025 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1026 tr("Your configuration is invalid. Please go to the configuration "
1027 "dialog and make sure the selected values are correct."));
1029 return error;