Colour targets: Revert an optimisation from almost 18 months ago that actually turned...
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blobb5e485c57c0b7b1b57a3a28c6485de1223f0e1be
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"
38 #include "detect.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(Detect::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 = Detect::installedVersion(settings->mountpoint());
480 if(Detect::check(settings,false,settings->curTargetId()) == false)
482 logger->addItem(tr("Aborted!"),LOGERROR);
483 logger->abort();
484 return false;
487 // check version
488 if(rbVersion != "")
490 if(QMessageBox::question(this, tr("Installed Rockbox detected"),
491 tr("Rockbox installation detected. Do you want to backup first?"),
492 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
494 logger->addItem(tr("Starting backup..."),LOGINFO);
495 QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip";
497 //! create dir, if it doesnt exist
498 QFileInfo backupFile(backupName);
499 if(!QDir(backupFile.path()).exists())
501 QDir a;
502 a.mkpath(backupFile.path());
505 //! create backup
506 RbZip backup;
507 connect(&backup,SIGNAL(zipProgress(int,int)),logger, SLOT(setProgress(int,int)));
508 if(backup.createZip(backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
510 logger->addItem(tr("Backup successfull"),LOGOK);
512 else
514 logger->addItem(tr("Backup failed!"),LOGERROR);
515 logger->abort();
516 return false;
521 //! install current build
522 ZipInstaller* installer = new ZipInstaller(this);
523 installer->setUrl(file);
524 installer->setLogSection("Rockbox (Base)");
525 installer->setLogVersion(myversion);
526 if(!settings->cacheDisabled())
527 installer->setCache(true);
528 installer->setMountPoint(settings->mountpoint());
530 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
532 installer->install(logger);
533 return true;
537 void RbUtilQt::install()
539 Install *installWindow = new Install(settings,this);
541 buildInfo.open();
542 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
543 buildInfo.close();
545 if(settings->curReleased()) {
546 // only set the keys if needed -- querying will yield an empty string
547 // if not set.
548 versmap.insert("rel_rev", settings->lastRelease());
549 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
551 installWindow->setVersionStrings(versmap);
553 installWindow->show();
556 bool RbUtilQt::installBootloaderAuto()
558 installBootloader();
559 return !m_error;
562 void RbUtilQt::installBootloaderBtn()
564 if(chkConfig(true)) return;
565 if(QMessageBox::question(this, tr("Confirm Installation"),
566 tr("Do you really want to install the Bootloader?"),
567 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
569 // create logger
570 logger = new ProgressLoggerGui(this);
571 logger->show();
573 installBootloader();
576 void RbUtilQt::installBootloader()
578 QString platform = settings->curPlatform();
580 // create installer
581 blinstaller = new BootloaderInstaller(this);
583 blinstaller->setMountPoint(settings->mountpoint());
585 blinstaller->setDevice(platform);
586 blinstaller->setBootloaderMethod(settings->curBootloaderMethod());
587 blinstaller->setBootloaderName(settings->curBootloaderName());
588 blinstaller->setBootloaderBaseUrl(settings->bootloaderUrl());
589 blinstaller->setBootloaderInfoUrl(settings->bootloaderInfoUrl());
590 if(!blinstaller->downloadInfo())
592 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
593 logger->abort();
594 m_error = true;
595 return;
598 if(blinstaller->uptodate())
600 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
601 tr("The bootloader is already installed and up to date.\n"
602 "Do want to replace the current bootloader?"),
603 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
604 if(ret == QMessageBox::No)
606 logger->addItem(tr("Bootloader installation skipped!"), LOGINFO);
607 logger->abort();
608 m_installed = true;
609 return;
613 // if fwpatcher , ask for extra file
614 QString offirmware;
615 if(settings->curBootloaderMethod() == "fwpatcher")
617 BrowseOF ofbrowser(this);
618 ofbrowser.setFile(settings->ofPath());
619 if(ofbrowser.exec() == QDialog::Accepted)
621 offirmware = ofbrowser.getFile();
622 qDebug() << offirmware;
623 if(!QFileInfo(offirmware).exists())
625 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
626 logger->abort();
627 m_error = true;
628 return;
630 else
632 settings->setOfPath(offirmware);
633 settings->sync();
636 else
638 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
639 logger->abort();
640 m_error = true;
641 return;
644 blinstaller->setOrigFirmwarePath(offirmware);
645 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
646 blinstaller->install(logger);
649 void RbUtilQt::installFontsBtn()
651 if(chkConfig(true)) return;
652 if(QMessageBox::question(this, tr("Confirm Installation"),
653 tr("Do you really want to install the fonts package?"),
654 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
655 // create logger
656 logger = new ProgressLoggerGui(this);
657 logger->show();
658 installFonts();
661 bool RbUtilQt::installFontsAuto()
663 installFonts();
665 return !m_error;
668 void RbUtilQt::installFonts()
670 // create zip installer
671 installer = new ZipInstaller(this);
673 installer->setUrl(settings->fontUrl());
674 installer->setLogSection("Fonts");
675 installer->setLogVersion(versmap.value("arch_date"));
676 installer->setMountPoint(settings->mountpoint());
677 if(!settings->cacheDisabled())
678 installer->setCache(true);
680 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
681 installer->install(logger);
685 void RbUtilQt::installVoice()
687 if(chkConfig(true)) return;
689 if(m_gotInfo == false)
691 QMessageBox::warning(this, tr("Warning"),
692 tr("The Application is still downloading Information about new Builds. Please try again shortly."));
693 return;
696 if(QMessageBox::question(this, tr("Confirm Installation"),
697 tr("Do you really want to install the voice file?"),
698 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
699 // create logger
700 logger = new ProgressLoggerGui(this);
701 logger->show();
703 // create zip installer
704 installer = new ZipInstaller(this);
706 QString voiceurl = settings->voiceUrl();
708 voiceurl += settings->curVoiceName() + "-" +
709 versmap.value("arch_date") + "-english.zip";
710 qDebug() << voiceurl;
712 installer->setUrl(voiceurl);
713 installer->setLogSection("Voice");
714 installer->setLogVersion(versmap.value("arch_date"));
715 installer->setMountPoint(settings->mountpoint());
716 if(!settings->cacheDisabled())
717 installer->setCache(true);
718 installer->install(logger);
722 void RbUtilQt::installDoomBtn()
724 if(chkConfig(true)) return;
725 if(!hasDoom()){
726 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
727 return;
730 if(QMessageBox::question(this, tr("Confirm Installation"),
731 tr("Do you really want to install the game addon files?"),
732 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
733 // create logger
734 logger = new ProgressLoggerGui(this);
735 logger->show();
737 installDoom();
739 bool RbUtilQt::installDoomAuto()
741 installDoom();
742 return !m_error;
745 bool RbUtilQt::hasDoom()
747 QFile doomrock(settings->mountpoint() +"/.rockbox/rocks/games/doom.rock");
748 return doomrock.exists();
751 void RbUtilQt::installDoom()
753 // create zip installer
754 installer = new ZipInstaller(this);
756 installer->setUrl(settings->doomUrl());
757 installer->setLogSection("Game Addons");
758 installer->setLogVersion(versmap.value("arch_date"));
759 installer->setMountPoint(settings->mountpoint());
760 if(!settings->cacheDisabled())
761 installer->setCache(true);
762 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
763 installer->install(logger);
767 void RbUtilQt::installThemes()
769 if(chkConfig(true)) return;
770 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
771 tw->setSettings(settings);
772 tw->setModal(true);
773 tw->show();
776 void RbUtilQt::createTalkFiles(void)
778 if(chkConfig(true)) return;
779 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
780 installWindow->setSettings(settings);
782 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
783 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
784 installWindow->show();
788 void RbUtilQt::createVoiceFile(void)
790 if(chkConfig(true)) return;
791 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
792 installWindow->setSettings(settings);
794 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
795 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
796 installWindow->show();
799 void RbUtilQt::uninstall(void)
801 if(chkConfig(true)) return;
802 UninstallWindow *uninstallWindow = new UninstallWindow(this);
803 uninstallWindow->setSettings(settings);
804 uninstallWindow->show();
808 void RbUtilQt::uninstallBootloader(void)
810 if(chkConfig(true)) return;
811 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
812 tr("Do you really want to uninstall the Bootloader?"),
813 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
814 // create logger
815 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
816 logger->show();
818 BootloaderInstaller blinstaller(this);
819 blinstaller.setMountPoint(settings->mountpoint());
820 blinstaller.setDevice(settings->curPlatform());
821 blinstaller.setBootloaderMethod(settings->curBootloaderMethod());
822 blinstaller.setBootloaderName(settings->curBootloaderName());
823 blinstaller.setBootloaderBaseUrl(settings->bootloaderUrl());
824 blinstaller.setBootloaderInfoUrl(settings->bootloaderInfoUrl());
825 if(!blinstaller.downloadInfo())
827 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
828 logger->abort();
829 return;
832 blinstaller.uninstall(logger);
837 void RbUtilQt::downloadManual(void)
839 if(chkConfig(true)) return;
840 if(QMessageBox::question(this, tr("Confirm download"),
841 tr("Do you really want to download the manual? The manual will be saved "
842 "to the root folder of your player."),
843 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
844 return;
846 buildInfo.open();
847 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
848 buildInfo.close();
850 QString manual = settings->curManual();
852 QString date = (info.value("dailies/date").toString());
854 QString manualurl;
855 QString target;
856 QString section;
857 if(ui.radioPdf->isChecked()) {
858 target = "/" + manual + ".pdf";
859 section = "Manual (PDF)";
861 else {
862 target = "/" + manual + "-" + date + "-html.zip";
863 section = "Manual (HTML)";
865 manualurl = settings->manualUrl() + "/" + target;
866 qDebug() << "manualurl =" << manualurl;
868 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
869 logger->show();
870 installer = new ZipInstaller(this);
871 installer->setMountPoint(settings->mountpoint());
872 if(!settings->cacheDisabled())
873 installer->setCache(true);
874 installer->setLogSection(section);
875 installer->setLogVersion(date);
876 installer->setUrl(manualurl);
877 installer->setUnzip(false);
878 installer->setTarget(target);
879 installer->install(logger);
883 void RbUtilQt::installPortable(void)
885 if(QMessageBox::question(this, tr("Confirm installation"),
886 tr("Do you really want to install Rockbox Utility to your player? "
887 "After installation you can run it from the players hard drive."),
888 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
889 return;
891 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
892 logger->setProgressMax(0);
893 logger->setProgressValue(0);
894 logger->show();
895 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
897 // check mountpoint
898 if(!QFileInfo(settings->mountpoint()).isDir()) {
899 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
900 logger->abort();
901 return;
904 // remove old files first.
905 QFile::remove(settings->mountpoint() + "/RockboxUtility.exe");
906 QFile::remove(settings->mountpoint() + "/RockboxUtility.ini");
907 // copy currently running binary and currently used settings file
908 if(!QFile::copy(qApp->applicationFilePath(), settings->mountpoint() + "/RockboxUtility.exe")) {
909 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
910 logger->abort();
911 return;
913 logger->addItem(tr("Installing user configuration"), LOGINFO);
914 if(!QFile::copy(settings->userSettingFilename(), settings->mountpoint() + "/RockboxUtility.ini")) {
915 logger->addItem(tr("Error installing user configuration"), LOGERROR);
916 logger->abort();
917 return;
919 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
920 logger->abort();
921 logger->setProgressMax(1);
922 logger->setProgressValue(1);
927 void RbUtilQt::updateInfo()
929 qDebug() << "RbUtilQt::updateInfo()";
931 QSettings log(settings->mountpoint() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
932 QStringList groups = log.childGroups();
933 QList<QTreeWidgetItem *> items;
934 QTreeWidgetItem *w, *w2;
935 QString min, max;
936 int olditems = 0;
938 // remove old list entries (if any)
939 int l = ui.treeInfo->topLevelItemCount();
940 while(l--) {
941 QTreeWidgetItem *m;
942 m = ui.treeInfo->takeTopLevelItem(l);
943 // delete childs (single level deep, no recursion here)
944 int n = m->childCount();
945 while(n--)
946 delete m->child(n);
948 // get and populate new items
949 for(int a = 0; a < groups.size(); a++) {
950 log.beginGroup(groups.at(a));
951 QStringList keys = log.allKeys();
952 w = new QTreeWidgetItem;
953 w->setFlags(Qt::ItemIsEnabled);
954 w->setText(0, groups.at(a));
955 items.append(w);
956 // get minimum and maximum version information so we can hilight old files
957 min = max = log.value(keys.at(0)).toString();
958 for(int b = 0; b < keys.size(); b++) {
959 if(log.value(keys.at(b)).toString() > max)
960 max = log.value(keys.at(b)).toString();
961 if(log.value(keys.at(b)).toString() < min)
962 min = log.value(keys.at(b)).toString();
965 for(int b = 0; b < keys.size(); b++) {
966 QString file;
967 file = settings->mountpoint() + "/" + keys.at(b);
968 if(QFileInfo(file).isDir())
969 continue;
970 w2 = new QTreeWidgetItem(w, QStringList() << "/"
971 + keys.at(b) << log.value(keys.at(b)).toString());
972 if(log.value(keys.at(b)).toString() != max) {
973 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
974 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
975 olditems++;
977 items.append(w2);
979 log.endGroup();
980 if(min != max)
981 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
982 else
983 w->setData(1, Qt::DisplayRole, max);
985 ui.treeInfo->insertTopLevelItems(0, items);
986 ui.treeInfo->resizeColumnToContents(0);
990 QUrl RbUtilQt::proxy()
992 if(settings->proxyType() == "manual")
993 return QUrl(settings->proxy());
994 else if(settings->proxy() == "system")
996 return Detect::systemProxy();
998 return QUrl("");
1002 bool RbUtilQt::chkConfig(bool warn)
1004 bool error = false;
1005 if(settings->curPlatform().isEmpty()
1006 || settings->mountpoint().isEmpty()
1007 || !QFileInfo(settings->mountpoint()).isWritable()) {
1008 error = true;
1010 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1011 tr("Your configuration is invalid. Please go to the configuration "
1012 "dialog and make sure the selected values are correct."));
1014 return error;