Add support for the Creative ZEN and renew the way firmwares are
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob564d9d83521e7f980b5ca8441a6e4edc8989780b
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"
37 #if defined(Q_OS_LINUX)
38 #include <stdio.h>
39 #endif
40 #if defined(Q_OS_WIN32)
41 #if defined(UNICODE)
42 #define _UNICODE
43 #endif
44 #include <stdio.h>
45 #include <tchar.h>
46 #include <windows.h>
47 #endif
49 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
51 absolutePath = qApp->applicationDirPath();
53 ui.setupUi(this);
55 settings = new RbSettings();
56 settings->open();
58 m_gotInfo = false;
60 // manual tab
61 updateSettings();
62 ui.radioPdf->setChecked(true);
64 // info tab
65 ui.treeInfo->setAlternatingRowColors(true);
66 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
67 ui.treeInfo->expandAll();
68 ui.treeInfo->setColumnCount(2);
70 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
71 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
72 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
73 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
74 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
75 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
76 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
77 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
78 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
79 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
80 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
81 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
82 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
83 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
84 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
85 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
86 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
87 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
88 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
90 // actions accessible from the menu
91 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
92 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
93 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
94 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
95 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
96 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
97 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
98 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
99 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
100 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
101 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
102 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
104 #if !defined(STATIC)
105 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
106 #else
107 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
108 #endif
110 initIpodpatcher();
111 initSansapatcher();
112 downloadInfo();
117 void RbUtilQt::updateTabs(int count)
119 switch(count) {
120 case 6:
121 updateInfo();
122 break;
123 default:
124 break;
129 void RbUtilQt::downloadInfo()
131 // try to get the current build information
132 daily = new HttpGet(this);
133 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
134 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
135 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
136 if(settings->cacheOffline())
137 daily->setCache(true);
138 else
139 daily->setCache(false);
140 qDebug() << "downloading build info";
141 daily->setFile(&buildInfo);
142 daily->getFile(QUrl(settings->serverConfUrl()));
146 void RbUtilQt::downloadDone(bool error)
148 if(error) {
149 qDebug() << "network error:" << daily->error();
150 return;
152 qDebug() << "network status:" << daily->error();
154 buildInfo.open();
155 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
156 buildInfo.close();
157 versmap.insert("arch_rev", info.value("dailies/rev").toString());
158 versmap.insert("arch_date", info.value("dailies/date").toString());
160 bleeding = new HttpGet(this);
161 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
162 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
163 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
164 if(settings->cacheOffline())
165 bleeding->setCache(true);
166 bleeding->setFile(&bleedingInfo);
167 bleeding->getFile(QUrl(settings->bleedingInfo()));
169 if(chkConfig(false)) {
170 QApplication::processEvents();
171 QMessageBox::critical(this, tr("Configuration error"),
172 tr("Your configuration is invalid. This is most likely due "
173 "to a new installation of Rockbox Utility or a changed device "
174 "path. The configuation dialog will now open to allow you "
175 "correcting the problem."));
176 configDialog();
181 void RbUtilQt::downloadBleedingDone(bool error)
183 if(error) qDebug() << "network error:" << bleeding->error();
185 bleedingInfo.open();
186 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
187 bleedingInfo.close();
188 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
189 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
190 qDebug() << "versmap =" << versmap;
192 m_gotInfo = true;
196 void RbUtilQt::downloadDone(int id, bool error)
198 QString errorString;
199 errorString = tr("Network error: %1. Please check your network and proxy settings.")
200 .arg(daily->errorString());
201 if(error) {
202 QMessageBox::about(this, "Network Error", errorString);
204 qDebug() << "downloadDone:" << id << error;
208 void RbUtilQt::about()
210 QDialog *window = new QDialog(this);
211 Ui::aboutBox about;
212 about.setupUi(window);
213 window->setModal(true);
215 QFile licence(":/docs/gpl-2.0.html");
216 licence.open(QIODevice::ReadOnly);
217 QTextStream c(&licence);
218 QString cline = c.readAll();
219 about.browserLicense->insertHtml(cline);
220 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
221 QFile credits(":/docs/CREDITS");
222 credits.open(QIODevice::ReadOnly);
223 QTextStream r(&credits);
224 QString rline = r.readAll();
225 about.browserCredits->insertPlainText(rline);
226 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
227 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
228 about.labelTitle->setText(title);
229 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
231 window->show();
236 void RbUtilQt::help()
238 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
239 QDesktopServices::openUrl(helpurl);
243 void RbUtilQt::configDialog()
245 Config *cw = new Config(this);
246 cw->setSettings(settings);
247 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
248 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
249 cw->show();
253 void RbUtilQt::updateSettings()
255 qDebug() << "updateSettings()";
256 updateDevice();
257 updateManual();
258 if(settings->proxyType() == "system") {
259 HttpGet::setGlobalProxy(systemProxy());
261 else if(settings->proxyType() == "manual") {
262 HttpGet::setGlobalProxy(settings->proxy());
264 else {
265 HttpGet::setGlobalProxy(QUrl(""));
267 HttpGet::setGlobalCache(settings->cachePath());
271 void RbUtilQt::updateDevice()
273 if(!settings->curNeedsBootloader() ) {
274 ui.buttonBootloader->setEnabled(false);
275 ui.buttonRemoveBootloader->setEnabled(false);
276 ui.labelBootloader->setEnabled(false);
277 ui.labelRemoveBootloader->setEnabled(false);
279 else {
280 ui.buttonBootloader->setEnabled(true);
281 ui.labelBootloader->setEnabled(true);
282 if(settings->curBootloaderMethod() == "fwpatcher") {
283 ui.labelRemoveBootloader->setEnabled(false);
284 ui.buttonRemoveBootloader->setEnabled(false);
286 else {
287 ui.labelRemoveBootloader->setEnabled(true);
288 ui.buttonRemoveBootloader->setEnabled(true);
292 // displayed device info
293 QString mountpoint = settings->mountpoint();
294 QString brand = settings->curBrand();
295 QString name = settings->curName();
296 if(name.isEmpty()) name = "&lt;none&gt;";
297 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
298 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
299 .arg(brand, name, QDir::toNativeSeparators(mountpoint)));
303 void RbUtilQt::updateManual()
305 if(settings->curPlatform() != "")
307 QString manual= settings->curManual();
309 if(manual == "")
310 manual = "rockbox-" + settings->curPlatform();
311 QString pdfmanual;
312 pdfmanual = settings->manualUrl() + "/" + manual + ".pdf";
313 QString htmlmanual;
314 htmlmanual = settings->manualUrl() + "/" + manual + "/rockbox-build.html";
315 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
316 .arg(pdfmanual));
317 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
318 .arg(htmlmanual));
320 else {
321 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
322 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
323 .arg("http://www.rockbox.org/manual.shtml"));
328 void RbUtilQt::completeInstall()
330 if(chkConfig(true)) return;
331 if(QMessageBox::question(this, tr("Confirm Installation"),
332 tr("Do you really want to make a complete Installation?"),
333 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
335 // create logger
336 logger = new ProgressLoggerGui(this);
337 logger->show();
339 if(smallInstallInner())
340 return;
341 logger->undoAbort();
342 // Fonts
343 m_error = false;
344 m_installed = false;
345 if(!installFontsAuto())
346 return;
347 else
349 // wait for installation finished
350 while(!m_installed)
351 QApplication::processEvents();
353 if(m_error) return;
354 logger->undoAbort();
356 // Doom
357 if(hasDoom())
359 m_error = false;
360 m_installed = false;
361 if(!installDoomAuto())
362 return;
363 else
365 // wait for installation finished
366 while(!m_installed)
367 QApplication::processEvents();
369 if(m_error) return;
372 // theme
373 // this is a window
374 // it has its own logger window,so close our.
375 logger->close();
376 installThemes();
380 void RbUtilQt::smallInstall()
382 if(chkConfig(true)) return;
383 if(QMessageBox::question(this, tr("Confirm Installation"),
384 tr("Do you really want to make a small Installation?"),
385 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
387 // create logger
388 logger = new ProgressLoggerGui(this);
389 logger->show();
391 smallInstallInner();
394 bool RbUtilQt::smallInstallInner()
396 QString mountpoint = settings->mountpoint();
397 // show dialog with error if mount point is wrong
398 if(!QFileInfo(mountpoint).isDir()) {
399 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
400 logger->abort();
401 return true;
403 // Bootloader
404 if(settings->curNeedsBootloader())
406 m_error = false;
407 m_installed = false;
408 if(!installBootloaderAuto())
409 return true;
410 else
412 // wait for boot loader installation finished
413 while(!m_installed)
414 QApplication::processEvents();
416 if(m_error) return true;
417 logger->undoAbort();
420 // Rockbox
421 m_error = false;
422 m_installed = false;
423 if(!installAuto())
424 return true;
425 else
427 // wait for installation finished
428 while(!m_installed)
429 QApplication::processEvents();
432 return false;
435 void RbUtilQt::installdone(bool error)
437 qDebug() << "install done";
438 m_installed = true;
439 m_error = error;
442 void RbUtilQt::installBtn()
444 if(chkConfig(true)) return;
445 install();
448 bool RbUtilQt::installAuto()
450 QString file = QString("%1%2/rockbox.zip")
451 .arg(settings->bleedingUrl(), settings->curPlatform());
453 buildInfo.open();
454 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
455 buildInfo.close();
457 if(settings->curReleased()) {
458 // only set the keys if needed -- querying will yield an empty string
459 // if not set.
460 versmap.insert("rel_rev", settings->lastRelease());
461 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
464 QString myversion = "r" + versmap.value("bleed_rev");
466 ZipInstaller* installer = new ZipInstaller(this);
467 installer->setUrl(file);
468 installer->setLogSection("Rockbox (Base)");
469 installer->setLogVersion(myversion);
470 if(!settings->cacheDisabled())
471 installer->setCache(true);
472 installer->setMountPoint(settings->mountpoint());
474 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
476 installer->install(logger);
477 return true;
480 void RbUtilQt::install()
482 Install *installWindow = new Install(this);
483 installWindow->setSettings(settings);
485 buildInfo.open();
486 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
487 buildInfo.close();
489 if(settings->curReleased()) {
490 // only set the keys if needed -- querying will yield an empty string
491 // if not set.
492 versmap.insert("rel_rev", settings->lastRelease());
493 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
495 installWindow->setVersionStrings(versmap);
497 installWindow->show();
500 bool RbUtilQt::installBootloaderAuto()
502 installBootloader();
503 return !m_error;
506 void RbUtilQt::installBootloaderBtn()
508 if(chkConfig(true)) return;
509 if(QMessageBox::question(this, tr("Confirm Installation"),
510 tr("Do you really want to install the Bootloader?"),
511 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
513 // create logger
514 logger = new ProgressLoggerGui(this);
515 logger->show();
517 installBootloader();
520 void RbUtilQt::installBootloader()
522 QString platform = settings->curPlatform();
524 // create installer
525 blinstaller = new BootloaderInstaller(this);
527 blinstaller->setMountPoint(settings->mountpoint());
529 blinstaller->setDevice(platform);
530 blinstaller->setBootloaderMethod(settings->curBootloaderMethod());
531 blinstaller->setBootloaderName(settings->curBootloaderName());
532 blinstaller->setBootloaderBaseUrl(settings->bootloaderUrl());
533 blinstaller->setBootloaderInfoUrl(settings->bootloaderInfoUrl());
534 if(!blinstaller->downloadInfo())
536 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
537 logger->abort();
538 m_error = true;
539 return;
542 if(blinstaller->uptodate())
544 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
545 tr("The bootloader is already installed and up to date.\n"
546 "Do want to replace the current bootloader?"),
547 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
548 if(ret == QMessageBox::No)
550 logger->addItem(tr("Bootloader installation skipped!"), LOGINFO);
551 logger->abort();
552 m_installed = true;
553 return;
557 // if fwpatcher , ask for extra file
558 QString offirmware;
559 if(settings->curBootloaderMethod() == "fwpatcher")
561 BrowseOF ofbrowser(this);
562 ofbrowser.setFile(settings->ofPath());
563 if(ofbrowser.exec() == QDialog::Accepted)
565 offirmware = ofbrowser.getFile();
566 qDebug() << offirmware;
567 if(!QFileInfo(offirmware).exists())
569 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
570 logger->abort();
571 m_error = true;
572 return;
574 else
576 settings->setOfPath(offirmware);
577 settings->sync();
580 else
582 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
583 logger->abort();
584 m_error = true;
585 return;
588 blinstaller->setOrigFirmwarePath(offirmware);
589 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
590 blinstaller->install(logger);
593 void RbUtilQt::installFontsBtn()
595 if(chkConfig(true)) return;
596 if(QMessageBox::question(this, tr("Confirm Installation"),
597 tr("Do you really want to install the fonts package?"),
598 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
599 // create logger
600 logger = new ProgressLoggerGui(this);
601 logger->show();
602 installFonts();
605 bool RbUtilQt::installFontsAuto()
607 installFonts();
609 return !m_error;
612 void RbUtilQt::installFonts()
614 // create zip installer
615 installer = new ZipInstaller(this);
617 installer->setUrl(settings->fontUrl());
618 installer->setLogSection("Fonts");
619 installer->setLogVersion(versmap.value("arch_date"));
620 installer->setMountPoint(settings->mountpoint());
621 if(!settings->cacheDisabled())
622 installer->setCache(true);
624 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
625 installer->install(logger);
629 void RbUtilQt::installVoice()
631 if(chkConfig(true)) return;
633 if(m_gotInfo == false)
635 QMessageBox::warning(this, tr("Warning"),
636 tr("The Application is still downloading Information about new Builds. Please try again shortly."));
637 return;
640 if(QMessageBox::question(this, tr("Confirm Installation"),
641 tr("Do you really want to install the voice file?"),
642 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
643 // create logger
644 logger = new ProgressLoggerGui(this);
645 logger->show();
647 // create zip installer
648 installer = new ZipInstaller(this);
650 QString voiceurl = settings->voiceUrl();
652 voiceurl += settings->curVoiceName() + "-" +
653 versmap.value("arch_date") + "-english.zip";
654 qDebug() << voiceurl;
656 installer->setUrl(voiceurl);
657 installer->setLogSection("Voice");
658 installer->setLogVersion(versmap.value("arch_date"));
659 installer->setMountPoint(settings->mountpoint());
660 if(!settings->cacheDisabled())
661 installer->setCache(true);
662 installer->install(logger);
666 void RbUtilQt::installDoomBtn()
668 if(chkConfig(true)) return;
669 if(!hasDoom()){
670 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
671 return;
674 if(QMessageBox::question(this, tr("Confirm Installation"),
675 tr("Do you really want to install the game addon files?"),
676 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
677 // create logger
678 logger = new ProgressLoggerGui(this);
679 logger->show();
681 installDoom();
683 bool RbUtilQt::installDoomAuto()
685 installDoom();
686 return !m_error;
689 bool RbUtilQt::hasDoom()
691 QFile doomrock(settings->mountpoint() +"/.rockbox/rocks/games/doom.rock");
692 return doomrock.exists();
695 void RbUtilQt::installDoom()
697 // create zip installer
698 installer = new ZipInstaller(this);
700 installer->setUrl(settings->doomUrl());
701 installer->setLogSection("Game Addons");
702 installer->setLogVersion(versmap.value("arch_date"));
703 installer->setMountPoint(settings->mountpoint());
704 if(!settings->cacheDisabled())
705 installer->setCache(true);
706 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
707 installer->install(logger);
711 void RbUtilQt::installThemes()
713 if(chkConfig(true)) return;
714 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
715 tw->setSettings(settings);
716 tw->setModal(true);
717 tw->show();
720 void RbUtilQt::createTalkFiles(void)
722 if(chkConfig(true)) return;
723 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
724 installWindow->setSettings(settings);
726 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
727 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
728 installWindow->show();
732 void RbUtilQt::createVoiceFile(void)
734 if(chkConfig(true)) return;
735 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
736 installWindow->setSettings(settings);
738 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
739 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
740 installWindow->show();
743 void RbUtilQt::uninstall(void)
745 if(chkConfig(true)) return;
746 UninstallWindow *uninstallWindow = new UninstallWindow(this);
747 uninstallWindow->setSettings(settings);
748 uninstallWindow->show();
752 void RbUtilQt::uninstallBootloader(void)
754 if(chkConfig(true)) return;
755 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
756 tr("Do you really want to uninstall the Bootloader?"),
757 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
758 // create logger
759 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
760 logger->show();
762 BootloaderInstaller blinstaller(this);
763 blinstaller.setMountPoint(settings->mountpoint());
764 blinstaller.setDevice(settings->curPlatform());
765 blinstaller.setBootloaderMethod(settings->curBootloaderMethod());
766 blinstaller.setBootloaderName(settings->curBootloaderName());
767 blinstaller.setBootloaderBaseUrl(settings->bootloaderUrl());
768 blinstaller.setBootloaderInfoUrl(settings->bootloaderInfoUrl());
769 if(!blinstaller.downloadInfo())
771 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
772 logger->abort();
773 return;
776 blinstaller.uninstall(logger);
781 void RbUtilQt::downloadManual(void)
783 if(chkConfig(true)) return;
784 if(QMessageBox::question(this, tr("Confirm download"),
785 tr("Do you really want to download the manual? The manual will be saved "
786 "to the root folder of your player."),
787 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
788 return;
790 buildInfo.open();
791 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
792 buildInfo.close();
794 QString manual = settings->curManual();
796 QString date = (info.value("dailies/date").toString());
798 QString manualurl;
799 QString target;
800 QString section;
801 if(ui.radioPdf->isChecked()) {
802 target = "/" + manual + ".pdf";
803 section = "Manual (PDF)";
805 else {
806 target = "/" + manual + "-" + date + "-html.zip";
807 section = "Manual (HTML)";
809 manualurl = settings->manualUrl() + "/" + target;
810 qDebug() << "manualurl =" << manualurl;
812 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
813 logger->show();
814 installer = new ZipInstaller(this);
815 installer->setMountPoint(settings->mountpoint());
816 if(!settings->cacheDisabled())
817 installer->setCache(true);
818 installer->setLogSection(section);
819 installer->setLogVersion(date);
820 installer->setUrl(manualurl);
821 installer->setUnzip(false);
822 installer->setTarget(target);
823 installer->install(logger);
827 void RbUtilQt::installPortable(void)
829 if(QMessageBox::question(this, tr("Confirm installation"),
830 tr("Do you really want to install Rockbox Utility to your player? "
831 "After installation you can run it from the players hard drive."),
832 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
833 return;
835 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
836 logger->setProgressMax(0);
837 logger->setProgressValue(0);
838 logger->show();
839 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
841 // check mountpoint
842 if(!QFileInfo(settings->mountpoint()).isDir()) {
843 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
844 logger->abort();
845 return;
848 // remove old files first.
849 QFile::remove(settings->mountpoint() + "/RockboxUtility.exe");
850 QFile::remove(settings->mountpoint() + "/RockboxUtility.ini");
851 // copy currently running binary and currently used settings file
852 if(!QFile::copy(qApp->applicationFilePath(), settings->mountpoint() + "/RockboxUtility.exe")) {
853 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
854 logger->abort();
855 return;
857 logger->addItem(tr("Installing user configuration"), LOGINFO);
858 if(!QFile::copy(settings->userSettingFilename(), settings->mountpoint() + "/RockboxUtility.ini")) {
859 logger->addItem(tr("Error installing user configuration"), LOGERROR);
860 logger->abort();
861 return;
863 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
864 logger->abort();
865 logger->setProgressMax(1);
866 logger->setProgressValue(1);
871 void RbUtilQt::updateInfo()
873 qDebug() << "RbUtilQt::updateInfo()";
875 QSettings log(settings->mountpoint() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
876 QStringList groups = log.childGroups();
877 QList<QTreeWidgetItem *> items;
878 QTreeWidgetItem *w, *w2;
879 QString min, max;
880 int olditems = 0;
882 // remove old list entries (if any)
883 int l = ui.treeInfo->topLevelItemCount();
884 while(l--) {
885 QTreeWidgetItem *m;
886 m = ui.treeInfo->takeTopLevelItem(l);
887 // delete childs (single level deep, no recursion here)
888 int n = m->childCount();
889 while(n--)
890 delete m->child(n);
892 // get and populate new items
893 for(int a = 0; a < groups.size(); a++) {
894 log.beginGroup(groups.at(a));
895 QStringList keys = log.allKeys();
896 w = new QTreeWidgetItem;
897 w->setFlags(Qt::ItemIsEnabled);
898 w->setText(0, groups.at(a));
899 items.append(w);
900 // get minimum and maximum version information so we can hilight old files
901 min = max = log.value(keys.at(0)).toString();
902 for(int b = 0; b < keys.size(); b++) {
903 if(log.value(keys.at(b)).toString() > max)
904 max = log.value(keys.at(b)).toString();
905 if(log.value(keys.at(b)).toString() < min)
906 min = log.value(keys.at(b)).toString();
909 for(int b = 0; b < keys.size(); b++) {
910 QString file;
911 file = settings->mountpoint() + "/" + keys.at(b);
912 if(QFileInfo(file).isDir())
913 continue;
914 w2 = new QTreeWidgetItem(w, QStringList() << "/"
915 + keys.at(b) << log.value(keys.at(b)).toString());
916 if(log.value(keys.at(b)).toString() != max) {
917 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
918 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
919 olditems++;
921 items.append(w2);
923 log.endGroup();
924 if(min != max)
925 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
926 else
927 w->setData(1, Qt::DisplayRole, max);
929 ui.treeInfo->insertTopLevelItems(0, items);
930 ui.treeInfo->resizeColumnToContents(0);
934 QUrl RbUtilQt::proxy()
936 if(settings->proxyType() == "manual")
937 return QUrl(settings->proxy());
938 else if(settings->proxy() == "system")
940 return systemProxy();
942 return QUrl("");
946 bool RbUtilQt::chkConfig(bool warn)
948 bool error = false;
949 if(settings->curPlatform().isEmpty()
950 || settings->mountpoint().isEmpty()
951 || !QFileInfo(settings->mountpoint()).isWritable()) {
952 error = true;
954 if(warn) QMessageBox::critical(this, tr("Configuration error"),
955 tr("Your configuration is invalid. Please go to the configuration "
956 "dialog and make sure the selected values are correct."));
958 return error;