Fix spelling error: successfull -> successful
[kugel-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blob8921eadb9a4aa1a1bdc35965a89a59d655929dc4
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(settings->curVersion() != PUREVERSION) {
180 QApplication::processEvents();
181 QMessageBox::information(this, tr("New installation"),
182 tr("This is a new installation of Rockbox Utility, or a new version. "
183 "The configuration dialog will now open to allow you to setup the program, "
184 " or review your settings."));
185 configDialog();
187 else if(chkConfig(false)) {
188 QApplication::processEvents();
189 QMessageBox::critical(this, tr("Configuration error"),
190 tr("Your configuration is invalid. This is most likely due "
191 "to a changed device path. The configuration dialog will "
192 "now open to allow you to correct 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;
209 m_gotInfo = true;
213 void RbUtilQt::downloadDone(int id, bool error)
215 QString errorString;
216 errorString = tr("Network error: %1. Please check your network and proxy settings.")
217 .arg(daily->errorString());
218 if(error) {
219 QMessageBox::about(this, "Network Error", errorString);
221 qDebug() << "downloadDone:" << id << error;
225 void RbUtilQt::about()
227 QDialog *window = new QDialog(this);
228 Ui::aboutBox about;
229 about.setupUi(window);
230 window->setModal(true);
232 QFile licence(":/docs/gpl-2.0.html");
233 licence.open(QIODevice::ReadOnly);
234 QTextStream c(&licence);
235 QString cline = c.readAll();
236 about.browserLicense->insertHtml(cline);
237 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
238 QFile credits(":/docs/CREDITS");
239 credits.open(QIODevice::ReadOnly);
240 QTextStream r(&credits);
241 QString rline = r.readAll();
242 about.browserCredits->insertPlainText(rline);
243 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
244 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
245 about.labelTitle->setText(title);
246 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
248 window->show();
253 void RbUtilQt::help()
255 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
256 QDesktopServices::openUrl(helpurl);
260 void RbUtilQt::configDialog()
262 Config *cw = new Config(this);
263 cw->setSettings(settings);
264 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
265 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
266 cw->show();
270 void RbUtilQt::updateSettings()
272 qDebug() << "updateSettings()";
273 updateDevice();
274 updateManual();
275 if(settings->proxyType() == "system") {
276 HttpGet::setGlobalProxy(Detect::systemProxy());
278 else if(settings->proxyType() == "manual") {
279 HttpGet::setGlobalProxy(settings->proxy());
281 else {
282 HttpGet::setGlobalProxy(QUrl(""));
284 HttpGet::setGlobalCache(settings->cachePath());
285 HttpGet::setGlobalDumbCache(settings->cacheOffline());
289 void RbUtilQt::updateDevice()
291 if(!settings->curNeedsBootloader() ) {
292 ui.buttonBootloader->setEnabled(false);
293 ui.buttonRemoveBootloader->setEnabled(false);
294 ui.labelBootloader->setEnabled(false);
295 ui.labelRemoveBootloader->setEnabled(false);
297 else {
298 ui.buttonBootloader->setEnabled(true);
299 ui.labelBootloader->setEnabled(true);
300 if(settings->curBootloaderMethod() == "fwpatcher") {
301 ui.labelRemoveBootloader->setEnabled(false);
302 ui.buttonRemoveBootloader->setEnabled(false);
304 else {
305 ui.labelRemoveBootloader->setEnabled(true);
306 ui.buttonRemoveBootloader->setEnabled(true);
310 // displayed device info
311 QString mountpoint = settings->mountpoint();
312 QString brand = settings->curBrand();
313 QString name = settings->curName();
314 if(name.isEmpty()) name = "&lt;none&gt;";
315 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
316 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
317 .arg(brand, name, QDir::toNativeSeparators(mountpoint)));
321 void RbUtilQt::updateManual()
323 if(settings->curPlatform() != "")
325 QString manual= settings->curManual();
327 if(manual == "")
328 manual = "rockbox-" + settings->curPlatform();
329 QString pdfmanual;
330 pdfmanual = settings->manualUrl() + "/" + manual + ".pdf";
331 QString htmlmanual;
332 htmlmanual = settings->manualUrl() + "/" + manual + "/rockbox-build.html";
333 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
334 .arg(pdfmanual));
335 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
336 .arg(htmlmanual));
338 else {
339 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
340 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
341 .arg("http://www.rockbox.org/manual.shtml"));
346 void RbUtilQt::completeInstall()
348 if(chkConfig(true)) return;
349 if(QMessageBox::question(this, tr("Confirm Installation"),
350 tr("Do you really want to make a complete Installation?"),
351 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
353 // create logger
354 logger = new ProgressLoggerGui(this);
355 logger->show();
357 if(smallInstallInner())
358 return;
359 logger->undoAbort();
360 // Fonts
361 m_error = false;
362 m_installed = false;
363 if(!installFontsAuto())
364 return;
365 else
367 // wait for installation finished
368 while(!m_installed)
369 QApplication::processEvents();
371 if(m_error) return;
372 logger->undoAbort();
374 // Doom
375 if(hasDoom())
377 m_error = false;
378 m_installed = false;
379 if(!installDoomAuto())
380 return;
381 else
383 // wait for installation finished
384 while(!m_installed)
385 QApplication::processEvents();
387 if(m_error) return;
390 // theme
391 // this is a window
392 // it has its own logger window,so close our.
393 logger->close();
394 installThemes();
398 void RbUtilQt::smallInstall()
400 if(chkConfig(true)) return;
401 if(QMessageBox::question(this, tr("Confirm Installation"),
402 tr("Do you really want to make a small Installation?"),
403 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
405 // create logger
406 logger = new ProgressLoggerGui(this);
407 logger->show();
409 smallInstallInner();
412 bool RbUtilQt::smallInstallInner()
414 QString mountpoint = settings->mountpoint();
415 // show dialog with error if mount point is wrong
416 if(!QFileInfo(mountpoint).isDir()) {
417 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
418 logger->abort();
419 return true;
421 // Bootloader
422 if(settings->curNeedsBootloader())
424 m_error = false;
425 m_installed = false;
426 if(!installBootloaderAuto())
427 return true;
428 else
430 // wait for boot loader installation finished
431 while(!m_installed)
432 QApplication::processEvents();
434 if(m_error) return true;
435 logger->undoAbort();
438 // Rockbox
439 m_error = false;
440 m_installed = false;
441 if(!installAuto())
442 return true;
443 else
445 // wait for installation finished
446 while(!m_installed)
447 QApplication::processEvents();
450 return false;
453 void RbUtilQt::installdone(bool error)
455 qDebug() << "install done";
456 m_installed = true;
457 m_error = error;
460 void RbUtilQt::installBtn()
462 if(chkConfig(true)) return;
463 install();
466 bool RbUtilQt::installAuto()
468 QString file = QString("%1%2/rockbox.zip")
469 .arg(settings->bleedingUrl(), settings->curPlatform());
471 buildInfo.open();
472 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
473 buildInfo.close();
475 if(settings->curReleased()) {
476 // only set the keys if needed -- querying will yield an empty string
477 // if not set.
478 versmap.insert("rel_rev", settings->lastRelease());
479 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
482 QString myversion = "r" + versmap.value("bleed_rev");
484 // check installed Version and Target
485 QString rbVersion = Detect::installedVersion(settings->mountpoint());
487 if(Detect::check(settings,false,settings->curTargetId()) == false)
489 logger->addItem(tr("Aborted!"),LOGERROR);
490 logger->abort();
491 return false;
494 // check version
495 if(rbVersion != "")
497 if(QMessageBox::question(this, tr("Installed Rockbox detected"),
498 tr("Rockbox installation detected. Do you want to backup first?"),
499 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
501 logger->addItem(tr("Starting backup..."),LOGINFO);
502 QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip";
504 //! create dir, if it doesnt exist
505 QFileInfo backupFile(backupName);
506 if(!QDir(backupFile.path()).exists())
508 QDir a;
509 a.mkpath(backupFile.path());
512 //! create backup
513 RbZip backup;
514 connect(&backup,SIGNAL(zipProgress(int,int)),logger, SLOT(setProgress(int,int)));
515 if(backup.createZip(backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
517 logger->addItem(tr("Backup successful"),LOGOK);
519 else
521 logger->addItem(tr("Backup failed!"),LOGERROR);
522 logger->abort();
523 return false;
528 //! install current build
529 ZipInstaller* installer = new ZipInstaller(this);
530 installer->setUrl(file);
531 installer->setLogSection("Rockbox (Base)");
532 installer->setLogVersion(myversion);
533 if(!settings->cacheDisabled())
534 installer->setCache(true);
535 installer->setMountPoint(settings->mountpoint());
537 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
539 installer->install(logger);
540 return true;
544 void RbUtilQt::install()
546 Install *installWindow = new Install(settings,this);
548 buildInfo.open();
549 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
550 buildInfo.close();
552 if(settings->curReleased()) {
553 // only set the keys if needed -- querying will yield an empty string
554 // if not set.
555 versmap.insert("rel_rev", settings->lastRelease());
556 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
558 installWindow->setVersionStrings(versmap);
560 installWindow->show();
563 bool RbUtilQt::installBootloaderAuto()
565 installBootloader();
566 return !m_error;
569 void RbUtilQt::installBootloaderBtn()
571 if(chkConfig(true)) return;
572 if(QMessageBox::question(this, tr("Confirm Installation"),
573 tr("Do you really want to install the Bootloader?"),
574 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
576 // create logger
577 logger = new ProgressLoggerGui(this);
578 logger->show();
580 installBootloader();
583 void RbUtilQt::installBootloader()
585 QString platform = settings->curPlatform();
587 // create installer
588 blinstaller = new BootloaderInstaller(this);
590 blinstaller->setMountPoint(settings->mountpoint());
592 blinstaller->setDevice(platform);
593 blinstaller->setBootloaderMethod(settings->curBootloaderMethod());
594 blinstaller->setBootloaderName(settings->curBootloaderName());
595 blinstaller->setBootloaderBaseUrl(settings->bootloaderUrl());
596 blinstaller->setBootloaderInfoUrl(settings->bootloaderInfoUrl());
597 if(!blinstaller->downloadInfo())
599 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
600 logger->abort();
601 m_error = true;
602 return;
605 if(blinstaller->uptodate())
607 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
608 tr("The bootloader is already installed and up to date.\n"
609 "Do want to replace the current bootloader?"),
610 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
611 if(ret == QMessageBox::No)
613 logger->addItem(tr("Bootloader installation skipped!"), LOGINFO);
614 logger->abort();
615 m_installed = true;
616 return;
620 // if fwpatcher , ask for extra file
621 QString offirmware;
622 if(settings->curBootloaderMethod() == "fwpatcher")
624 BrowseOF ofbrowser(this);
625 ofbrowser.setFile(settings->ofPath());
626 if(ofbrowser.exec() == QDialog::Accepted)
628 offirmware = ofbrowser.getFile();
629 qDebug() << offirmware;
630 if(!QFileInfo(offirmware).exists())
632 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
633 logger->abort();
634 m_error = true;
635 return;
637 else
639 settings->setOfPath(offirmware);
640 settings->sync();
643 else
645 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
646 logger->abort();
647 m_error = true;
648 return;
651 blinstaller->setOrigFirmwarePath(offirmware);
652 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
653 blinstaller->install(logger);
656 void RbUtilQt::installFontsBtn()
658 if(chkConfig(true)) return;
659 if(QMessageBox::question(this, tr("Confirm Installation"),
660 tr("Do you really want to install the fonts package?"),
661 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
662 // create logger
663 logger = new ProgressLoggerGui(this);
664 logger->show();
665 installFonts();
668 bool RbUtilQt::installFontsAuto()
670 installFonts();
672 return !m_error;
675 void RbUtilQt::installFonts()
677 // create zip installer
678 installer = new ZipInstaller(this);
680 installer->setUrl(settings->fontUrl());
681 installer->setLogSection("Fonts");
682 installer->setLogVersion(versmap.value("arch_date"));
683 installer->setMountPoint(settings->mountpoint());
684 if(!settings->cacheDisabled())
685 installer->setCache(true);
687 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
688 installer->install(logger);
692 void RbUtilQt::installVoice()
694 if(chkConfig(true)) return;
696 if(m_gotInfo == false)
698 QMessageBox::warning(this, tr("Warning"),
699 tr("The Application is still downloading Information about new Builds. Please try again shortly."));
700 return;
703 if(QMessageBox::question(this, tr("Confirm Installation"),
704 tr("Do you really want to install the voice file?"),
705 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
706 // create logger
707 logger = new ProgressLoggerGui(this);
708 logger->show();
710 // create zip installer
711 installer = new ZipInstaller(this);
713 QString voiceurl = settings->voiceUrl();
715 voiceurl += settings->curVoiceName() + "-" +
716 versmap.value("arch_date") + "-english.zip";
717 qDebug() << voiceurl;
719 installer->setUrl(voiceurl);
720 installer->setLogSection("Voice");
721 installer->setLogVersion(versmap.value("arch_date"));
722 installer->setMountPoint(settings->mountpoint());
723 if(!settings->cacheDisabled())
724 installer->setCache(true);
725 installer->install(logger);
729 void RbUtilQt::installDoomBtn()
731 if(chkConfig(true)) return;
732 if(!hasDoom()){
733 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
734 return;
737 if(QMessageBox::question(this, tr("Confirm Installation"),
738 tr("Do you really want to install the game addon files?"),
739 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
740 // create logger
741 logger = new ProgressLoggerGui(this);
742 logger->show();
744 installDoom();
746 bool RbUtilQt::installDoomAuto()
748 installDoom();
749 return !m_error;
752 bool RbUtilQt::hasDoom()
754 QFile doomrock(settings->mountpoint() +"/.rockbox/rocks/games/doom.rock");
755 return doomrock.exists();
758 void RbUtilQt::installDoom()
760 // create zip installer
761 installer = new ZipInstaller(this);
763 installer->setUrl(settings->doomUrl());
764 installer->setLogSection("Game Addons");
765 installer->setLogVersion(versmap.value("arch_date"));
766 installer->setMountPoint(settings->mountpoint());
767 if(!settings->cacheDisabled())
768 installer->setCache(true);
769 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
770 installer->install(logger);
774 void RbUtilQt::installThemes()
776 if(chkConfig(true)) return;
777 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
778 tw->setSettings(settings);
779 tw->setModal(true);
780 tw->show();
783 void RbUtilQt::createTalkFiles(void)
785 if(chkConfig(true)) return;
786 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
787 installWindow->setSettings(settings);
789 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
790 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
791 installWindow->show();
795 void RbUtilQt::createVoiceFile(void)
797 if(chkConfig(true)) return;
798 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
799 installWindow->setSettings(settings);
801 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
802 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
803 installWindow->show();
806 void RbUtilQt::uninstall(void)
808 if(chkConfig(true)) return;
809 UninstallWindow *uninstallWindow = new UninstallWindow(this);
810 uninstallWindow->setSettings(settings);
811 uninstallWindow->show();
815 void RbUtilQt::uninstallBootloader(void)
817 if(chkConfig(true)) return;
818 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
819 tr("Do you really want to uninstall the Bootloader?"),
820 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
821 // create logger
822 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
823 logger->show();
825 BootloaderInstaller blinstaller(this);
826 blinstaller.setMountPoint(settings->mountpoint());
827 blinstaller.setDevice(settings->curPlatform());
828 blinstaller.setBootloaderMethod(settings->curBootloaderMethod());
829 blinstaller.setBootloaderName(settings->curBootloaderName());
830 blinstaller.setBootloaderBaseUrl(settings->bootloaderUrl());
831 blinstaller.setBootloaderInfoUrl(settings->bootloaderInfoUrl());
832 if(!blinstaller.downloadInfo())
834 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
835 logger->abort();
836 return;
839 blinstaller.uninstall(logger);
844 void RbUtilQt::downloadManual(void)
846 if(chkConfig(true)) return;
847 if(QMessageBox::question(this, tr("Confirm download"),
848 tr("Do you really want to download the manual? The manual will be saved "
849 "to the root folder of your player."),
850 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
851 return;
853 buildInfo.open();
854 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
855 buildInfo.close();
857 QString manual = settings->curManual();
859 QString date = (info.value("dailies/date").toString());
861 QString manualurl;
862 QString target;
863 QString section;
864 if(ui.radioPdf->isChecked()) {
865 target = "/" + manual + ".pdf";
866 section = "Manual (PDF)";
868 else {
869 target = "/" + manual + "-" + date + "-html.zip";
870 section = "Manual (HTML)";
872 manualurl = settings->manualUrl() + "/" + target;
873 qDebug() << "manualurl =" << manualurl;
875 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
876 logger->show();
877 installer = new ZipInstaller(this);
878 installer->setMountPoint(settings->mountpoint());
879 if(!settings->cacheDisabled())
880 installer->setCache(true);
881 installer->setLogSection(section);
882 installer->setLogVersion(date);
883 installer->setUrl(manualurl);
884 installer->setUnzip(false);
885 installer->setTarget(target);
886 installer->install(logger);
890 void RbUtilQt::installPortable(void)
892 if(QMessageBox::question(this, tr("Confirm installation"),
893 tr("Do you really want to install Rockbox Utility to your player? "
894 "After installation you can run it from the players hard drive."),
895 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
896 return;
898 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
899 logger->setProgressMax(0);
900 logger->setProgressValue(0);
901 logger->show();
902 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
904 // check mountpoint
905 if(!QFileInfo(settings->mountpoint()).isDir()) {
906 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
907 logger->abort();
908 return;
911 // remove old files first.
912 QFile::remove(settings->mountpoint() + "/RockboxUtility.exe");
913 QFile::remove(settings->mountpoint() + "/RockboxUtility.ini");
914 // copy currently running binary and currently used settings file
915 if(!QFile::copy(qApp->applicationFilePath(), settings->mountpoint() + "/RockboxUtility.exe")) {
916 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
917 logger->abort();
918 return;
920 logger->addItem(tr("Installing user configuration"), LOGINFO);
921 if(!QFile::copy(settings->userSettingFilename(), settings->mountpoint() + "/RockboxUtility.ini")) {
922 logger->addItem(tr("Error installing user configuration"), LOGERROR);
923 logger->abort();
924 return;
926 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
927 logger->abort();
928 logger->setProgressMax(1);
929 logger->setProgressValue(1);
934 void RbUtilQt::updateInfo()
936 qDebug() << "RbUtilQt::updateInfo()";
938 QSettings log(settings->mountpoint() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
939 QStringList groups = log.childGroups();
940 QList<QTreeWidgetItem *> items;
941 QTreeWidgetItem *w, *w2;
942 QString min, max;
943 int olditems = 0;
945 // remove old list entries (if any)
946 int l = ui.treeInfo->topLevelItemCount();
947 while(l--) {
948 QTreeWidgetItem *m;
949 m = ui.treeInfo->takeTopLevelItem(l);
950 // delete childs (single level deep, no recursion here)
951 int n = m->childCount();
952 while(n--)
953 delete m->child(n);
955 // get and populate new items
956 for(int a = 0; a < groups.size(); a++) {
957 log.beginGroup(groups.at(a));
958 QStringList keys = log.allKeys();
959 w = new QTreeWidgetItem;
960 w->setFlags(Qt::ItemIsEnabled);
961 w->setText(0, groups.at(a));
962 items.append(w);
963 // get minimum and maximum version information so we can hilight old files
964 min = max = log.value(keys.at(0)).toString();
965 for(int b = 0; b < keys.size(); b++) {
966 if(log.value(keys.at(b)).toString() > max)
967 max = log.value(keys.at(b)).toString();
968 if(log.value(keys.at(b)).toString() < min)
969 min = log.value(keys.at(b)).toString();
972 for(int b = 0; b < keys.size(); b++) {
973 QString file;
974 file = settings->mountpoint() + "/" + keys.at(b);
975 if(QFileInfo(file).isDir())
976 continue;
977 w2 = new QTreeWidgetItem(w, QStringList() << "/"
978 + keys.at(b) << log.value(keys.at(b)).toString());
979 if(log.value(keys.at(b)).toString() != max) {
980 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
981 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
982 olditems++;
984 items.append(w2);
986 log.endGroup();
987 if(min != max)
988 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
989 else
990 w->setData(1, Qt::DisplayRole, max);
992 ui.treeInfo->insertTopLevelItems(0, items);
993 ui.treeInfo->resizeColumnToContents(0);
997 QUrl RbUtilQt::proxy()
999 if(settings->proxyType() == "manual")
1000 return QUrl(settings->proxy());
1001 else if(settings->proxy() == "system")
1003 return Detect::systemProxy();
1005 return QUrl("");
1009 bool RbUtilQt::chkConfig(bool warn)
1011 bool error = false;
1012 if(settings->curPlatform().isEmpty()
1013 || settings->mountpoint().isEmpty()
1014 || !QFileInfo(settings->mountpoint()).isWritable()) {
1015 error = true;
1017 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1018 tr("Your configuration is invalid. Please go to the configuration "
1019 "dialog and make sure the selected values are correct."));
1021 return error;